2 * Atheros AR71xx SoC platform devices
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>
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
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.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
19 #include <linux/etherdevice.h>
20 #include <linux/platform_device.h>
21 #include <linux/serial_8250.h>
22 #include <linux/clk.h>
23 #include <linux/sizes.h>
25 #include <asm/mach-ath79/ath79.h>
26 #include <asm/mach-ath79/ar71xx_regs.h>
27 #include <asm/mach-ath79/irq.h>
32 unsigned char ath79_mac_base
[ETH_ALEN
] __initdata
;
34 static struct resource ath79_mdio0_resources
[] = {
37 .flags
= IORESOURCE_MEM
,
38 .start
= AR71XX_GE0_BASE
,
39 .end
= AR71XX_GE0_BASE
+ 0x200 - 1,
43 struct ag71xx_mdio_platform_data ath79_mdio0_data
;
45 struct platform_device ath79_mdio0_device
= {
46 .name
= "ag71xx-mdio",
48 .resource
= ath79_mdio0_resources
,
49 .num_resources
= ARRAY_SIZE(ath79_mdio0_resources
),
51 .platform_data
= &ath79_mdio0_data
,
55 static struct resource ath79_mdio1_resources
[] = {
58 .flags
= IORESOURCE_MEM
,
59 .start
= AR71XX_GE1_BASE
,
60 .end
= AR71XX_GE1_BASE
+ 0x200 - 1,
64 struct ag71xx_mdio_platform_data ath79_mdio1_data
;
66 struct platform_device ath79_mdio1_device
= {
67 .name
= "ag71xx-mdio",
69 .resource
= ath79_mdio1_resources
,
70 .num_resources
= ARRAY_SIZE(ath79_mdio1_resources
),
72 .platform_data
= &ath79_mdio1_data
,
76 static void ath79_set_pll(u32 cfg_reg
, u32 pll_reg
, u32 pll_val
, u32 shift
)
81 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
83 t
= __raw_readl(base
+ cfg_reg
);
86 __raw_writel(t
, base
+ cfg_reg
);
89 __raw_writel(pll_val
, base
+ pll_reg
);
92 __raw_writel(t
, base
+ cfg_reg
);
96 __raw_writel(t
, base
+ cfg_reg
);
99 printk(KERN_DEBUG
"ar71xx: pll_reg %#x: %#x\n",
100 (unsigned int)(base
+ pll_reg
), __raw_readl(base
+ pll_reg
));
105 static void __init
ath79_mii_ctrl_set_if(unsigned int reg
,
111 base
= ioremap(AR71XX_MII_BASE
, AR71XX_MII_SIZE
);
113 t
= __raw_readl(base
+ reg
);
114 t
&= ~(AR71XX_MII_CTRL_IF_MASK
);
115 t
|= (mii_if
& AR71XX_MII_CTRL_IF_MASK
);
116 __raw_writel(t
, base
+ reg
);
121 static void ath79_mii_ctrl_set_speed(unsigned int reg
, unsigned int speed
)
124 unsigned int mii_speed
;
129 mii_speed
= AR71XX_MII_CTRL_SPEED_10
;
132 mii_speed
= AR71XX_MII_CTRL_SPEED_100
;
135 mii_speed
= AR71XX_MII_CTRL_SPEED_1000
;
141 base
= ioremap(AR71XX_MII_BASE
, AR71XX_MII_SIZE
);
143 t
= __raw_readl(base
+ reg
);
144 t
&= ~(AR71XX_MII_CTRL_SPEED_MASK
<< AR71XX_MII_CTRL_SPEED_SHIFT
);
145 t
|= mii_speed
<< AR71XX_MII_CTRL_SPEED_SHIFT
;
146 __raw_writel(t
, base
+ reg
);
151 static unsigned long ar934x_get_mdio_ref_clock(void)
157 base
= ioremap(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
160 t
= __raw_readl(base
+ AR934X_PLL_SWITCH_CLOCK_CONTROL_REG
);
161 if (t
& AR934X_PLL_SWITCH_CLOCK_CONTROL_MDIO_CLK_SEL
) {
162 ret
= 100 * 1000 * 1000;
166 clk
= clk_get(NULL
, "ref");
168 ret
= clk_get_rate(clk
);
176 void __init
ath79_register_mdio(unsigned int id
, u32 phy_mask
)
178 struct platform_device
*mdio_dev
;
179 struct ag71xx_mdio_platform_data
*mdio_data
;
182 if (ath79_soc
== ATH79_SOC_AR9341
||
183 ath79_soc
== ATH79_SOC_AR9342
||
184 ath79_soc
== ATH79_SOC_AR9344
||
185 ath79_soc
== ATH79_SOC_QCA9556
||
186 ath79_soc
== ATH79_SOC_QCA9558
||
187 ath79_soc
== ATH79_SOC_QCA956X
)
193 printk(KERN_ERR
"ar71xx: invalid MDIO id %u\n", id
);
198 case ATH79_SOC_AR7241
:
199 case ATH79_SOC_AR9330
:
200 case ATH79_SOC_AR9331
:
201 case ATH79_SOC_QCA9533
:
202 case ATH79_SOC_TP9343
:
203 mdio_dev
= &ath79_mdio1_device
;
204 mdio_data
= &ath79_mdio1_data
;
207 case ATH79_SOC_AR9341
:
208 case ATH79_SOC_AR9342
:
209 case ATH79_SOC_AR9344
:
210 case ATH79_SOC_QCA9556
:
211 case ATH79_SOC_QCA9558
:
212 case ATH79_SOC_QCA956X
:
214 mdio_dev
= &ath79_mdio0_device
;
215 mdio_data
= &ath79_mdio0_data
;
217 mdio_dev
= &ath79_mdio1_device
;
218 mdio_data
= &ath79_mdio1_data
;
222 case ATH79_SOC_AR7242
:
223 ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG
,
224 AR7242_PLL_REG_ETH0_INT_CLOCK
, 0x62000000,
225 AR71XX_ETH0_PLL_SHIFT
);
228 mdio_dev
= &ath79_mdio0_device
;
229 mdio_data
= &ath79_mdio0_data
;
233 mdio_data
->phy_mask
= phy_mask
;
236 case ATH79_SOC_AR7240
:
237 mdio_data
->is_ar7240
= 1;
239 case ATH79_SOC_AR7241
:
240 mdio_data
->builtin_switch
= 1;
243 case ATH79_SOC_AR9330
:
244 mdio_data
->is_ar9330
= 1;
246 case ATH79_SOC_AR9331
:
247 mdio_data
->builtin_switch
= 1;
250 case ATH79_SOC_AR9341
:
251 case ATH79_SOC_AR9342
:
252 case ATH79_SOC_AR9344
:
254 mdio_data
->builtin_switch
= 1;
255 mdio_data
->ref_clock
= ar934x_get_mdio_ref_clock();
256 mdio_data
->mdio_clock
= 6250000;
258 mdio_data
->is_ar934x
= 1;
261 case ATH79_SOC_QCA9533
:
262 case ATH79_SOC_TP9343
:
263 mdio_data
->builtin_switch
= 1;
266 case ATH79_SOC_QCA9556
:
267 case ATH79_SOC_QCA9558
:
268 mdio_data
->is_ar934x
= 1;
271 case ATH79_SOC_QCA956X
:
273 mdio_data
->builtin_switch
= 1;
274 mdio_data
->is_ar934x
= 1;
281 platform_device_register(mdio_dev
);
284 struct ath79_eth_pll_data ath79_eth0_pll_data
;
285 struct ath79_eth_pll_data ath79_eth1_pll_data
;
287 static u32
ath79_get_eth_pll(unsigned int mac
, int speed
)
289 struct ath79_eth_pll_data
*pll_data
;
294 pll_data
= &ath79_eth0_pll_data
;
297 pll_data
= &ath79_eth1_pll_data
;
305 pll_val
= pll_data
->pll_10
;
308 pll_val
= pll_data
->pll_100
;
311 pll_val
= pll_data
->pll_1000
;
320 static void ath79_set_speed_ge0(int speed
)
322 u32 val
= ath79_get_eth_pll(0, speed
);
324 ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR71XX_PLL_REG_ETH0_INT_CLOCK
,
325 val
, AR71XX_ETH0_PLL_SHIFT
);
326 ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL
, speed
);
329 static void ath79_set_speed_ge1(int speed
)
331 u32 val
= ath79_get_eth_pll(1, speed
);
333 ath79_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR71XX_PLL_REG_ETH1_INT_CLOCK
,
334 val
, AR71XX_ETH1_PLL_SHIFT
);
335 ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL
, speed
);
338 static void ar7242_set_speed_ge0(int speed
)
340 u32 val
= ath79_get_eth_pll(0, speed
);
343 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
344 __raw_writel(val
, base
+ AR7242_PLL_REG_ETH0_INT_CLOCK
);
348 static void ar91xx_set_speed_ge0(int speed
)
350 u32 val
= ath79_get_eth_pll(0, speed
);
352 ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG
, AR913X_PLL_REG_ETH0_INT_CLOCK
,
353 val
, AR913X_ETH0_PLL_SHIFT
);
354 ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII0_CTRL
, speed
);
357 static void ar91xx_set_speed_ge1(int speed
)
359 u32 val
= ath79_get_eth_pll(1, speed
);
361 ath79_set_pll(AR913X_PLL_REG_ETH_CONFIG
, AR913X_PLL_REG_ETH1_INT_CLOCK
,
362 val
, AR913X_ETH1_PLL_SHIFT
);
363 ath79_mii_ctrl_set_speed(AR71XX_MII_REG_MII1_CTRL
, speed
);
366 static void ar934x_set_speed_ge0(int speed
)
369 u32 val
= ath79_get_eth_pll(0, speed
);
371 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
372 __raw_writel(val
, base
+ AR934X_PLL_ETH_XMII_CONTROL_REG
);
376 static void qca955x_set_speed_xmii(int speed
)
379 u32 val
= ath79_get_eth_pll(0, speed
);
381 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
382 __raw_writel(val
, base
+ QCA955X_PLL_ETH_XMII_CONTROL_REG
);
386 static void qca955x_set_speed_sgmii(int speed
)
389 u32 val
= ath79_get_eth_pll(1, speed
);
391 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
392 __raw_writel(val
, base
+ QCA955X_PLL_ETH_SGMII_CONTROL_REG
);
396 static void qca956x_set_speed_sgmii(int speed
)
399 u32 val
= ath79_get_eth_pll(0, speed
);
401 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
402 __raw_writel(val
, base
+ QCA955X_PLL_ETH_SGMII_CONTROL_REG
);
406 static void ath79_set_speed_dummy(int speed
)
410 static void ath79_ddr_flush_ge0(void)
412 ath79_ddr_wb_flush(0);
415 static void ath79_ddr_flush_ge1(void)
417 ath79_ddr_wb_flush(1);
420 static struct resource ath79_eth0_resources
[] = {
423 .flags
= IORESOURCE_MEM
,
424 .start
= AR71XX_GE0_BASE
,
425 .end
= AR71XX_GE0_BASE
+ 0x200 - 1,
428 .flags
= IORESOURCE_IRQ
,
429 .start
= ATH79_CPU_IRQ(4),
430 .end
= ATH79_CPU_IRQ(4),
434 struct ag71xx_platform_data ath79_eth0_data
= {
435 .reset_bit
= AR71XX_RESET_GE0_MAC
,
438 struct platform_device ath79_eth0_device
= {
441 .resource
= ath79_eth0_resources
,
442 .num_resources
= ARRAY_SIZE(ath79_eth0_resources
),
444 .platform_data
= &ath79_eth0_data
,
448 static struct resource ath79_eth1_resources
[] = {
451 .flags
= IORESOURCE_MEM
,
452 .start
= AR71XX_GE1_BASE
,
453 .end
= AR71XX_GE1_BASE
+ 0x200 - 1,
456 .flags
= IORESOURCE_IRQ
,
457 .start
= ATH79_CPU_IRQ(5),
458 .end
= ATH79_CPU_IRQ(5),
462 struct ag71xx_platform_data ath79_eth1_data
= {
463 .reset_bit
= AR71XX_RESET_GE1_MAC
,
466 struct platform_device ath79_eth1_device
= {
469 .resource
= ath79_eth1_resources
,
470 .num_resources
= ARRAY_SIZE(ath79_eth1_resources
),
472 .platform_data
= &ath79_eth1_data
,
476 struct ag71xx_switch_platform_data ath79_switch_data
;
478 #define AR71XX_PLL_VAL_1000 0x00110000
479 #define AR71XX_PLL_VAL_100 0x00001099
480 #define AR71XX_PLL_VAL_10 0x00991099
482 #define AR724X_PLL_VAL_1000 0x00110000
483 #define AR724X_PLL_VAL_100 0x00001099
484 #define AR724X_PLL_VAL_10 0x00991099
486 #define AR7242_PLL_VAL_1000 0x16000000
487 #define AR7242_PLL_VAL_100 0x00000101
488 #define AR7242_PLL_VAL_10 0x00001616
490 #define AR913X_PLL_VAL_1000 0x1a000000
491 #define AR913X_PLL_VAL_100 0x13000a44
492 #define AR913X_PLL_VAL_10 0x00441099
494 #define AR933X_PLL_VAL_1000 0x00110000
495 #define AR933X_PLL_VAL_100 0x00001099
496 #define AR933X_PLL_VAL_10 0x00991099
498 #define AR934X_PLL_VAL_1000 0x16000000
499 #define AR934X_PLL_VAL_100 0x00000101
500 #define AR934X_PLL_VAL_10 0x00001616
502 #define QCA956X_PLL_VAL_1000 0x03000000
503 #define QCA956X_PLL_VAL_100 0x00000101
504 #define QCA956X_PLL_VAL_10 0x00001919
506 static void __init
ath79_init_eth_pll_data(unsigned int id
)
508 struct ath79_eth_pll_data
*pll_data
;
509 u32 pll_10
, pll_100
, pll_1000
;
513 pll_data
= &ath79_eth0_pll_data
;
516 pll_data
= &ath79_eth1_pll_data
;
523 case ATH79_SOC_AR7130
:
524 case ATH79_SOC_AR7141
:
525 case ATH79_SOC_AR7161
:
526 pll_10
= AR71XX_PLL_VAL_10
;
527 pll_100
= AR71XX_PLL_VAL_100
;
528 pll_1000
= AR71XX_PLL_VAL_1000
;
531 case ATH79_SOC_AR7240
:
532 case ATH79_SOC_AR7241
:
533 pll_10
= AR724X_PLL_VAL_10
;
534 pll_100
= AR724X_PLL_VAL_100
;
535 pll_1000
= AR724X_PLL_VAL_1000
;
538 case ATH79_SOC_AR7242
:
539 pll_10
= AR7242_PLL_VAL_10
;
540 pll_100
= AR7242_PLL_VAL_100
;
541 pll_1000
= AR7242_PLL_VAL_1000
;
544 case ATH79_SOC_AR9130
:
545 case ATH79_SOC_AR9132
:
546 pll_10
= AR913X_PLL_VAL_10
;
547 pll_100
= AR913X_PLL_VAL_100
;
548 pll_1000
= AR913X_PLL_VAL_1000
;
551 case ATH79_SOC_AR9330
:
552 case ATH79_SOC_AR9331
:
553 pll_10
= AR933X_PLL_VAL_10
;
554 pll_100
= AR933X_PLL_VAL_100
;
555 pll_1000
= AR933X_PLL_VAL_1000
;
558 case ATH79_SOC_AR9341
:
559 case ATH79_SOC_AR9342
:
560 case ATH79_SOC_AR9344
:
561 case ATH79_SOC_QCA9533
:
562 case ATH79_SOC_QCA9556
:
563 case ATH79_SOC_QCA9558
:
564 case ATH79_SOC_TP9343
:
565 pll_10
= AR934X_PLL_VAL_10
;
566 pll_100
= AR934X_PLL_VAL_100
;
567 pll_1000
= AR934X_PLL_VAL_1000
;
570 case ATH79_SOC_QCA956X
:
571 pll_10
= QCA956X_PLL_VAL_10
;
572 pll_100
= QCA956X_PLL_VAL_100
;
573 pll_1000
= QCA956X_PLL_VAL_1000
;
580 if (!pll_data
->pll_10
)
581 pll_data
->pll_10
= pll_10
;
583 if (!pll_data
->pll_100
)
584 pll_data
->pll_100
= pll_100
;
586 if (!pll_data
->pll_1000
)
587 pll_data
->pll_1000
= pll_1000
;
590 static int __init
ath79_setup_phy_if_mode(unsigned int id
,
591 struct ag71xx_platform_data
*pdata
)
598 case ATH79_SOC_AR7130
:
599 case ATH79_SOC_AR7141
:
600 case ATH79_SOC_AR7161
:
601 case ATH79_SOC_AR9130
:
602 case ATH79_SOC_AR9132
:
603 switch (pdata
->phy_if_mode
) {
604 case PHY_INTERFACE_MODE_MII
:
605 mii_if
= AR71XX_MII0_CTRL_IF_MII
;
607 case PHY_INTERFACE_MODE_GMII
:
608 mii_if
= AR71XX_MII0_CTRL_IF_GMII
;
610 case PHY_INTERFACE_MODE_RGMII
:
611 mii_if
= AR71XX_MII0_CTRL_IF_RGMII
;
613 case PHY_INTERFACE_MODE_RMII
:
614 mii_if
= AR71XX_MII0_CTRL_IF_RMII
;
619 ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII0_CTRL
, mii_if
);
622 case ATH79_SOC_AR7240
:
623 case ATH79_SOC_AR7241
:
624 case ATH79_SOC_AR9330
:
625 case ATH79_SOC_AR9331
:
626 case ATH79_SOC_QCA9533
:
627 case ATH79_SOC_TP9343
:
628 pdata
->phy_if_mode
= PHY_INTERFACE_MODE_MII
;
631 case ATH79_SOC_AR7242
:
634 case ATH79_SOC_AR9341
:
635 case ATH79_SOC_AR9342
:
636 case ATH79_SOC_AR9344
:
637 switch (pdata
->phy_if_mode
) {
638 case PHY_INTERFACE_MODE_MII
:
639 case PHY_INTERFACE_MODE_GMII
:
640 case PHY_INTERFACE_MODE_RGMII
:
641 case PHY_INTERFACE_MODE_RMII
:
648 case ATH79_SOC_QCA9556
:
649 case ATH79_SOC_QCA9558
:
650 case ATH79_SOC_QCA956X
:
651 switch (pdata
->phy_if_mode
) {
652 case PHY_INTERFACE_MODE_MII
:
653 case PHY_INTERFACE_MODE_RGMII
:
654 case PHY_INTERFACE_MODE_SGMII
:
667 case ATH79_SOC_AR7130
:
668 case ATH79_SOC_AR7141
:
669 case ATH79_SOC_AR7161
:
670 case ATH79_SOC_AR9130
:
671 case ATH79_SOC_AR9132
:
672 switch (pdata
->phy_if_mode
) {
673 case PHY_INTERFACE_MODE_RMII
:
674 mii_if
= AR71XX_MII1_CTRL_IF_RMII
;
676 case PHY_INTERFACE_MODE_RGMII
:
677 mii_if
= AR71XX_MII1_CTRL_IF_RGMII
;
682 ath79_mii_ctrl_set_if(AR71XX_MII_REG_MII1_CTRL
, mii_if
);
685 case ATH79_SOC_AR7240
:
686 case ATH79_SOC_AR7241
:
687 case ATH79_SOC_AR9330
:
688 case ATH79_SOC_AR9331
:
689 case ATH79_SOC_QCA956X
:
690 case ATH79_SOC_TP9343
:
691 pdata
->phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
694 case ATH79_SOC_AR7242
:
697 case ATH79_SOC_AR9341
:
698 case ATH79_SOC_AR9342
:
699 case ATH79_SOC_AR9344
:
700 case ATH79_SOC_QCA9533
:
701 switch (pdata
->phy_if_mode
) {
702 case PHY_INTERFACE_MODE_MII
:
703 case PHY_INTERFACE_MODE_GMII
:
710 case ATH79_SOC_QCA9556
:
711 case ATH79_SOC_QCA9558
:
712 switch (pdata
->phy_if_mode
) {
713 case PHY_INTERFACE_MODE_MII
:
714 case PHY_INTERFACE_MODE_RGMII
:
715 case PHY_INTERFACE_MODE_SGMII
:
731 void __init
ath79_setup_ar933x_phy4_switch(bool mac
, bool mdio
)
736 base
= ioremap(AR933X_GMAC_BASE
, AR933X_GMAC_SIZE
);
738 t
= __raw_readl(base
+ AR933X_GMAC_REG_ETH_CFG
);
739 t
&= ~(AR933X_ETH_CFG_SW_PHY_SWAP
| AR933X_ETH_CFG_SW_PHY_ADDR_SWAP
);
741 t
|= AR933X_ETH_CFG_SW_PHY_SWAP
;
743 t
|= AR933X_ETH_CFG_SW_PHY_ADDR_SWAP
;
744 __raw_writel(t
, base
+ AR933X_GMAC_REG_ETH_CFG
);
749 void __init
ath79_setup_ar934x_eth_cfg(u32 mask
)
754 base
= ioremap(AR934X_GMAC_BASE
, AR934X_GMAC_SIZE
);
756 t
= __raw_readl(base
+ AR934X_GMAC_REG_ETH_CFG
);
758 t
&= ~(AR934X_ETH_CFG_RGMII_GMAC0
|
759 AR934X_ETH_CFG_MII_GMAC0
|
760 AR934X_ETH_CFG_GMII_GMAC0
|
761 AR934X_ETH_CFG_SW_ONLY_MODE
|
762 AR934X_ETH_CFG_SW_PHY_SWAP
);
766 __raw_writel(t
, base
+ AR934X_GMAC_REG_ETH_CFG
);
768 __raw_readl(base
+ AR934X_GMAC_REG_ETH_CFG
);
773 void __init
ath79_setup_ar934x_eth_rx_delay(unsigned int rxd
,
779 rxd
&= AR934X_ETH_CFG_RXD_DELAY_MASK
;
780 rxdv
&= AR934X_ETH_CFG_RDV_DELAY_MASK
;
782 base
= ioremap(AR934X_GMAC_BASE
, AR934X_GMAC_SIZE
);
784 t
= __raw_readl(base
+ AR934X_GMAC_REG_ETH_CFG
);
786 t
&= ~(AR934X_ETH_CFG_RXD_DELAY_MASK
<< AR934X_ETH_CFG_RXD_DELAY_SHIFT
|
787 AR934X_ETH_CFG_RDV_DELAY_MASK
<< AR934X_ETH_CFG_RDV_DELAY_SHIFT
);
789 t
|= (rxd
<< AR934X_ETH_CFG_RXD_DELAY_SHIFT
|
790 rxdv
<< AR934X_ETH_CFG_RDV_DELAY_SHIFT
);
792 __raw_writel(t
, base
+ AR934X_GMAC_REG_ETH_CFG
);
794 __raw_readl(base
+ AR934X_GMAC_REG_ETH_CFG
);
799 void __init
ath79_setup_qca955x_eth_cfg(u32 mask
)
804 base
= ioremap(QCA955X_GMAC_BASE
, QCA955X_GMAC_SIZE
);
806 t
= __raw_readl(base
+ QCA955X_GMAC_REG_ETH_CFG
);
808 t
&= ~(QCA955X_ETH_CFG_RGMII_EN
| QCA955X_ETH_CFG_GE0_SGMII
);
812 __raw_writel(t
, base
+ QCA955X_GMAC_REG_ETH_CFG
);
817 static int ath79_eth_instance __initdata
;
818 void __init
ath79_register_eth(unsigned int id
)
820 struct platform_device
*pdev
;
821 struct ag71xx_platform_data
*pdata
;
825 printk(KERN_ERR
"ar71xx: invalid ethernet id %d\n", id
);
829 ath79_init_eth_pll_data(id
);
832 pdev
= &ath79_eth0_device
;
834 pdev
= &ath79_eth1_device
;
836 pdata
= pdev
->dev
.platform_data
;
838 pdata
->max_frame_len
= 1540;
839 pdata
->desc_pktlen_mask
= 0xfff;
841 err
= ath79_setup_phy_if_mode(id
, pdata
);
844 "ar71xx: invalid PHY interface mode for GE%u\n", id
);
849 pdata
->ddr_flush
= ath79_ddr_flush_ge0
;
851 pdata
->ddr_flush
= ath79_ddr_flush_ge1
;
854 case ATH79_SOC_AR7130
:
856 pdata
->set_speed
= ath79_set_speed_ge0
;
858 pdata
->set_speed
= ath79_set_speed_ge1
;
861 case ATH79_SOC_AR7141
:
862 case ATH79_SOC_AR7161
:
864 pdata
->set_speed
= ath79_set_speed_ge0
;
866 pdata
->set_speed
= ath79_set_speed_ge1
;
870 case ATH79_SOC_AR7242
:
872 pdata
->reset_bit
|= AR724X_RESET_GE0_MDIO
|
873 AR71XX_RESET_GE0_PHY
;
874 pdata
->set_speed
= ar7242_set_speed_ge0
;
876 pdata
->reset_bit
|= AR724X_RESET_GE1_MDIO
|
877 AR71XX_RESET_GE1_PHY
;
878 pdata
->set_speed
= ath79_set_speed_dummy
;
881 pdata
->is_ar724x
= 1;
883 if (!pdata
->fifo_cfg1
)
884 pdata
->fifo_cfg1
= 0x0010ffff;
885 if (!pdata
->fifo_cfg2
)
886 pdata
->fifo_cfg2
= 0x015500aa;
887 if (!pdata
->fifo_cfg3
)
888 pdata
->fifo_cfg3
= 0x01f00140;
891 case ATH79_SOC_AR7241
:
893 pdata
->reset_bit
|= AR724X_RESET_GE0_MDIO
;
895 pdata
->reset_bit
|= AR724X_RESET_GE1_MDIO
;
897 case ATH79_SOC_AR7240
:
899 pdata
->reset_bit
|= AR71XX_RESET_GE0_PHY
;
900 pdata
->set_speed
= ath79_set_speed_dummy
;
902 pdata
->phy_mask
= BIT(4);
904 pdata
->reset_bit
|= AR71XX_RESET_GE1_PHY
;
905 pdata
->set_speed
= ath79_set_speed_dummy
;
907 pdata
->speed
= SPEED_1000
;
908 pdata
->duplex
= DUPLEX_FULL
;
909 pdata
->switch_data
= &ath79_switch_data
;
910 pdata
->use_flow_control
= 1;
912 ath79_switch_data
.phy_poll_mask
|= BIT(4);
915 pdata
->is_ar724x
= 1;
916 if (ath79_soc
== ATH79_SOC_AR7240
)
917 pdata
->is_ar7240
= 1;
919 if (!pdata
->fifo_cfg1
)
920 pdata
->fifo_cfg1
= 0x0010ffff;
921 if (!pdata
->fifo_cfg2
)
922 pdata
->fifo_cfg2
= 0x015500aa;
923 if (!pdata
->fifo_cfg3
)
924 pdata
->fifo_cfg3
= 0x01f00140;
927 case ATH79_SOC_AR9132
:
930 case ATH79_SOC_AR9130
:
932 pdata
->set_speed
= ar91xx_set_speed_ge0
;
934 pdata
->set_speed
= ar91xx_set_speed_ge1
;
935 pdata
->is_ar91xx
= 1;
938 case ATH79_SOC_AR9330
:
939 case ATH79_SOC_AR9331
:
941 pdata
->reset_bit
= AR933X_RESET_GE0_MAC
|
942 AR933X_RESET_GE0_MDIO
;
943 pdata
->set_speed
= ath79_set_speed_dummy
;
945 pdata
->phy_mask
= BIT(4);
947 pdata
->reset_bit
= AR933X_RESET_GE1_MAC
|
948 AR933X_RESET_GE1_MDIO
;
949 pdata
->set_speed
= ath79_set_speed_dummy
;
951 pdata
->speed
= SPEED_1000
;
953 pdata
->duplex
= DUPLEX_FULL
;
954 pdata
->switch_data
= &ath79_switch_data
;
955 pdata
->use_flow_control
= 1;
957 ath79_switch_data
.phy_poll_mask
|= BIT(4);
960 pdata
->is_ar724x
= 1;
962 if (!pdata
->fifo_cfg1
)
963 pdata
->fifo_cfg1
= 0x0010ffff;
964 if (!pdata
->fifo_cfg2
)
965 pdata
->fifo_cfg2
= 0x015500aa;
966 if (!pdata
->fifo_cfg3
)
967 pdata
->fifo_cfg3
= 0x01f00140;
970 case ATH79_SOC_AR9341
:
971 case ATH79_SOC_AR9342
:
972 case ATH79_SOC_AR9344
:
973 case ATH79_SOC_QCA9533
:
975 pdata
->reset_bit
= AR934X_RESET_GE0_MAC
|
976 AR934X_RESET_GE0_MDIO
;
977 pdata
->set_speed
= ar934x_set_speed_ge0
;
979 pdata
->reset_bit
= AR934X_RESET_GE1_MAC
|
980 AR934X_RESET_GE1_MDIO
;
981 pdata
->set_speed
= ath79_set_speed_dummy
;
983 pdata
->switch_data
= &ath79_switch_data
;
984 pdata
->use_flow_control
= 1;
986 /* reset the built-in switch */
987 ath79_device_reset_set(AR934X_RESET_ETH_SWITCH
);
988 ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH
);
992 pdata
->is_ar724x
= 1;
994 pdata
->max_frame_len
= SZ_16K
- 1;
995 pdata
->desc_pktlen_mask
= SZ_16K
- 1;
997 if (!pdata
->fifo_cfg1
)
998 pdata
->fifo_cfg1
= 0x0010ffff;
999 if (!pdata
->fifo_cfg2
)
1000 pdata
->fifo_cfg2
= 0x015500aa;
1001 if (!pdata
->fifo_cfg3
)
1002 pdata
->fifo_cfg3
= 0x01f00140;
1005 case ATH79_SOC_TP9343
:
1007 pdata
->reset_bit
= AR933X_RESET_GE0_MAC
|
1008 AR933X_RESET_GE0_MDIO
;
1009 pdata
->set_speed
= ath79_set_speed_dummy
;
1011 if (!pdata
->phy_mask
)
1012 pdata
->phy_mask
= BIT(4);
1014 pdata
->reset_bit
= AR933X_RESET_GE1_MAC
|
1015 AR933X_RESET_GE1_MDIO
;
1016 pdata
->set_speed
= ath79_set_speed_dummy
;
1018 pdata
->speed
= SPEED_1000
;
1019 pdata
->duplex
= DUPLEX_FULL
;
1020 pdata
->switch_data
= &ath79_switch_data
;
1021 pdata
->use_flow_control
= 1;
1023 ath79_switch_data
.phy_poll_mask
|= BIT(4);
1026 pdata
->has_gbit
= 1;
1027 pdata
->is_ar724x
= 1;
1029 if (!pdata
->fifo_cfg1
)
1030 pdata
->fifo_cfg1
= 0x0010ffff;
1031 if (!pdata
->fifo_cfg2
)
1032 pdata
->fifo_cfg2
= 0x015500aa;
1033 if (!pdata
->fifo_cfg3
)
1034 pdata
->fifo_cfg3
= 0x01f00140;
1037 case ATH79_SOC_QCA9556
:
1038 case ATH79_SOC_QCA9558
:
1040 pdata
->reset_bit
= QCA955X_RESET_GE0_MAC
|
1041 QCA955X_RESET_GE0_MDIO
;
1042 pdata
->set_speed
= qca955x_set_speed_xmii
;
1044 pdata
->reset_bit
= QCA955X_RESET_GE1_MAC
|
1045 QCA955X_RESET_GE1_MDIO
;
1046 pdata
->set_speed
= qca955x_set_speed_sgmii
;
1047 pdata
->use_flow_control
= 1;
1050 pdata
->has_gbit
= 1;
1051 pdata
->is_ar724x
= 1;
1054 * Limit the maximum frame length to 4095 bytes.
1055 * Although the documentation says that the hardware
1056 * limit is 16383 bytes but that does not work in
1057 * practice. It seems that the hardware only updates
1058 * the lowest 12 bits of the packet length field
1059 * in the RX descriptor.
1061 pdata
->max_frame_len
= SZ_4K
- 1;
1062 pdata
->desc_pktlen_mask
= SZ_16K
- 1;
1064 if (!pdata
->fifo_cfg1
)
1065 pdata
->fifo_cfg1
= 0x0010ffff;
1066 if (!pdata
->fifo_cfg2
)
1067 pdata
->fifo_cfg2
= 0x015500aa;
1068 if (!pdata
->fifo_cfg3
)
1069 pdata
->fifo_cfg3
= 0x01f00140;
1072 case ATH79_SOC_QCA956X
:
1074 pdata
->reset_bit
= QCA955X_RESET_GE0_MAC
|
1075 QCA955X_RESET_GE0_MDIO
;
1077 if (pdata
->phy_if_mode
== PHY_INTERFACE_MODE_SGMII
)
1078 pdata
->set_speed
= qca956x_set_speed_sgmii
;
1080 pdata
->set_speed
= ath79_set_speed_ge0
;
1082 pdata
->reset_bit
= QCA955X_RESET_GE1_MAC
|
1083 QCA955X_RESET_GE1_MDIO
;
1085 pdata
->set_speed
= ath79_set_speed_dummy
;
1087 pdata
->switch_data
= &ath79_switch_data
;
1089 pdata
->speed
= SPEED_1000
;
1090 pdata
->duplex
= DUPLEX_FULL
;
1091 pdata
->use_flow_control
= 1;
1093 /* reset the built-in switch */
1094 ath79_device_reset_set(AR934X_RESET_ETH_SWITCH
);
1095 ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH
);
1098 pdata
->has_gbit
= 1;
1099 pdata
->is_ar724x
= 1;
1101 if (!pdata
->fifo_cfg1
)
1102 pdata
->fifo_cfg1
= 0x0010ffff;
1103 if (!pdata
->fifo_cfg2
)
1104 pdata
->fifo_cfg2
= 0x015500aa;
1105 if (!pdata
->fifo_cfg3
)
1106 pdata
->fifo_cfg3
= 0x01f00140;
1113 switch (pdata
->phy_if_mode
) {
1114 case PHY_INTERFACE_MODE_GMII
:
1115 case PHY_INTERFACE_MODE_RGMII
:
1116 case PHY_INTERFACE_MODE_SGMII
:
1117 if (!pdata
->has_gbit
) {
1118 printk(KERN_ERR
"ar71xx: no gbit available on eth%d\n",
1127 if (!is_valid_ether_addr(pdata
->mac_addr
)) {
1128 random_ether_addr(pdata
->mac_addr
);
1130 "ar71xx: using random MAC address for eth%d\n",
1131 ath79_eth_instance
);
1134 if (pdata
->mii_bus_dev
== NULL
) {
1135 switch (ath79_soc
) {
1136 case ATH79_SOC_AR9341
:
1137 case ATH79_SOC_AR9342
:
1138 case ATH79_SOC_AR9344
:
1140 pdata
->mii_bus_dev
= &ath79_mdio0_device
.dev
;
1142 pdata
->mii_bus_dev
= &ath79_mdio1_device
.dev
;
1145 case ATH79_SOC_AR7241
:
1146 case ATH79_SOC_AR9330
:
1147 case ATH79_SOC_AR9331
:
1148 case ATH79_SOC_QCA9533
:
1149 case ATH79_SOC_TP9343
:
1150 pdata
->mii_bus_dev
= &ath79_mdio1_device
.dev
;
1153 case ATH79_SOC_QCA9556
:
1154 case ATH79_SOC_QCA9558
:
1155 /* don't assign any MDIO device by default */
1158 case ATH79_SOC_QCA956X
:
1159 if (pdata
->phy_if_mode
!= PHY_INTERFACE_MODE_SGMII
)
1160 pdata
->mii_bus_dev
= &ath79_mdio1_device
.dev
;
1164 pdata
->mii_bus_dev
= &ath79_mdio0_device
.dev
;
1169 /* Reset the device */
1170 ath79_device_reset_set(pdata
->reset_bit
);
1173 ath79_device_reset_clear(pdata
->reset_bit
);
1176 platform_device_register(pdev
);
1177 ath79_eth_instance
++;
1180 void __init
ath79_set_mac_base(unsigned char *mac
)
1182 memcpy(ath79_mac_base
, mac
, ETH_ALEN
);
1185 void __init
ath79_parse_ascii_mac(char *mac_str
, u8
*mac
)
1189 t
= sscanf(mac_str
, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
1190 &mac
[0], &mac
[1], &mac
[2], &mac
[3], &mac
[4], &mac
[5]);
1193 t
= sscanf(mac_str
, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
1194 &mac
[0], &mac
[1], &mac
[2], &mac
[3], &mac
[4], &mac
[5]);
1196 if (t
!= ETH_ALEN
|| !is_valid_ether_addr(mac
)) {
1197 memset(mac
, 0, ETH_ALEN
);
1198 printk(KERN_DEBUG
"ar71xx: invalid mac address \"%s\"\n",
1203 static void __init
ath79_set_mac_base_ascii(char *str
)
1207 ath79_parse_ascii_mac(str
, mac
);
1208 ath79_set_mac_base(mac
);
1211 static int __init
ath79_ethaddr_setup(char *str
)
1213 ath79_set_mac_base_ascii(str
);
1216 __setup("ethaddr=", ath79_ethaddr_setup
);
1218 static int __init
ath79_kmac_setup(char *str
)
1220 ath79_set_mac_base_ascii(str
);
1223 __setup("kmac=", ath79_kmac_setup
);
1225 void __init
ath79_init_mac(unsigned char *dst
, const unsigned char *src
,
1233 if (!src
|| !is_valid_ether_addr(src
)) {
1234 memset(dst
, '\0', ETH_ALEN
);
1238 t
= (((u32
) src
[3]) << 16) + (((u32
) src
[4]) << 8) + ((u32
) src
[5]);
1244 dst
[3] = (t
>> 16) & 0xff;
1245 dst
[4] = (t
>> 8) & 0xff;
1249 void __init
ath79_init_local_mac(unsigned char *dst
, const unsigned char *src
)
1256 if (!src
|| !is_valid_ether_addr(src
)) {
1257 memset(dst
, '\0', ETH_ALEN
);
1261 for (i
= 0; i
< ETH_ALEN
; i
++)