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>
43 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
44 * Use ehci_omap_readl()/ehci_omap_writel() functions
47 /* TLL Register Set */
48 #define OMAP_USBTLL_REVISION (0x00)
49 #define OMAP_USBTLL_SYSCONFIG (0x10)
50 #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
51 #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
52 #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
53 #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
54 #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
56 #define OMAP_USBTLL_SYSSTATUS (0x14)
57 #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
59 #define OMAP_USBTLL_IRQSTATUS (0x18)
60 #define OMAP_USBTLL_IRQENABLE (0x1C)
62 #define OMAP_TLL_SHARED_CONF (0x30)
63 #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
64 #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
65 #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
66 #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
67 #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
69 #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
70 #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
71 #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
72 #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
73 #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
74 #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
76 #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
77 #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
78 #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
79 #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
80 #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
81 #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
82 #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
83 #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
84 #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
86 #define OMAP_TLL_CHANNEL_COUNT 3
87 #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1)
88 #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2)
89 #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4)
91 /* UHH Register Set */
92 #define OMAP_UHH_REVISION (0x00)
93 #define OMAP_UHH_SYSCONFIG (0x10)
94 #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
95 #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
96 #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
97 #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
98 #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
99 #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
101 #define OMAP_UHH_SYSSTATUS (0x14)
102 #define OMAP_UHH_HOSTCONFIG (0x40)
103 #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
104 #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
105 #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
106 #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
107 #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
108 #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
109 #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
110 #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
111 #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
112 #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
113 #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
115 #define OMAP_UHH_DEBUG_CSR (0x44)
117 /* EHCI Register Set */
118 #define EHCI_INSNREG05_ULPI (0xA4)
119 #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
120 #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
121 #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
122 #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
123 #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
124 #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
126 /*-------------------------------------------------------------------------*/
128 static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
130 __raw_writel(val, base + reg);
133 static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
135 return __raw_readl(base + reg);
138 static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
140 __raw_writeb(val, base + reg);
143 static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
145 return __raw_readb(base + reg);
148 /*-------------------------------------------------------------------------*/
150 struct ehci_hcd_omap {
151 struct ehci_hcd *ehci;
154 struct clk *usbhost_ick;
155 struct clk *usbhost2_120m_fck;
156 struct clk *usbhost1_48m_fck;
157 struct clk *usbtll_fck;
158 struct clk *usbtll_ick;
160 /* FIXME the following two workarounds are
161 * board specific not silicon-specific so these
162 * should be moved to board-file instead.
164 * Maybe someone from TI will know better which
165 * board is affected and needs the workarounds
169 /* gpio for resetting phy */
170 int reset_gpio_port[OMAP3_HS_USB_PORTS];
172 /* phy reset workaround */
175 /* desired phy_mode: TLL, PHY */
176 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
178 void __iomem *uhh_base;
179 void __iomem *tll_base;
180 void __iomem *ehci_base;
182 /* Regulators for USB PHYs.
183 * Each PHY can have a seperate regulator.
185 struct regulator *regulator[OMAP3_HS_USB_PORTS];
188 /*-------------------------------------------------------------------------*/
190 static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
195 /* Program the 3 TLL channels upfront */
196 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
197 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
199 /* Disable AutoIdle, BitStuffing and use SDR Mode */
200 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
201 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
202 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
203 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
206 /* Program Common TLL register */
207 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
208 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
209 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
210 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
211 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
213 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
215 /* Enable channels now */
216 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
217 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
219 /* Enable only the reg that is needed */
220 if (!(tll_channel_mask & 1<<i))
223 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
224 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
226 ehci_omap_writeb(omap->tll_base,
227 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
228 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
229 i+1, ehci_omap_readb(omap->tll_base,
230 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
234 /*-------------------------------------------------------------------------*/
237 * - Start the TI USBHOST controller
239 static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
241 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
246 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
248 /* Enable Clocks for USBHOST */
249 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
250 if (IS_ERR(omap->usbhost_ick)) {
251 ret = PTR_ERR(omap->usbhost_ick);
254 clk_enable(omap->usbhost_ick);
256 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
257 if (IS_ERR(omap->usbhost2_120m_fck)) {
258 ret = PTR_ERR(omap->usbhost2_120m_fck);
259 goto err_host_120m_fck;
261 clk_enable(omap->usbhost2_120m_fck);
263 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
264 if (IS_ERR(omap->usbhost1_48m_fck)) {
265 ret = PTR_ERR(omap->usbhost1_48m_fck);
266 goto err_host_48m_fck;
268 clk_enable(omap->usbhost1_48m_fck);
270 if (omap->phy_reset) {
272 if (gpio_is_valid(omap->reset_gpio_port[0])) {
273 gpio_request(omap->reset_gpio_port[0],
275 gpio_direction_output(omap->reset_gpio_port[0], 0);
278 if (gpio_is_valid(omap->reset_gpio_port[1])) {
279 gpio_request(omap->reset_gpio_port[1],
281 gpio_direction_output(omap->reset_gpio_port[1], 0);
284 /* Hold the PHY in RESET for enough time till DIR is high */
288 /* Configure TLL for 60Mhz clk for ULPI */
289 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
290 if (IS_ERR(omap->usbtll_fck)) {
291 ret = PTR_ERR(omap->usbtll_fck);
294 clk_enable(omap->usbtll_fck);
296 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
297 if (IS_ERR(omap->usbtll_ick)) {
298 ret = PTR_ERR(omap->usbtll_ick);
301 clk_enable(omap->usbtll_ick);
303 /* perform TLL soft reset, and wait until reset is complete */
304 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
305 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
307 /* Wait for TLL reset to complete */
308 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
309 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
312 if (time_after(jiffies, timeout)) {
313 dev_dbg(omap->dev, "operation timed out\n");
319 dev_dbg(omap->dev, "TLL RESET DONE\n");
321 /* (1<<3) = no idle mode only for initial debugging */
322 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
323 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
324 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
325 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
328 /* Put UHH in NoIdle/NoStandby mode */
329 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
330 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
331 | OMAP_UHH_SYSCONFIG_SIDLEMODE
332 | OMAP_UHH_SYSCONFIG_CACTIVITY
333 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
334 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
336 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
338 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
340 /* setup ULPI bypass and burst configurations */
341 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
342 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
343 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
344 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
346 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
347 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
348 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
349 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
350 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
351 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
353 /* Bypass the TLL module for PHY mode operation */
354 if (omap_rev() <= OMAP3430_REV_ES2_1) {
355 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1 \n");
356 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
357 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
358 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
359 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
361 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
363 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
364 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
365 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
366 else if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
367 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
369 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
370 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
371 else if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
372 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
374 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)
375 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
376 else if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
377 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
380 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
381 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
384 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
385 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
386 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
388 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
389 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
390 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
391 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
392 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
393 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
395 /* Enable UTMI mode for required TLL channels */
396 omap_usb_utmi_init(omap, tll_ch_mask);
399 if (omap->phy_reset) {
401 * Hold the PHY in RESET for enough time till
402 * PHY is settled and ready
406 if (gpio_is_valid(omap->reset_gpio_port[0]))
407 gpio_set_value(omap->reset_gpio_port[0], 1);
409 if (gpio_is_valid(omap->reset_gpio_port[1]))
410 gpio_set_value(omap->reset_gpio_port[1], 1);
416 clk_disable(omap->usbtll_ick);
417 clk_put(omap->usbtll_ick);
420 clk_disable(omap->usbtll_fck);
421 clk_put(omap->usbtll_fck);
424 clk_disable(omap->usbhost1_48m_fck);
425 clk_put(omap->usbhost1_48m_fck);
427 if (omap->phy_reset) {
428 if (gpio_is_valid(omap->reset_gpio_port[0]))
429 gpio_free(omap->reset_gpio_port[0]);
431 if (gpio_is_valid(omap->reset_gpio_port[1]))
432 gpio_free(omap->reset_gpio_port[1]);
436 clk_disable(omap->usbhost2_120m_fck);
437 clk_put(omap->usbhost2_120m_fck);
440 clk_disable(omap->usbhost_ick);
441 clk_put(omap->usbhost_ick);
447 static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
449 unsigned long timeout = jiffies + msecs_to_jiffies(100);
451 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
453 /* Reset OMAP modules for insmod/rmmod to work */
454 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
455 OMAP_UHH_SYSCONFIG_SOFTRESET);
456 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
460 if (time_after(jiffies, timeout))
461 dev_dbg(omap->dev, "operation timed out\n");
464 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
468 if (time_after(jiffies, timeout))
469 dev_dbg(omap->dev, "operation timed out\n");
472 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
476 if (time_after(jiffies, timeout))
477 dev_dbg(omap->dev, "operation timed out\n");
480 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
482 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
486 if (time_after(jiffies, timeout))
487 dev_dbg(omap->dev, "operation timed out\n");
490 if (omap->usbtll_fck != NULL) {
491 clk_disable(omap->usbtll_fck);
492 clk_put(omap->usbtll_fck);
493 omap->usbtll_fck = NULL;
496 if (omap->usbhost_ick != NULL) {
497 clk_disable(omap->usbhost_ick);
498 clk_put(omap->usbhost_ick);
499 omap->usbhost_ick = NULL;
502 if (omap->usbhost1_48m_fck != NULL) {
503 clk_disable(omap->usbhost1_48m_fck);
504 clk_put(omap->usbhost1_48m_fck);
505 omap->usbhost1_48m_fck = NULL;
508 if (omap->usbhost2_120m_fck != NULL) {
509 clk_disable(omap->usbhost2_120m_fck);
510 clk_put(omap->usbhost2_120m_fck);
511 omap->usbhost2_120m_fck = NULL;
514 if (omap->usbtll_ick != NULL) {
515 clk_disable(omap->usbtll_ick);
516 clk_put(omap->usbtll_ick);
517 omap->usbtll_ick = NULL;
520 if (omap->phy_reset) {
521 if (gpio_is_valid(omap->reset_gpio_port[0]))
522 gpio_free(omap->reset_gpio_port[0]);
524 if (gpio_is_valid(omap->reset_gpio_port[1]))
525 gpio_free(omap->reset_gpio_port[1]);
528 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
531 /*-------------------------------------------------------------------------*/
533 static const struct hc_driver ehci_omap_hc_driver;
535 /* configure so an HC device and id are always provided */
536 /* always called with process context; sleeping is OK */
539 * ehci_hcd_omap_probe - initialize TI-based HCDs
541 * Allocates basic resources for this USB host controller, and
542 * then invokes the start() method for the HCD associated with it
543 * through the hotplug entry's driver_data.
545 static int ehci_hcd_omap_probe(struct platform_device *pdev)
547 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
548 struct ehci_hcd_omap *omap;
549 struct resource *res;
552 int irq = platform_get_irq(pdev, 0);
558 dev_dbg(&pdev->dev, "missing platform_data\n");
565 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
571 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
572 dev_name(&pdev->dev));
574 dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
579 platform_set_drvdata(pdev, omap);
580 omap->dev = &pdev->dev;
581 omap->phy_reset = pdata->phy_reset;
582 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
583 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
584 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
585 omap->port_mode[0] = pdata->port_mode[0];
586 omap->port_mode[1] = pdata->port_mode[1];
587 omap->port_mode[2] = pdata->port_mode[2];
588 omap->ehci = hcd_to_ehci(hcd);
589 omap->ehci->sbrn = 0x20;
591 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
593 hcd->rsrc_start = res->start;
594 hcd->rsrc_len = resource_size(res);
596 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
598 dev_err(&pdev->dev, "EHCI ioremap failed\n");
603 /* we know this is the memory we want, no need to ioremap again */
604 omap->ehci->caps = hcd->regs;
605 omap->ehci_base = hcd->regs;
607 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
608 omap->uhh_base = ioremap(res->start, resource_size(res));
609 if (!omap->uhh_base) {
610 dev_err(&pdev->dev, "UHH ioremap failed\n");
612 goto err_uhh_ioremap;
615 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
616 omap->tll_base = ioremap(res->start, resource_size(res));
617 if (!omap->tll_base) {
618 dev_err(&pdev->dev, "TLL ioremap failed\n");
620 goto err_tll_ioremap;
623 /* get ehci regulator and enable */
624 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
625 if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
626 omap->regulator[i] = NULL;
629 snprintf(supply, sizeof(supply), "hsusb%d", i);
630 omap->regulator[i] = regulator_get(omap->dev, supply);
631 if (IS_ERR(omap->regulator[i]))
633 "failed to get ehci port%d regulator\n", i);
635 regulator_enable(omap->regulator[i]);
638 ret = omap_start_ehc(omap, hcd);
640 dev_dbg(&pdev->dev, "failed to start ehci\n");
644 omap->ehci->regs = hcd->regs
645 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
647 dbg_hcs_params(omap->ehci, "reset");
648 dbg_hcc_params(omap->ehci, "reset");
650 /* cache this readonly data; minimize chip reads */
651 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
653 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
655 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
662 omap_stop_ehc(omap, hcd);
665 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
666 if (omap->regulator[i]) {
667 regulator_disable(omap->regulator[i]);
668 regulator_put(omap->regulator[i]);
671 iounmap(omap->tll_base);
674 iounmap(omap->uhh_base);
689 /* may be called without controller electrically present */
690 /* may be called with controller, bus, and devices active */
693 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
694 * @pdev: USB Host Controller being removed
696 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
697 * the HCD's stop() method. It is always called from a thread
698 * context, normally "rmmod", "apmd", or something similar.
700 static int ehci_hcd_omap_remove(struct platform_device *pdev)
702 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
703 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
707 omap_stop_ehc(omap, hcd);
709 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
710 if (omap->regulator[i]) {
711 regulator_disable(omap->regulator[i]);
712 regulator_put(omap->regulator[i]);
715 iounmap(omap->tll_base);
716 iounmap(omap->uhh_base);
723 static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
725 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
726 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
728 if (hcd->driver->shutdown)
729 hcd->driver->shutdown(hcd);
732 static struct platform_driver ehci_hcd_omap_driver = {
733 .probe = ehci_hcd_omap_probe,
734 .remove = ehci_hcd_omap_remove,
735 .shutdown = ehci_hcd_omap_shutdown,
736 /*.suspend = ehci_hcd_omap_suspend, */
737 /*.resume = ehci_hcd_omap_resume, */
743 /*-------------------------------------------------------------------------*/
745 static const struct hc_driver ehci_omap_hc_driver = {
746 .description = hcd_name,
747 .product_desc = "OMAP-EHCI Host Controller",
748 .hcd_priv_size = sizeof(struct ehci_hcd),
751 * generic hardware linkage
754 .flags = HCD_MEMORY | HCD_USB2,
757 * basic lifecycle operations
762 .shutdown = ehci_shutdown,
765 * managing i/o requests and associated device resources
767 .urb_enqueue = ehci_urb_enqueue,
768 .urb_dequeue = ehci_urb_dequeue,
769 .endpoint_disable = ehci_endpoint_disable,
770 .endpoint_reset = ehci_endpoint_reset,
775 .get_frame_number = ehci_get_frame,
780 .hub_status_data = ehci_hub_status_data,
781 .hub_control = ehci_hub_control,
782 .bus_suspend = ehci_bus_suspend,
783 .bus_resume = ehci_bus_resume,
785 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
788 MODULE_ALIAS("platform:omap-ehci");
789 MODULE_AUTHOR("Texas Instruments, Inc.");
790 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");