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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
33 #include <linux/leds.h>
36 #include <asm/addrspace.h>
37 #include <asm/ar7/ar7.h>
38 #include <asm/ar7/gpio.h>
39 #include <asm/ar7/prom.h>
40 #include <asm/ar7/vlynq.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 if ((result
= gpio_request(pdata
->gpio_bit
, "vlynq")))
57 ar7_device_reset(pdata
->reset_bit
);
59 if ((result
= ar7_gpio_disable(pdata
->gpio_bit
)))
62 if ((result
= ar7_gpio_enable(pdata
->gpio_bit
)))
65 if ((result
= gpio_direction_output(pdata
->gpio_bit
, 0)))
66 goto out_gpio_enabled
;
70 gpio_set_value(pdata
->gpio_bit
, 1);
76 ar7_gpio_disable(pdata
->gpio_bit
);
78 ar7_device_disable(pdata
->reset_bit
);
79 gpio_free(pdata
->gpio_bit
);
84 static void vlynq_off(struct vlynq_device
*dev
)
86 struct plat_vlynq_data
*pdata
= dev
->dev
.platform_data
;
87 ar7_gpio_disable(pdata
->gpio_bit
);
88 gpio_free(pdata
->gpio_bit
);
89 ar7_device_disable(pdata
->reset_bit
);
92 static struct resource physmap_flash_resource
= {
94 .flags
= IORESOURCE_MEM
,
99 static struct resource cpmac_low_res
[] = {
102 .flags
= IORESOURCE_MEM
,
103 .start
= AR7_REGS_MAC0
,
104 .end
= AR7_REGS_MAC0
+ 0x7ff,
108 .flags
= IORESOURCE_IRQ
,
114 static struct resource cpmac_high_res
[] = {
117 .flags
= IORESOURCE_MEM
,
118 .start
= AR7_REGS_MAC1
,
119 .end
= AR7_REGS_MAC1
+ 0x7ff,
123 .flags
= IORESOURCE_IRQ
,
129 static struct resource vlynq_low_res
[] = {
132 .flags
= IORESOURCE_MEM
,
133 .start
= AR7_REGS_VLYNQ0
,
134 .end
= AR7_REGS_VLYNQ0
+ 0xff,
138 .flags
= IORESOURCE_IRQ
,
144 .flags
= IORESOURCE_MEM
,
150 .flags
= IORESOURCE_IRQ
,
156 static struct resource vlynq_high_res
[] = {
159 .flags
= IORESOURCE_MEM
,
160 .start
= AR7_REGS_VLYNQ1
,
161 .end
= AR7_REGS_VLYNQ1
+ 0xff,
165 .flags
= IORESOURCE_IRQ
,
171 .flags
= IORESOURCE_MEM
,
177 .flags
= IORESOURCE_IRQ
,
183 static struct resource usb_res
[] = {
186 .flags
= IORESOURCE_MEM
,
187 .start
= AR7_REGS_USB
,
188 .end
= AR7_REGS_USB
+ 0xff,
192 .flags
= IORESOURCE_IRQ
,
198 .flags
= IORESOURCE_MEM
,
204 static struct physmap_flash_data physmap_flash_data
= {
208 static struct plat_cpmac_data cpmac_low_data
= {
211 .phy_mask
= 0x80000000,
214 static struct plat_cpmac_data cpmac_high_data
= {
217 .phy_mask
= 0x7fffffff,
220 static struct plat_vlynq_data vlynq_low_data
= {
222 .ops
.off
= vlynq_off
,
227 static struct plat_vlynq_data vlynq_high_data
= {
229 .ops
.off
= vlynq_off
,
234 static struct platform_device physmap_flash
= {
236 .name
= "physmap-flash",
237 .dev
.platform_data
= &physmap_flash_data
,
238 .resource
= &physmap_flash_resource
,
242 static u64 cpmac_dma_mask
= DMA_32BIT_MASK
;
243 static struct platform_device cpmac_low
= {
247 .dma_mask
= &cpmac_dma_mask
,
248 .coherent_dma_mask
= DMA_32BIT_MASK
,
249 .platform_data
= &cpmac_low_data
,
251 .resource
= cpmac_low_res
,
252 .num_resources
= ARRAY_SIZE(cpmac_low_res
),
255 static struct platform_device cpmac_high
= {
259 .dma_mask
= &cpmac_dma_mask
,
260 .coherent_dma_mask
= DMA_32BIT_MASK
,
261 .platform_data
= &cpmac_high_data
,
263 .resource
= cpmac_high_res
,
264 .num_resources
= ARRAY_SIZE(cpmac_high_res
),
267 static struct platform_device vlynq_low
= {
270 .dev
.platform_data
= &vlynq_low_data
,
271 .resource
= vlynq_low_res
,
272 .num_resources
= ARRAY_SIZE(vlynq_low_res
),
275 static struct platform_device vlynq_high
= {
278 .dev
.platform_data
= &vlynq_high_data
,
279 .resource
= vlynq_high_res
,
280 .num_resources
= ARRAY_SIZE(vlynq_high_res
),
284 /* This is proper way to define uart ports, but they are then detected
285 * as xscale and, obviously, don't work...
287 #if !defined(CONFIG_SERIAL_8250)
289 static struct plat_serial8250_port uart0_data
= {
290 .mapbase
= AR7_REGS_UART0
,
291 .irq
= AR7_IRQ_UART0
,
294 .flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
,
297 static struct plat_serial8250_port uart1_data
= {
298 .mapbase
= UR8_REGS_UART1
,
299 .irq
= AR7_IRQ_UART1
,
302 .flags
= UPF_BOOT_AUTOCONF
| UPF_IOREMAP
,
305 static struct plat_serial8250_port uart_data
[] = {
311 static struct plat_serial8250_port uart_data_single
[] = {
316 static struct platform_device uart
= {
318 .name
= "serial8250",
319 .dev
.platform_data
= uart_data_single
323 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
324 static struct gpio_led default_leds
[] = {
325 { .name
= "status", .gpio
= 8, .active_low
= 1, },
328 static struct gpio_led fb_leds
[] = {
329 { .name
= "1", .gpio
= 7, },
330 { .name
= "2", .gpio
= 13, .active_low
= 1, },
331 { .name
= "3", .gpio
= 10, .active_low
= 1, },
332 { .name
= "4", .gpio
= 12, .active_low
= 1, },
333 { .name
= "5", .gpio
= 9, .active_low
= 1, },
336 static struct gpio_led fb_fon_leds
[] = {
337 { .name
= "1", .gpio
= 8, },
338 { .name
= "2", .gpio
= 3, .active_low
= 1, },
339 { .name
= "3", .gpio
= 5, },
340 { .name
= "4", .gpio
= 4, .active_low
= 1, },
341 { .name
= "5", .gpio
= 11, .active_low
= 1, },
344 static struct gpio_led_platform_data ar7_led_data
;
346 static struct platform_device ar7_gpio_leds
= {
350 .platform_data
= &ar7_led_data
,
355 static struct platform_device ar7_udc
= {
359 .num_resources
= ARRAY_SIZE(usb_res
),
362 static inline unsigned char char2hex(char h
)
365 case '0': case '1': case '2': case '3': case '4':
366 case '5': case '6': case '7': case '8': case '9':
368 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
370 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
377 static void cpmac_get_mac(int instance
, unsigned char *dev_addr
)
380 char name
[5], default_mac
[] = "00:00:00:12:34:56", *mac
;
383 sprintf(name
, "mac%c", 'a' + instance
);
384 mac
= prom_getenv(name
);
386 sprintf(name
, "mac%c", 'a');
387 mac
= prom_getenv(name
);
391 for (i
= 0; i
< 6; i
++)
392 dev_addr
[i
] = (char2hex(mac
[i
* 3]) << 4) +
393 char2hex(mac
[i
* 3 + 1]);
396 static int __init
ar7_register_devices(void)
400 #ifdef CONFIG_SERIAL_8250
402 static struct uart_port uart_port
[2];
404 memset(uart_port
, 0, sizeof(struct uart_port
) * 2);
406 uart_port
[0].type
= PORT_AR7
;
407 uart_port
[0].line
= 0;
408 uart_port
[0].irq
= AR7_IRQ_UART0
;
409 uart_port
[0].uartclk
= ar7_bus_freq() / 2;
410 uart_port
[0].iotype
= UPIO_MEM
;
411 uart_port
[0].mapbase
= AR7_REGS_UART0
;
412 uart_port
[0].membase
= ioremap(uart_port
[0].mapbase
, 256);
413 uart_port
[0].regshift
= 2;
414 res
= early_serial_setup(&uart_port
[0]);
419 /* Only TNETD73xx have a second serial port */
420 if (ar7_has_second_uart()) {
421 uart_port
[1].type
= PORT_AR7
;
422 uart_port
[1].line
= 1;
423 uart_port
[1].irq
= AR7_IRQ_UART1
;
424 uart_port
[1].uartclk
= ar7_bus_freq() / 2;
425 uart_port
[1].iotype
= UPIO_MEM
;
426 uart_port
[1].mapbase
= UR8_REGS_UART1
;
427 uart_port
[1].membase
= ioremap(uart_port
[1].mapbase
, 256);
428 uart_port
[1].regshift
= 2;
429 res
= early_serial_setup(&uart_port
[1]);
434 #else /* !CONFIG_SERIAL_8250 */
436 uart_data
[0].uartclk
= ar7_bus_freq() / 2;
437 uart_data
[1].uartclk
= uart_data
[0].uartclk
;
439 /* Only TNETD73xx have a second serial port */
440 if (ar7_has_second_uart())
441 uart
.dev
.platform_data
= uart_data
;
443 res
= platform_device_register(&uart
);
447 #endif /* CONFIG_SERIAL_8250 */
449 res
= platform_device_register(&physmap_flash
);
453 res
= platform_device_register(&vlynq_low
);
457 ar7_device_disable(vlynq_low_data
.reset_bit
);
458 if (ar7_has_high_vlynq()) {
459 ar7_device_disable(vlynq_high_data
.reset_bit
);
460 res
= platform_device_register(&vlynq_high
);
465 if (ar7_has_high_cpmac()) {
466 cpmac_get_mac(1, cpmac_high_data
.dev_addr
);
467 res
= platform_device_register(&cpmac_high
);
471 cpmac_low_data
.phy_mask
= 0xffffffff;
474 cpmac_get_mac(0, cpmac_low_data
.dev_addr
);
475 res
= platform_device_register(&cpmac_low
);
479 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
480 #warning FIXME: add model detection
481 ar7_led_data
.num_leds
= ARRAY_SIZE(default_leds
);
482 ar7_led_data
.leds
= default_leds
;
483 res
= platform_device_register(&ar7_gpio_leds
);
488 res
= platform_device_register(&ar7_udc
);
494 arch_initcall(ar7_register_devices
);