ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ppc / syslib / ppc4xx_setup.c
1 /*
2  *
3  *    Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
4  *
5  *    Copyright 2000-2001 MontaVista Software Inc.
6  *      Completed implementation.
7  *      Author: MontaVista Software, Inc.  <source@mvista.com>
8  *              Frank Rowand <frank_rowand@mvista.com>
9  *              Debbie Chu   <debbie_chu@mvista.com>
10  *      Further modifications by Armin Kuster
11  *
12  *    Module name: ppc4xx_setup.c
13  *
14  */
15
16 #include <linux/config.h>
17 #include <linux/init.h>
18 #include <linux/smp.h>
19 #include <linux/threads.h>
20 #include <linux/spinlock.h>
21 #include <linux/irq.h>
22 #include <linux/reboot.h>
23 #include <linux/param.h>
24 #include <linux/string.h>
25 #include <linux/initrd.h>
26 #include <linux/pci.h>
27 #include <linux/rtc.h>
28 #include <linux/console.h>
29 #include <linux/ide.h>
30 #include <linux/serial_reg.h>
31 #include <linux/seq_file.h>
32
33 #include <asm/system.h>
34 #include <asm/processor.h>
35 #include <asm/machdep.h>
36 #include <asm/page.h>
37 #include <asm/kgdb.h>
38 #include <asm/ibm4xx.h>
39 #include <asm/time.h>
40 #include <asm/todc.h>
41 #include <asm/ppc4xx_pic.h>
42 #include <asm/pci-bridge.h>
43 #include <asm/bootinfo.h>
44
45 /* Function Prototypes */
46 extern void abort(void);
47 extern void ppc4xx_find_bridges(void);
48
49 extern void ppc4xx_wdt_heartbeat(void);
50 extern int wdt_enable;
51 extern unsigned long wdt_period;
52
53 /* Global Variables */
54 bd_t __res;
55
56 void __init
57 ppc4xx_setup_arch(void)
58 {
59         /* Setup PCI host bridges */
60
61 #ifdef CONFIG_PCI
62         ppc4xx_find_bridges();
63 #endif
64
65 #if defined(CONFIG_FB)
66         conswitchp = &dummy_con;
67 #endif
68 }
69
70 /*
71  *   This routine pretty-prints the platform's internal CPU clock
72  *   frequencies into the buffer for usage in /proc/cpuinfo.
73  */
74
75 static int
76 ppc4xx_show_percpuinfo(struct seq_file *m, int i)
77 {
78         seq_printf(m, "clock\t\t: %ldMHz\n", (long)__res.bi_intfreq / 1000000);
79
80         return 0;
81 }
82
83 /*
84  *   This routine pretty-prints the platform's internal bus clock
85  *   frequencies into the buffer for usage in /proc/cpuinfo.
86  */
87 static int
88 ppc4xx_show_cpuinfo(struct seq_file *m)
89 {
90         bd_t *bip = &__res;
91
92         seq_printf(m, "machine\t\t: %s\n", PPC4xx_MACHINE_NAME);
93         seq_printf(m, "plb bus clock\t: %ldMHz\n",
94                    (long) bip->bi_busfreq / 1000000);
95 #ifdef CONFIG_PCI
96         seq_printf(m, "pci bus clock\t: %dMHz\n",
97                    bip->bi_pci_busfreq / 1000000);
98 #endif
99
100         return 0;
101 }
102
103 /*
104  * Return the virtual address representing the top of physical RAM.
105  */
106 static unsigned long __init
107 ppc4xx_find_end_of_memory(void)
108 {
109         return ((unsigned long) __res.bi_memsize);
110 }
111
112 void __init
113 ppc4xx_map_io(void)
114 {
115         io_block_mapping(PPC4xx_ONB_IO_VADDR,
116                          PPC4xx_ONB_IO_PADDR, PPC4xx_ONB_IO_SIZE, _PAGE_IO);
117 #ifdef CONFIG_PCI
118         io_block_mapping(PPC4xx_PCI_IO_VADDR,
119                          PPC4xx_PCI_IO_PADDR, PPC4xx_PCI_IO_SIZE, _PAGE_IO);
120         io_block_mapping(PPC4xx_PCI_CFG_VADDR,
121                          PPC4xx_PCI_CFG_PADDR, PPC4xx_PCI_CFG_SIZE, _PAGE_IO);
122         io_block_mapping(PPC4xx_PCI_LCFG_VADDR,
123                          PPC4xx_PCI_LCFG_PADDR, PPC4xx_PCI_LCFG_SIZE, _PAGE_IO);
124 #endif
125 }
126
127 void __init
128 ppc4xx_init_IRQ(void)
129 {
130         int i;
131
132         ppc4xx_pic_init();
133
134         for (i = 0; i < NR_IRQS; i++)
135                 irq_desc[i].handler = ppc4xx_pic;
136 }
137
138 static void
139 ppc4xx_restart(char *cmd)
140 {
141         printk("%s\n", cmd);
142         abort();
143 }
144
145 static void
146 ppc4xx_power_off(void)
147 {
148         printk("System Halted\n");
149         local_irq_disable();
150         while (1) ;
151 }
152
153 static void
154 ppc4xx_halt(void)
155 {
156         printk("System Halted\n");
157         local_irq_disable();
158         while (1) ;
159 }
160
161 /*
162  * This routine retrieves the internal processor frequency from the board
163  * information structure, sets up the kernel timer decrementer based on
164  * that value, enables the 4xx programmable interval timer (PIT) and sets
165  * it up for auto-reload.
166  */
167 static void __init
168 ppc4xx_calibrate_decr(void)
169 {
170         unsigned int freq;
171         bd_t *bip = &__res;
172
173 #if defined(CONFIG_WALNUT) || defined(CONFIG_ASH) || defined(CONFIG_SYCAMORE)
174         /* Walnut boot rom sets DCR CHCR1 (aka CPC0_CR1) bit CETE to 1 */
175         mtdcr(DCRN_CHCR1, mfdcr(DCRN_CHCR1) & ~CHR1_CETE);
176 #endif
177         freq = bip->bi_tbfreq;
178         tb_ticks_per_jiffy = freq / HZ;
179         tb_to_us = mulhwu_scale_factor(freq, 1000000);
180
181         /* Set the time base to zero.
182            ** At 200 Mhz, time base will rollover in ~2925 years.
183          */
184
185         mtspr(SPRN_TBWL, 0);
186         mtspr(SPRN_TBWU, 0);
187
188         /* Clear any pending timer interrupts */
189
190         mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_PIS | TSR_FIS);
191         mtspr(SPRN_TCR, TCR_PIE | TCR_ARE);
192
193         /* Set the PIT reload value and just let it run. */
194         mtspr(SPRN_PIT, tb_ticks_per_jiffy);
195 }
196 #ifdef CONFIG_SERIAL_TEXT_DEBUG
197
198 /* We assume that the UART has already been initialized by the
199    firmware or the boot loader */
200 static void
201 serial_putc(u8 * com_port, unsigned char c)
202 {
203         while ((readb(com_port + (UART_LSR)) & UART_LSR_THRE) == 0) ;
204         writeb(c, com_port);
205 }
206
207 static void
208 ppc4xx_progress(char *s, unsigned short hex)
209 {
210         char c;
211 #ifdef SERIAL_DEBUG_IO_BASE
212         u8 *com_port = (u8 *) SERIAL_DEBUG_IO_BASE;
213
214         while ((c = *s++) != '\0') {
215                 serial_putc(com_port, c);
216         }
217         serial_putc(com_port, '\r');
218         serial_putc(com_port, '\n');
219 #else
220         printk("%s\r\n");
221 #endif
222 }
223 #endif                          /* CONFIG_SERIAL_TEXT_DEBUG */
224
225 /*
226  * IDE stuff.
227  * should be generic for every IDE PCI chipset
228  */
229 #if defined(CONFIG_PCI) && defined(CONFIG_IDE)
230 static void
231 ppc4xx_ide_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
232                            unsigned long ctrl_port, int *irq)
233 {
234         int i;
235
236         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; ++i)
237                 hw->io_ports[i] = data_port + i - IDE_DATA_OFFSET;
238
239         hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
240 }
241 #endif /* defined(CONFIG_PCI) && defined(CONFIG_IDE) */
242
243 TODC_ALLOC();
244
245 /*
246  * Input(s):
247  *   r3 - Optional pointer to a board information structure.
248  *   r4 - Optional pointer to the physical starting address of the init RAM
249  *        disk.
250  *   r5 - Optional pointer to the physical ending address of the init RAM
251  *        disk.
252  *   r6 - Optional pointer to the physical starting address of any kernel
253  *        command-line parameters.
254  *   r7 - Optional pointer to the physical ending address of any kernel
255  *        command-line parameters.
256  */
257 void __init
258 ppc4xx_init(unsigned long r3, unsigned long r4, unsigned long r5,
259             unsigned long r6, unsigned long r7)
260 {
261         parse_bootinfo(find_bootinfo());
262
263         /*
264          * If we were passed in a board information, copy it into the
265          * residual data area.
266          */
267         if (r3)
268                 __res = *(bd_t *)(r3 + KERNELBASE);
269
270 #if defined(CONFIG_BLK_DEV_INITRD)
271         /*
272          * If the init RAM disk has been configured in, and there's a valid
273          * starting address for it, set it up.
274          */
275         if (r4) {
276                 initrd_start = r4 + KERNELBASE;
277                 initrd_end = r5 + KERNELBASE;
278         }
279 #endif                          /* CONFIG_BLK_DEV_INITRD */
280
281         /* Copy the kernel command line arguments to a safe place. */
282
283         if (r6) {
284                 *(char *) (r7 + KERNELBASE) = 0;
285                 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
286         }
287 #if defined(CONFIG_PPC405_WDT)
288 /* Look for wdt= option on command line */
289         if (strstr(cmd_line, "wdt=")) {
290                 int valid_wdt = 0;
291                 char *p, *q;
292                 for (q = cmd_line; (p = strstr(q, "wdt=")) != 0;) {
293                         q = p + 4;
294                         if (p > cmd_line && p[-1] != ' ')
295                                 continue;
296                         wdt_period = simple_strtoul(q, &q, 0);
297                         valid_wdt = 1;
298                         ++q;
299                 }
300                 wdt_enable = valid_wdt;
301         }
302 #endif
303
304         /* Initialize machine-dependent vectors */
305
306         ppc_md.setup_arch = ppc4xx_setup_arch;
307         ppc_md.show_percpuinfo = ppc4xx_show_percpuinfo;
308         ppc_md.show_cpuinfo = ppc4xx_show_cpuinfo;
309         ppc_md.init_IRQ = ppc4xx_init_IRQ;
310
311         ppc_md.restart = ppc4xx_restart;
312         ppc_md.power_off = ppc4xx_power_off;
313         ppc_md.halt = ppc4xx_halt;
314
315         ppc_md.calibrate_decr = ppc4xx_calibrate_decr;
316
317 #ifdef CONFIG_PPC405_WDT
318         ppc_md.heartbeat = ppc4xx_wdt_heartbeat;
319 #endif
320         ppc_md.heartbeat_count = 0;
321
322         ppc_md.find_end_of_memory = ppc4xx_find_end_of_memory;
323         ppc_md.setup_io_mappings = ppc4xx_map_io;
324
325 #ifdef CONFIG_SERIAL_TEXT_DEBUG
326         ppc_md.progress = ppc4xx_progress;
327 #endif
328
329 /*
330 **   m8xx_setup.c, prep_setup.c use
331 **     defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
332 */
333 #if defined(CONFIG_PCI) && defined(CONFIG_IDE)
334         ppc_ide_md.ide_init_hwif = ppc4xx_ide_init_hwif_ports;
335 #endif /* defined(CONFIG_PCI) && defined(CONFIG_IDE) */
336 }