Linux-2.6.12-rc2
[linux-2.6/next.git] / arch / ppc / platforms / powerpmc250.c
blob0abe15159e6ca2cfd804444b8eca5e882593cf5b
1 /*
2 * arch/ppc/platforms/powerpmc250.c
4 * Board setup routines for Force PowerPMC-250 Processor PMC
6 * Author: Troy Benjegerdes <tbenjegerdes@mvista.com>
7 * Borrowed heavily from prpmc750_*.c by
8 * Matt Porter <mporter@mvista.com>
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.
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>
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>
51 extern void powerpmc250_find_bridges(void);
52 extern unsigned long loops_per_jiffy;
54 static u_char powerpmc250_openpic_initsenses[] __initdata =
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) */
64 static int
65 powerpmc250_show_cpuinfo(struct seq_file *m)
67 seq_printf(m,"machine\t\t: Force PowerPMC250\n");
69 return 0;
72 static void __init
73 powerpmc250_setup_arch(void)
75 /* init to some ~sane value until calibrate_delay() runs */
76 loops_per_jiffy = 50000000/HZ;
78 /* Lookup PCI host bridges */
79 powerpmc250_find_bridges();
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
92 printk("Force PowerPMC250 port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
95 #if 0
97 * Compute the PrPMC750's bus speed using the baud clock as a
98 * reference.
100 unsigned long __init powerpmc250_get_bus_speed(void)
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;
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;
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.
122 count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
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);
131 old_state = current_state;
133 /* Get the starting time base value */
134 tbl_start = get_tbl();
137 * Loop until we have found a number of edges equal
138 * to half the count (half the baud rate)
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);
148 /* Get the ending time base value */
149 tbl_end = get_tbl();
151 /* Compute bus speed */
152 bus_speed = (tbl_end-tbl_start)*128;
154 return bus_speed;
156 #endif
158 static void __init
159 powerpmc250_calibrate_decr(void)
161 unsigned long freq;
162 int divisor = 4;
164 //freq = powerpmc250_get_bus_speed();
165 #warning hardcoded bus freq
166 freq = 100000000;
168 tb_ticks_per_jiffy = freq / (HZ * divisor);
169 tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
172 static void
173 powerpmc250_restart(char *cmd)
175 local_irq_disable();
176 /* Hard reset */
177 writeb(0x11, 0xfe000332);
178 while(1);
181 static void
182 powerpmc250_halt(void)
184 local_irq_disable();
185 while (1);
188 static void
189 powerpmc250_power_off(void)
191 powerpmc250_halt();
194 static void __init
195 powerpmc250_init_IRQ(void)
198 OpenPIC_InitSenses = powerpmc250_openpic_initsenses;
199 OpenPIC_NumInitSenses = sizeof(powerpmc250_openpic_initsenses);
200 mpc10x_set_openpic();
204 * Set BAT 3 to map 0xf0000000 to end of physical memory space.
206 static __inline__ void
207 powerpmc250_set_bat(void)
209 unsigned long bat3u, bat3l;
210 static int mapping_set = 0;
212 if (!mapping_set)
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));
224 mapping_set = 1;
226 return;
229 static unsigned long __init
230 powerpmc250_find_end_of_memory(void)
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();
236 return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
239 static void __init
240 powerpmc250_map_io(void)
242 io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
245 void __init
246 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
247 unsigned long r6, unsigned long r7)
249 parse_bootinfo(find_bootinfo());
251 #ifdef CONFIG_BLK_DEV_INITRD
252 if ( r4 )
254 initrd_start = r4 + KERNELBASE;
255 initrd_end = r5 + KERNELBASE;
257 #endif
259 /* Copy cmd_line parameters */
260 if ( r6)
262 *(char *)(r7 + KERNELBASE) = 0;
263 strcpy(cmd_line, (char *)(r6 + KERNELBASE));
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;
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;
275 ppc_md.find_end_of_memory = powerpmc250_find_end_of_memory;
276 ppc_md.setup_io_mappings = powerpmc250_map_io;
278 ppc_md.restart = powerpmc250_restart;
279 ppc_md.power_off = powerpmc250_power_off;
280 ppc_md.halt = powerpmc250_halt;
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;
291 * (This used to be arch/ppc/platforms/powerpmc250_pci.c)
293 * PCI support for Force PowerPMC250
297 #undef DEBUG
298 #ifdef DEBUG
299 #define DBG(x...) printk(x)
300 #else
301 #define DBG(x...)
302 #endif /* DEBUG */
304 static inline int __init
305 powerpmc250_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
307 static char pci_irq_table[][4] =
309 * PCI IDSEL/INTPIN->INTLINE
310 * A B C D
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?? */
320 const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
321 return PCI_IRQ_TABLE_LOOKUP;
324 static int
325 powerpmc250_exclude_device(u_char bus, u_char devfn)
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.
333 * The work around is that when doing a PCI Scan one
334 * should skip its own device number in the scan.
336 * The top IDsel is AD13 and the middle is AD14.
338 * -- Note from force
341 if ((bus == 0) && (PCI_SLOT(devfn) == 13 || PCI_SLOT(devfn) == 14)) {
342 return PCIBIOS_DEVICE_NOT_FOUND;
344 else {
345 return PCIBIOS_SUCCESSFUL;
349 void __init
350 powerpmc250_find_bridges(void)
352 struct pci_controller* hose;
354 hose = pcibios_alloc_controller();
355 if (!hose){
356 printk("Can't allocate PCI 'hose' structure!!!\n");
357 return;
360 hose->first_busno = 0;
361 hose->last_busno = 0xff;
363 if (mpc10x_bridge_init(hose,
364 MPC10X_MEM_MAP_B,
365 MPC10X_MEM_MAP_B,
366 MPC10X_MAPB_EUMB_BASE) == 0) {
368 hose->mem_resources[0].end = 0xffffffff;
370 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
372 /* ppc_md.pcibios_fixup = pcore_pcibios_fixup; */
373 ppc_md.pci_swizzle = common_swizzle;
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");