2 * Maple (970 eval board) setup code
4 * (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org),
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/export.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/user.h>
26 #include <linux/tty.h>
27 #include <linux/string.h>
28 #include <linux/delay.h>
29 #include <linux/ioport.h>
30 #include <linux/major.h>
31 #include <linux/initrd.h>
32 #include <linux/vt_kern.h>
33 #include <linux/console.h>
34 #include <linux/pci.h>
35 #include <linux/adb.h>
36 #include <linux/cuda.h>
37 #include <linux/pmu.h>
38 #include <linux/irq.h>
39 #include <linux/seq_file.h>
40 #include <linux/root_dev.h>
41 #include <linux/serial.h>
42 #include <linux/smp.h>
43 #include <linux/bitops.h>
44 #include <linux/of_device.h>
45 #include <linux/memblock.h>
47 #include <asm/processor.h>
48 #include <asm/sections.h>
50 #include <asm/pgtable.h>
52 #include <asm/pci-bridge.h>
53 #include <asm/iommu.h>
54 #include <asm/machdep.h>
56 #include <asm/cputable.h>
61 #include <asm/nvram.h>
66 #define DBG(fmt...) udbg_printf(fmt)
71 static unsigned long maple_find_nvram_base(void)
73 struct device_node *rtcs;
74 unsigned long result = 0;
76 /* find NVRAM device */
77 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
80 if (of_address_to_resource(rtcs, 0, &r)) {
81 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
85 if (!(r.flags & IORESOURCE_IO)) {
86 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
91 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
97 static void maple_restart(char *cmd)
99 unsigned int maple_nvram_base;
100 const unsigned int *maple_nvram_offset, *maple_nvram_command;
101 struct device_node *sp;
103 maple_nvram_base = maple_find_nvram_base();
104 if (maple_nvram_base == 0)
107 /* find service processor device */
108 sp = of_find_node_by_name(NULL, "service-processor");
110 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
113 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
114 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
118 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
121 printk(KERN_EMERG "Maple: Manual Restart Required\n");
124 static void maple_power_off(void)
126 unsigned int maple_nvram_base;
127 const unsigned int *maple_nvram_offset, *maple_nvram_command;
128 struct device_node *sp;
130 maple_nvram_base = maple_find_nvram_base();
131 if (maple_nvram_base == 0)
134 /* find service processor device */
135 sp = of_find_node_by_name(NULL, "service-processor");
137 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
140 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
141 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
145 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
148 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
151 static void maple_halt(void)
157 struct smp_ops_t maple_smp_ops = {
158 .probe = smp_mpic_probe,
159 .message_pass = smp_mpic_message_pass,
160 .kick_cpu = smp_generic_kick_cpu,
161 .setup_cpu = smp_mpic_setup_cpu,
162 .give_timebase = smp_generic_give_timebase,
163 .take_timebase = smp_generic_take_timebase,
165 #endif /* CONFIG_SMP */
167 static void __init maple_use_rtas_reboot_and_halt_if_present(void)
169 if (rtas_service_present("system-reboot") &&
170 rtas_service_present("power-off")) {
171 ppc_md.restart = rtas_restart;
172 pm_power_off = rtas_power_off;
173 ppc_md.halt = rtas_halt;
177 void __init maple_setup_arch(void)
179 /* init to some ~sane value until calibrate_delay() runs */
180 loops_per_jiffy = 50000000;
182 /* Setup SMP callback */
184 smp_ops = &maple_smp_ops;
186 /* Lookup PCI hosts */
189 #ifdef CONFIG_DUMMY_CONSOLE
190 conswitchp = &dummy_con;
192 maple_use_rtas_reboot_and_halt_if_present();
194 printk(KERN_DEBUG "Using native/NAP idle loop\n");
200 * Early initialization.
202 static void __init maple_init_early(void)
204 DBG(" -> maple_init_early\n");
206 iommu_init_early_dart();
208 DBG(" <- maple_init_early\n");
212 * This is almost identical to pSeries and CHRP. We need to make that
213 * code generic at one point, with appropriate bits in the device-tree to
214 * identify the presence of an HT APIC
216 static void __init maple_init_IRQ(void)
218 struct device_node *root, *np, *mpic_node = NULL;
219 const unsigned int *opprop;
220 unsigned long openpic_addr = 0;
221 int naddr, n, i, opplen, has_isus = 0;
223 unsigned int flags = 0;
225 /* Locate MPIC in the device-tree. Note that there is a bug
226 * in Maple device-tree where the type of the controller is
227 * open-pic and not interrupt-controller
230 for_each_node_by_type(np, "interrupt-controller")
231 if (of_device_is_compatible(np, "open-pic")) {
235 if (mpic_node == NULL)
236 for_each_node_by_type(np, "open-pic") {
240 if (mpic_node == NULL) {
242 "Failed to locate the MPIC interrupt controller\n");
246 /* Find address list in /platform-open-pic */
247 root = of_find_node_by_path("/");
248 naddr = of_n_addr_cells(root);
249 opprop = of_get_property(root, "platform-open-pic", &opplen);
251 openpic_addr = of_read_number(opprop, naddr);
252 has_isus = (opplen > naddr);
253 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
254 openpic_addr, has_isus);
257 BUG_ON(openpic_addr == 0);
259 /* Check for a big endian MPIC */
260 if (of_get_property(np, "big-endian", NULL) != NULL)
261 flags |= MPIC_BIG_ENDIAN;
263 /* XXX Maple specific bits */
264 flags |= MPIC_U3_HT_IRQS;
265 /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
266 flags |= MPIC_BIG_ENDIAN;
268 /* Setup the openpic driver. More device-tree junks, we hard code no
269 * ISUs for now. I'll have to revisit some stuffs with the folks doing
270 * the firmware for those
272 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
273 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
274 BUG_ON(mpic == NULL);
277 opplen /= sizeof(u32);
278 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
279 unsigned long isuaddr = of_read_number(opprop + i, naddr);
280 mpic_assign_isu(mpic, n, isuaddr);
283 /* All ISUs are setup, complete initialization */
285 ppc_md.get_irq = mpic_get_irq;
286 of_node_put(mpic_node);
290 static void __init maple_progress(char *s, unsigned short hex)
292 printk("*** %04x : %s\n", hex, s ? s : "");
297 * Called very early, MMU is off, device-tree isn't unflattened
299 static int __init maple_probe(void)
301 unsigned long root = of_get_flat_dt_root();
303 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
304 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
307 * On U3, the DART (iommu) must be allocated now since it
308 * has an impact on htab_initialize (due to the large page it
309 * occupies having to be broken up so the DART itself is not
310 * part of the cacheable linar mapping
315 pm_power_off = maple_power_off;
320 define_machine(maple) {
322 .probe = maple_probe,
323 .setup_arch = maple_setup_arch,
324 .init_early = maple_init_early,
325 .init_IRQ = maple_init_IRQ,
326 .pci_irq_fixup = maple_pci_irq_fixup,
327 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
328 .restart = maple_restart,
330 .get_boot_time = maple_get_boot_time,
331 .set_rtc_time = maple_set_rtc_time,
332 .get_rtc_time = maple_get_rtc_time,
333 .calibrate_decr = generic_calibrate_decr,
334 .progress = maple_progress,
335 .power_save = power4_idle,
340 * Register a platform device for CPC925 memory controller on
341 * all boards with U3H (CPC925) bridge.
343 static int __init maple_cpc925_edac_setup(void)
345 struct platform_device *pdev;
346 struct device_node *np = NULL;
349 volatile void __iomem *mem;
352 np = of_find_node_by_type(NULL, "memory-controller");
354 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
359 ret = of_address_to_resource(np, 0, &r);
363 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
368 mem = ioremap(r.start, resource_size(&r));
370 printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
375 rev = __raw_readl(mem);
378 if (rev < 0x34 || rev > 0x3f) { /* U3H */
379 printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
384 pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
386 return PTR_ERR(pdev);
388 printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
392 machine_device_initcall(maple, maple_cpc925_edac_setup);