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