2 * Freescale 83xx USB SOC setup code
4 * Copyright (C) 2007 Freescale Semiconductor, Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
20 #include <sysdev/fsl_soc.h>
25 #ifdef CONFIG_PPC_MPC834x
26 int mpc834x_usb_cfg(void)
28 unsigned long sccr
, sicrl
, sicrh
;
30 struct device_node
*np
= NULL
;
31 int port0_is_dr
= 0, port1_is_dr
= 0;
32 const void *prop
, *dr_mode
;
34 immap
= ioremap(get_immrbase(), 0x1000);
39 /* Note: DR and MPH must use the same clock setting in SCCR */
40 sccr
= in_be32(immap
+ MPC83XX_SCCR_OFFS
) & ~MPC83XX_SCCR_USB_MASK
;
41 sicrl
= in_be32(immap
+ MPC83XX_SICRL_OFFS
) & ~MPC834X_SICRL_USB_MASK
;
42 sicrh
= in_be32(immap
+ MPC83XX_SICRH_OFFS
) & ~MPC834X_SICRH_USB_UTMI
;
44 np
= of_find_compatible_node(NULL
, NULL
, "fsl-usb2-dr");
46 sccr
|= MPC83XX_SCCR_USB_DRCM_11
; /* 1:3 */
48 prop
= of_get_property(np
, "phy_type", NULL
);
49 if (prop
&& (!strcmp(prop
, "utmi") ||
50 !strcmp(prop
, "utmi_wide"))) {
51 sicrl
|= MPC834X_SICRL_USB0
| MPC834X_SICRL_USB1
;
52 sicrh
|= MPC834X_SICRH_USB_UTMI
;
54 } else if (prop
&& !strcmp(prop
, "serial")) {
55 dr_mode
= of_get_property(np
, "dr_mode", NULL
);
56 if (dr_mode
&& !strcmp(dr_mode
, "otg")) {
57 sicrl
|= MPC834X_SICRL_USB0
| MPC834X_SICRL_USB1
;
60 sicrl
|= MPC834X_SICRL_USB0
;
62 } else if (prop
&& !strcmp(prop
, "ulpi")) {
63 sicrl
|= MPC834X_SICRL_USB0
;
65 printk(KERN_WARNING
"834x USB PHY type not supported\n");
70 np
= of_find_compatible_node(NULL
, NULL
, "fsl-usb2-mph");
72 sccr
|= MPC83XX_SCCR_USB_MPHCM_11
; /* 1:3 */
74 prop
= of_get_property(np
, "port0", NULL
);
78 "834x USB port0 can't be used by both DR and MPH!\n");
79 sicrl
&= ~MPC834X_SICRL_USB0
;
81 prop
= of_get_property(np
, "port1", NULL
);
85 "834x USB port1 can't be used by both DR and MPH!\n");
86 sicrl
&= ~MPC834X_SICRL_USB1
;
92 out_be32(immap
+ MPC83XX_SCCR_OFFS
, sccr
);
93 out_be32(immap
+ MPC83XX_SICRL_OFFS
, sicrl
);
94 out_be32(immap
+ MPC83XX_SICRH_OFFS
, sicrh
);
99 #endif /* CONFIG_PPC_MPC834x */
101 #ifdef CONFIG_PPC_MPC831x
102 int mpc831x_usb_cfg(void)
105 void __iomem
*immap
, *usb_regs
;
106 struct device_node
*np
= NULL
;
107 struct device_node
*immr_node
= NULL
;
111 #ifdef CONFIG_USB_OTG
115 np
= of_find_compatible_node(NULL
, NULL
, "fsl-usb2-dr");
118 prop
= of_get_property(np
, "phy_type", NULL
);
120 /* Map IMMR space for pin and clock settings */
121 immap
= ioremap(get_immrbase(), 0x1000);
127 /* Configure clock */
128 immr_node
= of_get_parent(np
);
129 if (immr_node
&& of_device_is_compatible(immr_node
, "fsl,mpc8315-immr"))
130 clrsetbits_be32(immap
+ MPC83XX_SCCR_OFFS
,
131 MPC8315_SCCR_USB_MASK
,
132 MPC8315_SCCR_USB_DRCM_11
);
134 clrsetbits_be32(immap
+ MPC83XX_SCCR_OFFS
,
135 MPC83XX_SCCR_USB_MASK
,
136 MPC83XX_SCCR_USB_DRCM_11
);
138 /* Configure pin mux for ULPI. There is no pin mux for UTMI */
139 if (prop
&& !strcmp(prop
, "ulpi")) {
140 temp
= in_be32(immap
+ MPC83XX_SICRL_OFFS
);
141 temp
&= ~MPC831X_SICRL_USB_MASK
;
142 temp
|= MPC831X_SICRL_USB_ULPI
;
143 out_be32(immap
+ MPC83XX_SICRL_OFFS
, temp
);
145 temp
= in_be32(immap
+ MPC83XX_SICRH_OFFS
);
146 temp
&= ~MPC831X_SICRH_USB_MASK
;
147 temp
|= MPC831X_SICRH_USB_ULPI
;
148 out_be32(immap
+ MPC83XX_SICRH_OFFS
, temp
);
154 of_node_put(immr_node
);
156 /* Map USB SOC space */
157 ret
= of_address_to_resource(np
, 0, &res
);
162 usb_regs
= ioremap(res
.start
, res
.end
- res
.start
+ 1);
164 /* Using on-chip PHY */
165 if (prop
&& (!strcmp(prop
, "utmi_wide") ||
166 !strcmp(prop
, "utmi"))) {
167 /* Set UTMI_PHY_EN, REFSEL to 48MHZ */
168 out_be32(usb_regs
+ FSL_USB2_CONTROL_OFFS
,
169 CONTROL_UTMI_PHY_EN
| CONTROL_REFSEL_48MHZ
);
170 /* Using external UPLI PHY */
171 } else if (prop
&& !strcmp(prop
, "ulpi")) {
172 /* Set PHY_CLK_SEL to ULPI */
173 temp
= CONTROL_PHY_CLK_SEL_ULPI
;
174 #ifdef CONFIG_USB_OTG
176 dr_mode
= of_get_property(np
, "dr_mode", NULL
);
177 if (dr_mode
&& !strcmp(dr_mode
, "otg"))
178 temp
|= CONTROL_OTG_PORT
;
179 #endif /* CONFIG_USB_OTG */
180 out_be32(usb_regs
+ FSL_USB2_CONTROL_OFFS
, temp
);
182 printk(KERN_WARNING
"831x USB PHY type not supported\n");
190 #endif /* CONFIG_PPC_MPC831x */
192 #ifdef CONFIG_PPC_MPC837x
193 int mpc837x_usb_cfg(void)
196 struct device_node
*np
= NULL
;
200 np
= of_find_compatible_node(NULL
, NULL
, "fsl-usb2-dr");
203 prop
= of_get_property(np
, "phy_type", NULL
);
205 if (!prop
|| (strcmp(prop
, "ulpi") && strcmp(prop
, "serial"))) {
206 printk(KERN_WARNING
"837x USB PHY type not supported\n");
211 /* Map IMMR space for pin and clock settings */
212 immap
= ioremap(get_immrbase(), 0x1000);
218 /* Configure clock */
219 clrsetbits_be32(immap
+ MPC83XX_SCCR_OFFS
, MPC837X_SCCR_USB_DRCM_11
,
220 MPC837X_SCCR_USB_DRCM_11
);
222 /* Configure pin mux for ULPI/serial */
223 clrsetbits_be32(immap
+ MPC83XX_SICRL_OFFS
, MPC837X_SICRL_USB_MASK
,
224 MPC837X_SICRL_USB_ULPI
);
230 #endif /* CONFIG_PPC_MPC837x */