]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/ppc/platforms/prpmc750.c
Linux-2.6.12-rc2
[mirror_ubuntu-hirsute-kernel.git] / arch / ppc / platforms / prpmc750.c
1 /*
2 * arch/ppc/platforms/prpmc750_setup.c
3 *
4 * Board setup routines for Motorola PrPMC750
5 *
6 * Author: Matt Porter <mporter@mvista.com>
7 *
8 * 2001-2004 (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.
12 */
13
14 #include <linux/config.h>
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/errno.h>
19 #include <linux/reboot.h>
20 #include <linux/pci.h>
21 #include <linux/kdev_t.h>
22 #include <linux/types.h>
23 #include <linux/major.h>
24 #include <linux/initrd.h>
25 #include <linux/console.h>
26 #include <linux/delay.h>
27 #include <linux/irq.h>
28 #include <linux/seq_file.h>
29 #include <linux/ide.h>
30 #include <linux/root_dev.h>
31 #include <linux/slab.h>
32
33 #include <asm/byteorder.h>
34 #include <asm/system.h>
35 #include <asm/pgtable.h>
36 #include <asm/page.h>
37 #include <asm/dma.h>
38 #include <asm/io.h>
39 #include <asm/irq.h>
40 #include <asm/machdep.h>
41 #include <asm/pci-bridge.h>
42 #include <asm/uaccess.h>
43 #include <asm/time.h>
44 #include <asm/open_pic.h>
45 #include <asm/bootinfo.h>
46 #include <asm/hawk.h>
47
48 #include "prpmc750.h"
49
50 extern unsigned long loops_per_jiffy;
51
52 extern void gen550_progress(char *, unsigned short);
53
54 static u_char prpmc750_openpic_initsenses[] __initdata =
55 {
56 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT0 */
57 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UART */
58 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_DEBUGINT */
59 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HAWK_WDT */
60 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
61 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_ABORT */
62 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT1 */
63 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT2 */
64 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT3 */
65 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTA */
66 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTB */
67 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTC */
68 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTD */
69 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
70 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
71 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
72 };
73
74 /*
75 * Motorola PrPMC750/PrPMC800 in PrPMCBASE or PrPMC-Carrier
76 * Combined irq tables. Only Base has IDSEL 14, only Carrier has 21 and 22.
77 */
78 static inline int
79 prpmc_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
80 {
81 static char pci_irq_table[][4] =
82 /*
83 * PCI IDSEL/INTPIN->INTLINE
84 * A B C D
85 */
86 {
87 {12, 0, 0, 0}, /* IDSEL 14 - Ethernet, base */
88 {0, 0, 0, 0}, /* IDSEL 15 - unused */
89 {10, 11, 12, 9}, /* IDSEL 16 - PMC A1, PMC1 */
90 {10, 11, 12, 9}, /* IDSEL 17 - PrPMC-A-B, PMC2-B */
91 {11, 12, 9, 10}, /* IDSEL 18 - PMC A1-B, PMC1-B */
92 {0, 0, 0, 0}, /* IDSEL 19 - unused */
93 {9, 10, 11, 12}, /* IDSEL 20 - P2P Bridge */
94 {11, 12, 9, 10}, /* IDSEL 21 - PMC A2, carrier */
95 {12, 9, 10, 11}, /* IDSEL 22 - PMC A2-B, carrier */
96 };
97 const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
98 return PCI_IRQ_TABLE_LOOKUP;
99 };
100
101 static void __init prpmc750_pcibios_fixup(void)
102 {
103 struct pci_dev *dev;
104 unsigned short wtmp;
105
106 /*
107 * Kludge to clean up after PPC6BUG which doesn't
108 * configure the CL5446 VGA card. Also the
109 * resource subsystem doesn't fixup the
110 * PCI mem resources on the CL5446.
111 */
112 if ((dev = pci_get_device(PCI_VENDOR_ID_CIRRUS,
113 PCI_DEVICE_ID_CIRRUS_5446, 0))) {
114 dev->resource[0].start += PRPMC750_PCI_PHY_MEM_OFFSET;
115 dev->resource[0].end += PRPMC750_PCI_PHY_MEM_OFFSET;
116 pci_read_config_word(dev, PCI_COMMAND, &wtmp);
117 pci_write_config_word(dev, PCI_COMMAND, wtmp | 3);
118 /* Enable Color mode in MISC reg */
119 outb(0x03, 0x3c2);
120 /* Select DRAM config reg */
121 outb(0x0f, 0x3c4);
122 /* Set proper DRAM config */
123 outb(0xdf, 0x3c5);
124 pci_dev_put(dev);
125 }
126 }
127
128 void __init prpmc750_find_bridges(void)
129 {
130 struct pci_controller *hose;
131
132 hose = pcibios_alloc_controller();
133 if (!hose)
134 return;
135
136 hose->first_busno = 0;
137 hose->last_busno = 0xff;
138 hose->io_base_virt = (void *)PRPMC750_ISA_IO_BASE;
139 hose->pci_mem_offset = PRPMC750_PCI_PHY_MEM_OFFSET;
140
141 pci_init_resource(&hose->io_resource,
142 PRPMC750_PCI_IO_START,
143 PRPMC750_PCI_IO_END,
144 IORESOURCE_IO, "PCI host bridge");
145
146 pci_init_resource(&hose->mem_resources[0],
147 PRPMC750_PROC_PCI_MEM_START,
148 PRPMC750_PROC_PCI_MEM_END,
149 IORESOURCE_MEM, "PCI host bridge");
150
151 hose->io_space.start = PRPMC750_PCI_IO_START;
152 hose->io_space.end = PRPMC750_PCI_IO_END;
153 hose->mem_space.start = PRPMC750_PCI_MEM_START;
154 hose->mem_space.end = PRPMC750_PCI_MEM_END - HAWK_MPIC_SIZE;
155
156 if (hawk_init(hose, PRPMC750_HAWK_PPC_REG_BASE,
157 PRPMC750_PROC_PCI_MEM_START,
158 PRPMC750_PROC_PCI_MEM_END - HAWK_MPIC_SIZE,
159 PRPMC750_PROC_PCI_IO_START, PRPMC750_PROC_PCI_IO_END,
160 PRPMC750_PROC_PCI_MEM_END - HAWK_MPIC_SIZE + 1)
161 != 0) {
162 printk(KERN_CRIT "Could not initialize host bridge\n");
163 }
164
165 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
166
167 ppc_md.pcibios_fixup = prpmc750_pcibios_fixup;
168 ppc_md.pci_swizzle = common_swizzle;
169 ppc_md.pci_map_irq = prpmc_map_irq;
170 }
171 static int prpmc750_show_cpuinfo(struct seq_file *m)
172 {
173 seq_printf(m, "machine\t\t: PrPMC750\n");
174
175 return 0;
176 }
177
178 static void __init prpmc750_setup_arch(void)
179 {
180 /* init to some ~sane value until calibrate_delay() runs */
181 loops_per_jiffy = 50000000 / HZ;
182
183 /* Lookup PCI host bridges */
184 prpmc750_find_bridges();
185
186 #ifdef CONFIG_BLK_DEV_INITRD
187 if (initrd_start)
188 ROOT_DEV = Root_RAM0;
189 else
190 #endif
191 #ifdef CONFIG_ROOT_NFS
192 ROOT_DEV = Root_NFS;
193 #else
194 ROOT_DEV = Root_SDA2;
195 #endif
196
197 OpenPIC_InitSenses = prpmc750_openpic_initsenses;
198 OpenPIC_NumInitSenses = sizeof(prpmc750_openpic_initsenses);
199
200 printk(KERN_INFO "Port by MontaVista Software, Inc. "
201 "(source@mvista.com)\n");
202 }
203
204 /*
205 * Compute the PrPMC750's bus speed using the baud clock as a
206 * reference.
207 */
208 static unsigned long __init prpmc750_get_bus_speed(void)
209 {
210 unsigned long tbl_start, tbl_end;
211 unsigned long current_state, old_state, bus_speed;
212 unsigned char lcr, dll, dlm;
213 int baud_divisor, count;
214
215 /* Read the UART's baud clock divisor */
216 lcr = readb(PRPMC750_SERIAL_0_LCR);
217 writeb(lcr | UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
218 dll = readb(PRPMC750_SERIAL_0_DLL);
219 dlm = readb(PRPMC750_SERIAL_0_DLM);
220 writeb(lcr & ~UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
221 baud_divisor = (dlm << 8) | dll;
222
223 /*
224 * Use the baud clock divisor and base baud clock
225 * to determine the baud rate and use that as
226 * the number of baud clock edges we use for
227 * the time base sample. Make it half the baud
228 * rate.
229 */
230 count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
231
232 /* Find the first edge of the baud clock */
233 old_state = readb(PRPMC750_STATUS_REG) & PRPMC750_BAUDOUT_MASK;
234 do {
235 current_state = readb(PRPMC750_STATUS_REG) &
236 PRPMC750_BAUDOUT_MASK;
237 } while (old_state == current_state);
238
239 old_state = current_state;
240
241 /* Get the starting time base value */
242 tbl_start = get_tbl();
243
244 /*
245 * Loop until we have found a number of edges equal
246 * to half the count (half the baud rate)
247 */
248 do {
249 do {
250 current_state = readb(PRPMC750_STATUS_REG) &
251 PRPMC750_BAUDOUT_MASK;
252 } while (old_state == current_state);
253 old_state = current_state;
254 } while (--count);
255
256 /* Get the ending time base value */
257 tbl_end = get_tbl();
258
259 /* Compute bus speed */
260 bus_speed = (tbl_end - tbl_start) * 128;
261
262 return bus_speed;
263 }
264
265 static void __init prpmc750_calibrate_decr(void)
266 {
267 unsigned long freq;
268 int divisor = 4;
269
270 freq = prpmc750_get_bus_speed();
271
272 tb_ticks_per_jiffy = freq / (HZ * divisor);
273 tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
274 }
275
276 static void prpmc750_restart(char *cmd)
277 {
278 local_irq_disable();
279 writeb(PRPMC750_MODRST_MASK, PRPMC750_MODRST_REG);
280 while (1) ;
281 }
282
283 static void prpmc750_halt(void)
284 {
285 local_irq_disable();
286 while (1) ;
287 }
288
289 static void prpmc750_power_off(void)
290 {
291 prpmc750_halt();
292 }
293
294 static void __init prpmc750_init_IRQ(void)
295 {
296 openpic_init(0);
297 }
298
299 /*
300 * Set BAT 3 to map 0xf0000000 to end of physical memory space.
301 */
302 static __inline__ void prpmc750_set_bat(void)
303 {
304 mb();
305 mtspr(SPRN_DBAT1U, 0xf0001ffe);
306 mtspr(SPRN_DBAT1L, 0xf000002a);
307 mb();
308 }
309
310 /*
311 * We need to read the Falcon/Hawk memory controller
312 * to properly determine this value
313 */
314 static unsigned long __init prpmc750_find_end_of_memory(void)
315 {
316 /* Read the memory size from the Hawk SMC */
317 return hawk_get_mem_size(PRPMC750_HAWK_SMC_BASE);
318 }
319
320 static void __init prpmc750_map_io(void)
321 {
322 io_block_mapping(PRPMC750_ISA_IO_BASE, PRPMC750_ISA_IO_BASE,
323 0x10000000, _PAGE_IO);
324 #if 0
325 io_block_mapping(0xf0000000, 0xc0000000, 0x08000000, _PAGE_IO);
326 #endif
327 io_block_mapping(0xf8000000, 0xf8000000, 0x08000000, _PAGE_IO);
328 }
329
330 void __init
331 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
332 unsigned long r6, unsigned long r7)
333 {
334 parse_bootinfo(find_bootinfo());
335
336 /* Cover the Hawk registers with a BAT */
337 prpmc750_set_bat();
338
339 isa_io_base = PRPMC750_ISA_IO_BASE;
340 isa_mem_base = PRPMC750_ISA_MEM_BASE;
341 pci_dram_offset = PRPMC750_PCI_DRAM_OFFSET;
342
343 ppc_md.setup_arch = prpmc750_setup_arch;
344 ppc_md.show_cpuinfo = prpmc750_show_cpuinfo;
345 ppc_md.init_IRQ = prpmc750_init_IRQ;
346 ppc_md.get_irq = openpic_get_irq;
347
348 ppc_md.find_end_of_memory = prpmc750_find_end_of_memory;
349 ppc_md.setup_io_mappings = prpmc750_map_io;
350
351 ppc_md.restart = prpmc750_restart;
352 ppc_md.power_off = prpmc750_power_off;
353 ppc_md.halt = prpmc750_halt;
354
355 /* PrPMC750 has no timekeeper part */
356 ppc_md.time_init = NULL;
357 ppc_md.get_rtc_time = NULL;
358 ppc_md.set_rtc_time = NULL;
359 ppc_md.calibrate_decr = prpmc750_calibrate_decr;
360
361 #ifdef CONFIG_SERIAL_TEXT_DEBUG
362 ppc_md.progress = gen550_progress;
363 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
364 }