blob: 448e6aab73ac86e0be370a5cdca46d4d66ec58eb [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/kernel/setup.c
3 * Based on:
4 * Author:
5 *
6 * Created:
7 * Description:
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/delay.h>
31#include <linux/console.h>
32#include <linux/bootmem.h>
33#include <linux/seq_file.h>
34#include <linux/cpu.h>
35#include <linux/module.h>
Bryan Wu1394f032007-05-06 14:50:22 -070036#include <linux/tty.h>
37
38#include <linux/ext2_fs.h>
39#include <linux/cramfs_fs.h>
40#include <linux/romfs_fs.h>
41
Robin Getz3bebca22007-10-10 23:55:26 +080042#include <asm/cplb.h>
Bryan Wu1394f032007-05-06 14:50:22 -070043#include <asm/cacheflush.h>
44#include <asm/blackfin.h>
45#include <asm/cplbinit.h>
Bernd Schmidt7adfb582007-06-21 11:34:16 +080046#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070047
Mike Frysingera9c59c22007-05-21 18:09:32 +080048u16 _bfin_swrst;
49
Bryan Wu1394f032007-05-06 14:50:22 -070050unsigned long memory_start, memory_end, physical_mem_end;
51unsigned long reserved_mem_dcache_on;
52unsigned long reserved_mem_icache_on;
53EXPORT_SYMBOL(memory_start);
54EXPORT_SYMBOL(memory_end);
55EXPORT_SYMBOL(physical_mem_end);
56EXPORT_SYMBOL(_ramend);
57
58#ifdef CONFIG_MTD_UCLINUX
59unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
60unsigned long _ebss;
61EXPORT_SYMBOL(memory_mtd_end);
62EXPORT_SYMBOL(memory_mtd_start);
63EXPORT_SYMBOL(mtd_size);
64#endif
65
Mike Frysinger5e10b4a2007-06-11 16:44:09 +080066char __initdata command_line[COMMAND_LINE_SIZE];
Bryan Wu1394f032007-05-06 14:50:22 -070067
Bryan Wu1394f032007-05-06 14:50:22 -070068void __init bf53x_cache_init(void)
69{
Robin Getz3bebca22007-10-10 23:55:26 +080070#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
Bryan Wu1394f032007-05-06 14:50:22 -070071 generate_cpl_tables();
72#endif
73
Robin Getz3bebca22007-10-10 23:55:26 +080074#ifdef CONFIG_BFIN_ICACHE
Bryan Wu1394f032007-05-06 14:50:22 -070075 bfin_icache_init();
76 printk(KERN_INFO "Instruction Cache Enabled\n");
77#endif
78
Robin Getz3bebca22007-10-10 23:55:26 +080079#ifdef CONFIG_BFIN_DCACHE
Bryan Wu1394f032007-05-06 14:50:22 -070080 bfin_dcache_init();
81 printk(KERN_INFO "Data Cache Enabled"
Robin Getz3bebca22007-10-10 23:55:26 +080082# if defined CONFIG_BFIN_WB
Bryan Wu1394f032007-05-06 14:50:22 -070083 " (write-back)"
Robin Getz3bebca22007-10-10 23:55:26 +080084# elif defined CONFIG_BFIN_WT
Bryan Wu1394f032007-05-06 14:50:22 -070085 " (write-through)"
86# endif
87 "\n");
88#endif
89}
90
Mike Frysinger52a07812007-06-11 15:31:30 +080091void __init bf53x_relocate_l1_mem(void)
Bryan Wu1394f032007-05-06 14:50:22 -070092{
93 unsigned long l1_code_length;
94 unsigned long l1_data_a_length;
95 unsigned long l1_data_b_length;
96
97 l1_code_length = _etext_l1 - _stext_l1;
98 if (l1_code_length > L1_CODE_LENGTH)
99 l1_code_length = L1_CODE_LENGTH;
100 /* cannot complain as printk is not available as yet.
101 * But we can continue booting and complain later!
102 */
103
104 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
105 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
106
107 l1_data_a_length = _ebss_l1 - _sdata_l1;
108 if (l1_data_a_length > L1_DATA_A_LENGTH)
109 l1_data_a_length = L1_DATA_A_LENGTH;
110
111 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
112 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
113
114 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
115 if (l1_data_b_length > L1_DATA_B_LENGTH)
116 l1_data_b_length = L1_DATA_B_LENGTH;
117
118 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
119 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
120 l1_data_a_length, l1_data_b_length);
121
122}
123
124/*
125 * Initial parsing of the command line. Currently, we support:
126 * - Controlling the linux memory size: mem=xxx[KMG]
127 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
128 * $ -> reserved memory is dcacheable
129 * # -> reserved memory is icacheable
130 */
131static __init void parse_cmdline_early(char *cmdline_p)
132{
133 char c = ' ', *to = cmdline_p;
134 unsigned int memsize;
135 for (;;) {
136 if (c == ' ') {
137
138 if (!memcmp(to, "mem=", 4)) {
139 to += 4;
140 memsize = memparse(to, &to);
141 if (memsize)
142 _ramend = memsize;
143
144 } else if (!memcmp(to, "max_mem=", 8)) {
145 to += 8;
146 memsize = memparse(to, &to);
147 if (memsize) {
148 physical_mem_end = memsize;
149 if (*to != ' ') {
150 if (*to == '$'
151 || *(to + 1) == '$')
152 reserved_mem_dcache_on =
153 1;
154 if (*to == '#'
155 || *(to + 1) == '#')
156 reserved_mem_icache_on =
157 1;
158 }
159 }
160 }
161
162 }
163 c = *(to++);
164 if (!c)
165 break;
166 }
167}
168
169void __init setup_arch(char **cmdline_p)
170{
171 int bootmap_size;
172 unsigned long l1_length, sclk, cclk;
173#ifdef CONFIG_MTD_UCLINUX
174 unsigned long mtd_phys = 0;
175#endif
176
Michael Hennerich6e537e92007-05-21 18:09:20 +0800177#ifdef CONFIG_DUMMY_CONSOLE
178 conswitchp = &dummy_con;
179#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700180 cclk = get_cclk();
181 sclk = get_sclk();
182
Mike Frysinger1aafd902007-07-25 11:19:14 +0800183#if !defined(CONFIG_BFIN_KERNEL_CLOCK)
184 if (ANOMALY_05000273 && cclk == sclk)
Bryan Wu1394f032007-05-06 14:50:22 -0700185 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
186#endif
187
Mike Frysinger1aafd902007-07-25 11:19:14 +0800188#ifdef BF561_FAMILY
189 if (ANOMALY_05000266) {
190 bfin_read_IMDMA_D0_IRQ_STATUS();
191 bfin_read_IMDMA_D1_IRQ_STATUS();
192 }
Bryan Wu1394f032007-05-06 14:50:22 -0700193#endif
194
195#ifdef DEBUG_SERIAL_EARLY_INIT
196 bfin_console_init(); /* early console registration */
197 /* this give a chance to get printk() working before crash. */
198#endif
199
Robin Getz669b7922007-06-21 16:34:08 +0800200 printk(KERN_INFO "Hardware Trace ");
201 if (bfin_read_TBUFCTL() & 0x1 )
202 printk("Active ");
203 else
204 printk("Off ");
205 if (bfin_read_TBUFCTL() & 0x2)
206 printk("and Enabled\n");
207 else
208 printk("and Disabled\n");
209
210
Bryan Wu1394f032007-05-06 14:50:22 -0700211#if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
212 /* we need to initialize the Flashrom device here since we might
213 * do things with flash early on in the boot
214 */
215 flash_probe();
216#endif
217
218#if defined(CONFIG_CMDLINE_BOOL)
Bryan Wu1394f032007-05-06 14:50:22 -0700219 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
220 command_line[sizeof(command_line) - 1] = 0;
221#endif
222
223 /* Keep a copy of command line */
224 *cmdline_p = &command_line[0];
225 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
Mike Frysinger5e10b4a2007-06-11 16:44:09 +0800226 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
Bryan Wu1394f032007-05-06 14:50:22 -0700227
228 /* setup memory defaults from the user config */
229 physical_mem_end = 0;
230 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
231
232 parse_cmdline_early(&command_line[0]);
233
234 if (physical_mem_end == 0)
235 physical_mem_end = _ramend;
236
237 /* by now the stack is part of the init task */
238 memory_end = _ramend - DMA_UNCACHED_REGION;
239
240 _ramstart = (unsigned long)__bss_stop;
241 memory_start = PAGE_ALIGN(_ramstart);
242
243#if defined(CONFIG_MTD_UCLINUX)
244 /* generic memory mapped MTD driver */
245 memory_mtd_end = memory_end;
246
247 mtd_phys = _ramstart;
248 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
249
250# if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
251 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
252 mtd_size =
253 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
254# endif
255
256# if defined(CONFIG_CRAMFS)
257 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
258 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
259# endif
260
261# if defined(CONFIG_ROMFS_FS)
262 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
263 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
264 mtd_size =
265 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
Robin Getz3bebca22007-10-10 23:55:26 +0800266# if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700267 /* Due to a Hardware Anomaly we need to limit the size of usable
268 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
269 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
270 */
271# if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
272 if (memory_end >= 56 * 1024 * 1024)
273 memory_end = 56 * 1024 * 1024;
274# else
275 if (memory_end >= 60 * 1024 * 1024)
276 memory_end = 60 * 1024 * 1024;
277# endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
278# endif /* ANOMALY_05000263 */
279# endif /* CONFIG_ROMFS_FS */
280
281 memory_end -= mtd_size;
282
283 if (mtd_size == 0) {
284 console_init();
285 panic("Don't boot kernel without rootfs attached.\n");
286 }
287
288 /* Relocate MTD image to the top of memory after the uncached memory area */
289 dma_memcpy((char *)memory_end, __bss_stop, mtd_size);
290
291 memory_mtd_start = memory_end;
292 _ebss = memory_mtd_start; /* define _ebss for compatible */
293#endif /* CONFIG_MTD_UCLINUX */
294
Robin Getz3bebca22007-10-10 23:55:26 +0800295#if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700296 /* Due to a Hardware Anomaly we need to limit the size of usable
297 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
298 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
299 */
300#if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
301 if (memory_end >= 56 * 1024 * 1024)
302 memory_end = 56 * 1024 * 1024;
303#else
304 if (memory_end >= 60 * 1024 * 1024)
305 memory_end = 60 * 1024 * 1024;
306#endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
307 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
308#endif /* ANOMALY_05000263 */
309
310#if !defined(CONFIG_MTD_UCLINUX)
311 memory_end -= SIZE_4K; /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
312#endif
313 init_mm.start_code = (unsigned long)_stext;
314 init_mm.end_code = (unsigned long)_etext;
315 init_mm.end_data = (unsigned long)_edata;
316 init_mm.brk = (unsigned long)0;
317
318 init_leds();
319
320 printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
Jie Zhangde3025f2007-06-25 18:04:12 +0800321 if (bfin_compiled_revid() == 0xffff)
322 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
323 else if (bfin_compiled_revid() == -1)
324 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
325 else
326 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
327 if (bfin_revid() != bfin_compiled_revid()) {
328 if (bfin_compiled_revid() == -1)
329 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
330 bfin_revid());
331 else if (bfin_compiled_revid() != 0xffff)
332 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
333 bfin_compiled_revid(), bfin_revid());
334 }
Bryan Wu1394f032007-05-06 14:50:22 -0700335 if (bfin_revid() < SUPPORTED_REVID)
336 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
337 CPU, bfin_revid());
338 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
339
340 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu Mhz System Clock\n",
341 cclk / 1000000, sclk / 1000000);
342
Mike Frysinger1aafd902007-07-25 11:19:14 +0800343 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
Bryan Wu1394f032007-05-06 14:50:22 -0700344 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700345
346 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
347 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
348
349 printk(KERN_INFO "Memory map:\n"
350 KERN_INFO " text = 0x%p-0x%p\n"
Robin Getz86b73c82007-06-21 11:34:16 +0800351 KERN_INFO " rodata = 0x%p-0x%p\n"
Bryan Wu1394f032007-05-06 14:50:22 -0700352 KERN_INFO " data = 0x%p-0x%p\n"
Robin Getz86b73c82007-06-21 11:34:16 +0800353 KERN_INFO " stack = 0x%p-0x%p\n"
354 KERN_INFO " init = 0x%p-0x%p\n"
Bryan Wu1394f032007-05-06 14:50:22 -0700355 KERN_INFO " bss = 0x%p-0x%p\n"
356 KERN_INFO " available = 0x%p-0x%p\n"
357#ifdef CONFIG_MTD_UCLINUX
358 KERN_INFO " rootfs = 0x%p-0x%p\n"
359#endif
360#if DMA_UNCACHED_REGION > 0
361 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
362#endif
363 , _stext, _etext,
Robin Getz86b73c82007-06-21 11:34:16 +0800364 __start_rodata, __end_rodata,
Bryan Wu1394f032007-05-06 14:50:22 -0700365 _sdata, _edata,
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800366 (void *)&init_thread_union, (void *)((int)(&init_thread_union) + 0x2000),
Robin Getz86b73c82007-06-21 11:34:16 +0800367 __init_begin, __init_end,
Bryan Wu1394f032007-05-06 14:50:22 -0700368 __bss_start, __bss_stop,
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800369 (void *)_ramstart, (void *)memory_end
Bryan Wu1394f032007-05-06 14:50:22 -0700370#ifdef CONFIG_MTD_UCLINUX
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800371 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
Bryan Wu1394f032007-05-06 14:50:22 -0700372#endif
373#if DMA_UNCACHED_REGION > 0
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800374 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
Bryan Wu1394f032007-05-06 14:50:22 -0700375#endif
376 );
377
378 /*
379 * give all the memory to the bootmap allocator, tell it to put the
380 * boot mem_map at the start of memory
381 */
382 bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
383 PAGE_OFFSET >> PAGE_SHIFT,
384 memory_end >> PAGE_SHIFT);
385 /*
386 * free the usable memory, we have to make sure we do not free
387 * the bootmem bitmap so we then reserve it after freeing it :-)
388 */
389 free_bootmem(memory_start, memory_end - memory_start);
390
391 reserve_bootmem(memory_start, bootmap_size);
392 /*
393 * get kmalloc into gear
394 */
395 paging_init();
396
397 /* check the size of the l1 area */
398 l1_length = _etext_l1 - _stext_l1;
399 if (l1_length > L1_CODE_LENGTH)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800400 panic("L1 code memory overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700401
402 l1_length = _ebss_l1 - _sdata_l1;
403 if (l1_length > L1_DATA_A_LENGTH)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800404 panic("L1 data memory overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700405
Mike Frysingera9c59c22007-05-21 18:09:32 +0800406 _bfin_swrst = bfin_read_SWRST();
Mike Frysingera9c59c22007-05-21 18:09:32 +0800407
Bernd Schmidt7adfb582007-06-21 11:34:16 +0800408 /* Copy atomic sequences to their fixed location, and sanity check that
409 these locations are the ones that we advertise to userspace. */
410 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
411 FIXED_CODE_END - FIXED_CODE_START);
412 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
413 != SIGRETURN_STUB - FIXED_CODE_START);
414 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
415 != ATOMIC_XCHG32 - FIXED_CODE_START);
416 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
417 != ATOMIC_CAS32 - FIXED_CODE_START);
418 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
419 != ATOMIC_ADD32 - FIXED_CODE_START);
420 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
421 != ATOMIC_SUB32 - FIXED_CODE_START);
422 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
423 != ATOMIC_IOR32 - FIXED_CODE_START);
424 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
425 != ATOMIC_AND32 - FIXED_CODE_START);
426 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
427 != ATOMIC_XOR32 - FIXED_CODE_START);
Bernd Schmidt29440a22007-07-12 16:25:29 +0800428
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800429 init_exception_vectors();
Bernd Schmidt29440a22007-07-12 16:25:29 +0800430 bf53x_cache_init();
Bryan Wu1394f032007-05-06 14:50:22 -0700431}
432
Bryan Wu1394f032007-05-06 14:50:22 -0700433static int __init topology_init(void)
434{
435#if defined (CONFIG_BF561)
Mike Frysingerc0fc5252007-05-21 18:09:25 +0800436 static struct cpu cpu[2];
Bryan Wu1394f032007-05-06 14:50:22 -0700437 register_cpu(&cpu[0], 0);
438 register_cpu(&cpu[1], 1);
439 return 0;
440#else
Mike Frysingerc0fc5252007-05-21 18:09:25 +0800441 static struct cpu cpu[1];
Bryan Wu1394f032007-05-06 14:50:22 -0700442 return register_cpu(cpu, 0);
443#endif
444}
445
446subsys_initcall(topology_init);
447
Mike Frysinger52a07812007-06-11 15:31:30 +0800448static u_long get_vco(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700449{
450 u_long msel;
451 u_long vco;
452
453 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
454 if (0 == msel)
455 msel = 64;
456
457 vco = CONFIG_CLKIN_HZ;
458 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
459 vco = msel * vco;
460 return vco;
461}
462
463/*Get the Core clock*/
464u_long get_cclk(void)
465{
466 u_long csel, ssel;
467 if (bfin_read_PLL_STAT() & 0x1)
468 return CONFIG_CLKIN_HZ;
469
470 ssel = bfin_read_PLL_DIV();
471 csel = ((ssel >> 4) & 0x03);
472 ssel &= 0xf;
473 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
474 return get_vco() / ssel;
475 return get_vco() >> csel;
476}
Bryan Wu1394f032007-05-06 14:50:22 -0700477EXPORT_SYMBOL(get_cclk);
478
479/* Get the System clock */
480u_long get_sclk(void)
481{
482 u_long ssel;
483
484 if (bfin_read_PLL_STAT() & 0x1)
485 return CONFIG_CLKIN_HZ;
486
487 ssel = (bfin_read_PLL_DIV() & 0xf);
488 if (0 == ssel) {
489 printk(KERN_WARNING "Invalid System Clock\n");
490 ssel = 1;
491 }
492
493 return get_vco() / ssel;
494}
Bryan Wu1394f032007-05-06 14:50:22 -0700495EXPORT_SYMBOL(get_sclk);
496
497/*
498 * Get CPU information for use by the procfs.
499 */
500static int show_cpuinfo(struct seq_file *m, void *v)
501{
502 char *cpu, *mmu, *fpu, *name;
503 uint32_t revid;
504
505 u_long cclk = 0, sclk = 0;
506 u_int dcache_size = 0, dsup_banks = 0;
507
508 cpu = CPU;
509 mmu = "none";
510 fpu = "none";
511 revid = bfin_revid();
512 name = bfin_board_name;
513
514 cclk = get_cclk();
515 sclk = get_sclk();
516
517 seq_printf(m, "CPU:\t\tADSP-%s Rev. 0.%d\n"
518 "MMU:\t\t%s\n"
519 "FPU:\t\t%s\n"
520 "Core Clock:\t%9lu Hz\n"
521 "System Clock:\t%9lu Hz\n"
522 "BogoMips:\t%lu.%02lu\n"
523 "Calibration:\t%lu loops\n",
524 cpu, revid, mmu, fpu,
525 cclk,
526 sclk,
527 (loops_per_jiffy * HZ) / 500000,
528 ((loops_per_jiffy * HZ) / 5000) % 100,
529 (loops_per_jiffy * HZ));
530 seq_printf(m, "Board Name:\t%s\n", name);
531 seq_printf(m, "Board Memory:\t%ld MB\n", physical_mem_end >> 20);
532 seq_printf(m, "Kernel Memory:\t%ld MB\n", (unsigned long)_ramend >> 20);
533 if (bfin_read_IMEM_CONTROL() & (ENICPLB | IMC))
534 seq_printf(m, "I-CACHE:\tON\n");
535 else
536 seq_printf(m, "I-CACHE:\tOFF\n");
537 if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
538 seq_printf(m, "D-CACHE:\tON"
Robin Getz3bebca22007-10-10 23:55:26 +0800539#if defined CONFIG_BFIN_WB
Bryan Wu1394f032007-05-06 14:50:22 -0700540 " (write-back)"
Robin Getz3bebca22007-10-10 23:55:26 +0800541#elif defined CONFIG_BFIN_WT
Bryan Wu1394f032007-05-06 14:50:22 -0700542 " (write-through)"
543#endif
544 "\n");
545 else
546 seq_printf(m, "D-CACHE:\tOFF\n");
547
548
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800549 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
550 case ACACHE_BSRAM:
551 seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tSRAM\n");
552 dcache_size = 16;
553 dsup_banks = 1;
554 break;
555 case ACACHE_BCACHE:
556 seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tCACHE\n");
557 dcache_size = 32;
558 dsup_banks = 2;
559 break;
560 case ASRAM_BSRAM:
561 seq_printf(m, "DBANK-A:\tSRAM\n" "DBANK-B:\tSRAM\n");
562 dcache_size = 0;
563 dsup_banks = 0;
564 break;
565 default:
Bryan Wu1394f032007-05-06 14:50:22 -0700566 break;
567 }
568
569
Robin Getz3bebca22007-10-10 23:55:26 +0800570 seq_printf(m, "I-CACHE Size:\t%dKB\n", BFIN_ICACHESIZE / 1024);
Bryan Wu1394f032007-05-06 14:50:22 -0700571 seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
572 seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
Robin Getz3bebca22007-10-10 23:55:26 +0800573 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
Bryan Wu1394f032007-05-06 14:50:22 -0700574 seq_printf(m,
575 "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
Robin Getz3bebca22007-10-10 23:55:26 +0800576 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
577 BFIN_DLINES);
578#ifdef CONFIG_BFIN_ICACHE_LOCK
Bryan Wu1394f032007-05-06 14:50:22 -0700579 switch (read_iloc()) {
580 case WAY0_L:
581 seq_printf(m, "Way0 Locked-Down\n");
582 break;
583 case WAY1_L:
584 seq_printf(m, "Way1 Locked-Down\n");
585 break;
586 case WAY01_L:
587 seq_printf(m, "Way0,Way1 Locked-Down\n");
588 break;
589 case WAY2_L:
590 seq_printf(m, "Way2 Locked-Down\n");
591 break;
592 case WAY02_L:
593 seq_printf(m, "Way0,Way2 Locked-Down\n");
594 break;
595 case WAY12_L:
596 seq_printf(m, "Way1,Way2 Locked-Down\n");
597 break;
598 case WAY012_L:
599 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
600 break;
601 case WAY3_L:
602 seq_printf(m, "Way3 Locked-Down\n");
603 break;
604 case WAY03_L:
605 seq_printf(m, "Way0,Way3 Locked-Down\n");
606 break;
607 case WAY13_L:
608 seq_printf(m, "Way1,Way3 Locked-Down\n");
609 break;
610 case WAY013_L:
611 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
612 break;
613 case WAY32_L:
614 seq_printf(m, "Way3,Way2 Locked-Down\n");
615 break;
616 case WAY320_L:
617 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
618 break;
619 case WAY321_L:
620 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
621 break;
622 case WAYALL_L:
623 seq_printf(m, "All Ways are locked\n");
624 break;
625 default:
626 seq_printf(m, "No Ways are locked\n");
627 }
628#endif
629 return 0;
630}
631
632static void *c_start(struct seq_file *m, loff_t *pos)
633{
634 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
635}
636
637static void *c_next(struct seq_file *m, void *v, loff_t *pos)
638{
639 ++*pos;
640 return c_start(m, pos);
641}
642
643static void c_stop(struct seq_file *m, void *v)
644{
645}
646
647struct seq_operations cpuinfo_op = {
648 .start = c_start,
649 .next = c_next,
650 .stop = c_stop,
651 .show = show_cpuinfo,
652};
653
Mike Frysinger5e10b4a2007-06-11 16:44:09 +0800654void __init cmdline_init(const char *r0)
Bryan Wu1394f032007-05-06 14:50:22 -0700655{
656 if (r0)
Mike Frysinger52a07812007-06-11 15:31:30 +0800657 strncpy(command_line, r0, COMMAND_LINE_SIZE);
Bryan Wu1394f032007-05-06 14:50:22 -0700658}