2 * Netgear WNDR3700 board support
4 * Copyright (C) 2009 Marco Porsch
5 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/input.h>
16 #include <linux/pci.h>
17 #include <linux/ath9k_platform.h>
18 #include <linux/delay.h>
19 #include <linux/rtl8366_smi.h>
21 #include <asm/mips_machine.h>
22 #include <asm/mach-ar71xx/ar71xx.h>
23 #include <asm/mach-ar71xx/pci.h>
26 #include "dev-m25p80.h"
28 #define WNDR3700_GPIO_LED_WPS_ORANGE 0
29 #define WNDR3700_GPIO_LED_POWER_ORANGE 1
30 #define WNDR3700_GPIO_LED_POWER_GREEN 2
31 #define WNDR3700_GPIO_LED_WPS_GREEN 4
33 #define WNDR3700_GPIO_BTN_WPS 3
34 #define WNDR3700_GPIO_BTN_RESET 8
35 #define WNDR3700_GPIO_BTN_WIFI 11
37 #define WNDR3700_GPIO_RTL8366_SDA 5
38 #define WNDR3700_GPIO_RTL8366_SCK 7
40 #define WNDR3700_BUTTONS_POLL_INTERVAL 20
42 #ifdef CONFIG_MTD_PARTITIONS
43 static struct mtd_partition wndr3700_partitions
[] = {
48 .mask_flags
= MTD_WRITEABLE
,
53 .mask_flags
= MTD_WRITEABLE
,
62 .mask_flags
= MTD_WRITEABLE
,
67 .mask_flags
= MTD_WRITEABLE
,
72 .mask_flags
= MTD_WRITEABLE
,
74 .name
= "traffic_meter",
77 .mask_flags
= MTD_WRITEABLE
,
82 .mask_flags
= MTD_WRITEABLE
,
87 .mask_flags
= MTD_WRITEABLE
,
90 #endif /* CONFIG_MTD_PARTITIONS */
92 static struct flash_platform_data wndr3700_flash_data
= {
93 #ifdef CONFIG_MTD_PARTITIONS
94 .parts
= wndr3700_partitions
,
95 .nr_parts
= ARRAY_SIZE(wndr3700_partitions
),
100 static struct ar71xx_pci_irq wndr3700_pci_irqs
[] __initdata
= {
104 .irq
= AR71XX_PCI_IRQ_DEV0
,
108 .irq
= AR71XX_PCI_IRQ_DEV1
,
112 static struct ath9k_platform_data wndr3700_wmac0_data
;
113 static u8 wndr3700_wmac0_macaddr
[6];
114 static struct ath9k_platform_data wndr3700_wmac1_data
;
115 static u8 wndr3700_wmac1_macaddr
[6];
117 static void wndr3700_pci_fixup(struct pci_dev
*dev
)
125 if (ar71xx_mach
!= AR71XX_MACH_WNDR3700
)
128 switch (PCI_SLOT(dev
->devfn
)) {
130 cal_data
= wndr3700_wmac0_data
.eeprom_data
;
133 cal_data
= wndr3700_wmac1_data
.eeprom_data
;
139 if (*cal_data
!= 0xa55a) {
140 printk(KERN_ERR
"PCI: no calibration data found for %s\n",
145 mem
= ioremap(AR71XX_PCI_MEM_BASE
, 0x10000);
147 printk(KERN_ERR
"PCI: ioremap error for device %s\n",
152 printk(KERN_INFO
"PCI: fixup device %s\n", pci_name(dev
));
154 pci_read_config_dword(dev
, PCI_BASE_ADDRESS_0
, &bar0
);
156 /* Setup the PCI device to allow access to the internal registers */
157 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
, AR71XX_PCI_MEM_BASE
);
158 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
159 cmd
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
;
160 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
162 /* set pointer to first reg address */
164 while (*cal_data
!= 0xffff) {
168 val
|= (*cal_data
++) << 16;
170 __raw_writel(val
, mem
+ reg
);
174 pci_read_config_dword(dev
, PCI_VENDOR_ID
, &val
);
175 dev
->vendor
= val
& 0xffff;
176 dev
->device
= (val
>> 16) & 0xffff;
178 pci_read_config_dword(dev
, PCI_CLASS_REVISION
, &val
);
179 dev
->revision
= val
& 0xff;
180 dev
->class = val
>> 8; /* upper 3 bytes */
182 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
183 cmd
&= ~(PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
);
184 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
186 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
, bar0
);
190 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS
, PCI_ANY_ID
,
193 static int wndr3700_pci_plat_dev_init(struct pci_dev
*dev
)
195 switch (PCI_SLOT(dev
->devfn
)) {
197 dev
->dev
.platform_data
= &wndr3700_wmac0_data
;
200 dev
->dev
.platform_data
= &wndr3700_wmac1_data
;
207 static void __init
wndr3700_pci_init(void)
209 u8
*ee
= (u8
*) KSEG1ADDR(0x1fff0000);
211 memcpy(wndr3700_wmac0_data
.eeprom_data
, ee
+ 0x1000,
212 sizeof(wndr3700_wmac0_data
.eeprom_data
));
213 memcpy(wndr3700_wmac0_macaddr
, ee
, sizeof(wndr3700_wmac0_macaddr
));
214 wndr3700_wmac0_data
.macaddr
= wndr3700_wmac0_macaddr
;
216 memcpy(wndr3700_wmac1_data
.eeprom_data
, ee
+ 0x5000,
217 sizeof(wndr3700_wmac1_data
.eeprom_data
));
218 memcpy(wndr3700_wmac1_macaddr
, ee
+ 12, sizeof(wndr3700_wmac1_macaddr
));
219 wndr3700_wmac1_data
.macaddr
= wndr3700_wmac1_macaddr
;
221 ar71xx_pci_plat_dev_init
= wndr3700_pci_plat_dev_init
;
222 ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs
), wndr3700_pci_irqs
);
225 static inline void wndr3700_pci_init(void) { };
226 #endif /* CONFIG_PCI */
228 static struct gpio_led wndr3700_leds_gpio
[] __initdata
= {
230 .name
= "wndr3700:green:power",
231 .gpio
= WNDR3700_GPIO_LED_POWER_GREEN
,
234 .name
= "wndr3700:orange:power",
235 .gpio
= WNDR3700_GPIO_LED_POWER_ORANGE
,
238 .name
= "wndr3700:green:wps",
239 .gpio
= WNDR3700_GPIO_LED_WPS_GREEN
,
242 .name
= "wndr3700:orange:wps",
243 .gpio
= WNDR3700_GPIO_LED_WPS_ORANGE
,
248 static struct gpio_button wndr3700_gpio_buttons
[] __initdata
= {
254 .gpio
= WNDR3700_GPIO_BTN_RESET
,
260 .gpio
= WNDR3700_GPIO_BTN_WPS
,
266 .gpio
= WNDR3700_GPIO_BTN_WIFI
,
270 static struct rtl8366_smi_platform_data wndr3700_rtl8366_smi_data
= {
271 .gpio_sda
= WNDR3700_GPIO_RTL8366_SDA
,
272 .gpio_sck
= WNDR3700_GPIO_RTL8366_SCK
,
275 static struct platform_device wndr3700_rtl8366_smi_device
= {
276 .name
= "rtl8366-smi",
279 .platform_data
= &wndr3700_rtl8366_smi_data
,
283 static void __init
wndr3700_setup(void)
285 u8
*mac
= (u8
*) KSEG1ADDR(0x1fff0000);
287 ar71xx_set_mac_base(mac
);
289 ar71xx_eth0_pll_data
.pll_1000
= 0x11110000;
290 ar71xx_eth0_data
.mii_bus_dev
= &wndr3700_rtl8366_smi_device
.dev
;
291 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
292 ar71xx_eth0_data
.phy_mask
= 0xf;
293 ar71xx_eth0_data
.speed
= SPEED_1000
;
294 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
296 ar71xx_eth1_pll_data
.pll_1000
= 0x11110000;
297 ar71xx_eth1_data
.mii_bus_dev
= &wndr3700_rtl8366_smi_device
.dev
;
298 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
299 ar71xx_eth1_data
.phy_mask
= 0x10;
301 ar71xx_add_device_eth(0);
302 ar71xx_add_device_eth(1);
304 ar71xx_add_device_usb();
306 ar71xx_add_device_m25p80(&wndr3700_flash_data
);
308 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio
),
311 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL
,
312 ARRAY_SIZE(wndr3700_gpio_buttons
),
313 wndr3700_gpio_buttons
);
315 platform_device_register(&wndr3700_rtl8366_smi_device
);
316 platform_device_register_simple("wndr3700-led-usb", -1, NULL
, 0);
320 MIPS_MACHINE(AR71XX_MACH_WNDR3700
, "NETGEAR WNDR3700", wndr3700_setup
);