blob: acb1ef93224065a39e7058e29329d5010e421fae [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#include "mpc85xx.h"
34
Vitaly Bordug902f3922006-09-21 22:31:26 +040035#ifdef CONFIG_CPM2
Vitaly Bordugd3465c92006-09-21 22:38:05 +040036#include <linux/fs_enet_pd.h>
Vitaly Bordug902f3922006-09-21 22:31:26 +040037#include <asm/cpm2.h>
38#include <sysdev/cpm2_pic.h>
39#include <asm/fs_pd.h>
40#endif
41
Andy Fleming8080d542006-02-10 17:01:06 -060042#ifdef CONFIG_PCI
Kumar Gala7d52c7b2007-06-22 00:23:57 -050043static int mpc85xx_exclude_device(struct pci_controller *hose,
44 u_char bus, u_char devfn)
Andy Fleming8080d542006-02-10 17:01:06 -060045{
46 if (bus == 0 && PCI_SLOT(devfn) == 0)
47 return PCIBIOS_DEVICE_NOT_FOUND;
48 else
49 return PCIBIOS_SUCCESSFUL;
50}
Andy Fleming8080d542006-02-10 17:01:06 -060051#endif /* CONFIG_PCI */
52
Vitaly Bordug902f3922006-09-21 22:31:26 +040053#ifdef CONFIG_CPM2
54
Olaf Hering35a84c22006-10-07 22:08:26 +100055static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
Vitaly Bordug902f3922006-09-21 22:31:26 +040056{
57 int cascade_irq;
58
Olaf Hering35a84c22006-10-07 22:08:26 +100059 while ((cascade_irq = cpm2_get_irq()) >= 0) {
Olof Johansson49f19ce2006-10-05 20:31:10 -050060 generic_handle_irq(cascade_irq);
Vitaly Bordug902f3922006-09-21 22:31:26 +040061 }
62 desc->chip->eoi(irq);
63}
64
65#endif /* CONFIG_CPM2 */
Andy Fleming8080d542006-02-10 17:01:06 -060066
Kumar Gala27630be2007-02-09 09:30:45 -060067static void __init mpc85xx_ads_pic_init(void)
Becky Bruce63dafe52006-01-14 16:57:39 -060068{
Andy Fleming4c86cd92006-08-18 18:03:08 -050069 struct mpic *mpic;
70 struct resource r;
71 struct device_node *np = NULL;
Vitaly Bordug902f3922006-09-21 22:31:26 +040072#ifdef CONFIG_CPM2
73 int irq;
74#endif
Becky Bruce63dafe52006-01-14 16:57:39 -060075
Andy Fleming4c86cd92006-08-18 18:03:08 -050076 np = of_find_node_by_type(np, "open-pic");
Becky Bruce63dafe52006-01-14 16:57:39 -060077
Andy Fleming4c86cd92006-08-18 18:03:08 -050078 if (np == NULL) {
79 printk(KERN_ERR "Could not find open-pic node\n");
80 return;
81 }
Becky Bruce63dafe52006-01-14 16:57:39 -060082
Andy Fleming4c86cd92006-08-18 18:03:08 -050083 if(of_address_to_resource(np, 0, &r)) {
84 printk(KERN_ERR "Could not map mpic register space\n");
85 of_node_put(np);
86 return;
87 }
Becky Bruce63dafe52006-01-14 16:57:39 -060088
Andy Fleming4c86cd92006-08-18 18:03:08 -050089 mpic = mpic_alloc(np, r.start,
90 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
Kumar Galab533f8a2007-07-03 02:35:35 -050091 0, 256, " OpenPIC ");
Andy Fleming4c86cd92006-08-18 18:03:08 -050092 BUG_ON(mpic == NULL);
93 of_node_put(np);
94
Andy Fleming4c86cd92006-08-18 18:03:08 -050095 mpic_init(mpic);
Vitaly Bordug902f3922006-09-21 22:31:26 +040096
97#ifdef CONFIG_CPM2
98 /* Setup CPM2 PIC */
99 np = of_find_node_by_type(NULL, "cpm-pic");
100 if (np == NULL) {
101 printk(KERN_ERR "PIC init: can not find cpm-pic node\n");
102 return;
103 }
104 irq = irq_of_parse_and_map(np, 0);
105
106 cpm2_pic_init(np);
107 set_irq_chained_handler(irq, cpm2_cascade);
108#endif
Becky Bruce63dafe52006-01-14 16:57:39 -0600109}
110
Becky Bruce63dafe52006-01-14 16:57:39 -0600111/*
112 * Setup the architecture
113 */
Vitaly Bordug902f3922006-09-21 22:31:26 +0400114#ifdef CONFIG_CPM2
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400115void init_fcc_ioports(struct fs_platform_info *fpi)
Vitaly Bordug902f3922006-09-21 22:31:26 +0400116{
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400117 struct io_port *io = cpm2_map(im_ioport);
118 int fcc_no = fs_get_fcc_index(fpi->fs_no);
119 int target;
Vitaly Bordug902f3922006-09-21 22:31:26 +0400120 u32 tempval;
121
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400122 switch(fcc_no) {
123 case 1:
124 tempval = in_be32(&io->iop_pdirb);
125 tempval &= ~PB2_DIRB0;
126 tempval |= PB2_DIRB1;
127 out_be32(&io->iop_pdirb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400128
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400129 tempval = in_be32(&io->iop_psorb);
130 tempval &= ~PB2_PSORB0;
131 tempval |= PB2_PSORB1;
132 out_be32(&io->iop_psorb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400133
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400134 tempval = in_be32(&io->iop_pparb);
135 tempval |= (PB2_DIRB0 | PB2_DIRB1);
136 out_be32(&io->iop_pparb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400137
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400138 target = CPM_CLK_FCC2;
139 break;
140 case 2:
141 tempval = in_be32(&io->iop_pdirb);
142 tempval &= ~PB3_DIRB0;
143 tempval |= PB3_DIRB1;
144 out_be32(&io->iop_pdirb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400145
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400146 tempval = in_be32(&io->iop_psorb);
147 tempval &= ~PB3_PSORB0;
148 tempval |= PB3_PSORB1;
149 out_be32(&io->iop_psorb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400150
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400151 tempval = in_be32(&io->iop_pparb);
152 tempval |= (PB3_DIRB0 | PB3_DIRB1);
153 out_be32(&io->iop_pparb, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400154
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400155 tempval = in_be32(&io->iop_pdirc);
156 tempval |= PC3_DIRC1;
157 out_be32(&io->iop_pdirc, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400158
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400159 tempval = in_be32(&io->iop_pparc);
160 tempval |= PC3_DIRC1;
161 out_be32(&io->iop_pparc, tempval);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400162
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400163 target = CPM_CLK_FCC3;
164 break;
165 default:
166 printk(KERN_ERR "init_fcc_ioports: invalid FCC number\n");
167 return;
168 }
Vitaly Bordug902f3922006-09-21 22:31:26 +0400169
170 /* Port C has clocks...... */
171 tempval = in_be32(&io->iop_psorc);
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400172 tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
Vitaly Bordug902f3922006-09-21 22:31:26 +0400173 out_be32(&io->iop_psorc, tempval);
174
175 tempval = in_be32(&io->iop_pdirc);
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400176 tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
Vitaly Bordug902f3922006-09-21 22:31:26 +0400177 out_be32(&io->iop_pdirc, tempval);
178 tempval = in_be32(&io->iop_pparc);
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400179 tempval |= (PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
Vitaly Bordug902f3922006-09-21 22:31:26 +0400180 out_be32(&io->iop_pparc, tempval);
181
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400182 cpm2_unmap(io);
183
Vitaly Bordug902f3922006-09-21 22:31:26 +0400184 /* Configure Serial Interface clock routing.
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400185 * First, clear FCC bits to zero,
Vitaly Bordug902f3922006-09-21 22:31:26 +0400186 * then set the ones we want.
187 */
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400188 cpm2_clk_setup(target, fpi->clk_rx, CPM_CLK_RX);
189 cpm2_clk_setup(target, fpi->clk_tx, CPM_CLK_TX);
Vitaly Bordug902f3922006-09-21 22:31:26 +0400190}
191#endif
192
Becky Brucefbc94e72006-02-07 21:29:42 -0600193static void __init mpc85xx_ads_setup_arch(void)
Becky Bruce63dafe52006-01-14 16:57:39 -0600194{
Andy Fleming4c86cd92006-08-18 18:03:08 -0500195#ifdef CONFIG_PCI
Andy Fleming8080d542006-02-10 17:01:06 -0600196 struct device_node *np;
Andy Fleming4c86cd92006-08-18 18:03:08 -0500197#endif
Becky Bruce63dafe52006-01-14 16:57:39 -0600198
199 if (ppc_md.progress)
200 ppc_md.progress("mpc85xx_ads_setup_arch()", 0);
201
Vitaly Bordug902f3922006-09-21 22:31:26 +0400202#ifdef CONFIG_CPM2
203 cpm2_reset();
Vitaly Bordug902f3922006-09-21 22:31:26 +0400204#endif
205
Andy Fleming8080d542006-02-10 17:01:06 -0600206#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500207 for_each_compatible_node(np, "pci", "fsl,mpc8540-pci")
Roy Zang3f6c5da2007-07-10 18:47:06 +0800208 fsl_add_bridge(np, 1);
Kumar Galac9438af2007-10-04 00:28:43 -0500209
Andy Fleming8080d542006-02-10 17:01:06 -0600210 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
211#endif
Becky Bruce63dafe52006-01-14 16:57:39 -0600212}
213
Kumar Gala27630be2007-02-09 09:30:45 -0600214static void mpc85xx_ads_show_cpuinfo(struct seq_file *m)
Becky Bruce63dafe52006-01-14 16:57:39 -0600215{
216 uint pvid, svid, phid1;
217 uint memsize = total_memory;
218
219 pvid = mfspr(SPRN_PVR);
220 svid = mfspr(SPRN_SVR);
221
222 seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
223 seq_printf(m, "Machine\t\t: mpc85xx\n");
224 seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
225 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
226
227 /* Display cpu Pll setting */
228 phid1 = mfspr(SPRN_HID1);
229 seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
230
231 /* Display the amount of memory */
232 seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
233}
234
Kumar Gala72d2c3e2006-03-30 23:39:57 -0600235/*
236 * Called very early, device-tree isn't unflattened
237 */
238static int __init mpc85xx_ads_probe(void)
Becky Bruce63dafe52006-01-14 16:57:39 -0600239{
Kumar Gala6936c622007-02-17 16:19:34 -0600240 unsigned long root = of_get_flat_dt_root();
241
242 return of_flat_dt_is_compatible(root, "MPC85xxADS");
Becky Bruce63dafe52006-01-14 16:57:39 -0600243}
Kumar Gala72d2c3e2006-03-30 23:39:57 -0600244
245define_machine(mpc85xx_ads) {
246 .name = "MPC85xx ADS",
247 .probe = mpc85xx_ads_probe,
248 .setup_arch = mpc85xx_ads_setup_arch,
249 .init_IRQ = mpc85xx_ads_pic_init,
250 .show_cpuinfo = mpc85xx_ads_show_cpuinfo,
251 .get_irq = mpic_get_irq,
252 .restart = mpc85xx_restart,
253 .calibrate_decr = generic_calibrate_decr,
254 .progress = udbg_progress,
255};