Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs...
[pandora-kernel.git] / arch / h8300 / kernel / setup.c
1 /*
2  *  linux/arch/h8300/kernel/setup.c
3  *
4  *  Copyleft  ()) 2000       James D. Schettine {james@telos-systems.com}
5  *  Copyright (C) 1999,2000  Greg Ungerer (gerg@snapgear.com)
6  *  Copyright (C) 1998,1999  D. Jeff Dionne <jeff@lineo.ca>
7  *  Copyright (C) 1998       Kenneth Albanowski <kjahds@kjahds.com>
8  *  Copyright (C) 1995       Hamish Macdonald
9  *  Copyright (C) 2000       Lineo Inc. (www.lineo.com) 
10  *  Copyright (C) 2001       Lineo, Inc. <www.lineo.com>
11  *
12  *  H8/300 porting Yoshinori Sato <ysato@users.sourceforge.jp>
13  */
14
15 /*
16  * This file handles the architecture-dependent parts of system setup
17  */
18
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/delay.h>
22 #include <linux/interrupt.h>
23 #include <linux/mm.h>
24 #include <linux/fs.h>
25 #include <linux/fb.h>
26 #include <linux/console.h>
27 #include <linux/genhd.h>
28 #include <linux/errno.h>
29 #include <linux/string.h>
30 #include <linux/major.h>
31 #include <linux/bootmem.h>
32 #include <linux/seq_file.h>
33 #include <linux/init.h>
34
35 #include <asm/setup.h>
36 #include <asm/irq.h>
37 #include <asm/pgtable.h>
38
39 #if defined(__H8300H__)
40 #define CPU "H8/300H"
41 #include <asm/regs306x.h>
42 #endif
43
44 #if defined(__H8300S__)
45 #define CPU "H8S"
46 #include <asm/regs267x.h>
47 #endif
48
49 #define STUBSIZE 0xc000
50
51 unsigned long rom_length;
52 unsigned long memory_start;
53 unsigned long memory_end;
54
55 char __initdata command_line[COMMAND_LINE_SIZE];
56
57 extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
58 extern int _ramstart, _ramend;
59 extern char _target_name[];
60 extern void h8300_gpio_init(void);
61
62 #if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) \
63     && defined(CONFIG_GDB_MAGICPRINT)
64 /* printk with gdb service */
65 static void gdb_console_output(struct console *c, const char *msg, unsigned len)
66 {
67         for (; len > 0; len--) {
68                 asm("mov.w %0,r2\n\t"
69                     "jsr @0xc4"::"r"(*msg++):"er2");
70         }
71 }
72
73 /*
74  *      Setup initial baud/bits/parity. We do two things here:
75  *      - construct a cflag setting for the first rs_open()
76  *      - initialize the serial port
77  *      Return non-zero if we didn't find a serial port.
78  */
79 static int __init gdb_console_setup(struct console *co, char *options)
80 {
81         return 0;
82 }
83
84 static const struct console gdb_console = {
85         .name           = "gdb_con",
86         .write          = gdb_console_output,
87         .device         = NULL,
88         .setup          = gdb_console_setup,
89         .flags          = CON_PRINTBUFFER,
90         .index          = -1,
91 };
92 #endif
93
94 void __init setup_arch(char **cmdline_p)
95 {
96         int bootmap_size;
97
98         memory_start = (unsigned long) &_ramstart;
99
100         /* allow for ROMFS on the end of the kernel */
101         if (memcmp((void *)memory_start, "-rom1fs-", 8) == 0) {
102 #if defined(CONFIG_BLK_DEV_INITRD)
103                 initrd_start = memory_start;
104                 initrd_end = memory_start += be32_to_cpu(((unsigned long *) (memory_start))[2]);
105 #else
106                 memory_start += be32_to_cpu(((unsigned long *) memory_start)[2]);
107 #endif
108         }
109         memory_start = PAGE_ALIGN(memory_start);
110 #if !defined(CONFIG_BLKDEV_RESERVE)
111         memory_end = (unsigned long) &_ramend; /* by now the stack is part of the init task */
112 #if defined(CONFIG_GDB_DEBUG)
113         memory_end -= STUBSIZE;
114 #endif
115 #else
116         if ((memory_end < CONFIG_BLKDEV_RESERVE_ADDRESS) && 
117             (memory_end > CONFIG_BLKDEV_RESERVE_ADDRESS))
118             /* overlap userarea */
119             memory_end = CONFIG_BLKDEV_RESERVE_ADDRESS; 
120 #endif
121
122         init_mm.start_code = (unsigned long) &_stext;
123         init_mm.end_code = (unsigned long) &_etext;
124         init_mm.end_data = (unsigned long) &_edata;
125         init_mm.brk = (unsigned long) 0; 
126
127 #if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) && defined(CONFIG_GDB_MAGICPRINT)
128         register_console((struct console *)&gdb_console);
129 #endif
130
131         printk(KERN_INFO "\r\n\nuClinux " CPU "\n");
132         printk(KERN_INFO "Target Hardware: %s\n",_target_name);
133         printk(KERN_INFO "Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
134         printk(KERN_INFO "H8/300 series support by Yoshinori Sato <ysato@users.sourceforge.jp>\n");
135
136 #ifdef DEBUG
137         printk(KERN_DEBUG "KERNEL -> TEXT=0x%06x-0x%06x DATA=0x%06x-0x%06x "
138                 "BSS=0x%06x-0x%06x\n", (int) &_stext, (int) &_etext,
139                 (int) &_sdata, (int) &_edata,
140                 (int) &_sbss, (int) &_ebss);
141         printk(KERN_DEBUG "KERNEL -> ROMFS=0x%06x-0x%06x MEM=0x%06x-0x%06x "
142                 "STACK=0x%06x-0x%06x\n",
143                (int) &_ebss, (int) memory_start,
144                 (int) memory_start, (int) memory_end,
145                 (int) memory_end, (int) &_ramend);
146 #endif
147
148 #ifdef CONFIG_DEFAULT_CMDLINE
149         /* set from default command line */
150         if (*command_line == '\0')
151                 strcpy(command_line,CONFIG_KERNEL_COMMAND);
152 #endif
153         /* Keep a copy of command line */
154         *cmdline_p = &command_line[0];
155         memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
156         boot_command_line[COMMAND_LINE_SIZE-1] = 0;
157
158 #ifdef DEBUG
159         if (strlen(*cmdline_p)) 
160                 printk(KERN_DEBUG "Command line: '%s'\n", *cmdline_p);
161 #endif
162
163         /*
164          * give all the memory to the bootmap allocator,  tell it to put the
165          * boot mem_map at the start of memory
166          */
167         bootmap_size = init_bootmem_node(
168                         NODE_DATA(0),
169                         memory_start >> PAGE_SHIFT, /* map goes here */
170                         PAGE_OFFSET >> PAGE_SHIFT,      /* 0 on coldfire */
171                         memory_end >> PAGE_SHIFT);
172         /*
173          * free the usable memory,  we have to make sure we do not free
174          * the bootmem bitmap so we then reserve it after freeing it :-)
175          */
176         free_bootmem(memory_start, memory_end - memory_start);
177         reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
178         /*
179          * get kmalloc into gear
180          */
181         paging_init();
182         h8300_gpio_init();
183 #if defined(CONFIG_H8300_AKI3068NET) && defined(CONFIG_IDE)
184         {
185 #define AREABIT(addr) (1 << (((addr) >> 21) & 7))
186                 /* setup BSC */
187                 volatile unsigned char *abwcr = (volatile unsigned char *)ABWCR;
188                 volatile unsigned char *cscr = (volatile unsigned char *)CSCR;
189                 *abwcr &= ~(AREABIT(CONFIG_H8300_IDE_BASE) | AREABIT(CONFIG_H8300_IDE_ALT));
190                 *cscr  |= (AREABIT(CONFIG_H8300_IDE_BASE) | AREABIT(CONFIG_H8300_IDE_ALT)) | 0x0f;
191         }
192 #endif
193 #ifdef DEBUG
194         printk(KERN_DEBUG "Done setup_arch\n");
195 #endif
196 }
197
198 /*
199  *      Get CPU information for use by the procfs.
200  */
201
202 static int show_cpuinfo(struct seq_file *m, void *v)
203 {
204     char *cpu;
205     int mode;
206     u_long clockfreq;
207
208     cpu = CPU;
209     mode = *(volatile unsigned char *)MDCR & 0x07;
210
211     clockfreq = CONFIG_CPU_CLOCK;
212
213     seq_printf(m,  "CPU:\t\t%s (mode:%d)\n"
214                    "Clock:\t\t%lu.%1luMHz\n"
215                    "BogoMips:\t%lu.%02lu\n"
216                    "Calibration:\t%lu loops\n",
217                    cpu,mode,
218                    clockfreq/1000,clockfreq%1000,
219                    (loops_per_jiffy*HZ)/500000,((loops_per_jiffy*HZ)/5000)%100,
220                    (loops_per_jiffy*HZ));
221
222     return 0;
223 }
224
225 static void *c_start(struct seq_file *m, loff_t *pos)
226 {
227         return *pos < NR_CPUS ? ((void *) 0x12345678) : NULL;
228 }
229
230 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
231 {
232         ++*pos;
233         return c_start(m, pos);
234 }
235
236 static void c_stop(struct seq_file *m, void *v)
237 {
238 }
239
240 const struct seq_operations cpuinfo_op = {
241         .start  = c_start,
242         .next   = c_next,
243         .stop   = c_stop,
244         .show   = show_cpuinfo,
245 };