2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
7 * Copyright (C) 2006 FON Technology, SL.
8 * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
9 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
13 * Platform devices for Atheros SoCs
16 #include <linux/autoconf.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/platform_device.h>
22 #include <linux/kernel.h>
23 #include <linux/serial.h>
24 #include <linux/serial_core.h>
25 #include <asm/bootinfo.h>
26 #include <asm/irq_cpu.h>
30 char *board_config, *radio_config;
32 extern int early_serial_setup(struct uart_port *port);
34 static u8 *find_board_config(char *flash_limit)
39 for (addr = (char *) (flash_limit - 0x1000);
40 addr >= (char *) (flash_limit - 0x30000);
43 if ( *(int *)addr == 0x35333131) {
44 /* config magic found */
51 printk("WARNING: No board configuration data found!\n");
58 static u8 *find_radio_config(char *flash_limit, char *board_config)
64 * Now find the start of Radio Configuration data, using heuristics:
65 * Search forward from Board Configuration data by 0x1000 bytes
66 * at a time until we find non-0xffffffff.
69 for (radio_config = (u32) board_config + 0x1000;
70 (radio_config < (u32) flash_limit);
71 radio_config += 0x1000) {
72 if (*(int *)radio_config != 0xffffffff) {
78 #ifdef CONFIG_ATHEROS_AR5315
79 if (!dataFound) { /* AR2316 relocates radio config to new location */
80 for (radio_config = (u32) board_config + 0xf8;
81 (radio_config < (u32) flash_limit - 0x1000 + 0xf8);
82 radio_config += 0x1000) {
83 if (*(int *)radio_config != 0xffffffff) {
92 printk("Could not find Radio Configuration data\n");
96 return (u8 *) radio_config;
99 int __init ar531x_find_config(char *flash_limit)
101 unsigned int rcfg_size;
104 /* Copy the board and radio data to RAM, because with the new
105 * spiflash driver, accessing the mapped memory directly is no
108 bcfg = find_board_config(flash_limit);
112 board_config = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
113 memcpy(board_config, bcfg, 0x100);
115 /* Radio config starts 0x100 bytes after board config, regardless
116 * of what the physical layout on the flash chip looks like */
118 rcfg = find_radio_config(flash_limit, bcfg);
122 radio_config = board_config + 0x100 + ((rcfg - bcfg) & 0xfff);
123 printk("Radio config found at offset 0x%x(0x%x)\n", rcfg - bcfg, radio_config - board_config);
124 rcfg_size = BOARD_CONFIG_BUFSZ - ((rcfg - bcfg) & (BOARD_CONFIG_BUFSZ - 1));
125 memcpy(radio_config, rcfg, rcfg_size);
130 void __init serial_setup(unsigned long mapbase, unsigned int uartclk)
134 memset(&s, 0, sizeof(s));
136 s.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
138 s.irq = AR531X_MISC_IRQ_UART0;
142 s.membase = (void __iomem *)s.mapbase;
144 early_serial_setup(&s);
147 void __init plat_mem_setup(void)
149 DO_AR5312(ar5312_plat_setup();)
150 DO_AR5315(ar5315_plat_setup();)
152 /* Disable data watchpoints */
153 write_c0_watchlo0(0);
156 const char *get_system_type(void)
158 switch (mips_machtype) {
159 #ifdef CONFIG_ATHEROS_AR5312
160 case MACH_ATHEROS_AR5312:
161 return "Atheros AR5312";
163 case MACH_ATHEROS_AR2312:
164 return "Atheros AR2312";
166 case MACH_ATHEROS_AR2313:
167 return "Atheros AR2313";
169 #ifdef CONFIG_ATHEROS_AR5315
170 case MACH_ATHEROS_AR2315:
171 return "Atheros AR2315";
172 case MACH_ATHEROS_AR2316:
173 return "Atheros AR2316";
174 case MACH_ATHEROS_AR2317:
175 return "Atheros AR2317";
176 case MACH_ATHEROS_AR2318:
177 return "Atheros AR2318";
180 return "Atheros (unknown)";
183 void __init plat_timer_setup(struct irqaction *irq)
187 /* Usually irq is timer_irqaction (timer_interrupt) */
188 setup_irq(AR531X_IRQ_CPU_CLOCK, irq);
190 /* to generate the first CPU timer interrupt */
191 count = read_c0_count();
192 write_c0_compare(count + 1000);
195 asmlinkage void plat_irq_dispatch(void)
197 DO_AR5312(ar5312_irq_dispatch();)
198 DO_AR5315(ar5315_irq_dispatch();)
201 void __init arch_init_irq(void)
203 clear_c0_status(ST0_IM);
206 /* Initialize interrupt controllers */
207 DO_AR5312(ar5312_misc_intr_init(AR531X_MISC_IRQ_BASE);)
208 DO_AR5315(ar5315_misc_intr_init(AR531X_MISC_IRQ_BASE);)