linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / arch / ppc / platforms / powerpmc250.c
1 /*
2  * arch/ppc/platforms/powerpmc250.c
3  *
4  * Board setup routines for Force PowerPMC-250 Processor PMC
5  *
6  * Author: Troy Benjegerdes <tbenjegerdes@mvista.com>
7  * Borrowed heavily from prpmc750_*.c by
8  *      Matt Porter <mporter@mvista.com>
9  *
10  * 2001 (c) MontaVista, Software, Inc.  This file is licensed under
11  * the terms of the GNU General Public License version 2.  This program
12  * is licensed "as is" without any warranty of any kind, whether express
13  * or implied.
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/initrd.h>
27 #include <linux/console.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/seq_file.h>
31 #include <linux/ide.h>
32 #include <linux/root_dev.h>
33
34 #include <asm/byteorder.h>
35 #include <asm/system.h>
36 #include <asm/pgtable.h>
37 #include <asm/page.h>
38 #include <asm/dma.h>
39 #include <asm/io.h>
40 #include <asm/irq.h>
41 #include <asm/machdep.h>
42 #include <asm/time.h>
43 #include <platforms/powerpmc250.h>
44 #include <asm/open_pic.h>
45 #include <asm/pci-bridge.h>
46 #include <asm/mpc10x.h>
47 #include <asm/uaccess.h>
48 #include <asm/bootinfo.h>
49
50 extern void powerpmc250_find_bridges(void);
51 extern unsigned long loops_per_jiffy;
52
53 static u_char powerpmc250_openpic_initsenses[] __initdata =
54 {
55     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56     1,  /* PMC INTA (also MPC107 output interrupt INTA) */
57     1,  /* PMC INTB (also I82559 Ethernet controller) */
58     1,  /* PMC INTC */
59     1,  /* PMC INTD */
60     0,  /* DUART interrupt (active high) */
61 };
62
63 static int
64 powerpmc250_show_cpuinfo(struct seq_file *m)
65 {
66         seq_printf(m,"machine\t\t: Force PowerPMC250\n");
67
68         return 0;
69 }
70
71 static void __init
72 powerpmc250_setup_arch(void)
73 {
74         /* init to some ~sane value until calibrate_delay() runs */
75         loops_per_jiffy = 50000000/HZ;
76
77         /* Lookup PCI host bridges */
78         powerpmc250_find_bridges();
79
80 #ifdef CONFIG_BLK_DEV_INITRD
81         if (initrd_start)
82                 ROOT_DEV = Root_RAM0;
83         else
84 #endif
85 #ifdef CONFIG_ROOT_NFS
86                 ROOT_DEV = Root_NFS;
87 #else
88                 ROOT_DEV = Root_SDA2;
89 #endif
90
91         printk("Force PowerPMC250 port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
92 }
93
94 #if 0
95 /*
96  * Compute the PrPMC750's bus speed using the baud clock as a
97  * reference.
98  */
99 unsigned long __init powerpmc250_get_bus_speed(void)
100 {
101         unsigned long tbl_start, tbl_end;
102         unsigned long current_state, old_state, bus_speed;
103         unsigned char lcr, dll, dlm;
104         int baud_divisor, count;
105
106         /* Read the UART's baud clock divisor */
107         lcr = readb(PRPMC750_SERIAL_0_LCR);
108         writeb(lcr | UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
109         dll = readb(PRPMC750_SERIAL_0_DLL);
110         dlm = readb(PRPMC750_SERIAL_0_DLM);
111         writeb(lcr & ~UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
112         baud_divisor = (dlm << 8) | dll;
113
114         /*
115          * Use the baud clock divisor and base baud clock
116          * to determine the baud rate and use that as
117          * the number of baud clock edges we use for
118          * the time base sample.  Make it half the baud
119          * rate.
120          */
121         count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
122
123         /* Find the first edge of the baud clock */
124         old_state = readb(PRPMC750_STATUS_REG) & PRPMC750_BAUDOUT_MASK;
125         do {
126                 current_state = readb(PRPMC750_STATUS_REG) &
127                         PRPMC750_BAUDOUT_MASK;
128         } while(old_state == current_state);
129
130         old_state = current_state;
131
132         /* Get the starting time base value */
133         tbl_start = get_tbl();
134
135         /*
136          * Loop until we have found a number of edges equal
137          * to half the count (half the baud rate)
138          */
139         do {
140                 do {
141                         current_state = readb(PRPMC750_STATUS_REG) &
142                                 PRPMC750_BAUDOUT_MASK;
143                 } while(old_state == current_state);
144                 old_state = current_state;
145         } while (--count);
146
147         /* Get the ending time base value */
148         tbl_end = get_tbl();
149
150         /* Compute bus speed */
151         bus_speed = (tbl_end-tbl_start)*128;
152
153         return bus_speed;
154 }
155 #endif
156
157 static void __init
158 powerpmc250_calibrate_decr(void)
159 {
160         unsigned long freq;
161         int divisor = 4;
162
163         //freq = powerpmc250_get_bus_speed();
164 #warning hardcoded bus freq
165         freq = 100000000;
166
167         tb_ticks_per_jiffy = freq / (HZ * divisor);
168         tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
169 }
170
171 static void
172 powerpmc250_restart(char *cmd)
173 {
174         local_irq_disable();
175         /* Hard reset */
176         writeb(0x11, 0xfe000332);
177         while(1);
178 }
179
180 static void
181 powerpmc250_halt(void)
182 {
183         local_irq_disable();
184         while (1);
185 }
186
187 static void
188 powerpmc250_power_off(void)
189 {
190         powerpmc250_halt();
191 }
192
193 static void __init
194 powerpmc250_init_IRQ(void)
195 {
196
197         OpenPIC_InitSenses = powerpmc250_openpic_initsenses;
198         OpenPIC_NumInitSenses = sizeof(powerpmc250_openpic_initsenses);
199         mpc10x_set_openpic();
200 }
201
202 /*
203  * Set BAT 3 to map 0xf0000000 to end of physical memory space.
204  */
205 static __inline__ void
206 powerpmc250_set_bat(void)
207 {
208         unsigned long   bat3u, bat3l;
209         static int      mapping_set = 0;
210
211         if (!mapping_set)
212         {
213                 __asm__ __volatile__(
214                                 " lis %0,0xf000\n \
215                                 ori %1,%0,0x002a\n \
216                                 ori %0,%0,0x1ffe\n \
217                                 mtspr 0x21e,%0\n \
218                                 mtspr 0x21f,%1\n \
219                                 isync\n \
220                                 sync "
221                                 : "=r" (bat3u), "=r" (bat3l));
222
223                 mapping_set = 1;
224         }
225         return;
226 }
227
228 static unsigned long __init
229 powerpmc250_find_end_of_memory(void)
230 {
231         /* Cover I/O space with a BAT */
232         /* yuck, better hope your ram size is a power of 2  -- paulus */
233         powerpmc250_set_bat();
234
235         return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
236 }
237
238 static void __init
239 powerpmc250_map_io(void)
240 {
241         io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
242 }
243
244 void __init
245 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
246               unsigned long r6, unsigned long r7)
247 {
248         parse_bootinfo(find_bootinfo());
249
250 #ifdef CONFIG_BLK_DEV_INITRD
251         if ( r4 )
252         {
253                 initrd_start = r4 + KERNELBASE;
254                 initrd_end = r5 + KERNELBASE;
255         }
256 #endif
257
258         /* Copy cmd_line parameters */
259         if ( r6)
260         {
261                 *(char *)(r7 + KERNELBASE) = 0;
262                 strcpy(cmd_line, (char *)(r6 + KERNELBASE));
263         }
264
265         isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
266         isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
267         pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
268
269         ppc_md.setup_arch       = powerpmc250_setup_arch;
270         ppc_md.show_cpuinfo     = powerpmc250_show_cpuinfo;
271         ppc_md.init_IRQ         = powerpmc250_init_IRQ;
272         ppc_md.get_irq          = openpic_get_irq;
273
274         ppc_md.find_end_of_memory = powerpmc250_find_end_of_memory;
275         ppc_md.setup_io_mappings = powerpmc250_map_io;
276
277         ppc_md.restart          = powerpmc250_restart;
278         ppc_md.power_off        = powerpmc250_power_off;
279         ppc_md.halt             = powerpmc250_halt;
280
281         /* PowerPMC250 has no timekeeper part */
282         ppc_md.time_init        = NULL;
283         ppc_md.get_rtc_time     = NULL;
284         ppc_md.set_rtc_time     = NULL;
285         ppc_md.calibrate_decr   = powerpmc250_calibrate_decr;
286 }
287
288
289 /*
290  * (This used to be arch/ppc/platforms/powerpmc250_pci.c)
291  *
292  * PCI support for Force PowerPMC250
293  *
294  */
295
296 #undef DEBUG
297 #ifdef DEBUG
298 #define DBG(x...) printk(x)
299 #else
300 #define DBG(x...)
301 #endif /* DEBUG */
302
303 static inline int __init
304 powerpmc250_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
305 {
306         static char pci_irq_table[][4] =
307         /*
308          *      PCI IDSEL/INTPIN->INTLINE
309          *      A       B       C       D
310          */
311         {
312                 {17,    0,      0,      0},     /* Device 11 - 82559 */
313                 {0,     0,      0,      0},     /* 12 */
314                 {0,     0,      0,      0},     /* 13 */
315                 {0,     0,      0,      0},     /* 14 */
316                 {0,     0,      0,      0},     /* 15 */
317                 {16,    17,     18,     19},    /* Device 16 - PMC A1?? */
318                 };
319         const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
320         return PCI_IRQ_TABLE_LOOKUP;
321 };
322
323 static int
324 powerpmc250_exclude_device(u_char bus, u_char devfn)
325 {
326         /*
327          * While doing PCI Scan  the MPC107 will 'detect' itself as
328          * device on the PCI Bus, will create an incorrect response and
329          * later will respond incorrectly to Configuration read coming
330          * from another device.
331          *
332          * The work around is that when doing a PCI Scan one
333          * should skip its own device number in the scan.
334          *
335          * The top IDsel is AD13 and the middle is AD14.
336          *
337          * -- Note from force
338          */
339
340         if ((bus == 0) && (PCI_SLOT(devfn) == 13 || PCI_SLOT(devfn) == 14)) {
341                 return PCIBIOS_DEVICE_NOT_FOUND;
342         }
343         else {
344                 return PCIBIOS_SUCCESSFUL;
345         }
346 }
347
348 void __init
349 powerpmc250_find_bridges(void)
350 {
351         struct pci_controller* hose;
352
353         hose = pcibios_alloc_controller();
354         if (!hose){
355                 printk("Can't allocate PCI 'hose' structure!!!\n");
356                 return;
357         }
358
359         hose->first_busno = 0;
360         hose->last_busno = 0xff;
361
362         if (mpc10x_bridge_init(hose,
363                         MPC10X_MEM_MAP_B,
364                         MPC10X_MEM_MAP_B,
365                         MPC10X_MAPB_EUMB_BASE) == 0) {
366
367                 hose->mem_resources[0].end = 0xffffffff;
368
369                 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
370
371                 /* ppc_md.pcibios_fixup = pcore_pcibios_fixup; */
372                 ppc_md.pci_swizzle = common_swizzle;
373
374                 ppc_md.pci_exclude_device = powerpmc250_exclude_device;
375                 ppc_md.pci_map_irq = powerpmc250_map_irq;
376         } else {
377                 if (ppc_md.progress)
378                         ppc_md.progress("Bridge init failed", 0x100);
379                 printk("Host bridge init failed\n");
380         }
381
382 }