blob: a7bf88e94c6470953196a067df00ea3934c0cc35 [file] [log] [blame]
Olof Johansson1e768752006-09-06 14:42:08 -05001/*
Olof Johansson31c56d82007-02-04 16:36:55 -06002 * Copyright (C) 2006-2007 PA Semi, Inc
Olof Johansson1e768752006-09-06 14:42:08 -05003 *
4 * Authors: Kip Walker, PA Semi
5 * Olof Johansson, PA Semi
6 *
7 * Maintained by: Olof Johansson <olof@lixom.net>
8 *
9 * Based on arch/powerpc/platforms/maple/setup.c
10 *
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.
14 *
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.
19 *
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
23 */
24
Olof Johansson1e768752006-09-06 14:42:08 -050025#include <linux/errno.h>
26#include <linux/kernel.h>
27#include <linux/delay.h>
28#include <linux/console.h>
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +110029#include <linux/pci.h>
Olof Johansson1e768752006-09-06 14:42:08 -050030
31#include <asm/prom.h>
32#include <asm/system.h>
33#include <asm/iommu.h>
34#include <asm/machdep.h>
35#include <asm/mpic.h>
36#include <asm/smp.h>
37#include <asm/time.h>
Olof Johansson952418c2007-04-25 04:01:34 +100038#include <asm/of_platform.h>
Olof Johansson1e768752006-09-06 14:42:08 -050039
40#include "pasemi.h"
41
Olof Johanssonf620be92007-02-04 16:36:52 -060042static void __iomem *reset_reg;
43
Olof Johansson1e768752006-09-06 14:42:08 -050044static void pas_restart(char *cmd)
45{
Olof Johanssonf620be92007-02-04 16:36:52 -060046 printk("Restarting...\n");
47 while (1)
48 out_le32(reset_reg, 0x6000000);
Olof Johansson1e768752006-09-06 14:42:08 -050049}
50
51#ifdef CONFIG_SMP
Olof Johanssonc388cfe2007-02-04 16:36:53 -060052static DEFINE_SPINLOCK(timebase_lock);
53
54static void __devinit pas_give_timebase(void)
55{
56 unsigned long tb;
57
58 spin_lock(&timebase_lock);
59 mtspr(SPRN_TBCTL, TBCTL_FREEZE);
60 tb = mftb();
61 mtspr(SPRN_TBCTL, TBCTL_UPDATE_LOWER | (tb & 0xffffffff));
62 mtspr(SPRN_TBCTL, TBCTL_UPDATE_UPPER | (tb >> 32));
63 mtspr(SPRN_TBCTL, TBCTL_RESTART);
64 spin_unlock(&timebase_lock);
65 pr_debug("pas_give_timebase: cpu %d gave tb %lx\n",
66 smp_processor_id(), tb);
67}
68
69static void __devinit pas_take_timebase(void)
70{
71 pr_debug("pas_take_timebase: cpu %d has tb %lx\n",
72 smp_processor_id(), mftb());
73}
74
Olof Johansson1e768752006-09-06 14:42:08 -050075struct smp_ops_t pas_smp_ops = {
76 .probe = smp_mpic_probe,
77 .message_pass = smp_mpic_message_pass,
78 .kick_cpu = smp_generic_kick_cpu,
79 .setup_cpu = smp_mpic_setup_cpu,
Olof Johanssonc388cfe2007-02-04 16:36:53 -060080 .give_timebase = pas_give_timebase,
81 .take_timebase = pas_take_timebase,
Olof Johansson1e768752006-09-06 14:42:08 -050082};
83#endif /* CONFIG_SMP */
84
85void __init pas_setup_arch(void)
86{
87#ifdef CONFIG_SMP
88 /* Setup SMP callback */
89 smp_ops = &pas_smp_ops;
90#endif
91 /* Lookup PCI hosts */
92 pas_pci_init();
93
94#ifdef CONFIG_DUMMY_CONSOLE
95 conswitchp = &dummy_con;
96#endif
97
Olof Johanssonf620be92007-02-04 16:36:52 -060098 /* Remap SDC register for doing reset */
99 /* XXXOJN This should maybe come out of the device tree */
100 reset_reg = ioremap(0xfc101100, 4);
101
Olof Johansson11999192007-02-04 16:36:51 -0600102 pasemi_idle_init();
Olof Johansson1e768752006-09-06 14:42:08 -0500103}
104
Olof Johansson1e768752006-09-06 14:42:08 -0500105/* No legacy IO on our parts */
106static int pas_check_legacy_ioport(unsigned int baseport)
107{
108 return -ENODEV;
109}
110
111static __init void pas_init_IRQ(void)
112{
113 struct device_node *np;
114 struct device_node *root, *mpic_node;
115 unsigned long openpic_addr;
116 const unsigned int *opprop;
117 int naddr, opplen;
118 struct mpic *mpic;
119
120 mpic_node = NULL;
121
122 for_each_node_by_type(np, "interrupt-controller")
123 if (device_is_compatible(np, "open-pic")) {
124 mpic_node = np;
125 break;
126 }
127 if (!mpic_node)
128 for_each_node_by_type(np, "open-pic") {
129 mpic_node = np;
130 break;
131 }
132 if (!mpic_node) {
133 printk(KERN_ERR
134 "Failed to locate the MPIC interrupt controller\n");
135 return;
136 }
137
138 /* Find address list in /platform-open-pic */
139 root = of_find_node_by_path("/");
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000140 naddr = of_n_addr_cells(root);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000141 opprop = of_get_property(root, "platform-open-pic", &opplen);
Olof Johansson1e768752006-09-06 14:42:08 -0500142 if (!opprop) {
143 printk(KERN_ERR "No platform-open-pic property.\n");
144 of_node_put(root);
145 return;
146 }
147 openpic_addr = of_read_number(opprop, naddr);
148 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
Olof Johansson1e768752006-09-06 14:42:08 -0500149
Olof Johansson7df24572007-01-28 23:33:18 -0600150 mpic = mpic_alloc(mpic_node, openpic_addr,
Olof Johansson7e8bddf2007-04-16 16:28:38 +1000151 MPIC_PRIMARY|MPIC_LARGE_VECTORS|MPIC_WANTS_RESET,
Olof Johansson7df24572007-01-28 23:33:18 -0600152 0, 0, " PAS-OPIC ");
Olof Johansson1e768752006-09-06 14:42:08 -0500153 BUG_ON(!mpic);
154
155 mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);
156 mpic_init(mpic);
157 of_node_put(mpic_node);
158 of_node_put(root);
159}
160
161static void __init pas_progress(char *s, unsigned short hex)
162{
163 printk("[%04x] : %s\n", hex, s ? s : "");
164}
165
166
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600167static int pas_machine_check_handler(struct pt_regs *regs)
168{
169 int cpu = smp_processor_id();
170 unsigned long srr0, srr1, dsisr;
171
172 srr0 = regs->nip;
173 srr1 = regs->msr;
174 dsisr = mfspr(SPRN_DSISR);
175 printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
176 printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);
177 printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);
178 printk(KERN_ERR "Cause:\n");
179
180 if (srr1 & 0x200000)
181 printk(KERN_ERR "Signalled by SDC\n");
182 if (srr1 & 0x100000) {
183 printk(KERN_ERR "Load/Store detected error:\n");
184 if (dsisr & 0x8000)
185 printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
186 if (dsisr & 0x4000)
187 printk(KERN_ERR "LSU snoop response error\n");
188 if (dsisr & 0x2000)
189 printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
190 if (dsisr & 0x1000)
191 printk(KERN_ERR "Recoverable Duptags\n");
192 if (dsisr & 0x800)
193 printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
194 if (dsisr & 0x400)
195 printk(KERN_ERR "TLB parity error count overflow\n");
196 }
197 if (srr1 & 0x80000)
198 printk(KERN_ERR "Bus Error\n");
199 if (srr1 & 0x40000)
200 printk(KERN_ERR "I-side SLB multiple hit\n");
201 if (srr1 & 0x20000)
202 printk(KERN_ERR "I-cache parity error hit\n");
203
204 /* SRR1[62] is from MSR[62] if recoverable, so pass that back */
205 return !!(srr1 & 0x2);
206}
207
Olof Johansson31c56d82007-02-04 16:36:55 -0600208static void __init pas_init_early(void)
209{
210 iommu_init_early_pasemi();
211}
212
Olof Johanssonb97d2792007-04-18 16:39:54 +1000213static struct of_device_id pasemi_bus_ids[] = {
214 { .type = "sdc", },
215 {},
216};
217
218static int __init pasemi_publish_devices(void)
219{
220 /* Publish OF platform devices for southbridge IOs */
221 of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);
222
223 return 0;
224}
225device_initcall(pasemi_publish_devices);
226
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600227
Olof Johansson1e768752006-09-06 14:42:08 -0500228/*
229 * Called very early, MMU is off, device-tree isn't unflattened
230 */
231static int __init pas_probe(void)
232{
233 unsigned long root = of_get_flat_dt_root();
234
235 if (!of_flat_dt_is_compatible(root, "PA6T-1682M"))
236 return 0;
237
238 hpte_init_native();
239
Olof Johansson31c56d82007-02-04 16:36:55 -0600240 alloc_iobmap_l2();
241
Olof Johansson1e768752006-09-06 14:42:08 -0500242 return 1;
243}
244
245define_machine(pas) {
246 .name = "PA Semi PA6T-1682M",
247 .probe = pas_probe,
248 .setup_arch = pas_setup_arch,
Olof Johansson31c56d82007-02-04 16:36:55 -0600249 .init_early = pas_init_early,
Olof Johansson1e768752006-09-06 14:42:08 -0500250 .init_IRQ = pas_init_IRQ,
251 .get_irq = mpic_get_irq,
Olof Johansson1e768752006-09-06 14:42:08 -0500252 .restart = pas_restart,
Olof Johansson1e768752006-09-06 14:42:08 -0500253 .get_boot_time = pas_get_boot_time,
254 .calibrate_decr = generic_calibrate_decr,
255 .check_legacy_ioport = pas_check_legacy_ioport,
256 .progress = pas_progress,
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600257 .machine_check_exception = pas_machine_check_handler,
Olof Johanssonf9fba5b2007-02-04 16:36:54 -0600258 .pci_irq_fixup = pas_pci_irq_fixup,
Olof Johansson1e768752006-09-06 14:42:08 -0500259};