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