Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee13...
[pandora-kernel.git] / arch / powerpc / platforms / 85xx / mpc85xx_ads.c
1 /*
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
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/pci.h>
17 #include <linux/kdev_t.h>
18 #include <linux/delay.h>
19 #include <linux/seq_file.h>
20 #include <linux/root_dev.h>
21
22 #include <asm/system.h>
23 #include <asm/time.h>
24 #include <asm/machdep.h>
25 #include <asm/pci-bridge.h>
26 #include <asm/mpc85xx.h>
27 #include <asm/prom.h>
28 #include <asm/mpic.h>
29 #include <mm/mmu_decl.h>
30 #include <asm/udbg.h>
31
32 #include <sysdev/fsl_soc.h>
33 #include "mpc85xx.h"
34
35 #ifdef CONFIG_CPM2
36 #include <linux/fs_enet_pd.h>
37 #include <asm/cpm2.h>
38 #include <sysdev/cpm2_pic.h>
39 #include <asm/fs_pd.h>
40 #endif
41
42 #ifndef CONFIG_PCI
43 unsigned long isa_io_base = 0;
44 unsigned long isa_mem_base = 0;
45 #endif
46
47 #ifdef CONFIG_PCI
48 int
49 mpc85xx_exclude_device(u_char bus, u_char devfn)
50 {
51         if (bus == 0 && PCI_SLOT(devfn) == 0)
52                 return PCIBIOS_DEVICE_NOT_FOUND;
53         else
54                 return PCIBIOS_SUCCESSFUL;
55 }
56
57 void __init
58 mpc85xx_pcibios_fixup(void)
59 {
60         struct pci_dev *dev = NULL;
61
62         for_each_pci_dev(dev)
63                 pci_read_irq_line(dev);
64 }
65 #endif /* CONFIG_PCI */
66
67 #ifdef CONFIG_CPM2
68
69 static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
70 {
71         int cascade_irq;
72
73         while ((cascade_irq = cpm2_get_irq()) >= 0) {
74                 generic_handle_irq(cascade_irq);
75         }
76         desc->chip->eoi(irq);
77 }
78
79 #endif /* CONFIG_CPM2 */
80
81 void __init mpc85xx_ads_pic_init(void)
82 {
83         struct mpic *mpic;
84         struct resource r;
85         struct device_node *np = NULL;
86 #ifdef CONFIG_CPM2
87         int irq;
88 #endif
89
90         np = of_find_node_by_type(np, "open-pic");
91
92         if (np == NULL) {
93                 printk(KERN_ERR "Could not find open-pic node\n");
94                 return;
95         }
96
97         if(of_address_to_resource(np, 0, &r)) {
98                 printk(KERN_ERR "Could not map mpic register space\n");
99                 of_node_put(np);
100                 return;
101         }
102
103         mpic = mpic_alloc(np, r.start,
104                         MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
105                         4, 0, " OpenPIC  ");
106         BUG_ON(mpic == NULL);
107         of_node_put(np);
108
109         mpic_assign_isu(mpic, 0, r.start + 0x10200);
110         mpic_assign_isu(mpic, 1, r.start + 0x10280);
111         mpic_assign_isu(mpic, 2, r.start + 0x10300);
112         mpic_assign_isu(mpic, 3, r.start + 0x10380);
113         mpic_assign_isu(mpic, 4, r.start + 0x10400);
114         mpic_assign_isu(mpic, 5, r.start + 0x10480);
115         mpic_assign_isu(mpic, 6, r.start + 0x10500);
116         mpic_assign_isu(mpic, 7, r.start + 0x10580);
117
118         /* Unused on this platform (leave room for 8548) */
119         mpic_assign_isu(mpic, 8, r.start + 0x10600);
120         mpic_assign_isu(mpic, 9, r.start + 0x10680);
121         mpic_assign_isu(mpic, 10, r.start + 0x10700);
122         mpic_assign_isu(mpic, 11, r.start + 0x10780);
123
124         /* External Interrupts */
125         mpic_assign_isu(mpic, 12, r.start + 0x10000);
126         mpic_assign_isu(mpic, 13, r.start + 0x10080);
127         mpic_assign_isu(mpic, 14, r.start + 0x10100);
128
129         mpic_init(mpic);
130
131 #ifdef CONFIG_CPM2
132         /* Setup CPM2 PIC */
133         np = of_find_node_by_type(NULL, "cpm-pic");
134         if (np == NULL) {
135                 printk(KERN_ERR "PIC init: can not find cpm-pic node\n");
136                 return;
137         }
138         irq = irq_of_parse_and_map(np, 0);
139
140         cpm2_pic_init(np);
141         set_irq_chained_handler(irq, cpm2_cascade);
142 #endif
143 }
144
145 /*
146  * Setup the architecture
147  */
148 #ifdef CONFIG_CPM2
149 void init_fcc_ioports(struct fs_platform_info *fpi)
150 {
151         struct io_port *io = cpm2_map(im_ioport);
152         int fcc_no = fs_get_fcc_index(fpi->fs_no);
153         int target;
154         u32 tempval;
155
156         switch(fcc_no) {
157         case 1:
158                 tempval = in_be32(&io->iop_pdirb);
159                 tempval &= ~PB2_DIRB0;
160                 tempval |= PB2_DIRB1;
161                 out_be32(&io->iop_pdirb, tempval);
162
163                 tempval = in_be32(&io->iop_psorb);
164                 tempval &= ~PB2_PSORB0;
165                 tempval |= PB2_PSORB1;
166                 out_be32(&io->iop_psorb, tempval);
167
168                 tempval = in_be32(&io->iop_pparb);
169                 tempval |= (PB2_DIRB0 | PB2_DIRB1);
170                 out_be32(&io->iop_pparb, tempval);
171
172                 target = CPM_CLK_FCC2;
173                 break;
174         case 2:
175                 tempval = in_be32(&io->iop_pdirb);
176                 tempval &= ~PB3_DIRB0;
177                 tempval |= PB3_DIRB1;
178                 out_be32(&io->iop_pdirb, tempval);
179
180                 tempval = in_be32(&io->iop_psorb);
181                 tempval &= ~PB3_PSORB0;
182                 tempval |= PB3_PSORB1;
183                 out_be32(&io->iop_psorb, tempval);
184
185                 tempval = in_be32(&io->iop_pparb);
186                 tempval |= (PB3_DIRB0 | PB3_DIRB1);
187                 out_be32(&io->iop_pparb, tempval);
188
189                 tempval = in_be32(&io->iop_pdirc);
190                 tempval |= PC3_DIRC1;
191                 out_be32(&io->iop_pdirc, tempval);
192
193                 tempval = in_be32(&io->iop_pparc);
194                 tempval |= PC3_DIRC1;
195                 out_be32(&io->iop_pparc, tempval);
196
197                 target = CPM_CLK_FCC3;
198                 break;
199         default:
200                 printk(KERN_ERR "init_fcc_ioports: invalid FCC number\n");
201                 return;
202         }
203
204         /* Port C has clocks......  */
205         tempval = in_be32(&io->iop_psorc);
206         tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
207         out_be32(&io->iop_psorc, tempval);
208
209         tempval = in_be32(&io->iop_pdirc);
210         tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
211         out_be32(&io->iop_pdirc, tempval);
212         tempval = in_be32(&io->iop_pparc);
213         tempval |= (PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
214         out_be32(&io->iop_pparc, tempval);
215
216         cpm2_unmap(io);
217
218         /* Configure Serial Interface clock routing.
219          * First,  clear FCC bits to zero,
220          * then set the ones we want.
221          */
222         cpm2_clk_setup(target, fpi->clk_rx, CPM_CLK_RX);
223         cpm2_clk_setup(target, fpi->clk_tx, CPM_CLK_TX);
224 }
225 #endif
226
227 static void __init mpc85xx_ads_setup_arch(void)
228 {
229         struct device_node *cpu;
230 #ifdef CONFIG_PCI
231         struct device_node *np;
232 #endif
233
234         if (ppc_md.progress)
235                 ppc_md.progress("mpc85xx_ads_setup_arch()", 0);
236
237         cpu = of_find_node_by_type(NULL, "cpu");
238         if (cpu != 0) {
239                 const unsigned int *fp;
240
241                 fp = get_property(cpu, "clock-frequency", NULL);
242                 if (fp != 0)
243                         loops_per_jiffy = *fp / HZ;
244                 else
245                         loops_per_jiffy = 50000000 / HZ;
246                 of_node_put(cpu);
247         }
248
249 #ifdef CONFIG_CPM2
250         cpm2_reset();
251 #endif
252
253 #ifdef CONFIG_PCI
254         for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
255                 add_bridge(np);
256
257         ppc_md.pcibios_fixup = mpc85xx_pcibios_fixup;
258         ppc_md.pci_exclude_device = mpc85xx_exclude_device;
259 #endif
260
261 #ifdef  CONFIG_ROOT_NFS
262         ROOT_DEV = Root_NFS;
263 #else
264         ROOT_DEV = Root_HDA1;
265 #endif
266 }
267
268 void mpc85xx_ads_show_cpuinfo(struct seq_file *m)
269 {
270         uint pvid, svid, phid1;
271         uint memsize = total_memory;
272
273         pvid = mfspr(SPRN_PVR);
274         svid = mfspr(SPRN_SVR);
275
276         seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
277         seq_printf(m, "Machine\t\t: mpc85xx\n");
278         seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
279         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
280
281         /* Display cpu Pll setting */
282         phid1 = mfspr(SPRN_HID1);
283         seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
284
285         /* Display the amount of memory */
286         seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
287 }
288
289 /*
290  * Called very early, device-tree isn't unflattened
291  */
292 static int __init mpc85xx_ads_probe(void)
293 {
294         /* We always match for now, eventually we should look at the flat
295            dev tree to ensure this is the board we are suppose to run on
296         */
297         return 1;
298 }
299
300 define_machine(mpc85xx_ads) {
301         .name                   = "MPC85xx ADS",
302         .probe                  = mpc85xx_ads_probe,
303         .setup_arch             = mpc85xx_ads_setup_arch,
304         .init_IRQ               = mpc85xx_ads_pic_init,
305         .show_cpuinfo           = mpc85xx_ads_show_cpuinfo,
306         .get_irq                = mpic_get_irq,
307         .restart                = mpc85xx_restart,
308         .calibrate_decr         = generic_calibrate_decr,
309         .progress               = udbg_progress,
310 };