2 * Copyright (C) 2006, 2007 Felix Fietkau, Eugene Konev
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <linux/autoconf.h>
20 #include <linux/init.h>
21 #include <linux/types.h>
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/platform_device.h>
26 #include <linux/mtd/physmap.h>
27 #include <linux/serial.h>
28 #include <linux/serial_8250.h>
29 #include <linux/ioport.h>
31 #include <linux/version.h>
32 #include <linux/vlynq.h>
33 #include <linux/leds.h>
34 #include <linux/string.h>
36 #include <asm/addrspace.h>
37 #include <asm/ar7/ar7.h>
38 #include <asm/ar7/gpio.h>
39 #include <asm/ar7/prom.h>
41 struct plat_vlynq_data
{
42 struct plat_vlynq_ops ops
;
48 static int vlynq_on(struct vlynq_device
*dev
)
51 struct plat_vlynq_data
*pdata
= dev
->dev
.platform_data
;
53 if ((result
= gpio_request(pdata
->gpio_bit
, "vlynq")))
56 ar7_device_reset(pdata
->reset_bit
);
58 if ((result
= ar7_gpio_disable(pdata
->gpio_bit
)))
61 if ((result
= ar7_gpio_enable(pdata
->gpio_bit
)))
64 if ((result
= gpio_direction_output(pdata
->gpio_bit
, 0)))
65 goto out_gpio_enabled
;
69 gpio_set_value(pdata
->gpio_bit
, 1);
75 ar7_gpio_disable(pdata
->gpio_bit
);
77 ar7_device_disable(pdata
->reset_bit
);
78 gpio_free(pdata
->gpio_bit
);
83 static void vlynq_off(struct vlynq_device
*dev
)
85 struct plat_vlynq_data
*pdata
= dev
->dev
.platform_data
;
86 ar7_gpio_disable(pdata
->gpio_bit
);
87 gpio_free(pdata
->gpio_bit
);
88 ar7_device_disable(pdata
->reset_bit
);
91 static struct resource physmap_flash_resource
= {
93 .flags
= IORESOURCE_MEM
,
98 static struct resource cpmac_low_res
[] = {
101 .flags
= IORESOURCE_MEM
,
102 .start
= AR7_REGS_MAC0
,
103 .end
= AR7_REGS_MAC0
+ 0x7ff,
107 .flags
= IORESOURCE_IRQ
,
113 static struct resource cpmac_high_res
[] = {
116 .flags
= IORESOURCE_MEM
,
117 .start
= AR7_REGS_MAC1
,
118 .end
= AR7_REGS_MAC1
+ 0x7ff,
122 .flags
= IORESOURCE_IRQ
,
128 static struct resource vlynq_low_res
[] = {
131 .flags
= IORESOURCE_MEM
,
132 .start
= AR7_REGS_VLYNQ0
,
133 .end
= AR7_REGS_VLYNQ0
+ 0xff,
137 .flags
= IORESOURCE_IRQ
,
143 .flags
= IORESOURCE_MEM
,
149 .flags
= IORESOURCE_IRQ
,
155 static struct resource vlynq_high_res
[] = {
158 .flags
= IORESOURCE_MEM
,
159 .start
= AR7_REGS_VLYNQ1
,
160 .end
= AR7_REGS_VLYNQ1
+ 0xff,
164 .flags
= IORESOURCE_IRQ
,
170 .flags
= IORESOURCE_MEM
,
176 .flags
= IORESOURCE_IRQ
,
182 static struct resource usb_res
[] = {
185 .flags
= IORESOURCE_MEM
,
186 .start
= AR7_REGS_USB
,
187 .end
= AR7_REGS_USB
+ 0xff,
191 .flags
= IORESOURCE_IRQ
,
197 .flags
= IORESOURCE_MEM
,
203 static struct physmap_flash_data physmap_flash_data
= {
207 static struct plat_cpmac_data cpmac_low_data
= {
210 .phy_mask
= 0x80000000,
213 static struct plat_cpmac_data cpmac_high_data
= {
216 .phy_mask
= 0x7fffffff,
219 static struct plat_vlynq_data vlynq_low_data
= {
221 .ops
.off
= vlynq_off
,
226 static struct plat_vlynq_data vlynq_high_data
= {
228 .ops
.off
= vlynq_off
,
233 static struct platform_device physmap_flash
= {
235 .name
= "physmap-flash",
236 .dev
.platform_data
= &physmap_flash_data
,
237 .resource
= &physmap_flash_resource
,
241 static u64 cpmac_dma_mask
= DMA_32BIT_MASK
;
242 static struct platform_device cpmac_low
= {
246 .dma_mask
= &cpmac_dma_mask
,
247 .coherent_dma_mask
= DMA_32BIT_MASK
,
248 .platform_data
= &cpmac_low_data
,
250 .resource
= cpmac_low_res
,
251 .num_resources
= ARRAY_SIZE(cpmac_low_res
),
254 static struct platform_device cpmac_high
= {
258 .dma_mask
= &cpmac_dma_mask
,
259 .coherent_dma_mask
= DMA_32BIT_MASK
,
260 .platform_data
= &cpmac_high_data
,
262 .resource
= cpmac_high_res
,
263 .num_resources
= ARRAY_SIZE(cpmac_high_res
),
266 static struct platform_device vlynq_low
= {
269 .dev
.platform_data
= &vlynq_low_data
,
270 .resource
= vlynq_low_res
,
271 .num_resources
= ARRAY_SIZE(vlynq_low_res
),
274 static struct platform_device vlynq_high
= {
277 .dev
.platform_data
= &vlynq_high_data
,
278 .resource
= vlynq_high_res
,
279 .num_resources
= ARRAY_SIZE(vlynq_high_res
),
283 /* This is proper way to define uart ports, but they are then detected
284 * as xscale and, obviously, don't work...
286 #if !defined(CONFIG_SERIAL_8250)
288 static struct plat_serial8250_port uart0_data
= {
289 .mapbase
= AR7_REGS_UART0
,
290 .irq
= AR7_IRQ_UART0
,
293 .flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
,
296 static struct plat_serial8250_port uart1_data
= {
297 .mapbase
= UR8_REGS_UART1
,
298 .irq
= AR7_IRQ_UART1
,
301 .flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
,
304 static struct plat_serial8250_port uart_data
[] = {
310 static struct plat_serial8250_port uart_data_single
[] = {
315 static struct platform_device uart
= {
317 .name
= "serial8250",
318 .dev
.platform_data
= uart_data_single
322 static struct gpio_led default_leds
[] = {
323 { .name
= "status", .gpio
= 8, .active_low
= 1, },
326 static struct gpio_led dsl502t_leds
[] = {
327 { .name
= "status", .gpio
= 9, .active_low
= 1, },
328 { .name
= "ethernet", .gpio
= 7, .active_low
= 1, },
329 { .name
= "usb", .gpio
= 12, .active_low
= 1, },
332 static struct gpio_led dg834g_leds
[] = {
333 { .name
= "ppp", .gpio
= 6, .active_low
= 1, },
334 { .name
= "status", .gpio
= 7, .active_low
= 1, },
335 { .name
= "adsl", .gpio
= 8, .active_low
= 1, },
336 { .name
= "wifi", .gpio
= 12, .active_low
= 1, },
337 { .name
= "power", .gpio
= 14, .active_low
= 1, .default_trigger
= "default-on", },
340 static struct gpio_led fb_sl_leds
[] = {
341 { .name
= "1", .gpio
= 7, },
342 { .name
= "2", .gpio
= 13, .active_low
= 1, },
343 { .name
= "3", .gpio
= 10, .active_low
= 1, },
344 { .name
= "4", .gpio
= 12, .active_low
= 1, },
345 { .name
= "5", .gpio
= 9, .active_low
= 1, },
348 static struct gpio_led fb_fon_leds
[] = {
349 { .name
= "1", .gpio
= 8, },
350 { .name
= "2", .gpio
= 3, .active_low
= 1, },
351 { .name
= "3", .gpio
= 5, },
352 { .name
= "4", .gpio
= 4, .active_low
= 1, },
353 { .name
= "5", .gpio
= 11, .active_low
= 1, },
356 static struct gpio_led_platform_data ar7_led_data
;
358 static struct platform_device ar7_gpio_leds
= {
362 .platform_data
= &ar7_led_data
,
366 static struct platform_device ar7_udc
= {
370 .num_resources
= ARRAY_SIZE(usb_res
),
373 static inline unsigned char char2hex(char h
)
376 case '0': case '1': case '2': case '3': case '4':
377 case '5': case '6': case '7': case '8': case '9':
379 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
381 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
388 static void cpmac_get_mac(int instance
, unsigned char *dev_addr
)
391 char name
[5], default_mac
[] = "00:00:00:12:34:56", *mac
;
394 sprintf(name
, "mac%c", 'a' + instance
);
395 mac
= prom_getenv(name
);
397 sprintf(name
, "mac%c", 'a');
398 mac
= prom_getenv(name
);
402 for (i
= 0; i
< 6; i
++)
403 dev_addr
[i
] = (char2hex(mac
[i
* 3]) << 4) +
404 char2hex(mac
[i
* 3 + 1]);
407 static void __init
detect_leds(void)
409 char *prId
, *usb_prod
;
412 ar7_led_data
.num_leds
= ARRAY_SIZE(default_leds
);
413 ar7_led_data
.leds
= default_leds
;
415 /* FIXME: the whole thing is unreliable */
416 prId
= prom_getenv("ProductID");
417 usb_prod
= prom_getenv("usb_prod");
419 /* If we can't get the product id from PROM, use the default LEDs */
423 if (strstr(prId
, "Fritz_Box_FON")) {
424 ar7_led_data
.num_leds
= ARRAY_SIZE(fb_fon_leds
);
425 ar7_led_data
.leds
= fb_fon_leds
;
426 } else if (strstr(prId
, "Fritz_Box_")) {
427 ar7_led_data
.num_leds
= ARRAY_SIZE(fb_sl_leds
);
428 ar7_led_data
.leds
= fb_sl_leds
;
429 } else if ((!strcmp(prId
, "AR7RD") || !strcmp(prId
, "AR7DB")) && usb_prod
!= NULL
&& strstr(usb_prod
, "DSL-502T")) {
430 ar7_led_data
.num_leds
= ARRAY_SIZE(dsl502t_leds
);
431 ar7_led_data
.leds
= dsl502t_leds
;
432 } else if (strstr(prId
, "DG834")) {
433 ar7_led_data
.num_leds
= ARRAY_SIZE(dg834g_leds
);
434 ar7_led_data
.leds
= dg834g_leds
;
438 static int __init
ar7_register_devices(void)
442 #ifdef CONFIG_SERIAL_8250
444 static struct uart_port uart_port
[2];
446 memset(uart_port
, 0, sizeof(struct uart_port
) * 2);
448 uart_port
[0].type
= PORT_AR7
;
449 uart_port
[0].line
= 0;
450 uart_port
[0].irq
= AR7_IRQ_UART0
;
451 uart_port
[0].uartclk
= ar7_bus_freq() / 2;
452 uart_port
[0].iotype
= UPIO_MEM
;
453 uart_port
[0].mapbase
= AR7_REGS_UART0
;
454 uart_port
[0].membase
= ioremap(uart_port
[0].mapbase
, 256);
455 uart_port
[0].regshift
= 2;
456 res
= early_serial_setup(&uart_port
[0]);
461 /* Only TNETD73xx have a second serial port */
462 if (ar7_has_second_uart()) {
463 uart_port
[1].type
= PORT_AR7
;
464 uart_port
[1].line
= 1;
465 uart_port
[1].irq
= AR7_IRQ_UART1
;
466 uart_port
[1].uartclk
= ar7_bus_freq() / 2;
467 uart_port
[1].iotype
= UPIO_MEM
;
468 uart_port
[1].mapbase
= UR8_REGS_UART1
;
469 uart_port
[1].membase
= ioremap(uart_port
[1].mapbase
, 256);
470 uart_port
[1].regshift
= 2;
471 res
= early_serial_setup(&uart_port
[1]);
476 #else /* !CONFIG_SERIAL_8250 */
478 uart_data
[0].uartclk
= ar7_bus_freq() / 2;
479 uart_data
[1].uartclk
= uart_data
[0].uartclk
;
481 /* Only TNETD73xx have a second serial port */
482 if (ar7_has_second_uart())
483 uart
.dev
.platform_data
= uart_data
;
485 res
= platform_device_register(&uart
);
489 #endif /* CONFIG_SERIAL_8250 */
491 res
= platform_device_register(&physmap_flash
);
495 res
= platform_device_register(&vlynq_low
);
499 ar7_device_disable(vlynq_low_data
.reset_bit
);
500 if (ar7_has_high_vlynq()) {
501 ar7_device_disable(vlynq_high_data
.reset_bit
);
502 res
= platform_device_register(&vlynq_high
);
507 if (ar7_has_high_cpmac()) {
508 cpmac_get_mac(1, cpmac_high_data
.dev_addr
);
509 res
= platform_device_register(&cpmac_high
);
513 cpmac_low_data
.phy_mask
= 0xffffffff;
516 cpmac_get_mac(0, cpmac_low_data
.dev_addr
);
517 res
= platform_device_register(&cpmac_low
);
522 res
= platform_device_register(&ar7_gpio_leds
);
526 res
= platform_device_register(&ar7_udc
);
532 arch_initcall(ar7_register_devices
);