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