Merge branch 'sched-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / arch / powerpc / platforms / 85xx / mpc85xx_ds.c
1 /*
2  * MPC85xx DS Board Setup
3  *
4  * Author Xianghua Xiao (x.xiao@freescale.com)
5  * Roy Zang <tie-fei.zang@freescale.com>
6  *      - Add PCI/PCI Exprees support
7  * Copyright 2007 Freescale Semiconductor Inc.
8  *
9  * This program is free software; you can redistribute  it and/or modify it
10  * under  the terms of  the GNU General  Public License as published by the
11  * Free Software Foundation;  either version 2 of the  License, or (at your
12  * option) any later version.
13  */
14
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/kdev_t.h>
19 #include <linux/delay.h>
20 #include <linux/seq_file.h>
21 #include <linux/interrupt.h>
22 #include <linux/of_platform.h>
23
24 #include <asm/system.h>
25 #include <asm/time.h>
26 #include <asm/machdep.h>
27 #include <asm/pci-bridge.h>
28 #include <mm/mmu_decl.h>
29 #include <asm/prom.h>
30 #include <asm/udbg.h>
31 #include <asm/mpic.h>
32 #include <asm/i8259.h>
33
34 #include <sysdev/fsl_soc.h>
35 #include <sysdev/fsl_pci.h>
36
37 #undef DEBUG
38
39 #ifdef DEBUG
40 #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
41 #else
42 #define DBG(fmt, args...)
43 #endif
44
45 #ifdef CONFIG_PPC_I8259
46 static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
47 {
48         unsigned int cascade_irq = i8259_irq();
49
50         if (cascade_irq != NO_IRQ) {
51                 generic_handle_irq(cascade_irq);
52         }
53         desc->chip->eoi(irq);
54 }
55 #endif  /* CONFIG_PPC_I8259 */
56
57 void __init mpc85xx_ds_pic_init(void)
58 {
59         struct mpic *mpic;
60         struct resource r;
61         struct device_node *np;
62 #ifdef CONFIG_PPC_I8259
63         struct device_node *cascade_node = NULL;
64         int cascade_irq;
65 #endif
66
67         np = of_find_node_by_type(NULL, "open-pic");
68         if (np == NULL) {
69                 printk(KERN_ERR "Could not find open-pic node\n");
70                 return;
71         }
72
73         if (of_address_to_resource(np, 0, &r)) {
74                 printk(KERN_ERR "Failed to map mpic register space\n");
75                 of_node_put(np);
76                 return;
77         }
78
79         mpic = mpic_alloc(np, r.start,
80                           MPIC_PRIMARY | MPIC_WANTS_RESET |
81                           MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
82                         0, 256, " OpenPIC  ");
83         BUG_ON(mpic == NULL);
84         of_node_put(np);
85
86         mpic_init(mpic);
87
88 #ifdef CONFIG_PPC_I8259
89         /* Initialize the i8259 controller */
90         for_each_node_by_type(np, "interrupt-controller")
91             if (of_device_is_compatible(np, "chrp,iic")) {
92                 cascade_node = np;
93                 break;
94         }
95
96         if (cascade_node == NULL) {
97                 printk(KERN_DEBUG "Could not find i8259 PIC\n");
98                 return;
99         }
100
101         cascade_irq = irq_of_parse_and_map(cascade_node, 0);
102         if (cascade_irq == NO_IRQ) {
103                 printk(KERN_ERR "Failed to map cascade interrupt\n");
104                 return;
105         }
106
107         DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
108
109         i8259_init(cascade_node, 0);
110         of_node_put(cascade_node);
111
112         set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
113 #endif  /* CONFIG_PPC_I8259 */
114 }
115
116 #ifdef CONFIG_PCI
117 static int primary_phb_addr;
118 extern int uli_exclude_device(struct pci_controller *hose,
119                                 u_char bus, u_char devfn);
120
121 static int mpc85xx_exclude_device(struct pci_controller *hose,
122                                    u_char bus, u_char devfn)
123 {
124         struct device_node* node;
125         struct resource rsrc;
126
127         node = hose->dn;
128         of_address_to_resource(node, 0, &rsrc);
129
130         if ((rsrc.start & 0xfffff) == primary_phb_addr) {
131                 return uli_exclude_device(hose, bus, devfn);
132         }
133
134         return PCIBIOS_SUCCESSFUL;
135 }
136 #endif  /* CONFIG_PCI */
137
138 /*
139  * Setup the architecture
140  */
141 static void __init mpc85xx_ds_setup_arch(void)
142 {
143 #ifdef CONFIG_PCI
144         struct device_node *np;
145 #endif
146
147         if (ppc_md.progress)
148                 ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
149
150 #ifdef CONFIG_PCI
151         for_each_node_by_type(np, "pci") {
152                 if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
153                     of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
154                         struct resource rsrc;
155                         of_address_to_resource(np, 0, &rsrc);
156                         if ((rsrc.start & 0xfffff) == primary_phb_addr)
157                                 fsl_add_bridge(np, 1);
158                         else
159                                 fsl_add_bridge(np, 0);
160                 }
161         }
162
163         ppc_md.pci_exclude_device = mpc85xx_exclude_device;
164 #endif
165
166         printk("MPC85xx DS board from Freescale Semiconductor\n");
167 }
168
169 /*
170  * Called very early, device-tree isn't unflattened
171  */
172 static int __init mpc8544_ds_probe(void)
173 {
174         unsigned long root = of_get_flat_dt_root();
175
176         if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
177 #ifdef CONFIG_PCI
178                 primary_phb_addr = 0xb000;
179 #endif
180                 return 1;
181         } else {
182                 return 0;
183         }
184 }
185
186 static struct of_device_id __initdata mpc85xxds_ids[] = {
187         { .type = "soc", },
188         { .compatible = "soc", },
189         {},
190 };
191
192 static int __init mpc85xxds_publish_devices(void)
193 {
194         return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL);
195 }
196 machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices);
197 machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices);
198
199 /*
200  * Called very early, device-tree isn't unflattened
201  */
202 static int __init mpc8572_ds_probe(void)
203 {
204         unsigned long root = of_get_flat_dt_root();
205
206         if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
207 #ifdef CONFIG_PCI
208                 primary_phb_addr = 0x8000;
209 #endif
210                 return 1;
211         } else {
212                 return 0;
213         }
214 }
215
216 define_machine(mpc8544_ds) {
217         .name                   = "MPC8544 DS",
218         .probe                  = mpc8544_ds_probe,
219         .setup_arch             = mpc85xx_ds_setup_arch,
220         .init_IRQ               = mpc85xx_ds_pic_init,
221 #ifdef CONFIG_PCI
222         .pcibios_fixup_bus      = fsl_pcibios_fixup_bus,
223 #endif
224         .get_irq                = mpic_get_irq,
225         .restart                = fsl_rstcr_restart,
226         .calibrate_decr         = generic_calibrate_decr,
227         .progress               = udbg_progress,
228 };
229
230 define_machine(mpc8572_ds) {
231         .name                   = "MPC8572 DS",
232         .probe                  = mpc8572_ds_probe,
233         .setup_arch             = mpc85xx_ds_setup_arch,
234         .init_IRQ               = mpc85xx_ds_pic_init,
235 #ifdef CONFIG_PCI
236         .pcibios_fixup_bus      = fsl_pcibios_fixup_bus,
237 #endif
238         .get_irq                = mpic_get_irq,
239         .restart                = fsl_rstcr_restart,
240         .calibrate_decr         = generic_calibrate_decr,
241         .progress               = udbg_progress,
242 };