root/src/linux/ar531x/linux-2.6.23/arch/mips/atheros/ar5315/board.c

Revision 12400, 8.9 kB (checked in by BrainSlayer, 5 months ago)

more flexible EOC5610 partition layout, small performance increase by module remapping, lzma decoder speed improvements

Line 
1 /*
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
4  * for more details.
5  *
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>
10  */
11
12 /*
13  * Platform devices for Atheros SoCs
14  */
15
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/delay.h>
24 #include <linux/reboot.h>
25 #include <asm/bootinfo.h>
26 #include <asm/reboot.h>
27 #include <asm/time.h>
28 #include <asm/irq.h>
29 #include <asm/io.h>
30 #include "ar531x.h"
31
32 static int is_5315 = 0;
33
34 static struct resource ar5315_eth_res[] = {
35         {
36                 .name = "eth0_membase",
37                 .flags = IORESOURCE_MEM,
38                 .start = AR5315_ENET0,
39                 .end = AR5315_ENET0 + 0x2000,
40         },
41         {
42                 .name = "eth0_irq",
43                 .flags = IORESOURCE_IRQ,
44                 .start = AR5315_IRQ_ENET0_INTRS,
45                 .end = AR5315_IRQ_ENET0_INTRS,
46         },
47 };
48
49 static struct ar531x_eth ar5315_eth_data = {
50         .phy = 1,
51         .mac = 0,
52         .reset_base = AR5315_RESET,
53         .reset_mac = AR5315_RESET_ENET0,
54         .reset_phy = AR5315_RESET_EPHY0,
55         .phy_base = AR5315_ENET0
56 };
57
58 static struct platform_device ar5315_eth = {
59         .id = 0,
60         .name = "ar531x-eth",
61         .dev.platform_data = &ar5315_eth_data,
62         .resource = ar5315_eth_res,
63         .num_resources = ARRAY_SIZE(ar5315_eth_res)
64 };
65
66 static struct platform_device ar5315_wmac = {
67         .id = 0,
68         .name = "ar531x-wmac",
69         /* FIXME: add resources */
70 };
71
72 static struct resource ar5315_spiflash_res[] = {
73         {
74                 .name = "flash_base",
75                 .flags = IORESOURCE_MEM,
76                 .start = KSEG1ADDR(AR5315_SPI_READ),
77                 .end = KSEG1ADDR(AR5315_SPI_READ) + 0x800000,
78         },
79         {
80                 .name = "flash_regs",
81                 .flags = IORESOURCE_MEM,
82                 .start = 0x11300000,
83                 .end = 0x11300012,
84         },
85 };
86
87 static struct platform_device ar5315_spiflash = {
88         .id = 0,
89         .name = "spiflash",
90         .resource = ar5315_spiflash_res,
91         .num_resources = ARRAY_SIZE(ar5315_spiflash_res)
92 };
93
94 static __initdata struct platform_device *ar5315_devs[4];
95
96
97
98 static void *flash_regs;
99
100 static inline __u32 spiflash_regread32(int reg)
101 {
102         volatile __u32 *data = (__u32 *)(flash_regs + reg);
103
104         return (*data);
105 }
106
107 static inline void spiflash_regwrite32(int reg, __u32 data)
108 {
109         volatile __u32 *addr = (__u32 *)(flash_regs + reg);
110
111         *addr = data;
112 }
113
114 #define SPI_FLASH_CTL      0x00
115 #define SPI_FLASH_OPCODE   0x04
116 #define SPI_FLASH_DATA     0x08
117
118 static __u8 spiflash_probe(void)
119 {
120          __u32 reg;
121
122         do {
123                 reg = spiflash_regread32(SPI_FLASH_CTL);
124         } while (reg & SPI_CTL_BUSY);
125
126         spiflash_regwrite32(SPI_FLASH_OPCODE, 0xab);
127
128         reg = (reg & ~SPI_CTL_TX_RX_CNT_MASK) | 4 |
129                 (1 << 4) | SPI_CTL_START;
130         reg = (reg & ~SPI_CTL_CLK_SEL_MASK);
131         reg = (reg | (1 << 24)); // use slower clock timing (but still faster than original) since accton mounts crappy spi flash chips
132        
133
134         spiflash_regwrite32(SPI_FLASH_CTL, reg);
135  
136         do {
137                 reg = spiflash_regread32(SPI_FLASH_CTL);
138         } while (reg & SPI_CTL_BUSY);
139
140         reg = (__u32) spiflash_regread32(SPI_FLASH_DATA);
141         reg &= 0xff;
142
143         return (u8) reg;
144 }
145
146
147 #define STM_8MBIT_SIGNATURE     0x13
148 #define STM_16MBIT_SIGNATURE    0x14
149 #define STM_32MBIT_SIGNATURE    0x15
150 #define STM_64MBIT_SIGNATURE    0x16
151 #define STM_128MBIT_SIGNATURE   0x17
152
153
154 static char __init *ar5315_flash_limit(void)
155 {
156         u8 sig;
157         u32 flash_size = 0;
158
159         /* probe the flash chip size */
160         flash_regs = ioremap_nocache(ar5315_spiflash_res[1].start, ar5315_spiflash_res[1].end - ar5315_spiflash_res[1].start);
161         sig = spiflash_probe();
162         iounmap(flash_regs);
163
164         switch(sig) {
165                 case STM_8MBIT_SIGNATURE:
166                         flash_size = 0x00100000;
167                         break;
168                 case STM_16MBIT_SIGNATURE:
169                         flash_size = 0x00200000;
170                         break;
171                 case STM_32MBIT_SIGNATURE:
172                         flash_size = 0x00400000;
173                         break;
174                 case STM_64MBIT_SIGNATURE:
175                         flash_size = 0x00800000;
176                         break;
177                 case STM_128MBIT_SIGNATURE:
178                         flash_size = 0x01000000;
179                         break;
180         }
181
182         ar5315_spiflash_res[0].end = ar5315_spiflash_res[0].start + flash_size;
183         return (char *) ar5315_spiflash_res[0].end;
184 }
185
186 int __init ar5315_init_devices(void)
187 {
188         struct ar531x_config *config;
189         struct ar531x_boarddata *bcfg;
190         int dev = 0;
191
192         if (!is_5315)
193                 return 0;
194
195         /* Find board configuration */
196         ar531x_find_config(ar5315_flash_limit());
197         bcfg = (struct ar531x_boarddata *) board_config;
198
199
200         config = (struct ar531x_config *) kzalloc(sizeof(struct ar531x_config), GFP_KERNEL);
201         config->board = board_config;
202         config->radio = radio_config;
203         config->unit = 0;
204         config->tag = (u_int16_t) (sysRegRead(AR5315_SREV) & AR5315_REV_CHIP);
205        
206         ar5315_eth_data.board_config = board_config;
207         ar5315_eth_data.macaddr = bcfg->enet0Mac;
208         ar5315_wmac.dev.platform_data = config;
209        
210         ar5315_devs[dev++] = &ar5315_eth;
211         ar5315_devs[dev++] = &ar5315_wmac;
212         ar5315_devs[dev++] = &ar5315_spiflash;
213                        
214
215         return platform_add_devices(ar5315_devs, dev);
216 }
217
218 static void ar5315_halt(void)
219 {
220          while (1);
221 }
222
223 static void ar5315_power_off(void)
224 {
225          ar5315_halt();
226 }
227
228
229 static void ar5315_restart(char *command)
230 {
231         unsigned int reg;
232
233         void (*mips_reset_vec)(void) = (void *) 0xbfc00000;
234
235
236         /* reset the system */
237         sysRegWrite(AR5315_COLD_RESET,AR5317_RESET_SYSTEM);
238         mdelay(100);
239         /*
240          * Cold reset does not work on the AR2315/6, use the GPIO reset bits a workaround.
241          */
242         reg = sysRegRead(AR5315_GPIO_DO);
243         reg &= ~(1 << AR5315_RESET_GPIO);
244         sysRegWrite(AR5315_GPIO_DO, reg);
245         (void)sysRegRead(AR5315_GPIO_DO); /* flush write to hardware */
246
247         /* give it some time to attempt a gpio based hardware reset
248          * (atheros reference design workaround) */
249         mdelay(100);
250        
251         /* now do GPIO 0 reset, known to be used on Seano devices */
252         reg = sysRegRead(AR5315_GPIO_DO);
253         reg &= ~(1 << 0);
254         sysRegWrite(AR5315_GPIO_DO, reg);
255         (void)sysRegRead(AR5315_GPIO_DO); /* flush write to hardware */
256
257         /* give it some time to attempt a gpio based hardware reset
258          * (atheros reference design workaround) */
259         mdelay(100);
260
261         /* Some boards (e.g. Senao EOC-2610) don't implement the reset logic
262          * workaround as in the atheros reference design. Attempt to jump
263          * to the mips reset location - the boot loader might be able to recover
264          * the system on its own
265          */
266
267         mips_reset_vec();
268 }
269
270
271 /*
272  * This table is indexed by bits 5..4 of the CLOCKCTL1 register
273  * to determine the predevisor value.
274  */
275 static int __initdata CLOCKCTL1_PREDIVIDE_TABLE[4] = {
276     1,
277     2,
278     4,
279     5
280 };
281
282 static int __initdata PLLC_DIVIDE_TABLE[5] = {
283     2,
284     3,
285     4,
286     6,
287     3
288 };
289
290 static unsigned int __init
291 ar5315_sys_clk(unsigned int clockCtl)
292 {
293     unsigned int pllcCtrl,cpuDiv;
294     unsigned int pllcOut,refdiv,fdiv,divby2;
295         unsigned int clkDiv;
296
297     pllcCtrl = sysRegRead(AR5315_PLLC_CTL);
298     refdiv = (pllcCtrl & PLLC_REF_DIV_M) >> PLLC_REF_DIV_S;
299     refdiv = CLOCKCTL1_PREDIVIDE_TABLE[refdiv];
300     fdiv = (pllcCtrl & PLLC_FDBACK_DIV_M) >> PLLC_FDBACK_DIV_S;
301     divby2 = (pllcCtrl & PLLC_ADD_FDBACK_DIV_M) >> PLLC_ADD_FDBACK_DIV_S;
302     divby2 += 1;
303     pllcOut = (40000000/refdiv)*(2*divby2)*fdiv;
304
305
306     /* clkm input selected */
307         switch(clockCtl & CPUCLK_CLK_SEL_M) {
308                 case 0:
309                 case 1:
310                         clkDiv = PLLC_DIVIDE_TABLE[(pllcCtrl & PLLC_CLKM_DIV_M) >> PLLC_CLKM_DIV_S];
311                         break;
312                 case 2:
313                         clkDiv = PLLC_DIVIDE_TABLE[(pllcCtrl & PLLC_CLKC_DIV_M) >> PLLC_CLKC_DIV_S];
314                         break;
315                 default:
316                         pllcOut = 40000000;
317                         clkDiv = 1;
318                         break;
319         }
320         cpuDiv = (clockCtl & CPUCLK_CLK_DIV_M) >> CPUCLK_CLK_DIV_S; 
321         cpuDiv = cpuDiv * 2 ?: 1;
322         return (pllcOut/(clkDiv * cpuDiv));
323 }
324                
325 static inline unsigned int ar5315_cpu_frequency(void)
326 {
327     return ar5315_sys_clk(sysRegRead(AR5315_CPUCLK));
328 }
329
330 static inline unsigned int ar5315_apb_frequency(void)
331 {
332     return ar5315_sys_clk(sysRegRead(AR5315_AMBACLK));
333 }
334
335 static void __init ar5315_time_init(void)
336 {
337         mips_hpt_frequency = ar5315_cpu_frequency() / 2;
338 }
339
340 void __init ar5315_prom_init(void)
341 {
342         u32 memsize, memcfg, devid;
343
344         is_5315 = 1;
345         memcfg = sysRegRead(AR5315_MEM_CFG);
346         memsize   = 1 + ((memcfg & SDRAM_DATA_WIDTH_M) >> SDRAM_DATA_WIDTH_S);
347         memsize <<= 1 + ((memcfg & SDRAM_COL_WIDTH_M) >> SDRAM_COL_WIDTH_S);
348         memsize <<= 1 + ((memcfg & SDRAM_ROW_WIDTH_M) >> SDRAM_ROW_WIDTH_S);
349         memsize <<= 3;
350         add_memory_region(0, memsize, BOOT_MEM_RAM);
351
352         /* Detect the hardware based on the device ID */
353         devid = sysRegRead(AR5315_SREV) & AR5315_REV_CHIP;
354         printk(KERN_INFO "mips devid = %X\n",devid);
355         switch(devid) {
356                 case 0x90:
357                 case 0x91:
358                         mips_machtype = MACH_ATHEROS_AR2317;
359                         break;
360                 default:
361                         mips_machtype = MACH_ATHEROS_AR2315;
362                         break;
363         }
364 }
365
366 void __init ar5315_plat_setup(void)
367 {
368         unsigned int config = read_c0_config();
369
370         /* Clear any lingering AHB errors */
371         write_c0_config(config & ~0x3);
372         sysRegWrite(AR5315_AHB_ERR0,AHB_ERROR_DET);
373         sysRegRead(AR5315_AHB_ERR1);
374         sysRegWrite(AR5315_WDC, WDC_IGNORE_EXPIRATION);
375
376         board_time_init = ar5315_time_init;
377
378         _machine_restart = ar5315_restart;
379         _machine_halt = ar5315_halt;
380         pm_power_off = ar5315_power_off;
381
382         serial_setup(KSEG1ADDR(AR5315_UART0), ar5315_apb_frequency());
383 }
384
385 arch_initcall(ar5315_init_devices);
Note: See TracBrowser for help on using the browser.