QE: Move QE from arch/powerpc to drivers/soc
[linux-2.6-block.git] / arch / powerpc / platforms / 83xx / mpc836x_mds.c
CommitLineData
bc141dea 1/*
8a56e1ee 2 * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
bc141dea
LY
3 *
4 * Author: Li Yang <LeoLi@freescale.com>
5 * Yin Olivia <Hong-hua.Yin@freescale.com>
6 *
7 * Description:
322d05a1 8 * MPC8360E MDS board specific routines.
bc141dea
LY
9 *
10 * Changelog:
11 * Jun 21, 2006 Initial version
12 *
322d05a1 13 * This program is free software; you can redistribute it and/or modify it
bc141dea
LY
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/stddef.h>
20#include <linux/kernel.h>
78c77050 21#include <linux/compiler.h>
bc141dea
LY
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/initrd.h>
882407b9
JL
33#include <linux/of_platform.h>
34#include <linux/of_device.h>
bc141dea 35
60063497 36#include <linux/atomic.h>
bc141dea
LY
37#include <asm/time.h>
38#include <asm/io.h>
39#include <asm/machdep.h>
40#include <asm/ipic.h>
bc141dea
LY
41#include <asm/irq.h>
42#include <asm/prom.h>
43#include <asm/udbg.h>
44#include <sysdev/fsl_soc.h>
76fe1ffc 45#include <sysdev/fsl_pci.h>
c9c5e52d 46#include <sysdev/simple_gpio.h>
7aa1aa6e
ZQ
47#include <soc/fsl/qe/qe.h>
48#include <soc/fsl/qe/qe_ic.h>
bc141dea
LY
49
50#include "mpc83xx.h"
51
52#undef DEBUG
53#ifdef DEBUG
54#define DBG(fmt...) udbg_printf(fmt)
55#else
56#define DBG(fmt...)
57#endif
58
bc141dea
LY
59/* ************************************************************************
60 *
61 * Setup the architecture
62 *
63 */
322d05a1 64static void __init mpc836x_mds_setup_arch(void)
bc141dea
LY
65{
66 struct device_node *np;
78c77050 67 u8 __iomem *bcsr_regs = NULL;
bc141dea
LY
68
69 if (ppc_md.progress)
322d05a1 70 ppc_md.progress("mpc836x_mds_setup_arch()", 0);
bc141dea 71
bc141dea
LY
72 /* Map BCSR area */
73 np = of_find_node_by_name(NULL, "bcsr");
78c77050 74 if (np) {
bc141dea
LY
75 struct resource res;
76
77 of_address_to_resource(np, 0, &res);
28f65c11 78 bcsr_regs = ioremap(res.start, resource_size(&res));
bc141dea
LY
79 of_node_put(np);
80 }
81
bede480d 82 mpc83xx_setup_pci();
bc141dea
LY
83
84#ifdef CONFIG_QUICC_ENGINE
06cd9396 85 if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {
bc141dea
LY
86 par_io_init(np);
87 of_node_put(np);
88
89 for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
90 par_io_of_config(np);
c9c5e52d
AV
91#ifdef CONFIG_QE_USB
92 /* Must fixup Par IO before QE GPIO chips are registered. */
93 par_io_config_pin(1, 2, 1, 0, 3, 0); /* USBOE */
94 par_io_config_pin(1, 3, 1, 0, 3, 0); /* USBTP */
95 par_io_config_pin(1, 8, 1, 0, 1, 0); /* USBTN */
96 par_io_config_pin(1, 10, 2, 0, 3, 0); /* USBRXD */
97 par_io_config_pin(1, 9, 2, 1, 3, 0); /* USBRP */
98 par_io_config_pin(1, 11, 2, 1, 3, 0); /* USBRN */
99 par_io_config_pin(2, 20, 2, 0, 1, 0); /* CLK21 */
100#endif /* CONFIG_QE_USB */
bc141dea
LY
101 }
102
103 if ((np = of_find_compatible_node(NULL, "network", "ucc_geth"))
104 != NULL){
29a50a8b
KP
105 uint svid;
106
bc141dea 107 /* Reset the Ethernet PHY */
29a50a8b
KP
108#define BCSR9_GETHRST 0x20
109 clrbits8(&bcsr_regs[9], BCSR9_GETHRST);
bc141dea 110 udelay(1000);
29a50a8b
KP
111 setbits8(&bcsr_regs[9], BCSR9_GETHRST);
112
113 /* handle mpc8360ea rev.2.1 erratum 2: RGMII Timing */
114 svid = mfspr(SPRN_SVR);
115 if (svid == 0x80480021) {
116 void __iomem *immap;
117
118 immap = ioremap(get_immrbase() + 0x14a8, 8);
119
120 /*
121 * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
122 * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
123 */
124 setbits32(immap, 0x0c003000);
125
126 /*
127 * IMMR + 0x14AC[20:27] = 10101010
128 * (data delay for both UCC's)
129 */
130 clrsetbits_be32(immap + 4, 0xff0, 0xaa0);
131
132 iounmap(immap);
133 }
134
bc141dea
LY
135 iounmap(bcsr_regs);
136 of_node_put(np);
137 }
bc141dea 138#endif /* CONFIG_QUICC_ENGINE */
bc141dea
LY
139}
140
7669d58c 141machine_device_initcall(mpc836x_mds, mpc83xx_declare_of_platform_devices);
f5a37b06 142
c9c5e52d
AV
143#ifdef CONFIG_QE_USB
144static int __init mpc836x_usb_cfg(void)
145{
146 u8 __iomem *bcsr;
147 struct device_node *np;
148 const char *mode;
149 int ret = 0;
150
151 np = of_find_compatible_node(NULL, NULL, "fsl,mpc8360mds-bcsr");
152 if (!np)
153 return -ENODEV;
154
155 bcsr = of_iomap(np, 0);
156 of_node_put(np);
157 if (!bcsr)
158 return -ENOMEM;
159
160 np = of_find_compatible_node(NULL, NULL, "fsl,mpc8323-qe-usb");
161 if (!np) {
162 ret = -ENODEV;
163 goto err;
164 }
165
166#define BCSR8_TSEC1M_MASK (0x3 << 6)
167#define BCSR8_TSEC1M_RGMII (0x0 << 6)
168#define BCSR8_TSEC2M_MASK (0x3 << 4)
169#define BCSR8_TSEC2M_RGMII (0x0 << 4)
170 /*
171 * Default is GMII (2), but we should set it to RGMII (0) if we use
172 * USB (Eth PHY is in RGMII mode anyway).
173 */
174 clrsetbits_8(&bcsr[8], BCSR8_TSEC1M_MASK | BCSR8_TSEC2M_MASK,
175 BCSR8_TSEC1M_RGMII | BCSR8_TSEC2M_RGMII);
176
177#define BCSR13_USBMASK 0x0f
178#define BCSR13_nUSBEN 0x08 /* 1 - Disable, 0 - Enable */
179#define BCSR13_USBSPEED 0x04 /* 1 - Full, 0 - Low */
180#define BCSR13_USBMODE 0x02 /* 1 - Host, 0 - Function */
181#define BCSR13_nUSBVCC 0x01 /* 1 - gets VBUS, 0 - supplies VBUS */
182
183 clrsetbits_8(&bcsr[13], BCSR13_USBMASK, BCSR13_USBSPEED);
184
185 mode = of_get_property(np, "mode", NULL);
186 if (mode && !strcmp(mode, "peripheral")) {
187 setbits8(&bcsr[13], BCSR13_nUSBVCC);
188 qe_usb_clock_set(QE_CLK21, 48000000);
189 } else {
190 setbits8(&bcsr[13], BCSR13_USBMODE);
191 /*
192 * The BCSR GPIOs are used to control power and
193 * speed of the USB transceiver. This is needed for
194 * the USB Host only.
195 */
196 simple_gpiochip_init("fsl,mpc8360mds-bcsr-gpio");
197 }
198
199 of_node_put(np);
200err:
201 iounmap(bcsr);
202 return ret;
203}
204machine_arch_initcall(mpc836x_mds, mpc836x_usb_cfg);
205#endif /* CONFIG_QE_USB */
206
bc141dea
LY
207/*
208 * Called very early, MMU is off, device-tree isn't unflattened
209 */
322d05a1 210static int __init mpc836x_mds_probe(void)
bc141dea 211{
336c3c2e 212 unsigned long root = of_get_flat_dt_root();
bc141dea 213
336c3c2e 214 return of_flat_dt_is_compatible(root, "MPC836xMDS");
bc141dea
LY
215}
216
322d05a1
KG
217define_machine(mpc836x_mds) {
218 .name = "MPC836x MDS",
219 .probe = mpc836x_mds_probe,
220 .setup_arch = mpc836x_mds_setup_arch,
d4fb5ebd 221 .init_IRQ = mpc83xx_ipic_and_qe_init_IRQ,
322d05a1
KG
222 .get_irq = ipic_get_irq,
223 .restart = mpc83xx_restart,
224 .time_init = mpc83xx_time_init,
bc141dea 225 .calibrate_decr = generic_calibrate_decr,
322d05a1 226 .progress = udbg_progress,
bc141dea 227};