2 * Copyright (C) 2006, 2007 OpenWrt.org
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 fb_sl_leds
[] = {
327 { .name
= "1", .gpio
= 7, },
328 { .name
= "2", .gpio
= 13, .active_low
= 1, },
329 { .name
= "3", .gpio
= 10, .active_low
= 1, },
330 { .name
= "4", .gpio
= 12, .active_low
= 1, },
331 { .name
= "5", .gpio
= 9, .active_low
= 1, },
334 static struct gpio_led fb_fon_leds
[] = {
335 { .name
= "1", .gpio
= 8, },
336 { .name
= "2", .gpio
= 3, .active_low
= 1, },
337 { .name
= "3", .gpio
= 5, },
338 { .name
= "4", .gpio
= 4, .active_low
= 1, },
339 { .name
= "5", .gpio
= 11, .active_low
= 1, },
342 static struct gpio_led_platform_data ar7_led_data
;
344 static struct platform_device ar7_gpio_leds
= {
348 .platform_data
= &ar7_led_data
,
352 static struct platform_device ar7_udc
= {
356 .num_resources
= ARRAY_SIZE(usb_res
),
359 static inline unsigned char char2hex(char h
)
362 case '0': case '1': case '2': case '3': case '4':
363 case '5': case '6': case '7': case '8': case '9':
365 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
367 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
374 static void cpmac_get_mac(int instance
, unsigned char *dev_addr
)
377 char name
[5], default_mac
[] = "00:00:00:12:34:56", *mac
;
380 sprintf(name
, "mac%c", 'a' + instance
);
381 mac
= prom_getenv(name
);
383 sprintf(name
, "mac%c", 'a');
384 mac
= prom_getenv(name
);
388 for (i
= 0; i
< 6; i
++)
389 dev_addr
[i
] = (char2hex(mac
[i
* 3]) << 4) +
390 char2hex(mac
[i
* 3 + 1]);
393 static void __init
detect_leds(void)
398 ar7_led_data
.num_leds
= ARRAY_SIZE(default_leds
);
399 ar7_led_data
.leds
= default_leds
;
401 /* FIXME: the whole thing is unreliable */
402 prId
= prom_getenv("ProductID");
404 /* If we can't get the product id from PROM, use the default LEDs */
408 if (strstr(prId
, "Fritz_Box_FON")) {
409 ar7_led_data
.num_leds
= ARRAY_SIZE(fb_fon_leds
);
410 ar7_led_data
.leds
= fb_fon_leds
;
411 } else if (strstr(prId
, "Fritz_Box_")) {
412 ar7_led_data
.num_leds
= ARRAY_SIZE(fb_sl_leds
);
413 ar7_led_data
.leds
= fb_sl_leds
;
417 static int __init
ar7_register_devices(void)
421 #ifdef CONFIG_SERIAL_8250
423 static struct uart_port uart_port
[2];
425 memset(uart_port
, 0, sizeof(struct uart_port
) * 2);
427 uart_port
[0].type
= PORT_AR7
;
428 uart_port
[0].line
= 0;
429 uart_port
[0].irq
= AR7_IRQ_UART0
;
430 uart_port
[0].uartclk
= ar7_bus_freq() / 2;
431 uart_port
[0].iotype
= UPIO_MEM
;
432 uart_port
[0].mapbase
= AR7_REGS_UART0
;
433 uart_port
[0].membase
= ioremap(uart_port
[0].mapbase
, 256);
434 uart_port
[0].regshift
= 2;
435 res
= early_serial_setup(&uart_port
[0]);
440 /* Only TNETD73xx have a second serial port */
441 if (ar7_has_second_uart()) {
442 uart_port
[1].type
= PORT_AR7
;
443 uart_port
[1].line
= 1;
444 uart_port
[1].irq
= AR7_IRQ_UART1
;
445 uart_port
[1].uartclk
= ar7_bus_freq() / 2;
446 uart_port
[1].iotype
= UPIO_MEM
;
447 uart_port
[1].mapbase
= UR8_REGS_UART1
;
448 uart_port
[1].membase
= ioremap(uart_port
[1].mapbase
, 256);
449 uart_port
[1].regshift
= 2;
450 res
= early_serial_setup(&uart_port
[1]);
455 #else /* !CONFIG_SERIAL_8250 */
457 uart_data
[0].uartclk
= ar7_bus_freq() / 2;
458 uart_data
[1].uartclk
= uart_data
[0].uartclk
;
460 /* Only TNETD73xx have a second serial port */
461 if (ar7_has_second_uart())
462 uart
.dev
.platform_data
= uart_data
;
464 res
= platform_device_register(&uart
);
468 #endif /* CONFIG_SERIAL_8250 */
470 res
= platform_device_register(&physmap_flash
);
474 res
= platform_device_register(&vlynq_low
);
478 ar7_device_disable(vlynq_low_data
.reset_bit
);
479 if (ar7_has_high_vlynq()) {
480 ar7_device_disable(vlynq_high_data
.reset_bit
);
481 res
= platform_device_register(&vlynq_high
);
486 if (ar7_has_high_cpmac()) {
487 cpmac_get_mac(1, cpmac_high_data
.dev_addr
);
488 res
= platform_device_register(&cpmac_high
);
492 cpmac_low_data
.phy_mask
= 0xffffffff;
495 cpmac_get_mac(0, cpmac_low_data
.dev_addr
);
496 res
= platform_device_register(&cpmac_low
);
501 res
= platform_device_register(&ar7_gpio_leds
);
505 res
= platform_device_register(&ar7_udc
);
511 arch_initcall(ar7_register_devices
);