* update patches to 3.0
[openwrt/openwrt.git] / target / linux / lantiq / files-3.0 / arch / mips / lantiq / xway / mach-arv45xx.c
1 /*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
5 *
6 * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
7 */
8
9 #include <linux/init.h>
10 #include <linux/platform_device.h>
11 #include <linux/leds.h>
12 #include <linux/gpio.h>
13 #include <linux/gpio_buttons.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/input.h>
18 #include <linux/etherdevice.h>
19 #include <linux/ath5k_platform.h>
20 #include <linux/pci.h>
21
22 #include <lantiq_soc.h>
23 #include <lantiq_platform.h>
24
25 #include "../machtypes.h"
26 #include "../dev-leds-gpio.h"
27 #include "devices.h"
28 #include "dev-dwc_otg.h"
29
30 static struct mtd_partition arv4510_partitions[] =
31 {
32 {
33 .name = "uboot",
34 .offset = 0x0,
35 .size = 0x20000,
36 },
37 {
38 .name = "uboot_env",
39 .offset = 0x20000,
40 .size = 0x120000,
41 },
42 {
43 .name = "linux",
44 .offset = 0x40000,
45 .size = 0xfa0000,
46 },
47 {
48 .name = "board_config",
49 .offset = 0xfe0000,
50 .size = 0x20000,
51 },
52 };
53
54 static struct mtd_partition arv45xx_partitions[] =
55 {
56 {
57 .name = "uboot",
58 .offset = 0x0,
59 .size = 0x20000,
60 },
61 {
62 .name = "uboot_env",
63 .offset = 0x20000,
64 .size = 0x10000,
65 },
66 {
67 .name = "linux",
68 .offset = 0x30000,
69 .size = 0x3c0000,
70 },
71 {
72 .name = "board_config",
73 .offset = 0x3f0000,
74 .size = 0x10000,
75 },
76 };
77
78 static struct mtd_partition arv75xx_partitions[] =
79 {
80 {
81 .name = "uboot",
82 .offset = 0x0,
83 .size = 0x10000,
84 },
85 {
86 .name = "uboot_env",
87 .offset = 0x10000,
88 .size = 0x10000,
89 },
90 {
91 .name = "linux",
92 .offset = 0x20000,
93 .size = 0x7d0000,
94 },
95 {
96 .name = "board_config",
97 .offset = 0x7f0000,
98 .size = 0x10000,
99 },
100 };
101
102 static struct physmap_flash_data arv4510_flash_data = {
103 .nr_parts = ARRAY_SIZE(arv4510_partitions),
104 .parts = arv4510_partitions,
105 };
106
107 static struct physmap_flash_data arv45xx_flash_data = {
108 .nr_parts = ARRAY_SIZE(arv45xx_partitions),
109 .parts = arv45xx_partitions,
110 };
111
112 static struct physmap_flash_data arv75xx_flash_data = {
113 .nr_parts = ARRAY_SIZE(arv75xx_partitions),
114 .parts = arv75xx_partitions,
115 };
116
117 static struct ltq_pci_data ltq_pci_data = {
118 .clock = PCI_CLOCK_EXT,
119 .gpio = PCI_GNT1 | PCI_REQ1,
120 .irq = {
121 [14] = INT_NUM_IM0_IRL0 + 22,
122 },
123 };
124
125 static struct ltq_eth_data ltq_eth_data = {
126 .mii_mode = PHY_INTERFACE_MODE_RMII,
127 };
128
129 static struct gpio_led
130 arv4510pw_leds_gpio[] __initdata = {
131 { .name = "soc:green:foo", .gpio = 4, .active_low = 1, },
132 };
133
134 static struct gpio_led
135 arv4518pw_leds_gpio[] __initdata = {
136 { .name = "soc:green:power", .gpio = 3, .active_low = 1, .default_trigger = "default-on" },
137 { .name = "soc:green:adsl", .gpio = 4, .active_low = 1, .default_trigger = "default-on" },
138 { .name = "soc:green:internet", .gpio = 5, .active_low = 1, .default_trigger = "default-on" },
139 { .name = "soc:green:wlan", .gpio = 6, .active_low = 1, .default_trigger = "default-on" },
140 { .name = "soc:yellow:wps", .gpio = 7, .active_low = 1, .default_trigger = "default-on" },
141 { .name = "soc:red:fail", .gpio = 8, .active_low = 1, .default_trigger = "default-on" },
142 { .name = "soc:green:usb", .gpio = 19, .active_low = 1, .default_trigger = "default-on" },
143 { .name = "soc:green:voip", .gpio = 100, .active_low = 1, .default_trigger = "default-on" },
144 { .name = "soc:green:fxs1", .gpio = 101, .active_low = 1, .default_trigger = "default-on" },
145 { .name = "soc:green:fxs2", .gpio = 102, .active_low = 1, .default_trigger = "default-on" },
146 { .name = "soc:green:fxo", .gpio = 103, .active_low = 1, .default_trigger = "default-on" },
147 };
148
149 static struct gpio_button
150 arv4518pw_gpio_buttons[] __initdata = {
151 { .desc = "wlan", .type = EV_KEY, .code = BTN_0, .threshold = 3, .gpio = 28, .active_low = 1, },
152 { .desc = "wps", .type = EV_KEY, .code = BTN_1, .threshold = 3, .gpio = 29, .active_low = 1, },
153 { .desc = "reset", .type = EV_KEY, .code = BTN_2, .threshold = 3, .gpio = 30, .active_low = 1, },
154 };
155
156 static struct gpio_led
157 arv4520pw_leds_gpio[] __initdata = {
158 { .name = "soc:blue:power", .gpio = 3, .active_low = 1, },
159 { .name = "soc:blue:adsl", .gpio = 4, .active_low = 1, },
160 { .name = "soc:blue:internet", .gpio = 5, .active_low = 1, },
161 { .name = "soc:red:power", .gpio = 6, .active_low = 1, },
162 { .name = "soc:yellow:wps", .gpio = 7, .active_low = 1, },
163 { .name = "soc:red:wps", .gpio = 9, .active_low = 1, },
164 { .name = "soc:blue:voip", .gpio = 100, .active_low = 1, },
165 { .name = "soc:blue:fxs1", .gpio = 101, .active_low = 1, },
166 { .name = "soc:blue:fxs2", .gpio = 102, .active_low = 1, },
167 { .name = "soc:blue:fxo", .gpio = 103, .active_low = 1, },
168 { .name = "soc:blue:voice", .gpio = 104, .active_low = 1, },
169 { .name = "soc:blue:usb", .gpio = 105, .active_low = 1, },
170 { .name = "soc:blue:wlan", .gpio = 106, .active_low = 1, },
171 };
172
173 static struct gpio_led
174 arv452cpw_leds_gpio[] __initdata = {
175 { .name = "soc:blue:power", .gpio = 3, .active_low = 1, .default_trigger = "default-on" },
176 { .name = "soc:blue:adsl", .gpio = 4, .active_low = 1, .default_trigger = "default-on" },
177 { .name = "soc:blue:isdn", .gpio = 5, .active_low = 1, .default_trigger = "default-on" },
178 { .name = "soc:red:power", .gpio = 6, .active_low = 1, .default_trigger = "default-on" },
179 { .name = "soc:yellow:wps", .gpio = 7, .active_low = 1, .default_trigger = "default-on" },
180 { .name = "soc:red:wps", .gpio = 9, .active_low = 1, .default_trigger = "default-on" },
181 { .name = "soc:blue:fxs1", .gpio = 100, .active_low = 1, .default_trigger = "default-on" },
182 { .name = "soc:blue:fxs2", .gpio = 101, .active_low = 1, .default_trigger = "default-on" },
183 { .name = "soc:blue:wps", .gpio = 102, .active_low = 1, .default_trigger = "default-on" },
184 { .name = "soc:blue:fxo", .gpio = 103, .active_low = 1, .default_trigger = "default-on" },
185 { .name = "soc:blue:voice", .gpio = 104, .active_low = 1, .default_trigger = "default-on" },
186 { .name = "soc:blue:usb", .gpio = 105, .active_low = 1, .default_trigger = "default-on" },
187 { .name = "soc:blue:wlan", .gpio = 106, .active_low = 1, .default_trigger = "default-on" },
188 { .name = "soc:blue:internet", .gpio = 108, .active_low = 1, .default_trigger = "default-on" },
189 { .name = "soc:red:internet", .gpio = 109, .active_low = 1, .default_trigger = "default-on" },
190 };
191
192 static struct gpio_led
193 arv4525pw_leds_gpio[] __initdata = {
194 { .name = "soc:green:festnetz", .gpio = 4, .active_low = 1, .default_trigger = "default-on" },
195 { .name = "soc:green:internet", .gpio = 5, .active_low = 1, .default_trigger = "default-on" },
196 { .name = "soc:green:dsl", .gpio = 6, .active_low = 1, .default_trigger = "default-on" },
197 { .name = "soc:green:wlan", .gpio = 8, .active_low = 1, .default_trigger = "default-on" },
198 { .name = "soc:green:online", .gpio = 9, .active_low = 1, .default_trigger = "default-on" },
199 };
200
201 static struct gpio_led
202 arv752dpw22_leds_gpio[] __initdata = {
203 { .name = "soc:blue:power", .gpio = 3, .active_low = 1, .default_trigger = "default-on" },
204 { .name = "soc:red:internet", .gpio = 5, .active_low = 1, .default_trigger = "default-on" },
205 { .name = "soc:red:power", .gpio = 6, .active_low = 1, .default_trigger = "default-on" },
206 { .name = "soc:red:wps", .gpio = 8, .active_low = 1, .default_trigger = "default-on" },
207 { .name = "soc:red:fxo", .gpio = 103, .active_low = 1, .default_trigger = "default-on" },
208 { .name = "soc:red:voice", .gpio = 104, .active_low = 1, .default_trigger = "default-on" },
209 { .name = "soc:green:usb", .gpio = 105, .active_low = 1, .default_trigger = "default-on" },
210 { .name = "soc:green:wlan", .gpio = 106, .active_low = 1, .default_trigger = "default-on" },
211 { .name = "soc:green:wlan1", .gpio = 107, .active_low = 1, .default_trigger = "default-on" },
212 { .name = "soc:blue:wlan", .gpio = 108, .active_low = 1, .default_trigger = "default-on" },
213 { .name = "soc:blue:wlan1", .gpio = 109, .active_low = 1, .default_trigger = "default-on" },
214 { .name = "soc:green:eth1", .gpio = 111, .active_low = 1, .default_trigger = "default-on" },
215 { .name = "soc:green:eth2", .gpio = 112, .active_low = 1, .default_trigger = "default-on" },
216 { .name = "soc:green:eth3", .gpio = 113, .active_low = 1, .default_trigger = "default-on" },
217 { .name = "soc:green:eth4", .gpio = 114, .active_low = 1, .default_trigger = "default-on", },
218 };
219
220 static struct gpio_button
221 arv752dpw22_gpio_buttons[] __initdata = {
222 { .desc = "btn0", .type = EV_KEY, .code = BTN_0, .threshold = 3, .gpio = 12, .active_low = 1, },
223 { .desc = "btn1", .type = EV_KEY, .code = BTN_1, .threshold = 3, .gpio = 13, .active_low = 1, },
224 { .desc = "btn2", .type = EV_KEY, .code = BTN_2, .threshold = 3, .gpio = 28, .active_low = 1, },
225 };
226
227 static struct gpio_led
228 arv7518pw_leds_gpio[] __initdata = {
229 { .name = "soc:green:power", .gpio = 2, .active_low = 1, },
230 { .name = "soc:green:adsl", .gpio = 4, .active_low = 1, },
231 { .name = "soc:green:internet", .gpio = 5, .active_low = 1, },
232 { .name = "soc:green:wlan", .gpio = 6, .active_low = 1, },
233 { .name = "soc:red:internet", .gpio = 8, .active_low = 1, },
234 { .name = "soc:green:usb", .gpio = 19, .active_low = 1, },
235 };
236
237 static struct gpio_button
238 arv7518pw_gpio_buttons[] __initdata = {
239 { .desc = "reset", .type = EV_KEY, .code = BTN_0, .threshold = 3, .gpio = 23, .active_low = 1, },
240 { .desc = "wlan", .type = EV_KEY, .code = BTN_1, .threshold = 3, .gpio = 25, .active_low = 1, },
241 };
242
243 static void
244 arv45xx_register_ethernet(void)
245 {
246 #define ARV45XX_BRN_MAC 0x3f0016
247 memcpy_fromio(&ltq_eth_data.mac.sa_data,
248 (void *)KSEG1ADDR(LTQ_FLASH_START + ARV45XX_BRN_MAC), 6);
249 ltq_register_etop(&ltq_eth_data);
250 }
251
252 static void
253 arv75xx_register_ethernet(void)
254 {
255 #define ARV75XX_BRN_MAC 0x7f0016
256 memcpy_fromio(&ltq_eth_data.mac.sa_data,
257 (void *)KSEG1ADDR(LTQ_FLASH_START + ARV75XX_BRN_MAC), 6);
258 ltq_register_etop(&ltq_eth_data);
259 }
260
261 static void
262 bewan_register_ethernet(void)
263 {
264 #define BEWAN_BRN_MAC 0x3f0014
265 memcpy_fromio(&ltq_eth_data.mac.sa_data,
266 (void *)KSEG1ADDR(LTQ_FLASH_START + BEWAN_BRN_MAC), 6);
267 ltq_register_etop(&ltq_eth_data);
268 }
269
270 static u16 arv45xx_ath5k_eeprom_data[ATH5K_PLAT_EEP_MAX_WORDS];
271 static struct ath5k_platform_data arv45xx_ath5k_platform_data;
272
273 /*static int arv45xx_pci_plat_dev_init(struct pci_dev *dev)
274 {
275 dev->dev.platform_data = &arv45xx_ath5k_platform_data;
276 return 0;
277 }
278 */
279 void __init
280 arv45xx_register_ath5k(void)
281 {
282 #define ARV45XX_BRN_ATH 0x3f0478
283 int i;
284 unsigned char eeprom_mac[6];
285 static u16 eeprom_data[ATH5K_PLAT_EEP_MAX_WORDS];
286 u32 *p = (u32*)arv45xx_ath5k_eeprom_data;
287
288 memcpy_fromio(eeprom_mac,
289 (void *)KSEG1ADDR(LTQ_FLASH_START + ARV45XX_BRN_MAC), 6);
290 eeprom_mac[5]++;
291 memcpy_fromio(arv45xx_ath5k_eeprom_data,
292 (void *)KSEG1ADDR(LTQ_FLASH_START + ARV45XX_BRN_ATH), ATH5K_PLAT_EEP_MAX_WORDS);
293 // swap eeprom bytes
294 for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS>>1; i++){
295 //arv4518_ath5k_eeprom_data[i] = ((eeprom_data[i]&0xff)<<8)|((eeprom_data[i]&0xff00)>>8);
296 p[i] = ((eeprom_data[(i<<1)+1]&0xff)<<24)|((eeprom_data[(i<<1)+1]&0xff00)<<8)|((eeprom_data[i<<1]&0xff)<<8)|((eeprom_data[i<<1]&0xff00)>>8);
297 if (i == 0xbf>>1){
298 // printk ("regdomain: 0x%x --> 0x%x\n", p[i], (p[i] & 0xffff0000)|0x67);
299 /* regdomain is invalid?? how did original fw convert
300 * value to 0x82d4 ??
301 * for now, force to 0x67 */
302 p[i] &= 0xffff0000;
303 p[i] |= 0x67;
304 }
305 }
306 arv45xx_ath5k_platform_data.eeprom_data = arv45xx_ath5k_eeprom_data;
307 arv45xx_ath5k_platform_data.macaddr = eeprom_mac;
308 //lqpci_plat_dev_init = arv45xx_pci_plat_dev_init;
309 }
310
311 static void __init
312 arv3527p_init(void)
313 {
314 ltq_register_gpio_stp();
315 //ltq_add_device_leds_gpio(arv3527p_leds_gpio, ARRAY_SIZE(arv3527p_leds_gpio));
316 ltq_register_nor(&arv45xx_flash_data);
317 arv45xx_register_ethernet();
318 }
319
320 MIPS_MACHINE(LANTIQ_MACH_ARV3527P,
321 "ARV3527P",
322 "ARV3527P - Arcor Easybox 401",
323 arv3527p_init);
324
325 static void __init
326 arv4510pw_init(void)
327 {
328 ltq_register_gpio_stp();
329 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv4510pw_leds_gpio), arv4510pw_leds_gpio);
330 ltq_register_nor(&arv4510_flash_data);
331 ltq_pci_data.irq[12] = (INT_NUM_IM2_IRL0 + 31);
332 ltq_pci_data.irq[15] = (INT_NUM_IM0_IRL0 + 26);
333 ltq_pci_data.gpio |= PCI_EXIN2 | PCI_REQ2;
334 ltq_register_pci(&ltq_pci_data);
335 bewan_register_ethernet();
336 }
337
338 MIPS_MACHINE(LANTIQ_MACH_ARV4510PW,
339 "ARV4510PW",
340 "ARV4510PW - Wippies Homebox",
341 arv4510pw_init);
342
343 static void __init
344 arv4518pw_init(void)
345 {
346 #define ARV4518PW_EBU 0
347 #define ARV4518PW_USB 14
348 #define ARV4518PW_SWITCH_RESET 13
349
350 ltq_register_gpio_ebu(ARV4518PW_EBU);
351 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv4518pw_leds_gpio), arv4518pw_leds_gpio);
352 ltq_register_gpio_buttons(arv4518pw_gpio_buttons, ARRAY_SIZE(arv4518pw_gpio_buttons));
353 ltq_register_nor(&arv45xx_flash_data);
354 ltq_pci_data.gpio = PCI_GNT2 | PCI_REQ2;
355 ltq_register_pci(&ltq_pci_data);
356 ltq_register_madwifi_eep();
357 xway_register_dwc(ARV4518PW_USB);
358 arv45xx_register_ethernet();
359 arv45xx_register_ath5k();
360
361 gpio_request(ARV4518PW_SWITCH_RESET, "switch");
362 gpio_direction_output(ARV4518PW_SWITCH_RESET, 1);
363 gpio_export(ARV4518PW_SWITCH_RESET, 0);
364 }
365
366 MIPS_MACHINE(LANTIQ_MACH_ARV4518PW,
367 "ARV4518PW",
368 "ARV4518PW - SMC7908A-ISP, Airties WAV-221",
369 arv4518pw_init);
370
371 static void __init
372 arv4520pw_init(void)
373 {
374 #define ARV4520PW_EBU 0x400
375 #define ARV4520PW_USB 28
376 #define ARV4520PW_SWITCH_RESET 110
377
378 ltq_register_gpio_ebu(ARV4520PW_EBU);
379 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv4520pw_leds_gpio), arv4520pw_leds_gpio);
380 ltq_register_nor(&arv45xx_flash_data);
381 ltq_register_pci(&ltq_pci_data);
382 ltq_register_tapi();
383 arv45xx_register_ethernet();
384 xway_register_dwc(ARV4520PW_USB);
385
386 gpio_request(ARV4520PW_SWITCH_RESET, "switch");
387 gpio_set_value(ARV4520PW_SWITCH_RESET, 1);
388 }
389
390 MIPS_MACHINE(LANTIQ_MACH_ARV4520PW,
391 "ARV4520PW",
392 "ARV4520PW - Airties WAV-281, Arcor A800",
393 arv4520pw_init);
394
395 static void __init
396 arv452Cpw_init(void)
397 {
398 #define ARV452CPW_EBU 0x77f
399 #define ARV452CPW_USB 28
400 #define ARV452CPW_RELAY1 31
401 #define ARV452CPW_RELAY2 107
402 #define ARV452CPW_SWITCH_RESET 110
403
404 ltq_register_gpio_ebu(ARV452CPW_EBU);
405 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv452cpw_leds_gpio), arv452cpw_leds_gpio);
406 ltq_register_nor(&arv45xx_flash_data);
407 ltq_register_pci(&ltq_pci_data);
408 ltq_register_madwifi_eep();
409 xway_register_dwc(ARV452CPW_USB);
410 arv45xx_register_ethernet();
411 arv45xx_register_ath5k();
412
413 gpio_request(ARV452CPW_SWITCH_RESET, "switch");
414 gpio_set_value(ARV452CPW_SWITCH_RESET, 1);
415 gpio_export(ARV452CPW_SWITCH_RESET, 0);
416
417 gpio_request(ARV452CPW_RELAY1, "relay1");
418 gpio_direction_output(ARV452CPW_RELAY1, 1);
419 gpio_export(ARV452CPW_RELAY1, 0);
420
421 gpio_request(ARV452CPW_RELAY2, "relay2");
422 gpio_set_value(ARV452CPW_RELAY2, 1);
423 gpio_export(ARV452CPW_RELAY2, 0);
424 }
425
426 MIPS_MACHINE(LANTIQ_MACH_ARV452CPW,
427 "ARV452CPW",
428 "ARV452CPW - Arcor A801",
429 arv452Cpw_init);
430
431 static void __init
432 arv4525pw_init(void)
433 {
434 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv4525pw_leds_gpio), arv4525pw_leds_gpio);
435 ltq_register_nor(&arv45xx_flash_data);
436 ltq_pci_data.clock = PCI_CLOCK_INT;
437 ltq_register_pci(&ltq_pci_data);
438 ltq_register_madwifi_eep();
439 ltq_eth_data.mii_mode = PHY_INTERFACE_MODE_MII;
440 arv45xx_register_ethernet();
441 }
442
443 MIPS_MACHINE(LANTIQ_MACH_ARV4525PW,
444 "ARV4525PW",
445 "ARV4525PW - Speedport W502V",
446 arv4525pw_init);
447
448 static void __init
449 arv7518pw_init(void)
450 {
451 #define ARV7518PW_EBU 0x2
452 #define ARV7518PW_USB 14
453
454 ltq_register_gpio_ebu(ARV7518PW_EBU);
455 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv7518pw_leds_gpio), arv7518pw_leds_gpio);
456 ltq_register_gpio_buttons(arv7518pw_gpio_buttons, ARRAY_SIZE(arv7518pw_gpio_buttons));
457 ltq_register_nor(&arv75xx_flash_data);
458 ltq_register_pci(&ltq_pci_data);
459 ltq_register_tapi();
460 xway_register_dwc(ARV7518PW_USB);
461 arv75xx_register_ethernet();
462 //arv7518_register_ath9k(mac);
463 }
464
465 MIPS_MACHINE(LANTIQ_MACH_ARV7518PW,
466 "ARV7518PW",
467 "ARV7518PW - ASTORIA",
468 arv7518pw_init);
469
470 static void __init
471 arv752dpw22_init(void)
472 {
473 #define ARV752DPW22_EBU 0x2
474 #define ARV752DPW22_USB 100
475 #define ARV752DPW22_RELAY 101
476
477 ltq_register_gpio_ebu(ARV752DPW22_EBU);
478 ltq_add_device_leds_gpio(-1, ARRAY_SIZE(arv752dpw22_leds_gpio), arv752dpw22_leds_gpio);
479 ltq_register_gpio_buttons(arv752dpw22_gpio_buttons, ARRAY_SIZE(arv752dpw22_gpio_buttons));
480 ltq_register_nor(&arv75xx_flash_data);
481 ltq_pci_data.irq[15] = (INT_NUM_IM3_IRL0 + 31);
482 ltq_pci_data.gpio |= PCI_EXIN1 | PCI_REQ2;
483 ltq_register_pci(&ltq_pci_data);
484 xway_register_dwc(ARV752DPW22_USB);
485 arv75xx_register_ethernet();
486
487 gpio_request(ARV752DPW22_RELAY, "relay");
488 gpio_set_value(ARV752DPW22_RELAY, 1);
489 gpio_export(ARV752DPW22_RELAY, 0);
490 }
491
492 MIPS_MACHINE(LANTIQ_MACH_ARV752DPW22,
493 "ARV752DPW22",
494 "ARV752DPW22 - Arcor A803",
495 arv752dpw22_init);