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>
29 char *board_config, *radio_config;
31 static u8 *find_board_config(char *flash_limit)
36 for (addr = (char *) (flash_limit - 0x1000);
37 addr >= (char *) (flash_limit - 0x30000);
40 if ( *(int *)addr == 0x35333131) {
41 /* config magic found */
48 printk("WARNING: No board configuration data found!\n");
55 static u8 *find_radio_config(char *flash_limit, char *board_config)
61 * Now find the start of Radio Configuration data, using heuristics:
62 * Search forward from Board Configuration data by 0x1000 bytes
63 * at a time until we find non-0xffffffff.
66 for (radio_config = (u32) board_config + 0x1000;
67 (radio_config < (u32) flash_limit);
68 radio_config += 0x1000) {
69 if (*(int *)radio_config != 0xffffffff) {
75 #ifdef CONFIG_ATHEROS_AR5315
76 if (!dataFound) { /* AR2316 relocates radio config to new location */
77 for (radio_config = (u32) board_config + 0xf8;
78 (radio_config < (u32) flash_limit - 0x1000 + 0xf8);
79 radio_config += 0x1000) {
80 if (*(int *)radio_config != 0xffffffff) {
89 printk("Could not find Radio Configuration data\n");
93 return (u8 *) radio_config;
96 int __init ar531x_find_config(char *flash_limit)
98 unsigned int rcfg_size;
101 /* Copy the board and radio data to RAM, because with the new
102 * spiflash driver, accessing the mapped memory directly is no
105 bcfg = find_board_config(flash_limit);
109 board_config = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
110 memcpy(board_config, bcfg, 0x100);
112 /* Radio config starts 0x100 bytes after board config, regardless
113 * of what the physical layout on the flash chip looks like */
115 rcfg = find_radio_config(flash_limit, bcfg);
119 radio_config = board_config + 0x100 + ((rcfg - bcfg) & 0xfff);
120 printk("Radio config found at offset 0x%x(0x%x)\n", rcfg - bcfg, radio_config - board_config);
121 rcfg_size = BOARD_CONFIG_BUFSZ - ((rcfg - bcfg) & (BOARD_CONFIG_BUFSZ - 1));
122 memcpy(radio_config, rcfg, rcfg_size);
127 void __init serial_setup(unsigned long mapbase, unsigned int uartclk)
131 memset(&s, 0, sizeof(s));
133 s.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
135 s.irq = AR531X_MISC_IRQ_UART0;
139 s.membase = (void __iomem *)s.mapbase;
141 early_serial_setup(&s);
144 void __init plat_mem_setup(void)
146 DO_AR5312(ar5312_plat_setup();)
147 DO_AR5315(ar5315_plat_setup();)
149 /* Disable data watchpoints */
150 write_c0_watchlo0(0);
153 const char *get_system_type(void)
155 switch (mips_machtype) {
156 #ifdef CONFIG_ATHEROS_AR5312
157 case MACH_ATHEROS_AR5312:
158 return "Atheros AR5312\n";
160 case MACH_ATHEROS_AR2312:
161 return "Atheros AR2312\n";
163 case MACH_ATHEROS_AR2313:
164 return "Atheros AR2313\n";
166 #ifdef CONFIG_ATHEROS_AR5315
167 case MACH_ATHEROS_AR2315:
168 return "Atheros AR2315\n";
169 case MACH_ATHEROS_AR2316:
170 return "Atheros AR2316\n";
171 case MACH_ATHEROS_AR2317:
172 return "Atheros AR2317\n";
173 case MACH_ATHEROS_AR2318:
174 return "Atheros AR2318\n";
177 return "Atheros (unknown)";
180 void __init plat_timer_setup(struct irqaction *irq)
184 /* Usually irq is timer_irqaction (timer_interrupt) */
185 setup_irq(AR531X_IRQ_CPU_CLOCK, irq);
187 /* to generate the first CPU timer interrupt */
188 count = read_c0_count();
189 write_c0_compare(count + 1000);