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>
35 #include <asm/addrspace.h>
36 #include <asm/ar7/ar7.h>
37 #include <asm/ar7/gpio.h>
38 #include <asm/ar7/prom.h>
40 struct plat_vlynq_data
{
41 struct plat_vlynq_ops ops
;
47 static int vlynq_on(struct vlynq_device
*dev
)
50 struct plat_vlynq_data
*pdata
= dev
->dev
.platform_data
;
52 if ((result
= gpio_request(pdata
->gpio_bit
, "vlynq")))
55 ar7_device_reset(pdata
->reset_bit
);
57 if ((result
= ar7_gpio_disable(pdata
->gpio_bit
)))
60 if ((result
= ar7_gpio_enable(pdata
->gpio_bit
)))
63 if ((result
= gpio_direction_output(pdata
->gpio_bit
, 0)))
64 goto out_gpio_enabled
;
68 gpio_set_value(pdata
->gpio_bit
, 1);
74 ar7_gpio_disable(pdata
->gpio_bit
);
76 ar7_device_disable(pdata
->reset_bit
);
77 gpio_free(pdata
->gpio_bit
);
82 static void vlynq_off(struct vlynq_device
*dev
)
84 struct plat_vlynq_data
*pdata
= dev
->dev
.platform_data
;
85 ar7_gpio_disable(pdata
->gpio_bit
);
86 gpio_free(pdata
->gpio_bit
);
87 ar7_device_disable(pdata
->reset_bit
);
90 static struct resource physmap_flash_resource
= {
92 .flags
= IORESOURCE_MEM
,
97 static struct resource cpmac_low_res
[] = {
100 .flags
= IORESOURCE_MEM
,
101 .start
= AR7_REGS_MAC0
,
102 .end
= AR7_REGS_MAC0
+ 0x7ff,
106 .flags
= IORESOURCE_IRQ
,
112 static struct resource cpmac_high_res
[] = {
115 .flags
= IORESOURCE_MEM
,
116 .start
= AR7_REGS_MAC1
,
117 .end
= AR7_REGS_MAC1
+ 0x7ff,
121 .flags
= IORESOURCE_IRQ
,
127 static struct resource vlynq_low_res
[] = {
130 .flags
= IORESOURCE_MEM
,
131 .start
= AR7_REGS_VLYNQ0
,
132 .end
= AR7_REGS_VLYNQ0
+ 0xff,
136 .flags
= IORESOURCE_IRQ
,
142 .flags
= IORESOURCE_MEM
,
148 .flags
= IORESOURCE_IRQ
,
154 static struct resource vlynq_high_res
[] = {
157 .flags
= IORESOURCE_MEM
,
158 .start
= AR7_REGS_VLYNQ1
,
159 .end
= AR7_REGS_VLYNQ1
+ 0xff,
163 .flags
= IORESOURCE_IRQ
,
169 .flags
= IORESOURCE_MEM
,
175 .flags
= IORESOURCE_IRQ
,
181 static struct resource usb_res
[] = {
184 .flags
= IORESOURCE_MEM
,
185 .start
= AR7_REGS_USB
,
186 .end
= AR7_REGS_USB
+ 0xff,
190 .flags
= IORESOURCE_IRQ
,
196 .flags
= IORESOURCE_MEM
,
202 static struct physmap_flash_data physmap_flash_data
= {
206 static struct plat_cpmac_data cpmac_low_data
= {
209 .phy_mask
= 0x80000000,
212 static struct plat_cpmac_data cpmac_high_data
= {
215 .phy_mask
= 0x7fffffff,
218 static struct plat_vlynq_data vlynq_low_data
= {
220 .ops
.off
= vlynq_off
,
225 static struct plat_vlynq_data vlynq_high_data
= {
227 .ops
.off
= vlynq_off
,
232 static struct platform_device physmap_flash
= {
234 .name
= "physmap-flash",
235 .dev
.platform_data
= &physmap_flash_data
,
236 .resource
= &physmap_flash_resource
,
240 static u64 cpmac_dma_mask
= DMA_32BIT_MASK
;
241 static struct platform_device cpmac_low
= {
245 .dma_mask
= &cpmac_dma_mask
,
246 .coherent_dma_mask
= DMA_32BIT_MASK
,
247 .platform_data
= &cpmac_low_data
,
249 .resource
= cpmac_low_res
,
250 .num_resources
= ARRAY_SIZE(cpmac_low_res
),
253 static struct platform_device cpmac_high
= {
257 .dma_mask
= &cpmac_dma_mask
,
258 .coherent_dma_mask
= DMA_32BIT_MASK
,
259 .platform_data
= &cpmac_high_data
,
261 .resource
= cpmac_high_res
,
262 .num_resources
= ARRAY_SIZE(cpmac_high_res
),
265 static struct platform_device vlynq_low
= {
268 .dev
.platform_data
= &vlynq_low_data
,
269 .resource
= vlynq_low_res
,
270 .num_resources
= ARRAY_SIZE(vlynq_low_res
),
273 static struct platform_device vlynq_high
= {
276 .dev
.platform_data
= &vlynq_high_data
,
277 .resource
= vlynq_high_res
,
278 .num_resources
= ARRAY_SIZE(vlynq_high_res
),
282 /* This is proper way to define uart ports, but they are then detected
283 * as xscale and, obviously, don't work...
285 #if !defined(CONFIG_SERIAL_8250)
287 static struct plat_serial8250_port uart0_data
= {
288 .mapbase
= AR7_REGS_UART0
,
289 .irq
= AR7_IRQ_UART0
,
292 .flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
,
295 static struct plat_serial8250_port uart1_data
= {
296 .mapbase
= UR8_REGS_UART1
,
297 .irq
= AR7_IRQ_UART1
,
300 .flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
,
303 static struct plat_serial8250_port uart_data
[] = {
309 static struct plat_serial8250_port uart_data_single
[] = {
314 static struct platform_device uart
= {
316 .name
= "serial8250",
317 .dev
.platform_data
= uart_data_single
321 static struct gpio_led default_leds
[] = {
322 { .name
= "status", .gpio
= 8, .active_low
= 1, },
325 static struct gpio_led fb_leds
[] = {
326 { .name
= "1", .gpio
= 7, },
327 { .name
= "2", .gpio
= 13, .active_low
= 1, },
328 { .name
= "3", .gpio
= 10, .active_low
= 1, },
329 { .name
= "4", .gpio
= 12, .active_low
= 1, },
330 { .name
= "5", .gpio
= 9, .active_low
= 1, },
333 static struct gpio_led fb_fon_leds
[] = {
334 { .name
= "1", .gpio
= 8, },
335 { .name
= "2", .gpio
= 3, .active_low
= 1, },
336 { .name
= "3", .gpio
= 5, },
337 { .name
= "4", .gpio
= 4, .active_low
= 1, },
338 { .name
= "5", .gpio
= 11, .active_low
= 1, },
341 static struct gpio_led_platform_data ar7_led_data
;
343 static struct platform_device ar7_gpio_leds
= {
347 .platform_data
= &ar7_led_data
,
351 static struct platform_device ar7_udc
= {
355 .num_resources
= ARRAY_SIZE(usb_res
),
358 static inline unsigned char char2hex(char h
)
361 case '0': case '1': case '2': case '3': case '4':
362 case '5': case '6': case '7': case '8': case '9':
364 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
366 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
373 static void cpmac_get_mac(int instance
, unsigned char *dev_addr
)
376 char name
[5], default_mac
[] = "00:00:00:12:34:56", *mac
;
379 sprintf(name
, "mac%c", 'a' + instance
);
380 mac
= prom_getenv(name
);
382 sprintf(name
, "mac%c", 'a');
383 mac
= prom_getenv(name
);
387 for (i
= 0; i
< 6; i
++)
388 dev_addr
[i
] = (char2hex(mac
[i
* 3]) << 4) +
389 char2hex(mac
[i
* 3 + 1]);
392 static int __init
ar7_register_devices(void)
396 #ifdef CONFIG_SERIAL_8250
398 static struct uart_port uart_port
[2];
400 memset(uart_port
, 0, sizeof(struct uart_port
) * 2);
402 uart_port
[0].type
= PORT_AR7
;
403 uart_port
[0].line
= 0;
404 uart_port
[0].irq
= AR7_IRQ_UART0
;
405 uart_port
[0].uartclk
= ar7_bus_freq() / 2;
406 uart_port
[0].iotype
= UPIO_MEM
;
407 uart_port
[0].mapbase
= AR7_REGS_UART0
;
408 uart_port
[0].membase
= ioremap(uart_port
[0].mapbase
, 256);
409 uart_port
[0].regshift
= 2;
410 res
= early_serial_setup(&uart_port
[0]);
415 /* Only TNETD73xx have a second serial port */
416 if (ar7_has_second_uart()) {
417 uart_port
[1].type
= PORT_AR7
;
418 uart_port
[1].line
= 1;
419 uart_port
[1].irq
= AR7_IRQ_UART1
;
420 uart_port
[1].uartclk
= ar7_bus_freq() / 2;
421 uart_port
[1].iotype
= UPIO_MEM
;
422 uart_port
[1].mapbase
= UR8_REGS_UART1
;
423 uart_port
[1].membase
= ioremap(uart_port
[1].mapbase
, 256);
424 uart_port
[1].regshift
= 2;
425 res
= early_serial_setup(&uart_port
[1]);
430 #else /* !CONFIG_SERIAL_8250 */
432 uart_data
[0].uartclk
= ar7_bus_freq() / 2;
433 uart_data
[1].uartclk
= uart_data
[0].uartclk
;
435 /* Only TNETD73xx have a second serial port */
436 if (ar7_has_second_uart())
437 uart
.dev
.platform_data
= uart_data
;
439 res
= platform_device_register(&uart
);
443 #endif /* CONFIG_SERIAL_8250 */
445 res
= platform_device_register(&physmap_flash
);
449 res
= platform_device_register(&vlynq_low
);
453 ar7_device_disable(vlynq_low_data
.reset_bit
);
454 if (ar7_has_high_vlynq()) {
455 ar7_device_disable(vlynq_high_data
.reset_bit
);
456 res
= platform_device_register(&vlynq_high
);
461 if (ar7_has_high_cpmac()) {
462 cpmac_get_mac(1, cpmac_high_data
.dev_addr
);
463 res
= platform_device_register(&cpmac_high
);
467 cpmac_low_data
.phy_mask
= 0xffffffff;
470 cpmac_get_mac(0, cpmac_low_data
.dev_addr
);
471 res
= platform_device_register(&cpmac_low
);
475 #warning FIXME: add model detection
476 ar7_led_data
.num_leds
= ARRAY_SIZE(default_leds
);
477 ar7_led_data
.leds
= default_leds
;
478 res
= platform_device_register(&ar7_gpio_leds
);
482 res
= platform_device_register(&ar7_udc
);
488 arch_initcall(ar7_register_devices
);