ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ppc / platforms / 4xx / oak.c
1 /*
2  *
3  *    Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
4  *
5  *    Module name: oak.c
6  *
7  *    Description:
8  *      Architecture- / platform-specific boot-time initialization code for
9  *      the IBM PowerPC 403GCX "Oak" evaluation board. Adapted from original
10  *      code by Gary Thomas, Cort Dougan <cort@fsmlabs.com>, and Dan Malek
11  *      <dan@net4x.com>.
12  *
13  */
14
15 #include <linux/config.h>
16 #include <linux/init.h>
17 #include <linux/smp.h>
18 #include <linux/threads.h>
19 #include <linux/param.h>
20 #include <linux/string.h>
21 #include <linux/initrd.h>
22 #include <linux/irq.h>
23 #include <linux/seq_file.h>
24
25 #include <asm/board.h>
26 #include <asm/machdep.h>
27 #include <asm/page.h>
28 #include <asm/bootinfo.h>
29 #include <asm/ppc4xx_pic.h>
30 #include <asm/time.h>
31
32 #include "oak.h"
33
34 /* Function Prototypes */
35
36 extern void abort(void);
37
38 /* Global Variables */
39
40 unsigned char __res[sizeof(bd_t)];
41
42
43 /*
44  * void __init oak_init()
45  *
46  * Description:
47  *   This routine...
48  *
49  * Input(s):
50  *   r3 - Optional pointer to a board information structure.
51  *   r4 - Optional pointer to the physical starting address of the init RAM
52  *        disk.
53  *   r5 - Optional pointer to the physical ending address of the init RAM
54  *        disk.
55  *   r6 - Optional pointer to the physical starting address of any kernel
56  *        command-line parameters.
57  *   r7 - Optional pointer to the physical ending address of any kernel
58  *        command-line parameters.
59  *
60  * Output(s):
61  *   N/A
62  *
63  * Returns:
64  *   N/A
65  *
66  */
67 void __init
68 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
69               unsigned long r6, unsigned long r7)
70 {
71         parse_bootinfo(find_bootinfo());
72
73         /*
74          * If we were passed in a board information, copy it into the
75          * residual data area.
76          */
77         if (r3) {
78                 memcpy((void *)__res, (void *)(r3 + KERNELBASE), sizeof(bd_t));
79         }
80
81 #if defined(CONFIG_BLK_DEV_INITRD)
82         /*
83          * If the init RAM disk has been configured in, and there's a valid
84          * starting address for it, set it up.
85          */
86         if (r4) {
87                 initrd_start = r4 + KERNELBASE;
88                 initrd_end = r5 + KERNELBASE;
89         }
90 #endif /* CONFIG_BLK_DEV_INITRD */
91
92         /* Copy the kernel command line arguments to a safe place. */
93
94         if (r6) {
95                 *(char *)(r7 + KERNELBASE) = 0;
96                 strcpy(cmd_line, (char *)(r6 + KERNELBASE));
97         }
98
99         /* Initialize machine-dependency vectors */
100
101         ppc_md.setup_arch               = oak_setup_arch;
102         ppc_md.show_percpuinfo          = oak_show_percpuinfo;
103         ppc_md.irq_canonicalize         = NULL;
104         ppc_md.init_IRQ                 = oak_init_IRQ;
105         ppc_md.get_irq                  = oak_get_irq;
106         ppc_md.init                     = NULL;
107
108         ppc_md.restart                  = oak_restart;
109         ppc_md.power_off                = oak_power_off;
110         ppc_md.halt                     = oak_halt;
111
112         ppc_md.time_init                = oak_time_init;
113         ppc_md.set_rtc_time             = oak_set_rtc_time;
114         ppc_md.get_rtc_time             = oak_get_rtc_time;
115         ppc_md.calibrate_decr           = oak_calibrate_decr;
116 }
117
118 /*
119  * Document me.
120  */
121 void __init
122 oak_setup_arch(void)
123 {
124         /* XXX - Implement me */
125 }
126
127 /*
128  * int oak_show_percpuinfo()
129  *
130  * Description:
131  *   This routine pretty-prints the platform's internal CPU and bus clock
132  *   frequencies into the buffer for usage in /proc/cpuinfo.
133  *
134  * Input(s):
135  *  *buffer - Buffer into which CPU and bus clock frequencies are to be
136  *            printed.
137  *
138  * Output(s):
139  *  *buffer - Buffer with the CPU and bus clock frequencies.
140  *
141  * Returns:
142  *   The number of bytes copied into 'buffer' if OK, otherwise zero or less
143  *   on error.
144  */
145 int
146 oak_show_percpuinfo(struct seq_file *m, int i)
147 {
148         bd_t *bp = (bd_t *)__res;
149
150         seq_printf(m, "clock\t\t: %dMHz\n"
151                    "bus clock\t\t: %dMHz\n",
152                    bp->bi_intfreq / 1000000,
153                    bp->bi_busfreq / 1000000);
154
155         return 0;
156 }
157
158 /*
159  * Document me.
160  */
161 void __init
162 oak_init_IRQ(void)
163 {
164         int i;
165
166         ppc4xx_pic_init();
167
168         for (i = 0; i < NR_IRQS; i++) {
169                 irq_desc[i].handler = ppc4xx_pic;
170         }
171
172         return;
173 }
174
175 /*
176  * Document me.
177  */
178 int
179 oak_get_irq(struct pt_regs *regs)
180 {
181         return (ppc4xx_pic_get_irq(regs));
182 }
183
184 /*
185  * Document me.
186  */
187 void
188 oak_restart(char *cmd)
189 {
190         abort();
191 }
192
193 /*
194  * Document me.
195  */
196 void
197 oak_power_off(void)
198 {
199         oak_restart(NULL);
200 }
201
202 /*
203  * Document me.
204  */
205 void
206 oak_halt(void)
207 {
208         oak_restart(NULL);
209 }
210
211 /*
212  * Document me.
213  */
214 long __init
215 oak_time_init(void)
216 {
217         /* XXX - Implement me */
218         return 0;
219 }
220
221 /*
222  * Document me.
223  */
224 int __init
225 oak_set_rtc_time(unsigned long time)
226 {
227         /* XXX - Implement me */
228
229         return (0);
230 }
231
232 /*
233  * Document me.
234  */
235 unsigned long __init
236 oak_get_rtc_time(void)
237 {
238         /* XXX - Implement me */
239
240         return (0);
241 }
242
243 /*
244  * void __init oak_calibrate_decr()
245  *
246  * Description:
247  *   This routine retrieves the internal processor frequency from the board
248  *   information structure, sets up the kernel timer decrementer based on
249  *   that value, enables the 403 programmable interval timer (PIT) and sets
250  *   it up for auto-reload.
251  *
252  * Input(s):
253  *   N/A
254  *
255  * Output(s):
256  *   N/A
257  *
258  * Returns:
259  *   N/A
260  *
261  */
262 void __init
263 oak_calibrate_decr(void)
264 {
265         unsigned int freq;
266         bd_t *bip = (bd_t *)__res;
267
268         freq = bip->bi_intfreq;
269
270         decrementer_count = freq / HZ;
271         count_period_num = 1;
272         count_period_den = freq;
273
274         /* Enable the PIT and set auto-reload of its value */
275
276         mtspr(SPRN_TCR, TCR_PIE | TCR_ARE);
277
278         /* Clear any pending timer interrupts */
279
280         mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_PIS | TSR_FIS);
281 }