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/version.h>
32 #include <linux/vlynq.h>
33 #include <linux/leds.h>
34 #include <linux/string.h>
35 #include <linux/etherdevice.h>
37 #include <asm/addrspace.h>
38 #include <asm/mach-ar7/ar7.h>
39 #include <asm/mach-ar7/gpio.h>
40 #include <asm/mach-ar7/prom.h>
42 struct plat_vlynq_data {
43 struct plat_vlynq_ops ops;
49 static int vlynq_on(struct vlynq_device *dev)
52 struct plat_vlynq_data *pdata = dev->dev.platform_data;
54 result = gpio_request(pdata->gpio_bit, "vlynq");
58 ar7_device_reset(pdata->reset_bit);
60 result = ar7_gpio_disable(pdata->gpio_bit);
64 result = ar7_gpio_enable(pdata->gpio_bit);
68 result = gpio_direction_output(pdata->gpio_bit, 0);
70 goto out_gpio_enabled;
74 gpio_set_value(pdata->gpio_bit, 1);
80 ar7_gpio_disable(pdata->gpio_bit);
82 ar7_device_disable(pdata->reset_bit);
83 gpio_free(pdata->gpio_bit);
88 static void vlynq_off(struct vlynq_device *dev)
90 struct plat_vlynq_data *pdata = dev->dev.platform_data;
91 ar7_gpio_disable(pdata->gpio_bit);
92 gpio_free(pdata->gpio_bit);
93 ar7_device_disable(pdata->reset_bit);
96 static struct resource physmap_flash_resource = {
98 .flags = IORESOURCE_MEM,
103 static struct resource cpmac_low_res[] = {
106 .flags = IORESOURCE_MEM,
107 .start = AR7_REGS_MAC0,
108 .end = AR7_REGS_MAC0 + 0x7ff,
112 .flags = IORESOURCE_IRQ,
118 static struct resource cpmac_high_res[] = {
121 .flags = IORESOURCE_MEM,
122 .start = AR7_REGS_MAC1,
123 .end = AR7_REGS_MAC1 + 0x7ff,
127 .flags = IORESOURCE_IRQ,
133 static struct resource vlynq_low_res[] = {
136 .flags = IORESOURCE_MEM,
137 .start = AR7_REGS_VLYNQ0,
138 .end = AR7_REGS_VLYNQ0 + 0xff,
142 .flags = IORESOURCE_IRQ,
148 .flags = IORESOURCE_MEM,
154 .flags = IORESOURCE_IRQ,
160 static struct resource vlynq_high_res[] = {
163 .flags = IORESOURCE_MEM,
164 .start = AR7_REGS_VLYNQ1,
165 .end = AR7_REGS_VLYNQ1 + 0xff,
169 .flags = IORESOURCE_IRQ,
175 .flags = IORESOURCE_MEM,
181 .flags = IORESOURCE_IRQ,
187 static struct resource usb_res[] = {
190 .flags = IORESOURCE_MEM,
191 .start = AR7_REGS_USB,
192 .end = AR7_REGS_USB + 0xff,
196 .flags = IORESOURCE_IRQ,
202 .flags = IORESOURCE_MEM,
208 static struct physmap_flash_data physmap_flash_data = {
212 static struct plat_cpmac_data cpmac_low_data = {
215 .phy_mask = 0x80000000,
218 static struct plat_cpmac_data cpmac_high_data = {
221 .phy_mask = 0x7fffffff,
224 static struct plat_vlynq_data vlynq_low_data = {
226 .ops.off = vlynq_off,
231 static struct plat_vlynq_data vlynq_high_data = {
233 .ops.off = vlynq_off,
238 static struct platform_device physmap_flash = {
240 .name = "physmap-flash",
241 .dev.platform_data = &physmap_flash_data,
242 .resource = &physmap_flash_resource,
246 static u64 cpmac_dma_mask = DMA_32BIT_MASK;
247 static struct platform_device cpmac_low = {
251 .dma_mask = &cpmac_dma_mask,
252 .coherent_dma_mask = DMA_32BIT_MASK,
253 .platform_data = &cpmac_low_data,
255 .resource = cpmac_low_res,
256 .num_resources = ARRAY_SIZE(cpmac_low_res),
259 static struct platform_device cpmac_high = {
263 .dma_mask = &cpmac_dma_mask,
264 .coherent_dma_mask = DMA_32BIT_MASK,
265 .platform_data = &cpmac_high_data,
267 .resource = cpmac_high_res,
268 .num_resources = ARRAY_SIZE(cpmac_high_res),
271 static struct platform_device vlynq_low = {
274 .dev.platform_data = &vlynq_low_data,
275 .resource = vlynq_low_res,
276 .num_resources = ARRAY_SIZE(vlynq_low_res),
279 static struct platform_device vlynq_high = {
282 .dev.platform_data = &vlynq_high_data,
283 .resource = vlynq_high_res,
284 .num_resources = ARRAY_SIZE(vlynq_high_res),
288 static struct gpio_led default_leds[] = {
296 static struct gpio_led dsl502t_leds[] = {
314 static struct gpio_led dg834g_leds[] = {
339 .default_trigger = "default-on",
343 static struct gpio_led fb_sl_leds[] = {
370 static struct gpio_led fb_fon_leds[] = {
396 static struct gpio_led_platform_data ar7_led_data;
398 static struct platform_device ar7_gpio_leds = {
402 .platform_data = &ar7_led_data,
406 static struct platform_device ar7_udc = {
410 .num_resources = ARRAY_SIZE(usb_res),
413 static inline unsigned char char2hex(char h)
416 case '0': case '1': case '2': case '3': case '4':
417 case '5': case '6': case '7': case '8': case '9':
419 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
421 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
428 static void cpmac_get_mac(int instance, unsigned char *dev_addr)
431 char name[5], default_mac[ETH_ALEN], *mac;
434 sprintf(name, "mac%c", 'a' + instance);
435 mac = prom_getenv(name);
437 sprintf(name, "mac%c", 'a');
438 mac = prom_getenv(name);
441 random_ether_addr(default_mac);
444 for (i = 0; i < 6; i++)
445 dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
446 char2hex(mac[i * 3 + 1]);
449 static void __init detect_leds(void)
451 char *prid, *usb_prod;
454 ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
455 ar7_led_data.leds = default_leds;
457 /* FIXME: the whole thing is unreliable */
458 prid = prom_getenv("ProductID");
459 usb_prod = prom_getenv("usb_prod");
461 /* If we can't get the product id from PROM, use the default LEDs */
465 if (strstr(prid, "Fritz_Box_FON")) {
466 ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
467 ar7_led_data.leds = fb_fon_leds;
468 } else if (strstr(prid, "Fritz_Box_")) {
469 ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
470 ar7_led_data.leds = fb_sl_leds;
471 } else if ((!strcmp(prid, "AR7RD") || !strcmp(prid, "AR7DB"))
472 && usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
473 ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
474 ar7_led_data.leds = dsl502t_leds;
475 } else if (strstr(prid, "DG834")) {
476 ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
477 ar7_led_data.leds = dg834g_leds;
481 static int __init ar7_register_devices(void)
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]);
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);