dev-eth.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*
  2. * Atheros AR71xx SoC platform devices
  3. *
  4. * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  5. * Copyright (C) 2008-2012 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. *
  8. * Parts of this file are based on Atheros 2.6.15 BSP
  9. * Parts of this file are based on Atheros 2.6.31 BSP
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as published
  13. * by the Free Software Foundation.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/serial_8250.h>
  21. #include <linux/clk.h>
  22. #include <linux/sizes.h>
  23. #include <asm/mach-ath79/ath79.h>
  24. #include <asm/mach-ath79/ar71xx_regs.h>
  25. #include <asm/mach-ath79/irq.h>
  26. #include "common.h"
  27. #include "dev-eth.h"
  28. unsigned char ath79_mac_base[ETH_ALEN] __initdata;
  29. static struct resource ath79_mdio0_resources[] = {
  30. {
  31. .name = "mdio_base",
  32. .flags = IORESOURCE_MEM,
  33. .start = AR71XX_GE0_BASE,
  34. .end = AR71XX_GE0_BASE + 0x200 - 1,
  35. }
  36. };
  37. struct ag71xx_mdio_platform_data ath79_mdio0_data;
  38. struct platform_device ath79_mdio0_device = {
  39. .name = "ag71xx-mdio",
  40. .id = 0,
  41. .resource = ath79_mdio0_resources,
  42. .num_resources = ARRAY_SIZE(ath79_mdio0_resources),
  43. .dev = {
  44. .platform_data = &ath79_mdio0_data,
  45. },
  46. };
  47. static struct resource ath79_mdio1_resources[] = {
  48. {
  49. .name = "mdio_base",
  50. .flags = IORESOURCE_MEM,
  51. .start = AR71XX_GE1_BASE,
  52. .end = AR71XX_GE1_BASE + 0x200 - 1,
  53. }
  54. };
  55. struct ag71xx_mdio_platform_data ath79_mdio1_data;
  56. struct platform_device ath79_mdio1_device = {
  57. .name = "ag71xx-mdio",
  58. .id = 1,
  59. .resource = ath79_mdio1_resources,
  60. .num_resources = ARRAY_SIZE(ath79_mdio1_resources),
  61. .dev = {
  62. .platform_data = &ath79_mdio1_data,
  63. },
  64. };
  65. static void ath79_set_pll(u32 cfg_reg, u32 pll_reg, u32 pll_val, u32 shift)
  66. {
  67. void __iomem *base;
  68. u32 t;
  69. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  70. t = __raw_readl(base + cfg_reg);
  71. t &= ~(3 << shift);
  72. t |= (2 << shift);
  73. __raw_writel(t, base + cfg_reg);
  74. udelay(100);
  75. __raw_writel(pll_val, base + pll_reg);
  76. t |= (3 << shift);
  77. __raw_writel(t, base + cfg_reg);
  78. udelay(100);
  79. t &= ~(3 << shift);
  80. __raw_writel(t, base + cfg_reg);
  81. udelay(100);
  82. printk(KERN_DEBUG "ar71xx: pll_reg %#x: %#x\n",
  83. (unsigned int)(base + pll_reg), __raw_readl(base + pll_reg));
  84. iounmap(base);
  85. }
  86. static void __init ath79_mii_ctrl_set_if(unsigned int reg,
  87. unsigned int mii_if)
  88. {
  89. void __iomem *base;
  90. u32 t;
  91. base = ioremap(AR71XX_MII_BASE, AR71XX_MII_SIZE);
  92. t = __raw_readl(base + reg);
  93. t &= ~(AR71XX_MII_CTRL_IF_MASK);
  94. t |= (mii_if & AR71XX_MII_CTRL_IF_MASK);
  95. __raw_writel(t, base + reg);
  96. iounmap(base);
  97. }
  98. static void ath79_mii_ctrl_set_speed(unsigned int reg, unsigned int speed)
  99. {
  100. void __iomem *base;
  101. unsigned int mii_speed;
  102. u32 t;
  103. switch (speed) {
  104. case SPEED_10:
  105. mii_speed = AR71XX_MII_CTRL_SPEED_10;
  106. break;
  107. case SPEED_100:
  108. mii_speed = AR71XX_MII_CTRL_SPEED_100;
  109. break;
  110. case SPEED_1000:
  111. mii_speed = AR71XX_MII_CTRL_SPEED_1000;
  112. break;
  113. default:
  114. BUG();
  115. }
  116. base = ioremap(AR71XX_MII_BASE, AR71XX_MII_SIZE);
  117. t = __raw_readl(base + reg);
  118. t &= ~(AR71XX_MII_CTRL_SPEED_MASK << AR71XX_MII_CTRL_SPEED_SHIFT);
  119. t |= mii_speed << AR71XX_MII_CTRL_SPEED_SHIFT;
  120. __raw_writel(t, base + reg);
  121. iounmap(base);
  122. }
  123. static unsigned long ar934x_get_mdio_ref_clock(void)
  124. {
  125. void __iomem *base;
  126. unsigned long ret;
  127. u32 t;
  128. base = ioremap(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  129. ret = 0;
  130. t = __raw_readl(base + AR934X_PLL_SWITCH_CLOCK_CONTROL_REG);
  131. if (t & AR934X_PLL_SWITCH_CLOCK_CONTROL_MDIO_CLK_SEL) {
  132. ret = 100 * 1000 * 1000;
  133. } else {
  134. struct clk *clk;
  135. clk = clk_get(NULL, "ref");
  136. if (!IS_ERR(clk))
  137. ret = clk_get_rate(clk);
  138. }
  139. iounmap(base);
  140. return ret;
  141. }
  142. void __init ath79_register_mdio(unsigned int id, u32 phy_mask)
  143. {
  144. struct platform_device *mdio_dev;
  145. struct ag71xx_mdio_platform_data *mdio_data;
  146. unsigned int max_id;
  147. if (ath79_soc == ATH79_SOC_AR9341 ||
  148. ath79_soc == ATH79_SOC_AR9342 ||
  149. ath79_soc == ATH79_SOC_AR9344 ||
  150. ath79_soc == ATH79_SOC_QCA9556 ||
  151. ath79_soc == ATH79_SOC_QCA9558)
  152. max_id = 1;
  153. else
  154. max_id = 0;
  155. if (id > max_id) {
  156. printk(KERN_ERR "ar71xx: invalid MDIO id %u\n", id);
  157. return;
  158. }
  159. switch (ath79_soc) {
  160. case ATH79_SOC_AR7241:
  161. case ATH79_SOC_AR9330:
  162. case ATH79_SOC_AR9331:
  163. case ATH79_SOC_QCA9533:
  164. case ATH79_SOC_QCA9561:
  165. case ATH79_SOC_TP9343:
  166. mdio_dev = &ath79_mdio1_device;
  167. mdio_data = &ath79_mdio1_data;
  168. break;
  169. case ATH79_SOC_AR9341:
  170. case ATH79_SOC_AR9342:
  171. case ATH79_SOC_AR9344:
  172. case ATH79_SOC_QCA9556:
  173. case ATH79_SOC_QCA9558:
  174. if (id == 0) {
  175. mdio_dev = &ath79_mdio0_device;
  176. mdio_data = &ath79_mdio0_data;
  177. } else {
  178. mdio_dev = &ath79_mdio1_device;
  179. mdio_data = &ath79_mdio1_data;
  180. }
  181. break;
  182. case ATH79_SOC_AR7242:
  183. ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG,
  184. AR7242_PLL_REG_ETH0_INT_CLOCK, 0x62000000,
  185. AR71XX_ETH0_PLL_SHIFT);
  186. /* fall through */
  187. default:
  188. mdio_dev = &ath79_mdio0_device;
  189. mdio_data = &ath79_mdio0_data;
  190. break;
  191. }
  192. mdio_data->phy_mask = phy_mask;
  193. switch (ath79_soc) {
  194. case ATH79_SOC_AR7240:
  195. mdio_data->is_ar7240 = 1;
  196. /* fall through */
  197. case ATH79_SOC_AR7241:
  198. mdio_data->builtin_switch = 1;
  199. break;
  200. case ATH79_SOC_AR9330:
  201. mdio_data->is_ar9330 = 1;
  202. /* fall through */
  203. case ATH79_SOC_AR9331:
  204. mdio_data->builtin_switch = 1;
  205. break;
  206. case ATH79_SOC_AR9341:
  207. case ATH79_SOC_AR9342:
  208. case ATH79_SOC_AR9344:
  209. if (id == 1) {
  210. mdio_data->builtin_switch = 1;
  211. mdio_data->ref_clock = ar934x_get_mdio_ref_clock();
  212. mdio_data->mdio_clock = 6250000;
  213. }
  214. mdio_data->is_ar934x = 1;
  215. break;
  216. case ATH79_SOC_QCA9533:
  217. case ATH79_SOC_QCA9561:
  218. case ATH79_SOC_TP9343:
  219. mdio_data->builtin_switch = 1;
  220. break;
  221. case ATH79_SOC_QCA9556:
  222. case ATH79_SOC_QCA9558:
  223. mdio_data->is_ar934x = 1;
  224. break;
  225. default:
  226. break;
  227. }
  228. platform_device_register(mdio_dev);
  229. }
  230. struct ath79_eth_pll_data ath79_eth0_pll_data;
  231. struct ath79_eth_pll_data ath79_eth1_pll_data;
  232. static u32 ath79_get_eth_pll(unsigned int mac, int speed)
  233. {
  234. struct ath79_eth_pll_data *pll_data;
  235. u32 pll_val;
  236. switch (mac) {
  237. case 0:
  238. pll_data = &ath79_eth0_pll_data;
  239. break;
  240. case 1:
  241. pll_data = &ath79_eth1_pll_data;
  242. break;
  243. default:
  244. BUG();
  245. }
  246. switch (speed) {
  247. case SPEED_10:
  248. pll_val = pll_data->pll_10;
  249. break;
  250. case SPEED_100:
  251. pll_val = pll_data->pll_100;
  252. break;
  253. case SPEED_1000:
  254. pll_val = pll_data->pll_1000;
  255. break;
  256. default:
  257. BUG();
  258. }
  259. return pll_val;
  260. }
  261. static void ath79_set_speed_ge0(int speed)
  262. {
  263. u32 val = ath79_get_eth_pll(0, speed);
  264. ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH0_INT_CLOCK,
  265. val, AR71XX_ETH0_PLL_SHIFT);
  266. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL, speed);
  267. }
  268. static void ath79_set_speed_ge1(int speed)
  269. {
  270. u32 val = ath79_get_eth_pll(1, speed);
  271. ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH1_INT_CLOCK,
  272. val, AR71XX_ETH1_PLL_SHIFT);
  273. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL, speed);
  274. }
  275. static void ar7242_set_speed_ge0(int speed)
  276. {
  277. u32 val = ath79_get_eth_pll(0, speed);
  278. void __iomem *base;
  279. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  280. __raw_writel(val, base + AR7242_PLL_REG_ETH0_INT_CLOCK);
  281. iounmap(base);
  282. }
  283. static void ar91xx_set_speed_ge0(int speed)
  284. {
  285. u32 val = ath79_get_eth_pll(0, speed);
  286. ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG, AR913X_PLL_REG_ETH0_INT_CLOCK,
  287. val, AR913X_ETH0_PLL_SHIFT);
  288. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL, speed);
  289. }
  290. static void ar91xx_set_speed_ge1(int speed)
  291. {
  292. u32 val = ath79_get_eth_pll(1, speed);
  293. ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG, AR913X_PLL_REG_ETH1_INT_CLOCK,
  294. val, AR913X_ETH1_PLL_SHIFT);
  295. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL, speed);
  296. }
  297. static void ar934x_set_speed_ge0(int speed)
  298. {
  299. void __iomem *base;
  300. u32 val = ath79_get_eth_pll(0, speed);
  301. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  302. __raw_writel(val, base + AR934X_PLL_ETH_XMII_CONTROL_REG);
  303. iounmap(base);
  304. }
  305. static void qca955x_set_speed_xmii(int speed)
  306. {
  307. void __iomem *base;
  308. u32 val = ath79_get_eth_pll(0, speed);
  309. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  310. __raw_writel(val, base + QCA955X_PLL_ETH_XMII_CONTROL_REG);
  311. iounmap(base);
  312. }
  313. static void qca955x_set_speed_sgmii(int speed)
  314. {
  315. void __iomem *base;
  316. u32 val = ath79_get_eth_pll(1, speed);
  317. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  318. __raw_writel(val, base + QCA955X_PLL_ETH_SGMII_CONTROL_REG);
  319. iounmap(base);
  320. }
  321. static void ath79_set_speed_dummy(int speed)
  322. {
  323. }
  324. static void ath79_ddr_no_flush(void)
  325. {
  326. }
  327. static void ath79_ddr_flush_ge0(void)
  328. {
  329. ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_GE0);
  330. }
  331. static void ath79_ddr_flush_ge1(void)
  332. {
  333. ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_GE1);
  334. }
  335. static void ar724x_ddr_flush_ge0(void)
  336. {
  337. ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_GE0);
  338. }
  339. static void ar724x_ddr_flush_ge1(void)
  340. {
  341. ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_GE1);
  342. }
  343. static void ar91xx_ddr_flush_ge0(void)
  344. {
  345. ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_GE0);
  346. }
  347. static void ar91xx_ddr_flush_ge1(void)
  348. {
  349. ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_GE1);
  350. }
  351. static void ar933x_ddr_flush_ge0(void)
  352. {
  353. ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_GE0);
  354. }
  355. static void ar933x_ddr_flush_ge1(void)
  356. {
  357. ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_GE1);
  358. }
  359. static struct resource ath79_eth0_resources[] = {
  360. {
  361. .name = "mac_base",
  362. .flags = IORESOURCE_MEM,
  363. .start = AR71XX_GE0_BASE,
  364. .end = AR71XX_GE0_BASE + 0x200 - 1,
  365. }, {
  366. .name = "mac_irq",
  367. .flags = IORESOURCE_IRQ,
  368. .start = ATH79_CPU_IRQ(4),
  369. .end = ATH79_CPU_IRQ(4),
  370. },
  371. };
  372. struct ag71xx_platform_data ath79_eth0_data = {
  373. .reset_bit = AR71XX_RESET_GE0_MAC,
  374. };
  375. struct platform_device ath79_eth0_device = {
  376. .name = "ag71xx",
  377. .id = 0,
  378. .resource = ath79_eth0_resources,
  379. .num_resources = ARRAY_SIZE(ath79_eth0_resources),
  380. .dev = {
  381. .platform_data = &ath79_eth0_data,
  382. },
  383. };
  384. static struct resource ath79_eth1_resources[] = {
  385. {
  386. .name = "mac_base",
  387. .flags = IORESOURCE_MEM,
  388. .start = AR71XX_GE1_BASE,
  389. .end = AR71XX_GE1_BASE + 0x200 - 1,
  390. }, {
  391. .name = "mac_irq",
  392. .flags = IORESOURCE_IRQ,
  393. .start = ATH79_CPU_IRQ(5),
  394. .end = ATH79_CPU_IRQ(5),
  395. },
  396. };
  397. struct ag71xx_platform_data ath79_eth1_data = {
  398. .reset_bit = AR71XX_RESET_GE1_MAC,
  399. };
  400. struct platform_device ath79_eth1_device = {
  401. .name = "ag71xx",
  402. .id = 1,
  403. .resource = ath79_eth1_resources,
  404. .num_resources = ARRAY_SIZE(ath79_eth1_resources),
  405. .dev = {
  406. .platform_data = &ath79_eth1_data,
  407. },
  408. };
  409. struct ag71xx_switch_platform_data ath79_switch_data;
  410. #define AR71XX_PLL_VAL_1000 0x00110000
  411. #define AR71XX_PLL_VAL_100 0x00001099
  412. #define AR71XX_PLL_VAL_10 0x00991099
  413. #define AR724X_PLL_VAL_1000 0x00110000
  414. #define AR724X_PLL_VAL_100 0x00001099
  415. #define AR724X_PLL_VAL_10 0x00991099
  416. #define AR7242_PLL_VAL_1000 0x16000000
  417. #define AR7242_PLL_VAL_100 0x00000101
  418. #define AR7242_PLL_VAL_10 0x00001616
  419. #define AR913X_PLL_VAL_1000 0x1a000000
  420. #define AR913X_PLL_VAL_100 0x13000a44
  421. #define AR913X_PLL_VAL_10 0x00441099
  422. #define AR933X_PLL_VAL_1000 0x00110000
  423. #define AR933X_PLL_VAL_100 0x00001099
  424. #define AR933X_PLL_VAL_10 0x00991099
  425. #define AR934X_PLL_VAL_1000 0x16000000
  426. #define AR934X_PLL_VAL_100 0x00000101
  427. #define AR934X_PLL_VAL_10 0x00001616
  428. static void __init ath79_init_eth_pll_data(unsigned int id)
  429. {
  430. struct ath79_eth_pll_data *pll_data;
  431. u32 pll_10, pll_100, pll_1000;
  432. switch (id) {
  433. case 0:
  434. pll_data = &ath79_eth0_pll_data;
  435. break;
  436. case 1:
  437. pll_data = &ath79_eth1_pll_data;
  438. break;
  439. default:
  440. BUG();
  441. }
  442. switch (ath79_soc) {
  443. case ATH79_SOC_AR7130:
  444. case ATH79_SOC_AR7141:
  445. case ATH79_SOC_AR7161:
  446. pll_10 = AR71XX_PLL_VAL_10;
  447. pll_100 = AR71XX_PLL_VAL_100;
  448. pll_1000 = AR71XX_PLL_VAL_1000;
  449. break;
  450. case ATH79_SOC_AR7240:
  451. case ATH79_SOC_AR7241:
  452. pll_10 = AR724X_PLL_VAL_10;
  453. pll_100 = AR724X_PLL_VAL_100;
  454. pll_1000 = AR724X_PLL_VAL_1000;
  455. break;
  456. case ATH79_SOC_AR7242:
  457. pll_10 = AR7242_PLL_VAL_10;
  458. pll_100 = AR7242_PLL_VAL_100;
  459. pll_1000 = AR7242_PLL_VAL_1000;
  460. break;
  461. case ATH79_SOC_AR9130:
  462. case ATH79_SOC_AR9132:
  463. pll_10 = AR913X_PLL_VAL_10;
  464. pll_100 = AR913X_PLL_VAL_100;
  465. pll_1000 = AR913X_PLL_VAL_1000;
  466. break;
  467. case ATH79_SOC_AR9330:
  468. case ATH79_SOC_AR9331:
  469. pll_10 = AR933X_PLL_VAL_10;
  470. pll_100 = AR933X_PLL_VAL_100;
  471. pll_1000 = AR933X_PLL_VAL_1000;
  472. break;
  473. case ATH79_SOC_AR9341:
  474. case ATH79_SOC_AR9342:
  475. case ATH79_SOC_AR9344:
  476. case ATH79_SOC_QCA9533:
  477. case ATH79_SOC_QCA9556:
  478. case ATH79_SOC_QCA9558:
  479. case ATH79_SOC_QCA9561:
  480. case ATH79_SOC_TP9343:
  481. pll_10 = AR934X_PLL_VAL_10;
  482. pll_100 = AR934X_PLL_VAL_100;
  483. pll_1000 = AR934X_PLL_VAL_1000;
  484. break;
  485. default:
  486. BUG();
  487. }
  488. if (!pll_data->pll_10)
  489. pll_data->pll_10 = pll_10;
  490. if (!pll_data->pll_100)
  491. pll_data->pll_100 = pll_100;
  492. if (!pll_data->pll_1000)
  493. pll_data->pll_1000 = pll_1000;
  494. }
  495. static int __init ath79_setup_phy_if_mode(unsigned int id,
  496. struct ag71xx_platform_data *pdata)
  497. {
  498. unsigned int mii_if;
  499. switch (id) {
  500. case 0:
  501. switch (ath79_soc) {
  502. case ATH79_SOC_AR7130:
  503. case ATH79_SOC_AR7141:
  504. case ATH79_SOC_AR7161:
  505. case ATH79_SOC_AR9130:
  506. case ATH79_SOC_AR9132:
  507. switch (pdata->phy_if_mode) {
  508. case PHY_INTERFACE_MODE_MII:
  509. mii_if = AR71XX_MII0_CTRL_IF_MII;
  510. break;
  511. case PHY_INTERFACE_MODE_GMII:
  512. mii_if = AR71XX_MII0_CTRL_IF_GMII;
  513. break;
  514. case PHY_INTERFACE_MODE_RGMII:
  515. mii_if = AR71XX_MII0_CTRL_IF_RGMII;
  516. break;
  517. case PHY_INTERFACE_MODE_RMII:
  518. mii_if = AR71XX_MII0_CTRL_IF_RMII;
  519. break;
  520. default:
  521. return -EINVAL;
  522. }
  523. ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII0_CTRL, mii_if);
  524. break;
  525. case ATH79_SOC_AR7240:
  526. case ATH79_SOC_AR7241:
  527. case ATH79_SOC_AR9330:
  528. case ATH79_SOC_AR9331:
  529. case ATH79_SOC_QCA9533:
  530. case ATH79_SOC_QCA9561:
  531. case ATH79_SOC_TP9343:
  532. pdata->phy_if_mode = PHY_INTERFACE_MODE_MII;
  533. break;
  534. case ATH79_SOC_AR7242:
  535. /* FIXME */
  536. case ATH79_SOC_AR9341:
  537. case ATH79_SOC_AR9342:
  538. case ATH79_SOC_AR9344:
  539. switch (pdata->phy_if_mode) {
  540. case PHY_INTERFACE_MODE_MII:
  541. case PHY_INTERFACE_MODE_GMII:
  542. case PHY_INTERFACE_MODE_RGMII:
  543. case PHY_INTERFACE_MODE_RMII:
  544. break;
  545. default:
  546. return -EINVAL;
  547. }
  548. break;
  549. case ATH79_SOC_QCA9556:
  550. case ATH79_SOC_QCA9558:
  551. switch (pdata->phy_if_mode) {
  552. case PHY_INTERFACE_MODE_MII:
  553. case PHY_INTERFACE_MODE_RGMII:
  554. case PHY_INTERFACE_MODE_SGMII:
  555. break;
  556. default:
  557. return -EINVAL;
  558. }
  559. break;
  560. default:
  561. BUG();
  562. }
  563. break;
  564. case 1:
  565. switch (ath79_soc) {
  566. case ATH79_SOC_AR7130:
  567. case ATH79_SOC_AR7141:
  568. case ATH79_SOC_AR7161:
  569. case ATH79_SOC_AR9130:
  570. case ATH79_SOC_AR9132:
  571. switch (pdata->phy_if_mode) {
  572. case PHY_INTERFACE_MODE_RMII:
  573. mii_if = AR71XX_MII1_CTRL_IF_RMII;
  574. break;
  575. case PHY_INTERFACE_MODE_RGMII:
  576. mii_if = AR71XX_MII1_CTRL_IF_RGMII;
  577. break;
  578. default:
  579. return -EINVAL;
  580. }
  581. ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII1_CTRL, mii_if);
  582. break;
  583. case ATH79_SOC_AR7240:
  584. case ATH79_SOC_AR7241:
  585. case ATH79_SOC_AR9330:
  586. case ATH79_SOC_AR9331:
  587. case ATH79_SOC_QCA9561:
  588. case ATH79_SOC_TP9343:
  589. pdata->phy_if_mode = PHY_INTERFACE_MODE_GMII;
  590. break;
  591. case ATH79_SOC_AR7242:
  592. /* FIXME */
  593. case ATH79_SOC_AR9341:
  594. case ATH79_SOC_AR9342:
  595. case ATH79_SOC_AR9344:
  596. case ATH79_SOC_QCA9533:
  597. switch (pdata->phy_if_mode) {
  598. case PHY_INTERFACE_MODE_MII:
  599. case PHY_INTERFACE_MODE_GMII:
  600. break;
  601. default:
  602. return -EINVAL;
  603. }
  604. break;
  605. case ATH79_SOC_QCA9556:
  606. case ATH79_SOC_QCA9558:
  607. switch (pdata->phy_if_mode) {
  608. case PHY_INTERFACE_MODE_MII:
  609. case PHY_INTERFACE_MODE_RGMII:
  610. case PHY_INTERFACE_MODE_SGMII:
  611. break;
  612. default:
  613. return -EINVAL;
  614. }
  615. break;
  616. default:
  617. BUG();
  618. }
  619. break;
  620. }
  621. return 0;
  622. }
  623. void __init ath79_setup_ar933x_phy4_switch(bool mac, bool mdio)
  624. {
  625. void __iomem *base;
  626. u32 t;
  627. base = ioremap(AR933X_GMAC_BASE, AR933X_GMAC_SIZE);
  628. t = __raw_readl(base + AR933X_GMAC_REG_ETH_CFG);
  629. t &= ~(AR933X_ETH_CFG_SW_PHY_SWAP | AR933X_ETH_CFG_SW_PHY_ADDR_SWAP);
  630. if (mac)
  631. t |= AR933X_ETH_CFG_SW_PHY_SWAP;
  632. if (mdio)
  633. t |= AR933X_ETH_CFG_SW_PHY_ADDR_SWAP;
  634. __raw_writel(t, base + AR933X_GMAC_REG_ETH_CFG);
  635. iounmap(base);
  636. }
  637. void __init ath79_setup_ar934x_eth_cfg(u32 mask)
  638. {
  639. void __iomem *base;
  640. u32 t;
  641. base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE);
  642. t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  643. t &= ~(AR934X_ETH_CFG_RGMII_GMAC0 |
  644. AR934X_ETH_CFG_MII_GMAC0 |
  645. AR934X_ETH_CFG_GMII_GMAC0 |
  646. AR934X_ETH_CFG_SW_ONLY_MODE |
  647. AR934X_ETH_CFG_SW_PHY_SWAP);
  648. t |= mask;
  649. __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG);
  650. /* flush write */
  651. __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  652. iounmap(base);
  653. }
  654. void __init ath79_setup_ar934x_eth_rx_delay(unsigned int rxd,
  655. unsigned int rxdv)
  656. {
  657. void __iomem *base;
  658. u32 t;
  659. rxd &= AR934X_ETH_CFG_RXD_DELAY_MASK;
  660. rxdv &= AR934X_ETH_CFG_RDV_DELAY_MASK;
  661. base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE);
  662. t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  663. t &= ~(AR934X_ETH_CFG_RXD_DELAY_MASK << AR934X_ETH_CFG_RXD_DELAY_SHIFT |
  664. AR934X_ETH_CFG_RDV_DELAY_MASK << AR934X_ETH_CFG_RDV_DELAY_SHIFT);
  665. t |= (rxd << AR934X_ETH_CFG_RXD_DELAY_SHIFT |
  666. rxdv << AR934X_ETH_CFG_RDV_DELAY_SHIFT);
  667. __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG);
  668. /* flush write */
  669. __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  670. iounmap(base);
  671. }
  672. void __init ath79_setup_qca955x_eth_cfg(u32 mask)
  673. {
  674. void __iomem *base;
  675. u32 t;
  676. base = ioremap(QCA955X_GMAC_BASE, QCA955X_GMAC_SIZE);
  677. t = __raw_readl(base + QCA955X_GMAC_REG_ETH_CFG);
  678. t &= ~(QCA955X_ETH_CFG_RGMII_EN | QCA955X_ETH_CFG_GE0_SGMII);
  679. t |= mask;
  680. __raw_writel(t, base + QCA955X_GMAC_REG_ETH_CFG);
  681. iounmap(base);
  682. }
  683. static int ath79_eth_instance __initdata;
  684. void __init ath79_register_eth(unsigned int id)
  685. {
  686. struct platform_device *pdev;
  687. struct ag71xx_platform_data *pdata;
  688. int err;
  689. if (id > 1) {
  690. printk(KERN_ERR "ar71xx: invalid ethernet id %d\n", id);
  691. return;
  692. }
  693. ath79_init_eth_pll_data(id);
  694. if (id == 0)
  695. pdev = &ath79_eth0_device;
  696. else
  697. pdev = &ath79_eth1_device;
  698. pdata = pdev->dev.platform_data;
  699. pdata->max_frame_len = 1540;
  700. pdata->desc_pktlen_mask = 0xfff;
  701. err = ath79_setup_phy_if_mode(id, pdata);
  702. if (err) {
  703. printk(KERN_ERR
  704. "ar71xx: invalid PHY interface mode for GE%u\n", id);
  705. return;
  706. }
  707. switch (ath79_soc) {
  708. case ATH79_SOC_AR7130:
  709. if (id == 0) {
  710. pdata->ddr_flush = ath79_ddr_flush_ge0;
  711. pdata->set_speed = ath79_set_speed_ge0;
  712. } else {
  713. pdata->ddr_flush = ath79_ddr_flush_ge1;
  714. pdata->set_speed = ath79_set_speed_ge1;
  715. }
  716. break;
  717. case ATH79_SOC_AR7141:
  718. case ATH79_SOC_AR7161:
  719. if (id == 0) {
  720. pdata->ddr_flush = ath79_ddr_flush_ge0;
  721. pdata->set_speed = ath79_set_speed_ge0;
  722. } else {
  723. pdata->ddr_flush = ath79_ddr_flush_ge1;
  724. pdata->set_speed = ath79_set_speed_ge1;
  725. }
  726. pdata->has_gbit = 1;
  727. break;
  728. case ATH79_SOC_AR7242:
  729. if (id == 0) {
  730. pdata->reset_bit |= AR724X_RESET_GE0_MDIO |
  731. AR71XX_RESET_GE0_PHY;
  732. pdata->ddr_flush = ar724x_ddr_flush_ge0;
  733. pdata->set_speed = ar7242_set_speed_ge0;
  734. } else {
  735. pdata->reset_bit |= AR724X_RESET_GE1_MDIO |
  736. AR71XX_RESET_GE1_PHY;
  737. pdata->ddr_flush = ar724x_ddr_flush_ge1;
  738. pdata->set_speed = ath79_set_speed_dummy;
  739. }
  740. pdata->has_gbit = 1;
  741. pdata->is_ar724x = 1;
  742. if (!pdata->fifo_cfg1)
  743. pdata->fifo_cfg1 = 0x0010ffff;
  744. if (!pdata->fifo_cfg2)
  745. pdata->fifo_cfg2 = 0x015500aa;
  746. if (!pdata->fifo_cfg3)
  747. pdata->fifo_cfg3 = 0x01f00140;
  748. break;
  749. case ATH79_SOC_AR7241:
  750. if (id == 0)
  751. pdata->reset_bit |= AR724X_RESET_GE0_MDIO;
  752. else
  753. pdata->reset_bit |= AR724X_RESET_GE1_MDIO;
  754. /* fall through */
  755. case ATH79_SOC_AR7240:
  756. if (id == 0) {
  757. pdata->reset_bit |= AR71XX_RESET_GE0_PHY;
  758. pdata->ddr_flush = ar724x_ddr_flush_ge0;
  759. pdata->set_speed = ath79_set_speed_dummy;
  760. pdata->phy_mask = BIT(4);
  761. } else {
  762. pdata->reset_bit |= AR71XX_RESET_GE1_PHY;
  763. pdata->ddr_flush = ar724x_ddr_flush_ge1;
  764. pdata->set_speed = ath79_set_speed_dummy;
  765. pdata->speed = SPEED_1000;
  766. pdata->duplex = DUPLEX_FULL;
  767. pdata->switch_data = &ath79_switch_data;
  768. ath79_switch_data.phy_poll_mask |= BIT(4);
  769. }
  770. pdata->has_gbit = 1;
  771. pdata->is_ar724x = 1;
  772. if (ath79_soc == ATH79_SOC_AR7240)
  773. pdata->is_ar7240 = 1;
  774. if (!pdata->fifo_cfg1)
  775. pdata->fifo_cfg1 = 0x0010ffff;
  776. if (!pdata->fifo_cfg2)
  777. pdata->fifo_cfg2 = 0x015500aa;
  778. if (!pdata->fifo_cfg3)
  779. pdata->fifo_cfg3 = 0x01f00140;
  780. break;
  781. case ATH79_SOC_AR9130:
  782. if (id == 0) {
  783. pdata->ddr_flush = ar91xx_ddr_flush_ge0;
  784. pdata->set_speed = ar91xx_set_speed_ge0;
  785. } else {
  786. pdata->ddr_flush = ar91xx_ddr_flush_ge1;
  787. pdata->set_speed = ar91xx_set_speed_ge1;
  788. }
  789. pdata->is_ar91xx = 1;
  790. break;
  791. case ATH79_SOC_AR9132:
  792. if (id == 0) {
  793. pdata->ddr_flush = ar91xx_ddr_flush_ge0;
  794. pdata->set_speed = ar91xx_set_speed_ge0;
  795. } else {
  796. pdata->ddr_flush = ar91xx_ddr_flush_ge1;
  797. pdata->set_speed = ar91xx_set_speed_ge1;
  798. }
  799. pdata->is_ar91xx = 1;
  800. pdata->has_gbit = 1;
  801. break;
  802. case ATH79_SOC_AR9330:
  803. case ATH79_SOC_AR9331:
  804. if (id == 0) {
  805. pdata->reset_bit = AR933X_RESET_GE0_MAC |
  806. AR933X_RESET_GE0_MDIO;
  807. pdata->ddr_flush = ar933x_ddr_flush_ge0;
  808. pdata->set_speed = ath79_set_speed_dummy;
  809. pdata->phy_mask = BIT(4);
  810. } else {
  811. pdata->reset_bit = AR933X_RESET_GE1_MAC |
  812. AR933X_RESET_GE1_MDIO;
  813. pdata->ddr_flush = ar933x_ddr_flush_ge1;
  814. pdata->set_speed = ath79_set_speed_dummy;
  815. pdata->speed = SPEED_1000;
  816. pdata->has_gbit = 1;
  817. pdata->duplex = DUPLEX_FULL;
  818. pdata->switch_data = &ath79_switch_data;
  819. ath79_switch_data.phy_poll_mask |= BIT(4);
  820. }
  821. pdata->is_ar724x = 1;
  822. if (!pdata->fifo_cfg1)
  823. pdata->fifo_cfg1 = 0x0010ffff;
  824. if (!pdata->fifo_cfg2)
  825. pdata->fifo_cfg2 = 0x015500aa;
  826. if (!pdata->fifo_cfg3)
  827. pdata->fifo_cfg3 = 0x01f00140;
  828. break;
  829. case ATH79_SOC_AR9341:
  830. case ATH79_SOC_AR9342:
  831. case ATH79_SOC_AR9344:
  832. case ATH79_SOC_QCA9533:
  833. if (id == 0) {
  834. pdata->reset_bit = AR934X_RESET_GE0_MAC |
  835. AR934X_RESET_GE0_MDIO;
  836. pdata->set_speed = ar934x_set_speed_ge0;
  837. } else {
  838. pdata->reset_bit = AR934X_RESET_GE1_MAC |
  839. AR934X_RESET_GE1_MDIO;
  840. pdata->set_speed = ath79_set_speed_dummy;
  841. pdata->switch_data = &ath79_switch_data;
  842. /* reset the built-in switch */
  843. ath79_device_reset_set(AR934X_RESET_ETH_SWITCH);
  844. ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH);
  845. }
  846. pdata->ddr_flush = ath79_ddr_no_flush;
  847. pdata->has_gbit = 1;
  848. pdata->is_ar724x = 1;
  849. pdata->max_frame_len = SZ_16K - 1;
  850. pdata->desc_pktlen_mask = SZ_16K - 1;
  851. if (!pdata->fifo_cfg1)
  852. pdata->fifo_cfg1 = 0x0010ffff;
  853. if (!pdata->fifo_cfg2)
  854. pdata->fifo_cfg2 = 0x015500aa;
  855. if (!pdata->fifo_cfg3)
  856. pdata->fifo_cfg3 = 0x01f00140;
  857. break;
  858. case ATH79_SOC_QCA9561:
  859. case ATH79_SOC_TP9343:
  860. if (id == 0) {
  861. pdata->reset_bit = AR933X_RESET_GE0_MAC |
  862. AR933X_RESET_GE0_MDIO;
  863. pdata->set_speed = ath79_set_speed_dummy;
  864. pdata->phy_mask = BIT(4);
  865. } else {
  866. pdata->reset_bit = AR933X_RESET_GE1_MAC |
  867. AR933X_RESET_GE1_MDIO;
  868. pdata->set_speed = ath79_set_speed_dummy;
  869. pdata->speed = SPEED_1000;
  870. pdata->duplex = DUPLEX_FULL;
  871. pdata->switch_data = &ath79_switch_data;
  872. ath79_switch_data.phy_poll_mask |= BIT(4);
  873. }
  874. pdata->ddr_flush = ath79_ddr_no_flush;
  875. pdata->has_gbit = 1;
  876. pdata->is_ar724x = 1;
  877. if (!pdata->fifo_cfg1)
  878. pdata->fifo_cfg1 = 0x0010ffff;
  879. if (!pdata->fifo_cfg2)
  880. pdata->fifo_cfg2 = 0x015500aa;
  881. if (!pdata->fifo_cfg3)
  882. pdata->fifo_cfg3 = 0x01f00140;
  883. break;
  884. case ATH79_SOC_QCA9556:
  885. case ATH79_SOC_QCA9558:
  886. if (id == 0) {
  887. pdata->reset_bit = QCA955X_RESET_GE0_MAC |
  888. QCA955X_RESET_GE0_MDIO;
  889. pdata->set_speed = qca955x_set_speed_xmii;
  890. } else {
  891. pdata->reset_bit = QCA955X_RESET_GE1_MAC |
  892. QCA955X_RESET_GE1_MDIO;
  893. pdata->set_speed = qca955x_set_speed_sgmii;
  894. }
  895. pdata->ddr_flush = ath79_ddr_no_flush;
  896. pdata->has_gbit = 1;
  897. pdata->is_ar724x = 1;
  898. /*
  899. * Limit the maximum frame length to 4095 bytes.
  900. * Although the documentation says that the hardware
  901. * limit is 16383 bytes but that does not work in
  902. * practice. It seems that the hardware only updates
  903. * the lowest 12 bits of the packet length field
  904. * in the RX descriptor.
  905. */
  906. pdata->max_frame_len = SZ_4K - 1;
  907. pdata->desc_pktlen_mask = SZ_16K - 1;
  908. if (!pdata->fifo_cfg1)
  909. pdata->fifo_cfg1 = 0x0010ffff;
  910. if (!pdata->fifo_cfg2)
  911. pdata->fifo_cfg2 = 0x015500aa;
  912. if (!pdata->fifo_cfg3)
  913. pdata->fifo_cfg3 = 0x01f00140;
  914. break;
  915. default:
  916. BUG();
  917. }
  918. switch (pdata->phy_if_mode) {
  919. case PHY_INTERFACE_MODE_GMII:
  920. case PHY_INTERFACE_MODE_RGMII:
  921. case PHY_INTERFACE_MODE_SGMII:
  922. if (!pdata->has_gbit) {
  923. printk(KERN_ERR "ar71xx: no gbit available on eth%d\n",
  924. id);
  925. return;
  926. }
  927. /* fallthrough */
  928. default:
  929. break;
  930. }
  931. if (!is_valid_ether_addr(pdata->mac_addr)) {
  932. random_ether_addr(pdata->mac_addr);
  933. printk(KERN_DEBUG
  934. "ar71xx: using random MAC address for eth%d\n",
  935. ath79_eth_instance);
  936. }
  937. if (pdata->mii_bus_dev == NULL) {
  938. switch (ath79_soc) {
  939. case ATH79_SOC_AR9341:
  940. case ATH79_SOC_AR9342:
  941. case ATH79_SOC_AR9344:
  942. if (id == 0)
  943. pdata->mii_bus_dev = &ath79_mdio0_device.dev;
  944. else
  945. pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  946. break;
  947. case ATH79_SOC_AR7241:
  948. case ATH79_SOC_AR9330:
  949. case ATH79_SOC_AR9331:
  950. case ATH79_SOC_QCA9533:
  951. case ATH79_SOC_QCA9561:
  952. case ATH79_SOC_TP9343:
  953. pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  954. break;
  955. case ATH79_SOC_QCA9556:
  956. case ATH79_SOC_QCA9558:
  957. /* don't assign any MDIO device by default */
  958. break;
  959. default:
  960. pdata->mii_bus_dev = &ath79_mdio0_device.dev;
  961. break;
  962. }
  963. }
  964. /* Reset the device */
  965. ath79_device_reset_set(pdata->reset_bit);
  966. msleep(100);
  967. ath79_device_reset_clear(pdata->reset_bit);
  968. msleep(100);
  969. platform_device_register(pdev);
  970. ath79_eth_instance++;
  971. }
  972. void __init ath79_set_mac_base(unsigned char *mac)
  973. {
  974. memcpy(ath79_mac_base, mac, ETH_ALEN);
  975. }
  976. void __init ath79_parse_ascii_mac(char *mac_str, u8 *mac)
  977. {
  978. int t;
  979. t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  980. &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  981. if (t != ETH_ALEN)
  982. t = sscanf(mac_str, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
  983. &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  984. if (t != ETH_ALEN || !is_valid_ether_addr(mac)) {
  985. memset(mac, 0, ETH_ALEN);
  986. printk(KERN_DEBUG "ar71xx: invalid mac address \"%s\"\n",
  987. mac_str);
  988. }
  989. }
  990. static void __init ath79_set_mac_base_ascii(char *str)
  991. {
  992. u8 mac[ETH_ALEN];
  993. ath79_parse_ascii_mac(str, mac);
  994. ath79_set_mac_base(mac);
  995. }
  996. static int __init ath79_ethaddr_setup(char *str)
  997. {
  998. ath79_set_mac_base_ascii(str);
  999. return 1;
  1000. }
  1001. __setup("ethaddr=", ath79_ethaddr_setup);
  1002. static int __init ath79_kmac_setup(char *str)
  1003. {
  1004. ath79_set_mac_base_ascii(str);
  1005. return 1;
  1006. }
  1007. __setup("kmac=", ath79_kmac_setup);
  1008. void __init ath79_init_mac(unsigned char *dst, const unsigned char *src,
  1009. int offset)
  1010. {
  1011. int t;
  1012. if (!dst)
  1013. return;
  1014. if (!src || !is_valid_ether_addr(src)) {
  1015. memset(dst, '\0', ETH_ALEN);
  1016. return;
  1017. }
  1018. t = (((u32) src[3]) << 16) + (((u32) src[4]) << 8) + ((u32) src[5]);
  1019. t += offset;
  1020. dst[0] = src[0];
  1021. dst[1] = src[1];
  1022. dst[2] = src[2];
  1023. dst[3] = (t >> 16) & 0xff;
  1024. dst[4] = (t >> 8) & 0xff;
  1025. dst[5] = t & 0xff;
  1026. }
  1027. void __init ath79_init_local_mac(unsigned char *dst, const unsigned char *src)
  1028. {
  1029. int i;
  1030. if (!dst)
  1031. return;
  1032. if (!src || !is_valid_ether_addr(src)) {
  1033. memset(dst, '\0', ETH_ALEN);
  1034. return;
  1035. }
  1036. for (i = 0; i < ETH_ALEN; i++)
  1037. dst[i] = src[i];
  1038. dst[0] |= 0x02;
  1039. }