more changes on original files
[linux-2.4.git] / arch / ppc / platforms / spruce_setup.c
1 /*
2  * arch/ppc/platforms/spruce_setup.c
3  *
4  * Board setup routines for IBM Spruce
5  *
6  * Authors: Johnnie Peters <jpeters@mvista.com>
7  *          Matt Porter <mporter@mvista.com>
8  *
9  * 2001-2002 (c) MontaVista, Software, Inc.  This file is licensed under
10  * the terms of the GNU General Public License version 2.  This program
11  * is licensed "as is" without any warranty of any kind, whether express
12  * or implied.
13  */
14
15 #include <linux/config.h>
16 #include <linux/stddef.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/errno.h>
20 #include <linux/reboot.h>
21 #include <linux/pci.h>
22 #include <linux/kdev_t.h>
23 #include <linux/types.h>
24 #include <linux/major.h>
25 #include <linux/blk.h>
26 #include <linux/console.h>
27 #include <linux/delay.h>
28 #include <linux/seq_file.h>
29 #include <linux/ide.h>
30 #include <linux/serial.h>
31
32 #include <asm/keyboard.h>
33 #include <asm/system.h>
34 #include <asm/pgtable.h>
35 #include <asm/page.h>
36 #include <asm/dma.h>
37 #include <asm/io.h>
38 #include <asm/machdep.h>
39 #include <asm/time.h>
40 #include <platforms/spruce.h>
41 #include <asm/todc.h>
42 #include <asm/bootinfo.h>
43
44 #include "cpc700.h"
45
46 extern void spruce_init_IRQ(void);
47 extern int spruce_get_irq(struct pt_regs *);
48 extern void spruce_setup_hose(void);
49
50 extern int pckbd_setkeycode(unsigned int, unsigned int);
51 extern int pckbd_getkeycode(unsigned int);
52 extern int pckbd_translate(unsigned char, unsigned char *, char);
53 extern char pckbd_unexpected_up(unsigned char);
54 extern void pckbd_leds(unsigned char);
55 extern void pckbd_init_hw(void);
56 extern unsigned char pckbd_sysrq_xlate[128];
57 extern char cmd_line[];
58
59 extern void gen550_progress(char *, unsigned short);
60 extern void gen550_init(int, struct serial_struct *);
61
62 /*
63  * CPC700 PIC interrupt programming table
64  *
65  * First entry is the sensitivity (level/edge), second is the polarity.
66  */
67 unsigned int cpc700_irq_assigns[32][2] = {
68         { 1, 1 },       /* IRQ  0: ECC Correctable Error - rising edge */
69         { 1, 1 },       /* IRQ  1: PCI Write Mem Range   - rising edge */
70         { 0, 1 },       /* IRQ  2: PCI Write Command Reg - active high */
71         { 0, 1 },       /* IRQ  3: UART 0                - active high */
72         { 0, 1 },       /* IRQ  4: UART 1                - active high */
73         { 0, 1 },       /* IRQ  5: ICC 0                 - active high */
74         { 0, 1 },       /* IRQ  6: ICC 1                 - active high */
75         { 0, 1 },       /* IRQ  7: GPT Compare 0         - active high */
76         { 0, 1 },       /* IRQ  8: GPT Compare 1         - active high */
77         { 0, 1 },       /* IRQ  9: GPT Compare 2         - active high */
78         { 0, 1 },       /* IRQ 10: GPT Compare 3         - active high */
79         { 0, 1 },       /* IRQ 11: GPT Compare 4         - active high */
80         { 0, 1 },       /* IRQ 12: GPT Capture 0         - active high */
81         { 0, 1 },       /* IRQ 13: GPT Capture 1         - active high */
82         { 0, 1 },       /* IRQ 14: GPT Capture 2         - active high */
83         { 0, 1 },       /* IRQ 15: GPT Capture 3         - active high */
84         { 0, 1 },       /* IRQ 16: GPT Capture 4         - active high */
85         { 0, 0 },       /* IRQ 17: Reserved */
86         { 0, 0 },       /* IRQ 18: Reserved */
87         { 0, 0 },       /* IRQ 19: Reserved */
88         { 0, 1 },       /* IRQ 20: FPGA EXT_IRQ0         - active high */
89         { 1, 1 },       /* IRQ 21: Mouse                 - rising edge */
90         { 1, 1 },       /* IRQ 22: Keyboard              - rising edge */
91         { 0, 0 },       /* IRQ 23: PCI Slot 3            - active low */
92         { 0, 0 },       /* IRQ 24: PCI Slot 2            - active low */
93         { 0, 0 },       /* IRQ 25: PCI Slot 1            - active low */
94         { 0, 0 },       /* IRQ 26: PCI Slot 0            - active low */
95 };
96
97 static void __init
98 spruce_calibrate_decr(void)
99 {
100         int freq, divisor = 4;
101
102         /* determine processor bus speed */
103         freq = SPRUCE_BUS_SPEED;
104         tb_ticks_per_jiffy = freq / HZ / divisor;
105         tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
106 }
107
108 static int
109 spruce_show_cpuinfo(struct seq_file *m)
110 {
111         seq_printf(m, "vendor\t\t: IBM\n");
112         seq_printf(m, "machine\t\t: Spruce\n");
113
114         return 0;
115 }
116
117 #ifdef CONFIG_SERIAL
118 static void __init
119 spruce_early_serial_map(void)
120 {
121         u32 baud_base;
122         struct serial_struct serial_req;
123
124         if (SPRUCE_UARTCLK_IS_33M(readb(SPRUCE_FPGA_REG_A)))
125                 baud_base = SPRUCE_BAUD_33M;
126         else
127                 baud_base = SPRUCE_BAUD_30M;
128
129         /* Setup serial port access */
130         memset(&serial_req, 0, sizeof(serial_req));
131         serial_req.baud_base = baud_base;
132         serial_req.line = 0;
133         serial_req.port = 0;
134         serial_req.irq = 3;
135         serial_req.flags = ASYNC_BOOT_AUTOCONF;
136         serial_req.io_type = SERIAL_IO_MEM;
137         serial_req.iomem_base = (u_char *)UART0_IO_BASE;
138         serial_req.iomem_reg_shift = 0;
139
140 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
141         gen550_init(0, &serial_req);
142 #endif
143
144         if (early_serial_setup(&serial_req) != 0)
145                 printk("Early serial init of port 0 failed\n");
146
147         /* Assume early_serial_setup() doesn't modify serial_req */
148         serial_req.line = 1;
149         serial_req.port = 1;
150         serial_req.irq = 4;
151         serial_req.iomem_base = (u_char *)UART1_IO_BASE;
152
153 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
154         gen550_init(1, &serial_req);
155 #endif
156
157         if (early_serial_setup(&serial_req) != 0)
158                 printk("Early serial init of port 1 failed\n");
159 }
160 #endif
161
162 TODC_ALLOC();
163
164 static void __init
165 spruce_setup_arch(void)
166 {
167         /* Setup TODC access */
168         TODC_INIT(TODC_TYPE_DS1643, 0, 0, SPRUCE_RTC_BASE_ADDR, 8);
169
170         /* init to some ~sane value until calibrate_delay() runs */
171         loops_per_jiffy = 50000000 / HZ;
172
173         /* Setup PCI host bridge */
174         spruce_setup_hose();
175
176 #ifdef CONFIG_BLK_DEV_INITRD
177         if (initrd_start)
178                 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0); /* /dev/ram */
179         else
180 #endif
181 #ifdef CONFIG_ROOT_NFS
182                 ROOT_DEV = to_kdev_t(0x00FF);   /* /dev/nfs pseudo device */
183 #else
184                 ROOT_DEV = to_kdev_t(0x0801);   /* /dev/sda1 */
185 #endif
186
187 #ifdef CONFIG_DUMMY_CONSOLE
188         conswitchp = &dummy_con;
189 #endif
190
191 #ifdef CONFIG_SERIAL
192         spruce_early_serial_map();
193 #endif
194
195         /* Identify the system */
196         printk("System Identification: IBM Spruce\n");
197         printk("IBM Spruce port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
198 }
199
200 static void
201 spruce_restart(char *cmd)
202 {
203         __cli();
204
205         /* SRR0 has system reset vector, SRR1 has default MSR value */
206         /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
207         asm volatile("  lis     3,0xfff0        \n\
208                         ori     3,3,0x0100      \n\
209                         mtspr   26,3            \n\
210                         li      3,0             \n\
211                         mtspr   27,3            \n\
212                         rfi");
213         for(;;);
214 }
215
216 static void
217 spruce_power_off(void)
218 {
219         for(;;);
220 }
221
222 static void
223 spruce_halt(void)
224 {
225         spruce_restart(NULL);
226 }
227
228 static unsigned long __init
229 spruce_find_end_of_memory(void)
230 {
231         return boot_mem_size;
232 }
233
234 static void __init
235 spruce_map_io(void)
236 {
237         io_block_mapping(SPRUCE_PCI_IO_BASE, SPRUCE_PCI_PHY_IO_BASE,
238                          0x08000000, _PAGE_IO);
239 }
240
241 unsigned char spruce_read_keyb_status(void)
242 {
243         unsigned long kbd_status;
244
245         __raw_writel(0x00000088, 0xff500008);
246         eieio();
247
248         __raw_writel(0x03000000, 0xff50000c);
249         eieio();
250
251         asm volatile("  lis     7,0xff88        \n\
252                         ori     7,7,0x8         \n\
253                         lswi    6,7,0x8         \n\
254                         mr      %0,6"
255                         : "=r" (kbd_status) :: "6", "7");
256
257         __raw_writel(0x00000000, 0xff50000c);
258         eieio();
259
260         return (unsigned char)(kbd_status >> 24);
261 }
262
263 unsigned char spruce_read_keyb_data(void)
264 {
265         unsigned long kbd_data;
266
267         __raw_writel(0x00000088, 0xff500008);
268         eieio();
269
270         __raw_writel(0x03000000, 0xff50000c);
271         eieio();
272
273         asm volatile("  lis     7,0xff88        \n\
274                         lswi    6,7,0x8         \n\
275                         mr      %0,6"
276                         : "=r" (kbd_data) :: "6", "7");
277
278         __raw_writel(0x00000000, 0xff50000c);
279         eieio();
280
281         return (unsigned char)(kbd_data >> 24);
282 }
283
284 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
285 /*
286  * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
287  */
288 static __inline__ void
289 spruce_set_bat(void)
290 {
291         unsigned long   bat3u, bat3l;
292
293         asm volatile("  lis     %0,0xf800       \n\
294                         ori     %1,%0,0x002a    \n\
295                         ori     %0,%0,0x0ffe    \n\
296                         mtspr   0x21e,%0        \n\
297                         mtspr   0x21f,%1        \n\
298                         isync                   \n\
299                         sync "
300                         : "=r" (bat3u), "=r" (bat3l));
301 }
302 #endif
303
304 void __init
305 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
306               unsigned long r6, unsigned long r7)
307 {
308         parse_bootinfo(find_bootinfo());
309
310         isa_io_base = SPRUCE_ISA_IO_BASE;
311         pci_dram_offset = SPRUCE_PCI_SYS_MEM_BASE;
312
313         ppc_md.setup_arch = spruce_setup_arch;
314         ppc_md.show_cpuinfo = spruce_show_cpuinfo;
315         ppc_md.init_IRQ = cpc700_init_IRQ;
316         ppc_md.get_irq = cpc700_get_irq;
317
318         ppc_md.find_end_of_memory = spruce_find_end_of_memory;
319         ppc_md.setup_io_mappings = spruce_map_io;
320
321         ppc_md.restart = spruce_restart;
322         ppc_md.power_off = spruce_power_off;
323         ppc_md.halt = spruce_halt;
324
325         ppc_md.time_init = todc_time_init;
326         ppc_md.set_rtc_time = todc_set_rtc_time;
327         ppc_md.get_rtc_time = todc_get_rtc_time;
328         ppc_md.calibrate_decr = spruce_calibrate_decr;
329
330         ppc_md.nvram_read_val = todc_direct_read_val;
331         ppc_md.nvram_write_val = todc_direct_write_val;
332
333 #if defined(CONFIG_SERIAL) && (defined(CONFIG_SERIAL_TEXT_DEBUG) \
334                 || defined(CONFIG_KGDB))
335         spruce_set_bat();
336         spruce_early_serial_map();
337
338 #ifdef CONFIG_SERIAL_TEXT_DEBUG
339         ppc_md.progress = gen550_progress;
340 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
341         ppc_md.early_serial_map = spruce_early_serial_map;
342 #endif
343
344 #ifdef CONFIG_VT
345         /* Spruce has a PS2 style keyboard */
346         ppc_md.kbd_setkeycode = pckbd_setkeycode;
347         ppc_md.kbd_getkeycode = pckbd_getkeycode;
348         ppc_md.kbd_translate = pckbd_translate;
349         ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
350         ppc_md.kbd_leds = pckbd_leds;
351         ppc_md.kbd_init_hw = pckbd_init_hw;
352 #ifdef CONFIG_MAGIC_SYSRQ
353         ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
354         SYSRQ_KEY = 0x54;
355 #endif
356 #endif
357 }