fix to allow usb modules to compile
[linux-2.4.21-pre4.git] / arch / ppc / platforms / menf1_setup.c
1 /*
2  * arch/ppc/platforms/menf1_setup.c
3  
4  * Board setup routines for MEN F1
5  *
6  * Author: Matt Porter <mporter@mvista.com>
7  *
8  * Copyright 2001 MontaVista Software Inc.
9  *
10  * This program is free software; you can redistribute  it and/or modify it
11  * under  the terms of  the GNU General Public License as published by the
12  * Free Software Foundation;  either version 2 of the  License, or (at your
13  * option) any later version.
14  */
15
16 #include <linux/config.h>
17 #include <linux/stddef.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/reboot.h>
22 #include <linux/pci.h>
23 #include <linux/kdev_t.h>
24 #include <linux/types.h>
25 #include <linux/major.h>
26 #include <linux/blk.h>
27 #include <linux/console.h>
28 #include <linux/delay.h>
29 #include <linux/ide.h>
30 #include <linux/irq.h>
31 #include <linux/seq_file.h>
32
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 <asm/i8259.h>
41 #include <asm/mpc10x.h>
42 #include <asm/todc.h>
43 #include <asm/bootinfo.h>
44
45 #include "menf1.h"
46
47 extern void menf1_find_bridges(void);
48 extern unsigned long loops_per_jiffy;
49
50 /* Dummy variable to satisfy mpc10x_common.o */
51 void *OpenPIC_Addr;
52
53 static int
54 menf1_show_cpuinfo(struct seq_file *m)
55 {
56         seq_printf(m, "machine\t\t: MEN F1\n");
57
58         return 0;
59 }
60
61 static void __init
62 menf1_setup_arch(void)
63 {
64         /* init to some ~sane value until calibrate_delay() runs */
65         loops_per_jiffy = 50000000/HZ;
66
67         /* Lookup PCI host bridges */
68         menf1_find_bridges();
69
70 #ifdef CONFIG_BLK_DEV_INITRD
71         if (initrd_start)
72                 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
73         else
74 #endif
75 #ifdef CONFIG_ROOT_NFS
76                 ROOT_DEV = to_kdev_t(0x00ff); /* /dev/nfs pseudo device */
77 #else
78                 ROOT_DEV = to_kdev_t(0x0302); /* /dev/hda2 */
79 #endif
80
81 #ifdef CONFIG_DUMMY_CONSOLE
82         conswitchp = &dummy_con;
83 #endif
84
85         printk("MEN F1 port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
86 }
87
88 static void
89 menf1_restart(char *cmd)
90 {
91
92        int     picr1;
93        struct pci_dev *pdev;
94
95         __cli();
96
97         /*
98          * Firmware doesn't like re-entry using Map B (CHRP), so make sure the
99          * PCI bridge is using MAP A (PReP).
100          */
101
102         pdev = pci_find_slot(0, PCI_DEVFN(0,0));
103
104         while(pdev == NULL); /* paranoia */
105
106         pci_read_config_dword(pdev, MPC10X_CFG_PICR1_REG, &picr1);
107
108         picr1 = (picr1 & ~MPC10X_CFG_PICR1_ADDR_MAP_MASK) |
109                 MPC10X_CFG_PICR1_ADDR_MAP_A;
110
111         pci_write_config_dword(pdev, MPC10X_CFG_PICR1_REG, picr1);
112
113         asm volatile("sync");
114
115         /* SRR0 has system reset vector, SRR1 has default MSR value */
116         /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
117         __asm__ __volatile__
118         ("\n\
119         lis     3,0xfff0
120         ori     3,3,0x0100
121         mtspr   26,3
122         li      3,0
123         mtspr   27,3
124         rfi
125         ");
126         while(1);
127 }
128
129 static void
130 menf1_halt(void)
131 {
132         __cli();
133         while (1);
134 }
135
136 static void
137 menf1_power_off(void)
138 {
139         menf1_halt();
140 }
141
142 static void __init
143 menf1_init_IRQ(void)
144 {
145         int i;
146
147         for ( i = 0 ; i < NUM_8259_INTERRUPTS  ; i++ )
148                 irq_desc[i].handler = &i8259_pic;
149         i8259_init(0);
150 }
151
152 /*
153  * Set BAT 3 to map 0xF0000000.
154  */
155 static __inline__ void
156 menf1_set_bat(void)
157 {
158         static int      mapping_set = 0;
159
160         if (!mapping_set)
161         {
162
163                 /* wait for all outstanding memory accesses to complete */
164                 mb();
165
166                 /* setup DBATs */
167                 mtspr(DBAT3U, 0xf0001ffe);
168                 mtspr(DBAT3L, 0xf000002a);
169
170                 /* wait for updates */
171                 mb();
172
173                 mapping_set = 1;
174         }
175         return;
176 }
177
178 static unsigned long __init
179 menf1_find_end_of_memory(void)
180 {
181         /* Cover the I/O with a BAT */
182         menf1_set_bat();
183
184         /* Read the memory size from the MPC107 SMC */
185         return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
186 }
187
188 static void __init
189 menf1_map_io(void)
190 {
191         io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
192 }
193
194 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
195 /* IDE functions */
196 static void __init
197 menf1_ide_init_hwif_ports (hw_regs_t *hw, ide_ioreg_t data_port,
198                 ide_ioreg_t ctrl_port, int *irq)
199 {
200         ide_ioreg_t reg = data_port;
201         int i = 8;
202
203         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
204                 hw->io_ports[i] = reg;
205                 reg += 1;
206         }
207         if (ctrl_port)
208                 hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
209         else
210                 hw->io_ports[IDE_CONTROL_OFFSET] =
211                         hw->io_ports[IDE_DATA_OFFSET] + 0x206;
212
213         if (irq != NULL)
214                 *irq = 0;
215 }
216
217 static int
218 menf1_ide_default_irq(ide_ioreg_t base)
219 {
220         if (base == MENF1_IDE0_BASE_ADDR)
221                 return 14;
222         else if (base == MENF1_IDE1_BASE_ADDR)
223                 return 15;
224         else
225                 return 0;
226 }
227
228 static ide_ioreg_t
229 menf1_ide_default_io_base(int index)
230 {
231         if (index == 0)
232                 return MENF1_IDE0_BASE_ADDR;
233         else if (index == 1)
234                 return MENF1_IDE1_BASE_ADDR;
235         else
236                 return 0;
237 }
238 #endif
239
240 TODC_ALLOC();
241
242 void __init
243 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
244               unsigned long r6, unsigned long r7)
245 {
246         parse_bootinfo(find_bootinfo());
247
248         isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
249         isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
250         pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
251
252         ppc_md.setup_arch       = menf1_setup_arch;
253         ppc_md.show_cpuinfo     = menf1_show_cpuinfo;
254         ppc_md.init_IRQ         = menf1_init_IRQ;
255         ppc_md.get_irq          = i8259_irq;
256
257         ppc_md.find_end_of_memory = menf1_find_end_of_memory;
258         ppc_md.setup_io_mappings = menf1_map_io;
259
260         ppc_md.restart          = menf1_restart;
261         ppc_md.power_off        = menf1_power_off;
262         ppc_md.halt             = menf1_halt;
263
264         TODC_INIT(TODC_TYPE_MK48T59,
265                   MENF1_NVRAM_AS0,
266                   MENF1_NVRAM_AS1,
267                   MENF1_NVRAM_DATA,
268                   7);
269
270         ppc_md.time_init        = todc_time_init;
271         ppc_md.get_rtc_time     = todc_get_rtc_time;
272         ppc_md.set_rtc_time     = todc_set_rtc_time;
273         ppc_md.calibrate_decr   = todc_calibrate_decr;
274
275         ppc_md.nvram_read_val   = todc_m48txx_read_val;
276         ppc_md.nvram_write_val  = todc_m48txx_write_val;
277
278 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
279         ppc_ide_md.default_io_base = menf1_ide_default_io_base;
280         ppc_ide_md.default_irq = menf1_ide_default_irq;
281         ppc_ide_md.ide_init_hwif = menf1_ide_init_hwif_ports;
282 #endif
283 }