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/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/input.h>
18 #include <linux/pci.h>
19 #include <linux/ath9k_platform.h>
20 #include <linux/delay.h>
22 #include <asm/mips_machine.h>
23 #include <asm/mach-ar71xx/ar71xx.h>
24 #include <asm/mach-ar71xx/pci.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_BUTTONS_POLL_INTERVAL 20
39 #ifdef CONFIG_MTD_PARTITIONS
40 static struct mtd_partition wndr3700_partitions
[] = {
45 .mask_flags
= MTD_WRITEABLE
,
50 .mask_flags
= MTD_WRITEABLE
,
59 .mask_flags
= MTD_WRITEABLE
,
64 .mask_flags
= MTD_WRITEABLE
,
69 .mask_flags
= MTD_WRITEABLE
,
71 .name
= "traffic_meter",
74 .mask_flags
= MTD_WRITEABLE
,
79 .mask_flags
= MTD_WRITEABLE
,
84 .mask_flags
= MTD_WRITEABLE
,
87 #endif /* CONFIG_MTD_PARTITIONS */
89 static struct flash_platform_data wndr3700_flash_data
= {
90 #ifdef CONFIG_MTD_PARTITIONS
91 .parts
= wndr3700_partitions
,
92 .nr_parts
= ARRAY_SIZE(wndr3700_partitions
),
97 static struct ar71xx_pci_irq wndr3700_pci_irqs
[] __initdata
= {
101 .irq
= AR71XX_PCI_IRQ_DEV0
,
105 .irq
= AR71XX_PCI_IRQ_DEV1
,
109 static struct ath9k_platform_data wndr3700_wmac0_data
;
110 static u8 wndr3700_wmac0_macaddr
[6];
111 static struct ath9k_platform_data wndr3700_wmac1_data
;
112 static u8 wndr3700_wmac1_macaddr
[6];
114 static void wndr3700_pci_fixup(struct pci_dev
*dev
)
122 if (ar71xx_mach
!= AR71XX_MACH_WNDR3700
)
125 switch (PCI_SLOT(dev
->devfn
)) {
127 cal_data
= wndr3700_wmac0_data
.eeprom_data
;
130 cal_data
= wndr3700_wmac1_data
.eeprom_data
;
136 if (*cal_data
!= 0xa55a) {
137 printk(KERN_ERR
"PCI: no calibration data found for %s\n",
142 mem
= ioremap(AR71XX_PCI_MEM_BASE
, 0x10000);
144 printk(KERN_ERR
"PCI: ioremap error for device %s\n",
149 printk(KERN_INFO
"PCI: fixup device %s\n", pci_name(dev
));
151 pci_read_config_dword(dev
, PCI_BASE_ADDRESS_0
, &bar0
);
153 /* Setup the PCI device to allow access to the internal registers */
154 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
, AR71XX_PCI_MEM_BASE
);
155 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
156 cmd
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
;
157 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
159 /* set pointer to first reg address */
161 while (*cal_data
!= 0xffff) {
165 val
|= (*cal_data
++) << 16;
167 __raw_writel(val
, mem
+ reg
);
171 pci_read_config_dword(dev
, PCI_VENDOR_ID
, &val
);
172 dev
->vendor
= val
& 0xffff;
173 dev
->device
= (val
>> 16) & 0xffff;
175 pci_read_config_dword(dev
, PCI_CLASS_REVISION
, &val
);
176 dev
->revision
= val
& 0xff;
177 dev
->class = val
>> 8; /* upper 3 bytes */
179 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
180 cmd
&= ~(PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
);
181 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
183 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
, bar0
);
187 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS
, PCI_ANY_ID
,
190 static int wndr3700_pci_plat_dev_init(struct pci_dev
*dev
)
192 switch (PCI_SLOT(dev
->devfn
)) {
194 dev
->dev
.platform_data
= &wndr3700_wmac0_data
;
197 dev
->dev
.platform_data
= &wndr3700_wmac1_data
;
204 static void __init
wndr3700_pci_init(void)
206 u8
*ee
= (u8
*) KSEG1ADDR(0x1fff0000);
208 memcpy(wndr3700_wmac0_data
.eeprom_data
, ee
+ 0x1000,
209 sizeof(wndr3700_wmac0_data
.eeprom_data
));
210 memcpy(wndr3700_wmac0_macaddr
, ee
, sizeof(wndr3700_wmac0_macaddr
));
211 wndr3700_wmac0_data
.macaddr
= wndr3700_wmac0_macaddr
;
213 memcpy(wndr3700_wmac1_data
.eeprom_data
, ee
+ 0x5000,
214 sizeof(wndr3700_wmac1_data
.eeprom_data
));
215 memcpy(wndr3700_wmac1_macaddr
, ee
+ 12, sizeof(wndr3700_wmac1_macaddr
));
216 wndr3700_wmac1_data
.macaddr
= wndr3700_wmac1_macaddr
;
218 ar71xx_pci_plat_dev_init
= wndr3700_pci_plat_dev_init
;
219 ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs
), wndr3700_pci_irqs
);
222 static inline void wndr3700_pci_init(void) { };
223 #endif /* CONFIG_PCI */
225 static struct spi_board_info wndr3700_spi_info
[] = {
229 .max_speed_hz
= 25000000,
230 .modalias
= "m25p80",
231 .platform_data
= &wndr3700_flash_data
,
235 static struct gpio_led wndr3700_leds_gpio
[] __initdata
= {
237 .name
= "wndr3700:green:power",
238 .gpio
= WNDR3700_GPIO_LED_POWER_GREEN
,
241 .name
= "wndr3700:orange:power",
242 .gpio
= WNDR3700_GPIO_LED_POWER_ORANGE
,
245 .name
= "wndr3700:green:wps",
246 .gpio
= WNDR3700_GPIO_LED_WPS_GREEN
,
249 .name
= "wndr3700:orange:wps",
250 .gpio
= WNDR3700_GPIO_LED_WPS_ORANGE
,
255 static struct gpio_button wndr3700_gpio_buttons
[] __initdata
= {
261 .gpio
= WNDR3700_GPIO_BTN_RESET
,
267 .gpio
= WNDR3700_GPIO_BTN_WPS
,
273 .gpio
= WNDR3700_GPIO_BTN_WIFI
,
277 static void __init
wndr3700_setup(void)
279 u8
*mac
= (u8
*) KSEG1ADDR(0x1fff0000);
281 ar71xx_set_mac_base(mac
);
282 ar71xx_add_device_mdio(0x0);
284 ar71xx_eth0_pll_data
.pll_1000
= 0x11110000;
285 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
286 ar71xx_eth0_data
.phy_mask
= 0xf;
287 ar71xx_eth0_data
.speed
= SPEED_1000
;
288 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
290 ar71xx_eth1_pll_data
.pll_1000
= 0x11110000;
291 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
292 ar71xx_eth1_data
.phy_mask
= 0x10;
294 ar71xx_add_device_eth(0);
295 ar71xx_add_device_eth(1);
297 ar71xx_add_device_usb();
299 ar71xx_add_device_spi(NULL
, wndr3700_spi_info
,
300 ARRAY_SIZE(wndr3700_spi_info
));
302 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio
),
305 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL
,
306 ARRAY_SIZE(wndr3700_gpio_buttons
),
307 wndr3700_gpio_buttons
);
312 MIPS_MACHINE(AR71XX_MACH_WNDR3700
, "NETGEAR WNDR3700", wndr3700_setup
);