blob: e77c869d391621f727a3fb53d61d5eea9cd02095 [file] [log] [blame]
Andy Fleming591f0a42006-04-02 17:42:40 -05001/*
2 * MPC85xx setup and early boot code plus other random bits.
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
6 * Copyright 2005 Freescale Semiconductor Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
Andy Fleming591f0a42006-04-02 17:42:40 -050014#include <linux/stddef.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/reboot.h>
19#include <linux/pci.h>
20#include <linux/kdev_t.h>
21#include <linux/major.h>
22#include <linux/console.h>
23#include <linux/delay.h>
24#include <linux/seq_file.h>
Andy Fleming591f0a42006-04-02 17:42:40 -050025#include <linux/initrd.h>
26#include <linux/module.h>
Randy Vinson3620fc12007-06-06 16:26:15 -070027#include <linux/interrupt.h>
Andy Fleming591f0a42006-04-02 17:42:40 -050028#include <linux/fsl_devices.h>
29
30#include <asm/system.h>
31#include <asm/pgtable.h>
32#include <asm/page.h>
33#include <asm/atomic.h>
34#include <asm/time.h>
35#include <asm/io.h>
36#include <asm/machdep.h>
37#include <asm/ipic.h>
38#include <asm/bootinfo.h>
39#include <asm/pci-bridge.h>
40#include <asm/mpc85xx.h>
41#include <asm/irq.h>
42#include <mm/mmu_decl.h>
43#include <asm/prom.h>
44#include <asm/udbg.h>
45#include <asm/mpic.h>
46#include <asm/i8259.h>
47
48#include <sysdev/fsl_soc.h>
Roy Zang3f6c5da2007-07-10 18:47:06 +080049#include <sysdev/fsl_pci.h>
Andy Fleming591f0a42006-04-02 17:42:40 -050050#include "mpc85xx.h"
51
Andy Fleming591f0a42006-04-02 17:42:40 -050052static int cds_pci_slot = 2;
53static volatile u8 *cadmus;
54
Andy Fleming591f0a42006-04-02 17:42:40 -050055#ifdef CONFIG_PCI
Andy Fleming591f0a42006-04-02 17:42:40 -050056
57#define ARCADIA_HOST_BRIDGE_IDSEL 17
58#define ARCADIA_2ND_BRIDGE_IDSEL 3
59
Kumar Gala7d52c7b2007-06-22 00:23:57 -050060static int mpc85xx_exclude_device(struct pci_controller *hose,
61 u_char bus, u_char devfn)
Andy Fleming591f0a42006-04-02 17:42:40 -050062{
Andy Fleming591f0a42006-04-02 17:42:40 -050063 /* We explicitly do not go past the Tundra 320 Bridge */
64 if ((bus == 1) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
65 return PCIBIOS_DEVICE_NOT_FOUND;
66 if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
67 return PCIBIOS_DEVICE_NOT_FOUND;
68 else
69 return PCIBIOS_SUCCESSFUL;
70}
71
Randy Vinson637e9e12007-03-23 15:43:37 -070072static void mpc85xx_cds_restart(char *cmd)
73{
74 struct pci_dev *dev;
75 u_char tmp;
76
77 if ((dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686,
78 NULL))) {
79
80 /* Use the VIA Super Southbridge to force a PCI reset */
81 pci_read_config_byte(dev, 0x47, &tmp);
82 pci_write_config_byte(dev, 0x47, tmp | 1);
83
84 /* Flush the outbound PCI write queues */
85 pci_read_config_byte(dev, 0x47, &tmp);
86
87 /*
88 * At this point, the harware reset should have triggered.
89 * However, if it doesn't work for some mysterious reason,
90 * just fall through to the default reset below.
91 */
92
93 pci_dev_put(dev);
94 }
95
96 /*
97 * If we can't find the VIA chip (maybe the P2P bridge is disabled)
98 * or the VIA chip reset didn't work, just use the default reset.
99 */
100 mpc85xx_restart(NULL);
101}
102
Roy Zang749e8082007-06-01 16:05:38 +0800103static void __init mpc85xx_cds_pci_irq_fixup(struct pci_dev *dev)
Andy Fleming591f0a42006-04-02 17:42:40 -0500104{
Roy Zang749e8082007-06-01 16:05:38 +0800105 u_char c;
106 if (dev->vendor == PCI_VENDOR_ID_VIA) {
107 switch (dev->device) {
108 case PCI_DEVICE_ID_VIA_82C586_1:
109 /*
110 * U-Boot does not set the enable bits
111 * for the IDE device. Force them on here.
112 */
113 pci_read_config_byte(dev, 0x40, &c);
114 c |= 0x03; /* IDE: Chip Enable Bits */
115 pci_write_config_byte(dev, 0x40, c);
Andy Fleming591f0a42006-04-02 17:42:40 -0500116
Roy Zang749e8082007-06-01 16:05:38 +0800117 /*
118 * Since only primary interface works, force the
119 * IDE function to standard primary IDE interrupt
120 * w/ 8259 offset
121 */
122 dev->irq = 14;
123 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
124 break;
Andy Fleming591f0a42006-04-02 17:42:40 -0500125 /*
Roy Zang749e8082007-06-01 16:05:38 +0800126 * Force legacy USB interrupt routing
Andy Fleming591f0a42006-04-02 17:42:40 -0500127 */
Roy Zang749e8082007-06-01 16:05:38 +0800128 case PCI_DEVICE_ID_VIA_82C586_2:
129 /* There are two USB controllers.
130 * Identify them by functon number
Andy Fleming591f0a42006-04-02 17:42:40 -0500131 */
Roy Zang749e8082007-06-01 16:05:38 +0800132 if (PCI_FUNC(dev->devfn))
133 dev->irq = 11;
134 else
135 dev->irq = 10;
136 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
137 default:
138 break;
139 }
Andy Fleming591f0a42006-04-02 17:42:40 -0500140 }
Andy Fleming591f0a42006-04-02 17:42:40 -0500141}
Andy Flemingddd64152006-08-17 20:24:48 -0500142
Kumar Gala4e798212007-07-19 15:39:24 -0500143static void __devinit skip_fake_bridge(struct pci_dev *dev)
144{
145 /* Make it an error to skip the fake bridge
146 * in pci_setup_device() in probe.c */
147 dev->hdr_type = 0x7f;
148}
149DECLARE_PCI_FIXUP_EARLY(0x1957, 0x3fff, skip_fake_bridge);
150DECLARE_PCI_FIXUP_EARLY(0x3fff, 0x1957, skip_fake_bridge);
151DECLARE_PCI_FIXUP_EARLY(0xff3f, 0x5719, skip_fake_bridge);
152
Andy Flemingddd64152006-08-17 20:24:48 -0500153#ifdef CONFIG_PPC_I8259
Randy Vinson3620fc12007-06-06 16:26:15 -0700154static void mpc85xx_8259_cascade_handler(unsigned int irq,
155 struct irq_desc *desc)
Andy Flemingddd64152006-08-17 20:24:48 -0500156{
Olaf Hering35a84c22006-10-07 22:08:26 +1000157 unsigned int cascade_irq = i8259_irq();
Andy Flemingddd64152006-08-17 20:24:48 -0500158
159 if (cascade_irq != NO_IRQ)
Randy Vinson3620fc12007-06-06 16:26:15 -0700160 /* handle an interrupt from the 8259 */
Olof Johansson49f19ce2006-10-05 20:31:10 -0500161 generic_handle_irq(cascade_irq);
Andy Flemingddd64152006-08-17 20:24:48 -0500162
Randy Vinson3620fc12007-06-06 16:26:15 -0700163 /* check for any interrupts from the shared IRQ line */
164 handle_fasteoi_irq(irq, desc);
Andy Flemingddd64152006-08-17 20:24:48 -0500165}
Randy Vinson3620fc12007-06-06 16:26:15 -0700166
167static irqreturn_t mpc85xx_8259_cascade_action(int irq, void *dev_id)
168{
169 return IRQ_HANDLED;
170}
171
172static struct irqaction mpc85xxcds_8259_irqaction = {
173 .handler = mpc85xx_8259_cascade_action,
174 .flags = IRQF_SHARED,
175 .mask = CPU_MASK_NONE,
176 .name = "8259 cascade",
177};
Andy Flemingddd64152006-08-17 20:24:48 -0500178#endif /* PPC_I8259 */
Andy Fleming591f0a42006-04-02 17:42:40 -0500179#endif /* CONFIG_PCI */
180
Kumar Gala27630be2007-02-09 09:30:45 -0600181static void __init mpc85xx_cds_pic_init(void)
Andy Fleming591f0a42006-04-02 17:42:40 -0500182{
Andy Flemingddd64152006-08-17 20:24:48 -0500183 struct mpic *mpic;
184 struct resource r;
185 struct device_node *np = NULL;
Randy Vinson3620fc12007-06-06 16:26:15 -0700186#if defined(CONFIG_PPC_I8259) && defined(CONFIG_PCI)
Andy Flemingddd64152006-08-17 20:24:48 -0500187 struct device_node *cascade_node = NULL;
188 int cascade_irq;
Olaf Hering35a84c22006-10-07 22:08:26 +1000189#endif
Andy Fleming591f0a42006-04-02 17:42:40 -0500190
Andy Flemingddd64152006-08-17 20:24:48 -0500191 np = of_find_node_by_type(np, "open-pic");
Andy Fleming591f0a42006-04-02 17:42:40 -0500192
Andy Flemingddd64152006-08-17 20:24:48 -0500193 if (np == NULL) {
194 printk(KERN_ERR "Could not find open-pic node\n");
195 return;
196 }
197
198 if (of_address_to_resource(np, 0, &r)) {
199 printk(KERN_ERR "Failed to map mpic register space\n");
200 of_node_put(np);
201 return;
202 }
203
204 mpic = mpic_alloc(np, r.start,
Andy Fleming591f0a42006-04-02 17:42:40 -0500205 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
Kumar Galab533f8a2007-07-03 02:35:35 -0500206 0, 256, " OpenPIC ");
Andy Flemingddd64152006-08-17 20:24:48 -0500207 BUG_ON(mpic == NULL);
Andy Fleming591f0a42006-04-02 17:42:40 -0500208
Andy Flemingddd64152006-08-17 20:24:48 -0500209 /* Return the mpic node */
210 of_node_put(np);
Andy Fleming591f0a42006-04-02 17:42:40 -0500211
Andy Flemingddd64152006-08-17 20:24:48 -0500212 mpic_init(mpic);
213
Randy Vinson3620fc12007-06-06 16:26:15 -0700214#if defined(CONFIG_PPC_I8259) && defined(CONFIG_PCI)
Andy Flemingddd64152006-08-17 20:24:48 -0500215 /* Initialize the i8259 controller */
216 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000217 if (of_device_is_compatible(np, "chrp,iic")) {
Andy Flemingddd64152006-08-17 20:24:48 -0500218 cascade_node = np;
219 break;
220 }
221
222 if (cascade_node == NULL) {
223 printk(KERN_DEBUG "Could not find i8259 PIC\n");
224 return;
225 }
226
227 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
228 if (cascade_irq == NO_IRQ) {
229 printk(KERN_ERR "Failed to map cascade interrupt\n");
230 return;
231 }
232
233 i8259_init(cascade_node, 0);
234 of_node_put(cascade_node);
235
Randy Vinson3620fc12007-06-06 16:26:15 -0700236 /*
237 * Hook the interrupt to make sure desc->action is never NULL.
238 * This is required to ensure that the interrupt does not get
239 * disabled when the last user of the shared IRQ line frees their
240 * interrupt.
241 */
242 if (setup_irq(cascade_irq, &mpc85xxcds_8259_irqaction))
243 printk(KERN_ERR "Failed to setup cascade interrupt\n");
244 else
245 /* Success. Connect our low-level cascade handler. */
246 set_irq_handler(cascade_irq, mpc85xx_8259_cascade_handler);
Andy Flemingddd64152006-08-17 20:24:48 -0500247#endif /* CONFIG_PPC_I8259 */
Andy Fleming591f0a42006-04-02 17:42:40 -0500248}
249
Andy Fleming591f0a42006-04-02 17:42:40 -0500250/*
251 * Setup the architecture
252 */
Kumar Gala27630be2007-02-09 09:30:45 -0600253static void __init mpc85xx_cds_setup_arch(void)
Andy Fleming591f0a42006-04-02 17:42:40 -0500254{
255 struct device_node *cpu;
256#ifdef CONFIG_PCI
257 struct device_node *np;
258#endif
259
260 if (ppc_md.progress)
261 ppc_md.progress("mpc85xx_cds_setup_arch()", 0);
262
263 cpu = of_find_node_by_type(NULL, "cpu");
264 if (cpu != 0) {
Jeremy Kerr8efca492006-07-12 15:39:42 +1000265 const unsigned int *fp;
Andy Fleming591f0a42006-04-02 17:42:40 -0500266
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000267 fp = of_get_property(cpu, "clock-frequency", NULL);
Andy Fleming591f0a42006-04-02 17:42:40 -0500268 if (fp != 0)
269 loops_per_jiffy = *fp / HZ;
270 else
271 loops_per_jiffy = 500000000 / HZ;
272 of_node_put(cpu);
273 }
274
275 cadmus = ioremap(CADMUS_BASE, CADMUS_SIZE);
276 cds_pci_slot = ((cadmus[CM_CSR] >> 6) & 0x3) + 1;
277
278 if (ppc_md.progress) {
279 char buf[40];
280 snprintf(buf, 40, "CDS Version = 0x%x in slot %d\n",
281 cadmus[CM_VER], cds_pci_slot);
282 ppc_md.progress(buf, 0);
283 }
284
285#ifdef CONFIG_PCI
Roy Zang3f6c5da2007-07-10 18:47:06 +0800286 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;) {
287 struct resource rsrc;
288 of_address_to_resource(np, 0, &rsrc);
289 if ((rsrc.start & 0xfffff) == 0x9000)
290 fsl_add_bridge(np, 0);
291 else
292 fsl_add_bridge(np, 1);
293 }
Roy Zang749e8082007-06-01 16:05:38 +0800294 ppc_md.pci_irq_fixup = mpc85xx_cds_pci_irq_fixup;
Andy Fleming591f0a42006-04-02 17:42:40 -0500295 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
296#endif
Andy Fleming591f0a42006-04-02 17:42:40 -0500297}
298
Kumar Gala27630be2007-02-09 09:30:45 -0600299static void mpc85xx_cds_show_cpuinfo(struct seq_file *m)
Andy Fleming591f0a42006-04-02 17:42:40 -0500300{
301 uint pvid, svid, phid1;
302 uint memsize = total_memory;
303
304 pvid = mfspr(SPRN_PVR);
305 svid = mfspr(SPRN_SVR);
306
307 seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
308 seq_printf(m, "Machine\t\t: MPC85xx CDS (0x%x)\n", cadmus[CM_VER]);
309 seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
310 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
311
312 /* Display cpu Pll setting */
313 phid1 = mfspr(SPRN_HID1);
314 seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
315
316 /* Display the amount of memory */
317 seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
318}
319
320
321/*
322 * Called very early, device-tree isn't unflattened
323 */
324static int __init mpc85xx_cds_probe(void)
325{
Kumar Gala6936c622007-02-17 16:19:34 -0600326 unsigned long root = of_get_flat_dt_root();
327
328 return of_flat_dt_is_compatible(root, "MPC85xxCDS");
Andy Fleming591f0a42006-04-02 17:42:40 -0500329}
330
331define_machine(mpc85xx_cds) {
332 .name = "MPC85xx CDS",
333 .probe = mpc85xx_cds_probe,
334 .setup_arch = mpc85xx_cds_setup_arch,
335 .init_IRQ = mpc85xx_cds_pic_init,
336 .show_cpuinfo = mpc85xx_cds_show_cpuinfo,
337 .get_irq = mpic_get_irq,
Randy Vinson637e9e12007-03-23 15:43:37 -0700338#ifdef CONFIG_PCI
339 .restart = mpc85xx_cds_restart,
340#else
Andy Fleming591f0a42006-04-02 17:42:40 -0500341 .restart = mpc85xx_restart,
Randy Vinson637e9e12007-03-23 15:43:37 -0700342#endif
Andy Fleming591f0a42006-04-02 17:42:40 -0500343 .calibrate_decr = generic_calibrate_decr,
344 .progress = udbg_progress,
Kumar Gala6c0a11c2007-07-19 15:29:53 -0500345 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
Andy Fleming591f0a42006-04-02 17:42:40 -0500346};