ar71xx: fix mac address for 5GHz interface on WNDR3700
[openwrt/staging/yousong.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
22 #include <asm/mips_machine.h>
23 #include <asm/mach-ar71xx/ar71xx.h>
24 #include <asm/mach-ar71xx/pci.h>
25
26 #include "devices.h"
27
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
32
33 #define WNDR3700_GPIO_BTN_WPS 3
34 #define WNDR3700_GPIO_BTN_RESET 8
35 #define WNDR3700_GPIO_BTN_WIFI 11
36
37 #define WNDR3700_BUTTONS_POLL_INTERVAL 20
38
39 #ifdef CONFIG_MTD_PARTITIONS
40 static struct mtd_partition wndr3700_partitions[] = {
41 {
42 .name = "uboot",
43 .offset = 0,
44 .size = 0x050000,
45 .mask_flags = MTD_WRITEABLE,
46 } , {
47 .name = "env",
48 .offset = 0x050000,
49 .size = 0x020000,
50 .mask_flags = MTD_WRITEABLE,
51 } , {
52 .name = "rootfs",
53 .offset = 0x070000,
54 .size = 0x720000,
55 } , {
56 .name = "config",
57 .offset = 0x790000,
58 .size = 0x010000,
59 .mask_flags = MTD_WRITEABLE,
60 } , {
61 .name = "config_bak",
62 .offset = 0x7a0000,
63 .size = 0x010000,
64 .mask_flags = MTD_WRITEABLE,
65 } , {
66 .name = "pot",
67 .offset = 0x7b0000,
68 .size = 0x010000,
69 .mask_flags = MTD_WRITEABLE,
70 } , {
71 .name = "traffic_meter",
72 .offset = 0x7c0000,
73 .size = 0x010000,
74 .mask_flags = MTD_WRITEABLE,
75 } , {
76 .name = "language",
77 .offset = 0x7d0000,
78 .size = 0x020000,
79 .mask_flags = MTD_WRITEABLE,
80 } , {
81 .name = "caldata",
82 .offset = 0x7f0000,
83 .size = 0x010000,
84 .mask_flags = MTD_WRITEABLE,
85 }
86 };
87 #endif /* CONFIG_MTD_PARTITIONS */
88
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),
93 #endif
94 };
95
96 #ifdef CONFIG_PCI
97 static struct ar71xx_pci_irq wndr3700_pci_irqs[] __initdata = {
98 {
99 .slot = 0,
100 .pin = 1,
101 .irq = AR71XX_PCI_IRQ_DEV0,
102 }, {
103 .slot = 1,
104 .pin = 1,
105 .irq = AR71XX_PCI_IRQ_DEV1,
106 }
107 };
108
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];
113
114 static void wndr3700_pci_fixup(struct pci_dev *dev)
115 {
116 void __iomem *mem;
117 u16 *cal_data;
118 u16 cmd;
119 u32 bar0;
120 u32 val;
121
122 if (ar71xx_mach != AR71XX_MACH_WNDR3700)
123 return;
124
125 switch (PCI_SLOT(dev->devfn)) {
126 case 17:
127 cal_data = wndr3700_wmac0_data.eeprom_data;
128 break;
129 case 18:
130 cal_data = wndr3700_wmac1_data.eeprom_data;
131 break;
132 default:
133 return;
134 }
135
136 if (*cal_data != 0xa55a) {
137 printk(KERN_ERR "PCI: no calibration data found for %s\n",
138 pci_name(dev));
139 return;
140 }
141
142 mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
143 if (!mem) {
144 printk(KERN_ERR "PCI: ioremap error for device %s\n",
145 pci_name(dev));
146 return;
147 }
148
149 printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
150
151 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
152
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);
158
159 /* set pointer to first reg address */
160 cal_data += 3;
161 while (*cal_data != 0xffff) {
162 u32 reg;
163 reg = *cal_data++;
164 val = *cal_data++;
165 val |= (*cal_data++) << 16;
166
167 __raw_writel(val, mem + reg);
168 udelay(100);
169 }
170
171 pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
172 dev->vendor = val & 0xffff;
173 dev->device = (val >> 16) & 0xffff;
174
175 pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
176 dev->revision = val & 0xff;
177 dev->class = val >> 8; /* upper 3 bytes */
178
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);
182
183 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
184
185 iounmap(mem);
186 }
187 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID,
188 wndr3700_pci_fixup);
189
190 static int wndr3700_pci_plat_dev_init(struct pci_dev *dev)
191 {
192 switch (PCI_SLOT(dev->devfn)) {
193 case 17:
194 dev->dev.platform_data = &wndr3700_wmac0_data;
195 break;
196 case 18:
197 dev->dev.platform_data = &wndr3700_wmac1_data;
198 break;
199 }
200
201 return 0;
202 }
203
204 static void __init wndr3700_pci_init(void)
205 {
206 u8 *ee = (u8 *) KSEG1ADDR(0x1fff0000);
207
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;
212
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;
217
218 ar71xx_pci_plat_dev_init = wndr3700_pci_plat_dev_init;
219 ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs), wndr3700_pci_irqs);
220 }
221 #else
222 static inline void wndr3700_pci_init(void) { };
223 #endif /* CONFIG_PCI */
224
225 static struct spi_board_info wndr3700_spi_info[] = {
226 {
227 .bus_num = 0,
228 .chip_select = 0,
229 .max_speed_hz = 25000000,
230 .modalias = "m25p80",
231 .platform_data = &wndr3700_flash_data,
232 }
233 };
234
235 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
236 {
237 .name = "wndr3700:green:power",
238 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
239 .active_low = 1,
240 }, {
241 .name = "wndr3700:orange:power",
242 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
243 .active_low = 1,
244 }, {
245 .name = "wndr3700:green:wps",
246 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
247 .active_low = 1,
248 }, {
249 .name = "wndr3700:orange:wps",
250 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
251 .active_low = 1,
252 }
253 };
254
255 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
256 {
257 .desc = "reset",
258 .type = EV_KEY,
259 .code = BTN_0,
260 .threshold = 5,
261 .gpio = WNDR3700_GPIO_BTN_RESET,
262 }, {
263 .desc = "wps",
264 .type = EV_KEY,
265 .code = BTN_1,
266 .threshold = 5,
267 .gpio = WNDR3700_GPIO_BTN_WPS,
268 } , {
269 .desc = "wifi",
270 .type = EV_KEY,
271 .code = BTN_2,
272 .threshold = 5,
273 .gpio = WNDR3700_GPIO_BTN_WIFI,
274 }
275 };
276
277 static void __init wndr3700_setup(void)
278 {
279 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
280
281 ar71xx_set_mac_base(mac);
282 ar71xx_add_device_mdio(0x0);
283
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;
289
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;
293
294 ar71xx_add_device_eth(0);
295 ar71xx_add_device_eth(1);
296
297 ar71xx_add_device_usb();
298
299 ar71xx_add_device_spi(NULL, wndr3700_spi_info,
300 ARRAY_SIZE(wndr3700_spi_info));
301
302 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
303 wndr3700_leds_gpio);
304
305 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
306 ARRAY_SIZE(wndr3700_gpio_buttons),
307 wndr3700_gpio_buttons);
308
309 wndr3700_pci_init();
310 }
311
312 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);