Merge ../linux-2.6-watchdog-mm
[linux-drm-fsl-dcu.git] / arch / powerpc / platforms / embedded6xx / mpc7448_hpc2.c
1 /*
2  * mpc7448_hpc2.c
3  *
4  * Board setup routines for the Freescale mpc7448hpc2(taiga) platform
5  *
6  * Author: Jacob Pan
7  *       jacob.pan@freescale.com
8  * Author: Xianghua Xiao
9  *       x.xiao@freescale.com
10  * Maintainer: Roy Zang <tie-fei.zang@freescale.com>
11  *      Add Flat Device Tree support fot mpc7448hpc2 board
12  *
13  * Copyright 2004-2006 Freescale Semiconductor, Inc.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version
18  * 2 of the License, or (at your option) any later version.
19  */
20
21 #include <linux/stddef.h>
22 #include <linux/kernel.h>
23 #include <linux/pci.h>
24 #include <linux/kdev_t.h>
25 #include <linux/console.h>
26 #include <linux/delay.h>
27 #include <linux/irq.h>
28 #include <linux/ide.h>
29 #include <linux/seq_file.h>
30 #include <linux/root_dev.h>
31 #include <linux/serial.h>
32 #include <linux/tty.h>
33 #include <linux/serial_core.h>
34
35 #include <asm/system.h>
36 #include <asm/time.h>
37 #include <asm/machdep.h>
38 #include <asm/prom.h>
39 #include <asm/udbg.h>
40 #include <asm/tsi108.h>
41 #include <asm/pci-bridge.h>
42 #include <asm/reg.h>
43 #include <mm/mmu_decl.h>
44 #include "mpc7448_hpc2.h"
45 #include <asm/tsi108_irq.h>
46 #include <asm/mpic.h>
47
48 #undef DEBUG
49 #ifdef DEBUG
50 #define DBG(fmt...) do { printk(fmt); } while(0)
51 #else
52 #define DBG(fmt...) do { } while(0)
53 #endif
54
55 #ifndef CONFIG_PCI
56 isa_io_base = MPC7448_HPC2_ISA_IO_BASE;
57 isa_mem_base = MPC7448_HPC2_ISA_MEM_BASE;
58 pci_dram_offset = MPC7448_HPC2_PCI_MEM_OFFSET;
59 #endif
60
61 extern int tsi108_setup_pci(struct device_node *dev);
62 extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
63 extern void tsi108_pci_int_init(void);
64 extern void tsi108_irq_cascade(unsigned int irq, struct irq_desc *desc);
65
66 int mpc7448_hpc2_exclude_device(u_char bus, u_char devfn)
67 {
68         if (bus == 0 && PCI_SLOT(devfn) == 0)
69                 return PCIBIOS_DEVICE_NOT_FOUND;
70         else
71                 return PCIBIOS_SUCCESSFUL;
72 }
73
74 /*
75  * find pci slot by devfn in interrupt map of OF tree
76  */
77 u8 find_slot_by_devfn(unsigned int *interrupt_map, unsigned int devfn)
78 {
79         int i;
80         unsigned int tmp;
81         for (i = 0; i < 4; i++){
82                 tmp = interrupt_map[i*4*7];
83                 if ((tmp >> 11) == (devfn >> 3))
84                         return i;
85         }
86         return i;
87 }
88
89 /*
90  * Scans the interrupt map for pci device
91  */
92 void mpc7448_hpc2_fixup_irq(struct pci_dev *dev)
93 {
94         struct pci_controller *hose;
95         struct device_node *node;
96         const unsigned int *interrupt;
97         int busnr;
98         int len;
99         u8 slot;
100         u8 pin;
101
102         /* Lookup the hose */
103         busnr = dev->bus->number;
104         hose = pci_bus_to_hose(busnr);
105         if (!hose)
106                 printk(KERN_ERR "No pci hose found\n");
107
108         /* Check it has an OF node associated */
109         node = (struct device_node *) hose->arch_data;
110         if (!node)
111                 printk(KERN_ERR "No pci node found\n");
112
113         interrupt = get_property(node, "interrupt-map", &len);
114         slot = find_slot_by_devfn(interrupt, dev->devfn);
115         pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
116         if (pin == 0 || pin > 4)
117                 pin = 1;
118         pin--;
119         dev->irq  = interrupt[slot*4*7 + pin*7 + 5];
120         DBG("TSI_PCI: dev->irq = 0x%x\n", dev->irq);
121 }
122 /* temporary pci irq map fixup*/
123
124 void __init mpc7448_hpc2_pcibios_fixup(void)
125 {
126         struct pci_dev *dev = NULL;
127         for_each_pci_dev(dev) {
128                 mpc7448_hpc2_fixup_irq(dev);
129                 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
130         }
131 }
132
133 static void __init mpc7448_hpc2_setup_arch(void)
134 {
135         struct device_node *cpu;
136         struct device_node *np;
137         if (ppc_md.progress)
138                 ppc_md.progress("mpc7448_hpc2_setup_arch():set_bridge", 0);
139
140         cpu = of_find_node_by_type(NULL, "cpu");
141         if (cpu != 0) {
142                 const unsigned int *fp;
143
144                 fp = get_property(cpu, "clock-frequency", NULL);
145                 if (fp != 0)
146                         loops_per_jiffy = *fp / HZ;
147                 else
148                         loops_per_jiffy = 50000000 / HZ;
149                 of_node_put(cpu);
150         }
151         tsi108_csr_vir_base = get_vir_csrbase();
152
153 #ifdef  CONFIG_ROOT_NFS
154         ROOT_DEV = Root_NFS;
155 #else
156         ROOT_DEV = Root_HDA1;
157 #endif
158
159 #ifdef CONFIG_BLK_DEV_INITRD
160         ROOT_DEV = Root_RAM0;
161 #endif
162
163         /* setup PCI host bridge */
164 #ifdef CONFIG_PCI
165         for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
166                 tsi108_setup_pci(np);
167
168         ppc_md.pci_exclude_device = mpc7448_hpc2_exclude_device;
169         if (ppc_md.progress)
170                 ppc_md.progress("tsi108: resources set", 0x100);
171 #endif
172
173         printk(KERN_INFO "MPC7448HPC2 (TAIGA) Platform\n");
174         printk(KERN_INFO
175                "Jointly ported by Freescale and Tundra Semiconductor\n");
176         printk(KERN_INFO
177                "Enabling L2 cache then enabling the HID0 prefetch engine.\n");
178 }
179
180 /*
181  * Interrupt setup and service.  Interrrupts on the mpc7448_hpc2 come
182  * from the four external INT pins, PCI interrupts are routed via
183  * PCI interrupt control registers, it generates internal IRQ23
184  *
185  * Interrupt routing on the Taiga Board:
186  * TSI108:PB_INT[0] -> CPU0:INT#
187  * TSI108:PB_INT[1] -> CPU0:MCP#
188  * TSI108:PB_INT[2] -> N/C
189  * TSI108:PB_INT[3] -> N/C
190  */
191 static void __init mpc7448_hpc2_init_IRQ(void)
192 {
193         struct mpic *mpic;
194         phys_addr_t mpic_paddr = 0;
195         unsigned int cascade_pci_irq;
196         struct device_node *tsi_pci;
197         struct device_node *tsi_pic;
198
199         tsi_pic = of_find_node_by_type(NULL, "open-pic");
200         if (tsi_pic) {
201                 unsigned int size;
202                 const void *prop = get_property(tsi_pic, "reg", &size);
203                 mpic_paddr = of_translate_address(tsi_pic, prop);
204         }
205
206         if (mpic_paddr == 0) {
207                 printk("%s: No tsi108 PIC found !\n", __FUNCTION__);
208                 return;
209         }
210
211         DBG("%s: tsi108pic phys_addr = 0x%x\n", __FUNCTION__,
212             (u32) mpic_paddr);
213
214         mpic = mpic_alloc(tsi_pic, mpic_paddr,
215                         MPIC_PRIMARY | MPIC_BIG_ENDIAN | MPIC_WANTS_RESET |
216                         MPIC_SPV_EOI | MPIC_NO_PTHROU_DIS | MPIC_REGSET_TSI108,
217                         0, /* num_sources used */
218                         0, /* num_sources used */
219                         "Tsi108_PIC");
220
221         BUG_ON(mpic == NULL); /* XXXX */
222         mpic_init(mpic);
223
224         tsi_pci = of_find_node_by_type(NULL, "pci");
225         if (tsi_pci == 0) {
226                 printk("%s: No tsi108 pci node found !\n", __FUNCTION__);
227                 return;
228         }
229
230         cascade_pci_irq = irq_of_parse_and_map(tsi_pci, 0);
231         set_irq_data(cascade_pci_irq, mpic);
232         set_irq_chained_handler(cascade_pci_irq, tsi108_irq_cascade);
233
234         tsi108_pci_int_init();
235
236         /* Configure MPIC outputs to CPU0 */
237         tsi108_write_reg(TSI108_MPIC_OFFSET + 0x30c, 0);
238         of_node_put(tsi_pic);
239 }
240
241 void mpc7448_hpc2_show_cpuinfo(struct seq_file *m)
242 {
243         seq_printf(m, "vendor\t\t: Freescale Semiconductor\n");
244         seq_printf(m, "machine\t\t: MPC7448hpc2\n");
245 }
246
247 void mpc7448_hpc2_restart(char *cmd)
248 {
249         local_irq_disable();
250
251         /* Set exception prefix high - to the firmware */
252         _nmask_and_or_msr(0, MSR_IP);
253
254         for (;;) ;              /* Spin until reset happens */
255 }
256
257 void mpc7448_hpc2_power_off(void)
258 {
259         local_irq_disable();
260         for (;;) ;              /* No way to shut power off with software */
261 }
262
263 void mpc7448_hpc2_halt(void)
264 {
265         mpc7448_hpc2_power_off();
266 }
267
268 /*
269  * Called very early, device-tree isn't unflattened
270  */
271 static int __init mpc7448_hpc2_probe(void)
272 {
273         unsigned long root = of_get_flat_dt_root();
274
275         if (!of_flat_dt_is_compatible(root, "mpc74xx"))
276                 return 0;
277         return 1;
278 }
279
280 static int mpc7448_machine_check_exception(struct pt_regs *regs)
281 {
282         extern void tsi108_clear_pci_cfg_error(void);
283         const struct exception_table_entry *entry;
284
285         /* Are we prepared to handle this fault */
286         if ((entry = search_exception_tables(regs->nip)) != NULL) {
287                 tsi108_clear_pci_cfg_error();
288                 regs->msr |= MSR_RI;
289                 regs->nip = entry->fixup;
290                 return 1;
291         }
292         return 0;
293
294 }
295
296 define_machine(mpc7448_hpc2){
297         .name                   = "MPC7448 HPC2",
298         .probe                  = mpc7448_hpc2_probe,
299         .setup_arch             = mpc7448_hpc2_setup_arch,
300         .init_IRQ               = mpc7448_hpc2_init_IRQ,
301         .show_cpuinfo           = mpc7448_hpc2_show_cpuinfo,
302         .get_irq                = mpic_get_irq,
303         .pcibios_fixup          = mpc7448_hpc2_pcibios_fixup,
304         .restart                = mpc7448_hpc2_restart,
305         .calibrate_decr         = generic_calibrate_decr,
306         .machine_check_exception= mpc7448_machine_check_exception,
307         .progress               = udbg_progress,
308 };