blob: dd9d5c1d9a8f9c066329df52e7d5095a7c9071e9 [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
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530130#define is_ehci_phy_mode(x) (x == EHCI_HCD_OMAP_MODE_PHY)
131#define is_ehci_tll_mode(x) (x == EHCI_HCD_OMAP_MODE_TLL)
132
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300133/*-------------------------------------------------------------------------*/
134
135static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
136{
137 __raw_writel(val, base + reg);
138}
139
140static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
141{
142 return __raw_readl(base + reg);
143}
144
145static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
146{
147 __raw_writeb(val, base + reg);
148}
149
150static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
151{
152 return __raw_readb(base + reg);
153}
154
155/*-------------------------------------------------------------------------*/
156
157struct ehci_hcd_omap {
158 struct ehci_hcd *ehci;
159 struct device *dev;
160
161 struct clk *usbhost_ick;
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530162 struct clk *usbhost_hs_fck;
163 struct clk *usbhost_fs_fck;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300164 struct clk *usbtll_fck;
165 struct clk *usbtll_ick;
166
167 /* FIXME the following two workarounds are
168 * board specific not silicon-specific so these
169 * should be moved to board-file instead.
170 *
171 * Maybe someone from TI will know better which
172 * board is affected and needs the workarounds
173 * to be applied
174 */
175
176 /* gpio for resetting phy */
177 int reset_gpio_port[OMAP3_HS_USB_PORTS];
178
179 /* phy reset workaround */
180 int phy_reset;
181
182 /* desired phy_mode: TLL, PHY */
183 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
184
185 void __iomem *uhh_base;
186 void __iomem *tll_base;
187 void __iomem *ehci_base;
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200188
189 /* Regulators for USB PHYs.
Anand Gadiyara8cd4562010-05-10 14:51:19 +0530190 * Each PHY can have a separate regulator.
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200191 */
192 struct regulator *regulator[OMAP3_HS_USB_PORTS];
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300193};
194
195/*-------------------------------------------------------------------------*/
196
Keshava Munegowdac0726042010-11-21 23:23:40 +0530197static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask,
198 u8 tll_channel_count)
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300199{
200 unsigned reg;
201 int i;
202
203 /* Program the 3 TLL channels upfront */
Keshava Munegowdac0726042010-11-21 23:23:40 +0530204 for (i = 0; i < tll_channel_count; i++) {
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300205 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
206
207 /* Disable AutoIdle, BitStuffing and use SDR Mode */
208 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
209 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
210 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
211 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
212 }
213
214 /* Program Common TLL register */
215 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
216 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
217 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
218 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
219 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
220
221 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
222
223 /* Enable channels now */
Keshava Munegowdac0726042010-11-21 23:23:40 +0530224 for (i = 0; i < tll_channel_count; i++) {
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300225 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
226
227 /* Enable only the reg that is needed */
228 if (!(tll_channel_mask & 1<<i))
229 continue;
230
231 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
232 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
233
234 ehci_omap_writeb(omap->tll_base,
235 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
236 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
237 i+1, ehci_omap_readb(omap->tll_base,
238 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
239 }
240}
241
242/*-------------------------------------------------------------------------*/
243
Ajay Kumar Gupta5aa4af22010-07-08 14:03:02 +0530244static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
245{
246 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
247 unsigned reg = 0;
248
249 reg = ULPI_FUNC_CTRL_RESET
250 /* FUNCTION_CTRL_SET register */
251 | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
252 /* Write */
253 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
254 /* PORTn */
255 | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
256 /* start ULPI access*/
257 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
258
259 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg);
260
261 /* Wait for ULPI access completion */
262 while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI)
263 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
264 cpu_relax();
265
266 if (time_after(jiffies, timeout)) {
267 dev_dbg(omap->dev, "phy reset operation timed out\n");
268 break;
269 }
270 }
271}
272
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300273/* omap_start_ehc
274 * - Start the TI USBHOST controller
275 */
276static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
277{
278 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
279 u8 tll_ch_mask = 0;
280 unsigned reg = 0;
281 int ret = 0;
282
283 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
284
285 /* Enable Clocks for USBHOST */
286 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
287 if (IS_ERR(omap->usbhost_ick)) {
288 ret = PTR_ERR(omap->usbhost_ick);
289 goto err_host_ick;
290 }
291 clk_enable(omap->usbhost_ick);
292
Anand Gadiyarc5dff552010-11-21 23:23:41 +0530293 omap->usbhost_hs_fck = clk_get(omap->dev, "hs_fck");
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530294 if (IS_ERR(omap->usbhost_hs_fck)) {
295 ret = PTR_ERR(omap->usbhost_hs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300296 goto err_host_120m_fck;
297 }
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530298 clk_enable(omap->usbhost_hs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300299
Anand Gadiyarc5dff552010-11-21 23:23:41 +0530300 omap->usbhost_fs_fck = clk_get(omap->dev, "fs_fck");
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530301 if (IS_ERR(omap->usbhost_fs_fck)) {
302 ret = PTR_ERR(omap->usbhost_fs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300303 goto err_host_48m_fck;
304 }
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530305 clk_enable(omap->usbhost_fs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300306
307 if (omap->phy_reset) {
308 /* Refer: ISSUE1 */
309 if (gpio_is_valid(omap->reset_gpio_port[0])) {
310 gpio_request(omap->reset_gpio_port[0],
311 "USB1 PHY reset");
312 gpio_direction_output(omap->reset_gpio_port[0], 0);
313 }
314
315 if (gpio_is_valid(omap->reset_gpio_port[1])) {
316 gpio_request(omap->reset_gpio_port[1],
317 "USB2 PHY reset");
318 gpio_direction_output(omap->reset_gpio_port[1], 0);
319 }
320
321 /* Hold the PHY in RESET for enough time till DIR is high */
322 udelay(10);
323 }
324
325 /* Configure TLL for 60Mhz clk for ULPI */
326 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
327 if (IS_ERR(omap->usbtll_fck)) {
328 ret = PTR_ERR(omap->usbtll_fck);
329 goto err_tll_fck;
330 }
331 clk_enable(omap->usbtll_fck);
332
333 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
334 if (IS_ERR(omap->usbtll_ick)) {
335 ret = PTR_ERR(omap->usbtll_ick);
336 goto err_tll_ick;
337 }
338 clk_enable(omap->usbtll_ick);
339
340 /* perform TLL soft reset, and wait until reset is complete */
341 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
342 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
343
344 /* Wait for TLL reset to complete */
345 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
346 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
347 cpu_relax();
348
349 if (time_after(jiffies, timeout)) {
350 dev_dbg(omap->dev, "operation timed out\n");
351 ret = -EINVAL;
352 goto err_sys_status;
353 }
354 }
355
356 dev_dbg(omap->dev, "TLL RESET DONE\n");
357
358 /* (1<<3) = no idle mode only for initial debugging */
359 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
360 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
361 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
362 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
363
364
365 /* Put UHH in NoIdle/NoStandby mode */
366 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
367 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
368 | OMAP_UHH_SYSCONFIG_SIDLEMODE
369 | OMAP_UHH_SYSCONFIG_CACTIVITY
370 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
371 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
372
373 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
374
375 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
376
377 /* setup ULPI bypass and burst configurations */
378 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
379 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
380 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
381 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
382
383 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
384 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
385 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
386 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
387 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
388 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
389
390 /* Bypass the TLL module for PHY mode operation */
Ajay Kumar Gupta97dc7c62010-05-04 13:15:23 +0530391 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
392 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530393 if (is_ehci_phy_mode(omap->port_mode[0]) ||
394 is_ehci_phy_mode(omap->port_mode[1]) ||
395 is_ehci_phy_mode(omap->port_mode[2]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300396 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
397 else
398 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
399 } else {
400 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530401 if (is_ehci_phy_mode(omap->port_mode[0]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300402 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530403 else if (is_ehci_tll_mode(omap->port_mode[0]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300404 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
405
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530406 if (is_ehci_phy_mode(omap->port_mode[1]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300407 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530408 else if (is_ehci_tll_mode(omap->port_mode[1]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300409 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
410
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530411 if (is_ehci_phy_mode(omap->port_mode[2]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300412 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
Anand Gadiyara42ccdc2010-11-21 23:23:41 +0530413 else if (is_ehci_tll_mode(omap->port_mode[2]))
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300414 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
415
416 }
417 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
418 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
419
420
Anand Gadiyar572538d2010-05-06 20:09:48 +0530421 /*
422 * An undocumented "feature" in the OMAP3 EHCI controller,
423 * causes suspended ports to be taken out of suspend when
424 * the USBCMD.Run/Stop bit is cleared (for example when
425 * we do ehci_bus_suspend).
426 * This breaks suspend-resume if the root-hub is allowed
427 * to suspend. Writing 1 to this undocumented register bit
428 * disables this feature and restores normal behavior.
429 */
430 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04,
431 EHCI_INSNREG04_DISABLE_UNSUSPEND);
432
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300433 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
434 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
435 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
436
437 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
438 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
439 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
440 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
441 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
442 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
443
444 /* Enable UTMI mode for required TLL channels */
Keshava Munegowdac0726042010-11-21 23:23:40 +0530445 omap_usb_utmi_init(omap, tll_ch_mask, OMAP_TLL_CHANNEL_COUNT);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300446 }
447
448 if (omap->phy_reset) {
449 /* Refer ISSUE1:
450 * Hold the PHY in RESET for enough time till
451 * PHY is settled and ready
452 */
453 udelay(10);
454
455 if (gpio_is_valid(omap->reset_gpio_port[0]))
456 gpio_set_value(omap->reset_gpio_port[0], 1);
457
458 if (gpio_is_valid(omap->reset_gpio_port[1]))
459 gpio_set_value(omap->reset_gpio_port[1], 1);
460 }
461
Ajay Kumar Gupta5aa4af22010-07-08 14:03:02 +0530462 /* Soft reset the PHY using PHY reset command over ULPI */
463 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
464 omap_ehci_soft_phy_reset(omap, 0);
465 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
466 omap_ehci_soft_phy_reset(omap, 1);
467
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300468 return 0;
469
470err_sys_status:
471 clk_disable(omap->usbtll_ick);
472 clk_put(omap->usbtll_ick);
473
474err_tll_ick:
475 clk_disable(omap->usbtll_fck);
476 clk_put(omap->usbtll_fck);
477
478err_tll_fck:
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530479 clk_disable(omap->usbhost_fs_fck);
480 clk_put(omap->usbhost_fs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300481
482 if (omap->phy_reset) {
483 if (gpio_is_valid(omap->reset_gpio_port[0]))
484 gpio_free(omap->reset_gpio_port[0]);
485
486 if (gpio_is_valid(omap->reset_gpio_port[1]))
487 gpio_free(omap->reset_gpio_port[1]);
488 }
489
490err_host_48m_fck:
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530491 clk_disable(omap->usbhost_hs_fck);
492 clk_put(omap->usbhost_hs_fck);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300493
494err_host_120m_fck:
495 clk_disable(omap->usbhost_ick);
496 clk_put(omap->usbhost_ick);
497
498err_host_ick:
499 return ret;
500}
501
502static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
503{
504 unsigned long timeout = jiffies + msecs_to_jiffies(100);
505
506 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
507
508 /* Reset OMAP modules for insmod/rmmod to work */
509 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
510 OMAP_UHH_SYSCONFIG_SOFTRESET);
511 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
512 & (1 << 0))) {
513 cpu_relax();
514
515 if (time_after(jiffies, timeout))
516 dev_dbg(omap->dev, "operation timed out\n");
517 }
518
519 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
520 & (1 << 1))) {
521 cpu_relax();
522
523 if (time_after(jiffies, timeout))
524 dev_dbg(omap->dev, "operation timed out\n");
525 }
526
527 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
528 & (1 << 2))) {
529 cpu_relax();
530
531 if (time_after(jiffies, timeout))
532 dev_dbg(omap->dev, "operation timed out\n");
533 }
534
535 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
536
537 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
538 & (1 << 0))) {
539 cpu_relax();
540
541 if (time_after(jiffies, timeout))
542 dev_dbg(omap->dev, "operation timed out\n");
543 }
544
545 if (omap->usbtll_fck != NULL) {
546 clk_disable(omap->usbtll_fck);
547 clk_put(omap->usbtll_fck);
548 omap->usbtll_fck = NULL;
549 }
550
551 if (omap->usbhost_ick != NULL) {
552 clk_disable(omap->usbhost_ick);
553 clk_put(omap->usbhost_ick);
554 omap->usbhost_ick = NULL;
555 }
556
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530557 if (omap->usbhost_fs_fck != NULL) {
558 clk_disable(omap->usbhost_fs_fck);
559 clk_put(omap->usbhost_fs_fck);
560 omap->usbhost_fs_fck = NULL;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300561 }
562
Keshava Munegowda6dba39e2010-11-21 23:23:40 +0530563 if (omap->usbhost_hs_fck != NULL) {
564 clk_disable(omap->usbhost_hs_fck);
565 clk_put(omap->usbhost_hs_fck);
566 omap->usbhost_hs_fck = NULL;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300567 }
568
569 if (omap->usbtll_ick != NULL) {
570 clk_disable(omap->usbtll_ick);
571 clk_put(omap->usbtll_ick);
572 omap->usbtll_ick = NULL;
573 }
574
575 if (omap->phy_reset) {
576 if (gpio_is_valid(omap->reset_gpio_port[0]))
577 gpio_free(omap->reset_gpio_port[0]);
578
579 if (gpio_is_valid(omap->reset_gpio_port[1]))
580 gpio_free(omap->reset_gpio_port[1]);
581 }
582
583 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
584}
585
586/*-------------------------------------------------------------------------*/
587
588static const struct hc_driver ehci_omap_hc_driver;
589
590/* configure so an HC device and id are always provided */
591/* always called with process context; sleeping is OK */
592
593/**
594 * ehci_hcd_omap_probe - initialize TI-based HCDs
595 *
596 * Allocates basic resources for this USB host controller, and
597 * then invokes the start() method for the HCD associated with it
598 * through the hotplug entry's driver_data.
599 */
600static int ehci_hcd_omap_probe(struct platform_device *pdev)
601{
602 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
603 struct ehci_hcd_omap *omap;
604 struct resource *res;
605 struct usb_hcd *hcd;
606
607 int irq = platform_get_irq(pdev, 0);
608 int ret = -ENODEV;
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200609 int i;
610 char supply[7];
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300611
612 if (!pdata) {
613 dev_dbg(&pdev->dev, "missing platform_data\n");
614 goto err_pdata;
615 }
616
617 if (usb_disabled())
618 goto err_disabled;
619
620 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
621 if (!omap) {
622 ret = -ENOMEM;
Julia Lawallb2b60802009-11-21 12:52:17 +0100623 goto err_disabled;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300624 }
625
626 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
627 dev_name(&pdev->dev));
628 if (!hcd) {
629 dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
630 ret = -ENOMEM;
631 goto err_create_hcd;
632 }
633
634 platform_set_drvdata(pdev, omap);
635 omap->dev = &pdev->dev;
636 omap->phy_reset = pdata->phy_reset;
637 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
638 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
639 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
640 omap->port_mode[0] = pdata->port_mode[0];
641 omap->port_mode[1] = pdata->port_mode[1];
642 omap->port_mode[2] = pdata->port_mode[2];
643 omap->ehci = hcd_to_ehci(hcd);
644 omap->ehci->sbrn = 0x20;
645
646 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647
648 hcd->rsrc_start = res->start;
649 hcd->rsrc_len = resource_size(res);
650
651 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
652 if (!hcd->regs) {
653 dev_err(&pdev->dev, "EHCI ioremap failed\n");
654 ret = -ENOMEM;
655 goto err_ioremap;
656 }
657
658 /* we know this is the memory we want, no need to ioremap again */
659 omap->ehci->caps = hcd->regs;
660 omap->ehci_base = hcd->regs;
661
662 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
663 omap->uhh_base = ioremap(res->start, resource_size(res));
664 if (!omap->uhh_base) {
665 dev_err(&pdev->dev, "UHH ioremap failed\n");
666 ret = -ENOMEM;
667 goto err_uhh_ioremap;
668 }
669
670 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
671 omap->tll_base = ioremap(res->start, resource_size(res));
672 if (!omap->tll_base) {
673 dev_err(&pdev->dev, "TLL ioremap failed\n");
674 ret = -ENOMEM;
675 goto err_tll_ioremap;
676 }
677
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200678 /* get ehci regulator and enable */
679 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
680 if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
681 omap->regulator[i] = NULL;
682 continue;
683 }
684 snprintf(supply, sizeof(supply), "hsusb%d", i);
685 omap->regulator[i] = regulator_get(omap->dev, supply);
Ajay Kumar Gupta18f91192010-03-18 16:58:35 +0530686 if (IS_ERR(omap->regulator[i])) {
687 omap->regulator[i] = NULL;
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200688 dev_dbg(&pdev->dev,
689 "failed to get ehci port%d regulator\n", i);
Ajay Kumar Gupta18f91192010-03-18 16:58:35 +0530690 } else {
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200691 regulator_enable(omap->regulator[i]);
Ajay Kumar Gupta18f91192010-03-18 16:58:35 +0530692 }
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200693 }
694
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300695 ret = omap_start_ehc(omap, hcd);
696 if (ret) {
697 dev_dbg(&pdev->dev, "failed to start ehci\n");
698 goto err_start;
699 }
700
701 omap->ehci->regs = hcd->regs
702 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
703
Anand Gadiyarbdb581b2010-02-12 17:54:59 +0530704 dbg_hcs_params(omap->ehci, "reset");
705 dbg_hcc_params(omap->ehci, "reset");
706
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300707 /* cache this readonly data; minimize chip reads */
708 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
709
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300710 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
711 if (ret) {
712 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
713 goto err_add_hcd;
714 }
715
Ajay Kumar Gupta289621c2010-05-04 19:53:09 +0530716 /* root ports should always stay powered */
717 ehci_port_power(omap->ehci, 1);
718
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300719 return 0;
720
721err_add_hcd:
722 omap_stop_ehc(omap, hcd);
723
724err_start:
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200725 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
726 if (omap->regulator[i]) {
727 regulator_disable(omap->regulator[i]);
728 regulator_put(omap->regulator[i]);
729 }
730 }
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300731 iounmap(omap->tll_base);
732
733err_tll_ioremap:
734 iounmap(omap->uhh_base);
735
736err_uhh_ioremap:
737 iounmap(hcd->regs);
738
739err_ioremap:
740 usb_put_hcd(hcd);
741
742err_create_hcd:
Julia Lawallb2b60802009-11-21 12:52:17 +0100743 kfree(omap);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300744err_disabled:
745err_pdata:
746 return ret;
747}
748
749/* may be called without controller electrically present */
750/* may be called with controller, bus, and devices active */
751
752/**
753 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
754 * @pdev: USB Host Controller being removed
755 *
756 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
757 * the HCD's stop() method. It is always called from a thread
758 * context, normally "rmmod", "apmd", or something similar.
759 */
760static int ehci_hcd_omap_remove(struct platform_device *pdev)
761{
762 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
763 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200764 int i;
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300765
766 usb_remove_hcd(hcd);
767 omap_stop_ehc(omap, hcd);
768 iounmap(hcd->regs);
Ajay Kumar Gupta88114262009-12-28 13:40:46 +0200769 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
770 if (omap->regulator[i]) {
771 regulator_disable(omap->regulator[i]);
772 regulator_put(omap->regulator[i]);
773 }
774 }
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300775 iounmap(omap->tll_base);
776 iounmap(omap->uhh_base);
777 usb_put_hcd(hcd);
Ajay Kumar Guptad3ae8562009-12-28 13:40:45 +0200778 kfree(omap);
Felipe Balbi54ab2b02009-10-14 11:44:14 +0300779
780 return 0;
781}
782
783static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
784{
785 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
786 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
787
788 if (hcd->driver->shutdown)
789 hcd->driver->shutdown(hcd);
790}
791
792static struct platform_driver ehci_hcd_omap_driver = {
793 .probe = ehci_hcd_omap_probe,
794 .remove = ehci_hcd_omap_remove,
795 .shutdown = ehci_hcd_omap_shutdown,
796 /*.suspend = ehci_hcd_omap_suspend, */
797 /*.resume = ehci_hcd_omap_resume, */
798 .driver = {
799 .name = "ehci-omap",
800 }
801};
802
803/*-------------------------------------------------------------------------*/
804
805static const struct hc_driver ehci_omap_hc_driver = {
806 .description = hcd_name,
807 .product_desc = "OMAP-EHCI Host Controller",
808 .hcd_priv_size = sizeof(struct ehci_hcd),
809
810 /*
811 * generic hardware linkage
812 */
813 .irq = ehci_irq,
814 .flags = HCD_MEMORY | HCD_USB2,
815
816 /*
817 * basic lifecycle operations
818 */
819 .reset = ehci_init,
820 .start = ehci_run,
821 .stop = ehci_stop,
822 .shutdown = ehci_shutdown,
823
824 /*
825 * managing i/o requests and associated device resources
826 */
827 .urb_enqueue = ehci_urb_enqueue,
828 .urb_dequeue = ehci_urb_dequeue,
829 .endpoint_disable = ehci_endpoint_disable,
830 .endpoint_reset = ehci_endpoint_reset,
831
832 /*
833 * scheduling support
834 */
835 .get_frame_number = ehci_get_frame,
836
837 /*
838 * root hub support
839 */
840 .hub_status_data = ehci_hub_status_data,
841 .hub_control = ehci_hub_control,
842 .bus_suspend = ehci_bus_suspend,
843 .bus_resume = ehci_bus_resume,
844
845 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
846};
847
848MODULE_ALIAS("platform:omap-ehci");
849MODULE_AUTHOR("Texas Instruments, Inc.");
850MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
851