4 * Copyright (C) 2006, 2007 OpenWrt.org
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <linux/autoconf.h>
22 #include <linux/init.h>
23 #include <linux/types.h>
24 #include <linux/module.h>
25 #include <linux/delay.h>
26 #include <linux/platform_device.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/serial.h>
29 #include <linux/serial_8250.h>
30 #include <linux/ioport.h>
31 #include <asm/addrspace.h>
33 #include <asm/ar7/ar7.h>
34 #include <asm/ar7/gpio.h>
35 #include <asm/ar7/prom.h>
36 #include <asm/ar7/vlynq.h>
38 struct plat_vlynq_data {
39 struct plat_vlynq_ops ops;
45 static int vlynq_on(struct vlynq_device *dev)
48 struct plat_vlynq_data *pdata = dev->dev.platform_data;
50 if ((result = gpio_request(pdata->gpio_bit, "vlynq")))
53 ar7_device_reset(pdata->reset_bit);
55 if ((result = ar7_gpio_disable(pdata->gpio_bit)))
58 if ((result = ar7_gpio_enable(pdata->gpio_bit)))
61 if ((result = gpio_direction_output(pdata->gpio_bit)))
62 goto out_gpio_enabled;
64 gpio_set_value(pdata->gpio_bit, 0);
67 gpio_set_value(pdata->gpio_bit, 1);
73 ar7_gpio_disable(pdata->gpio_bit);
75 ar7_device_disable(pdata->reset_bit);
76 gpio_free(pdata->gpio_bit);
81 static void vlynq_off(struct vlynq_device *dev)
83 struct plat_vlynq_data *pdata = dev->dev.platform_data;
84 ar7_gpio_disable(pdata->gpio_bit);
85 gpio_free(pdata->gpio_bit);
86 ar7_device_disable(pdata->reset_bit);
89 static struct resource physmap_flash_resource = {
91 .flags = IORESOURCE_MEM,
96 static struct resource cpmac_low_res[] = {
99 .flags = IORESOURCE_MEM,
100 .start = AR7_REGS_MAC0,
101 .end = AR7_REGS_MAC0 + 0x7FF,
105 .flags = IORESOURCE_IRQ,
111 static struct resource cpmac_high_res[] = {
114 .flags = IORESOURCE_MEM,
115 .start = AR7_REGS_MAC1,
116 .end = AR7_REGS_MAC1 + 0x7FF,
120 .flags = IORESOURCE_IRQ,
126 static struct resource vlynq_low_res[] = {
129 .flags = IORESOURCE_MEM,
130 .start = AR7_REGS_VLYNQ0,
131 .end = AR7_REGS_VLYNQ0 + 0xff,
135 .flags = IORESOURCE_IRQ,
141 .flags = IORESOURCE_MEM,
147 .flags = IORESOURCE_IRQ,
153 static struct resource vlynq_high_res[] = {
156 .flags = IORESOURCE_MEM,
157 .start = AR7_REGS_VLYNQ1,
158 .end = AR7_REGS_VLYNQ1 + 0xFF,
162 .flags = IORESOURCE_IRQ,
168 .flags = IORESOURCE_MEM,
174 .flags = IORESOURCE_IRQ,
180 static struct physmap_flash_data physmap_flash_data = {
184 static struct plat_cpmac_data cpmac_low_data = {
187 .phy_mask = 0x80000000,
190 static struct plat_cpmac_data cpmac_high_data = {
193 .phy_mask = 0x7fffffff,
196 static struct plat_vlynq_data vlynq_low_data = {
198 .ops.off = vlynq_off,
203 static struct plat_vlynq_data vlynq_high_data = {
205 .ops.off = vlynq_off,
210 static struct platform_device physmap_flash = {
212 .name = "physmap-flash",
213 .dev.platform_data = &physmap_flash_data,
214 .resource = &physmap_flash_resource,
218 static struct platform_device cpmac_low = {
221 .dev.platform_data = &cpmac_low_data,
222 .resource = cpmac_low_res,
223 .num_resources = ARRAY_SIZE(cpmac_low_res),
226 static struct platform_device cpmac_high = {
229 .dev.platform_data = &cpmac_high_data,
230 .resource = cpmac_high_res,
231 .num_resources = ARRAY_SIZE(cpmac_high_res),
234 static struct platform_device vlynq_low = {
237 .dev.platform_data = &vlynq_low_data,
238 .resource = vlynq_low_res,
239 .num_resources = ARRAY_SIZE(vlynq_low_res),
242 static struct platform_device vlynq_high = {
245 .dev.platform_data = &vlynq_high_data,
246 .resource = vlynq_high_res,
247 .num_resources = ARRAY_SIZE(vlynq_high_res),
251 /* This is proper way to define uart ports, but they are then detected
252 * as xscale and, obviously, don't work...
254 #if !defined(CONFIG_SERIAL_8250)
256 static struct plat_serial8250_port uart0_data =
258 .mapbase = AR7_REGS_UART0,
259 .irq = AR7_IRQ_UART0,
262 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
265 static struct plat_serial8250_port uart1_data =
267 .mapbase = UR8_REGS_UART1,
268 .irq = AR7_IRQ_UART1,
271 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
274 static struct plat_serial8250_port uart_data[] = {
280 static struct plat_serial8250_port uart_data_single[] = {
285 static struct platform_device uart = {
287 .name = "serial8250",
288 .dev.platform_data = uart_data_single
292 static inline unsigned char char2hex(char h)
295 case '0': case '1': case '2': case '3': case '4':
296 case '5': case '6': case '7': case '8': case '9':
298 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
300 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
307 static void cpmac_get_mac(int instance, unsigned char *dev_addr)
310 char name[5], default_mac[] = "00:00:00:12:34:56", *mac;
313 sprintf(name, "mac%c", 'a' + instance);
314 mac = prom_getenv(name);
316 sprintf(name, "mac%c", 'a');
317 mac = prom_getenv(name);
321 for (i = 0; i < 6; i++)
322 dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
323 char2hex(mac[i * 3 + 1]);
326 static int __init ar7_register_devices(void)
330 #ifdef CONFIG_SERIAL_8250
332 static struct uart_port uart_port[2];
334 memset(uart_port, 0, sizeof(struct uart_port) * 2);
336 uart_port[0].type = PORT_AR7;
337 uart_port[0].line = 0;
338 uart_port[0].irq = AR7_IRQ_UART0;
339 uart_port[0].uartclk = ar7_bus_freq() / 2;
340 uart_port[0].iotype = UPIO_MEM;
341 uart_port[0].mapbase = AR7_REGS_UART0;
342 uart_port[0].membase = ioremap(uart_port[0].mapbase, 256);
343 uart_port[0].regshift = 2;
344 res = early_serial_setup(&uart_port[0]);
349 // Only TNETD73xx have a second serial port
350 if (ar7_has_second_uart()) {
351 uart_port[1].type = PORT_AR7;
352 uart_port[1].line = 1;
353 uart_port[1].irq = AR7_IRQ_UART1;
354 uart_port[1].uartclk = ar7_bus_freq() / 2;
355 uart_port[1].iotype = UPIO_MEM;
356 uart_port[1].mapbase = UR8_REGS_UART1;
357 uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
358 uart_port[1].regshift = 2;
359 res = early_serial_setup(&uart_port[1]);
364 #else // !CONFIG_SERIAL_8250
366 uart_data[0].uartclk = ar7_bus_freq() / 2;
367 uart_data[1].uartclk = uart_data[0].uartclk;
369 // Only TNETD73xx have a second serial port
370 if (ar7_has_second_uart()) {
371 uart.dev.platform_data = uart_data;
374 res = platform_device_register(&uart);
378 #endif // CONFIG_SERIAL_8250
380 res = platform_device_register(&physmap_flash);
384 res = platform_device_register(&vlynq_low);
388 ar7_device_disable(vlynq_low_data.reset_bit);
389 if (ar7_has_high_vlynq()) {
390 ar7_device_disable(vlynq_high_data.reset_bit);
391 res = platform_device_register(&vlynq_high);
396 if (ar7_has_high_cpmac()) {
397 cpmac_get_mac(1, cpmac_high_data.dev_addr);
398 res = platform_device_register(&cpmac_high);
402 cpmac_low_data.phy_mask = 0xffffffff;
405 cpmac_get_mac(0, cpmac_low_data.dev_addr);
406 res = platform_device_register(&cpmac_low);
412 arch_initcall(ar7_register_devices);