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>
21 #include <linux/rtl8366_smi.h>
23 #include <asm/mips_machine.h>
24 #include <asm/mach-ar71xx/ar71xx.h>
25 #include <asm/mach-ar71xx/pci.h>
29 #define WNDR3700_GPIO_LED_WPS_ORANGE 0
30 #define WNDR3700_GPIO_LED_POWER_ORANGE 1
31 #define WNDR3700_GPIO_LED_POWER_GREEN 2
32 #define WNDR3700_GPIO_LED_WPS_GREEN 4
34 #define WNDR3700_GPIO_BTN_WPS 3
35 #define WNDR3700_GPIO_BTN_RESET 8
36 #define WNDR3700_GPIO_BTN_WIFI 11
38 #define WNDR3700_GPIO_RTL8366_SDA 5
39 #define WNDR3700_GPIO_RTL8366_SCK 7
41 #define WNDR3700_BUTTONS_POLL_INTERVAL 20
43 #ifdef CONFIG_MTD_PARTITIONS
44 static struct mtd_partition wndr3700_partitions[] = {
49 .mask_flags = MTD_WRITEABLE,
54 .mask_flags = MTD_WRITEABLE,
63 .mask_flags = MTD_WRITEABLE,
68 .mask_flags = MTD_WRITEABLE,
73 .mask_flags = MTD_WRITEABLE,
75 .name = "traffic_meter",
78 .mask_flags = MTD_WRITEABLE,
83 .mask_flags = MTD_WRITEABLE,
88 .mask_flags = MTD_WRITEABLE,
91 #endif /* CONFIG_MTD_PARTITIONS */
93 static struct flash_platform_data wndr3700_flash_data = {
94 #ifdef CONFIG_MTD_PARTITIONS
95 .parts = wndr3700_partitions,
96 .nr_parts = ARRAY_SIZE(wndr3700_partitions),
101 static struct ar71xx_pci_irq wndr3700_pci_irqs[] __initdata = {
105 .irq = AR71XX_PCI_IRQ_DEV0,
109 .irq = AR71XX_PCI_IRQ_DEV1,
113 static struct ath9k_platform_data wndr3700_wmac0_data;
114 static u8 wndr3700_wmac0_macaddr[6];
115 static struct ath9k_platform_data wndr3700_wmac1_data;
116 static u8 wndr3700_wmac1_macaddr[6];
118 static void wndr3700_pci_fixup(struct pci_dev *dev)
126 if (ar71xx_mach != AR71XX_MACH_WNDR3700)
129 switch (PCI_SLOT(dev->devfn)) {
131 cal_data = wndr3700_wmac0_data.eeprom_data;
134 cal_data = wndr3700_wmac1_data.eeprom_data;
140 if (*cal_data != 0xa55a) {
141 printk(KERN_ERR "PCI: no calibration data found for %s\n",
146 mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
148 printk(KERN_ERR "PCI: ioremap error for device %s\n",
153 printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
155 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
157 /* Setup the PCI device to allow access to the internal registers */
158 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, AR71XX_PCI_MEM_BASE);
159 pci_read_config_word(dev, PCI_COMMAND, &cmd);
160 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
161 pci_write_config_word(dev, PCI_COMMAND, cmd);
163 /* set pointer to first reg address */
165 while (*cal_data != 0xffff) {
169 val |= (*cal_data++) << 16;
171 __raw_writel(val, mem + reg);
175 pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
176 dev->vendor = val & 0xffff;
177 dev->device = (val >> 16) & 0xffff;
179 pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
180 dev->revision = val & 0xff;
181 dev->class = val >> 8; /* upper 3 bytes */
183 pci_read_config_word(dev, PCI_COMMAND, &cmd);
184 cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
185 pci_write_config_word(dev, PCI_COMMAND, cmd);
187 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
191 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID,
194 static int wndr3700_pci_plat_dev_init(struct pci_dev *dev)
196 switch (PCI_SLOT(dev->devfn)) {
198 dev->dev.platform_data = &wndr3700_wmac0_data;
201 dev->dev.platform_data = &wndr3700_wmac1_data;
208 static void __init wndr3700_pci_init(void)
210 u8 *ee = (u8 *) KSEG1ADDR(0x1fff0000);
212 memcpy(wndr3700_wmac0_data.eeprom_data, ee + 0x1000,
213 sizeof(wndr3700_wmac0_data.eeprom_data));
214 memcpy(wndr3700_wmac0_macaddr, ee, sizeof(wndr3700_wmac0_macaddr));
215 wndr3700_wmac0_data.macaddr = wndr3700_wmac0_macaddr;
217 memcpy(wndr3700_wmac1_data.eeprom_data, ee + 0x5000,
218 sizeof(wndr3700_wmac1_data.eeprom_data));
219 memcpy(wndr3700_wmac1_macaddr, ee + 12, sizeof(wndr3700_wmac1_macaddr));
220 wndr3700_wmac1_data.macaddr = wndr3700_wmac1_macaddr;
222 ar71xx_pci_plat_dev_init = wndr3700_pci_plat_dev_init;
223 ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs), wndr3700_pci_irqs);
226 static inline void wndr3700_pci_init(void) { };
227 #endif /* CONFIG_PCI */
229 static struct spi_board_info wndr3700_spi_info[] = {
233 .max_speed_hz = 25000000,
234 .modalias = "m25p80",
235 .platform_data = &wndr3700_flash_data,
239 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
241 .name = "wndr3700:green:power",
242 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
245 .name = "wndr3700:orange:power",
246 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
249 .name = "wndr3700:green:wps",
250 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
253 .name = "wndr3700:orange:wps",
254 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
259 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
265 .gpio = WNDR3700_GPIO_BTN_RESET,
271 .gpio = WNDR3700_GPIO_BTN_WPS,
277 .gpio = WNDR3700_GPIO_BTN_WIFI,
281 static struct rtl8366_smi_platform_data wndr3700_rtl8366_smi_data = {
282 .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
283 .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
286 static struct platform_device wndr3700_rtl8366_smi_device = {
287 .name = "rtl8366-smi",
290 .platform_data = &wndr3700_rtl8366_smi_data,
294 static void __init wndr3700_setup(void)
296 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
298 ar71xx_set_mac_base(mac);
300 ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
301 ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366_smi_device.dev;
302 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
303 ar71xx_eth0_data.phy_mask = 0xf;
304 ar71xx_eth0_data.speed = SPEED_1000;
305 ar71xx_eth0_data.duplex = DUPLEX_FULL;
307 ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
308 ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366_smi_device.dev;
309 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
310 ar71xx_eth1_data.phy_mask = 0x10;
312 ar71xx_add_device_eth(0);
313 ar71xx_add_device_eth(1);
315 ar71xx_add_device_usb();
317 ar71xx_add_device_spi(NULL, wndr3700_spi_info,
318 ARRAY_SIZE(wndr3700_spi_info));
320 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
323 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
324 ARRAY_SIZE(wndr3700_gpio_buttons),
325 wndr3700_gpio_buttons);
327 platform_device_register(&wndr3700_rtl8366_smi_device);
328 platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
332 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);