dev-eth.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. ath79_soc == ATH79_SOC_QCA956X)
  153. max_id = 1;
  154. else
  155. max_id = 0;
  156. if (id > max_id) {
  157. printk(KERN_ERR "ar71xx: invalid MDIO id %u\n", id);
  158. return;
  159. }
  160. switch (ath79_soc) {
  161. case ATH79_SOC_AR7241:
  162. case ATH79_SOC_AR9330:
  163. case ATH79_SOC_AR9331:
  164. case ATH79_SOC_QCA9533:
  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. case ATH79_SOC_QCA956X:
  175. if (id == 0) {
  176. mdio_dev = &ath79_mdio0_device;
  177. mdio_data = &ath79_mdio0_data;
  178. } else {
  179. mdio_dev = &ath79_mdio1_device;
  180. mdio_data = &ath79_mdio1_data;
  181. }
  182. break;
  183. case ATH79_SOC_AR7242:
  184. ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG,
  185. AR7242_PLL_REG_ETH0_INT_CLOCK, 0x62000000,
  186. AR71XX_ETH0_PLL_SHIFT);
  187. /* fall through */
  188. default:
  189. mdio_dev = &ath79_mdio0_device;
  190. mdio_data = &ath79_mdio0_data;
  191. break;
  192. }
  193. mdio_data->phy_mask = phy_mask;
  194. switch (ath79_soc) {
  195. case ATH79_SOC_AR7240:
  196. mdio_data->is_ar7240 = 1;
  197. /* fall through */
  198. case ATH79_SOC_AR7241:
  199. mdio_data->builtin_switch = 1;
  200. break;
  201. case ATH79_SOC_AR9330:
  202. mdio_data->is_ar9330 = 1;
  203. /* fall through */
  204. case ATH79_SOC_AR9331:
  205. mdio_data->builtin_switch = 1;
  206. break;
  207. case ATH79_SOC_AR9341:
  208. case ATH79_SOC_AR9342:
  209. case ATH79_SOC_AR9344:
  210. if (id == 1) {
  211. mdio_data->builtin_switch = 1;
  212. mdio_data->ref_clock = ar934x_get_mdio_ref_clock();
  213. mdio_data->mdio_clock = 6250000;
  214. }
  215. mdio_data->is_ar934x = 1;
  216. break;
  217. case ATH79_SOC_QCA9533:
  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. case ATH79_SOC_QCA956X:
  226. if (id == 1)
  227. mdio_data->builtin_switch = 1;
  228. mdio_data->is_ar934x = 1;
  229. break;
  230. default:
  231. break;
  232. }
  233. platform_device_register(mdio_dev);
  234. }
  235. struct ath79_eth_pll_data ath79_eth0_pll_data;
  236. struct ath79_eth_pll_data ath79_eth1_pll_data;
  237. static u32 ath79_get_eth_pll(unsigned int mac, int speed)
  238. {
  239. struct ath79_eth_pll_data *pll_data;
  240. u32 pll_val;
  241. switch (mac) {
  242. case 0:
  243. pll_data = &ath79_eth0_pll_data;
  244. break;
  245. case 1:
  246. pll_data = &ath79_eth1_pll_data;
  247. break;
  248. default:
  249. BUG();
  250. }
  251. switch (speed) {
  252. case SPEED_10:
  253. pll_val = pll_data->pll_10;
  254. break;
  255. case SPEED_100:
  256. pll_val = pll_data->pll_100;
  257. break;
  258. case SPEED_1000:
  259. pll_val = pll_data->pll_1000;
  260. break;
  261. default:
  262. BUG();
  263. }
  264. return pll_val;
  265. }
  266. static void ath79_set_speed_ge0(int speed)
  267. {
  268. u32 val = ath79_get_eth_pll(0, speed);
  269. ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH0_INT_CLOCK,
  270. val, AR71XX_ETH0_PLL_SHIFT);
  271. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL, speed);
  272. }
  273. static void ath79_set_speed_ge1(int speed)
  274. {
  275. u32 val = ath79_get_eth_pll(1, speed);
  276. ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH1_INT_CLOCK,
  277. val, AR71XX_ETH1_PLL_SHIFT);
  278. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL, speed);
  279. }
  280. static void ar7242_set_speed_ge0(int speed)
  281. {
  282. u32 val = ath79_get_eth_pll(0, speed);
  283. void __iomem *base;
  284. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  285. __raw_writel(val, base + AR7242_PLL_REG_ETH0_INT_CLOCK);
  286. iounmap(base);
  287. }
  288. static void ar91xx_set_speed_ge0(int speed)
  289. {
  290. u32 val = ath79_get_eth_pll(0, speed);
  291. ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG, AR913X_PLL_REG_ETH0_INT_CLOCK,
  292. val, AR913X_ETH0_PLL_SHIFT);
  293. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL, speed);
  294. }
  295. static void ar91xx_set_speed_ge1(int speed)
  296. {
  297. u32 val = ath79_get_eth_pll(1, speed);
  298. ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG, AR913X_PLL_REG_ETH1_INT_CLOCK,
  299. val, AR913X_ETH1_PLL_SHIFT);
  300. ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL, speed);
  301. }
  302. static void ar934x_set_speed_ge0(int speed)
  303. {
  304. void __iomem *base;
  305. u32 val = ath79_get_eth_pll(0, speed);
  306. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  307. __raw_writel(val, base + AR934X_PLL_ETH_XMII_CONTROL_REG);
  308. iounmap(base);
  309. }
  310. static void qca955x_set_speed_xmii(int speed)
  311. {
  312. void __iomem *base;
  313. u32 val = ath79_get_eth_pll(0, speed);
  314. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  315. __raw_writel(val, base + QCA955X_PLL_ETH_XMII_CONTROL_REG);
  316. iounmap(base);
  317. }
  318. static void qca955x_set_speed_sgmii(int speed)
  319. {
  320. void __iomem *base;
  321. u32 val = ath79_get_eth_pll(1, speed);
  322. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  323. __raw_writel(val, base + QCA955X_PLL_ETH_SGMII_CONTROL_REG);
  324. iounmap(base);
  325. }
  326. static void qca956x_set_speed_sgmii(int speed)
  327. {
  328. void __iomem *base;
  329. u32 val = ath79_get_eth_pll(0, speed);
  330. base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  331. __raw_writel(val, base + QCA955X_PLL_ETH_SGMII_CONTROL_REG);
  332. iounmap(base);
  333. }
  334. static void ath79_set_speed_dummy(int speed)
  335. {
  336. }
  337. static void ath79_ddr_no_flush(void)
  338. {
  339. }
  340. static void ath79_ddr_flush_ge0(void)
  341. {
  342. ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_GE0);
  343. }
  344. static void ath79_ddr_flush_ge1(void)
  345. {
  346. ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_GE1);
  347. }
  348. static void ar724x_ddr_flush_ge0(void)
  349. {
  350. ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_GE0);
  351. }
  352. static void ar724x_ddr_flush_ge1(void)
  353. {
  354. ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_GE1);
  355. }
  356. static void ar91xx_ddr_flush_ge0(void)
  357. {
  358. ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_GE0);
  359. }
  360. static void ar91xx_ddr_flush_ge1(void)
  361. {
  362. ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_GE1);
  363. }
  364. static void ar933x_ddr_flush_ge0(void)
  365. {
  366. ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_GE0);
  367. }
  368. static void ar933x_ddr_flush_ge1(void)
  369. {
  370. ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_GE1);
  371. }
  372. static struct resource ath79_eth0_resources[] = {
  373. {
  374. .name = "mac_base",
  375. .flags = IORESOURCE_MEM,
  376. .start = AR71XX_GE0_BASE,
  377. .end = AR71XX_GE0_BASE + 0x200 - 1,
  378. }, {
  379. .name = "mac_irq",
  380. .flags = IORESOURCE_IRQ,
  381. .start = ATH79_CPU_IRQ(4),
  382. .end = ATH79_CPU_IRQ(4),
  383. },
  384. };
  385. struct ag71xx_platform_data ath79_eth0_data = {
  386. .reset_bit = AR71XX_RESET_GE0_MAC,
  387. };
  388. struct platform_device ath79_eth0_device = {
  389. .name = "ag71xx",
  390. .id = 0,
  391. .resource = ath79_eth0_resources,
  392. .num_resources = ARRAY_SIZE(ath79_eth0_resources),
  393. .dev = {
  394. .platform_data = &ath79_eth0_data,
  395. },
  396. };
  397. static struct resource ath79_eth1_resources[] = {
  398. {
  399. .name = "mac_base",
  400. .flags = IORESOURCE_MEM,
  401. .start = AR71XX_GE1_BASE,
  402. .end = AR71XX_GE1_BASE + 0x200 - 1,
  403. }, {
  404. .name = "mac_irq",
  405. .flags = IORESOURCE_IRQ,
  406. .start = ATH79_CPU_IRQ(5),
  407. .end = ATH79_CPU_IRQ(5),
  408. },
  409. };
  410. struct ag71xx_platform_data ath79_eth1_data = {
  411. .reset_bit = AR71XX_RESET_GE1_MAC,
  412. };
  413. struct platform_device ath79_eth1_device = {
  414. .name = "ag71xx",
  415. .id = 1,
  416. .resource = ath79_eth1_resources,
  417. .num_resources = ARRAY_SIZE(ath79_eth1_resources),
  418. .dev = {
  419. .platform_data = &ath79_eth1_data,
  420. },
  421. };
  422. struct ag71xx_switch_platform_data ath79_switch_data;
  423. #define AR71XX_PLL_VAL_1000 0x00110000
  424. #define AR71XX_PLL_VAL_100 0x00001099
  425. #define AR71XX_PLL_VAL_10 0x00991099
  426. #define AR724X_PLL_VAL_1000 0x00110000
  427. #define AR724X_PLL_VAL_100 0x00001099
  428. #define AR724X_PLL_VAL_10 0x00991099
  429. #define AR7242_PLL_VAL_1000 0x16000000
  430. #define AR7242_PLL_VAL_100 0x00000101
  431. #define AR7242_PLL_VAL_10 0x00001616
  432. #define AR913X_PLL_VAL_1000 0x1a000000
  433. #define AR913X_PLL_VAL_100 0x13000a44
  434. #define AR913X_PLL_VAL_10 0x00441099
  435. #define AR933X_PLL_VAL_1000 0x00110000
  436. #define AR933X_PLL_VAL_100 0x00001099
  437. #define AR933X_PLL_VAL_10 0x00991099
  438. #define AR934X_PLL_VAL_1000 0x16000000
  439. #define AR934X_PLL_VAL_100 0x00000101
  440. #define AR934X_PLL_VAL_10 0x00001616
  441. #define QCA956X_PLL_VAL_1000 0x03000000
  442. #define QCA956X_PLL_VAL_100 0x00000101
  443. #define QCA956X_PLL_VAL_10 0x00001919
  444. static void __init ath79_init_eth_pll_data(unsigned int id)
  445. {
  446. struct ath79_eth_pll_data *pll_data;
  447. u32 pll_10, pll_100, pll_1000;
  448. switch (id) {
  449. case 0:
  450. pll_data = &ath79_eth0_pll_data;
  451. break;
  452. case 1:
  453. pll_data = &ath79_eth1_pll_data;
  454. break;
  455. default:
  456. BUG();
  457. }
  458. switch (ath79_soc) {
  459. case ATH79_SOC_AR7130:
  460. case ATH79_SOC_AR7141:
  461. case ATH79_SOC_AR7161:
  462. pll_10 = AR71XX_PLL_VAL_10;
  463. pll_100 = AR71XX_PLL_VAL_100;
  464. pll_1000 = AR71XX_PLL_VAL_1000;
  465. break;
  466. case ATH79_SOC_AR7240:
  467. case ATH79_SOC_AR7241:
  468. pll_10 = AR724X_PLL_VAL_10;
  469. pll_100 = AR724X_PLL_VAL_100;
  470. pll_1000 = AR724X_PLL_VAL_1000;
  471. break;
  472. case ATH79_SOC_AR7242:
  473. pll_10 = AR7242_PLL_VAL_10;
  474. pll_100 = AR7242_PLL_VAL_100;
  475. pll_1000 = AR7242_PLL_VAL_1000;
  476. break;
  477. case ATH79_SOC_AR9130:
  478. case ATH79_SOC_AR9132:
  479. pll_10 = AR913X_PLL_VAL_10;
  480. pll_100 = AR913X_PLL_VAL_100;
  481. pll_1000 = AR913X_PLL_VAL_1000;
  482. break;
  483. case ATH79_SOC_AR9330:
  484. case ATH79_SOC_AR9331:
  485. pll_10 = AR933X_PLL_VAL_10;
  486. pll_100 = AR933X_PLL_VAL_100;
  487. pll_1000 = AR933X_PLL_VAL_1000;
  488. break;
  489. case ATH79_SOC_AR9341:
  490. case ATH79_SOC_AR9342:
  491. case ATH79_SOC_AR9344:
  492. case ATH79_SOC_QCA9533:
  493. case ATH79_SOC_QCA9556:
  494. case ATH79_SOC_QCA9558:
  495. case ATH79_SOC_TP9343:
  496. pll_10 = AR934X_PLL_VAL_10;
  497. pll_100 = AR934X_PLL_VAL_100;
  498. pll_1000 = AR934X_PLL_VAL_1000;
  499. break;
  500. case ATH79_SOC_QCA956X:
  501. pll_10 = QCA956X_PLL_VAL_10;
  502. pll_100 = QCA956X_PLL_VAL_100;
  503. pll_1000 = QCA956X_PLL_VAL_1000;
  504. break;
  505. default:
  506. BUG();
  507. }
  508. if (!pll_data->pll_10)
  509. pll_data->pll_10 = pll_10;
  510. if (!pll_data->pll_100)
  511. pll_data->pll_100 = pll_100;
  512. if (!pll_data->pll_1000)
  513. pll_data->pll_1000 = pll_1000;
  514. }
  515. static int __init ath79_setup_phy_if_mode(unsigned int id,
  516. struct ag71xx_platform_data *pdata)
  517. {
  518. unsigned int mii_if;
  519. switch (id) {
  520. case 0:
  521. switch (ath79_soc) {
  522. case ATH79_SOC_AR7130:
  523. case ATH79_SOC_AR7141:
  524. case ATH79_SOC_AR7161:
  525. case ATH79_SOC_AR9130:
  526. case ATH79_SOC_AR9132:
  527. switch (pdata->phy_if_mode) {
  528. case PHY_INTERFACE_MODE_MII:
  529. mii_if = AR71XX_MII0_CTRL_IF_MII;
  530. break;
  531. case PHY_INTERFACE_MODE_GMII:
  532. mii_if = AR71XX_MII0_CTRL_IF_GMII;
  533. break;
  534. case PHY_INTERFACE_MODE_RGMII:
  535. mii_if = AR71XX_MII0_CTRL_IF_RGMII;
  536. break;
  537. case PHY_INTERFACE_MODE_RMII:
  538. mii_if = AR71XX_MII0_CTRL_IF_RMII;
  539. break;
  540. default:
  541. return -EINVAL;
  542. }
  543. ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII0_CTRL, mii_if);
  544. break;
  545. case ATH79_SOC_AR7240:
  546. case ATH79_SOC_AR7241:
  547. case ATH79_SOC_AR9330:
  548. case ATH79_SOC_AR9331:
  549. case ATH79_SOC_QCA9533:
  550. case ATH79_SOC_TP9343:
  551. pdata->phy_if_mode = PHY_INTERFACE_MODE_MII;
  552. break;
  553. case ATH79_SOC_AR7242:
  554. /* FIXME */
  555. case ATH79_SOC_AR9341:
  556. case ATH79_SOC_AR9342:
  557. case ATH79_SOC_AR9344:
  558. switch (pdata->phy_if_mode) {
  559. case PHY_INTERFACE_MODE_MII:
  560. case PHY_INTERFACE_MODE_GMII:
  561. case PHY_INTERFACE_MODE_RGMII:
  562. case PHY_INTERFACE_MODE_RMII:
  563. break;
  564. default:
  565. return -EINVAL;
  566. }
  567. break;
  568. case ATH79_SOC_QCA9556:
  569. case ATH79_SOC_QCA9558:
  570. case ATH79_SOC_QCA956X:
  571. switch (pdata->phy_if_mode) {
  572. case PHY_INTERFACE_MODE_MII:
  573. case PHY_INTERFACE_MODE_RGMII:
  574. case PHY_INTERFACE_MODE_SGMII:
  575. break;
  576. default:
  577. return -EINVAL;
  578. }
  579. break;
  580. default:
  581. BUG();
  582. }
  583. break;
  584. case 1:
  585. switch (ath79_soc) {
  586. case ATH79_SOC_AR7130:
  587. case ATH79_SOC_AR7141:
  588. case ATH79_SOC_AR7161:
  589. case ATH79_SOC_AR9130:
  590. case ATH79_SOC_AR9132:
  591. switch (pdata->phy_if_mode) {
  592. case PHY_INTERFACE_MODE_RMII:
  593. mii_if = AR71XX_MII1_CTRL_IF_RMII;
  594. break;
  595. case PHY_INTERFACE_MODE_RGMII:
  596. mii_if = AR71XX_MII1_CTRL_IF_RGMII;
  597. break;
  598. default:
  599. return -EINVAL;
  600. }
  601. ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII1_CTRL, mii_if);
  602. break;
  603. case ATH79_SOC_AR7240:
  604. case ATH79_SOC_AR7241:
  605. case ATH79_SOC_AR9330:
  606. case ATH79_SOC_AR9331:
  607. case ATH79_SOC_QCA956X:
  608. case ATH79_SOC_TP9343:
  609. pdata->phy_if_mode = PHY_INTERFACE_MODE_GMII;
  610. break;
  611. case ATH79_SOC_AR7242:
  612. /* FIXME */
  613. case ATH79_SOC_AR9341:
  614. case ATH79_SOC_AR9342:
  615. case ATH79_SOC_AR9344:
  616. case ATH79_SOC_QCA9533:
  617. switch (pdata->phy_if_mode) {
  618. case PHY_INTERFACE_MODE_MII:
  619. case PHY_INTERFACE_MODE_GMII:
  620. break;
  621. default:
  622. return -EINVAL;
  623. }
  624. break;
  625. case ATH79_SOC_QCA9556:
  626. case ATH79_SOC_QCA9558:
  627. switch (pdata->phy_if_mode) {
  628. case PHY_INTERFACE_MODE_MII:
  629. case PHY_INTERFACE_MODE_RGMII:
  630. case PHY_INTERFACE_MODE_SGMII:
  631. break;
  632. default:
  633. return -EINVAL;
  634. }
  635. break;
  636. default:
  637. BUG();
  638. }
  639. break;
  640. }
  641. return 0;
  642. }
  643. void __init ath79_setup_ar933x_phy4_switch(bool mac, bool mdio)
  644. {
  645. void __iomem *base;
  646. u32 t;
  647. base = ioremap(AR933X_GMAC_BASE, AR933X_GMAC_SIZE);
  648. t = __raw_readl(base + AR933X_GMAC_REG_ETH_CFG);
  649. t &= ~(AR933X_ETH_CFG_SW_PHY_SWAP | AR933X_ETH_CFG_SW_PHY_ADDR_SWAP);
  650. if (mac)
  651. t |= AR933X_ETH_CFG_SW_PHY_SWAP;
  652. if (mdio)
  653. t |= AR933X_ETH_CFG_SW_PHY_ADDR_SWAP;
  654. __raw_writel(t, base + AR933X_GMAC_REG_ETH_CFG);
  655. iounmap(base);
  656. }
  657. void __init ath79_setup_ar934x_eth_cfg(u32 mask)
  658. {
  659. void __iomem *base;
  660. u32 t;
  661. base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE);
  662. t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  663. t &= ~(AR934X_ETH_CFG_RGMII_GMAC0 |
  664. AR934X_ETH_CFG_MII_GMAC0 |
  665. AR934X_ETH_CFG_GMII_GMAC0 |
  666. AR934X_ETH_CFG_SW_ONLY_MODE |
  667. AR934X_ETH_CFG_SW_PHY_SWAP);
  668. t |= mask;
  669. __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG);
  670. /* flush write */
  671. __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  672. iounmap(base);
  673. }
  674. void __init ath79_setup_ar934x_eth_rx_delay(unsigned int rxd,
  675. unsigned int rxdv)
  676. {
  677. void __iomem *base;
  678. u32 t;
  679. rxd &= AR934X_ETH_CFG_RXD_DELAY_MASK;
  680. rxdv &= AR934X_ETH_CFG_RDV_DELAY_MASK;
  681. base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE);
  682. t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  683. t &= ~(AR934X_ETH_CFG_RXD_DELAY_MASK << AR934X_ETH_CFG_RXD_DELAY_SHIFT |
  684. AR934X_ETH_CFG_RDV_DELAY_MASK << AR934X_ETH_CFG_RDV_DELAY_SHIFT);
  685. t |= (rxd << AR934X_ETH_CFG_RXD_DELAY_SHIFT |
  686. rxdv << AR934X_ETH_CFG_RDV_DELAY_SHIFT);
  687. __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG);
  688. /* flush write */
  689. __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  690. iounmap(base);
  691. }
  692. void __init ath79_setup_qca955x_eth_cfg(u32 mask)
  693. {
  694. void __iomem *base;
  695. u32 t;
  696. base = ioremap(QCA955X_GMAC_BASE, QCA955X_GMAC_SIZE);
  697. t = __raw_readl(base + QCA955X_GMAC_REG_ETH_CFG);
  698. t &= ~(QCA955X_ETH_CFG_RGMII_EN | QCA955X_ETH_CFG_GE0_SGMII);
  699. t |= mask;
  700. __raw_writel(t, base + QCA955X_GMAC_REG_ETH_CFG);
  701. iounmap(base);
  702. }
  703. static int ath79_eth_instance __initdata;
  704. void __init ath79_register_eth(unsigned int id)
  705. {
  706. struct platform_device *pdev;
  707. struct ag71xx_platform_data *pdata;
  708. int err;
  709. if (id > 1) {
  710. printk(KERN_ERR "ar71xx: invalid ethernet id %d\n", id);
  711. return;
  712. }
  713. ath79_init_eth_pll_data(id);
  714. if (id == 0)
  715. pdev = &ath79_eth0_device;
  716. else
  717. pdev = &ath79_eth1_device;
  718. pdata = pdev->dev.platform_data;
  719. pdata->max_frame_len = 1540;
  720. pdata->desc_pktlen_mask = 0xfff;
  721. err = ath79_setup_phy_if_mode(id, pdata);
  722. if (err) {
  723. printk(KERN_ERR
  724. "ar71xx: invalid PHY interface mode for GE%u\n", id);
  725. return;
  726. }
  727. switch (ath79_soc) {
  728. case ATH79_SOC_AR7130:
  729. if (id == 0) {
  730. pdata->ddr_flush = ath79_ddr_flush_ge0;
  731. pdata->set_speed = ath79_set_speed_ge0;
  732. } else {
  733. pdata->ddr_flush = ath79_ddr_flush_ge1;
  734. pdata->set_speed = ath79_set_speed_ge1;
  735. }
  736. break;
  737. case ATH79_SOC_AR7141:
  738. case ATH79_SOC_AR7161:
  739. if (id == 0) {
  740. pdata->ddr_flush = ath79_ddr_flush_ge0;
  741. pdata->set_speed = ath79_set_speed_ge0;
  742. } else {
  743. pdata->ddr_flush = ath79_ddr_flush_ge1;
  744. pdata->set_speed = ath79_set_speed_ge1;
  745. }
  746. pdata->has_gbit = 1;
  747. break;
  748. case ATH79_SOC_AR7242:
  749. if (id == 0) {
  750. pdata->reset_bit |= AR724X_RESET_GE0_MDIO |
  751. AR71XX_RESET_GE0_PHY;
  752. pdata->ddr_flush = ar724x_ddr_flush_ge0;
  753. pdata->set_speed = ar7242_set_speed_ge0;
  754. } else {
  755. pdata->reset_bit |= AR724X_RESET_GE1_MDIO |
  756. AR71XX_RESET_GE1_PHY;
  757. pdata->ddr_flush = ar724x_ddr_flush_ge1;
  758. pdata->set_speed = ath79_set_speed_dummy;
  759. }
  760. pdata->has_gbit = 1;
  761. pdata->is_ar724x = 1;
  762. if (!pdata->fifo_cfg1)
  763. pdata->fifo_cfg1 = 0x0010ffff;
  764. if (!pdata->fifo_cfg2)
  765. pdata->fifo_cfg2 = 0x015500aa;
  766. if (!pdata->fifo_cfg3)
  767. pdata->fifo_cfg3 = 0x01f00140;
  768. break;
  769. case ATH79_SOC_AR7241:
  770. if (id == 0)
  771. pdata->reset_bit |= AR724X_RESET_GE0_MDIO;
  772. else
  773. pdata->reset_bit |= AR724X_RESET_GE1_MDIO;
  774. /* fall through */
  775. case ATH79_SOC_AR7240:
  776. if (id == 0) {
  777. pdata->reset_bit |= AR71XX_RESET_GE0_PHY;
  778. pdata->ddr_flush = ar724x_ddr_flush_ge0;
  779. pdata->set_speed = ath79_set_speed_dummy;
  780. pdata->phy_mask = BIT(4);
  781. } else {
  782. pdata->reset_bit |= AR71XX_RESET_GE1_PHY;
  783. pdata->ddr_flush = ar724x_ddr_flush_ge1;
  784. pdata->set_speed = ath79_set_speed_dummy;
  785. pdata->speed = SPEED_1000;
  786. pdata->duplex = DUPLEX_FULL;
  787. pdata->switch_data = &ath79_switch_data;
  788. ath79_switch_data.phy_poll_mask |= BIT(4);
  789. }
  790. pdata->has_gbit = 1;
  791. pdata->is_ar724x = 1;
  792. if (ath79_soc == ATH79_SOC_AR7240)
  793. pdata->is_ar7240 = 1;
  794. if (!pdata->fifo_cfg1)
  795. pdata->fifo_cfg1 = 0x0010ffff;
  796. if (!pdata->fifo_cfg2)
  797. pdata->fifo_cfg2 = 0x015500aa;
  798. if (!pdata->fifo_cfg3)
  799. pdata->fifo_cfg3 = 0x01f00140;
  800. break;
  801. case ATH79_SOC_AR9130:
  802. if (id == 0) {
  803. pdata->ddr_flush = ar91xx_ddr_flush_ge0;
  804. pdata->set_speed = ar91xx_set_speed_ge0;
  805. } else {
  806. pdata->ddr_flush = ar91xx_ddr_flush_ge1;
  807. pdata->set_speed = ar91xx_set_speed_ge1;
  808. }
  809. pdata->is_ar91xx = 1;
  810. break;
  811. case ATH79_SOC_AR9132:
  812. if (id == 0) {
  813. pdata->ddr_flush = ar91xx_ddr_flush_ge0;
  814. pdata->set_speed = ar91xx_set_speed_ge0;
  815. } else {
  816. pdata->ddr_flush = ar91xx_ddr_flush_ge1;
  817. pdata->set_speed = ar91xx_set_speed_ge1;
  818. }
  819. pdata->is_ar91xx = 1;
  820. pdata->has_gbit = 1;
  821. break;
  822. case ATH79_SOC_AR9330:
  823. case ATH79_SOC_AR9331:
  824. if (id == 0) {
  825. pdata->reset_bit = AR933X_RESET_GE0_MAC |
  826. AR933X_RESET_GE0_MDIO;
  827. pdata->ddr_flush = ar933x_ddr_flush_ge0;
  828. pdata->set_speed = ath79_set_speed_dummy;
  829. pdata->phy_mask = BIT(4);
  830. } else {
  831. pdata->reset_bit = AR933X_RESET_GE1_MAC |
  832. AR933X_RESET_GE1_MDIO;
  833. pdata->ddr_flush = ar933x_ddr_flush_ge1;
  834. pdata->set_speed = ath79_set_speed_dummy;
  835. pdata->speed = SPEED_1000;
  836. pdata->has_gbit = 1;
  837. pdata->duplex = DUPLEX_FULL;
  838. pdata->switch_data = &ath79_switch_data;
  839. ath79_switch_data.phy_poll_mask |= BIT(4);
  840. }
  841. pdata->is_ar724x = 1;
  842. if (!pdata->fifo_cfg1)
  843. pdata->fifo_cfg1 = 0x0010ffff;
  844. if (!pdata->fifo_cfg2)
  845. pdata->fifo_cfg2 = 0x015500aa;
  846. if (!pdata->fifo_cfg3)
  847. pdata->fifo_cfg3 = 0x01f00140;
  848. break;
  849. case ATH79_SOC_AR9341:
  850. case ATH79_SOC_AR9342:
  851. case ATH79_SOC_AR9344:
  852. case ATH79_SOC_QCA9533:
  853. if (id == 0) {
  854. pdata->reset_bit = AR934X_RESET_GE0_MAC |
  855. AR934X_RESET_GE0_MDIO;
  856. pdata->set_speed = ar934x_set_speed_ge0;
  857. } else {
  858. pdata->reset_bit = AR934X_RESET_GE1_MAC |
  859. AR934X_RESET_GE1_MDIO;
  860. pdata->set_speed = ath79_set_speed_dummy;
  861. pdata->switch_data = &ath79_switch_data;
  862. /* reset the built-in switch */
  863. ath79_device_reset_set(AR934X_RESET_ETH_SWITCH);
  864. ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH);
  865. }
  866. pdata->ddr_flush = ath79_ddr_no_flush;
  867. pdata->has_gbit = 1;
  868. pdata->is_ar724x = 1;
  869. pdata->max_frame_len = SZ_16K - 1;
  870. pdata->desc_pktlen_mask = SZ_16K - 1;
  871. if (!pdata->fifo_cfg1)
  872. pdata->fifo_cfg1 = 0x0010ffff;
  873. if (!pdata->fifo_cfg2)
  874. pdata->fifo_cfg2 = 0x015500aa;
  875. if (!pdata->fifo_cfg3)
  876. pdata->fifo_cfg3 = 0x01f00140;
  877. break;
  878. case ATH79_SOC_TP9343:
  879. if (id == 0) {
  880. pdata->reset_bit = AR933X_RESET_GE0_MAC |
  881. AR933X_RESET_GE0_MDIO;
  882. pdata->set_speed = ath79_set_speed_dummy;
  883. if (!pdata->phy_mask)
  884. pdata->phy_mask = BIT(4);
  885. } else {
  886. pdata->reset_bit = AR933X_RESET_GE1_MAC |
  887. AR933X_RESET_GE1_MDIO;
  888. pdata->set_speed = ath79_set_speed_dummy;
  889. pdata->speed = SPEED_1000;
  890. pdata->duplex = DUPLEX_FULL;
  891. pdata->switch_data = &ath79_switch_data;
  892. ath79_switch_data.phy_poll_mask |= BIT(4);
  893. }
  894. pdata->ddr_flush = ath79_ddr_no_flush;
  895. pdata->has_gbit = 1;
  896. pdata->is_ar724x = 1;
  897. if (!pdata->fifo_cfg1)
  898. pdata->fifo_cfg1 = 0x0010ffff;
  899. if (!pdata->fifo_cfg2)
  900. pdata->fifo_cfg2 = 0x015500aa;
  901. if (!pdata->fifo_cfg3)
  902. pdata->fifo_cfg3 = 0x01f00140;
  903. break;
  904. case ATH79_SOC_QCA9556:
  905. case ATH79_SOC_QCA9558:
  906. if (id == 0) {
  907. pdata->reset_bit = QCA955X_RESET_GE0_MAC |
  908. QCA955X_RESET_GE0_MDIO;
  909. pdata->set_speed = qca955x_set_speed_xmii;
  910. } else {
  911. pdata->reset_bit = QCA955X_RESET_GE1_MAC |
  912. QCA955X_RESET_GE1_MDIO;
  913. pdata->set_speed = qca955x_set_speed_sgmii;
  914. }
  915. pdata->ddr_flush = ath79_ddr_no_flush;
  916. pdata->has_gbit = 1;
  917. pdata->is_ar724x = 1;
  918. /*
  919. * Limit the maximum frame length to 4095 bytes.
  920. * Although the documentation says that the hardware
  921. * limit is 16383 bytes but that does not work in
  922. * practice. It seems that the hardware only updates
  923. * the lowest 12 bits of the packet length field
  924. * in the RX descriptor.
  925. */
  926. pdata->max_frame_len = SZ_4K - 1;
  927. pdata->desc_pktlen_mask = SZ_16K - 1;
  928. if (!pdata->fifo_cfg1)
  929. pdata->fifo_cfg1 = 0x0010ffff;
  930. if (!pdata->fifo_cfg2)
  931. pdata->fifo_cfg2 = 0x015500aa;
  932. if (!pdata->fifo_cfg3)
  933. pdata->fifo_cfg3 = 0x01f00140;
  934. break;
  935. case ATH79_SOC_QCA956X:
  936. if (id == 0) {
  937. pdata->reset_bit = QCA955X_RESET_GE0_MAC |
  938. QCA955X_RESET_GE0_MDIO;
  939. if (pdata->phy_if_mode == PHY_INTERFACE_MODE_SGMII)
  940. pdata->set_speed = qca956x_set_speed_sgmii;
  941. else
  942. pdata->set_speed = ath79_set_speed_ge0;
  943. } else {
  944. pdata->reset_bit = QCA955X_RESET_GE1_MAC |
  945. QCA955X_RESET_GE1_MDIO;
  946. pdata->set_speed = ath79_set_speed_dummy;
  947. pdata->switch_data = &ath79_switch_data;
  948. pdata->speed = SPEED_1000;
  949. pdata->duplex = DUPLEX_FULL;
  950. /* reset the built-in switch */
  951. ath79_device_reset_set(AR934X_RESET_ETH_SWITCH);
  952. ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH);
  953. }
  954. pdata->ddr_flush = ath79_ddr_no_flush;
  955. pdata->has_gbit = 1;
  956. pdata->is_ar724x = 1;
  957. if (!pdata->fifo_cfg1)
  958. pdata->fifo_cfg1 = 0x0010ffff;
  959. if (!pdata->fifo_cfg2)
  960. pdata->fifo_cfg2 = 0x015500aa;
  961. if (!pdata->fifo_cfg3)
  962. pdata->fifo_cfg3 = 0x01f00140;
  963. break;
  964. default:
  965. BUG();
  966. }
  967. switch (pdata->phy_if_mode) {
  968. case PHY_INTERFACE_MODE_GMII:
  969. case PHY_INTERFACE_MODE_RGMII:
  970. case PHY_INTERFACE_MODE_SGMII:
  971. if (!pdata->has_gbit) {
  972. printk(KERN_ERR "ar71xx: no gbit available on eth%d\n",
  973. id);
  974. return;
  975. }
  976. /* fallthrough */
  977. default:
  978. break;
  979. }
  980. if (!is_valid_ether_addr(pdata->mac_addr)) {
  981. random_ether_addr(pdata->mac_addr);
  982. printk(KERN_DEBUG
  983. "ar71xx: using random MAC address for eth%d\n",
  984. ath79_eth_instance);
  985. }
  986. if (pdata->mii_bus_dev == NULL) {
  987. switch (ath79_soc) {
  988. case ATH79_SOC_AR9341:
  989. case ATH79_SOC_AR9342:
  990. case ATH79_SOC_AR9344:
  991. if (id == 0)
  992. pdata->mii_bus_dev = &ath79_mdio0_device.dev;
  993. else
  994. pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  995. break;
  996. case ATH79_SOC_AR7241:
  997. case ATH79_SOC_AR9330:
  998. case ATH79_SOC_AR9331:
  999. case ATH79_SOC_QCA9533:
  1000. case ATH79_SOC_TP9343:
  1001. pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  1002. break;
  1003. case ATH79_SOC_QCA9556:
  1004. case ATH79_SOC_QCA9558:
  1005. /* don't assign any MDIO device by default */
  1006. break;
  1007. case ATH79_SOC_QCA956X:
  1008. if (pdata->phy_if_mode != PHY_INTERFACE_MODE_SGMII)
  1009. pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  1010. break;
  1011. default:
  1012. pdata->mii_bus_dev = &ath79_mdio0_device.dev;
  1013. break;
  1014. }
  1015. }
  1016. /* Reset the device */
  1017. ath79_device_reset_set(pdata->reset_bit);
  1018. msleep(100);
  1019. ath79_device_reset_clear(pdata->reset_bit);
  1020. msleep(100);
  1021. platform_device_register(pdev);
  1022. ath79_eth_instance++;
  1023. }
  1024. void __init ath79_set_mac_base(unsigned char *mac)
  1025. {
  1026. memcpy(ath79_mac_base, mac, ETH_ALEN);
  1027. }
  1028. void __init ath79_parse_ascii_mac(char *mac_str, u8 *mac)
  1029. {
  1030. int t;
  1031. t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  1032. &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  1033. if (t != ETH_ALEN)
  1034. t = sscanf(mac_str, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
  1035. &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  1036. if (t != ETH_ALEN || !is_valid_ether_addr(mac)) {
  1037. memset(mac, 0, ETH_ALEN);
  1038. printk(KERN_DEBUG "ar71xx: invalid mac address \"%s\"\n",
  1039. mac_str);
  1040. }
  1041. }
  1042. static void __init ath79_set_mac_base_ascii(char *str)
  1043. {
  1044. u8 mac[ETH_ALEN];
  1045. ath79_parse_ascii_mac(str, mac);
  1046. ath79_set_mac_base(mac);
  1047. }
  1048. static int __init ath79_ethaddr_setup(char *str)
  1049. {
  1050. ath79_set_mac_base_ascii(str);
  1051. return 1;
  1052. }
  1053. __setup("ethaddr=", ath79_ethaddr_setup);
  1054. static int __init ath79_kmac_setup(char *str)
  1055. {
  1056. ath79_set_mac_base_ascii(str);
  1057. return 1;
  1058. }
  1059. __setup("kmac=", ath79_kmac_setup);
  1060. void __init ath79_init_mac(unsigned char *dst, const unsigned char *src,
  1061. int offset)
  1062. {
  1063. int t;
  1064. if (!dst)
  1065. return;
  1066. if (!src || !is_valid_ether_addr(src)) {
  1067. memset(dst, '\0', ETH_ALEN);
  1068. return;
  1069. }
  1070. t = (((u32) src[3]) << 16) + (((u32) src[4]) << 8) + ((u32) src[5]);
  1071. t += offset;
  1072. dst[0] = src[0];
  1073. dst[1] = src[1];
  1074. dst[2] = src[2];
  1075. dst[3] = (t >> 16) & 0xff;
  1076. dst[4] = (t >> 8) & 0xff;
  1077. dst[5] = t & 0xff;
  1078. }
  1079. void __init ath79_init_local_mac(unsigned char *dst, const unsigned char *src)
  1080. {
  1081. int i;
  1082. if (!dst)
  1083. return;
  1084. if (!src || !is_valid_ether_addr(src)) {
  1085. memset(dst, '\0', ETH_ALEN);
  1086. return;
  1087. }
  1088. for (i = 0; i < ETH_ALEN; i++)
  1089. dst[i] = src[i];
  1090. dst[0] |= 0x02;
  1091. }