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>
27 unsigned char ar71xx_mac_base
[ETH_ALEN
] __initdata
;
29 static struct resource ar71xx_uart_resources
[] = {
31 .start
= AR71XX_UART_BASE
,
32 .end
= AR71XX_UART_BASE
+ AR71XX_UART_SIZE
- 1,
33 .flags
= IORESOURCE_MEM
,
37 #define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
38 static struct plat_serial8250_port ar71xx_uart_data
[] = {
40 .mapbase
= AR71XX_UART_BASE
,
41 .irq
= AR71XX_MISC_IRQ_UART
,
42 .flags
= AR71XX_UART_FLAGS
,
46 /* terminating entry */
50 static struct platform_device ar71xx_uart_device
= {
52 .id
= PLAT8250_DEV_PLATFORM
,
53 .resource
= ar71xx_uart_resources
,
54 .num_resources
= ARRAY_SIZE(ar71xx_uart_resources
),
56 .platform_data
= ar71xx_uart_data
60 void __init
ar71xx_add_device_uart(void)
63 case AR71XX_SOC_AR7130
:
64 case AR71XX_SOC_AR7141
:
65 case AR71XX_SOC_AR7161
:
66 case AR71XX_SOC_AR7240
:
67 case AR71XX_SOC_AR7241
:
68 case AR71XX_SOC_AR7242
:
69 case AR71XX_SOC_AR9130
:
70 case AR71XX_SOC_AR9132
:
71 ar71xx_uart_data
[0].uartclk
= ar71xx_ahb_freq
;
74 case AR71XX_SOC_AR9330
:
75 case AR71XX_SOC_AR9331
:
76 /* These SoCs are using a different UART core */
79 case AR71XX_SOC_AR9341
:
80 case AR71XX_SOC_AR9342
:
81 case AR71XX_SOC_AR9344
:
82 ar71xx_uart_data
[0].uartclk
= ar71xx_ref_freq
;
89 platform_device_register(&ar71xx_uart_device
);
92 static struct resource ar71xx_mdio_resources
[] = {
95 .flags
= IORESOURCE_MEM
,
96 .start
= AR71XX_GE0_BASE
,
97 .end
= AR71XX_GE0_BASE
+ 0x200 - 1,
101 static struct ag71xx_mdio_platform_data ar71xx_mdio_data
;
103 struct platform_device ar71xx_mdio_device
= {
104 .name
= "ag71xx-mdio",
106 .resource
= ar71xx_mdio_resources
,
107 .num_resources
= ARRAY_SIZE(ar71xx_mdio_resources
),
109 .platform_data
= &ar71xx_mdio_data
,
113 static void ar71xx_set_pll(u32 cfg_reg
, u32 pll_reg
, u32 pll_val
, u32 shift
)
118 base
= ioremap_nocache(AR71XX_PLL_BASE
, AR71XX_PLL_SIZE
);
120 t
= __raw_readl(base
+ cfg_reg
);
123 __raw_writel(t
, base
+ cfg_reg
);
126 __raw_writel(pll_val
, base
+ pll_reg
);
129 __raw_writel(t
, base
+ cfg_reg
);
133 __raw_writel(t
, base
+ cfg_reg
);
136 printk(KERN_DEBUG
"ar71xx: pll_reg %#x: %#x\n",
137 (unsigned int)(base
+ pll_reg
), __raw_readl(base
+ pll_reg
));
142 void __init
ar71xx_add_device_mdio(u32 phy_mask
)
144 switch (ar71xx_soc
) {
145 case AR71XX_SOC_AR7240
:
146 ar71xx_mdio_data
.is_ar7240
= 1;
148 case AR71XX_SOC_AR7241
:
149 ar71xx_mdio_data
.is_ar7240
= 1;
150 ar71xx_mdio_resources
[0].start
= AR71XX_GE1_BASE
;
151 ar71xx_mdio_resources
[0].end
= AR71XX_GE1_BASE
+ 0x200 - 1;
153 case AR71XX_SOC_AR7242
:
154 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
,
155 AR7242_PLL_REG_ETH0_INT_CLOCK
, 0x62000000,
156 AR71XX_ETH0_PLL_SHIFT
);
158 case AR71XX_SOC_AR9330
:
159 case AR71XX_SOC_AR9331
:
160 ar71xx_mdio_data
.is_ar7240
= 1;
161 ar71xx_mdio_resources
[0].start
= AR71XX_GE1_BASE
;
162 ar71xx_mdio_resources
[0].end
= AR71XX_GE1_BASE
+ 0x200 - 1;
168 ar71xx_mdio_data
.phy_mask
= phy_mask
;
170 platform_device_register(&ar71xx_mdio_device
);
173 struct ar71xx_eth_pll_data ar71xx_eth0_pll_data
;
174 struct ar71xx_eth_pll_data ar71xx_eth1_pll_data
;
176 static u32
ar71xx_get_eth_pll(unsigned int mac
, int speed
)
178 struct ar71xx_eth_pll_data
*pll_data
;
183 pll_data
= &ar71xx_eth0_pll_data
;
186 pll_data
= &ar71xx_eth1_pll_data
;
194 pll_val
= pll_data
->pll_10
;
197 pll_val
= pll_data
->pll_100
;
200 pll_val
= pll_data
->pll_1000
;
209 static void ar71xx_set_pll_ge0(int speed
)
211 u32 val
= ar71xx_get_eth_pll(0, speed
);
213 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR71XX_PLL_REG_ETH0_INT_CLOCK
,
214 val
, AR71XX_ETH0_PLL_SHIFT
);
217 static void ar71xx_set_pll_ge1(int speed
)
219 u32 val
= ar71xx_get_eth_pll(1, speed
);
221 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR71XX_PLL_REG_ETH1_INT_CLOCK
,
222 val
, AR71XX_ETH1_PLL_SHIFT
);
225 static void ar724x_set_pll_ge0(int speed
)
230 static void ar724x_set_pll_ge1(int speed
)
235 static void ar7242_set_pll_ge0(int speed
)
237 u32 val
= ar71xx_get_eth_pll(0, speed
);
239 ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG
, AR7242_PLL_REG_ETH0_INT_CLOCK
,
240 val
, AR71XX_ETH0_PLL_SHIFT
);
243 static void ar91xx_set_pll_ge0(int speed
)
245 u32 val
= ar71xx_get_eth_pll(0, speed
);
247 ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG
, AR91XX_PLL_REG_ETH0_INT_CLOCK
,
248 val
, AR91XX_ETH0_PLL_SHIFT
);
251 static void ar91xx_set_pll_ge1(int speed
)
253 u32 val
= ar71xx_get_eth_pll(1, speed
);
255 ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG
, AR91XX_PLL_REG_ETH1_INT_CLOCK
,
256 val
, AR91XX_ETH1_PLL_SHIFT
);
259 static void ar933x_set_pll_ge0(int speed
)
264 static void ar933x_set_pll_ge1(int speed
)
269 static void ar71xx_ddr_flush_ge0(void)
271 ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE0
);
274 static void ar71xx_ddr_flush_ge1(void)
276 ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE1
);
279 static void ar724x_ddr_flush_ge0(void)
281 ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE0
);
284 static void ar724x_ddr_flush_ge1(void)
286 ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE1
);
289 static void ar91xx_ddr_flush_ge0(void)
291 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE0
);
294 static void ar91xx_ddr_flush_ge1(void)
296 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE1
);
299 static void ar933x_ddr_flush_ge0(void)
301 ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_GE0
);
304 static void ar933x_ddr_flush_ge1(void)
306 ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_GE1
);
309 static struct resource ar71xx_eth0_resources
[] = {
312 .flags
= IORESOURCE_MEM
,
313 .start
= AR71XX_GE0_BASE
,
314 .end
= AR71XX_GE0_BASE
+ 0x200 - 1,
317 .flags
= IORESOURCE_MEM
,
318 .start
= AR71XX_MII_BASE
+ MII_REG_MII0_CTRL
,
319 .end
= AR71XX_MII_BASE
+ MII_REG_MII0_CTRL
+ 3,
322 .flags
= IORESOURCE_IRQ
,
323 .start
= AR71XX_CPU_IRQ_GE0
,
324 .end
= AR71XX_CPU_IRQ_GE0
,
328 struct ag71xx_platform_data ar71xx_eth0_data
= {
329 .reset_bit
= RESET_MODULE_GE0_MAC
,
332 struct platform_device ar71xx_eth0_device
= {
335 .resource
= ar71xx_eth0_resources
,
336 .num_resources
= ARRAY_SIZE(ar71xx_eth0_resources
),
338 .platform_data
= &ar71xx_eth0_data
,
342 static struct resource ar71xx_eth1_resources
[] = {
345 .flags
= IORESOURCE_MEM
,
346 .start
= AR71XX_GE1_BASE
,
347 .end
= AR71XX_GE1_BASE
+ 0x200 - 1,
350 .flags
= IORESOURCE_MEM
,
351 .start
= AR71XX_MII_BASE
+ MII_REG_MII1_CTRL
,
352 .end
= AR71XX_MII_BASE
+ MII_REG_MII1_CTRL
+ 3,
355 .flags
= IORESOURCE_IRQ
,
356 .start
= AR71XX_CPU_IRQ_GE1
,
357 .end
= AR71XX_CPU_IRQ_GE1
,
361 struct ag71xx_platform_data ar71xx_eth1_data
= {
362 .reset_bit
= RESET_MODULE_GE1_MAC
,
365 struct platform_device ar71xx_eth1_device
= {
368 .resource
= ar71xx_eth1_resources
,
369 .num_resources
= ARRAY_SIZE(ar71xx_eth1_resources
),
371 .platform_data
= &ar71xx_eth1_data
,
375 #define AR71XX_PLL_VAL_1000 0x00110000
376 #define AR71XX_PLL_VAL_100 0x00001099
377 #define AR71XX_PLL_VAL_10 0x00991099
379 #define AR724X_PLL_VAL_1000 0x00110000
380 #define AR724X_PLL_VAL_100 0x00001099
381 #define AR724X_PLL_VAL_10 0x00991099
383 #define AR7242_PLL_VAL_1000 0x1c000000
384 #define AR7242_PLL_VAL_100 0x00000101
385 #define AR7242_PLL_VAL_10 0x00001616
387 #define AR91XX_PLL_VAL_1000 0x1a000000
388 #define AR91XX_PLL_VAL_100 0x13000a44
389 #define AR91XX_PLL_VAL_10 0x00441099
391 #define AR933X_PLL_VAL_1000 0x00110000
392 #define AR933X_PLL_VAL_100 0x00001099
393 #define AR933X_PLL_VAL_10 0x00991099
395 static void __init
ar71xx_init_eth_pll_data(unsigned int id
)
397 struct ar71xx_eth_pll_data
*pll_data
;
398 u32 pll_10
, pll_100
, pll_1000
;
402 pll_data
= &ar71xx_eth0_pll_data
;
405 pll_data
= &ar71xx_eth1_pll_data
;
411 switch (ar71xx_soc
) {
412 case AR71XX_SOC_AR7130
:
413 case AR71XX_SOC_AR7141
:
414 case AR71XX_SOC_AR7161
:
415 pll_10
= AR71XX_PLL_VAL_10
;
416 pll_100
= AR71XX_PLL_VAL_100
;
417 pll_1000
= AR71XX_PLL_VAL_1000
;
420 case AR71XX_SOC_AR7240
:
421 case AR71XX_SOC_AR7241
:
422 pll_10
= AR724X_PLL_VAL_10
;
423 pll_100
= AR724X_PLL_VAL_100
;
424 pll_1000
= AR724X_PLL_VAL_1000
;
427 case AR71XX_SOC_AR7242
:
428 pll_10
= AR7242_PLL_VAL_10
;
429 pll_100
= AR7242_PLL_VAL_100
;
430 pll_1000
= AR7242_PLL_VAL_1000
;
433 case AR71XX_SOC_AR9130
:
434 case AR71XX_SOC_AR9132
:
435 pll_10
= AR91XX_PLL_VAL_10
;
436 pll_100
= AR91XX_PLL_VAL_100
;
437 pll_1000
= AR91XX_PLL_VAL_1000
;
440 case AR71XX_SOC_AR9330
:
441 case AR71XX_SOC_AR9331
:
442 pll_10
= AR933X_PLL_VAL_10
;
443 pll_100
= AR933X_PLL_VAL_100
;
444 pll_1000
= AR933X_PLL_VAL_1000
;
451 if (!pll_data
->pll_10
)
452 pll_data
->pll_10
= pll_10
;
454 if (!pll_data
->pll_100
)
455 pll_data
->pll_100
= pll_100
;
457 if (!pll_data
->pll_1000
)
458 pll_data
->pll_1000
= pll_1000
;
461 static int ar71xx_eth_instance __initdata
;
462 void __init
ar71xx_add_device_eth(unsigned int id
)
464 struct platform_device
*pdev
;
465 struct ag71xx_platform_data
*pdata
;
467 ar71xx_init_eth_pll_data(id
);
471 switch (ar71xx_eth0_data
.phy_if_mode
) {
472 case PHY_INTERFACE_MODE_MII
:
473 ar71xx_eth0_data
.mii_if
= MII0_CTRL_IF_MII
;
475 case PHY_INTERFACE_MODE_GMII
:
476 ar71xx_eth0_data
.mii_if
= MII0_CTRL_IF_GMII
;
478 case PHY_INTERFACE_MODE_RGMII
:
479 ar71xx_eth0_data
.mii_if
= MII0_CTRL_IF_RGMII
;
481 case PHY_INTERFACE_MODE_RMII
:
482 ar71xx_eth0_data
.mii_if
= MII0_CTRL_IF_RMII
;
485 printk(KERN_ERR
"ar71xx: invalid PHY interface mode "
489 pdev
= &ar71xx_eth0_device
;
492 switch (ar71xx_eth1_data
.phy_if_mode
) {
493 case PHY_INTERFACE_MODE_RMII
:
494 ar71xx_eth1_data
.mii_if
= MII1_CTRL_IF_RMII
;
496 case PHY_INTERFACE_MODE_RGMII
:
497 ar71xx_eth1_data
.mii_if
= MII1_CTRL_IF_RGMII
;
500 printk(KERN_ERR
"ar71xx: invalid PHY interface mode "
504 pdev
= &ar71xx_eth1_device
;
507 printk(KERN_ERR
"ar71xx: invalid ethernet id %d\n", id
);
511 pdata
= pdev
->dev
.platform_data
;
513 switch (ar71xx_soc
) {
514 case AR71XX_SOC_AR7130
:
515 pdata
->ddr_flush
= id
? ar71xx_ddr_flush_ge1
516 : ar71xx_ddr_flush_ge0
;
517 pdata
->set_pll
= id
? ar71xx_set_pll_ge1
518 : ar71xx_set_pll_ge0
;
521 case AR71XX_SOC_AR7141
:
522 case AR71XX_SOC_AR7161
:
523 pdata
->ddr_flush
= id
? ar71xx_ddr_flush_ge1
524 : ar71xx_ddr_flush_ge0
;
525 pdata
->set_pll
= id
? ar71xx_set_pll_ge1
526 : ar71xx_set_pll_ge0
;
530 case AR71XX_SOC_AR7242
:
531 ar71xx_eth0_data
.reset_bit
|= AR724X_RESET_GE0_MDIO
;
532 ar71xx_eth1_data
.reset_bit
|= AR724X_RESET_GE1_MDIO
;
533 pdata
->ddr_flush
= id
? ar724x_ddr_flush_ge1
534 : ar724x_ddr_flush_ge0
;
535 pdata
->set_pll
= id
? ar724x_set_pll_ge1
536 : ar7242_set_pll_ge0
;
538 pdata
->is_ar724x
= 1;
540 if (!pdata
->fifo_cfg1
)
541 pdata
->fifo_cfg1
= 0x0010ffff;
542 if (!pdata
->fifo_cfg2
)
543 pdata
->fifo_cfg2
= 0x015500aa;
544 if (!pdata
->fifo_cfg3
)
545 pdata
->fifo_cfg3
= 0x01f00140;
548 case AR71XX_SOC_AR7241
:
549 ar71xx_eth0_data
.reset_bit
|= AR724X_RESET_GE0_MDIO
;
550 ar71xx_eth1_data
.reset_bit
|= AR724X_RESET_GE1_MDIO
;
552 case AR71XX_SOC_AR7240
:
553 pdata
->ddr_flush
= id
? ar724x_ddr_flush_ge1
554 : ar724x_ddr_flush_ge0
;
555 pdata
->set_pll
= id
? ar724x_set_pll_ge1
556 : ar724x_set_pll_ge0
;
557 pdata
->is_ar724x
= 1;
559 if (!pdata
->fifo_cfg1
)
560 pdata
->fifo_cfg1
= 0x0010ffff;
561 if (!pdata
->fifo_cfg2
)
562 pdata
->fifo_cfg2
= 0x015500aa;
563 if (!pdata
->fifo_cfg3
)
564 pdata
->fifo_cfg3
= 0x01f00140;
567 case AR71XX_SOC_AR9130
:
568 pdata
->ddr_flush
= id
? ar91xx_ddr_flush_ge1
569 : ar91xx_ddr_flush_ge0
;
570 pdata
->set_pll
= id
? ar91xx_set_pll_ge1
571 : ar91xx_set_pll_ge0
;
572 pdata
->is_ar91xx
= 1;
575 case AR71XX_SOC_AR9132
:
576 pdata
->ddr_flush
= id
? ar91xx_ddr_flush_ge1
577 : ar91xx_ddr_flush_ge0
;
578 pdata
->set_pll
= id
? ar91xx_set_pll_ge1
579 : ar91xx_set_pll_ge0
;
580 pdata
->is_ar91xx
= 1;
584 case AR71XX_SOC_AR9330
:
585 case AR71XX_SOC_AR9331
:
586 ar71xx_eth0_data
.reset_bit
= AR933X_RESET_GE0_MAC
|
587 AR933X_RESET_GE0_MDIO
;
588 ar71xx_eth1_data
.reset_bit
= AR933X_RESET_GE1_MAC
|
589 AR933X_RESET_GE1_MDIO
;
590 pdata
->ddr_flush
= id
? ar933x_ddr_flush_ge1
591 : ar933x_ddr_flush_ge0
;
592 pdata
->set_pll
= id
? ar933x_set_pll_ge1
593 : ar933x_set_pll_ge0
;
595 pdata
->is_ar724x
= 1;
597 if (!pdata
->fifo_cfg1
)
598 pdata
->fifo_cfg1
= 0x0010ffff;
599 if (!pdata
->fifo_cfg2
)
600 pdata
->fifo_cfg2
= 0x015500aa;
601 if (!pdata
->fifo_cfg3
)
602 pdata
->fifo_cfg3
= 0x01f00140;
609 switch (pdata
->phy_if_mode
) {
610 case PHY_INTERFACE_MODE_GMII
:
611 case PHY_INTERFACE_MODE_RGMII
:
612 if (!pdata
->has_gbit
) {
613 printk(KERN_ERR
"ar71xx: no gbit available on eth%d\n",
622 if (!is_valid_ether_addr(pdata
->mac_addr
)) {
623 random_ether_addr(pdata
->mac_addr
);
625 "ar71xx: using random MAC address for eth%d\n",
626 ar71xx_eth_instance
);
629 if (pdata
->mii_bus_dev
== NULL
)
630 pdata
->mii_bus_dev
= &ar71xx_mdio_device
.dev
;
632 /* Reset the device */
633 ar71xx_device_stop(pdata
->reset_bit
);
636 ar71xx_device_start(pdata
->reset_bit
);
639 platform_device_register(pdev
);
640 ar71xx_eth_instance
++;
643 static struct resource ar71xx_spi_resources
[] = {
645 .start
= AR71XX_SPI_BASE
,
646 .end
= AR71XX_SPI_BASE
+ AR71XX_SPI_SIZE
- 1,
647 .flags
= IORESOURCE_MEM
,
651 static struct platform_device ar71xx_spi_device
= {
652 .name
= "ar71xx-spi",
654 .resource
= ar71xx_spi_resources
,
655 .num_resources
= ARRAY_SIZE(ar71xx_spi_resources
),
658 void __init
ar71xx_add_device_spi(struct ar71xx_spi_platform_data
*pdata
,
659 struct spi_board_info
const *info
,
662 spi_register_board_info(info
, n
);
663 ar71xx_spi_device
.dev
.platform_data
= pdata
;
664 platform_device_register(&ar71xx_spi_device
);
667 void __init
ar71xx_add_device_wdt(void)
669 platform_device_register_simple("ar71xx-wdt", -1, NULL
, 0);
672 void __init
ar71xx_set_mac_base(unsigned char *mac
)
674 memcpy(ar71xx_mac_base
, mac
, ETH_ALEN
);
677 void __init
ar71xx_parse_mac_addr(char *mac_str
)
682 t
= sscanf(mac_str
, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
683 &tmp
[0], &tmp
[1], &tmp
[2], &tmp
[3], &tmp
[4], &tmp
[5]);
686 t
= sscanf(mac_str
, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
687 &tmp
[0], &tmp
[1], &tmp
[2], &tmp
[3], &tmp
[4], &tmp
[5]);
690 ar71xx_set_mac_base(tmp
);
692 printk(KERN_DEBUG
"ar71xx: failed to parse mac address "
693 "\"%s\"\n", mac_str
);
696 static int __init
ar71xx_ethaddr_setup(char *str
)
698 ar71xx_parse_mac_addr(str
);
701 __setup("ethaddr=", ar71xx_ethaddr_setup
);
703 static int __init
ar71xx_kmac_setup(char *str
)
705 ar71xx_parse_mac_addr(str
);
708 __setup("kmac=", ar71xx_kmac_setup
);
710 void __init
ar71xx_init_mac(unsigned char *dst
, const unsigned char *src
,
715 if (!is_valid_ether_addr(src
)) {
716 memset(dst
, '\0', ETH_ALEN
);
720 t
= (((u32
) src
[3]) << 16) + (((u32
) src
[4]) << 8) + ((u32
) src
[5]);
726 dst
[3] = (t
>> 16) & 0xff;
727 dst
[4] = (t
>> 8) & 0xff;