2 * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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/vlynq.h>
32 #include <linux/leds.h>
33 #include <linux/string.h>
34 #include <linux/etherdevice.h>
36 #include <asm/addrspace.h>
37 #include <asm/mach-ar7/ar7.h>
38 #include <asm/mach-ar7/gpio.h>
39 #include <asm/mach-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 result
= gpio_request(pdata
->gpio_bit
, "vlynq");
57 ar7_device_reset(pdata
->reset_bit
);
59 result
= ar7_gpio_disable(pdata
->gpio_bit
);
63 result
= ar7_gpio_enable(pdata
->gpio_bit
);
67 result
= gpio_direction_output(pdata
->gpio_bit
, 0);
69 goto out_gpio_enabled
;
73 gpio_set_value(pdata
->gpio_bit
, 1);
79 ar7_gpio_disable(pdata
->gpio_bit
);
81 ar7_device_disable(pdata
->reset_bit
);
82 gpio_free(pdata
->gpio_bit
);
87 static void vlynq_off(struct vlynq_device
*dev
)
89 struct plat_vlynq_data
*pdata
= dev
->dev
.platform_data
;
90 ar7_gpio_disable(pdata
->gpio_bit
);
91 gpio_free(pdata
->gpio_bit
);
92 ar7_device_disable(pdata
->reset_bit
);
95 static struct resource physmap_flash_resource
= {
97 .flags
= IORESOURCE_MEM
,
102 static struct resource cpmac_low_res
[] = {
105 .flags
= IORESOURCE_MEM
,
106 .start
= AR7_REGS_MAC0
,
107 .end
= AR7_REGS_MAC0
+ 0x7ff,
111 .flags
= IORESOURCE_IRQ
,
117 static struct resource cpmac_high_res
[] = {
120 .flags
= IORESOURCE_MEM
,
121 .start
= AR7_REGS_MAC1
,
122 .end
= AR7_REGS_MAC1
+ 0x7ff,
126 .flags
= IORESOURCE_IRQ
,
132 static struct resource vlynq_low_res
[] = {
135 .flags
= IORESOURCE_MEM
,
136 .start
= AR7_REGS_VLYNQ0
,
137 .end
= AR7_REGS_VLYNQ0
+ 0xff,
141 .flags
= IORESOURCE_IRQ
,
147 .flags
= IORESOURCE_MEM
,
153 .flags
= IORESOURCE_IRQ
,
159 static struct resource vlynq_high_res
[] = {
162 .flags
= IORESOURCE_MEM
,
163 .start
= AR7_REGS_VLYNQ1
,
164 .end
= AR7_REGS_VLYNQ1
+ 0xff,
168 .flags
= IORESOURCE_IRQ
,
174 .flags
= IORESOURCE_MEM
,
180 .flags
= IORESOURCE_IRQ
,
186 static struct resource usb_res
[] = {
189 .flags
= IORESOURCE_MEM
,
190 .start
= AR7_REGS_USB
,
191 .end
= AR7_REGS_USB
+ 0xff,
195 .flags
= IORESOURCE_IRQ
,
201 .flags
= IORESOURCE_MEM
,
207 static struct physmap_flash_data physmap_flash_data
= {
211 static struct plat_cpmac_data cpmac_low_data
= {
214 .phy_mask
= 0x80000000,
217 static struct plat_cpmac_data cpmac_high_data
= {
220 .phy_mask
= 0x7fffffff,
223 static struct plat_vlynq_data vlynq_low_data
= {
225 .ops
.off
= vlynq_off
,
230 static struct plat_vlynq_data vlynq_high_data
= {
232 .ops
.off
= vlynq_off
,
237 static struct platform_device physmap_flash
= {
239 .name
= "physmap-flash",
240 .dev
.platform_data
= &physmap_flash_data
,
241 .resource
= &physmap_flash_resource
,
245 static u64 cpmac_dma_mask
= DMA_BIT_MASK(32);
246 static struct platform_device cpmac_low
= {
250 .dma_mask
= &cpmac_dma_mask
,
251 .coherent_dma_mask
= DMA_BIT_MASK(32),
252 .platform_data
= &cpmac_low_data
,
254 .resource
= cpmac_low_res
,
255 .num_resources
= ARRAY_SIZE(cpmac_low_res
),
258 static struct platform_device cpmac_high
= {
262 .dma_mask
= &cpmac_dma_mask
,
263 .coherent_dma_mask
= DMA_BIT_MASK(32),
264 .platform_data
= &cpmac_high_data
,
266 .resource
= cpmac_high_res
,
267 .num_resources
= ARRAY_SIZE(cpmac_high_res
),
270 static struct platform_device vlynq_low
= {
273 .dev
.platform_data
= &vlynq_low_data
,
274 .resource
= vlynq_low_res
,
275 .num_resources
= ARRAY_SIZE(vlynq_low_res
),
278 static struct platform_device vlynq_high
= {
281 .dev
.platform_data
= &vlynq_high_data
,
282 .resource
= vlynq_high_res
,
283 .num_resources
= ARRAY_SIZE(vlynq_high_res
),
287 static struct gpio_led default_leds
[] = {
295 static struct gpio_led dsl502t_leds
[] = {
313 static struct gpio_led dg834g_leds
[] = {
338 .default_trigger
= "default-on",
342 static struct gpio_led fb_sl_leds
[] = {
369 static struct gpio_led fb_fon_leds
[] = {
395 static struct gpio_led_platform_data ar7_led_data
;
397 static struct platform_device ar7_gpio_leds
= {
401 .platform_data
= &ar7_led_data
,
405 static struct platform_device ar7_udc
= {
409 .num_resources
= ARRAY_SIZE(usb_res
),
412 static inline unsigned char char2hex(char h
)
415 case '0': case '1': case '2': case '3': case '4':
416 case '5': case '6': case '7': case '8': case '9':
418 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
420 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
427 static void cpmac_get_mac(int instance
, unsigned char *dev_addr
)
430 char name
[5], default_mac
[ETH_ALEN
], *mac
;
433 sprintf(name
, "mac%c", 'a' + instance
);
434 mac
= prom_getenv(name
);
436 sprintf(name
, "mac%c", 'a');
437 mac
= prom_getenv(name
);
440 random_ether_addr(default_mac
);
443 for (i
= 0; i
< 6; i
++)
444 dev_addr
[i
] = (char2hex(mac
[i
* 3]) << 4) +
445 char2hex(mac
[i
* 3 + 1]);
448 static void __init
detect_leds(void)
450 char *prid
, *usb_prod
;
453 ar7_led_data
.num_leds
= ARRAY_SIZE(default_leds
);
454 ar7_led_data
.leds
= default_leds
;
456 /* FIXME: the whole thing is unreliable */
457 prid
= prom_getenv("ProductID");
458 usb_prod
= prom_getenv("usb_prod");
460 /* If we can't get the product id from PROM, use the default LEDs */
464 if (strstr(prid
, "Fritz_Box_FON")) {
465 ar7_led_data
.num_leds
= ARRAY_SIZE(fb_fon_leds
);
466 ar7_led_data
.leds
= fb_fon_leds
;
467 } else if (strstr(prid
, "Fritz_Box_")) {
468 ar7_led_data
.num_leds
= ARRAY_SIZE(fb_sl_leds
);
469 ar7_led_data
.leds
= fb_sl_leds
;
470 } else if ((!strcmp(prid
, "AR7RD") || !strcmp(prid
, "AR7DB"))
471 && usb_prod
!= NULL
&& strstr(usb_prod
, "DSL-502T")) {
472 ar7_led_data
.num_leds
= ARRAY_SIZE(dsl502t_leds
);
473 ar7_led_data
.leds
= dsl502t_leds
;
474 } else if (strstr(prid
, "DG834")) {
475 ar7_led_data
.num_leds
= ARRAY_SIZE(dg834g_leds
);
476 ar7_led_data
.leds
= dg834g_leds
;
480 static int __init
ar7_register_devices(void)
483 #ifdef CONFIG_SERIAL_8250
484 static struct uart_port uart_port
[2];
486 memset(uart_port
, 0, sizeof(struct uart_port
) * 2);
488 uart_port
[0].type
= PORT_16550A
;
489 uart_port
[0].line
= 0;
490 uart_port
[0].irq
= AR7_IRQ_UART0
;
491 uart_port
[0].uartclk
= ar7_bus_freq() / 2;
492 uart_port
[0].iotype
= UPIO_MEM32
;
493 uart_port
[0].mapbase
= AR7_REGS_UART0
;
494 uart_port
[0].membase
= ioremap(uart_port
[0].mapbase
, 256);
495 uart_port
[0].regshift
= 2;
496 res
= early_serial_setup(&uart_port
[0]);
501 /* Only TNETD73xx have a second serial port */
502 if (ar7_has_second_uart()) {
503 uart_port
[1].type
= PORT_16550A
;
504 uart_port
[1].line
= 1;
505 uart_port
[1].irq
= AR7_IRQ_UART1
;
506 uart_port
[1].uartclk
= ar7_bus_freq() / 2;
507 uart_port
[1].iotype
= UPIO_MEM32
;
508 uart_port
[1].mapbase
= UR8_REGS_UART1
;
509 uart_port
[1].membase
= ioremap(uart_port
[1].mapbase
, 256);
510 uart_port
[1].regshift
= 2;
511 res
= early_serial_setup(&uart_port
[1]);
515 #endif /* CONFIG_SERIAL_8250 */
516 res
= platform_device_register(&physmap_flash
);
520 ar7_device_disable(vlynq_low_data
.reset_bit
);
521 res
= platform_device_register(&vlynq_low
);
525 if (ar7_has_high_vlynq()) {
526 ar7_device_disable(vlynq_high_data
.reset_bit
);
527 res
= platform_device_register(&vlynq_high
);
532 if (ar7_has_high_cpmac()) {
533 cpmac_get_mac(1, cpmac_high_data
.dev_addr
);
534 res
= platform_device_register(&cpmac_high
);
538 cpmac_low_data
.phy_mask
= 0xffffffff;
541 cpmac_get_mac(0, cpmac_low_data
.dev_addr
);
542 res
= platform_device_register(&cpmac_low
);
547 res
= platform_device_register(&ar7_gpio_leds
);
551 res
= platform_device_register(&ar7_udc
);
555 arch_initcall(ar7_register_devices
);