blob: d60efdc9b142a3b9cabae8649960d77389ddb36b [file] [log] [blame]
Felipe Balbi54ab2b02009-10-14 11:44:14 +03001/*
2 * ehci-omap.c - driver for USBHOST on OMAP 34xx processor
3 *
4 * Bus Glue for OMAP34xx USBHOST 3 port EHCI controller
5 * Tested on OMAP3430 ES2.0 SDP
6 *
7 * Copyright (C) 2007-2008 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 *
10 * Copyright (C) 2009 Nokia Corporation
11 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
12 *
13 * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
Anand Gadiyarbdee2d82010-02-12 17:49:00 +053029 * TODO (last updated Feb 12, 2010):
Felipe Balbi54ab2b02009-10-14 11:44:14 +030030 * - add kernel-doc
31 * - enable AUTOIDLE
Felipe Balbi54ab2b02009-10-14 11:44:14 +030032 * - add suspend/resume
33 * - move workarounds to board-files
34 */
35
36#include <linux/platform_device.h>
37#include <linux/clk.h>
38#include <linux/gpio.h>
Ajay Kumar Gupta88114262009-12-28 13:40:46 +020039#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Ajay Kumar Gupta5aa4af22010-07-08 14:03:02 +053041#include <linux/usb/ulpi.h>
Thomas Weberc76f7822009-12-15 10:38:05 -080042#include <plat/usb.h>
Felipe Balbi54ab2b02009-10-14 11:44:14 +030043
44/*
45 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
46 * Use ehci_omap_readl()/ehci_omap_writel() functions
47 */
48
49/* TLL Register Set */
50#define OMAP_USBTLL_REVISION (0x00)
51#define OMAP_USBTLL_SYSCONFIG (0x10)
52#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
53#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
54#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
55#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
56#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
57
58#define OMAP_USBTLL_SYSSTATUS (0x14)
59#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
60
61#define OMAP_USBTLL_IRQSTATUS (0x18)
62#define OMAP_USBTLL_IRQENABLE (0x1C)
63
64#define OMAP_TLL_SHARED_CONF (0x30)
65#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
66#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
67#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
68#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
69#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
70
71#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
72#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
73#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
74#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
75#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
76#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
77
78#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
79#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
80#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
81#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
82#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
83#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
84#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
85#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
86#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
87
88#define OMAP_TLL_CHANNEL_COUNT 3
89#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1)
90#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2)
91#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4)
92
93/* UHH Register Set */
94#define OMAP_UHH_REVISION (0x00)
95#define OMAP_UHH_SYSCONFIG (0x10)
96#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
97#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
98#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
99#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
100#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
101#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
102
103#define OMAP_UHH_SYSSTATUS (0x14)
104#define OMAP_UHH_HOSTCONFIG (0x40)
105#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
106#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
107#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
108#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
109#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
110#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
111#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
112#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
113#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
114#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
115#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
116
117#define OMAP_UHH_DEBUG_CSR (0x44)
118
119/* EHCI Register Set */
Anand Gadiyar572538d2010-05-06 20:09:48 +0530120#define EHCI_INSNREG04 (0xA0)
121#define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300122#define EHCI_INSNREG05_ULPI (0xA4)
123#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
124#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
125#define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
126#define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
127#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
128#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
129
130/*-------------------------------------------------------------------------*/
131
132static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
133{
134 __raw_writel(val, base + reg);
135}
136
137static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
138{
139 return __raw_readl(base + reg);
140}
141
142static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
143{
144 __raw_writeb(val, base + reg);
145}
146
147static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
148{
149 return __raw_readb(base + reg);
150}
151
152/*-------------------------------------------------------------------------*/
153
154struct ehci_hcd_omap {
155 struct ehci_hcd *ehci;
156 struct device *dev;
157
158 struct clk *usbhost_ick;
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530159 struct clk *usbhost_hs_fck;
160 struct clk *usbhost_fs_fck;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300161 struct clk *usbtll_fck;
162 struct clk *usbtll_ick;
163
164 /* FIXME the following two workarounds are
165 * board specific not silicon-specific so these
166 * should be moved to board-file instead.
167 *
168 * Maybe someone from TI will know better which
169 * board is affected and needs the workarounds
170 * to be applied
171 */
172
173 /* gpio for resetting phy */
174 int reset_gpio_port[OMAP3_HS_USB_PORTS];
175
176 /* phy reset workaround */
177 int phy_reset;
178
179 /* desired phy_mode: TLL, PHY */
180 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
181
182 void __iomem *uhh_base;
183 void __iomem *tll_base;
184 void __iomem *ehci_base;
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200185
186 /* Regulators for USB PHYs.
Anand Gadiyara8cd4562010-05-10 14:51:19 +0530187 * Each PHY can have a separate regulator.
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200188 */
189 struct regulator *regulator[OMAP3_HS_USB_PORTS];
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300190};
191
192/*-------------------------------------------------------------------------*/
193
Keshava Munegowdac0726042010-11-21 23:23:40 +0530194static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask,
195 u8 tll_channel_count)
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300196{
197 unsigned reg;
198 int i;
199
200 /* Program the 3 TLL channels upfront */
Keshava Munegowdac0726042010-11-21 23:23:40 +0530201 for (i = 0; i < tll_channel_count; i++) {
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300202 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
203
204 /* Disable AutoIdle, BitStuffing and use SDR Mode */
205 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
206 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
207 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
208 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
209 }
210
211 /* Program Common TLL register */
212 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
213 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
214 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
215 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
216 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
217
218 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
219
220 /* Enable channels now */
Keshava Munegowdac0726042010-11-21 23:23:40 +0530221 for (i = 0; i < tll_channel_count; i++) {
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300222 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
223
224 /* Enable only the reg that is needed */
225 if (!(tll_channel_mask & 1<<i))
226 continue;
227
228 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
229 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
230
231 ehci_omap_writeb(omap->tll_base,
232 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
233 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
234 i+1, ehci_omap_readb(omap->tll_base,
235 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
236 }
237}
238
239/*-------------------------------------------------------------------------*/
240
Ajay Kumar Gupta5aa4af22010-07-08 14:03:02 +0530241static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
242{
243 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
244 unsigned reg = 0;
245
246 reg = ULPI_FUNC_CTRL_RESET
247 /* FUNCTION_CTRL_SET register */
248 | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
249 /* Write */
250 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
251 /* PORTn */
252 | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
253 /* start ULPI access*/
254 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
255
256 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg);
257
258 /* Wait for ULPI access completion */
259 while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI)
260 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
261 cpu_relax();
262
263 if (time_after(jiffies, timeout)) {
264 dev_dbg(omap->dev, "phy reset operation timed out\n");
265 break;
266 }
267 }
268}
269
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300270/* omap_start_ehc
271 * - Start the TI USBHOST controller
272 */
273static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
274{
275 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
276 u8 tll_ch_mask = 0;
277 unsigned reg = 0;
278 int ret = 0;
279
280 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
281
282 /* Enable Clocks for USBHOST */
283 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
284 if (IS_ERR(omap->usbhost_ick)) {
285 ret = PTR_ERR(omap->usbhost_ick);
286 goto err_host_ick;
287 }
288 clk_enable(omap->usbhost_ick);
289
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530290 omap->usbhost_hs_fck = clk_get(omap->dev, "usbhost_120m_fck");
291 if (IS_ERR(omap->usbhost_hs_fck)) {
292 ret = PTR_ERR(omap->usbhost_hs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300293 goto err_host_120m_fck;
294 }
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530295 clk_enable(omap->usbhost_hs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300296
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530297 omap->usbhost_fs_fck = clk_get(omap->dev, "usbhost_48m_fck");
298 if (IS_ERR(omap->usbhost_fs_fck)) {
299 ret = PTR_ERR(omap->usbhost_fs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300300 goto err_host_48m_fck;
301 }
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530302 clk_enable(omap->usbhost_fs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300303
304 if (omap->phy_reset) {
305 /* Refer: ISSUE1 */
306 if (gpio_is_valid(omap->reset_gpio_port[0])) {
307 gpio_request(omap->reset_gpio_port[0],
308 "USB1 PHY reset");
309 gpio_direction_output(omap->reset_gpio_port[0], 0);
310 }
311
312 if (gpio_is_valid(omap->reset_gpio_port[1])) {
313 gpio_request(omap->reset_gpio_port[1],
314 "USB2 PHY reset");
315 gpio_direction_output(omap->reset_gpio_port[1], 0);
316 }
317
318 /* Hold the PHY in RESET for enough time till DIR is high */
319 udelay(10);
320 }
321
322 /* Configure TLL for 60Mhz clk for ULPI */
323 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
324 if (IS_ERR(omap->usbtll_fck)) {
325 ret = PTR_ERR(omap->usbtll_fck);
326 goto err_tll_fck;
327 }
328 clk_enable(omap->usbtll_fck);
329
330 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
331 if (IS_ERR(omap->usbtll_ick)) {
332 ret = PTR_ERR(omap->usbtll_ick);
333 goto err_tll_ick;
334 }
335 clk_enable(omap->usbtll_ick);
336
337 /* perform TLL soft reset, and wait until reset is complete */
338 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
339 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
340
341 /* Wait for TLL reset to complete */
342 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
343 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
344 cpu_relax();
345
346 if (time_after(jiffies, timeout)) {
347 dev_dbg(omap->dev, "operation timed out\n");
348 ret = -EINVAL;
349 goto err_sys_status;
350 }
351 }
352
353 dev_dbg(omap->dev, "TLL RESET DONE\n");
354
355 /* (1<<3) = no idle mode only for initial debugging */
356 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
357 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
358 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
359 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
360
361
362 /* Put UHH in NoIdle/NoStandby mode */
363 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
364 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
365 | OMAP_UHH_SYSCONFIG_SIDLEMODE
366 | OMAP_UHH_SYSCONFIG_CACTIVITY
367 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
368 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
369
370 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
371
372 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
373
374 /* setup ULPI bypass and burst configurations */
375 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
376 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
377 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
378 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
379
380 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
381 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
382 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
383 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
384 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
385 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
386
387 /* Bypass the TLL module for PHY mode operation */
Ajay Kumar Gupta97dc7c62010-05-04 13:15:23 +0530388 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
389 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300390 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
391 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
392 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
393 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
394 else
395 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
396 } else {
397 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
398 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
399 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
400 else if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
401 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
402
403 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
404 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
405 else if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
406 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
407
408 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)
409 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
410 else if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
411 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
412
413 }
414 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
415 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
416
417
Anand Gadiyar572538d2010-05-06 20:09:48 +0530418 /*
419 * An undocumented "feature" in the OMAP3 EHCI controller,
420 * causes suspended ports to be taken out of suspend when
421 * the USBCMD.Run/Stop bit is cleared (for example when
422 * we do ehci_bus_suspend).
423 * This breaks suspend-resume if the root-hub is allowed
424 * to suspend. Writing 1 to this undocumented register bit
425 * disables this feature and restores normal behavior.
426 */
427 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04,
428 EHCI_INSNREG04_DISABLE_UNSUSPEND);
429
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300430 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
431 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
432 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
433
434 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
435 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
436 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
437 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
438 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
439 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
440
441 /* Enable UTMI mode for required TLL channels */
Keshava Munegowdac0726042010-11-21 23:23:40 +0530442 omap_usb_utmi_init(omap, tll_ch_mask, OMAP_TLL_CHANNEL_COUNT);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300443 }
444
445 if (omap->phy_reset) {
446 /* Refer ISSUE1:
447 * Hold the PHY in RESET for enough time till
448 * PHY is settled and ready
449 */
450 udelay(10);
451
452 if (gpio_is_valid(omap->reset_gpio_port[0]))
453 gpio_set_value(omap->reset_gpio_port[0], 1);
454
455 if (gpio_is_valid(omap->reset_gpio_port[1]))
456 gpio_set_value(omap->reset_gpio_port[1], 1);
457 }
458
Ajay Kumar Gupta5aa4af22010-07-08 14:03:02 +0530459 /* Soft reset the PHY using PHY reset command over ULPI */
460 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
461 omap_ehci_soft_phy_reset(omap, 0);
462 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
463 omap_ehci_soft_phy_reset(omap, 1);
464
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300465 return 0;
466
467err_sys_status:
468 clk_disable(omap->usbtll_ick);
469 clk_put(omap->usbtll_ick);
470
471err_tll_ick:
472 clk_disable(omap->usbtll_fck);
473 clk_put(omap->usbtll_fck);
474
475err_tll_fck:
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530476 clk_disable(omap->usbhost_fs_fck);
477 clk_put(omap->usbhost_fs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300478
479 if (omap->phy_reset) {
480 if (gpio_is_valid(omap->reset_gpio_port[0]))
481 gpio_free(omap->reset_gpio_port[0]);
482
483 if (gpio_is_valid(omap->reset_gpio_port[1]))
484 gpio_free(omap->reset_gpio_port[1]);
485 }
486
487err_host_48m_fck:
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530488 clk_disable(omap->usbhost_hs_fck);
489 clk_put(omap->usbhost_hs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300490
491err_host_120m_fck:
492 clk_disable(omap->usbhost_ick);
493 clk_put(omap->usbhost_ick);
494
495err_host_ick:
496 return ret;
497}
498
499static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
500{
501 unsigned long timeout = jiffies + msecs_to_jiffies(100);
502
503 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
504
505 /* Reset OMAP modules for insmod/rmmod to work */
506 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
507 OMAP_UHH_SYSCONFIG_SOFTRESET);
508 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
509 & (1 << 0))) {
510 cpu_relax();
511
512 if (time_after(jiffies, timeout))
513 dev_dbg(omap->dev, "operation timed out\n");
514 }
515
516 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
517 & (1 << 1))) {
518 cpu_relax();
519
520 if (time_after(jiffies, timeout))
521 dev_dbg(omap->dev, "operation timed out\n");
522 }
523
524 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
525 & (1 << 2))) {
526 cpu_relax();
527
528 if (time_after(jiffies, timeout))
529 dev_dbg(omap->dev, "operation timed out\n");
530 }
531
532 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
533
534 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
535 & (1 << 0))) {
536 cpu_relax();
537
538 if (time_after(jiffies, timeout))
539 dev_dbg(omap->dev, "operation timed out\n");
540 }
541
542 if (omap->usbtll_fck != NULL) {
543 clk_disable(omap->usbtll_fck);
544 clk_put(omap->usbtll_fck);
545 omap->usbtll_fck = NULL;
546 }
547
548 if (omap->usbhost_ick != NULL) {
549 clk_disable(omap->usbhost_ick);
550 clk_put(omap->usbhost_ick);
551 omap->usbhost_ick = NULL;
552 }
553
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530554 if (omap->usbhost_fs_fck != NULL) {
555 clk_disable(omap->usbhost_fs_fck);
556 clk_put(omap->usbhost_fs_fck);
557 omap->usbhost_fs_fck = NULL;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300558 }
559
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530560 if (omap->usbhost_hs_fck != NULL) {
561 clk_disable(omap->usbhost_hs_fck);
562 clk_put(omap->usbhost_hs_fck);
563 omap->usbhost_hs_fck = NULL;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300564 }
565
566 if (omap->usbtll_ick != NULL) {
567 clk_disable(omap->usbtll_ick);
568 clk_put(omap->usbtll_ick);
569 omap->usbtll_ick = NULL;
570 }
571
572 if (omap->phy_reset) {
573 if (gpio_is_valid(omap->reset_gpio_port[0]))
574 gpio_free(omap->reset_gpio_port[0]);
575
576 if (gpio_is_valid(omap->reset_gpio_port[1]))
577 gpio_free(omap->reset_gpio_port[1]);
578 }
579
580 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
581}
582
583/*-------------------------------------------------------------------------*/
584
585static const struct hc_driver ehci_omap_hc_driver;
586
587/* configure so an HC device and id are always provided */
588/* always called with process context; sleeping is OK */
589
590/**
591 * ehci_hcd_omap_probe - initialize TI-based HCDs
592 *
593 * Allocates basic resources for this USB host controller, and
594 * then invokes the start() method for the HCD associated with it
595 * through the hotplug entry's driver_data.
596 */
597static int ehci_hcd_omap_probe(struct platform_device *pdev)
598{
599 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
600 struct ehci_hcd_omap *omap;
601 struct resource *res;
602 struct usb_hcd *hcd;
603
604 int irq = platform_get_irq(pdev, 0);
605 int ret = -ENODEV;
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200606 int i;
607 char supply[7];
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300608
609 if (!pdata) {
610 dev_dbg(&pdev->dev, "missing platform_data\n");
611 goto err_pdata;
612 }
613
614 if (usb_disabled())
615 goto err_disabled;
616
617 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
618 if (!omap) {
619 ret = -ENOMEM;
Julia Lawallb2b60802009-11-21 12:52:17 +0100620 goto err_disabled;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300621 }
622
623 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
624 dev_name(&pdev->dev));
625 if (!hcd) {
626 dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
627 ret = -ENOMEM;
628 goto err_create_hcd;
629 }
630
631 platform_set_drvdata(pdev, omap);
632 omap->dev = &pdev->dev;
633 omap->phy_reset = pdata->phy_reset;
634 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
635 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
636 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
637 omap->port_mode[0] = pdata->port_mode[0];
638 omap->port_mode[1] = pdata->port_mode[1];
639 omap->port_mode[2] = pdata->port_mode[2];
640 omap->ehci = hcd_to_ehci(hcd);
641 omap->ehci->sbrn = 0x20;
642
643 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
644
645 hcd->rsrc_start = res->start;
646 hcd->rsrc_len = resource_size(res);
647
648 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
649 if (!hcd->regs) {
650 dev_err(&pdev->dev, "EHCI ioremap failed\n");
651 ret = -ENOMEM;
652 goto err_ioremap;
653 }
654
655 /* we know this is the memory we want, no need to ioremap again */
656 omap->ehci->caps = hcd->regs;
657 omap->ehci_base = hcd->regs;
658
659 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
660 omap->uhh_base = ioremap(res->start, resource_size(res));
661 if (!omap->uhh_base) {
662 dev_err(&pdev->dev, "UHH ioremap failed\n");
663 ret = -ENOMEM;
664 goto err_uhh_ioremap;
665 }
666
667 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
668 omap->tll_base = ioremap(res->start, resource_size(res));
669 if (!omap->tll_base) {
670 dev_err(&pdev->dev, "TLL ioremap failed\n");
671 ret = -ENOMEM;
672 goto err_tll_ioremap;
673 }
674
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200675 /* get ehci regulator and enable */
676 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
677 if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
678 omap->regulator[i] = NULL;
679 continue;
680 }
681 snprintf(supply, sizeof(supply), "hsusb%d", i);
682 omap->regulator[i] = regulator_get(omap->dev, supply);
Ajay Kumar Gupta18f91192010-03-18 16:58:35 +0530683 if (IS_ERR(omap->regulator[i])) {
684 omap->regulator[i] = NULL;
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200685 dev_dbg(&pdev->dev,
686 "failed to get ehci port%d regulator\n", i);
Ajay Kumar Gupta18f91192010-03-18 16:58:35 +0530687 } else {
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200688 regulator_enable(omap->regulator[i]);
Ajay Kumar Gupta18f91192010-03-18 16:58:35 +0530689 }
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200690 }
691
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300692 ret = omap_start_ehc(omap, hcd);
693 if (ret) {
694 dev_dbg(&pdev->dev, "failed to start ehci\n");
695 goto err_start;
696 }
697
698 omap->ehci->regs = hcd->regs
699 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
700
Anand Gadiyarbdb581b2010-02-12 17:54:59 +0530701 dbg_hcs_params(omap->ehci, "reset");
702 dbg_hcc_params(omap->ehci, "reset");
703
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300704 /* cache this readonly data; minimize chip reads */
705 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
706
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300707 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
708 if (ret) {
709 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
710 goto err_add_hcd;
711 }
712
Ajay Kumar Gupta289621c2010-05-04 19:53:09 +0530713 /* root ports should always stay powered */
714 ehci_port_power(omap->ehci, 1);
715
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300716 return 0;
717
718err_add_hcd:
719 omap_stop_ehc(omap, hcd);
720
721err_start:
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200722 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
723 if (omap->regulator[i]) {
724 regulator_disable(omap->regulator[i]);
725 regulator_put(omap->regulator[i]);
726 }
727 }
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300728 iounmap(omap->tll_base);
729
730err_tll_ioremap:
731 iounmap(omap->uhh_base);
732
733err_uhh_ioremap:
734 iounmap(hcd->regs);
735
736err_ioremap:
737 usb_put_hcd(hcd);
738
739err_create_hcd:
Julia Lawallb2b60802009-11-21 12:52:17 +0100740 kfree(omap);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300741err_disabled:
742err_pdata:
743 return ret;
744}
745
746/* may be called without controller electrically present */
747/* may be called with controller, bus, and devices active */
748
749/**
750 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
751 * @pdev: USB Host Controller being removed
752 *
753 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
754 * the HCD's stop() method. It is always called from a thread
755 * context, normally "rmmod", "apmd", or something similar.
756 */
757static int ehci_hcd_omap_remove(struct platform_device *pdev)
758{
759 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
760 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200761 int i;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300762
763 usb_remove_hcd(hcd);
764 omap_stop_ehc(omap, hcd);
765 iounmap(hcd->regs);
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200766 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
767 if (omap->regulator[i]) {
768 regulator_disable(omap->regulator[i]);
769 regulator_put(omap->regulator[i]);
770 }
771 }
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300772 iounmap(omap->tll_base);
773 iounmap(omap->uhh_base);
774 usb_put_hcd(hcd);
Ajay Kumar Guptad3ae8562009-12-28 13:40:45 +0200775 kfree(omap);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300776
777 return 0;
778}
779
780static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
781{
782 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
783 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
784
785 if (hcd->driver->shutdown)
786 hcd->driver->shutdown(hcd);
787}
788
789static struct platform_driver ehci_hcd_omap_driver = {
790 .probe = ehci_hcd_omap_probe,
791 .remove = ehci_hcd_omap_remove,
792 .shutdown = ehci_hcd_omap_shutdown,
793 /*.suspend = ehci_hcd_omap_suspend, */
794 /*.resume = ehci_hcd_omap_resume, */
795 .driver = {
796 .name = "ehci-omap",
797 }
798};
799
800/*-------------------------------------------------------------------------*/
801
802static const struct hc_driver ehci_omap_hc_driver = {
803 .description = hcd_name,
804 .product_desc = "OMAP-EHCI Host Controller",
805 .hcd_priv_size = sizeof(struct ehci_hcd),
806
807 /*
808 * generic hardware linkage
809 */
810 .irq = ehci_irq,
811 .flags = HCD_MEMORY | HCD_USB2,
812
813 /*
814 * basic lifecycle operations
815 */
816 .reset = ehci_init,
817 .start = ehci_run,
818 .stop = ehci_stop,
819 .shutdown = ehci_shutdown,
820
821 /*
822 * managing i/o requests and associated device resources
823 */
824 .urb_enqueue = ehci_urb_enqueue,
825 .urb_dequeue = ehci_urb_dequeue,
826 .endpoint_disable = ehci_endpoint_disable,
827 .endpoint_reset = ehci_endpoint_reset,
828
829 /*
830 * scheduling support
831 */
832 .get_frame_number = ehci_get_frame,
833
834 /*
835 * root hub support
836 */
837 .hub_status_data = ehci_hub_status_data,
838 .hub_control = ehci_hub_control,
839 .bus_suspend = ehci_bus_suspend,
840 .bus_resume = ehci_bus_resume,
841
842 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
843};
844
845MODULE_ALIAS("platform:omap-ehci");
846MODULE_AUTHOR("Texas Instruments, Inc.");
847MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
848