blob: b436f4d0a3fa753e2a1b54764dbcab0b0150a26f [file] [log] [blame]
Kumar Galaa819f8b2005-12-09 11:57:44 -06001/*
2 * arch/ppc/platforms/85xx/tqm85xx.c
3 *
4 * TQM85xx (40/41/55/60) board specific routines
5 *
6 * Copyright (c) 2005 DENX Software Engineering
7 * Stefan Roese <sr@denx.de>
8 *
9 * Based on original work by
10 * Kumar Gala <galak@kernel.crashing.org>
11 * Copyright 2004 Freescale Semiconductor Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
19#include <linux/config.h>
20#include <linux/stddef.h>
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/errno.h>
24#include <linux/reboot.h>
25#include <linux/pci.h>
26#include <linux/kdev_t.h>
27#include <linux/major.h>
28#include <linux/console.h>
29#include <linux/delay.h>
30#include <linux/seq_file.h>
31#include <linux/root_dev.h>
32#include <linux/serial.h>
33#include <linux/tty.h> /* for linux/serial_core.h */
34#include <linux/serial_core.h>
35#include <linux/initrd.h>
36#include <linux/module.h>
37#include <linux/fsl_devices.h>
38
39#include <asm/system.h>
40#include <asm/pgtable.h>
41#include <asm/page.h>
42#include <asm/atomic.h>
43#include <asm/time.h>
44#include <asm/io.h>
45#include <asm/machdep.h>
46#include <asm/open_pic.h>
47#include <asm/bootinfo.h>
48#include <asm/pci-bridge.h>
49#include <asm/mpc85xx.h>
50#include <asm/irq.h>
51#include <asm/immap_85xx.h>
52#include <asm/kgdb.h>
53#include <asm/ppc_sys.h>
54#include <asm/cpm2.h>
55#include <mm/mmu_decl.h>
56
57#include <syslib/ppc85xx_setup.h>
58#include <syslib/cpm2_pic.h>
59#include <syslib/ppc85xx_common.h>
60#include <syslib/ppc85xx_rio.h>
61
62#ifndef CONFIG_PCI
63unsigned long isa_io_base = 0;
64unsigned long isa_mem_base = 0;
65#endif
66
67
68extern unsigned long total_memory; /* in mm/init */
69
70unsigned char __res[sizeof (bd_t)];
71
72/* Internal interrupts are all Level Sensitive, and Positive Polarity */
73static u_char tqm85xx_openpic_initsenses[] __initdata = {
74 MPC85XX_INTERNAL_IRQ_SENSES,
75 0x0, /* External 0: */
76 0x0, /* External 1: */
77#if defined(CONFIG_PCI)
78 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 2: PCI INTA */
79 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 3: PCI INTB */
80#else
81 0x0, /* External 2: */
82 0x0, /* External 3: */
83#endif
84 0x0, /* External 4: */
85 0x0, /* External 5: */
86 0x0, /* External 6: */
87 0x0, /* External 7: */
88 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 8: PHY */
89 0x0, /* External 9: */
90 0x0, /* External 10: */
91 0x0, /* External 11: */
92};
93
Kumar Galaa819f8b2005-12-09 11:57:44 -060094/* ************************************************************************
95 *
96 * Setup the architecture
97 *
98 */
99static void __init
100tqm85xx_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#ifdef CONFIG_MPC8560
108 cpm2_reset();
109#endif
110
111 /* get the core frequency */
112 freq = binfo->bi_intfreq;
113
114 if (ppc_md.progress)
115 ppc_md.progress("tqm85xx_setup_arch()", 0);
116
117 /* Set loops_per_jiffy to a half-way reasonable value,
118 for use until calibrate_delay gets called. */
119 loops_per_jiffy = freq / HZ;
120
121#ifdef CONFIG_PCI
122 /* setup PCI host bridges */
123 mpc85xx_setup_hose();
124#endif
125
126#ifndef CONFIG_MPC8560
127#if defined(CONFIG_SERIAL_8250)
128 mpc85xx_early_serial_map();
129#endif
130
131#ifdef CONFIG_SERIAL_TEXT_DEBUG
132 /* Invalidate the entry we stole earlier the serial ports
133 * should be properly mapped */
134 invalidate_tlbcam_entry(num_tlbcam_entries - 1);
135#endif
136#endif /* CONFIG_MPC8560 */
137
138 /* setup the board related info for the MDIO bus */
139 mdata = (struct gianfar_mdio_data *) ppc_sys_get_pdata(MPC85xx_MDIO);
140
141 mdata->irq[0] = MPC85xx_IRQ_EXT8;
142 mdata->irq[1] = MPC85xx_IRQ_EXT8;
143 mdata->irq[2] = -1;
144 mdata->irq[3] = MPC85xx_IRQ_EXT8;
145 mdata->irq[31] = -1;
Kumar Galaa819f8b2005-12-09 11:57:44 -0600146
147 /* setup the board related information for the enet controllers */
148 pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC1);
149 if (pdata) {
150 pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
Kumar Gala7e78e5e2006-01-12 21:04:23 -0600151 pdata->bus_id = 0;
152 pdata->phy_id = 2;
Kumar Galaa819f8b2005-12-09 11:57:44 -0600153 memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
154 }
155
156 pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC2);
157 if (pdata) {
158 pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
Kumar Gala7e78e5e2006-01-12 21:04:23 -0600159 pdata->bus_id = 0;
160 pdata->phy_id = 1;
Kumar Galaa819f8b2005-12-09 11:57:44 -0600161 memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
162 }
163
164#ifdef CONFIG_MPC8540
165 pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_FEC);
166 if (pdata) {
167 pdata->board_flags = 0;
Kumar Gala7e78e5e2006-01-12 21:04:23 -0600168 pdata->bus_id = 0;
169 pdata->phy_id = 3;
Kumar Galaa819f8b2005-12-09 11:57:44 -0600170 memcpy(pdata->mac_addr, binfo->bi_enet2addr, 6);
171 }
172#endif
173
174#ifdef CONFIG_BLK_DEV_INITRD
175 if (initrd_start)
176 ROOT_DEV = Root_RAM0;
177 else
178#endif
179#ifdef CONFIG_ROOT_NFS
180 ROOT_DEV = Root_NFS;
181#else
182 ROOT_DEV = Root_HDA1;
183#endif
184}
185
186#ifdef CONFIG_MPC8560
187static irqreturn_t cpm2_cascade(int irq, void *dev_id, struct pt_regs *regs)
188{
189 while ((irq = cpm2_get_irq(regs)) >= 0)
190 __do_IRQ(irq, regs);
191 return IRQ_HANDLED;
192}
193
194static struct irqaction cpm2_irqaction = {
195 .handler = cpm2_cascade,
196 .flags = SA_INTERRUPT,
197 .mask = CPU_MASK_NONE,
198 .name = "cpm2_cascade",
199};
200#endif /* CONFIG_MPC8560 */
201
202void __init
203tqm85xx_init_IRQ(void)
204{
205 bd_t *binfo = (bd_t *) __res;
206
207 /* Determine the Physical Address of the OpenPIC regs */
208 phys_addr_t OpenPIC_PAddr =
209 binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
210 OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
211 OpenPIC_InitSenses = tqm85xx_openpic_initsenses;
212 OpenPIC_NumInitSenses = sizeof (tqm85xx_openpic_initsenses);
213
214 /* Skip reserved space and internal sources */
215 openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
216
217 /* Map PIC IRQs 0-11 */
218 openpic_set_sources(48, 12, OpenPIC_Addr + 0x10000);
219
220 /* we let openpic interrupts starting from an offset, to
221 * leave space for cascading interrupts underneath.
222 */
223 openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
224
225#ifdef CONFIG_MPC8560
226 /* Setup CPM2 PIC */
227 cpm2_init_IRQ();
228
229 setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
230#endif /* CONFIG_MPC8560 */
231
232 return;
233}
234
235int tqm85xx_show_cpuinfo(struct seq_file *m)
236{
237 uint pvid, svid, phid1;
238 uint memsize = total_memory;
239 bd_t *binfo = (bd_t *) __res;
240 unsigned int freq;
241
242 /* get the core frequency */
243 freq = binfo->bi_intfreq;
244
245 pvid = mfspr(SPRN_PVR);
246 svid = mfspr(SPRN_SVR);
247
248 seq_printf(m, "Vendor\t\t: TQ Components\n");
249 seq_printf(m, "Machine\t\t: TQM%s\n", cur_ppc_sys_spec->ppc_sys_name);
250 seq_printf(m, "clock\t\t: %dMHz\n", freq / 1000000);
251 seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
252 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
253
254 /* Display cpu Pll setting */
255 phid1 = mfspr(SPRN_HID1);
256 seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
257
258 /* Display the amount of memory */
259 seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
260
261 return 0;
262}
263
264#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_DS1337)
265extern ulong ds1337_get_rtc_time(void);
266extern int ds1337_set_rtc_time(unsigned long nowtime);
267
268static int __init
269tqm85xx_rtc_hookup(void)
270{
271 struct timespec tv;
272
273 ppc_md.set_rtc_time = ds1337_set_rtc_time;
274 ppc_md.get_rtc_time = ds1337_get_rtc_time;
275
276 tv.tv_nsec = 0;
277 tv.tv_sec = (ppc_md.get_rtc_time)();
278 do_settimeofday(&tv);
279
280 return 0;
281}
282late_initcall(tqm85xx_rtc_hookup);
283#endif
284
285#ifdef CONFIG_PCI
286/*
287 * interrupt routing
288 */
289int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
290{
291 static char pci_irq_table[][4] =
292 /*
293 * PCI IDSEL/INTPIN->INTLINE
294 * A B C D
295 */
296 {
297 {PIRQA, PIRQB, 0, 0},
298 };
299
300 const long min_idsel = 0x1c, max_idsel = 0x1c, irqs_per_slot = 4;
301 return PCI_IRQ_TABLE_LOOKUP;
302}
303
304int mpc85xx_exclude_device(u_char bus, u_char devfn)
305{
306 if (bus == 0 && PCI_SLOT(devfn) == 0)
307 return PCIBIOS_DEVICE_NOT_FOUND;
308 else
309 return PCIBIOS_SUCCESSFUL;
310}
311
312#endif /* CONFIG_PCI */
313
314#ifdef CONFIG_RAPIDIO
315void platform_rio_init(void)
316{
317 /* 512MB RIO LAW at 0xc0000000 */
318 mpc85xx_rio_setup(0xc0000000, 0x20000000);
319}
320#endif /* CONFIG_RAPIDIO */
321
322/* ************************************************************************ */
323void __init
324platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
325 unsigned long r6, unsigned long r7)
326{
327 /* parse_bootinfo must always be called first */
328 parse_bootinfo(find_bootinfo());
329
330 /*
331 * If we were passed in a board information, copy it into the
332 * residual data area.
333 */
334 if (r3) {
335 memcpy((void *) __res, (void *) (r3 + KERNELBASE),
336 sizeof (bd_t));
337 }
338
339#if defined(CONFIG_SERIAL_TEXT_DEBUG) && !defined(CONFIG_MPC8560)
340 {
341 bd_t *binfo = (bd_t *) __res;
342 struct uart_port p;
343
344 /* Use the last TLB entry to map CCSRBAR to allow access to DUART regs */
345 settlbcam(num_tlbcam_entries - 1, binfo->bi_immr_base,
346 binfo->bi_immr_base, MPC85xx_CCSRBAR_SIZE, _PAGE_IO, 0);
347
348 memset(&p, 0, sizeof (p));
349 p.iotype = SERIAL_IO_MEM;
350 p.membase = (void *) binfo->bi_immr_base + MPC85xx_UART0_OFFSET;
351 p.uartclk = binfo->bi_busfreq;
352
353 gen550_init(0, &p);
354
355 memset(&p, 0, sizeof (p));
356 p.iotype = SERIAL_IO_MEM;
357 p.membase = (void *) binfo->bi_immr_base + MPC85xx_UART1_OFFSET;
358 p.uartclk = binfo->bi_busfreq;
359
360 gen550_init(1, &p);
361 }
362#endif
363
364#if defined(CONFIG_BLK_DEV_INITRD)
365 /*
366 * If the init RAM disk has been configured in, and there's a valid
367 * starting address for it, set it up.
368 */
369 if (r4) {
370 initrd_start = r4 + KERNELBASE;
371 initrd_end = r5 + KERNELBASE;
372 }
373#endif /* CONFIG_BLK_DEV_INITRD */
374
375 /* Copy the kernel command line arguments to a safe place. */
376
377 if (r6) {
378 *(char *) (r7 + KERNELBASE) = 0;
379 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
380 }
381
382 identify_ppc_sys_by_id(mfspr(SPRN_SVR));
383
384 /* setup the PowerPC module struct */
385 ppc_md.setup_arch = tqm85xx_setup_arch;
386 ppc_md.show_cpuinfo = tqm85xx_show_cpuinfo;
387
388 ppc_md.init_IRQ = tqm85xx_init_IRQ;
389 ppc_md.get_irq = openpic_get_irq;
390
391 ppc_md.restart = mpc85xx_restart;
392 ppc_md.power_off = mpc85xx_power_off;
393 ppc_md.halt = mpc85xx_halt;
394
395 ppc_md.find_end_of_memory = mpc85xx_find_end_of_memory;
396
397 ppc_md.time_init = NULL;
398 ppc_md.set_rtc_time = NULL;
399 ppc_md.get_rtc_time = NULL;
400 ppc_md.calibrate_decr = mpc85xx_calibrate_decr;
401
402#ifndef CONFIG_MPC8560
403#if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
404 ppc_md.progress = gen550_progress;
405#endif /* CONFIG_SERIAL_8250 && CONFIG_SERIAL_TEXT_DEBUG */
406#if defined(CONFIG_SERIAL_8250) && defined(CONFIG_KGDB)
407 ppc_md.early_serial_map = mpc85xx_early_serial_map;
408#endif /* CONFIG_SERIAL_8250 && CONFIG_KGDB */
409#endif /* CONFIG_MPC8560 */
410
411 if (ppc_md.progress)
412 ppc_md.progress("tqm85xx_init(): exit", 0);
413
414 return;
415}