729267ac461488bd668dea8db83cd3bd623b9e83
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wndr3700.c
1 /*
2 * Netgear WNDR3700 board support
3 *
4 * Copyright (C) 2009 Marco Porsch
5 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
6 *
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.
10 */
11
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>
22
23 #include <asm/mips_machine.h>
24 #include <asm/mach-ar71xx/ar71xx.h>
25 #include <asm/mach-ar71xx/pci.h>
26
27 #include "devices.h"
28
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
33
34 #define WNDR3700_GPIO_BTN_WPS 3
35 #define WNDR3700_GPIO_BTN_RESET 8
36 #define WNDR3700_GPIO_BTN_WIFI 11
37
38 #define WNDR3700_GPIO_RTL8366_SDA 5
39 #define WNDR3700_GPIO_RTL8366_SCK 7
40
41 #define WNDR3700_BUTTONS_POLL_INTERVAL 20
42
43 #ifdef CONFIG_MTD_PARTITIONS
44 static struct mtd_partition wndr3700_partitions[] = {
45 {
46 .name = "uboot",
47 .offset = 0,
48 .size = 0x050000,
49 .mask_flags = MTD_WRITEABLE,
50 } , {
51 .name = "env",
52 .offset = 0x050000,
53 .size = 0x020000,
54 .mask_flags = MTD_WRITEABLE,
55 } , {
56 .name = "rootfs",
57 .offset = 0x070000,
58 .size = 0x720000,
59 } , {
60 .name = "config",
61 .offset = 0x790000,
62 .size = 0x010000,
63 .mask_flags = MTD_WRITEABLE,
64 } , {
65 .name = "config_bak",
66 .offset = 0x7a0000,
67 .size = 0x010000,
68 .mask_flags = MTD_WRITEABLE,
69 } , {
70 .name = "pot",
71 .offset = 0x7b0000,
72 .size = 0x010000,
73 .mask_flags = MTD_WRITEABLE,
74 } , {
75 .name = "traffic_meter",
76 .offset = 0x7c0000,
77 .size = 0x010000,
78 .mask_flags = MTD_WRITEABLE,
79 } , {
80 .name = "language",
81 .offset = 0x7d0000,
82 .size = 0x020000,
83 .mask_flags = MTD_WRITEABLE,
84 } , {
85 .name = "caldata",
86 .offset = 0x7f0000,
87 .size = 0x010000,
88 .mask_flags = MTD_WRITEABLE,
89 }
90 };
91 #endif /* CONFIG_MTD_PARTITIONS */
92
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),
97 #endif
98 };
99
100 #ifdef CONFIG_PCI
101 static struct ar71xx_pci_irq wndr3700_pci_irqs[] __initdata = {
102 {
103 .slot = 0,
104 .pin = 1,
105 .irq = AR71XX_PCI_IRQ_DEV0,
106 }, {
107 .slot = 1,
108 .pin = 1,
109 .irq = AR71XX_PCI_IRQ_DEV1,
110 }
111 };
112
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];
117
118 static void wndr3700_pci_fixup(struct pci_dev *dev)
119 {
120 void __iomem *mem;
121 u16 *cal_data;
122 u16 cmd;
123 u32 bar0;
124 u32 val;
125
126 if (ar71xx_mach != AR71XX_MACH_WNDR3700)
127 return;
128
129 switch (PCI_SLOT(dev->devfn)) {
130 case 17:
131 cal_data = wndr3700_wmac0_data.eeprom_data;
132 break;
133 case 18:
134 cal_data = wndr3700_wmac1_data.eeprom_data;
135 break;
136 default:
137 return;
138 }
139
140 if (*cal_data != 0xa55a) {
141 printk(KERN_ERR "PCI: no calibration data found for %s\n",
142 pci_name(dev));
143 return;
144 }
145
146 mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
147 if (!mem) {
148 printk(KERN_ERR "PCI: ioremap error for device %s\n",
149 pci_name(dev));
150 return;
151 }
152
153 printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
154
155 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
156
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);
162
163 /* set pointer to first reg address */
164 cal_data += 3;
165 while (*cal_data != 0xffff) {
166 u32 reg;
167 reg = *cal_data++;
168 val = *cal_data++;
169 val |= (*cal_data++) << 16;
170
171 __raw_writel(val, mem + reg);
172 udelay(100);
173 }
174
175 pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
176 dev->vendor = val & 0xffff;
177 dev->device = (val >> 16) & 0xffff;
178
179 pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
180 dev->revision = val & 0xff;
181 dev->class = val >> 8; /* upper 3 bytes */
182
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);
186
187 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
188
189 iounmap(mem);
190 }
191 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID,
192 wndr3700_pci_fixup);
193
194 static int wndr3700_pci_plat_dev_init(struct pci_dev *dev)
195 {
196 switch (PCI_SLOT(dev->devfn)) {
197 case 17:
198 dev->dev.platform_data = &wndr3700_wmac0_data;
199 break;
200 case 18:
201 dev->dev.platform_data = &wndr3700_wmac1_data;
202 break;
203 }
204
205 return 0;
206 }
207
208 static void __init wndr3700_pci_init(void)
209 {
210 u8 *ee = (u8 *) KSEG1ADDR(0x1fff0000);
211
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;
216
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;
221
222 ar71xx_pci_plat_dev_init = wndr3700_pci_plat_dev_init;
223 ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs), wndr3700_pci_irqs);
224 }
225 #else
226 static inline void wndr3700_pci_init(void) { };
227 #endif /* CONFIG_PCI */
228
229 static struct spi_board_info wndr3700_spi_info[] = {
230 {
231 .bus_num = 0,
232 .chip_select = 0,
233 .max_speed_hz = 25000000,
234 .modalias = "m25p80",
235 .platform_data = &wndr3700_flash_data,
236 }
237 };
238
239 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
240 {
241 .name = "wndr3700:green:power",
242 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
243 .active_low = 1,
244 }, {
245 .name = "wndr3700:orange:power",
246 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
247 .active_low = 1,
248 }, {
249 .name = "wndr3700:green:wps",
250 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
251 .active_low = 1,
252 }, {
253 .name = "wndr3700:orange:wps",
254 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
255 .active_low = 1,
256 }
257 };
258
259 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
260 {
261 .desc = "reset",
262 .type = EV_KEY,
263 .code = BTN_0,
264 .threshold = 5,
265 .gpio = WNDR3700_GPIO_BTN_RESET,
266 }, {
267 .desc = "wps",
268 .type = EV_KEY,
269 .code = BTN_1,
270 .threshold = 5,
271 .gpio = WNDR3700_GPIO_BTN_WPS,
272 } , {
273 .desc = "wifi",
274 .type = EV_KEY,
275 .code = BTN_2,
276 .threshold = 5,
277 .gpio = WNDR3700_GPIO_BTN_WIFI,
278 }
279 };
280
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,
284 };
285
286 static struct platform_device wndr3700_rtl8366_smi_device = {
287 .name = "rtl8366-smi",
288 .id = -1,
289 .dev = {
290 .platform_data = &wndr3700_rtl8366_smi_data,
291 }
292 };
293
294 static void __init wndr3700_setup(void)
295 {
296 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
297
298 ar71xx_set_mac_base(mac);
299
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;
306
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;
311
312 ar71xx_add_device_eth(0);
313 ar71xx_add_device_eth(1);
314
315 ar71xx_add_device_usb();
316
317 ar71xx_add_device_spi(NULL, wndr3700_spi_info,
318 ARRAY_SIZE(wndr3700_spi_info));
319
320 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
321 wndr3700_leds_gpio);
322
323 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
324 ARRAY_SIZE(wndr3700_gpio_buttons),
325 wndr3700_gpio_buttons);
326
327 platform_device_register(&wndr3700_rtl8366_smi_device);
328 platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
329 wndr3700_pci_init();
330 }
331
332 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);
This page took 0.060735 seconds and 3 git commands to generate.