2 * Atheros AR71xx SoC platform devices
4 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
5 * Copyright (C) 2008-2009 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>
23 #include <asm/mach-ar71xx/ar71xx.h>
24 #include <asm/mach-ar71xx/ar933x_uart_platform.h>
28 unsigned char ar71xx_mac_base
[ETH_ALEN
] __initdata
;
30 static struct resource ar71xx_uart_resources
[] = {
32 .start
= AR71XX_UART_BASE
,
33 .end
= AR71XX_UART_BASE
+ AR71XX_UART_SIZE
- 1,
34 .flags
= IORESOURCE_MEM
,
38 #define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
39 static struct plat_serial8250_port ar71xx_uart_data
[] = {
41 .mapbase
= AR71XX_UART_BASE
,
42 .irq
= AR71XX_MISC_IRQ_UART
,
43 .flags
= AR71XX_UART_FLAGS
,
47 /* terminating entry */
51 static struct platform_device ar71xx_uart_device
= {
53 .id
= PLAT8250_DEV_PLATFORM
,
54 .resource
= ar71xx_uart_resources
,
55 .num_resources
= ARRAY_SIZE(ar71xx_uart_resources
),
57 .platform_data
= ar71xx_uart_data
61 static struct resource ar933x_uart_resources
[] = {
63 .start
= AR933X_UART_BASE
,
64 .end
= AR933X_UART_BASE
+ AR71XX_UART_SIZE
- 1,
65 .flags
= IORESOURCE_MEM
,
68 .start
= AR71XX_MISC_IRQ_UART
,
69 .end
= AR71XX_MISC_IRQ_UART
,
70 .flags
= IORESOURCE_IRQ
,
74 static struct ar933x_uart_platform_data ar933x_uart_data
;
75 static struct platform_device ar933x_uart_device
= {
76 .name
= "ar933x-uart",
78 .resource
= ar933x_uart_resources
,
79 .num_resources
= ARRAY_SIZE(ar933x_uart_resources
),
81 .platform_data
= &ar933x_uart_data
,
85 void __init
ar71xx_add_device_uart(void)
87 struct platform_device
*pdev
;
90 case AR71XX_SOC_AR7130
:
91 case AR71XX_SOC_AR7141
:
92 case AR71XX_SOC_AR7161
:
93 case AR71XX_SOC_AR7240
:
94 case AR71XX_SOC_AR7241
:
95 case AR71XX_SOC_AR7242
:
96 case AR71XX_SOC_AR9130
:
97 case AR71XX_SOC_AR9132
:
98 pdev
= &ar71xx_uart_device
;
99 ar71xx_uart_data
[0].uartclk
= ar71xx_ahb_freq
;
102 case AR71XX_SOC_AR9330
:
103 case AR71XX_SOC_AR9331
:
104 pdev
= &ar933x_uart_device
;
105 ar933x_uart_data
.uartclk
= ar71xx_ref_freq
;
108 case AR71XX_SOC_AR9341
:
109 case AR71XX_SOC_AR9342
:
110 case AR71XX_SOC_AR9344
:
111 pdev
= &ar71xx_uart_device
;
112 ar71xx_uart_data
[0].uartclk
= ar71xx_ref_freq
;
119 platform_device_register(pdev
);
122 static struct resource ar71xx_mdio0_resources
[] = {
125 .flags
= IORESOURCE_MEM
,
126 .start
= AR71XX_GE0_BASE
,
127 .end
= AR71XX_GE0_BASE
+ 0x200 - 1,
131 static struct ag71xx_mdio_platform_data ar71xx_mdio0_data
;
133 struct platform_device ar71xx_mdio0_device
= {
134 .name
= "ag71xx-mdio",
136 .resource
= ar71xx_mdio0_resources
,
137 .num_resources
= ARRAY_SIZE(ar71xx_mdio0_resources
),
139 .platform_data
= &ar71xx_mdio0_data
,
143 static struct resource ar71xx_mdio1_resources
[] = {
146 .flags
= IORESOURCE_MEM
,
147 .start
= AR71XX_GE1_BASE
,
148 .end
= AR71XX_GE1_BASE
+ 0x200 - 1,
152 static struct ag71xx_mdio_platform_data ar71xx_mdio1_data
;
154 struct platform_device ar71xx_mdio1_device
= {
155 .name
= "ag71xx-mdio",
157 .resource
= ar71xx_mdio1_resources
,
158 .num_resources
= ARRAY_SIZE(ar71xx_mdio1_resources
),
160 .platform_data
= &ar71xx_mdio1_data
,
164 static void ar71xx_set_pll(u32 cfg_reg
, u32 pll_reg
, u32 pll_val
, u32 shift
)
169 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
171 t
= __raw_readl(base
+ cfg_reg
);
174 __raw_writel(t
, base
+ cfg_reg
);
177 __raw_writel(pll_val
, base
+ pll_reg
);
180 __raw_writel(t
, base
+ cfg_reg
);
184 __raw_writel(t
, base
+ cfg_reg
);
187 printk(KERN_DEBUG
"ar71xx: pll_reg %#x: %#x\n",
188 (unsigned int)(base
+ pll_reg
), __raw_readl(base
+ pll_reg
));
193 static void __init
ar71xx_mii_ctrl_set_if(unsigned int reg
,
199 base
= ioremap(AR71XX_MII_BASE
, AR71XX_MII_SIZE
);
201 t
= __raw_readl(base
+ reg
);
202 t
&= ~(MII_CTRL_IF_MASK
);
203 t
|= (mii_if
& MII_CTRL_IF_MASK
);
204 __raw_writel(t
, base
+ reg
);
209 static void ar71xx_mii_ctrl_set_speed(unsigned int reg
, unsigned int speed
)
212 unsigned int mii_speed
;
217 mii_speed
= MII_CTRL_SPEED_10
;
220 mii_speed
= MII_CTRL_SPEED_100
;
223 mii_speed
= MII_CTRL_SPEED_1000
;
229 base
= ioremap(AR71XX_MII_BASE
, AR71XX_MII_SIZE
);
231 t
= __raw_readl(base
+ reg
);
232 t
&= ~(MII_CTRL_SPEED_MASK
<< MII_CTRL_SPEED_SHIFT
);
233 t
|= mii_speed
<< MII_CTRL_SPEED_SHIFT
;
234 __raw_writel(t
, base
+ reg
);
239 void __init
ar71xx_add_device_mdio(unsigned int id
, u32 phy_mask
)
241 struct platform_device
*mdio_dev
;
242 struct ag71xx_mdio_platform_data
*mdio_data
;
245 if (ar71xx_soc
== AR71XX_SOC_AR9341
||
246 ar71xx_soc
== AR71XX_SOC_AR9342
||
247 ar71xx_soc
== AR71XX_SOC_AR9344
)
253 printk(KERN_ERR
"ar71xx: invalid MDIO id %u\n", id
);
257 switch (ar71xx_soc
) {
258 case AR71XX_SOC_AR7241
:
259 case AR71XX_SOC_AR9330
:
260 case AR71XX_SOC_AR9331
:
261 mdio_dev
= &ar71xx_mdio1_device
;
262 mdio_data
= &ar71xx_mdio1_data
;
265 case AR71XX_SOC_AR9341
:
266 case AR71XX_SOC_AR9342
:
267 case AR71XX_SOC_AR9344
:
269 mdio_dev
= &ar71xx_mdio0_device
;
270 mdio_data
= &ar71xx_mdio0_data
;
272 mdio_dev
= &ar71xx_mdio1_device
;
273 mdio_data
= &ar71xx_mdio1_data
;
277 case AR71XX_SOC_AR7242
:
278 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
,
279 AR7242_PLL_REG_ETH0_INT_CLOCK
, 0x62000000,
280 AR71XX_ETH0_PLL_SHIFT
);
283 mdio_dev
= &ar71xx_mdio0_device
;
284 mdio_data
= &ar71xx_mdio0_data
;
288 mdio_data
->phy_mask
= phy_mask
;
290 switch (ar71xx_soc
) {
291 case AR71XX_SOC_AR7240
:
292 case AR71XX_SOC_AR7241
:
293 case AR71XX_SOC_AR9330
:
294 case AR71XX_SOC_AR9331
:
295 mdio_data
->is_ar7240
= 1;
298 case AR71XX_SOC_AR9341
:
299 case AR71XX_SOC_AR9342
:
300 case AR71XX_SOC_AR9344
:
302 mdio_data
->is_ar7240
= 1;
309 platform_device_register(mdio_dev
);
312 struct ar71xx_eth_pll_data ar71xx_eth0_pll_data
;
313 struct ar71xx_eth_pll_data ar71xx_eth1_pll_data
;
315 static u32
ar71xx_get_eth_pll(unsigned int mac
, int speed
)
317 struct ar71xx_eth_pll_data
*pll_data
;
322 pll_data
= &ar71xx_eth0_pll_data
;
325 pll_data
= &ar71xx_eth1_pll_data
;
333 pll_val
= pll_data
->pll_10
;
336 pll_val
= pll_data
->pll_100
;
339 pll_val
= pll_data
->pll_1000
;
348 static void ar71xx_set_speed_ge0(int speed
)
350 u32 val
= ar71xx_get_eth_pll(0, speed
);
352 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR71XX_PLL_REG_ETH0_INT_CLOCK
,
353 val
, AR71XX_ETH0_PLL_SHIFT
);
354 ar71xx_mii_ctrl_set_speed(MII_REG_MII0_CTRL
, speed
);
357 static void ar71xx_set_speed_ge1(int speed
)
359 u32 val
= ar71xx_get_eth_pll(1, speed
);
361 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR71XX_PLL_REG_ETH1_INT_CLOCK
,
362 val
, AR71XX_ETH1_PLL_SHIFT
);
363 ar71xx_mii_ctrl_set_speed(MII_REG_MII1_CTRL
, speed
);
366 static void ar724x_set_speed_ge0(int speed
)
371 static void ar724x_set_speed_ge1(int speed
)
376 static void ar7242_set_speed_ge0(int speed
)
378 u32 val
= ar71xx_get_eth_pll(0, speed
);
381 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
382 __raw_writel(val
, base
+ AR7242_PLL_REG_ETH0_INT_CLOCK
);
386 static void ar91xx_set_speed_ge0(int speed
)
388 u32 val
= ar71xx_get_eth_pll(0, speed
);
390 ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG
, AR91XX_PLL_REG_ETH0_INT_CLOCK
,
391 val
, AR91XX_ETH0_PLL_SHIFT
);
392 ar71xx_mii_ctrl_set_speed(MII_REG_MII0_CTRL
, speed
);
395 static void ar91xx_set_speed_ge1(int speed
)
397 u32 val
= ar71xx_get_eth_pll(1, speed
);
399 ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG
, AR91XX_PLL_REG_ETH1_INT_CLOCK
,
400 val
, AR91XX_ETH1_PLL_SHIFT
);
401 ar71xx_mii_ctrl_set_speed(MII_REG_MII1_CTRL
, speed
);
404 static void ar933x_set_speed_ge0(int speed
)
409 static void ar933x_set_speed_ge1(int speed
)
414 static void ar934x_set_speed_ge0(int speed
)
419 static void ar934x_set_speed_ge1(int speed
)
424 static void ar71xx_ddr_flush_ge0(void)
426 ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE0
);
429 static void ar71xx_ddr_flush_ge1(void)
431 ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE1
);
434 static void ar724x_ddr_flush_ge0(void)
436 ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE0
);
439 static void ar724x_ddr_flush_ge1(void)
441 ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE1
);
444 static void ar91xx_ddr_flush_ge0(void)
446 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE0
);
449 static void ar91xx_ddr_flush_ge1(void)
451 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE1
);
454 static void ar933x_ddr_flush_ge0(void)
456 ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_GE0
);
459 static void ar933x_ddr_flush_ge1(void)
461 ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_GE1
);
464 static void ar934x_ddr_flush_ge0(void)
466 ar71xx_ddr_flush(AR934X_DDR_REG_FLUSH_GE0
);
469 static void ar934x_ddr_flush_ge1(void)
471 ar71xx_ddr_flush(AR934X_DDR_REG_FLUSH_GE1
);
474 static struct resource ar71xx_eth0_resources
[] = {
477 .flags
= IORESOURCE_MEM
,
478 .start
= AR71XX_GE0_BASE
,
479 .end
= AR71XX_GE0_BASE
+ 0x200 - 1,
482 .flags
= IORESOURCE_IRQ
,
483 .start
= AR71XX_CPU_IRQ_GE0
,
484 .end
= AR71XX_CPU_IRQ_GE0
,
488 struct ag71xx_platform_data ar71xx_eth0_data
= {
489 .reset_bit
= RESET_MODULE_GE0_MAC
,
492 struct platform_device ar71xx_eth0_device
= {
495 .resource
= ar71xx_eth0_resources
,
496 .num_resources
= ARRAY_SIZE(ar71xx_eth0_resources
),
498 .platform_data
= &ar71xx_eth0_data
,
502 static struct resource ar71xx_eth1_resources
[] = {
505 .flags
= IORESOURCE_MEM
,
506 .start
= AR71XX_GE1_BASE
,
507 .end
= AR71XX_GE1_BASE
+ 0x200 - 1,
510 .flags
= IORESOURCE_IRQ
,
511 .start
= AR71XX_CPU_IRQ_GE1
,
512 .end
= AR71XX_CPU_IRQ_GE1
,
516 struct ag71xx_platform_data ar71xx_eth1_data
= {
517 .reset_bit
= RESET_MODULE_GE1_MAC
,
520 struct platform_device ar71xx_eth1_device
= {
523 .resource
= ar71xx_eth1_resources
,
524 .num_resources
= ARRAY_SIZE(ar71xx_eth1_resources
),
526 .platform_data
= &ar71xx_eth1_data
,
530 struct ag71xx_switch_platform_data ar71xx_switch_data
;
532 #define AR71XX_PLL_VAL_1000 0x00110000
533 #define AR71XX_PLL_VAL_100 0x00001099
534 #define AR71XX_PLL_VAL_10 0x00991099
536 #define AR724X_PLL_VAL_1000 0x00110000
537 #define AR724X_PLL_VAL_100 0x00001099
538 #define AR724X_PLL_VAL_10 0x00991099
540 #define AR7242_PLL_VAL_1000 0x16000000
541 #define AR7242_PLL_VAL_100 0x00000101
542 #define AR7242_PLL_VAL_10 0x00001616
544 #define AR91XX_PLL_VAL_1000 0x1a000000
545 #define AR91XX_PLL_VAL_100 0x13000a44
546 #define AR91XX_PLL_VAL_10 0x00441099
548 #define AR933X_PLL_VAL_1000 0x00110000
549 #define AR933X_PLL_VAL_100 0x00001099
550 #define AR933X_PLL_VAL_10 0x00991099
552 #define AR934X_PLL_VAL_1000 0x00110000
553 #define AR934X_PLL_VAL_100 0x00001099
554 #define AR934X_PLL_VAL_10 0x00991099
556 static void __init
ar71xx_init_eth_pll_data(unsigned int id
)
558 struct ar71xx_eth_pll_data
*pll_data
;
559 u32 pll_10
, pll_100
, pll_1000
;
563 pll_data
= &ar71xx_eth0_pll_data
;
566 pll_data
= &ar71xx_eth1_pll_data
;
572 switch (ar71xx_soc
) {
573 case AR71XX_SOC_AR7130
:
574 case AR71XX_SOC_AR7141
:
575 case AR71XX_SOC_AR7161
:
576 pll_10
= AR71XX_PLL_VAL_10
;
577 pll_100
= AR71XX_PLL_VAL_100
;
578 pll_1000
= AR71XX_PLL_VAL_1000
;
581 case AR71XX_SOC_AR7240
:
582 case AR71XX_SOC_AR7241
:
583 pll_10
= AR724X_PLL_VAL_10
;
584 pll_100
= AR724X_PLL_VAL_100
;
585 pll_1000
= AR724X_PLL_VAL_1000
;
588 case AR71XX_SOC_AR7242
:
589 pll_10
= AR7242_PLL_VAL_10
;
590 pll_100
= AR7242_PLL_VAL_100
;
591 pll_1000
= AR7242_PLL_VAL_1000
;
594 case AR71XX_SOC_AR9130
:
595 case AR71XX_SOC_AR9132
:
596 pll_10
= AR91XX_PLL_VAL_10
;
597 pll_100
= AR91XX_PLL_VAL_100
;
598 pll_1000
= AR91XX_PLL_VAL_1000
;
601 case AR71XX_SOC_AR9330
:
602 case AR71XX_SOC_AR9331
:
603 pll_10
= AR933X_PLL_VAL_10
;
604 pll_100
= AR933X_PLL_VAL_100
;
605 pll_1000
= AR933X_PLL_VAL_1000
;
608 case AR71XX_SOC_AR9341
:
609 case AR71XX_SOC_AR9342
:
610 case AR71XX_SOC_AR9344
:
611 pll_10
= AR934X_PLL_VAL_10
;
612 pll_100
= AR934X_PLL_VAL_100
;
613 pll_1000
= AR934X_PLL_VAL_1000
;
620 if (!pll_data
->pll_10
)
621 pll_data
->pll_10
= pll_10
;
623 if (!pll_data
->pll_100
)
624 pll_data
->pll_100
= pll_100
;
626 if (!pll_data
->pll_1000
)
627 pll_data
->pll_1000
= pll_1000
;
630 static int __init
ar71xx_setup_phy_if_mode(unsigned int id
,
631 struct ag71xx_platform_data
*pdata
)
637 switch (ar71xx_soc
) {
638 case AR71XX_SOC_AR7130
:
639 case AR71XX_SOC_AR7141
:
640 case AR71XX_SOC_AR7161
:
641 case AR71XX_SOC_AR9130
:
642 case AR71XX_SOC_AR9132
:
643 switch (pdata
->phy_if_mode
) {
644 case PHY_INTERFACE_MODE_MII
:
645 mii_if
= MII0_CTRL_IF_MII
;
647 case PHY_INTERFACE_MODE_GMII
:
648 mii_if
= MII0_CTRL_IF_GMII
;
650 case PHY_INTERFACE_MODE_RGMII
:
651 mii_if
= MII0_CTRL_IF_RGMII
;
653 case PHY_INTERFACE_MODE_RMII
:
654 mii_if
= MII0_CTRL_IF_RMII
;
659 ar71xx_mii_ctrl_set_if(MII_REG_MII0_CTRL
, mii_if
);
662 case AR71XX_SOC_AR7240
:
663 case AR71XX_SOC_AR7241
:
664 case AR71XX_SOC_AR9330
:
665 case AR71XX_SOC_AR9331
:
666 pdata
->phy_if_mode
= PHY_INTERFACE_MODE_MII
;
669 case AR71XX_SOC_AR7242
:
672 case AR71XX_SOC_AR9341
:
673 case AR71XX_SOC_AR9342
:
674 case AR71XX_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
:
691 switch (ar71xx_soc
) {
692 case AR71XX_SOC_AR7130
:
693 case AR71XX_SOC_AR7141
:
694 case AR71XX_SOC_AR7161
:
695 case AR71XX_SOC_AR9130
:
696 case AR71XX_SOC_AR9132
:
697 switch (pdata
->phy_if_mode
) {
698 case PHY_INTERFACE_MODE_RMII
:
699 mii_if
= MII1_CTRL_IF_RMII
;
701 case PHY_INTERFACE_MODE_RGMII
:
702 mii_if
= MII1_CTRL_IF_RGMII
;
707 ar71xx_mii_ctrl_set_if(MII_REG_MII1_CTRL
, mii_if
);
710 case AR71XX_SOC_AR7240
:
711 case AR71XX_SOC_AR7241
:
712 case AR71XX_SOC_AR9330
:
713 case AR71XX_SOC_AR9331
:
714 pdata
->phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
717 case AR71XX_SOC_AR7242
:
720 case AR71XX_SOC_AR9341
:
721 case AR71XX_SOC_AR9342
:
722 case AR71XX_SOC_AR9344
:
723 switch (pdata
->phy_if_mode
) {
724 case PHY_INTERFACE_MODE_MII
:
725 case PHY_INTERFACE_MODE_GMII
:
741 static int ar71xx_eth_instance __initdata
;
742 void __init
ar71xx_add_device_eth(unsigned int id
)
744 struct platform_device
*pdev
;
745 struct ag71xx_platform_data
*pdata
;
749 printk(KERN_ERR
"ar71xx: invalid ethernet id %d\n", id
);
753 ar71xx_init_eth_pll_data(id
);
756 pdev
= &ar71xx_eth0_device
;
758 pdev
= &ar71xx_eth1_device
;
760 pdata
= pdev
->dev
.platform_data
;
762 err
= ar71xx_setup_phy_if_mode(id
, pdata
);
765 "ar71xx: invalid PHY interface mode for GE%u\n", id
);
769 switch (ar71xx_soc
) {
770 case AR71XX_SOC_AR7130
:
772 pdata
->ddr_flush
= ar71xx_ddr_flush_ge0
;
773 pdata
->set_speed
= ar71xx_set_speed_ge0
;
775 pdata
->ddr_flush
= ar71xx_ddr_flush_ge1
;
776 pdata
->set_speed
= ar71xx_set_speed_ge1
;
780 case AR71XX_SOC_AR7141
:
781 case AR71XX_SOC_AR7161
:
783 pdata
->ddr_flush
= ar71xx_ddr_flush_ge0
;
784 pdata
->set_speed
= ar71xx_set_speed_ge0
;
786 pdata
->ddr_flush
= ar71xx_ddr_flush_ge1
;
787 pdata
->set_speed
= ar71xx_set_speed_ge1
;
792 case AR71XX_SOC_AR7242
:
794 pdata
->reset_bit
|= AR724X_RESET_GE0_MDIO
|
795 RESET_MODULE_GE0_PHY
;
796 pdata
->ddr_flush
= ar724x_ddr_flush_ge0
;
797 pdata
->set_speed
= ar7242_set_speed_ge0
;
799 pdata
->reset_bit
|= AR724X_RESET_GE1_MDIO
|
800 RESET_MODULE_GE1_PHY
;
801 pdata
->ddr_flush
= ar724x_ddr_flush_ge1
;
802 pdata
->set_speed
= ar724x_set_speed_ge1
;
805 pdata
->is_ar724x
= 1;
807 if (!pdata
->fifo_cfg1
)
808 pdata
->fifo_cfg1
= 0x0010ffff;
809 if (!pdata
->fifo_cfg2
)
810 pdata
->fifo_cfg2
= 0x015500aa;
811 if (!pdata
->fifo_cfg3
)
812 pdata
->fifo_cfg3
= 0x01f00140;
815 case AR71XX_SOC_AR7241
:
817 pdata
->reset_bit
|= AR724X_RESET_GE0_MDIO
;
819 pdata
->reset_bit
|= AR724X_RESET_GE1_MDIO
;
821 case AR71XX_SOC_AR7240
:
823 pdata
->reset_bit
|= RESET_MODULE_GE0_PHY
;
824 pdata
->ddr_flush
= ar724x_ddr_flush_ge0
;
825 pdata
->set_speed
= ar724x_set_speed_ge0
;
827 pdata
->phy_mask
= BIT(4);
829 pdata
->reset_bit
|= RESET_MODULE_GE1_PHY
;
830 pdata
->ddr_flush
= ar724x_ddr_flush_ge1
;
831 pdata
->set_speed
= ar724x_set_speed_ge1
;
833 pdata
->speed
= SPEED_1000
;
834 pdata
->duplex
= DUPLEX_FULL
;
835 pdata
->switch_data
= &ar71xx_switch_data
;
838 pdata
->is_ar724x
= 1;
839 if (ar71xx_soc
== AR71XX_SOC_AR7240
)
840 pdata
->is_ar7240
= 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;
850 case AR71XX_SOC_AR9130
:
852 pdata
->ddr_flush
= ar91xx_ddr_flush_ge0
;
853 pdata
->set_speed
= ar91xx_set_speed_ge0
;
855 pdata
->ddr_flush
= ar91xx_ddr_flush_ge1
;
856 pdata
->set_speed
= ar91xx_set_speed_ge1
;
858 pdata
->is_ar91xx
= 1;
861 case AR71XX_SOC_AR9132
:
863 pdata
->ddr_flush
= ar91xx_ddr_flush_ge0
;
864 pdata
->set_speed
= ar91xx_set_speed_ge0
;
866 pdata
->ddr_flush
= ar91xx_ddr_flush_ge1
;
867 pdata
->set_speed
= ar91xx_set_speed_ge1
;
869 pdata
->is_ar91xx
= 1;
873 case AR71XX_SOC_AR9330
:
874 case AR71XX_SOC_AR9331
:
876 pdata
->reset_bit
= AR933X_RESET_GE0_MAC
|
877 AR933X_RESET_GE0_MDIO
;
878 pdata
->ddr_flush
= ar933x_ddr_flush_ge0
;
879 pdata
->set_speed
= ar933x_set_speed_ge0
;
881 pdata
->phy_mask
= BIT(4);
883 pdata
->reset_bit
= AR933X_RESET_GE1_MAC
|
884 AR933X_RESET_GE1_MDIO
;
885 pdata
->ddr_flush
= ar933x_ddr_flush_ge1
;
886 pdata
->set_speed
= ar933x_set_speed_ge1
;
888 pdata
->speed
= SPEED_1000
;
889 pdata
->duplex
= DUPLEX_FULL
;
890 pdata
->switch_data
= &ar71xx_switch_data
;
894 pdata
->is_ar724x
= 1;
896 if (!pdata
->fifo_cfg1
)
897 pdata
->fifo_cfg1
= 0x0010ffff;
898 if (!pdata
->fifo_cfg2
)
899 pdata
->fifo_cfg2
= 0x015500aa;
900 if (!pdata
->fifo_cfg3
)
901 pdata
->fifo_cfg3
= 0x01f00140;
904 case AR71XX_SOC_AR9341
:
905 case AR71XX_SOC_AR9342
:
906 case AR71XX_SOC_AR9344
:
908 pdata
->reset_bit
= AR934X_RESET_GE0_MAC
|
909 AR934X_RESET_GE0_MDIO
;
910 pdata
->ddr_flush
=ar934x_ddr_flush_ge0
;
911 pdata
->set_speed
= ar934x_set_speed_ge0
;
913 pdata
->reset_bit
= AR934X_RESET_GE1_MAC
|
914 AR934X_RESET_GE1_MDIO
;
915 pdata
->ddr_flush
= ar934x_ddr_flush_ge1
;
916 pdata
->set_speed
= ar934x_set_speed_ge1
;
918 pdata
->switch_data
= &ar71xx_switch_data
;
922 pdata
->is_ar724x
= 1;
924 if (!pdata
->fifo_cfg1
)
925 pdata
->fifo_cfg1
= 0x0010ffff;
926 if (!pdata
->fifo_cfg2
)
927 pdata
->fifo_cfg2
= 0x015500aa;
928 if (!pdata
->fifo_cfg3
)
929 pdata
->fifo_cfg3
= 0x01f00140;
936 switch (pdata
->phy_if_mode
) {
937 case PHY_INTERFACE_MODE_GMII
:
938 case PHY_INTERFACE_MODE_RGMII
:
939 if (!pdata
->has_gbit
) {
940 printk(KERN_ERR
"ar71xx: no gbit available on eth%d\n",
949 if (!is_valid_ether_addr(pdata
->mac_addr
)) {
950 random_ether_addr(pdata
->mac_addr
);
952 "ar71xx: using random MAC address for eth%d\n",
953 ar71xx_eth_instance
);
956 if (pdata
->mii_bus_dev
== NULL
) {
957 switch (ar71xx_soc
) {
958 case AR71XX_SOC_AR9341
:
959 case AR71XX_SOC_AR9342
:
960 case AR71XX_SOC_AR9344
:
962 pdata
->mii_bus_dev
= &ar71xx_mdio0_device
.dev
;
964 pdata
->mii_bus_dev
= &ar71xx_mdio1_device
.dev
;
967 case AR71XX_SOC_AR7241
:
968 case AR71XX_SOC_AR9330
:
969 case AR71XX_SOC_AR9331
:
970 pdata
->mii_bus_dev
= &ar71xx_mdio1_device
.dev
;
974 pdata
->mii_bus_dev
= &ar71xx_mdio0_device
.dev
;
979 /* Reset the device */
980 ar71xx_device_stop(pdata
->reset_bit
);
983 ar71xx_device_start(pdata
->reset_bit
);
986 platform_device_register(pdev
);
987 ar71xx_eth_instance
++;
990 static struct resource ar71xx_spi_resources
[] = {
992 .start
= AR71XX_SPI_BASE
,
993 .end
= AR71XX_SPI_BASE
+ AR71XX_SPI_SIZE
- 1,
994 .flags
= IORESOURCE_MEM
,
998 static struct platform_device ar71xx_spi_device
= {
999 .name
= "ar71xx-spi",
1001 .resource
= ar71xx_spi_resources
,
1002 .num_resources
= ARRAY_SIZE(ar71xx_spi_resources
),
1005 void __init
ar71xx_add_device_spi(struct ar71xx_spi_platform_data
*pdata
,
1006 struct spi_board_info
const *info
,
1009 spi_register_board_info(info
, n
);
1010 ar71xx_spi_device
.dev
.platform_data
= pdata
;
1011 platform_device_register(&ar71xx_spi_device
);
1014 void __init
ar71xx_add_device_wdt(void)
1016 platform_device_register_simple("ar71xx-wdt", -1, NULL
, 0);
1019 void __init
ar71xx_set_mac_base(unsigned char *mac
)
1021 memcpy(ar71xx_mac_base
, mac
, ETH_ALEN
);
1024 void __init
ar71xx_parse_mac_addr(char *mac_str
)
1029 t
= sscanf(mac_str
, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
1030 &tmp
[0], &tmp
[1], &tmp
[2], &tmp
[3], &tmp
[4], &tmp
[5]);
1033 t
= sscanf(mac_str
, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
1034 &tmp
[0], &tmp
[1], &tmp
[2], &tmp
[3], &tmp
[4], &tmp
[5]);
1037 ar71xx_set_mac_base(tmp
);
1039 printk(KERN_DEBUG
"ar71xx: failed to parse mac address "
1040 "\"%s\"\n", mac_str
);
1043 static int __init
ar71xx_ethaddr_setup(char *str
)
1045 ar71xx_parse_mac_addr(str
);
1048 __setup("ethaddr=", ar71xx_ethaddr_setup
);
1050 static int __init
ar71xx_kmac_setup(char *str
)
1052 ar71xx_parse_mac_addr(str
);
1055 __setup("kmac=", ar71xx_kmac_setup
);
1057 void __init
ar71xx_init_mac(unsigned char *dst
, const unsigned char *src
,
1062 if (!is_valid_ether_addr(src
)) {
1063 memset(dst
, '\0', ETH_ALEN
);
1067 t
= (((u32
) src
[3]) << 16) + (((u32
) src
[4]) << 8) + ((u32
) src
[5]);
1073 dst
[3] = (t
>> 16) & 0xff;
1074 dst
[4] = (t
>> 8) & 0xff;