1
0

0022-mips-ath79-add-ath79-ethernet-driver.patch 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. From 0c6bdad5f210f5f2fe28dc197ab77a36402bb36e Mon Sep 17 00:00:00 2001
  2. From: Phil Sutter <phil@nwl.cc>
  3. Date: Wed, 14 May 2014 03:08:37 +0200
  4. Subject: [PATCH] mips: ath79: add ath79 ethernet driver
  5. ---
  6. arch/mips/ath79/Kconfig | 3 +
  7. arch/mips/ath79/Makefile | 1 +
  8. arch/mips/ath79/dev-eth.c | 1151 ++++++++++++++++++++++++
  9. arch/mips/ath79/dev-eth.h | 51 ++
  10. arch/mips/include/asm/mach-ath79/ar71xx_regs.h | 81 ++
  11. 5 files changed, 1287 insertions(+)
  12. create mode 100644 arch/mips/ath79/dev-eth.c
  13. create mode 100644 arch/mips/ath79/dev-eth.h
  14. diff --git a/arch/mips/ath79/Kconfig b/arch/mips/ath79/Kconfig
  15. index 3995e31..52cefd7 100644
  16. --- a/arch/mips/ath79/Kconfig
  17. +++ b/arch/mips/ath79/Kconfig
  18. @@ -109,6 +109,9 @@ config SOC_QCA955X
  19. config PCI_AR724X
  20. def_bool n
  21. +config ATH79_DEV_ETH
  22. + def_bool n
  23. +
  24. config ATH79_DEV_GPIO_BUTTONS
  25. def_bool n
  26. diff --git a/arch/mips/ath79/Makefile b/arch/mips/ath79/Makefile
  27. index 5c9ff69..05485da 100644
  28. --- a/arch/mips/ath79/Makefile
  29. +++ b/arch/mips/ath79/Makefile
  30. @@ -17,6 +17,7 @@ obj-$(CONFIG_PCI) += pci.o
  31. # Devices
  32. #
  33. obj-y += dev-common.o
  34. +obj-$(CONFIG_ATH79_DEV_ETH) += dev-eth.o
  35. obj-$(CONFIG_ATH79_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o
  36. obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o
  37. obj-$(CONFIG_ATH79_DEV_SPI) += dev-spi.o
  38. diff --git a/arch/mips/ath79/dev-eth.c b/arch/mips/ath79/dev-eth.c
  39. new file mode 100644
  40. index 0000000..21feeb9
  41. --- /dev/null
  42. +++ b/arch/mips/ath79/dev-eth.c
  43. @@ -0,0 +1,1151 @@
  44. +/*
  45. + * Atheros AR71xx SoC platform devices
  46. + *
  47. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  48. + * Copyright (C) 2008-2012 Gabor Juhos <juhosg@openwrt.org>
  49. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  50. + *
  51. + * Parts of this file are based on Atheros 2.6.15 BSP
  52. + * Parts of this file are based on Atheros 2.6.31 BSP
  53. + *
  54. + * This program is free software; you can redistribute it and/or modify it
  55. + * under the terms of the GNU General Public License version 2 as published
  56. + * by the Free Software Foundation.
  57. + */
  58. +
  59. +#include <linux/kernel.h>
  60. +#include <linux/init.h>
  61. +#include <linux/delay.h>
  62. +#include <linux/etherdevice.h>
  63. +#include <linux/platform_device.h>
  64. +#include <linux/serial_8250.h>
  65. +#include <linux/clk.h>
  66. +#include <linux/sizes.h>
  67. +
  68. +#include <asm/mach-ath79/ath79.h>
  69. +#include <asm/mach-ath79/ar71xx_regs.h>
  70. +#include <asm/mach-ath79/irq.h>
  71. +
  72. +#include "common.h"
  73. +#include "dev-eth.h"
  74. +
  75. +unsigned char ath79_mac_base[ETH_ALEN] __initdata;
  76. +
  77. +static struct resource ath79_mdio0_resources[] = {
  78. + {
  79. + .name = "mdio_base",
  80. + .flags = IORESOURCE_MEM,
  81. + .start = AR71XX_GE0_BASE,
  82. + .end = AR71XX_GE0_BASE + 0x200 - 1,
  83. + }
  84. +};
  85. +
  86. +struct ag71xx_mdio_platform_data ath79_mdio0_data;
  87. +
  88. +struct platform_device ath79_mdio0_device = {
  89. + .name = "ag71xx-mdio",
  90. + .id = 0,
  91. + .resource = ath79_mdio0_resources,
  92. + .num_resources = ARRAY_SIZE(ath79_mdio0_resources),
  93. + .dev = {
  94. + .platform_data = &ath79_mdio0_data,
  95. + },
  96. +};
  97. +
  98. +static struct resource ath79_mdio1_resources[] = {
  99. + {
  100. + .name = "mdio_base",
  101. + .flags = IORESOURCE_MEM,
  102. + .start = AR71XX_GE1_BASE,
  103. + .end = AR71XX_GE1_BASE + 0x200 - 1,
  104. + }
  105. +};
  106. +
  107. +struct ag71xx_mdio_platform_data ath79_mdio1_data;
  108. +
  109. +struct platform_device ath79_mdio1_device = {
  110. + .name = "ag71xx-mdio",
  111. + .id = 1,
  112. + .resource = ath79_mdio1_resources,
  113. + .num_resources = ARRAY_SIZE(ath79_mdio1_resources),
  114. + .dev = {
  115. + .platform_data = &ath79_mdio1_data,
  116. + },
  117. +};
  118. +
  119. +static void ath79_set_pll(u32 cfg_reg, u32 pll_reg, u32 pll_val, u32 shift)
  120. +{
  121. + void __iomem *base;
  122. + u32 t;
  123. +
  124. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  125. +
  126. + t = __raw_readl(base + cfg_reg);
  127. + t &= ~(3 << shift);
  128. + t |= (2 << shift);
  129. + __raw_writel(t, base + cfg_reg);
  130. + udelay(100);
  131. +
  132. + __raw_writel(pll_val, base + pll_reg);
  133. +
  134. + t |= (3 << shift);
  135. + __raw_writel(t, base + cfg_reg);
  136. + udelay(100);
  137. +
  138. + t &= ~(3 << shift);
  139. + __raw_writel(t, base + cfg_reg);
  140. + udelay(100);
  141. +
  142. + printk(KERN_DEBUG "ar71xx: pll_reg %#x: %#x\n",
  143. + (unsigned int)(base + pll_reg), __raw_readl(base + pll_reg));
  144. +
  145. + iounmap(base);
  146. +}
  147. +
  148. +static void __init ath79_mii_ctrl_set_if(unsigned int reg,
  149. + unsigned int mii_if)
  150. +{
  151. + void __iomem *base;
  152. + u32 t;
  153. +
  154. + base = ioremap(AR71XX_MII_BASE, AR71XX_MII_SIZE);
  155. +
  156. + t = __raw_readl(base + reg);
  157. + t &= ~(AR71XX_MII_CTRL_IF_MASK);
  158. + t |= (mii_if & AR71XX_MII_CTRL_IF_MASK);
  159. + __raw_writel(t, base + reg);
  160. +
  161. + iounmap(base);
  162. +}
  163. +
  164. +static void ath79_mii_ctrl_set_speed(unsigned int reg, unsigned int speed)
  165. +{
  166. + void __iomem *base;
  167. + unsigned int mii_speed;
  168. + u32 t;
  169. +
  170. + switch (speed) {
  171. + case SPEED_10:
  172. + mii_speed = AR71XX_MII_CTRL_SPEED_10;
  173. + break;
  174. + case SPEED_100:
  175. + mii_speed = AR71XX_MII_CTRL_SPEED_100;
  176. + break;
  177. + case SPEED_1000:
  178. + mii_speed = AR71XX_MII_CTRL_SPEED_1000;
  179. + break;
  180. + default:
  181. + BUG();
  182. + }
  183. +
  184. + base = ioremap(AR71XX_MII_BASE, AR71XX_MII_SIZE);
  185. +
  186. + t = __raw_readl(base + reg);
  187. + t &= ~(AR71XX_MII_CTRL_SPEED_MASK << AR71XX_MII_CTRL_SPEED_SHIFT);
  188. + t |= mii_speed << AR71XX_MII_CTRL_SPEED_SHIFT;
  189. + __raw_writel(t, base + reg);
  190. +
  191. + iounmap(base);
  192. +}
  193. +
  194. +static unsigned long ar934x_get_mdio_ref_clock(void)
  195. +{
  196. + void __iomem *base;
  197. + unsigned long ret;
  198. + u32 t;
  199. +
  200. + base = ioremap(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  201. +
  202. + ret = 0;
  203. + t = __raw_readl(base + AR934X_PLL_SWITCH_CLOCK_CONTROL_REG);
  204. + if (t & AR934X_PLL_SWITCH_CLOCK_CONTROL_MDIO_CLK_SEL) {
  205. + ret = 100 * 1000 * 1000;
  206. + } else {
  207. + struct clk *clk;
  208. +
  209. + clk = clk_get(NULL, "ref");
  210. + if (!IS_ERR(clk))
  211. + ret = clk_get_rate(clk);
  212. + }
  213. +
  214. + iounmap(base);
  215. +
  216. + return ret;
  217. +}
  218. +
  219. +void __init ath79_register_mdio(unsigned int id, u32 phy_mask)
  220. +{
  221. + struct platform_device *mdio_dev;
  222. + struct ag71xx_mdio_platform_data *mdio_data;
  223. + unsigned int max_id;
  224. +
  225. + if (ath79_soc == ATH79_SOC_AR9341 ||
  226. + ath79_soc == ATH79_SOC_AR9342 ||
  227. + ath79_soc == ATH79_SOC_AR9344 ||
  228. + ath79_soc == ATH79_SOC_QCA9556 ||
  229. + ath79_soc == ATH79_SOC_QCA9558)
  230. + max_id = 1;
  231. + else
  232. + max_id = 0;
  233. +
  234. + if (id > max_id) {
  235. + printk(KERN_ERR "ar71xx: invalid MDIO id %u\n", id);
  236. + return;
  237. + }
  238. +
  239. + switch (ath79_soc) {
  240. + case ATH79_SOC_AR7241:
  241. + case ATH79_SOC_AR9330:
  242. + case ATH79_SOC_AR9331:
  243. + mdio_dev = &ath79_mdio1_device;
  244. + mdio_data = &ath79_mdio1_data;
  245. + break;
  246. +
  247. + case ATH79_SOC_AR9341:
  248. + case ATH79_SOC_AR9342:
  249. + case ATH79_SOC_AR9344:
  250. + case ATH79_SOC_QCA9556:
  251. + case ATH79_SOC_QCA9558:
  252. + if (id == 0) {
  253. + mdio_dev = &ath79_mdio0_device;
  254. + mdio_data = &ath79_mdio0_data;
  255. + } else {
  256. + mdio_dev = &ath79_mdio1_device;
  257. + mdio_data = &ath79_mdio1_data;
  258. + }
  259. + break;
  260. +
  261. + case ATH79_SOC_AR7242:
  262. + ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG,
  263. + AR7242_PLL_REG_ETH0_INT_CLOCK, 0x62000000,
  264. + AR71XX_ETH0_PLL_SHIFT);
  265. + /* fall through */
  266. + default:
  267. + mdio_dev = &ath79_mdio0_device;
  268. + mdio_data = &ath79_mdio0_data;
  269. + break;
  270. + }
  271. +
  272. + mdio_data->phy_mask = phy_mask;
  273. +
  274. + switch (ath79_soc) {
  275. + case ATH79_SOC_AR7240:
  276. + mdio_data->is_ar7240 = 1;
  277. + /* fall through */
  278. + case ATH79_SOC_AR7241:
  279. + mdio_data->builtin_switch = 1;
  280. + break;
  281. +
  282. + case ATH79_SOC_AR9330:
  283. + mdio_data->is_ar9330 = 1;
  284. + /* fall through */
  285. + case ATH79_SOC_AR9331:
  286. + mdio_data->builtin_switch = 1;
  287. + break;
  288. +
  289. + case ATH79_SOC_AR9341:
  290. + case ATH79_SOC_AR9342:
  291. + case ATH79_SOC_AR9344:
  292. + if (id == 1) {
  293. + mdio_data->builtin_switch = 1;
  294. + mdio_data->ref_clock = ar934x_get_mdio_ref_clock();
  295. + mdio_data->mdio_clock = 6250000;
  296. + }
  297. + mdio_data->is_ar934x = 1;
  298. + break;
  299. +
  300. + case ATH79_SOC_QCA9556:
  301. + case ATH79_SOC_QCA9558:
  302. + mdio_data->is_ar934x = 1;
  303. + break;
  304. +
  305. + default:
  306. + break;
  307. + }
  308. +
  309. + platform_device_register(mdio_dev);
  310. +}
  311. +
  312. +struct ath79_eth_pll_data ath79_eth0_pll_data;
  313. +struct ath79_eth_pll_data ath79_eth1_pll_data;
  314. +
  315. +static u32 ath79_get_eth_pll(unsigned int mac, int speed)
  316. +{
  317. + struct ath79_eth_pll_data *pll_data;
  318. + u32 pll_val;
  319. +
  320. + switch (mac) {
  321. + case 0:
  322. + pll_data = &ath79_eth0_pll_data;
  323. + break;
  324. + case 1:
  325. + pll_data = &ath79_eth1_pll_data;
  326. + break;
  327. + default:
  328. + BUG();
  329. + }
  330. +
  331. + switch (speed) {
  332. + case SPEED_10:
  333. + pll_val = pll_data->pll_10;
  334. + break;
  335. + case SPEED_100:
  336. + pll_val = pll_data->pll_100;
  337. + break;
  338. + case SPEED_1000:
  339. + pll_val = pll_data->pll_1000;
  340. + break;
  341. + default:
  342. + BUG();
  343. + }
  344. +
  345. + return pll_val;
  346. +}
  347. +
  348. +static void ath79_set_speed_ge0(int speed)
  349. +{
  350. + u32 val = ath79_get_eth_pll(0, speed);
  351. +
  352. + ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH0_INT_CLOCK,
  353. + val, AR71XX_ETH0_PLL_SHIFT);
  354. + ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL, speed);
  355. +}
  356. +
  357. +static void ath79_set_speed_ge1(int speed)
  358. +{
  359. + u32 val = ath79_get_eth_pll(1, speed);
  360. +
  361. + ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH1_INT_CLOCK,
  362. + val, AR71XX_ETH1_PLL_SHIFT);
  363. + ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL, speed);
  364. +}
  365. +
  366. +static void ar7242_set_speed_ge0(int speed)
  367. +{
  368. + u32 val = ath79_get_eth_pll(0, speed);
  369. + void __iomem *base;
  370. +
  371. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  372. + __raw_writel(val, base + AR7242_PLL_REG_ETH0_INT_CLOCK);
  373. + iounmap(base);
  374. +}
  375. +
  376. +static void ar91xx_set_speed_ge0(int speed)
  377. +{
  378. + u32 val = ath79_get_eth_pll(0, speed);
  379. +
  380. + ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG, AR913X_PLL_REG_ETH0_INT_CLOCK,
  381. + val, AR913X_ETH0_PLL_SHIFT);
  382. + ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL, speed);
  383. +}
  384. +
  385. +static void ar91xx_set_speed_ge1(int speed)
  386. +{
  387. + u32 val = ath79_get_eth_pll(1, speed);
  388. +
  389. + ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG, AR913X_PLL_REG_ETH1_INT_CLOCK,
  390. + val, AR913X_ETH1_PLL_SHIFT);
  391. + ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL, speed);
  392. +}
  393. +
  394. +static void ar934x_set_speed_ge0(int speed)
  395. +{
  396. + void __iomem *base;
  397. + u32 val = ath79_get_eth_pll(0, speed);
  398. +
  399. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  400. + __raw_writel(val, base + AR934X_PLL_ETH_XMII_CONTROL_REG);
  401. + iounmap(base);
  402. +}
  403. +
  404. +static void qca955x_set_speed_xmii(int speed)
  405. +{
  406. + void __iomem *base;
  407. + u32 val = ath79_get_eth_pll(0, speed);
  408. +
  409. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  410. + __raw_writel(val, base + QCA955X_PLL_ETH_XMII_CONTROL_REG);
  411. + iounmap(base);
  412. +}
  413. +
  414. +static void qca955x_set_speed_sgmii(int speed)
  415. +{
  416. + void __iomem *base;
  417. + u32 val = ath79_get_eth_pll(1, speed);
  418. +
  419. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  420. + __raw_writel(val, base + QCA955X_PLL_ETH_SGMII_CONTROL_REG);
  421. + iounmap(base);
  422. +}
  423. +
  424. +static void ath79_set_speed_dummy(int speed)
  425. +{
  426. +}
  427. +
  428. +static void ath79_ddr_no_flush(void)
  429. +{
  430. +}
  431. +
  432. +static void ath79_ddr_flush_ge0(void)
  433. +{
  434. + ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_GE0);
  435. +}
  436. +
  437. +static void ath79_ddr_flush_ge1(void)
  438. +{
  439. + ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_GE1);
  440. +}
  441. +
  442. +static void ar724x_ddr_flush_ge0(void)
  443. +{
  444. + ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_GE0);
  445. +}
  446. +
  447. +static void ar724x_ddr_flush_ge1(void)
  448. +{
  449. + ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_GE1);
  450. +}
  451. +
  452. +static void ar91xx_ddr_flush_ge0(void)
  453. +{
  454. + ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_GE0);
  455. +}
  456. +
  457. +static void ar91xx_ddr_flush_ge1(void)
  458. +{
  459. + ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_GE1);
  460. +}
  461. +
  462. +static void ar933x_ddr_flush_ge0(void)
  463. +{
  464. + ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_GE0);
  465. +}
  466. +
  467. +static void ar933x_ddr_flush_ge1(void)
  468. +{
  469. + ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_GE1);
  470. +}
  471. +
  472. +static struct resource ath79_eth0_resources[] = {
  473. + {
  474. + .name = "mac_base",
  475. + .flags = IORESOURCE_MEM,
  476. + .start = AR71XX_GE0_BASE,
  477. + .end = AR71XX_GE0_BASE + 0x200 - 1,
  478. + }, {
  479. + .name = "mac_irq",
  480. + .flags = IORESOURCE_IRQ,
  481. + .start = ATH79_CPU_IRQ(4),
  482. + .end = ATH79_CPU_IRQ(4),
  483. + },
  484. +};
  485. +
  486. +struct ag71xx_platform_data ath79_eth0_data = {
  487. + .reset_bit = AR71XX_RESET_GE0_MAC,
  488. +};
  489. +
  490. +struct platform_device ath79_eth0_device = {
  491. + .name = "ag71xx",
  492. + .id = 0,
  493. + .resource = ath79_eth0_resources,
  494. + .num_resources = ARRAY_SIZE(ath79_eth0_resources),
  495. + .dev = {
  496. + .platform_data = &ath79_eth0_data,
  497. + },
  498. +};
  499. +
  500. +static struct resource ath79_eth1_resources[] = {
  501. + {
  502. + .name = "mac_base",
  503. + .flags = IORESOURCE_MEM,
  504. + .start = AR71XX_GE1_BASE,
  505. + .end = AR71XX_GE1_BASE + 0x200 - 1,
  506. + }, {
  507. + .name = "mac_irq",
  508. + .flags = IORESOURCE_IRQ,
  509. + .start = ATH79_CPU_IRQ(5),
  510. + .end = ATH79_CPU_IRQ(5),
  511. + },
  512. +};
  513. +
  514. +struct ag71xx_platform_data ath79_eth1_data = {
  515. + .reset_bit = AR71XX_RESET_GE1_MAC,
  516. +};
  517. +
  518. +struct platform_device ath79_eth1_device = {
  519. + .name = "ag71xx",
  520. + .id = 1,
  521. + .resource = ath79_eth1_resources,
  522. + .num_resources = ARRAY_SIZE(ath79_eth1_resources),
  523. + .dev = {
  524. + .platform_data = &ath79_eth1_data,
  525. + },
  526. +};
  527. +
  528. +struct ag71xx_switch_platform_data ath79_switch_data;
  529. +
  530. +#define AR71XX_PLL_VAL_1000 0x00110000
  531. +#define AR71XX_PLL_VAL_100 0x00001099
  532. +#define AR71XX_PLL_VAL_10 0x00991099
  533. +
  534. +#define AR724X_PLL_VAL_1000 0x00110000
  535. +#define AR724X_PLL_VAL_100 0x00001099
  536. +#define AR724X_PLL_VAL_10 0x00991099
  537. +
  538. +#define AR7242_PLL_VAL_1000 0x16000000
  539. +#define AR7242_PLL_VAL_100 0x00000101
  540. +#define AR7242_PLL_VAL_10 0x00001616
  541. +
  542. +#define AR913X_PLL_VAL_1000 0x1a000000
  543. +#define AR913X_PLL_VAL_100 0x13000a44
  544. +#define AR913X_PLL_VAL_10 0x00441099
  545. +
  546. +#define AR933X_PLL_VAL_1000 0x00110000
  547. +#define AR933X_PLL_VAL_100 0x00001099
  548. +#define AR933X_PLL_VAL_10 0x00991099
  549. +
  550. +#define AR934X_PLL_VAL_1000 0x16000000
  551. +#define AR934X_PLL_VAL_100 0x00000101
  552. +#define AR934X_PLL_VAL_10 0x00001616
  553. +
  554. +static void __init ath79_init_eth_pll_data(unsigned int id)
  555. +{
  556. + struct ath79_eth_pll_data *pll_data;
  557. + u32 pll_10, pll_100, pll_1000;
  558. +
  559. + switch (id) {
  560. + case 0:
  561. + pll_data = &ath79_eth0_pll_data;
  562. + break;
  563. + case 1:
  564. + pll_data = &ath79_eth1_pll_data;
  565. + break;
  566. + default:
  567. + BUG();
  568. + }
  569. +
  570. + switch (ath79_soc) {
  571. + case ATH79_SOC_AR7130:
  572. + case ATH79_SOC_AR7141:
  573. + case ATH79_SOC_AR7161:
  574. + pll_10 = AR71XX_PLL_VAL_10;
  575. + pll_100 = AR71XX_PLL_VAL_100;
  576. + pll_1000 = AR71XX_PLL_VAL_1000;
  577. + break;
  578. +
  579. + case ATH79_SOC_AR7240:
  580. + case ATH79_SOC_AR7241:
  581. + pll_10 = AR724X_PLL_VAL_10;
  582. + pll_100 = AR724X_PLL_VAL_100;
  583. + pll_1000 = AR724X_PLL_VAL_1000;
  584. + break;
  585. +
  586. + case ATH79_SOC_AR7242:
  587. + pll_10 = AR7242_PLL_VAL_10;
  588. + pll_100 = AR7242_PLL_VAL_100;
  589. + pll_1000 = AR7242_PLL_VAL_1000;
  590. + break;
  591. +
  592. + case ATH79_SOC_AR9130:
  593. + case ATH79_SOC_AR9132:
  594. + pll_10 = AR913X_PLL_VAL_10;
  595. + pll_100 = AR913X_PLL_VAL_100;
  596. + pll_1000 = AR913X_PLL_VAL_1000;
  597. + break;
  598. +
  599. + case ATH79_SOC_AR9330:
  600. + case ATH79_SOC_AR9331:
  601. + pll_10 = AR933X_PLL_VAL_10;
  602. + pll_100 = AR933X_PLL_VAL_100;
  603. + pll_1000 = AR933X_PLL_VAL_1000;
  604. + break;
  605. +
  606. + case ATH79_SOC_AR9341:
  607. + case ATH79_SOC_AR9342:
  608. + case ATH79_SOC_AR9344:
  609. + case ATH79_SOC_QCA9556:
  610. + case ATH79_SOC_QCA9558:
  611. + pll_10 = AR934X_PLL_VAL_10;
  612. + pll_100 = AR934X_PLL_VAL_100;
  613. + pll_1000 = AR934X_PLL_VAL_1000;
  614. + break;
  615. +
  616. + default:
  617. + BUG();
  618. + }
  619. +
  620. + if (!pll_data->pll_10)
  621. + pll_data->pll_10 = pll_10;
  622. +
  623. + if (!pll_data->pll_100)
  624. + pll_data->pll_100 = pll_100;
  625. +
  626. + if (!pll_data->pll_1000)
  627. + pll_data->pll_1000 = pll_1000;
  628. +}
  629. +
  630. +static int __init ath79_setup_phy_if_mode(unsigned int id,
  631. + struct ag71xx_platform_data *pdata)
  632. +{
  633. + unsigned int mii_if;
  634. +
  635. + switch (id) {
  636. + case 0:
  637. + switch (ath79_soc) {
  638. + case ATH79_SOC_AR7130:
  639. + case ATH79_SOC_AR7141:
  640. + case ATH79_SOC_AR7161:
  641. + case ATH79_SOC_AR9130:
  642. + case ATH79_SOC_AR9132:
  643. + switch (pdata->phy_if_mode) {
  644. + case PHY_INTERFACE_MODE_MII:
  645. + mii_if = AR71XX_MII0_CTRL_IF_MII;
  646. + break;
  647. + case PHY_INTERFACE_MODE_GMII:
  648. + mii_if = AR71XX_MII0_CTRL_IF_GMII;
  649. + break;
  650. + case PHY_INTERFACE_MODE_RGMII:
  651. + mii_if = AR71XX_MII0_CTRL_IF_RGMII;
  652. + break;
  653. + case PHY_INTERFACE_MODE_RMII:
  654. + mii_if = AR71XX_MII0_CTRL_IF_RMII;
  655. + break;
  656. + default:
  657. + return -EINVAL;
  658. + }
  659. + ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII0_CTRL, mii_if);
  660. + break;
  661. +
  662. + case ATH79_SOC_AR7240:
  663. + case ATH79_SOC_AR7241:
  664. + case ATH79_SOC_AR9330:
  665. + case ATH79_SOC_AR9331:
  666. + pdata->phy_if_mode = PHY_INTERFACE_MODE_MII;
  667. + break;
  668. +
  669. + case ATH79_SOC_AR7242:
  670. + /* FIXME */
  671. +
  672. + case ATH79_SOC_AR9341:
  673. + case ATH79_SOC_AR9342:
  674. + case ATH79_SOC_AR9344:
  675. + switch (pdata->phy_if_mode) {
  676. + case PHY_INTERFACE_MODE_MII:
  677. + case PHY_INTERFACE_MODE_GMII:
  678. + case PHY_INTERFACE_MODE_RGMII:
  679. + case PHY_INTERFACE_MODE_RMII:
  680. + break;
  681. + default:
  682. + return -EINVAL;
  683. + }
  684. + break;
  685. +
  686. + case ATH79_SOC_QCA9556:
  687. + case ATH79_SOC_QCA9558:
  688. + switch (pdata->phy_if_mode) {
  689. + case PHY_INTERFACE_MODE_MII:
  690. + case PHY_INTERFACE_MODE_RGMII:
  691. + case PHY_INTERFACE_MODE_SGMII:
  692. + break;
  693. + default:
  694. + return -EINVAL;
  695. + }
  696. + break;
  697. +
  698. + default:
  699. + BUG();
  700. + }
  701. + break;
  702. + case 1:
  703. + switch (ath79_soc) {
  704. + case ATH79_SOC_AR7130:
  705. + case ATH79_SOC_AR7141:
  706. + case ATH79_SOC_AR7161:
  707. + case ATH79_SOC_AR9130:
  708. + case ATH79_SOC_AR9132:
  709. + switch (pdata->phy_if_mode) {
  710. + case PHY_INTERFACE_MODE_RMII:
  711. + mii_if = AR71XX_MII1_CTRL_IF_RMII;
  712. + break;
  713. + case PHY_INTERFACE_MODE_RGMII:
  714. + mii_if = AR71XX_MII1_CTRL_IF_RGMII;
  715. + break;
  716. + default:
  717. + return -EINVAL;
  718. + }
  719. + ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII1_CTRL, mii_if);
  720. + break;
  721. +
  722. + case ATH79_SOC_AR7240:
  723. + case ATH79_SOC_AR7241:
  724. + case ATH79_SOC_AR9330:
  725. + case ATH79_SOC_AR9331:
  726. + pdata->phy_if_mode = PHY_INTERFACE_MODE_GMII;
  727. + break;
  728. +
  729. + case ATH79_SOC_AR7242:
  730. + /* FIXME */
  731. +
  732. + case ATH79_SOC_AR9341:
  733. + case ATH79_SOC_AR9342:
  734. + case ATH79_SOC_AR9344:
  735. + switch (pdata->phy_if_mode) {
  736. + case PHY_INTERFACE_MODE_MII:
  737. + case PHY_INTERFACE_MODE_GMII:
  738. + break;
  739. + default:
  740. + return -EINVAL;
  741. + }
  742. + break;
  743. +
  744. + case ATH79_SOC_QCA9556:
  745. + case ATH79_SOC_QCA9558:
  746. + switch (pdata->phy_if_mode) {
  747. + case PHY_INTERFACE_MODE_MII:
  748. + case PHY_INTERFACE_MODE_RGMII:
  749. + case PHY_INTERFACE_MODE_SGMII:
  750. + break;
  751. + default:
  752. + return -EINVAL;
  753. + }
  754. + break;
  755. +
  756. + default:
  757. + BUG();
  758. + }
  759. + break;
  760. + }
  761. +
  762. + return 0;
  763. +}
  764. +
  765. +void __init ath79_setup_ar933x_phy4_switch(bool mac, bool mdio)
  766. +{
  767. + void __iomem *base;
  768. + u32 t;
  769. +
  770. + base = ioremap(AR933X_GMAC_BASE, AR933X_GMAC_SIZE);
  771. +
  772. + t = __raw_readl(base + AR933X_GMAC_REG_ETH_CFG);
  773. + t &= ~(AR933X_ETH_CFG_SW_PHY_SWAP | AR933X_ETH_CFG_SW_PHY_ADDR_SWAP);
  774. + if (mac)
  775. + t |= AR933X_ETH_CFG_SW_PHY_SWAP;
  776. + if (mdio)
  777. + t |= AR933X_ETH_CFG_SW_PHY_ADDR_SWAP;
  778. + __raw_writel(t, base + AR933X_GMAC_REG_ETH_CFG);
  779. +
  780. + iounmap(base);
  781. +}
  782. +
  783. +void __init ath79_setup_ar934x_eth_cfg(u32 mask)
  784. +{
  785. + void __iomem *base;
  786. + u32 t;
  787. +
  788. + base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE);
  789. +
  790. + t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  791. +
  792. + t &= ~(AR934X_ETH_CFG_RGMII_GMAC0 |
  793. + AR934X_ETH_CFG_MII_GMAC0 |
  794. + AR934X_ETH_CFG_GMII_GMAC0 |
  795. + AR934X_ETH_CFG_SW_ONLY_MODE |
  796. + AR934X_ETH_CFG_SW_PHY_SWAP);
  797. +
  798. + t |= mask;
  799. +
  800. + __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG);
  801. + /* flush write */
  802. + __raw_readl(base + AR934X_GMAC_REG_ETH_CFG);
  803. +
  804. + iounmap(base);
  805. +}
  806. +
  807. +static int ath79_eth_instance __initdata;
  808. +void __init ath79_register_eth(unsigned int id)
  809. +{
  810. + struct platform_device *pdev;
  811. + struct ag71xx_platform_data *pdata;
  812. + int err;
  813. +
  814. + if (id > 1) {
  815. + printk(KERN_ERR "ar71xx: invalid ethernet id %d\n", id);
  816. + return;
  817. + }
  818. +
  819. + ath79_init_eth_pll_data(id);
  820. +
  821. + if (id == 0)
  822. + pdev = &ath79_eth0_device;
  823. + else
  824. + pdev = &ath79_eth1_device;
  825. +
  826. + pdata = pdev->dev.platform_data;
  827. +
  828. + pdata->max_frame_len = 1540;
  829. + pdata->desc_pktlen_mask = 0xfff;
  830. +
  831. + err = ath79_setup_phy_if_mode(id, pdata);
  832. + if (err) {
  833. + printk(KERN_ERR
  834. + "ar71xx: invalid PHY interface mode for GE%u\n", id);
  835. + return;
  836. + }
  837. +
  838. + switch (ath79_soc) {
  839. + case ATH79_SOC_AR7130:
  840. + if (id == 0) {
  841. + pdata->ddr_flush = ath79_ddr_flush_ge0;
  842. + pdata->set_speed = ath79_set_speed_ge0;
  843. + } else {
  844. + pdata->ddr_flush = ath79_ddr_flush_ge1;
  845. + pdata->set_speed = ath79_set_speed_ge1;
  846. + }
  847. + break;
  848. +
  849. + case ATH79_SOC_AR7141:
  850. + case ATH79_SOC_AR7161:
  851. + if (id == 0) {
  852. + pdata->ddr_flush = ath79_ddr_flush_ge0;
  853. + pdata->set_speed = ath79_set_speed_ge0;
  854. + } else {
  855. + pdata->ddr_flush = ath79_ddr_flush_ge1;
  856. + pdata->set_speed = ath79_set_speed_ge1;
  857. + }
  858. + pdata->has_gbit = 1;
  859. + break;
  860. +
  861. + case ATH79_SOC_AR7242:
  862. + if (id == 0) {
  863. + pdata->reset_bit |= AR724X_RESET_GE0_MDIO |
  864. + AR71XX_RESET_GE0_PHY;
  865. + pdata->ddr_flush = ar724x_ddr_flush_ge0;
  866. + pdata->set_speed = ar7242_set_speed_ge0;
  867. + } else {
  868. + pdata->reset_bit |= AR724X_RESET_GE1_MDIO |
  869. + AR71XX_RESET_GE1_PHY;
  870. + pdata->ddr_flush = ar724x_ddr_flush_ge1;
  871. + pdata->set_speed = ath79_set_speed_dummy;
  872. + }
  873. + pdata->has_gbit = 1;
  874. + pdata->is_ar724x = 1;
  875. +
  876. + if (!pdata->fifo_cfg1)
  877. + pdata->fifo_cfg1 = 0x0010ffff;
  878. + if (!pdata->fifo_cfg2)
  879. + pdata->fifo_cfg2 = 0x015500aa;
  880. + if (!pdata->fifo_cfg3)
  881. + pdata->fifo_cfg3 = 0x01f00140;
  882. + break;
  883. +
  884. + case ATH79_SOC_AR7241:
  885. + if (id == 0)
  886. + pdata->reset_bit |= AR724X_RESET_GE0_MDIO;
  887. + else
  888. + pdata->reset_bit |= AR724X_RESET_GE1_MDIO;
  889. + /* fall through */
  890. + case ATH79_SOC_AR7240:
  891. + if (id == 0) {
  892. + pdata->reset_bit |= AR71XX_RESET_GE0_PHY;
  893. + pdata->ddr_flush = ar724x_ddr_flush_ge0;
  894. + pdata->set_speed = ath79_set_speed_dummy;
  895. +
  896. + pdata->phy_mask = BIT(4);
  897. + } else {
  898. + pdata->reset_bit |= AR71XX_RESET_GE1_PHY;
  899. + pdata->ddr_flush = ar724x_ddr_flush_ge1;
  900. + pdata->set_speed = ath79_set_speed_dummy;
  901. +
  902. + pdata->speed = SPEED_1000;
  903. + pdata->duplex = DUPLEX_FULL;
  904. + pdata->switch_data = &ath79_switch_data;
  905. +
  906. + ath79_switch_data.phy_poll_mask |= BIT(4);
  907. + }
  908. + pdata->has_gbit = 1;
  909. + pdata->is_ar724x = 1;
  910. + if (ath79_soc == ATH79_SOC_AR7240)
  911. + pdata->is_ar7240 = 1;
  912. +
  913. + if (!pdata->fifo_cfg1)
  914. + pdata->fifo_cfg1 = 0x0010ffff;
  915. + if (!pdata->fifo_cfg2)
  916. + pdata->fifo_cfg2 = 0x015500aa;
  917. + if (!pdata->fifo_cfg3)
  918. + pdata->fifo_cfg3 = 0x01f00140;
  919. + break;
  920. +
  921. + case ATH79_SOC_AR9130:
  922. + if (id == 0) {
  923. + pdata->ddr_flush = ar91xx_ddr_flush_ge0;
  924. + pdata->set_speed = ar91xx_set_speed_ge0;
  925. + } else {
  926. + pdata->ddr_flush = ar91xx_ddr_flush_ge1;
  927. + pdata->set_speed = ar91xx_set_speed_ge1;
  928. + }
  929. + pdata->is_ar91xx = 1;
  930. + break;
  931. +
  932. + case ATH79_SOC_AR9132:
  933. + if (id == 0) {
  934. + pdata->ddr_flush = ar91xx_ddr_flush_ge0;
  935. + pdata->set_speed = ar91xx_set_speed_ge0;
  936. + } else {
  937. + pdata->ddr_flush = ar91xx_ddr_flush_ge1;
  938. + pdata->set_speed = ar91xx_set_speed_ge1;
  939. + }
  940. + pdata->is_ar91xx = 1;
  941. + pdata->has_gbit = 1;
  942. + break;
  943. +
  944. + case ATH79_SOC_AR9330:
  945. + case ATH79_SOC_AR9331:
  946. + if (id == 0) {
  947. + pdata->reset_bit = AR933X_RESET_GE0_MAC |
  948. + AR933X_RESET_GE0_MDIO;
  949. + pdata->ddr_flush = ar933x_ddr_flush_ge0;
  950. + pdata->set_speed = ath79_set_speed_dummy;
  951. +
  952. + pdata->phy_mask = BIT(4);
  953. + } else {
  954. + pdata->reset_bit = AR933X_RESET_GE1_MAC |
  955. + AR933X_RESET_GE1_MDIO;
  956. + pdata->ddr_flush = ar933x_ddr_flush_ge1;
  957. + pdata->set_speed = ath79_set_speed_dummy;
  958. +
  959. + pdata->speed = SPEED_1000;
  960. + pdata->duplex = DUPLEX_FULL;
  961. + pdata->switch_data = &ath79_switch_data;
  962. +
  963. + ath79_switch_data.phy_poll_mask |= BIT(4);
  964. + }
  965. +
  966. + pdata->has_gbit = 1;
  967. + pdata->is_ar724x = 1;
  968. +
  969. + if (!pdata->fifo_cfg1)
  970. + pdata->fifo_cfg1 = 0x0010ffff;
  971. + if (!pdata->fifo_cfg2)
  972. + pdata->fifo_cfg2 = 0x015500aa;
  973. + if (!pdata->fifo_cfg3)
  974. + pdata->fifo_cfg3 = 0x01f00140;
  975. + break;
  976. +
  977. + case ATH79_SOC_AR9341:
  978. + case ATH79_SOC_AR9342:
  979. + case ATH79_SOC_AR9344:
  980. + if (id == 0) {
  981. + pdata->reset_bit = AR934X_RESET_GE0_MAC |
  982. + AR934X_RESET_GE0_MDIO;
  983. + pdata->set_speed = ar934x_set_speed_ge0;
  984. + } else {
  985. + pdata->reset_bit = AR934X_RESET_GE1_MAC |
  986. + AR934X_RESET_GE1_MDIO;
  987. + pdata->set_speed = ath79_set_speed_dummy;
  988. +
  989. + pdata->switch_data = &ath79_switch_data;
  990. +
  991. + /* reset the built-in switch */
  992. + ath79_device_reset_set(AR934X_RESET_ETH_SWITCH);
  993. + ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH);
  994. + }
  995. +
  996. + pdata->ddr_flush = ath79_ddr_no_flush;
  997. + pdata->has_gbit = 1;
  998. + pdata->is_ar724x = 1;
  999. +
  1000. + pdata->max_frame_len = SZ_16K - 1;
  1001. + pdata->desc_pktlen_mask = SZ_16K - 1;
  1002. +
  1003. + if (!pdata->fifo_cfg1)
  1004. + pdata->fifo_cfg1 = 0x0010ffff;
  1005. + if (!pdata->fifo_cfg2)
  1006. + pdata->fifo_cfg2 = 0x015500aa;
  1007. + if (!pdata->fifo_cfg3)
  1008. + pdata->fifo_cfg3 = 0x01f00140;
  1009. + break;
  1010. +
  1011. + case ATH79_SOC_QCA9556:
  1012. + case ATH79_SOC_QCA9558:
  1013. + if (id == 0) {
  1014. + pdata->reset_bit = QCA955X_RESET_GE0_MAC |
  1015. + QCA955X_RESET_GE0_MDIO;
  1016. + pdata->set_speed = qca955x_set_speed_xmii;
  1017. + } else {
  1018. + pdata->reset_bit = QCA955X_RESET_GE1_MAC |
  1019. + QCA955X_RESET_GE1_MDIO;
  1020. + pdata->set_speed = qca955x_set_speed_sgmii;
  1021. + }
  1022. +
  1023. + pdata->ddr_flush = ath79_ddr_no_flush;
  1024. + pdata->has_gbit = 1;
  1025. + pdata->is_ar724x = 1;
  1026. +
  1027. + /*
  1028. + * Limit the maximum frame length to 4095 bytes.
  1029. + * Although the documentation says that the hardware
  1030. + * limit is 16383 bytes but that does not work in
  1031. + * practice. It seems that the hardware only updates
  1032. + * the lowest 12 bits of the packet length field
  1033. + * in the RX descriptor.
  1034. + */
  1035. + pdata->max_frame_len = SZ_4K - 1;
  1036. + pdata->desc_pktlen_mask = SZ_16K - 1;
  1037. +
  1038. + if (!pdata->fifo_cfg1)
  1039. + pdata->fifo_cfg1 = 0x0010ffff;
  1040. + if (!pdata->fifo_cfg2)
  1041. + pdata->fifo_cfg2 = 0x015500aa;
  1042. + if (!pdata->fifo_cfg3)
  1043. + pdata->fifo_cfg3 = 0x01f00140;
  1044. + break;
  1045. +
  1046. + default:
  1047. + BUG();
  1048. + }
  1049. +
  1050. + switch (pdata->phy_if_mode) {
  1051. + case PHY_INTERFACE_MODE_GMII:
  1052. + case PHY_INTERFACE_MODE_RGMII:
  1053. + case PHY_INTERFACE_MODE_SGMII:
  1054. + if (!pdata->has_gbit) {
  1055. + printk(KERN_ERR "ar71xx: no gbit available on eth%d\n",
  1056. + id);
  1057. + return;
  1058. + }
  1059. + /* fallthrough */
  1060. + default:
  1061. + break;
  1062. + }
  1063. +
  1064. + if (!is_valid_ether_addr(pdata->mac_addr)) {
  1065. + random_ether_addr(pdata->mac_addr);
  1066. + printk(KERN_DEBUG
  1067. + "ar71xx: using random MAC address for eth%d\n",
  1068. + ath79_eth_instance);
  1069. + }
  1070. +
  1071. + if (pdata->mii_bus_dev == NULL) {
  1072. + switch (ath79_soc) {
  1073. + case ATH79_SOC_AR9341:
  1074. + case ATH79_SOC_AR9342:
  1075. + case ATH79_SOC_AR9344:
  1076. + if (id == 0)
  1077. + pdata->mii_bus_dev = &ath79_mdio0_device.dev;
  1078. + else
  1079. + pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  1080. + break;
  1081. +
  1082. + case ATH79_SOC_AR7241:
  1083. + case ATH79_SOC_AR9330:
  1084. + case ATH79_SOC_AR9331:
  1085. + pdata->mii_bus_dev = &ath79_mdio1_device.dev;
  1086. + break;
  1087. +
  1088. + case ATH79_SOC_QCA9556:
  1089. + case ATH79_SOC_QCA9558:
  1090. + /* don't assign any MDIO device by default */
  1091. + break;
  1092. +
  1093. + default:
  1094. + pdata->mii_bus_dev = &ath79_mdio0_device.dev;
  1095. + break;
  1096. + }
  1097. + }
  1098. +
  1099. + /* Reset the device */
  1100. + ath79_device_reset_set(pdata->reset_bit);
  1101. + mdelay(100);
  1102. +
  1103. + ath79_device_reset_clear(pdata->reset_bit);
  1104. + mdelay(100);
  1105. +
  1106. + platform_device_register(pdev);
  1107. + ath79_eth_instance++;
  1108. +}
  1109. +
  1110. +void __init ath79_set_mac_base(unsigned char *mac)
  1111. +{
  1112. + memcpy(ath79_mac_base, mac, ETH_ALEN);
  1113. +}
  1114. +
  1115. +void __init ath79_parse_ascii_mac(char *mac_str, u8 *mac)
  1116. +{
  1117. + int t;
  1118. +
  1119. + t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  1120. + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  1121. +
  1122. + if (t != ETH_ALEN)
  1123. + t = sscanf(mac_str, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
  1124. + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  1125. +
  1126. + if (t != ETH_ALEN || !is_valid_ether_addr(mac)) {
  1127. + memset(mac, 0, ETH_ALEN);
  1128. + printk(KERN_DEBUG "ar71xx: invalid mac address \"%s\"\n",
  1129. + mac_str);
  1130. + }
  1131. +}
  1132. +
  1133. +static void __init ath79_set_mac_base_ascii(char *str)
  1134. +{
  1135. + u8 mac[ETH_ALEN];
  1136. +
  1137. + ath79_parse_ascii_mac(str, mac);
  1138. + ath79_set_mac_base(mac);
  1139. +}
  1140. +
  1141. +static int __init ath79_ethaddr_setup(char *str)
  1142. +{
  1143. + ath79_set_mac_base_ascii(str);
  1144. + return 1;
  1145. +}
  1146. +__setup("ethaddr=", ath79_ethaddr_setup);
  1147. +
  1148. +static int __init ath79_kmac_setup(char *str)
  1149. +{
  1150. + ath79_set_mac_base_ascii(str);
  1151. + return 1;
  1152. +}
  1153. +__setup("kmac=", ath79_kmac_setup);
  1154. +
  1155. +void __init ath79_init_mac(unsigned char *dst, const unsigned char *src,
  1156. + int offset)
  1157. +{
  1158. + int t;
  1159. +
  1160. + if (!dst)
  1161. + return;
  1162. +
  1163. + if (!src || !is_valid_ether_addr(src)) {
  1164. + memset(dst, '\0', ETH_ALEN);
  1165. + return;
  1166. + }
  1167. +
  1168. + t = (((u32) src[3]) << 16) + (((u32) src[4]) << 8) + ((u32) src[5]);
  1169. + t += offset;
  1170. +
  1171. + dst[0] = src[0];
  1172. + dst[1] = src[1];
  1173. + dst[2] = src[2];
  1174. + dst[3] = (t >> 16) & 0xff;
  1175. + dst[4] = (t >> 8) & 0xff;
  1176. + dst[5] = t & 0xff;
  1177. +}
  1178. +
  1179. +void __init ath79_init_local_mac(unsigned char *dst, const unsigned char *src)
  1180. +{
  1181. + int i;
  1182. +
  1183. + if (!dst)
  1184. + return;
  1185. +
  1186. + if (!src || !is_valid_ether_addr(src)) {
  1187. + memset(dst, '\0', ETH_ALEN);
  1188. + return;
  1189. + }
  1190. +
  1191. + for (i = 0; i < ETH_ALEN; i++)
  1192. + dst[i] = src[i];
  1193. + dst[0] |= 0x02;
  1194. +}
  1195. diff --git a/arch/mips/ath79/dev-eth.h b/arch/mips/ath79/dev-eth.h
  1196. new file mode 100644
  1197. index 0000000..ff26ec4
  1198. --- /dev/null
  1199. +++ b/arch/mips/ath79/dev-eth.h
  1200. @@ -0,0 +1,51 @@
  1201. +/*
  1202. + * Atheros AR71xx SoC device definitions
  1203. + *
  1204. + * Copyright (C) 2008-2012 Gabor Juhos <juhosg@openwrt.org>
  1205. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1206. + *
  1207. + * This program is free software; you can redistribute it and/or modify it
  1208. + * under the terms of the GNU General Public License version 2 as published
  1209. + * by the Free Software Foundation.
  1210. + */
  1211. +
  1212. +#ifndef _ATH79_DEV_ETH_H
  1213. +#define _ATH79_DEV_ETH_H
  1214. +
  1215. +#include <asm/mach-ath79/ag71xx_platform.h>
  1216. +
  1217. +struct platform_device;
  1218. +
  1219. +extern unsigned char ath79_mac_base[] __initdata;
  1220. +void ath79_parse_ascii_mac(char *mac_str, u8 *mac);
  1221. +void ath79_init_mac(unsigned char *dst, const unsigned char *src,
  1222. + int offset);
  1223. +void ath79_init_local_mac(unsigned char *dst, const unsigned char *src);
  1224. +
  1225. +struct ath79_eth_pll_data {
  1226. + u32 pll_10;
  1227. + u32 pll_100;
  1228. + u32 pll_1000;
  1229. +};
  1230. +
  1231. +extern struct ath79_eth_pll_data ath79_eth0_pll_data;
  1232. +extern struct ath79_eth_pll_data ath79_eth1_pll_data;
  1233. +
  1234. +extern struct ag71xx_platform_data ath79_eth0_data;
  1235. +extern struct ag71xx_platform_data ath79_eth1_data;
  1236. +extern struct platform_device ath79_eth0_device;
  1237. +extern struct platform_device ath79_eth1_device;
  1238. +void ath79_register_eth(unsigned int id);
  1239. +
  1240. +extern struct ag71xx_switch_platform_data ath79_switch_data;
  1241. +
  1242. +extern struct ag71xx_mdio_platform_data ath79_mdio0_data;
  1243. +extern struct ag71xx_mdio_platform_data ath79_mdio1_data;
  1244. +extern struct platform_device ath79_mdio0_device;
  1245. +extern struct platform_device ath79_mdio1_device;
  1246. +void ath79_register_mdio(unsigned int id, u32 phy_mask);
  1247. +
  1248. +void ath79_setup_ar933x_phy4_switch(bool mac, bool mdio);
  1249. +void ath79_setup_ar934x_eth_cfg(u32 mask);
  1250. +
  1251. +#endif /* _ATH79_DEV_ETH_H */
  1252. diff --git a/arch/mips/include/asm/mach-ath79/ar71xx_regs.h b/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
  1253. index cd41e93..3e6b2ed 100644
  1254. --- a/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
  1255. +++ b/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
  1256. @@ -20,6 +20,10 @@
  1257. #include <linux/bitops.h>
  1258. #define AR71XX_APB_BASE 0x18000000
  1259. +#define AR71XX_GE0_BASE 0x19000000
  1260. +#define AR71XX_GE0_SIZE 0x10000
  1261. +#define AR71XX_GE1_BASE 0x1a000000
  1262. +#define AR71XX_GE1_SIZE 0x10000
  1263. #define AR71XX_EHCI_BASE 0x1b000000
  1264. #define AR71XX_EHCI_SIZE 0x1000
  1265. #define AR71XX_OHCI_BASE 0x1c000000
  1266. @@ -39,6 +43,8 @@
  1267. #define AR71XX_PLL_SIZE 0x100
  1268. #define AR71XX_RESET_BASE (AR71XX_APB_BASE + 0x00060000)
  1269. #define AR71XX_RESET_SIZE 0x100
  1270. +#define AR71XX_MII_BASE (AR71XX_APB_BASE + 0x00070000)
  1271. +#define AR71XX_MII_SIZE 0x100
  1272. #define AR71XX_PCI_MEM_BASE 0x10000000
  1273. #define AR71XX_PCI_MEM_SIZE 0x07000000
  1274. @@ -81,11 +87,15 @@
  1275. #define AR933X_UART_BASE (AR71XX_APB_BASE + 0x00020000)
  1276. #define AR933X_UART_SIZE 0x14
  1277. +#define AR933X_GMAC_BASE (AR71XX_APB_BASE + 0x00070000)
  1278. +#define AR933X_GMAC_SIZE 0x04
  1279. #define AR933X_WMAC_BASE (AR71XX_APB_BASE + 0x00100000)
  1280. #define AR933X_WMAC_SIZE 0x20000
  1281. #define AR933X_EHCI_BASE 0x1b000000
  1282. #define AR933X_EHCI_SIZE 0x1000
  1283. +#define AR934X_GMAC_BASE (AR71XX_APB_BASE + 0x00070000)
  1284. +#define AR934X_GMAC_SIZE 0x14
  1285. #define AR934X_WMAC_BASE (AR71XX_APB_BASE + 0x00100000)
  1286. #define AR934X_WMAC_SIZE 0x20000
  1287. #define AR934X_EHCI_BASE 0x1b000000
  1288. @@ -166,6 +176,9 @@
  1289. #define AR71XX_AHB_DIV_SHIFT 20
  1290. #define AR71XX_AHB_DIV_MASK 0x7
  1291. +#define AR71XX_ETH0_PLL_SHIFT 17
  1292. +#define AR71XX_ETH1_PLL_SHIFT 19
  1293. +
  1294. #define AR724X_PLL_REG_CPU_CONFIG 0x00
  1295. #define AR724X_PLL_REG_PCIE_CONFIG 0x18
  1296. @@ -178,6 +191,8 @@
  1297. #define AR724X_DDR_DIV_SHIFT 22
  1298. #define AR724X_DDR_DIV_MASK 0x3
  1299. +#define AR7242_PLL_REG_ETH0_INT_CLOCK 0x2c
  1300. +
  1301. #define AR913X_PLL_REG_CPU_CONFIG 0x00
  1302. #define AR913X_PLL_REG_ETH_CONFIG 0x04
  1303. #define AR913X_PLL_REG_ETH0_INT_CLOCK 0x14
  1304. @@ -190,6 +205,9 @@
  1305. #define AR913X_AHB_DIV_SHIFT 19
  1306. #define AR913X_AHB_DIV_MASK 0x1
  1307. +#define AR913X_ETH0_PLL_SHIFT 20
  1308. +#define AR913X_ETH1_PLL_SHIFT 22
  1309. +
  1310. #define AR933X_PLL_CPU_CONFIG_REG 0x00
  1311. #define AR933X_PLL_CLOCK_CTRL_REG 0x08
  1312. @@ -211,6 +229,8 @@
  1313. #define AR934X_PLL_CPU_CONFIG_REG 0x00
  1314. #define AR934X_PLL_DDR_CONFIG_REG 0x04
  1315. #define AR934X_PLL_CPU_DDR_CLK_CTRL_REG 0x08
  1316. +#define AR934X_PLL_SWITCH_CLOCK_CONTROL_REG 0x24
  1317. +#define AR934X_PLL_ETH_XMII_CONTROL_REG 0x2c
  1318. #define AR934X_PLL_CPU_CONFIG_NFRAC_SHIFT 0
  1319. #define AR934X_PLL_CPU_CONFIG_NFRAC_MASK 0x3f
  1320. @@ -243,9 +263,13 @@
  1321. #define AR934X_PLL_CPU_DDR_CLK_CTRL_DDRCLK_FROM_DDRPLL BIT(21)
  1322. #define AR934X_PLL_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL BIT(24)
  1323. +#define AR934X_PLL_SWITCH_CLOCK_CONTROL_MDIO_CLK_SEL BIT(6)
  1324. +
  1325. #define QCA955X_PLL_CPU_CONFIG_REG 0x00
  1326. #define QCA955X_PLL_DDR_CONFIG_REG 0x04
  1327. #define QCA955X_PLL_CLK_CTRL_REG 0x08
  1328. +#define QCA955X_PLL_ETH_XMII_CONTROL_REG 0x28
  1329. +#define QCA955X_PLL_ETH_SGMII_CONTROL_REG 0x48
  1330. #define QCA955X_PLL_CPU_CONFIG_NFRAC_SHIFT 0
  1331. #define QCA955X_PLL_CPU_CONFIG_NFRAC_MASK 0x3f
  1332. @@ -370,16 +394,30 @@
  1333. #define AR913X_RESET_USB_HOST BIT(5)
  1334. #define AR913X_RESET_USB_PHY BIT(4)
  1335. +#define AR933X_RESET_GE1_MDIO BIT(23)
  1336. +#define AR933X_RESET_GE0_MDIO BIT(22)
  1337. +#define AR933X_RESET_GE1_MAC BIT(13)
  1338. #define AR933X_RESET_WMAC BIT(11)
  1339. +#define AR933X_RESET_GE0_MAC BIT(9)
  1340. #define AR933X_RESET_USB_HOST BIT(5)
  1341. #define AR933X_RESET_USB_PHY BIT(4)
  1342. #define AR933X_RESET_USBSUS_OVERRIDE BIT(3)
  1343. +#define AR934X_RESET_GE1_MDIO BIT(23)
  1344. +#define AR934X_RESET_GE0_MDIO BIT(22)
  1345. +#define AR934X_RESET_GE1_MAC BIT(13)
  1346. #define AR934X_RESET_USB_PHY_ANALOG BIT(11)
  1347. +#define AR934X_RESET_GE0_MAC BIT(9)
  1348. +#define AR934X_RESET_ETH_SWITCH BIT(8)
  1349. #define AR934X_RESET_USB_HOST BIT(5)
  1350. #define AR934X_RESET_USB_PHY BIT(4)
  1351. #define AR934X_RESET_USBSUS_OVERRIDE BIT(3)
  1352. +#define QCA955X_RESET_GE1_MDIO BIT(23)
  1353. +#define QCA955X_RESET_GE0_MDIO BIT(22)
  1354. +#define QCA955X_RESET_GE1_MAC BIT(13)
  1355. +#define QCA955X_RESET_GE0_MAC BIT(9)
  1356. +
  1357. #define AR933X_BOOTSTRAP_REF_CLK_40 BIT(0)
  1358. #define AR934X_BOOTSTRAP_SW_OPTION8 BIT(23)
  1359. @@ -552,4 +590,47 @@
  1360. #define AR934X_SRIF_DPLL2_OUTDIV_SHIFT 13
  1361. #define AR934X_SRIF_DPLL2_OUTDIV_MASK 0x7
  1362. +#define AR71XX_GPIO_FUNC_SPI_CS2_EN BIT(13)
  1363. +#define AR71XX_GPIO_FUNC_SPI_CS1_EN BIT(12)
  1364. +
  1365. +/*
  1366. + * MII_CTRL block
  1367. + */
  1368. +#define AR71XX_MII_REG_MII0_CTRL 0x00
  1369. +#define AR71XX_MII_REG_MII1_CTRL 0x04
  1370. +
  1371. +#define AR71XX_MII_CTRL_IF_MASK 3
  1372. +#define AR71XX_MII_CTRL_SPEED_SHIFT 4
  1373. +#define AR71XX_MII_CTRL_SPEED_MASK 3
  1374. +#define AR71XX_MII_CTRL_SPEED_10 0
  1375. +#define AR71XX_MII_CTRL_SPEED_100 1
  1376. +#define AR71XX_MII_CTRL_SPEED_1000 2
  1377. +
  1378. +#define AR71XX_MII0_CTRL_IF_GMII 0
  1379. +#define AR71XX_MII0_CTRL_IF_MII 1
  1380. +#define AR71XX_MII0_CTRL_IF_RGMII 2
  1381. +#define AR71XX_MII0_CTRL_IF_RMII 3
  1382. +
  1383. +#define AR71XX_MII1_CTRL_IF_RGMII 0
  1384. +#define AR71XX_MII1_CTRL_IF_RMII 1
  1385. +
  1386. +/*
  1387. + * AR933X GMAC interface
  1388. + */
  1389. +#define AR933X_GMAC_REG_ETH_CFG 0x00
  1390. +
  1391. +#define AR933X_ETH_CFG_SW_PHY_SWAP BIT(7)
  1392. +#define AR933X_ETH_CFG_SW_PHY_ADDR_SWAP BIT(8)
  1393. +
  1394. +/*
  1395. + * AR934X GMAC Interface
  1396. + */
  1397. +#define AR934X_GMAC_REG_ETH_CFG 0x00
  1398. +
  1399. +#define AR934X_ETH_CFG_RGMII_GMAC0 BIT(0)
  1400. +#define AR934X_ETH_CFG_MII_GMAC0 BIT(1)
  1401. +#define AR934X_ETH_CFG_GMII_GMAC0 BIT(2)
  1402. +#define AR934X_ETH_CFG_SW_ONLY_MODE BIT(6)
  1403. +#define AR934X_ETH_CFG_SW_PHY_SWAP BIT(7)
  1404. +
  1405. #endif /* __ASM_MACH_AR71XX_REGS_H */
  1406. --
  1407. 1.8.5.3