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/platform_device.h>
25 #include <linux/mtd/physmap.h>
26 #include <linux/serial.h>
27 #include <linux/serial_8250.h>
28 #include <linux/ioport.h>
31 #include <asm/addrspace.h>
32 #include <asm/ar7/ar7.h>
33 #include <asm/ar7/gpio.h>
34 #include <asm/ar7/prom.h>
35 #include <asm/ar7/vlynq.h>
37 struct plat_vlynq_data {
38 struct plat_vlynq_ops ops;
44 static int vlynq_on(struct vlynq_device *dev)
47 struct plat_vlynq_data *pdata = dev->dev.platform_data;
49 if ((result = gpio_request(pdata->gpio_bit, "vlynq")))
52 ar7_device_reset(pdata->reset_bit);
54 if ((result = ar7_gpio_disable(pdata->gpio_bit)))
57 if ((result = ar7_gpio_enable(pdata->gpio_bit)))
60 if ((result = gpio_direction_output(pdata->gpio_bit)))
61 goto out_gpio_enabled;
63 gpio_set_value(pdata->gpio_bit, 0);
66 gpio_set_value(pdata->gpio_bit, 1);
72 ar7_gpio_disable(pdata->gpio_bit);
74 ar7_device_disable(pdata->reset_bit);
75 gpio_free(pdata->gpio_bit);
80 static void vlynq_off(struct vlynq_device *dev)
82 struct plat_vlynq_data *pdata = dev->dev.platform_data;
83 ar7_gpio_disable(pdata->gpio_bit);
84 gpio_free(pdata->gpio_bit);
85 ar7_device_disable(pdata->reset_bit);
88 static struct resource physmap_flash_resource = {
90 .flags = IORESOURCE_MEM,
95 static struct resource cpmac_low_res[] = {
98 .flags = IORESOURCE_MEM,
99 .start = AR7_REGS_MAC0,
100 .end = AR7_REGS_MAC0 + 0x7ff,
104 .flags = IORESOURCE_IRQ,
110 static struct resource cpmac_high_res[] = {
113 .flags = IORESOURCE_MEM,
114 .start = AR7_REGS_MAC1,
115 .end = AR7_REGS_MAC1 + 0x7ff,
119 .flags = IORESOURCE_IRQ,
125 static struct resource vlynq_low_res[] = {
128 .flags = IORESOURCE_MEM,
129 .start = AR7_REGS_VLYNQ0,
130 .end = AR7_REGS_VLYNQ0 + 0xff,
134 .flags = IORESOURCE_IRQ,
140 .flags = IORESOURCE_MEM,
146 .flags = IORESOURCE_IRQ,
152 static struct resource vlynq_high_res[] = {
155 .flags = IORESOURCE_MEM,
156 .start = AR7_REGS_VLYNQ1,
157 .end = AR7_REGS_VLYNQ1 + 0xff,
161 .flags = IORESOURCE_IRQ,
167 .flags = IORESOURCE_MEM,
173 .flags = IORESOURCE_IRQ,
179 static struct physmap_flash_data physmap_flash_data = {
183 static struct plat_cpmac_data cpmac_low_data = {
186 .phy_mask = 0x80000000,
189 static struct plat_cpmac_data cpmac_high_data = {
192 .phy_mask = 0x7fffffff,
195 static struct plat_vlynq_data vlynq_low_data = {
197 .ops.off = vlynq_off,
202 static struct plat_vlynq_data vlynq_high_data = {
204 .ops.off = vlynq_off,
209 static struct platform_device physmap_flash = {
211 .name = "physmap-flash",
212 .dev.platform_data = &physmap_flash_data,
213 .resource = &physmap_flash_resource,
217 static struct platform_device cpmac_low = {
220 .dev.platform_data = &cpmac_low_data,
221 .resource = cpmac_low_res,
222 .num_resources = ARRAY_SIZE(cpmac_low_res),
225 static struct platform_device cpmac_high = {
228 .dev.platform_data = &cpmac_high_data,
229 .resource = cpmac_high_res,
230 .num_resources = ARRAY_SIZE(cpmac_high_res),
233 static struct platform_device vlynq_low = {
236 .dev.platform_data = &vlynq_low_data,
237 .resource = vlynq_low_res,
238 .num_resources = ARRAY_SIZE(vlynq_low_res),
241 static struct platform_device vlynq_high = {
244 .dev.platform_data = &vlynq_high_data,
245 .resource = vlynq_high_res,
246 .num_resources = ARRAY_SIZE(vlynq_high_res),
250 /* This is proper way to define uart ports, but they are then detected
251 * as xscale and, obviously, don't work...
253 #if !defined(CONFIG_SERIAL_8250)
255 static struct plat_serial8250_port uart0_data = {
256 .mapbase = AR7_REGS_UART0,
257 .irq = AR7_IRQ_UART0,
260 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
263 static struct plat_serial8250_port uart1_data = {
264 .mapbase = UR8_REGS_UART1,
265 .irq = AR7_IRQ_UART1,
268 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
271 static struct plat_serial8250_port uart_data[] = {
277 static struct plat_serial8250_port uart_data_single[] = {
282 static struct platform_device uart = {
284 .name = "serial8250",
285 .dev.platform_data = uart_data_single
289 static inline unsigned char char2hex(char h)
292 case '0': case '1': case '2': case '3': case '4':
293 case '5': case '6': case '7': case '8': case '9':
295 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
297 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
304 static void cpmac_get_mac(int instance, unsigned char *dev_addr)
307 char name[5], default_mac[] = "00:00:00:12:34:56", *mac;
310 sprintf(name, "mac%c", 'a' + instance);
311 mac = prom_getenv(name);
313 sprintf(name, "mac%c", 'a');
314 mac = prom_getenv(name);
318 for (i = 0; i < 6; i++)
319 dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
320 char2hex(mac[i * 3 + 1]);
323 static int __init ar7_register_devices(void)
327 #ifdef CONFIG_SERIAL_8250
329 static struct uart_port uart_port[2];
331 memset(uart_port, 0, sizeof(struct uart_port) * 2);
333 uart_port[0].type = PORT_AR7;
334 uart_port[0].line = 0;
335 uart_port[0].irq = AR7_IRQ_UART0;
336 uart_port[0].uartclk = ar7_bus_freq() / 2;
337 uart_port[0].iotype = UPIO_MEM;
338 uart_port[0].mapbase = AR7_REGS_UART0;
339 uart_port[0].membase = ioremap(uart_port[0].mapbase, 256);
340 uart_port[0].regshift = 2;
341 res = early_serial_setup(&uart_port[0]);
346 /* Only TNETD73xx have a second serial port */
347 if (ar7_has_second_uart()) {
348 uart_port[1].type = PORT_AR7;
349 uart_port[1].line = 1;
350 uart_port[1].irq = AR7_IRQ_UART1;
351 uart_port[1].uartclk = ar7_bus_freq() / 2;
352 uart_port[1].iotype = UPIO_MEM;
353 uart_port[1].mapbase = UR8_REGS_UART1;
354 uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
355 uart_port[1].regshift = 2;
356 res = early_serial_setup(&uart_port[1]);
361 #else /* !CONFIG_SERIAL_8250 */
363 uart_data[0].uartclk = ar7_bus_freq() / 2;
364 uart_data[1].uartclk = uart_data[0].uartclk;
366 /* Only TNETD73xx have a second serial port */
367 if (ar7_has_second_uart())
368 uart.dev.platform_data = uart_data;
370 res = platform_device_register(&uart);
374 #endif /* CONFIG_SERIAL_8250 */
376 res = platform_device_register(&physmap_flash);
380 res = platform_device_register(&vlynq_low);
384 ar7_device_disable(vlynq_low_data.reset_bit);
385 if (ar7_has_high_vlynq()) {
386 ar7_device_disable(vlynq_high_data.reset_bit);
387 res = platform_device_register(&vlynq_high);
392 if (ar7_has_high_cpmac()) {
393 cpmac_get_mac(1, cpmac_high_data.dev_addr);
394 res = platform_device_register(&cpmac_high);
398 cpmac_low_data.phy_mask = 0xffffffff;
401 cpmac_get_mac(0, cpmac_low_data.dev_addr);
402 res = platform_device_register(&cpmac_low);
408 arch_initcall(ar7_register_devices);