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 struct ath9k_platform_data wndr3700_wmac1_data;
112 static void wndr3700_pci_fixup(struct pci_dev *dev)
120 if (ar71xx_mach != AR71XX_MACH_WNDR3700)
123 switch (PCI_SLOT(dev->devfn)) {
125 cal_data = wndr3700_wmac0_data.eeprom_data;
128 cal_data = wndr3700_wmac1_data.eeprom_data;
134 if (*cal_data != 0xa55a) {
135 printk(KERN_ERR "PCI: no calibration data found for %s\n",
140 mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
142 printk(KERN_ERR "PCI: ioremap error for device %s\n",
147 printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
149 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
151 /* Setup the PCI device to allow access to the internal registers */
152 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, AR71XX_PCI_MEM_BASE);
153 pci_read_config_word(dev, PCI_COMMAND, &cmd);
154 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
155 pci_write_config_word(dev, PCI_COMMAND, cmd);
157 /* set pointer to first reg address */
159 while (*cal_data != 0xffff) {
163 val |= (*cal_data++) << 16;
165 __raw_writel(val, mem + reg);
169 pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
170 dev->vendor = val & 0xffff;
171 dev->device = (val >> 16) & 0xffff;
173 pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
174 dev->revision = val & 0xff;
175 dev->class = val >> 8; /* upper 3 bytes */
177 pci_read_config_word(dev, PCI_COMMAND, &cmd);
178 cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
179 pci_write_config_word(dev, PCI_COMMAND, cmd);
181 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
185 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID,
188 static int wndr3700_pci_plat_dev_init(struct pci_dev *dev)
190 switch (PCI_SLOT(dev->devfn)) {
192 dev->dev.platform_data = &wndr3700_wmac0_data;
195 dev->dev.platform_data = &wndr3700_wmac1_data;
202 static void __init wndr3700_pci_init(void)
206 ee = (u8 *) KSEG1ADDR(0x1fff1000);
207 memcpy(wndr3700_wmac0_data.eeprom_data, ee,
208 sizeof(wndr3700_wmac0_data.eeprom_data));
210 ee = (u8 *) KSEG1ADDR(0x1fff5000);
211 memcpy(wndr3700_wmac1_data.eeprom_data, ee,
212 sizeof(wndr3700_wmac1_data.eeprom_data));
214 ar71xx_pci_plat_dev_init = wndr3700_pci_plat_dev_init;
215 ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs), wndr3700_pci_irqs);
218 static inline void wndr3700_pci_init(void) { };
219 #endif /* CONFIG_PCI */
221 static struct spi_board_info wndr3700_spi_info[] = {
225 .max_speed_hz = 25000000,
226 .modalias = "m25p80",
227 .platform_data = &wndr3700_flash_data,
231 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
233 .name = "wndr3700:green:power",
234 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
237 .name = "wndr3700:orange:power",
238 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
241 .name = "wndr3700:green:wps",
242 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
245 .name = "wndr3700:orange:wps",
246 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
251 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
257 .gpio = WNDR3700_GPIO_BTN_RESET,
263 .gpio = WNDR3700_GPIO_BTN_WPS,
269 .gpio = WNDR3700_GPIO_BTN_WIFI,
273 static void __init wndr3700_setup(void)
275 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
277 ar71xx_set_mac_base(mac);
278 ar71xx_add_device_mdio(0x0);
280 ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
281 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
282 ar71xx_eth0_data.phy_mask = 0xf;
283 ar71xx_eth0_data.speed = SPEED_1000;
284 ar71xx_eth0_data.duplex = DUPLEX_FULL;
286 ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
287 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
288 ar71xx_eth1_data.phy_mask = 0x10;
290 ar71xx_add_device_eth(0);
291 ar71xx_add_device_eth(1);
293 ar71xx_add_device_usb();
295 ar71xx_add_device_spi(NULL, wndr3700_spi_info,
296 ARRAY_SIZE(wndr3700_spi_info));
298 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
301 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
302 ARRAY_SIZE(wndr3700_gpio_buttons),
303 wndr3700_gpio_buttons);
308 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);