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