blob: 378a244b3bac867a23291b2428c18162a72687de [file] [log] [blame]
Becky Bruce63dafe52006-01-14 16:57:39 -06001/*
2 * MPC85xx setup and early boot code plus other random bits.
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
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
Becky Bruce63dafe52006-01-14 16:57:39 -060014#include <linux/stddef.h>
15#include <linux/kernel.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060016#include <linux/pci.h>
17#include <linux/kdev_t.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060018#include <linux/delay.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060019#include <linux/seq_file.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060020
21#include <asm/system.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060022#include <asm/time.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060023#include <asm/machdep.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060024#include <asm/pci-bridge.h>
25#include <asm/mpc85xx.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060026#include <asm/prom.h>
27#include <asm/mpic.h>
28#include <mm/mmu_decl.h>
29#include <asm/udbg.h>
30
31#include <sysdev/fsl_soc.h>
Roy Zang3f6c5da2007-07-10 18:47:06 +080032#include <sysdev/fsl_pci.h>
Becky Bruce63dafe52006-01-14 16:57:39 -060033
Vitaly Bordug902f3922006-09-21 22:31:26 +040034#ifdef CONFIG_CPM2
Vitaly Bordugd3465c92006-09-21 22:38:05 +040035#include <linux/fs_enet_pd.h>
Vitaly Bordug902f3922006-09-21 22:31:26 +040036#include <asm/cpm2.h>
37#include <sysdev/cpm2_pic.h>
38#include <asm/fs_pd.h>
39#endif
40
Andy Fleming8080d542006-02-10 17:01:06 -060041#ifdef CONFIG_PCI
Kumar Gala7d52c7b2007-06-22 00:23:57 -050042static int mpc85xx_exclude_device(struct pci_controller *hose,
43 u_char bus, u_char devfn)
Andy Fleming8080d542006-02-10 17:01:06 -060044{
45 if (bus == 0 && PCI_SLOT(devfn) == 0)
46 return PCIBIOS_DEVICE_NOT_FOUND;
47 else
48 return PCIBIOS_SUCCESSFUL;
49}
Andy Fleming8080d542006-02-10 17:01:06 -060050#endif /* CONFIG_PCI */
51
Vitaly Bordug902f3922006-09-21 22:31:26 +040052#ifdef CONFIG_CPM2
53
Olaf Hering35a84c22006-10-07 22:08:26 +100054static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
Vitaly Bordug902f3922006-09-21 22:31:26 +040055{
56 int cascade_irq;
57
Olaf Hering35a84c22006-10-07 22:08:26 +100058 while ((cascade_irq = cpm2_get_irq()) >= 0) {
Olof Johansson49f19ce2006-10-05 20:31:10 -050059 generic_handle_irq(cascade_irq);
Vitaly Bordug902f3922006-09-21 22:31:26 +040060 }
61 desc->chip->eoi(irq);
62}
63
64#endif /* CONFIG_CPM2 */
Andy Fleming8080d542006-02-10 17:01:06 -060065
Kumar Gala27630be2007-02-09 09:30:45 -060066static void __init mpc85xx_ads_pic_init(void)
Becky Bruce63dafe52006-01-14 16:57:39 -060067{
Andy Fleming4c86cd92006-08-18 18:03:08 -050068 struct mpic *mpic;
69 struct resource r;
70 struct device_node *np = NULL;
Vitaly Bordug902f3922006-09-21 22:31:26 +040071#ifdef CONFIG_CPM2
72 int irq;
73#endif
Becky Bruce63dafe52006-01-14 16:57:39 -060074
Andy Fleming4c86cd92006-08-18 18:03:08 -050075 np = of_find_node_by_type(np, "open-pic");
Becky Bruce63dafe52006-01-14 16:57:39 -060076
Andy Fleming4c86cd92006-08-18 18:03:08 -050077 if (np == NULL) {
78 printk(KERN_ERR "Could not find open-pic node\n");
79 return;
80 }
Becky Bruce63dafe52006-01-14 16:57:39 -060081
Andy Fleming4c86cd92006-08-18 18:03:08 -050082 if(of_address_to_resource(np, 0, &r)) {
83 printk(KERN_ERR "Could not map mpic register space\n");
84 of_node_put(np);
85 return;
86 }
Becky Bruce63dafe52006-01-14 16:57:39 -060087
Andy Fleming4c86cd92006-08-18 18:03:08 -050088 mpic = mpic_alloc(np, r.start,
89 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
Kumar Galab533f8a2007-07-03 02:35:35 -050090 0, 256, " OpenPIC ");
Andy Fleming4c86cd92006-08-18 18:03:08 -050091 BUG_ON(mpic == NULL);
92 of_node_put(np);
93
Andy Fleming4c86cd92006-08-18 18:03:08 -050094 mpic_init(mpic);
Vitaly Bordug902f3922006-09-21 22:31:26 +040095
96#ifdef CONFIG_CPM2
97 /* Setup CPM2 PIC */
98 np = of_find_node_by_type(NULL, "cpm-pic");
99 if (np == NULL) {
100 printk(KERN_ERR "PIC init: can not find cpm-pic node\n");
101 return;
102 }
103 irq = irq_of_parse_and_map(np, 0);
104
105 cpm2_pic_init(np);
106 set_irq_chained_handler(irq, cpm2_cascade);
107#endif
Becky Bruce63dafe52006-01-14 16:57:39 -0600108}
109
Becky Bruce63dafe52006-01-14 16:57:39 -0600110/*
111 * Setup the architecture
112 */
Vitaly Bordug902f3922006-09-21 22:31:26 +0400113#ifdef CONFIG_CPM2
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400114void init_fcc_ioports(struct fs_platform_info *fpi)
Vitaly Bordug902f3922006-09-21 22:31:26 +0400115{
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400116 struct io_port *io = cpm2_map(im_ioport);
117 int fcc_no = fs_get_fcc_index(fpi->fs_no);
118 int target;
Vitaly Bordug902f3922006-09-21 22:31:26 +0400119 u32 tempval;
120
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400121 switch(fcc_no) {
122 case 1:
123 tempval = in_be32(&io->iop_pdirb);
124 tempval &= ~PB2_DIRB0;
125 tempval |= PB2_DIRB1;
126 out_be32(&io->iop_pdirb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400127
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400128 tempval = in_be32(&io->iop_psorb);
129 tempval &= ~PB2_PSORB0;
130 tempval |= PB2_PSORB1;
131 out_be32(&io->iop_psorb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400132
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400133 tempval = in_be32(&io->iop_pparb);
134 tempval |= (PB2_DIRB0 | PB2_DIRB1);
135 out_be32(&io->iop_pparb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400136
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400137 target = CPM_CLK_FCC2;
138 break;
139 case 2:
140 tempval = in_be32(&io->iop_pdirb);
141 tempval &= ~PB3_DIRB0;
142 tempval |= PB3_DIRB1;
143 out_be32(&io->iop_pdirb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400144
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400145 tempval = in_be32(&io->iop_psorb);
146 tempval &= ~PB3_PSORB0;
147 tempval |= PB3_PSORB1;
148 out_be32(&io->iop_psorb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400149
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400150 tempval = in_be32(&io->iop_pparb);
151 tempval |= (PB3_DIRB0 | PB3_DIRB1);
152 out_be32(&io->iop_pparb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400153
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400154 tempval = in_be32(&io->iop_pdirc);
155 tempval |= PC3_DIRC1;
156 out_be32(&io->iop_pdirc, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400157
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400158 tempval = in_be32(&io->iop_pparc);
159 tempval |= PC3_DIRC1;
160 out_be32(&io->iop_pparc, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400161
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400162 target = CPM_CLK_FCC3;
163 break;
164 default:
165 printk(KERN_ERR "init_fcc_ioports: invalid FCC number\n");
166 return;
167 }
Vitaly Bordug902f3922006-09-21 22:31:26 +0400168
169 /* Port C has clocks...... */
170 tempval = in_be32(&io->iop_psorc);
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400171 tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
Vitaly Bordug902f3922006-09-21 22:31:26 +0400172 out_be32(&io->iop_psorc, tempval);
173
174 tempval = in_be32(&io->iop_pdirc);
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400175 tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
Vitaly Bordug902f3922006-09-21 22:31:26 +0400176 out_be32(&io->iop_pdirc, tempval);
177 tempval = in_be32(&io->iop_pparc);
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400178 tempval |= (PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
Vitaly Bordug902f3922006-09-21 22:31:26 +0400179 out_be32(&io->iop_pparc, tempval);
180
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400181 cpm2_unmap(io);
182
Vitaly Bordug902f3922006-09-21 22:31:26 +0400183 /* Configure Serial Interface clock routing.
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400184 * First, clear FCC bits to zero,
Vitaly Bordug902f3922006-09-21 22:31:26 +0400185 * then set the ones we want.
186 */
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400187 cpm2_clk_setup(target, fpi->clk_rx, CPM_CLK_RX);
188 cpm2_clk_setup(target, fpi->clk_tx, CPM_CLK_TX);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400189}
190#endif
191
Becky Brucefbc94e72006-02-07 21:29:42 -0600192static void __init mpc85xx_ads_setup_arch(void)
Becky Bruce63dafe52006-01-14 16:57:39 -0600193{
Andy Fleming4c86cd92006-08-18 18:03:08 -0500194#ifdef CONFIG_PCI
Andy Fleming8080d542006-02-10 17:01:06 -0600195 struct device_node *np;
Andy Fleming4c86cd92006-08-18 18:03:08 -0500196#endif
Becky Bruce63dafe52006-01-14 16:57:39 -0600197
198 if (ppc_md.progress)
199 ppc_md.progress("mpc85xx_ads_setup_arch()", 0);
200
Vitaly Bordug902f3922006-09-21 22:31:26 +0400201#ifdef CONFIG_CPM2
202 cpm2_reset();
Vitaly Bordug902f3922006-09-21 22:31:26 +0400203#endif
204
Andy Fleming8080d542006-02-10 17:01:06 -0600205#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500206 for_each_compatible_node(np, "pci", "fsl,mpc8540-pci")
Roy Zang3f6c5da2007-07-10 18:47:06 +0800207 fsl_add_bridge(np, 1);
Kumar Galac9438af2007-10-04 00:28:43 -0500208
Andy Fleming8080d542006-02-10 17:01:06 -0600209 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
210#endif
Becky Bruce63dafe52006-01-14 16:57:39 -0600211}
212
Kumar Gala27630be2007-02-09 09:30:45 -0600213static void mpc85xx_ads_show_cpuinfo(struct seq_file *m)
Becky Bruce63dafe52006-01-14 16:57:39 -0600214{
215 uint pvid, svid, phid1;
216 uint memsize = total_memory;
217
218 pvid = mfspr(SPRN_PVR);
219 svid = mfspr(SPRN_SVR);
220
221 seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
222 seq_printf(m, "Machine\t\t: mpc85xx\n");
223 seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
224 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
225
226 /* Display cpu Pll setting */
227 phid1 = mfspr(SPRN_HID1);
228 seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
229
230 /* Display the amount of memory */
231 seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
232}
233
Kumar Gala72d2c3e2006-03-30 23:39:57 -0600234/*
235 * Called very early, device-tree isn't unflattened
236 */
237static int __init mpc85xx_ads_probe(void)
Becky Bruce63dafe52006-01-14 16:57:39 -0600238{
Kumar Gala6936c622007-02-17 16:19:34 -0600239 unsigned long root = of_get_flat_dt_root();
240
241 return of_flat_dt_is_compatible(root, "MPC85xxADS");
Becky Bruce63dafe52006-01-14 16:57:39 -0600242}
Kumar Gala72d2c3e2006-03-30 23:39:57 -0600243
244define_machine(mpc85xx_ads) {
245 .name = "MPC85xx ADS",
246 .probe = mpc85xx_ads_probe,
247 .setup_arch = mpc85xx_ads_setup_arch,
248 .init_IRQ = mpc85xx_ads_pic_init,
249 .show_cpuinfo = mpc85xx_ads_show_cpuinfo,
250 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500251 .restart = fsl_rstcr_restart,
Kumar Gala72d2c3e2006-03-30 23:39:57 -0600252 .calibrate_decr = generic_calibrate_decr,
253 .progress = udbg_progress,
254};