2 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
3 * Copyright (C) 2010 Freescale Semiconductor, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/platform_device.h>
23 #include <mach/hardware.h>
24 #include <mach/mxc_ehci.h>
26 #define USBCTRL_OTGBASE_OFFSET 0x600
28 #define MX31_OTG_SIC_SHIFT 29
29 #define MX31_OTG_SIC_MASK (0x3 << MX31_OTG_SIC_SHIFT)
30 #define MX31_OTG_PM_BIT (1 << 24)
32 #define MX31_H2_SIC_SHIFT 21
33 #define MX31_H2_SIC_MASK (0x3 << MX31_H2_SIC_SHIFT)
34 #define MX31_H2_PM_BIT (1 << 16)
35 #define MX31_H2_DT_BIT (1 << 5)
37 #define MX31_H1_SIC_SHIFT 13
38 #define MX31_H1_SIC_MASK (0x3 << MX31_H1_SIC_SHIFT)
39 #define MX31_H1_PM_BIT (1 << 8)
40 #define MX31_H1_DT_BIT (1 << 4)
42 #define MX35_OTG_SIC_SHIFT 29
43 #define MX35_OTG_SIC_MASK (0x3 << MX35_OTG_SIC_SHIFT)
44 #define MX35_OTG_PM_BIT (1 << 24)
46 #define MX35_H1_SIC_SHIFT 21
47 #define MX35_H1_SIC_MASK (0x3 << MX35_H1_SIC_SHIFT)
48 #define MX35_H1_PM_BIT (1 << 8)
49 #define MX35_H1_IPPUE_UP_BIT (1 << 7)
50 #define MX35_H1_IPPUE_DOWN_BIT (1 << 6)
51 #define MX35_H1_TLL_BIT (1 << 5)
52 #define MX35_H1_USBTE_BIT (1 << 4)
54 #define MXC_OTG_OFFSET 0
55 #define MXC_H1_OFFSET 0x200
58 #define MXC_OTG_UCTRL_OWIE_BIT (1 << 27) /* OTG wakeup intr enable */
59 #define MXC_OTG_UCTRL_OPM_BIT (1 << 24) /* OTG power mask */
60 #define MXC_H1_UCTRL_H1UIE_BIT (1 << 12) /* Host1 ULPI interrupt enable */
61 #define MXC_H1_UCTRL_H1WIE_BIT (1 << 11) /* HOST1 wakeup intr enable */
62 #define MXC_H1_UCTRL_H1PM_BIT (1 << 8) /* HOST1 power mask */
64 /* USB_PHY_CTRL_FUNC */
65 #define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8) /* OTG Disable Overcurrent Event */
66 #define MXC_H1_OC_DIS_BIT (1 << 5) /* UH1 Disable Overcurrent Event */
68 #define MXC_USBCMD_OFFSET 0x140
71 #define MXC_UCMD_ITC_NO_THRESHOLD_MASK (~(0xff << 16)) /* Interrupt Threshold Control */
73 int mxc_initialize_usb_hw(int port
, unsigned int flags
)
76 #ifdef CONFIG_ARCH_MX3
78 v
= readl(MX31_IO_ADDRESS(MX31_OTG_BASE_ADDR
+
79 USBCTRL_OTGBASE_OFFSET
));
82 case 0: /* OTG port */
83 v
&= ~(MX31_OTG_SIC_MASK
| MX31_OTG_PM_BIT
);
84 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
85 << MX31_OTG_SIC_SHIFT
;
86 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
91 v
&= ~(MX31_H1_SIC_MASK
| MX31_H1_PM_BIT
| MX31_H1_DT_BIT
);
92 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
94 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
97 if (!(flags
& MXC_EHCI_TTL_ENABLED
))
101 case 2: /* H2 port */
102 v
&= ~(MX31_H2_SIC_MASK
| MX31_H2_PM_BIT
| MX31_H2_DT_BIT
);
103 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
104 << MX31_H2_SIC_SHIFT
;
105 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
108 if (!(flags
& MXC_EHCI_TTL_ENABLED
))
116 writel(v
, MX31_IO_ADDRESS(MX31_OTG_BASE_ADDR
+
117 USBCTRL_OTGBASE_OFFSET
));
122 v
= readl(MX35_IO_ADDRESS(MX35_OTG_BASE_ADDR
+
123 USBCTRL_OTGBASE_OFFSET
));
126 case 0: /* OTG port */
127 v
&= ~(MX35_OTG_SIC_MASK
| MX35_OTG_PM_BIT
);
128 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
129 << MX35_OTG_SIC_SHIFT
;
130 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
131 v
|= MX35_OTG_PM_BIT
;
134 case 1: /* H1 port */
135 v
&= ~(MX35_H1_SIC_MASK
| MX35_H1_PM_BIT
| MX35_H1_TLL_BIT
|
136 MX35_H1_USBTE_BIT
| MX35_H1_IPPUE_DOWN_BIT
| MX35_H1_IPPUE_UP_BIT
);
137 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
138 << MX35_H1_SIC_SHIFT
;
139 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
142 if (!(flags
& MXC_EHCI_TTL_ENABLED
))
143 v
|= MX35_H1_TLL_BIT
;
145 if (flags
& MXC_EHCI_INTERNAL_PHY
)
146 v
|= MX35_H1_USBTE_BIT
;
148 if (flags
& MXC_EHCI_IPPUE_DOWN
)
149 v
|= MX35_H1_IPPUE_DOWN_BIT
;
151 if (flags
& MXC_EHCI_IPPUE_UP
)
152 v
|= MX35_H1_IPPUE_UP_BIT
;
159 writel(v
, MX35_IO_ADDRESS(MX35_OTG_BASE_ADDR
+
160 USBCTRL_OTGBASE_OFFSET
));
163 #endif /* CONFIG_ARCH_MX3 */
164 #ifdef CONFIG_MACH_MX27
166 /* On i.MX27 we can use the i.MX31 USBCTRL bits, they
169 v
= readl(MX27_IO_ADDRESS(MX27_OTG_BASE_ADDR
+
170 USBCTRL_OTGBASE_OFFSET
));
172 case 0: /* OTG port */
173 v
&= ~(MX31_OTG_SIC_MASK
| MX31_OTG_PM_BIT
);
174 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
175 << MX31_OTG_SIC_SHIFT
;
176 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
177 v
|= MX31_OTG_PM_BIT
;
179 case 1: /* H1 port */
180 v
&= ~(MX31_H1_SIC_MASK
| MX31_H1_PM_BIT
| MX31_H1_DT_BIT
);
181 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
182 << MX31_H1_SIC_SHIFT
;
183 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
186 if (!(flags
& MXC_EHCI_TTL_ENABLED
))
190 case 2: /* H2 port */
191 v
&= ~(MX31_H2_SIC_MASK
| MX31_H2_PM_BIT
| MX31_H2_DT_BIT
);
192 v
|= (flags
& MXC_EHCI_INTERFACE_MASK
)
193 << MX31_H2_SIC_SHIFT
;
194 if (!(flags
& MXC_EHCI_POWER_PINS_ENABLED
))
197 if (!(flags
& MXC_EHCI_TTL_ENABLED
))
204 writel(v
, MX27_IO_ADDRESS(MX27_OTG_BASE_ADDR
+
205 USBCTRL_OTGBASE_OFFSET
));
208 #endif /* CONFIG_MACH_MX27 */
209 #ifdef CONFIG_ARCH_MX51
211 void __iomem
*usb_base
;
216 usb_base
= ioremap(MX51_OTG_BASE_ADDR
, SZ_4K
);
219 case 0: /* OTG port */
220 usbotg_base
= usb_base
+ MXC_OTG_OFFSET
;
222 case 1: /* Host 1 port */
223 usbotg_base
= usb_base
+ MXC_H1_OFFSET
;
226 printk(KERN_ERR
"%s no such port %d\n", __func__
, port
);
230 usbother_base
= usb_base
+ MX5_USBOTHER_REGS_OFFSET
;
233 case 0: /*OTG port */
234 if (flags
& MXC_EHCI_INTERNAL_PHY
) {
235 v
= __raw_readl(usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
237 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
238 v
|= (MXC_OTG_PHYCTRL_OC_DIS_BIT
| MXC_OTG_UCTRL_OPM_BIT
); /* OC/USBPWR is not used */
240 v
&= ~(MXC_OTG_PHYCTRL_OC_DIS_BIT
| MXC_OTG_UCTRL_OPM_BIT
); /* OC/USBPWR is used */
241 __raw_writel(v
, usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
243 v
= __raw_readl(usbother_base
+ MXC_USBCTRL_OFFSET
);
244 if (flags
& MXC_EHCI_WAKEUP_ENABLED
)
245 v
|= MXC_OTG_UCTRL_OWIE_BIT
;/* OTG wakeup enable */
247 v
&= ~MXC_OTG_UCTRL_OWIE_BIT
;/* OTG wakeup disable */
248 __raw_writel(v
, usbother_base
+ MXC_USBCTRL_OFFSET
);
253 v
= __raw_readl(usbother_base
+ MXC_USBCTRL_OFFSET
);
254 if (flags
& MXC_EHCI_WAKEUP_ENABLED
)
255 v
&= ~(MXC_H1_UCTRL_H1WIE_BIT
| MXC_H1_UCTRL_H1UIE_BIT
);/* HOST1 wakeup/ULPI intr disable */
257 v
&= ~(MXC_H1_UCTRL_H1WIE_BIT
| MXC_H1_UCTRL_H1UIE_BIT
);/* HOST1 wakeup/ULPI intr disable */
259 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
260 v
&= ~MXC_H1_UCTRL_H1PM_BIT
; /* HOST1 power mask used*/
262 v
|= MXC_H1_UCTRL_H1PM_BIT
; /* HOST1 power mask used*/
263 __raw_writel(v
, usbother_base
+ MXC_USBCTRL_OFFSET
);
265 v
= __raw_readl(usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
266 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
267 v
&= ~MXC_H1_OC_DIS_BIT
; /* OC is used */
269 v
|= MXC_H1_OC_DIS_BIT
; /* OC is not used */
270 __raw_writel(v
, usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
272 v
= __raw_readl(usbotg_base
+ MXC_USBCMD_OFFSET
);
273 if (flags
& MXC_EHCI_ITC_NO_THRESHOLD
)
274 /* Interrupt Threshold Control:Immediate (no threshold) */
275 v
&= MXC_UCMD_ITC_NO_THRESHOLD_MASK
;
276 __raw_writel(v
, usbotg_base
+ MXC_USBCMD_OFFSET
);
286 "%s() unable to setup USBCONTROL for this CPU\n", __func__
);
289 EXPORT_SYMBOL(mxc_initialize_usb_hw
);