2 * ehci-omap.c - driver for USBHOST on OMAP 34xx processor
4 * Bus Glue for OMAP34xx USBHOST 3 port EHCI controller
5 * Tested on OMAP3430 ES2.0 SDP
7 * Copyright (C) 2007-2008 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com>
10 * Copyright (C) 2009 Nokia Corporation
11 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
13 * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
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.
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.
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
29 * TODO (last updated Feb 12, 2010):
32 * - add suspend/resume
33 * - move workarounds to board-files
36 #include <linux/platform_device.h>
37 #include <linux/clk.h>
38 #include <linux/gpio.h>
39 #include <linux/regulator/consumer.h>
40 #include <linux/slab.h>
44 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
45 * Use ehci_omap_readl()/ehci_omap_writel() functions
48 /* TLL Register Set */
49 #define OMAP_USBTLL_REVISION (0x00)
50 #define OMAP_USBTLL_SYSCONFIG (0x10)
51 #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
52 #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
53 #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
54 #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
55 #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
57 #define OMAP_USBTLL_SYSSTATUS (0x14)
58 #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
60 #define OMAP_USBTLL_IRQSTATUS (0x18)
61 #define OMAP_USBTLL_IRQENABLE (0x1C)
63 #define OMAP_TLL_SHARED_CONF (0x30)
64 #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
65 #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
66 #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
67 #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
68 #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
70 #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
71 #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
72 #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
73 #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
74 #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
75 #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
77 #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
78 #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
79 #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
80 #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
81 #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
82 #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
83 #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
84 #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
85 #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
87 #define OMAP_TLL_CHANNEL_COUNT 3
88 #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1)
89 #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2)
90 #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4)
92 /* UHH Register Set */
93 #define OMAP_UHH_REVISION (0x00)
94 #define OMAP_UHH_SYSCONFIG (0x10)
95 #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
96 #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
97 #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
98 #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
99 #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
100 #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
102 #define OMAP_UHH_SYSSTATUS (0x14)
103 #define OMAP_UHH_HOSTCONFIG (0x40)
104 #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
105 #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
106 #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
107 #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
108 #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
109 #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
110 #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
111 #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
112 #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
113 #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
114 #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
116 #define OMAP_UHH_DEBUG_CSR (0x44)
118 /* EHCI Register Set */
119 #define EHCI_INSNREG05_ULPI (0xA4)
120 #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
121 #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
122 #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
123 #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
124 #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
125 #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
127 /*-------------------------------------------------------------------------*/
129 static inline void ehci_omap_writel(void __iomem
*base
, u32 reg
, u32 val
)
131 __raw_writel(val
, base
+ reg
);
134 static inline u32
ehci_omap_readl(void __iomem
*base
, u32 reg
)
136 return __raw_readl(base
+ reg
);
139 static inline void ehci_omap_writeb(void __iomem
*base
, u8 reg
, u8 val
)
141 __raw_writeb(val
, base
+ reg
);
144 static inline u8
ehci_omap_readb(void __iomem
*base
, u8 reg
)
146 return __raw_readb(base
+ reg
);
149 /*-------------------------------------------------------------------------*/
151 struct ehci_hcd_omap
{
152 struct ehci_hcd
*ehci
;
155 struct clk
*usbhost_ick
;
156 struct clk
*usbhost2_120m_fck
;
157 struct clk
*usbhost1_48m_fck
;
158 struct clk
*usbtll_fck
;
159 struct clk
*usbtll_ick
;
161 /* FIXME the following two workarounds are
162 * board specific not silicon-specific so these
163 * should be moved to board-file instead.
165 * Maybe someone from TI will know better which
166 * board is affected and needs the workarounds
170 /* gpio for resetting phy */
171 int reset_gpio_port
[OMAP3_HS_USB_PORTS
];
173 /* phy reset workaround */
176 /* desired phy_mode: TLL, PHY */
177 enum ehci_hcd_omap_mode port_mode
[OMAP3_HS_USB_PORTS
];
179 void __iomem
*uhh_base
;
180 void __iomem
*tll_base
;
181 void __iomem
*ehci_base
;
183 /* Regulators for USB PHYs.
184 * Each PHY can have a seperate regulator.
186 struct regulator
*regulator
[OMAP3_HS_USB_PORTS
];
189 /*-------------------------------------------------------------------------*/
191 static void omap_usb_utmi_init(struct ehci_hcd_omap
*omap
, u8 tll_channel_mask
)
196 /* Program the 3 TLL channels upfront */
197 for (i
= 0; i
< OMAP_TLL_CHANNEL_COUNT
; i
++) {
198 reg
= ehci_omap_readl(omap
->tll_base
, OMAP_TLL_CHANNEL_CONF(i
));
200 /* Disable AutoIdle, BitStuffing and use SDR Mode */
201 reg
&= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
202 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
203 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE
);
204 ehci_omap_writel(omap
->tll_base
, OMAP_TLL_CHANNEL_CONF(i
), reg
);
207 /* Program Common TLL register */
208 reg
= ehci_omap_readl(omap
->tll_base
, OMAP_TLL_SHARED_CONF
);
209 reg
|= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
210 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
211 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN
);
212 reg
&= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN
;
214 ehci_omap_writel(omap
->tll_base
, OMAP_TLL_SHARED_CONF
, reg
);
216 /* Enable channels now */
217 for (i
= 0; i
< OMAP_TLL_CHANNEL_COUNT
; i
++) {
218 reg
= ehci_omap_readl(omap
->tll_base
, OMAP_TLL_CHANNEL_CONF(i
));
220 /* Enable only the reg that is needed */
221 if (!(tll_channel_mask
& 1<<i
))
224 reg
|= OMAP_TLL_CHANNEL_CONF_CHANEN
;
225 ehci_omap_writel(omap
->tll_base
, OMAP_TLL_CHANNEL_CONF(i
), reg
);
227 ehci_omap_writeb(omap
->tll_base
,
228 OMAP_TLL_ULPI_SCRATCH_REGISTER(i
), 0xbe);
229 dev_dbg(omap
->dev
, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
230 i
+1, ehci_omap_readb(omap
->tll_base
,
231 OMAP_TLL_ULPI_SCRATCH_REGISTER(i
)));
235 /*-------------------------------------------------------------------------*/
238 * - Start the TI USBHOST controller
240 static int omap_start_ehc(struct ehci_hcd_omap
*omap
, struct usb_hcd
*hcd
)
242 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
247 dev_dbg(omap
->dev
, "starting TI EHCI USB Controller\n");
249 /* Enable Clocks for USBHOST */
250 omap
->usbhost_ick
= clk_get(omap
->dev
, "usbhost_ick");
251 if (IS_ERR(omap
->usbhost_ick
)) {
252 ret
= PTR_ERR(omap
->usbhost_ick
);
255 clk_enable(omap
->usbhost_ick
);
257 omap
->usbhost2_120m_fck
= clk_get(omap
->dev
, "usbhost_120m_fck");
258 if (IS_ERR(omap
->usbhost2_120m_fck
)) {
259 ret
= PTR_ERR(omap
->usbhost2_120m_fck
);
260 goto err_host_120m_fck
;
262 clk_enable(omap
->usbhost2_120m_fck
);
264 omap
->usbhost1_48m_fck
= clk_get(omap
->dev
, "usbhost_48m_fck");
265 if (IS_ERR(omap
->usbhost1_48m_fck
)) {
266 ret
= PTR_ERR(omap
->usbhost1_48m_fck
);
267 goto err_host_48m_fck
;
269 clk_enable(omap
->usbhost1_48m_fck
);
271 if (omap
->phy_reset
) {
273 if (gpio_is_valid(omap
->reset_gpio_port
[0])) {
274 gpio_request(omap
->reset_gpio_port
[0],
276 gpio_direction_output(omap
->reset_gpio_port
[0], 0);
279 if (gpio_is_valid(omap
->reset_gpio_port
[1])) {
280 gpio_request(omap
->reset_gpio_port
[1],
282 gpio_direction_output(omap
->reset_gpio_port
[1], 0);
285 /* Hold the PHY in RESET for enough time till DIR is high */
289 /* Configure TLL for 60Mhz clk for ULPI */
290 omap
->usbtll_fck
= clk_get(omap
->dev
, "usbtll_fck");
291 if (IS_ERR(omap
->usbtll_fck
)) {
292 ret
= PTR_ERR(omap
->usbtll_fck
);
295 clk_enable(omap
->usbtll_fck
);
297 omap
->usbtll_ick
= clk_get(omap
->dev
, "usbtll_ick");
298 if (IS_ERR(omap
->usbtll_ick
)) {
299 ret
= PTR_ERR(omap
->usbtll_ick
);
302 clk_enable(omap
->usbtll_ick
);
304 /* perform TLL soft reset, and wait until reset is complete */
305 ehci_omap_writel(omap
->tll_base
, OMAP_USBTLL_SYSCONFIG
,
306 OMAP_USBTLL_SYSCONFIG_SOFTRESET
);
308 /* Wait for TLL reset to complete */
309 while (!(ehci_omap_readl(omap
->tll_base
, OMAP_USBTLL_SYSSTATUS
)
310 & OMAP_USBTLL_SYSSTATUS_RESETDONE
)) {
313 if (time_after(jiffies
, timeout
)) {
314 dev_dbg(omap
->dev
, "operation timed out\n");
320 dev_dbg(omap
->dev
, "TLL RESET DONE\n");
322 /* (1<<3) = no idle mode only for initial debugging */
323 ehci_omap_writel(omap
->tll_base
, OMAP_USBTLL_SYSCONFIG
,
324 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP
|
325 OMAP_USBTLL_SYSCONFIG_SIDLEMODE
|
326 OMAP_USBTLL_SYSCONFIG_CACTIVITY
);
329 /* Put UHH in NoIdle/NoStandby mode */
330 reg
= ehci_omap_readl(omap
->uhh_base
, OMAP_UHH_SYSCONFIG
);
331 reg
|= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
332 | OMAP_UHH_SYSCONFIG_SIDLEMODE
333 | OMAP_UHH_SYSCONFIG_CACTIVITY
334 | OMAP_UHH_SYSCONFIG_MIDLEMODE
);
335 reg
&= ~OMAP_UHH_SYSCONFIG_AUTOIDLE
;
337 ehci_omap_writel(omap
->uhh_base
, OMAP_UHH_SYSCONFIG
, reg
);
339 reg
= ehci_omap_readl(omap
->uhh_base
, OMAP_UHH_HOSTCONFIG
);
341 /* setup ULPI bypass and burst configurations */
342 reg
|= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
343 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
344 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN
);
345 reg
&= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN
;
347 if (omap
->port_mode
[0] == EHCI_HCD_OMAP_MODE_UNKNOWN
)
348 reg
&= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS
;
349 if (omap
->port_mode
[1] == EHCI_HCD_OMAP_MODE_UNKNOWN
)
350 reg
&= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS
;
351 if (omap
->port_mode
[2] == EHCI_HCD_OMAP_MODE_UNKNOWN
)
352 reg
&= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS
;
354 /* Bypass the TLL module for PHY mode operation */
355 if (omap_rev() <= OMAP3430_REV_ES2_1
) {
356 dev_dbg(omap
->dev
, "OMAP3 ES version <= ES2.1 \n");
357 if ((omap
->port_mode
[0] == EHCI_HCD_OMAP_MODE_PHY
) ||
358 (omap
->port_mode
[1] == EHCI_HCD_OMAP_MODE_PHY
) ||
359 (omap
->port_mode
[2] == EHCI_HCD_OMAP_MODE_PHY
))
360 reg
&= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS
;
362 reg
|= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS
;
364 dev_dbg(omap
->dev
, "OMAP3 ES version > ES2.1\n");
365 if (omap
->port_mode
[0] == EHCI_HCD_OMAP_MODE_PHY
)
366 reg
&= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS
;
367 else if (omap
->port_mode
[0] == EHCI_HCD_OMAP_MODE_TLL
)
368 reg
|= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS
;
370 if (omap
->port_mode
[1] == EHCI_HCD_OMAP_MODE_PHY
)
371 reg
&= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS
;
372 else if (omap
->port_mode
[1] == EHCI_HCD_OMAP_MODE_TLL
)
373 reg
|= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS
;
375 if (omap
->port_mode
[2] == EHCI_HCD_OMAP_MODE_PHY
)
376 reg
&= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS
;
377 else if (omap
->port_mode
[2] == EHCI_HCD_OMAP_MODE_TLL
)
378 reg
|= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS
;
381 ehci_omap_writel(omap
->uhh_base
, OMAP_UHH_HOSTCONFIG
, reg
);
382 dev_dbg(omap
->dev
, "UHH setup done, uhh_hostconfig=%x\n", reg
);
385 if ((omap
->port_mode
[0] == EHCI_HCD_OMAP_MODE_TLL
) ||
386 (omap
->port_mode
[1] == EHCI_HCD_OMAP_MODE_TLL
) ||
387 (omap
->port_mode
[2] == EHCI_HCD_OMAP_MODE_TLL
)) {
389 if (omap
->port_mode
[0] == EHCI_HCD_OMAP_MODE_TLL
)
390 tll_ch_mask
|= OMAP_TLL_CHANNEL_1_EN_MASK
;
391 if (omap
->port_mode
[1] == EHCI_HCD_OMAP_MODE_TLL
)
392 tll_ch_mask
|= OMAP_TLL_CHANNEL_2_EN_MASK
;
393 if (omap
->port_mode
[2] == EHCI_HCD_OMAP_MODE_TLL
)
394 tll_ch_mask
|= OMAP_TLL_CHANNEL_3_EN_MASK
;
396 /* Enable UTMI mode for required TLL channels */
397 omap_usb_utmi_init(omap
, tll_ch_mask
);
400 if (omap
->phy_reset
) {
402 * Hold the PHY in RESET for enough time till
403 * PHY is settled and ready
407 if (gpio_is_valid(omap
->reset_gpio_port
[0]))
408 gpio_set_value(omap
->reset_gpio_port
[0], 1);
410 if (gpio_is_valid(omap
->reset_gpio_port
[1]))
411 gpio_set_value(omap
->reset_gpio_port
[1], 1);
417 clk_disable(omap
->usbtll_ick
);
418 clk_put(omap
->usbtll_ick
);
421 clk_disable(omap
->usbtll_fck
);
422 clk_put(omap
->usbtll_fck
);
425 clk_disable(omap
->usbhost1_48m_fck
);
426 clk_put(omap
->usbhost1_48m_fck
);
428 if (omap
->phy_reset
) {
429 if (gpio_is_valid(omap
->reset_gpio_port
[0]))
430 gpio_free(omap
->reset_gpio_port
[0]);
432 if (gpio_is_valid(omap
->reset_gpio_port
[1]))
433 gpio_free(omap
->reset_gpio_port
[1]);
437 clk_disable(omap
->usbhost2_120m_fck
);
438 clk_put(omap
->usbhost2_120m_fck
);
441 clk_disable(omap
->usbhost_ick
);
442 clk_put(omap
->usbhost_ick
);
448 static void omap_stop_ehc(struct ehci_hcd_omap
*omap
, struct usb_hcd
*hcd
)
450 unsigned long timeout
= jiffies
+ msecs_to_jiffies(100);
452 dev_dbg(omap
->dev
, "stopping TI EHCI USB Controller\n");
454 /* Reset OMAP modules for insmod/rmmod to work */
455 ehci_omap_writel(omap
->uhh_base
, OMAP_UHH_SYSCONFIG
,
456 OMAP_UHH_SYSCONFIG_SOFTRESET
);
457 while (!(ehci_omap_readl(omap
->uhh_base
, OMAP_UHH_SYSSTATUS
)
461 if (time_after(jiffies
, timeout
))
462 dev_dbg(omap
->dev
, "operation timed out\n");
465 while (!(ehci_omap_readl(omap
->uhh_base
, OMAP_UHH_SYSSTATUS
)
469 if (time_after(jiffies
, timeout
))
470 dev_dbg(omap
->dev
, "operation timed out\n");
473 while (!(ehci_omap_readl(omap
->uhh_base
, OMAP_UHH_SYSSTATUS
)
477 if (time_after(jiffies
, timeout
))
478 dev_dbg(omap
->dev
, "operation timed out\n");
481 ehci_omap_writel(omap
->tll_base
, OMAP_USBTLL_SYSCONFIG
, (1 << 1));
483 while (!(ehci_omap_readl(omap
->tll_base
, OMAP_USBTLL_SYSSTATUS
)
487 if (time_after(jiffies
, timeout
))
488 dev_dbg(omap
->dev
, "operation timed out\n");
491 if (omap
->usbtll_fck
!= NULL
) {
492 clk_disable(omap
->usbtll_fck
);
493 clk_put(omap
->usbtll_fck
);
494 omap
->usbtll_fck
= NULL
;
497 if (omap
->usbhost_ick
!= NULL
) {
498 clk_disable(omap
->usbhost_ick
);
499 clk_put(omap
->usbhost_ick
);
500 omap
->usbhost_ick
= NULL
;
503 if (omap
->usbhost1_48m_fck
!= NULL
) {
504 clk_disable(omap
->usbhost1_48m_fck
);
505 clk_put(omap
->usbhost1_48m_fck
);
506 omap
->usbhost1_48m_fck
= NULL
;
509 if (omap
->usbhost2_120m_fck
!= NULL
) {
510 clk_disable(omap
->usbhost2_120m_fck
);
511 clk_put(omap
->usbhost2_120m_fck
);
512 omap
->usbhost2_120m_fck
= NULL
;
515 if (omap
->usbtll_ick
!= NULL
) {
516 clk_disable(omap
->usbtll_ick
);
517 clk_put(omap
->usbtll_ick
);
518 omap
->usbtll_ick
= NULL
;
521 if (omap
->phy_reset
) {
522 if (gpio_is_valid(omap
->reset_gpio_port
[0]))
523 gpio_free(omap
->reset_gpio_port
[0]);
525 if (gpio_is_valid(omap
->reset_gpio_port
[1]))
526 gpio_free(omap
->reset_gpio_port
[1]);
529 dev_dbg(omap
->dev
, "Clock to USB host has been disabled\n");
532 /*-------------------------------------------------------------------------*/
534 static const struct hc_driver ehci_omap_hc_driver
;
536 /* configure so an HC device and id are always provided */
537 /* always called with process context; sleeping is OK */
540 * ehci_hcd_omap_probe - initialize TI-based HCDs
542 * Allocates basic resources for this USB host controller, and
543 * then invokes the start() method for the HCD associated with it
544 * through the hotplug entry's driver_data.
546 static int ehci_hcd_omap_probe(struct platform_device
*pdev
)
548 struct ehci_hcd_omap_platform_data
*pdata
= pdev
->dev
.platform_data
;
549 struct ehci_hcd_omap
*omap
;
550 struct resource
*res
;
553 int irq
= platform_get_irq(pdev
, 0);
559 dev_dbg(&pdev
->dev
, "missing platform_data\n");
566 omap
= kzalloc(sizeof(*omap
), GFP_KERNEL
);
572 hcd
= usb_create_hcd(&ehci_omap_hc_driver
, &pdev
->dev
,
573 dev_name(&pdev
->dev
));
575 dev_dbg(&pdev
->dev
, "failed to create hcd with err %d\n", ret
);
580 platform_set_drvdata(pdev
, omap
);
581 omap
->dev
= &pdev
->dev
;
582 omap
->phy_reset
= pdata
->phy_reset
;
583 omap
->reset_gpio_port
[0] = pdata
->reset_gpio_port
[0];
584 omap
->reset_gpio_port
[1] = pdata
->reset_gpio_port
[1];
585 omap
->reset_gpio_port
[2] = pdata
->reset_gpio_port
[2];
586 omap
->port_mode
[0] = pdata
->port_mode
[0];
587 omap
->port_mode
[1] = pdata
->port_mode
[1];
588 omap
->port_mode
[2] = pdata
->port_mode
[2];
589 omap
->ehci
= hcd_to_ehci(hcd
);
590 omap
->ehci
->sbrn
= 0x20;
592 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
594 hcd
->rsrc_start
= res
->start
;
595 hcd
->rsrc_len
= resource_size(res
);
597 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
599 dev_err(&pdev
->dev
, "EHCI ioremap failed\n");
604 /* we know this is the memory we want, no need to ioremap again */
605 omap
->ehci
->caps
= hcd
->regs
;
606 omap
->ehci_base
= hcd
->regs
;
608 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
609 omap
->uhh_base
= ioremap(res
->start
, resource_size(res
));
610 if (!omap
->uhh_base
) {
611 dev_err(&pdev
->dev
, "UHH ioremap failed\n");
613 goto err_uhh_ioremap
;
616 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 2);
617 omap
->tll_base
= ioremap(res
->start
, resource_size(res
));
618 if (!omap
->tll_base
) {
619 dev_err(&pdev
->dev
, "TLL ioremap failed\n");
621 goto err_tll_ioremap
;
624 /* get ehci regulator and enable */
625 for (i
= 0 ; i
< OMAP3_HS_USB_PORTS
; i
++) {
626 if (omap
->port_mode
[i
] != EHCI_HCD_OMAP_MODE_PHY
) {
627 omap
->regulator
[i
] = NULL
;
630 snprintf(supply
, sizeof(supply
), "hsusb%d", i
);
631 omap
->regulator
[i
] = regulator_get(omap
->dev
, supply
);
632 if (IS_ERR(omap
->regulator
[i
]))
634 "failed to get ehci port%d regulator\n", i
);
636 regulator_enable(omap
->regulator
[i
]);
639 ret
= omap_start_ehc(omap
, hcd
);
641 dev_dbg(&pdev
->dev
, "failed to start ehci\n");
645 omap
->ehci
->regs
= hcd
->regs
646 + HC_LENGTH(readl(&omap
->ehci
->caps
->hc_capbase
));
648 dbg_hcs_params(omap
->ehci
, "reset");
649 dbg_hcc_params(omap
->ehci
, "reset");
651 /* cache this readonly data; minimize chip reads */
652 omap
->ehci
->hcs_params
= readl(&omap
->ehci
->caps
->hcs_params
);
654 ret
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| IRQF_SHARED
);
656 dev_dbg(&pdev
->dev
, "failed to add hcd with err %d\n", ret
);
663 omap_stop_ehc(omap
, hcd
);
666 for (i
= 0 ; i
< OMAP3_HS_USB_PORTS
; i
++) {
667 if (omap
->regulator
[i
]) {
668 regulator_disable(omap
->regulator
[i
]);
669 regulator_put(omap
->regulator
[i
]);
672 iounmap(omap
->tll_base
);
675 iounmap(omap
->uhh_base
);
690 /* may be called without controller electrically present */
691 /* may be called with controller, bus, and devices active */
694 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
695 * @pdev: USB Host Controller being removed
697 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
698 * the HCD's stop() method. It is always called from a thread
699 * context, normally "rmmod", "apmd", or something similar.
701 static int ehci_hcd_omap_remove(struct platform_device
*pdev
)
703 struct ehci_hcd_omap
*omap
= platform_get_drvdata(pdev
);
704 struct usb_hcd
*hcd
= ehci_to_hcd(omap
->ehci
);
708 omap_stop_ehc(omap
, hcd
);
710 for (i
= 0 ; i
< OMAP3_HS_USB_PORTS
; i
++) {
711 if (omap
->regulator
[i
]) {
712 regulator_disable(omap
->regulator
[i
]);
713 regulator_put(omap
->regulator
[i
]);
716 iounmap(omap
->tll_base
);
717 iounmap(omap
->uhh_base
);
724 static void ehci_hcd_omap_shutdown(struct platform_device
*pdev
)
726 struct ehci_hcd_omap
*omap
= platform_get_drvdata(pdev
);
727 struct usb_hcd
*hcd
= ehci_to_hcd(omap
->ehci
);
729 if (hcd
->driver
->shutdown
)
730 hcd
->driver
->shutdown(hcd
);
733 static struct platform_driver ehci_hcd_omap_driver
= {
734 .probe
= ehci_hcd_omap_probe
,
735 .remove
= ehci_hcd_omap_remove
,
736 .shutdown
= ehci_hcd_omap_shutdown
,
737 /*.suspend = ehci_hcd_omap_suspend, */
738 /*.resume = ehci_hcd_omap_resume, */
744 /*-------------------------------------------------------------------------*/
746 static const struct hc_driver ehci_omap_hc_driver
= {
747 .description
= hcd_name
,
748 .product_desc
= "OMAP-EHCI Host Controller",
749 .hcd_priv_size
= sizeof(struct ehci_hcd
),
752 * generic hardware linkage
755 .flags
= HCD_MEMORY
| HCD_USB2
,
758 * basic lifecycle operations
763 .shutdown
= ehci_shutdown
,
766 * managing i/o requests and associated device resources
768 .urb_enqueue
= ehci_urb_enqueue
,
769 .urb_dequeue
= ehci_urb_dequeue
,
770 .endpoint_disable
= ehci_endpoint_disable
,
771 .endpoint_reset
= ehci_endpoint_reset
,
776 .get_frame_number
= ehci_get_frame
,
781 .hub_status_data
= ehci_hub_status_data
,
782 .hub_control
= ehci_hub_control
,
783 .bus_suspend
= ehci_bus_suspend
,
784 .bus_resume
= ehci_bus_resume
,
786 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
789 MODULE_ALIAS("platform:omap-ehci");
790 MODULE_AUTHOR("Texas Instruments, Inc.");
791 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");