2 * Author: Dale Farnsworth <dale.farnsworth@mvista.com>
4 * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
5 * the terms of the GNU General Public License version 2. This program
6 * is licensed "as is" without any warranty of any kind, whether express
10 #include <linux/stddef.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/errno.h>
14 #include <linux/reboot.h>
15 #include <linux/pci.h>
16 #include <linux/kdev_t.h>
17 #include <linux/types.h>
18 #include <linux/major.h>
19 #include <linux/initrd.h>
20 #include <linux/console.h>
21 #include <linux/delay.h>
22 #include <linux/seq_file.h>
23 #include <linux/ide.h>
24 #include <linux/root_dev.h>
25 #include <linux/harrier_defs.h>
27 #include <asm/byteorder.h>
28 #include <asm/system.h>
29 #include <asm/pgtable.h>
34 #include <asm/machdep.h>
36 #include <asm/pci-bridge.h>
37 #include <asm/open_pic.h>
38 #include <asm/bootinfo.h>
39 #include <asm/harrier.h>
43 #define HARRIER_REVI_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_REVI_OFF)
44 #define HARRIER_UCTL_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_UCTL_OFF)
45 #define HARRIER_MISC_CSR_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_MISC_CSR_OFF)
46 #define HARRIER_IFEVP_REG (PRPMC800_HARRIER_MPIC_BASE+HARRIER_MPIC_IFEVP_OFF)
47 #define HARRIER_IFEDE_REG (PRPMC800_HARRIER_MPIC_BASE+HARRIER_MPIC_IFEDE_OFF)
48 #define HARRIER_FEEN_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_FEEN_OFF)
49 #define HARRIER_FEMA_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_FEMA_OFF)
51 #define HARRIER_VENI_REG (PRPMC800_HARRIER_XCSR_BASE + HARRIER_VENI_OFF)
52 #define HARRIER_MISC_CSR (PRPMC800_HARRIER_XCSR_BASE + \
55 #define MONARCH (monarch != 0)
56 #define NON_MONARCH (monarch == 0)
58 extern int mpic_init(void);
59 extern unsigned long loops_per_jiffy
;
60 extern void gen550_progress(char *, unsigned short);
62 static int monarch
= 0;
63 static int found_self
= 0;
66 static u_char prpmc800_openpic_initsenses
[] __initdata
=
68 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_HOSTINT0 */
69 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_UNUSED */
70 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_DEBUGINT */
71 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_HARRIER_WDT */
72 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_UNUSED */
73 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_UNUSED */
74 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_HOSTINT1 */
75 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_HOSTINT2 */
76 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_HOSTINT3 */
77 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_PMC_INTA */
78 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_PMC_INTB */
79 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_PMC_INTC */
80 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_PMC_INTD */
81 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_UNUSED */
82 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_UNUSED */
83 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_UNUSED */
84 (IRQ_SENSE_LEVEL
| IRQ_POLARITY_NEGATIVE
), /* PRPMC800_INT_HARRIER_INT (UARTS, ABORT, DMA) */
88 * Motorola PrPMC750/PrPMC800 in PrPMCBASE or PrPMC-Carrier
89 * Combined irq tables. Only Base has IDSEL 14, only Carrier has 21 and 22.
92 prpmc_map_irq(struct pci_dev
*dev
, unsigned char idsel
, unsigned char pin
)
94 static char pci_irq_table
[][4] =
96 * PCI IDSEL/INTPIN->INTLINE
100 {12, 0, 0, 0}, /* IDSEL 14 - Ethernet, base */
101 {0, 0, 0, 0}, /* IDSEL 15 - unused */
102 {10, 11, 12, 9}, /* IDSEL 16 - PMC A1, PMC1 */
103 {10, 11, 12, 9}, /* IDSEL 17 - PrPMC-A-B, PMC2-B */
104 {11, 12, 9, 10}, /* IDSEL 18 - PMC A1-B, PMC1-B */
105 {0, 0, 0, 0}, /* IDSEL 19 - unused */
106 {9, 10, 11, 12}, /* IDSEL 20 - P2P Bridge */
107 {11, 12, 9, 10}, /* IDSEL 21 - PMC A2, carrier */
108 {12, 9, 10, 11}, /* IDSEL 22 - PMC A2-B, carrier */
110 const long min_idsel
= 14, max_idsel
= 22, irqs_per_slot
= 4;
111 return PCI_IRQ_TABLE_LOOKUP
;
115 prpmc_read_config_dword(struct pci_controller
*hose
, u8 bus
, u8 devfn
,
116 int offset
, u32
* val
)
119 if ((hose
== NULL
) ||
120 (hose
->cfg_addr
== NULL
) || (hose
->cfg_data
== NULL
))
121 return PCIBIOS_DEVICE_NOT_FOUND
;
123 out_be32(hose
->cfg_addr
, ((offset
& 0xfc) << 24) | (devfn
<< 16)
124 | ((bus
- hose
->bus_offset
) << 8) | 0x80);
125 *val
= in_le32((u32
*) (hose
->cfg_data
+ (offset
& 3)));
127 return PCIBIOS_SUCCESSFUL
;
130 #define HARRIER_PCI_VEND_DEV_ID (PCI_VENDOR_ID_MOTOROLA | \
131 (PCI_DEVICE_ID_MOTOROLA_HARRIER << 16))
132 static int prpmc_self(u8 bus
, u8 devfn
)
135 * Harriers always view themselves as being on bus 0. If we're not
136 * looking at bus 0, we're not going to find ourselves.
139 return PCIBIOS_DEVICE_NOT_FOUND
;
143 struct pci_controller
*hose
;
145 hose
= pci_bus_to_hose(bus
);
147 /* See if target device is a Harrier */
148 result
= prpmc_read_config_dword(hose
, bus
, devfn
,
149 PCI_VENDOR_ID
, &val
);
150 if ((result
!= PCIBIOS_SUCCESSFUL
) ||
151 (val
!= HARRIER_PCI_VEND_DEV_ID
))
152 return PCIBIOS_DEVICE_NOT_FOUND
;
155 * LBA bit is set if target Harrier == initiating Harrier
156 * (i.e. if we are reading our own PCI header).
158 result
= prpmc_read_config_dword(hose
, bus
, devfn
,
159 HARRIER_LBA_OFF
, &val
);
160 if ((result
!= PCIBIOS_SUCCESSFUL
) ||
161 ((val
& HARRIER_LBA_MSK
) != HARRIER_LBA_MSK
))
162 return PCIBIOS_DEVICE_NOT_FOUND
;
164 /* It's us, save our location for later */
167 return PCIBIOS_SUCCESSFUL
;
171 static int prpmc_exclude_device(u8 bus
, u8 devfn
)
174 * Monarch is allowed to access all PCI devices. Non-monarch is
175 * only allowed to access its own Harrier.
179 return PCIBIOS_SUCCESSFUL
;
181 if ((bus
== 0) && (devfn
== self
))
182 return PCIBIOS_SUCCESSFUL
;
184 return PCIBIOS_DEVICE_NOT_FOUND
;
186 return prpmc_self(bus
, devfn
);
189 void __init
prpmc800_find_bridges(void)
191 struct pci_controller
*hose
;
194 hose
= pcibios_alloc_controller();
198 hose
->first_busno
= 0;
199 hose
->last_busno
= 0xff;
201 ppc_md
.pci_exclude_device
= prpmc_exclude_device
;
202 ppc_md
.pcibios_fixup
= NULL
;
203 ppc_md
.pcibios_fixup_bus
= NULL
;
204 ppc_md
.pci_swizzle
= common_swizzle
;
205 ppc_md
.pci_map_irq
= prpmc_map_irq
;
207 setup_indirect_pci(hose
,
208 PRPMC800_PCI_CONFIG_ADDR
, PRPMC800_PCI_CONFIG_DATA
);
210 /* Get host bridge vendor/dev id */
212 host_bridge
= in_be32((uint
*) (HARRIER_VENI_REG
));
214 if (host_bridge
!= HARRIER_VEND_DEV_ID
) {
215 printk(KERN_CRIT
"Host bridge 0x%x not supported\n",
220 monarch
= in_be32((uint
*) HARRIER_MISC_CSR
) & HARRIER_SYSCON
;
222 printk(KERN_INFO
"Running as %s.\n",
223 MONARCH
? "Monarch" : "Non-Monarch");
225 hose
->io_space
.start
= PRPMC800_PCI_IO_START
;
226 hose
->io_space
.end
= PRPMC800_PCI_IO_END
;
227 hose
->io_base_virt
= (void *)PRPMC800_ISA_IO_BASE
;
228 hose
->pci_mem_offset
= PRPMC800_PCI_PHY_MEM_OFFSET
;
230 pci_init_resource(&hose
->io_resource
,
231 PRPMC800_PCI_IO_START
, PRPMC800_PCI_IO_END
,
232 IORESOURCE_IO
, "PCI host bridge");
235 hose
->mem_space
.start
= PRPMC800_PCI_MEM_START
;
236 hose
->mem_space
.end
= PRPMC800_PCI_MEM_END
;
238 pci_init_resource(&hose
->mem_resources
[0],
239 PRPMC800_PCI_MEM_START
,
240 PRPMC800_PCI_MEM_END
,
241 IORESOURCE_MEM
, "PCI host bridge");
243 if (harrier_init(hose
,
244 PRPMC800_HARRIER_XCSR_BASE
,
245 PRPMC800_PROC_PCI_MEM_START
,
246 PRPMC800_PROC_PCI_MEM_END
,
247 PRPMC800_PROC_PCI_IO_START
,
248 PRPMC800_PROC_PCI_IO_END
,
249 PRPMC800_HARRIER_MPIC_BASE
) != 0)
250 printk(KERN_CRIT
"Could not initialize HARRIER "
253 harrier_release_eready(PRPMC800_HARRIER_XCSR_BASE
);
254 harrier_wait_eready(PRPMC800_HARRIER_XCSR_BASE
);
255 hose
->last_busno
= pciauto_bus_scan(hose
, hose
->first_busno
);
258 pci_init_resource(&hose
->mem_resources
[0],
259 PRPMC800_NM_PCI_MEM_START
,
260 PRPMC800_NM_PCI_MEM_END
,
261 IORESOURCE_MEM
, "PCI host bridge");
263 hose
->mem_space
.start
= PRPMC800_NM_PCI_MEM_START
;
264 hose
->mem_space
.end
= PRPMC800_NM_PCI_MEM_END
;
266 if (harrier_init(hose
,
267 PRPMC800_HARRIER_XCSR_BASE
,
268 PRPMC800_NM_PROC_PCI_MEM_START
,
269 PRPMC800_NM_PROC_PCI_MEM_END
,
270 PRPMC800_PROC_PCI_IO_START
,
271 PRPMC800_PROC_PCI_IO_END
,
272 PRPMC800_HARRIER_MPIC_BASE
) != 0)
273 printk(KERN_CRIT
"Could not initialize HARRIER "
276 harrier_setup_nonmonarch(PRPMC800_HARRIER_XCSR_BASE
,
278 harrier_release_eready(PRPMC800_HARRIER_XCSR_BASE
);
282 static int prpmc800_show_cpuinfo(struct seq_file
*m
)
284 seq_printf(m
, "machine\t\t: PrPMC800\n");
289 static void __init
prpmc800_setup_arch(void)
291 /* init to some ~sane value until calibrate_delay() runs */
292 loops_per_jiffy
= 50000000 / HZ
;
294 /* Lookup PCI host bridges */
295 prpmc800_find_bridges();
297 #ifdef CONFIG_BLK_DEV_INITRD
299 ROOT_DEV
= Root_RAM0
;
302 #ifdef CONFIG_ROOT_NFS
305 ROOT_DEV
= Root_SDA2
;
308 printk(KERN_INFO
"Port by MontaVista Software, Inc. "
309 "(source@mvista.com)\n");
313 * Compute the PrPMC800's tbl frequency using the baud clock as a reference.
315 static void __init
prpmc800_calibrate_decr(void)
317 unsigned long tbl_start
, tbl_end
;
318 unsigned long current_state
, old_state
, tb_ticks_per_second
;
320 unsigned int harrier_revision
;
322 harrier_revision
= readb(HARRIER_REVI_REG
);
323 if (harrier_revision
< 2) {
324 /* XTAL64 was broken in harrier revision 1 */
325 printk(KERN_INFO
"time_init: Harrier revision %d, assuming "
326 "100 Mhz bus\n", harrier_revision
);
327 tb_ticks_per_second
= 100000000 / 4;
328 tb_ticks_per_jiffy
= tb_ticks_per_second
/ HZ
;
329 tb_to_us
= mulhwu_scale_factor(tb_ticks_per_second
, 1000000);
334 * The XTAL64 bit oscillates at the 1/64 the base baud clock
335 * Set count to XTAL64 cycles per second. Since we'll count
336 * half-cycles, we'll reach the count in half a second.
338 count
= PRPMC800_BASE_BAUD
/ 64;
340 /* Find the first edge of the baud clock */
341 old_state
= readb(HARRIER_UCTL_REG
) & HARRIER_XTAL64_MASK
;
343 current_state
= readb(HARRIER_UCTL_REG
) & HARRIER_XTAL64_MASK
;
344 } while (old_state
== current_state
);
346 old_state
= current_state
;
348 /* Get the starting time base value */
349 tbl_start
= get_tbl();
352 * Loop until we have found a number of edges (half-cycles)
353 * equal to the count (half a second)
357 current_state
= readb(HARRIER_UCTL_REG
) &
359 } while (old_state
== current_state
);
360 old_state
= current_state
;
363 /* Get the ending time base value */
366 /* We only counted for half a second, so double to get ticks/second */
367 tb_ticks_per_second
= (tbl_end
- tbl_start
) * 2;
368 tb_ticks_per_jiffy
= tb_ticks_per_second
/ HZ
;
369 tb_to_us
= mulhwu_scale_factor(tb_ticks_per_second
, 1000000);
372 static void prpmc800_restart(char *cmd
)
377 temp
= in_be32((uint
*) HARRIER_MISC_CSR_REG
);
378 temp
|= HARRIER_RSTOUT
;
379 out_be32((uint
*) HARRIER_MISC_CSR_REG
, temp
);
383 static void prpmc800_halt(void)
389 static void prpmc800_power_off(void)
394 static void __init
prpmc800_init_IRQ(void)
396 OpenPIC_InitSenses
= prpmc800_openpic_initsenses
;
397 OpenPIC_NumInitSenses
= sizeof(prpmc800_openpic_initsenses
);
399 /* Setup external interrupt sources. */
400 openpic_set_sources(0, 16, OpenPIC_Addr
+ 0x10000);
401 /* Setup internal UART interrupt source. */
402 openpic_set_sources(16, 1, OpenPIC_Addr
+ 0x10200);
404 /* Do the MPIC initialization based on the above settings. */
407 /* enable functional exceptions for uarts and abort */
408 out_8((u8
*) HARRIER_FEEN_REG
, (HARRIER_FE_UA0
| HARRIER_FE_UA1
));
409 out_8((u8
*) HARRIER_FEMA_REG
, ~(HARRIER_FE_UA0
| HARRIER_FE_UA1
));
413 * Set BAT 3 to map 0xf0000000 to end of physical memory space.
415 static __inline__
void prpmc800_set_bat(void)
418 mtspr(SPRN_DBAT1U
, 0xf0001ffe);
419 mtspr(SPRN_DBAT1L
, 0xf000002a);
424 * We need to read the Harrier memory controller
425 * to properly determine this value
427 static unsigned long __init
prpmc800_find_end_of_memory(void)
429 /* Read the memory size from the Harrier XCSR */
430 return harrier_get_mem_size(PRPMC800_HARRIER_XCSR_BASE
);
433 static void __init
prpmc800_map_io(void)
435 io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO
);
436 io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO
);
440 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
441 unsigned long r6
, unsigned long r7
)
443 parse_bootinfo(find_bootinfo());
447 isa_io_base
= PRPMC800_ISA_IO_BASE
;
448 isa_mem_base
= PRPMC800_ISA_MEM_BASE
;
449 pci_dram_offset
= PRPMC800_PCI_DRAM_OFFSET
;
451 ppc_md
.setup_arch
= prpmc800_setup_arch
;
452 ppc_md
.show_cpuinfo
= prpmc800_show_cpuinfo
;
453 ppc_md
.init_IRQ
= prpmc800_init_IRQ
;
454 ppc_md
.get_irq
= openpic_get_irq
;
456 ppc_md
.find_end_of_memory
= prpmc800_find_end_of_memory
;
457 ppc_md
.setup_io_mappings
= prpmc800_map_io
;
459 ppc_md
.restart
= prpmc800_restart
;
460 ppc_md
.power_off
= prpmc800_power_off
;
461 ppc_md
.halt
= prpmc800_halt
;
463 /* PrPMC800 has no timekeeper part */
464 ppc_md
.time_init
= NULL
;
465 ppc_md
.get_rtc_time
= NULL
;
466 ppc_md
.set_rtc_time
= NULL
;
467 ppc_md
.calibrate_decr
= prpmc800_calibrate_decr
;
468 #ifdef CONFIG_SERIAL_TEXT_DEBUG
469 ppc_md
.progress
= gen550_progress
;
470 #else /* !CONFIG_SERIAL_TEXT_DEBUG */
471 ppc_md
.progress
= NULL
;
472 #endif /* CONFIG_SERIAL_TEXT_DEBUG */