2 * arch/ppc/platforms/prpmc800.c
4 * Author: Dale Farnsworth <dale.farnsworth@mvista.com>
6 * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
12 #include <linux/config.h>
13 #include <linux/stddef.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/errno.h>
17 #include <linux/reboot.h>
18 #include <linux/pci.h>
19 #include <linux/kdev_t.h>
20 #include <linux/types.h>
21 #include <linux/major.h>
22 #include <linux/initrd.h>
23 #include <linux/console.h>
24 #include <linux/delay.h>
25 #include <linux/irq.h>
26 #include <linux/seq_file.h>
27 #include <linux/ide.h>
28 #include <linux/root_dev.h>
29 #include <linux/harrier_defs.h>
31 #include <asm/byteorder.h>
32 #include <asm/system.h>
33 #include <asm/pgtable.h>
38 #include <asm/machdep.h>
40 #include <asm/pci-bridge.h>
41 #include <asm/open_pic.h>
42 #include <asm/bootinfo.h>
43 #include <asm/harrier.h>
47 #define HARRIER_REVI_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_REVI_OFF)
48 #define HARRIER_UCTL_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_UCTL_OFF)
49 #define HARRIER_MISC_CSR_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_MISC_CSR_OFF)
50 #define HARRIER_IFEVP_REG (PRPMC800_HARRIER_MPIC_BASE+HARRIER_MPIC_IFEVP_OFF)
51 #define HARRIER_IFEDE_REG (PRPMC800_HARRIER_MPIC_BASE+HARRIER_MPIC_IFEDE_OFF)
52 #define HARRIER_FEEN_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_FEEN_OFF)
53 #define HARRIER_FEMA_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_FEMA_OFF)
55 #define HARRIER_VENI_REG (PRPMC800_HARRIER_XCSR_BASE + HARRIER_VENI_OFF)
56 #define HARRIER_MISC_CSR (PRPMC800_HARRIER_XCSR_BASE + \
59 #define MONARCH (monarch != 0)
60 #define NON_MONARCH (monarch == 0)
62 extern int mpic_init(void);
63 extern unsigned long loops_per_jiffy;
64 extern void gen550_progress(char *, unsigned short);
66 static int monarch = 0;
67 static int found_self = 0;
70 static u_char prpmc800_openpic_initsenses[] __initdata =
72 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT0 */
73 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
74 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_DEBUGINT */
75 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HARRIER_WDT */
76 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
77 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
78 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT1 */
79 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT2 */
80 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT3 */
81 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTA */
82 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTB */
83 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTC */
84 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTD */
85 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
86 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
87 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
88 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HARRIER_INT (UARTS, ABORT, DMA) */
92 * Motorola PrPMC750/PrPMC800 in PrPMCBASE or PrPMC-Carrier
93 * Combined irq tables. Only Base has IDSEL 14, only Carrier has 21 and 22.
96 prpmc_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
98 static char pci_irq_table[][4] =
100 * PCI IDSEL/INTPIN->INTLINE
104 {12, 0, 0, 0}, /* IDSEL 14 - Ethernet, base */
105 {0, 0, 0, 0}, /* IDSEL 15 - unused */
106 {10, 11, 12, 9}, /* IDSEL 16 - PMC A1, PMC1 */
107 {10, 11, 12, 9}, /* IDSEL 17 - PrPMC-A-B, PMC2-B */
108 {11, 12, 9, 10}, /* IDSEL 18 - PMC A1-B, PMC1-B */
109 {0, 0, 0, 0}, /* IDSEL 19 - unused */
110 {9, 10, 11, 12}, /* IDSEL 20 - P2P Bridge */
111 {11, 12, 9, 10}, /* IDSEL 21 - PMC A2, carrier */
112 {12, 9, 10, 11}, /* IDSEL 22 - PMC A2-B, carrier */
114 const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
115 return PCI_IRQ_TABLE_LOOKUP;
119 prpmc_read_config_dword(struct pci_controller *hose, u8 bus, u8 devfn,
120 int offset, u32 * val)
123 if ((hose == NULL) ||
124 (hose->cfg_addr == NULL) || (hose->cfg_data == NULL))
125 return PCIBIOS_DEVICE_NOT_FOUND;
127 out_be32(hose->cfg_addr, ((offset & 0xfc) << 24) | (devfn << 16)
128 | ((bus - hose->bus_offset) << 8) | 0x80);
129 *val = in_le32((u32 *) (hose->cfg_data + (offset & 3)));
131 return PCIBIOS_SUCCESSFUL;
134 #define HARRIER_PCI_VEND_DEV_ID (PCI_VENDOR_ID_MOTOROLA | \
135 (PCI_DEVICE_ID_MOTOROLA_HARRIER << 16))
136 static int prpmc_self(u8 bus, u8 devfn)
139 * Harriers always view themselves as being on bus 0. If we're not
140 * looking at bus 0, we're not going to find ourselves.
143 return PCIBIOS_DEVICE_NOT_FOUND;
147 struct pci_controller *hose;
149 hose = pci_bus_to_hose(bus);
151 /* See if target device is a Harrier */
152 result = prpmc_read_config_dword(hose, bus, devfn,
153 PCI_VENDOR_ID, &val);
154 if ((result != PCIBIOS_SUCCESSFUL) ||
155 (val != HARRIER_PCI_VEND_DEV_ID))
156 return PCIBIOS_DEVICE_NOT_FOUND;
159 * LBA bit is set if target Harrier == initiating Harrier
160 * (i.e. if we are reading our own PCI header).
162 result = prpmc_read_config_dword(hose, bus, devfn,
163 HARRIER_LBA_OFF, &val);
164 if ((result != PCIBIOS_SUCCESSFUL) ||
165 ((val & HARRIER_LBA_MSK) != HARRIER_LBA_MSK))
166 return PCIBIOS_DEVICE_NOT_FOUND;
168 /* It's us, save our location for later */
171 return PCIBIOS_SUCCESSFUL;
175 static int prpmc_exclude_device(u8 bus, u8 devfn)
178 * Monarch is allowed to access all PCI devices. Non-monarch is
179 * only allowed to access its own Harrier.
183 return PCIBIOS_SUCCESSFUL;
185 if ((bus == 0) && (devfn == self))
186 return PCIBIOS_SUCCESSFUL;
188 return PCIBIOS_DEVICE_NOT_FOUND;
190 return prpmc_self(bus, devfn);
193 void __init prpmc800_find_bridges(void)
195 struct pci_controller *hose;
198 hose = pcibios_alloc_controller();
202 hose->first_busno = 0;
203 hose->last_busno = 0xff;
205 ppc_md.pci_exclude_device = prpmc_exclude_device;
206 ppc_md.pcibios_fixup = NULL;
207 ppc_md.pcibios_fixup_bus = NULL;
208 ppc_md.pci_swizzle = common_swizzle;
209 ppc_md.pci_map_irq = prpmc_map_irq;
211 setup_indirect_pci(hose,
212 PRPMC800_PCI_CONFIG_ADDR, PRPMC800_PCI_CONFIG_DATA);
214 /* Get host bridge vendor/dev id */
216 host_bridge = in_be32((uint *) (HARRIER_VENI_REG));
218 if (host_bridge != HARRIER_VEND_DEV_ID) {
219 printk(KERN_CRIT "Host bridge 0x%x not supported\n",
224 monarch = in_be32((uint *) HARRIER_MISC_CSR) & HARRIER_SYSCON;
226 printk(KERN_INFO "Running as %s.\n",
227 MONARCH ? "Monarch" : "Non-Monarch");
229 hose->io_space.start = PRPMC800_PCI_IO_START;
230 hose->io_space.end = PRPMC800_PCI_IO_END;
231 hose->io_base_virt = (void *)PRPMC800_ISA_IO_BASE;
232 hose->pci_mem_offset = PRPMC800_PCI_PHY_MEM_OFFSET;
234 pci_init_resource(&hose->io_resource,
235 PRPMC800_PCI_IO_START, PRPMC800_PCI_IO_END,
236 IORESOURCE_IO, "PCI host bridge");
239 hose->mem_space.start = PRPMC800_PCI_MEM_START;
240 hose->mem_space.end = PRPMC800_PCI_MEM_END;
242 pci_init_resource(&hose->mem_resources[0],
243 PRPMC800_PCI_MEM_START,
244 PRPMC800_PCI_MEM_END,
245 IORESOURCE_MEM, "PCI host bridge");
247 if (harrier_init(hose,
248 PRPMC800_HARRIER_XCSR_BASE,
249 PRPMC800_PROC_PCI_MEM_START,
250 PRPMC800_PROC_PCI_MEM_END,
251 PRPMC800_PROC_PCI_IO_START,
252 PRPMC800_PROC_PCI_IO_END,
253 PRPMC800_HARRIER_MPIC_BASE) != 0)
254 printk(KERN_CRIT "Could not initialize HARRIER "
257 harrier_release_eready(PRPMC800_HARRIER_XCSR_BASE);
258 harrier_wait_eready(PRPMC800_HARRIER_XCSR_BASE);
259 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
262 pci_init_resource(&hose->mem_resources[0],
263 PRPMC800_NM_PCI_MEM_START,
264 PRPMC800_NM_PCI_MEM_END,
265 IORESOURCE_MEM, "PCI host bridge");
267 hose->mem_space.start = PRPMC800_NM_PCI_MEM_START;
268 hose->mem_space.end = PRPMC800_NM_PCI_MEM_END;
270 if (harrier_init(hose,
271 PRPMC800_HARRIER_XCSR_BASE,
272 PRPMC800_NM_PROC_PCI_MEM_START,
273 PRPMC800_NM_PROC_PCI_MEM_END,
274 PRPMC800_PROC_PCI_IO_START,
275 PRPMC800_PROC_PCI_IO_END,
276 PRPMC800_HARRIER_MPIC_BASE) != 0)
277 printk(KERN_CRIT "Could not initialize HARRIER "
280 harrier_setup_nonmonarch(PRPMC800_HARRIER_XCSR_BASE,
282 harrier_release_eready(PRPMC800_HARRIER_XCSR_BASE);
286 static int prpmc800_show_cpuinfo(struct seq_file *m)
288 seq_printf(m, "machine\t\t: PrPMC800\n");
293 static void __init prpmc800_setup_arch(void)
295 /* init to some ~sane value until calibrate_delay() runs */
296 loops_per_jiffy = 50000000 / HZ;
298 /* Lookup PCI host bridges */
299 prpmc800_find_bridges();
301 #ifdef CONFIG_BLK_DEV_INITRD
303 ROOT_DEV = Root_RAM0;
306 #ifdef CONFIG_ROOT_NFS
309 ROOT_DEV = Root_SDA2;
312 printk(KERN_INFO "Port by MontaVista Software, Inc. "
313 "(source@mvista.com)\n");
317 * Compute the PrPMC800's tbl frequency using the baud clock as a reference.
319 static void __init prpmc800_calibrate_decr(void)
321 unsigned long tbl_start, tbl_end;
322 unsigned long current_state, old_state, tb_ticks_per_second;
324 unsigned int harrier_revision;
326 harrier_revision = readb(HARRIER_REVI_REG);
327 if (harrier_revision < 2) {
328 /* XTAL64 was broken in harrier revision 1 */
329 printk(KERN_INFO "time_init: Harrier revision %d, assuming "
330 "100 Mhz bus\n", harrier_revision);
331 tb_ticks_per_second = 100000000 / 4;
332 tb_ticks_per_jiffy = tb_ticks_per_second / HZ;
333 tb_to_us = mulhwu_scale_factor(tb_ticks_per_second, 1000000);
338 * The XTAL64 bit oscillates at the 1/64 the base baud clock
339 * Set count to XTAL64 cycles per second. Since we'll count
340 * half-cycles, we'll reach the count in half a second.
342 count = PRPMC800_BASE_BAUD / 64;
344 /* Find the first edge of the baud clock */
345 old_state = readb(HARRIER_UCTL_REG) & HARRIER_XTAL64_MASK;
347 current_state = readb(HARRIER_UCTL_REG) & HARRIER_XTAL64_MASK;
348 } while (old_state == current_state);
350 old_state = current_state;
352 /* Get the starting time base value */
353 tbl_start = get_tbl();
356 * Loop until we have found a number of edges (half-cycles)
357 * equal to the count (half a second)
361 current_state = readb(HARRIER_UCTL_REG) &
363 } while (old_state == current_state);
364 old_state = current_state;
367 /* Get the ending time base value */
370 /* We only counted for half a second, so double to get ticks/second */
371 tb_ticks_per_second = (tbl_end - tbl_start) * 2;
372 tb_ticks_per_jiffy = tb_ticks_per_second / HZ;
373 tb_to_us = mulhwu_scale_factor(tb_ticks_per_second, 1000000);
376 static void prpmc800_restart(char *cmd)
381 temp = in_be32((uint *) HARRIER_MISC_CSR_REG);
382 temp |= HARRIER_RSTOUT;
383 out_be32((uint *) HARRIER_MISC_CSR_REG, temp);
387 static void prpmc800_halt(void)
393 static void prpmc800_power_off(void)
398 static void __init prpmc800_init_IRQ(void)
400 OpenPIC_InitSenses = prpmc800_openpic_initsenses;
401 OpenPIC_NumInitSenses = sizeof(prpmc800_openpic_initsenses);
403 /* Setup external interrupt sources. */
404 openpic_set_sources(0, 16, OpenPIC_Addr + 0x10000);
405 /* Setup internal UART interrupt source. */
406 openpic_set_sources(16, 1, OpenPIC_Addr + 0x10200);
408 /* Do the MPIC initialization based on the above settings. */
411 /* enable functional exceptions for uarts and abort */
412 out_8((u8 *) HARRIER_FEEN_REG, (HARRIER_FE_UA0 | HARRIER_FE_UA1));
413 out_8((u8 *) HARRIER_FEMA_REG, ~(HARRIER_FE_UA0 | HARRIER_FE_UA1));
417 * Set BAT 3 to map 0xf0000000 to end of physical memory space.
419 static __inline__ void prpmc800_set_bat(void)
422 mtspr(SPRN_DBAT1U, 0xf0001ffe);
423 mtspr(SPRN_DBAT1L, 0xf000002a);
428 * We need to read the Harrier memory controller
429 * to properly determine this value
431 static unsigned long __init prpmc800_find_end_of_memory(void)
433 /* Read the memory size from the Harrier XCSR */
434 return harrier_get_mem_size(PRPMC800_HARRIER_XCSR_BASE);
437 static void __init prpmc800_map_io(void)
439 io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO);
440 io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
444 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
445 unsigned long r6, unsigned long r7)
447 parse_bootinfo(find_bootinfo());
451 isa_io_base = PRPMC800_ISA_IO_BASE;
452 isa_mem_base = PRPMC800_ISA_MEM_BASE;
453 pci_dram_offset = PRPMC800_PCI_DRAM_OFFSET;
455 ppc_md.setup_arch = prpmc800_setup_arch;
456 ppc_md.show_cpuinfo = prpmc800_show_cpuinfo;
457 ppc_md.init_IRQ = prpmc800_init_IRQ;
458 ppc_md.get_irq = openpic_get_irq;
460 ppc_md.find_end_of_memory = prpmc800_find_end_of_memory;
461 ppc_md.setup_io_mappings = prpmc800_map_io;
463 ppc_md.restart = prpmc800_restart;
464 ppc_md.power_off = prpmc800_power_off;
465 ppc_md.halt = prpmc800_halt;
467 /* PrPMC800 has no timekeeper part */
468 ppc_md.time_init = NULL;
469 ppc_md.get_rtc_time = NULL;
470 ppc_md.set_rtc_time = NULL;
471 ppc_md.calibrate_decr = prpmc800_calibrate_decr;
472 #ifdef CONFIG_SERIAL_TEXT_DEBUG
473 ppc_md.progress = gen550_progress;
474 #else /* !CONFIG_SERIAL_TEXT_DEBUG */
475 ppc_md.progress = NULL;
476 #endif /* CONFIG_SERIAL_TEXT_DEBUG */