2 * Copyright (C) 2006-2007 PA Semi, Inc
4 * Authors: Kip Walker, PA Semi
5 * Olof Johansson, PA Semi
7 * Maintained by: Olof Johansson <olof@lixom.net>
9 * Based on arch/powerpc/platforms/maple/setup.c
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/errno.h>
26 #include <linux/kernel.h>
27 #include <linux/delay.h>
28 #include <linux/console.h>
29 #include <linux/pci.h>
30 #include <linux/of_platform.h>
33 #include <asm/system.h>
34 #include <asm/iommu.h>
35 #include <asm/machdep.h>
41 #include <pcmcia/ss.h>
42 #include <pcmcia/cistpl.h>
43 #include <pcmcia/ds.h>
47 #if !defined(CONFIG_SMP)
48 static void smp_send_stop(void) {}
51 /* SDC reset register, must be pre-mapped at reset time */
52 static void __iomem *reset_reg;
54 /* Various error status registers, must be pre-mapped at MCE time */
56 #define MAX_MCE_REGS 32
62 static struct mce_regs mce_regs[MAX_MCE_REGS];
63 static int num_mce_regs;
64 static int nmi_virq = NO_IRQ;
67 static void pas_restart(char *cmd)
69 /* Need to put others cpu in hold loop so they're not sleeping */
72 printk("Restarting...\n");
74 out_le32(reset_reg, 0x6000000);
78 static DEFINE_SPINLOCK(timebase_lock);
79 static unsigned long timebase;
81 static void __devinit pas_give_timebase(void)
83 spin_lock(&timebase_lock);
84 mtspr(SPRN_TBCTL, TBCTL_FREEZE);
87 spin_unlock(&timebase_lock);
91 mtspr(SPRN_TBCTL, TBCTL_RESTART);
94 static void __devinit pas_take_timebase(void)
99 spin_lock(&timebase_lock);
100 set_tb(timebase >> 32, timebase & 0xffffffff);
102 spin_unlock(&timebase_lock);
105 struct smp_ops_t pas_smp_ops = {
106 .probe = smp_mpic_probe,
107 .message_pass = smp_mpic_message_pass,
108 .kick_cpu = smp_generic_kick_cpu,
109 .setup_cpu = smp_mpic_setup_cpu,
110 .give_timebase = pas_give_timebase,
111 .take_timebase = pas_take_timebase,
113 #endif /* CONFIG_SMP */
115 void __init pas_setup_arch(void)
118 /* Setup SMP callback */
119 smp_ops = &pas_smp_ops;
121 /* Lookup PCI hosts */
124 #ifdef CONFIG_DUMMY_CONSOLE
125 conswitchp = &dummy_con;
128 /* Remap SDC register for doing reset */
129 /* XXXOJN This should maybe come out of the device tree */
130 reset_reg = ioremap(0xfc101100, 4);
133 static int __init pas_setup_mce_regs(void)
138 if (!machine_is(pasemi))
141 /* Remap various SoC status registers for use by the MCE handler */
145 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);
146 while (dev && reg < MAX_MCE_REGS) {
147 mce_regs[reg].name = kasprintf(GFP_KERNEL,
148 "mc%d_mcdebug_errsta", reg);
149 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
150 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
154 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
155 if (dev && reg+4 < MAX_MCE_REGS) {
156 mce_regs[reg].name = "iobdbg_IntStatus1";
157 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);
159 mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";
160 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);
162 mce_regs[reg].name = "iobiom_IntStatus";
163 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);
165 mce_regs[reg].name = "iobiom_IntDbgReg";
166 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
170 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
171 if (dev && reg+2 < MAX_MCE_REGS) {
172 mce_regs[reg].name = "l2csts_IntStatus";
173 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);
175 mce_regs[reg].name = "l2csts_Cnt";
176 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
184 device_initcall(pas_setup_mce_regs);
186 static __init void pas_init_IRQ(void)
188 struct device_node *np;
189 struct device_node *root, *mpic_node;
190 unsigned long openpic_addr;
191 const unsigned int *opprop;
194 const unsigned int *nmiprop;
199 for_each_node_by_type(np, "interrupt-controller")
200 if (of_device_is_compatible(np, "open-pic")) {
205 for_each_node_by_type(np, "open-pic") {
211 "Failed to locate the MPIC interrupt controller\n");
215 /* Find address list in /platform-open-pic */
216 root = of_find_node_by_path("/");
217 naddr = of_n_addr_cells(root);
218 opprop = of_get_property(root, "platform-open-pic", &opplen);
220 printk(KERN_ERR "No platform-open-pic property.\n");
224 openpic_addr = of_read_number(opprop, naddr);
225 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
227 mpic_flags = MPIC_PRIMARY | MPIC_LARGE_VECTORS;
229 nmiprop = of_get_property(mpic_node, "nmi-source", NULL);
231 mpic_flags |= MPIC_ENABLE_MCK;
233 mpic = mpic_alloc(mpic_node, openpic_addr,
234 mpic_flags, 0, 0, "PASEMI-OPIC");
237 mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);
239 /* The NMI/MCK source needs to be prio 15 */
241 nmi_virq = irq_create_mapping(NULL, *nmiprop);
242 mpic_irq_set_priority(nmi_virq, 15);
243 set_irq_type(nmi_virq, IRQ_TYPE_EDGE_RISING);
244 mpic_unmask_irq(nmi_virq);
247 of_node_put(mpic_node);
251 static void __init pas_progress(char *s, unsigned short hex)
253 printk("[%04x] : %s\n", hex, s ? s : "");
257 static int pas_machine_check_handler(struct pt_regs *regs)
259 int cpu = smp_processor_id();
260 unsigned long srr0, srr1, dsisr;
267 if (mpic_get_mcirq() == nmi_virq) {
268 printk(KERN_ERR "NMI delivered\n");
270 mpic_end_irq(nmi_virq);
274 dsisr = mfspr(SPRN_DSISR);
275 printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
276 printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);
277 printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);
278 printk(KERN_ERR "BER 0x%016lx MER 0x%016lx\n", mfspr(SPRN_PA6T_BER),
279 mfspr(SPRN_PA6T_MER));
280 printk(KERN_ERR "IER 0x%016lx DER 0x%016lx\n", mfspr(SPRN_PA6T_IER),
281 mfspr(SPRN_PA6T_DER));
282 printk(KERN_ERR "Cause:\n");
285 printk(KERN_ERR "Signalled by SDC\n");
287 if (srr1 & 0x100000) {
288 printk(KERN_ERR "Load/Store detected error:\n");
290 printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
292 printk(KERN_ERR "LSU snoop response error\n");
293 if (dsisr & 0x2000) {
294 printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
298 printk(KERN_ERR "Recoverable Duptags\n");
300 printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
302 printk(KERN_ERR "TLB parity error count overflow\n");
306 printk(KERN_ERR "Bus Error\n");
308 if (srr1 & 0x40000) {
309 printk(KERN_ERR "I-side SLB multiple hit\n");
314 printk(KERN_ERR "I-cache parity error hit\n");
316 if (num_mce_regs == 0)
317 printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");
319 printk(KERN_ERR "SoC debug registers:\n");
321 for (i = 0; i < num_mce_regs; i++)
322 printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,
323 in_le32(mce_regs[i].addr));
329 printk(KERN_ERR "slb contents:\n");
330 for (i = 0; i < mmu_slb_size; i++) {
331 asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));
332 asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));
333 printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);
338 /* SRR1[62] is from MSR[62] if recoverable, so pass that back */
339 return !!(srr1 & 0x2);
342 static void __init pas_init_early(void)
344 iommu_init_early_pasemi();
348 static int pcmcia_notify(struct notifier_block *nb, unsigned long action,
351 struct device *dev = data;
352 struct device *parent;
353 struct pcmcia_device *pdev = to_pcmcia_dev(dev);
355 /* We are only intereted in device addition */
356 if (action != BUS_NOTIFY_ADD_DEVICE)
359 parent = pdev->socket->dev.parent;
361 /* We know electra_cf devices will always have of_node set, since
362 * electra_cf is an of_platform driver.
364 if (!parent->archdata.of_node)
367 if (!of_device_is_compatible(parent->archdata.of_node, "electra-cf"))
370 /* We use the direct ops for localbus */
371 dev->archdata.dma_ops = &dma_direct_ops;
376 static struct notifier_block pcmcia_notifier = {
377 .notifier_call = pcmcia_notify,
380 static inline void pasemi_pcmcia_init(void)
382 extern struct bus_type pcmcia_bus_type;
384 bus_register_notifier(&pcmcia_bus_type, &pcmcia_notifier);
389 static inline void pasemi_pcmcia_init(void)
396 static struct of_device_id pasemi_bus_ids[] = {
397 /* Unfortunately needed for legacy firmwares */
398 { .type = "localbus", },
400 /* These are the proper entries, which newer firmware uses */
401 { .compatible = "pasemi,localbus", },
402 { .compatible = "pasemi,sdc", },
406 static int __init pasemi_publish_devices(void)
408 if (!machine_is(pasemi))
411 pasemi_pcmcia_init();
413 /* Publish OF platform devices for SDC and other non-PCI devices */
414 of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);
418 device_initcall(pasemi_publish_devices);
422 * Called very early, MMU is off, device-tree isn't unflattened
424 static int __init pas_probe(void)
426 unsigned long root = of_get_flat_dt_root();
428 if (!of_flat_dt_is_compatible(root, "PA6T-1682M") &&
429 !of_flat_dt_is_compatible(root, "pasemi,pwrficient"))
439 define_machine(pasemi) {
440 .name = "PA Semi PWRficient",
442 .setup_arch = pas_setup_arch,
443 .init_early = pas_init_early,
444 .init_IRQ = pas_init_IRQ,
445 .get_irq = mpic_get_irq,
446 .restart = pas_restart,
447 .get_boot_time = pas_get_boot_time,
448 .calibrate_decr = generic_calibrate_decr,
449 .progress = pas_progress,
450 .machine_check_exception = pas_machine_check_handler,