Merge master.kernel.org:/home/rmk/linux-2.6-mmc
[sfrench/cifs-2.6.git] / arch / ppc / platforms / 83xx / mpc834x_sys.c
1 /*
2  * arch/ppc/platforms/83xx/mpc834x_sys.c
3  *
4  * MPC834x SYS board specific routines
5  *
6  * Maintainer: Kumar Gala <galak@kernel.crashing.org>
7  *
8  * Copyright 2005 Freescale Semiconductor Inc.
9  *
10  * This program is free software; you can redistribute  it and/or modify it
11  * under  the terms of  the GNU General  Public License as published by the
12  * Free Software Foundation;  either version 2 of the  License, or (at your
13  * option) any later version.
14  */
15
16 #include <linux/config.h>
17 #include <linux/stddef.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/reboot.h>
22 #include <linux/pci.h>
23 #include <linux/kdev_t.h>
24 #include <linux/major.h>
25 #include <linux/console.h>
26 #include <linux/delay.h>
27 #include <linux/seq_file.h>
28 #include <linux/root_dev.h>
29 #include <linux/serial.h>
30 #include <linux/tty.h>  /* for linux/serial_core.h */
31 #include <linux/serial_core.h>
32 #include <linux/initrd.h>
33 #include <linux/module.h>
34 #include <linux/fsl_devices.h>
35
36 #include <asm/system.h>
37 #include <asm/pgtable.h>
38 #include <asm/page.h>
39 #include <asm/atomic.h>
40 #include <asm/time.h>
41 #include <asm/io.h>
42 #include <asm/machdep.h>
43 #include <asm/ipic.h>
44 #include <asm/bootinfo.h>
45 #include <asm/pci-bridge.h>
46 #include <asm/mpc83xx.h>
47 #include <asm/irq.h>
48 #include <asm/kgdb.h>
49 #include <asm/ppc_sys.h>
50 #include <mm/mmu_decl.h>
51
52 #include <syslib/ppc83xx_setup.h>
53
54 static const char *GFAR_PHY_0 = "phy0:0";
55 static const char *GFAR_PHY_1 = "phy0:1";
56
57 #ifndef CONFIG_PCI
58 unsigned long isa_io_base = 0;
59 unsigned long isa_mem_base = 0;
60 #endif
61
62 extern unsigned long total_memory;      /* in mm/init */
63
64 unsigned char __res[sizeof (bd_t)];
65
66 #ifdef CONFIG_PCI
67 int
68 mpc83xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
69 {
70         static char pci_irq_table[][4] =
71             /*
72              *      PCI IDSEL/INTPIN->INTLINE
73              *       A      B      C      D
74              */
75         {
76                 {PIRQA, PIRQB, PIRQC, PIRQD},   /* idsel 0x11 */
77                 {PIRQC, PIRQD, PIRQA, PIRQB},   /* idsel 0x12 */
78                 {PIRQD, PIRQA, PIRQB, PIRQC},   /* idsel 0x13 */
79                 {0, 0, 0, 0},
80                 {PIRQA, PIRQB, PIRQC, PIRQD},   /* idsel 0x15 */
81                 {PIRQD, PIRQA, PIRQB, PIRQC},   /* idsel 0x16 */
82                 {PIRQC, PIRQD, PIRQA, PIRQB},   /* idsel 0x17 */
83                 {PIRQB, PIRQC, PIRQD, PIRQA},   /* idsel 0x18 */
84                 {0, 0, 0, 0},                   /* idsel 0x19 */
85                 {0, 0, 0, 0},                   /* idsel 0x20 */
86         };
87
88         const long min_idsel = 0x11, max_idsel = 0x20, irqs_per_slot = 4;
89         return PCI_IRQ_TABLE_LOOKUP;
90 }
91
92 int
93 mpc83xx_exclude_device(u_char bus, u_char devfn)
94 {
95         return PCIBIOS_SUCCESSFUL;
96 }
97 #endif /* CONFIG_PCI */
98
99 /* ************************************************************************
100  *
101  * Setup the architecture
102  *
103  */
104 static void __init
105 mpc834x_sys_setup_arch(void)
106 {
107         bd_t *binfo = (bd_t *) __res;
108         unsigned int freq;
109         struct gianfar_platform_data *pdata;
110         struct gianfar_mdio_data *mdata;
111
112         /* get the core frequency */
113         freq = binfo->bi_intfreq;
114
115         /* Set loops_per_jiffy to a half-way reasonable value,
116            for use until calibrate_delay gets called. */
117         loops_per_jiffy = freq / HZ;
118
119 #ifdef CONFIG_PCI
120         /* setup PCI host bridges */
121         mpc83xx_setup_hose();
122 #endif
123         mpc83xx_early_serial_map();
124
125         /* setup the board related info for the MDIO bus */
126         mdata = (struct gianfar_mdio_data *) ppc_sys_get_pdata(MPC83xx_MDIO);
127
128         mdata->irq[0] = MPC83xx_IRQ_EXT1;
129         mdata->irq[1] = MPC83xx_IRQ_EXT2;
130         mdata->irq[2] = -1;
131         mdata->irq[31] = -1;
132         mdata->paddr += binfo->bi_immr_base;
133
134         /* setup the board related information for the enet controllers */
135         pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC83xx_TSEC1);
136         if (pdata) {
137                 pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
138                 pdata->bus_id = GFAR_PHY_0;
139                 memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
140         }
141
142         pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC83xx_TSEC2);
143         if (pdata) {
144                 pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
145                 pdata->bus_id = GFAR_PHY_1;
146                 memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
147         }
148
149 #ifdef CONFIG_BLK_DEV_INITRD
150         if (initrd_start)
151                 ROOT_DEV = Root_RAM0;
152         else
153 #endif
154 #ifdef  CONFIG_ROOT_NFS
155                 ROOT_DEV = Root_NFS;
156 #else
157                 ROOT_DEV = Root_HDA1;
158 #endif
159 }
160
161 static void __init
162 mpc834x_sys_map_io(void)
163 {
164         /* we steal the lowest ioremap addr for virt space */
165         io_block_mapping(VIRT_IMMRBAR, immrbar, 1024*1024, _PAGE_IO);
166 }
167
168 int
169 mpc834x_sys_show_cpuinfo(struct seq_file *m)
170 {
171         uint pvid, svid, phid1;
172         bd_t *binfo = (bd_t *) __res;
173         unsigned int freq;
174
175         /* get the core frequency */
176         freq = binfo->bi_intfreq;
177
178         pvid = mfspr(SPRN_PVR);
179         svid = mfspr(SPRN_SVR);
180
181         seq_printf(m, "Vendor\t\t: Freescale Inc.\n");
182         seq_printf(m, "Machine\t\t: mpc%s sys\n", cur_ppc_sys_spec->ppc_sys_name);
183         seq_printf(m, "core clock\t: %d MHz\n"
184                         "bus  clock\t: %d MHz\n",
185                         (int)(binfo->bi_intfreq / 1000000),
186                         (int)(binfo->bi_busfreq / 1000000));
187         seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
188         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
189
190         /* Display cpu Pll setting */
191         phid1 = mfspr(SPRN_HID1);
192         seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
193
194         /* Display the amount of memory */
195         seq_printf(m, "Memory\t\t: %d MB\n", (int)(binfo->bi_memsize / (1024 * 1024)));
196
197         return 0;
198 }
199
200
201 void __init
202 mpc834x_sys_init_IRQ(void)
203 {
204         bd_t *binfo = (bd_t *) __res;
205
206         u8 senses[8] = {
207                 0,                      /* EXT 0 */
208                 IRQ_SENSE_LEVEL,        /* EXT 1 */
209                 IRQ_SENSE_LEVEL,        /* EXT 2 */
210                 0,                      /* EXT 3 */
211 #ifdef CONFIG_PCI
212                 IRQ_SENSE_LEVEL,        /* EXT 4 */
213                 IRQ_SENSE_LEVEL,        /* EXT 5 */
214                 IRQ_SENSE_LEVEL,        /* EXT 6 */
215                 IRQ_SENSE_LEVEL,        /* EXT 7 */
216 #else
217                 0,                      /* EXT 4 */
218                 0,                      /* EXT 5 */
219                 0,                      /* EXT 6 */
220                 0,                      /* EXT 7 */
221 #endif
222         };
223
224         ipic_init(binfo->bi_immr_base + 0x00700, 0, MPC83xx_IPIC_IRQ_OFFSET, senses, 8);
225
226         /* Initialize the default interrupt mapping priorities,
227          * in case the boot rom changed something on us.
228          */
229         ipic_set_default_priority();
230 }
231
232 #if defined(CONFIG_I2C_MPC) && defined(CONFIG_SENSORS_DS1374)
233 extern ulong    ds1374_get_rtc_time(void);
234 extern int      ds1374_set_rtc_time(ulong);
235
236 static int __init
237 mpc834x_rtc_hookup(void)
238 {
239         struct timespec tv;
240
241         ppc_md.get_rtc_time = ds1374_get_rtc_time;
242         ppc_md.set_rtc_time = ds1374_set_rtc_time;
243
244         tv.tv_nsec = 0;
245         tv.tv_sec = (ppc_md.get_rtc_time)();
246         do_settimeofday(&tv);
247
248         return 0;
249 }
250 late_initcall(mpc834x_rtc_hookup);
251 #endif
252 static __inline__ void
253 mpc834x_sys_set_bat(void)
254 {
255         /* we steal the lowest ioremap addr for virt space */
256         mb();
257         mtspr(SPRN_DBAT1U, VIRT_IMMRBAR | 0x1e);
258         mtspr(SPRN_DBAT1L, immrbar | 0x2a);
259         mb();
260 }
261
262 void __init
263 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
264               unsigned long r6, unsigned long r7)
265 {
266         bd_t *binfo = (bd_t *) __res;
267
268         /* parse_bootinfo must always be called first */
269         parse_bootinfo(find_bootinfo());
270
271         /*
272          * If we were passed in a board information, copy it into the
273          * residual data area.
274          */
275         if (r3) {
276                 memcpy((void *) __res, (void *) (r3 + KERNELBASE),
277                        sizeof (bd_t));
278         }
279
280 #if defined(CONFIG_BLK_DEV_INITRD)
281         /*
282          * If the init RAM disk has been configured in, and there's a valid
283          * starting address for it, set it up.
284          */
285         if (r4) {
286                 initrd_start = r4 + KERNELBASE;
287                 initrd_end = r5 + KERNELBASE;
288         }
289 #endif /* CONFIG_BLK_DEV_INITRD */
290
291         /* Copy the kernel command line arguments to a safe place. */
292         if (r6) {
293                 *(char *) (r7 + KERNELBASE) = 0;
294                 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
295         }
296
297         immrbar = binfo->bi_immr_base;
298
299         mpc834x_sys_set_bat();
300
301 #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
302         {
303                 struct uart_port p;
304
305                 memset(&p, 0, sizeof (p));
306                 p.iotype = SERIAL_IO_MEM;
307                 p.membase = (unsigned char __iomem *)(VIRT_IMMRBAR + 0x4500);
308                 p.uartclk = binfo->bi_busfreq;
309
310                 gen550_init(0, &p);
311
312                 memset(&p, 0, sizeof (p));
313                 p.iotype = SERIAL_IO_MEM;
314                 p.membase = (unsigned char __iomem *)(VIRT_IMMRBAR + 0x4600);
315                 p.uartclk = binfo->bi_busfreq;
316
317                 gen550_init(1, &p);
318         }
319 #endif
320
321         identify_ppc_sys_by_id(mfspr(SPRN_SVR));
322
323         /* setup the PowerPC module struct */
324         ppc_md.setup_arch = mpc834x_sys_setup_arch;
325         ppc_md.show_cpuinfo = mpc834x_sys_show_cpuinfo;
326
327         ppc_md.init_IRQ = mpc834x_sys_init_IRQ;
328         ppc_md.get_irq = ipic_get_irq;
329
330         ppc_md.restart = mpc83xx_restart;
331         ppc_md.power_off = mpc83xx_power_off;
332         ppc_md.halt = mpc83xx_halt;
333
334         ppc_md.find_end_of_memory = mpc83xx_find_end_of_memory;
335         ppc_md.setup_io_mappings  = mpc834x_sys_map_io;
336
337         ppc_md.time_init = mpc83xx_time_init;
338         ppc_md.set_rtc_time = NULL;
339         ppc_md.get_rtc_time = NULL;
340         ppc_md.calibrate_decr = mpc83xx_calibrate_decr;
341
342         ppc_md.early_serial_map = mpc83xx_early_serial_map;
343 #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
344         ppc_md.progress = gen550_progress;
345 #endif  /* CONFIG_SERIAL_8250 && CONFIG_SERIAL_TEXT_DEBUG */
346
347         if (ppc_md.progress)
348                 ppc_md.progress("mpc834x_sys_init(): exit", 0);
349
350         return;
351 }