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