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