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 * Copyright (C) 2007-2008 Vikram Pandita <vikram.pandita@ti.com>
9 * Based on "ehci-fsl.c" by David Brownell and
10 * "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <asm/arch/gpio.h>
32 #include "ehci-omap.h"
35 #ifdef CONFIG_OMAP_EHCI_PHY_MODE
36 /* EHCI connected to External PHY */
38 /* External USB connectivity board: 750-2083-001
39 * Connected to OMAP3430 SDP
40 * The board has Port1 and Port2 connected to ISP1504 in 12-pin ULPI mode
44 * ISP1504 for input clocking mode needs special reset handling
45 * Hold the PHY in reset by asserting RESET_N signal
46 * Then start the 60Mhz clock input to PHY
47 * Release the reset after a delay -
48 * to get the PHY state machine in working state
50 #define EXTERNAL_PHY_RESET
51 #define EXT_PHY_RESET_GPIO_PORT1 (57)
52 #define EXT_PHY_RESET_GPIO_PORT2 (61)
53 #define EXT_PHY_RESET_DELAY (10)
56 * USBHOST supports External charge pump PHYs only
57 * Use the VBUS from Port1 to power VBUS of Port2 externally
58 * So use Port2 as the working ULPI port
60 #define VBUS_INTERNAL_CHARGEPUMP_HACK
62 #endif /* CONFIG_OMAP_EHCI_PHY_MODE */
64 /*-------------------------------------------------------------------------*/
66 /* Define USBHOST clocks for clock management */
67 struct ehci_omap_clock_defs {
68 struct clk *usbhost_ick_clk;
69 struct clk *usbhost2_120m_fck_clk;
70 struct clk *usbhost1_48m_fck_clk;
71 struct clk *usbtll_fck_clk;
72 struct clk *usbtll_ick_clk;
75 /* Clock names as per clock framework: May change so keep as #defs */
76 #define USBHOST_ICKL "usbhost_l4_ick"
77 #define USBHOST_120M_FCLK "usbhost_120m_fck"
78 #define USBHOST_48M_FCLK "usbhost_48m_fck"
79 #define USBHOST_TLL_ICKL "usbtll_ick"
80 #define USBHOST_TLL_FCLK "usbtll_fck"
81 /*-------------------------------------------------------------------------*/
84 #ifndef CONFIG_OMAP_EHCI_PHY_MODE
86 static void omap_usb_utmi_init(struct usb_hcd *hcd, u8 tll_channel_mask)
90 /* Use UTMI Ports of TLL */
91 omap_writel((1 << OMAP_UHH_HOSTCONFIG_ULPI_BYPASS_SHIFT),
93 /* Enusre bit is set */
94 while (!(omap_readl(OMAP_UHH_HOSTCONFIG) &
95 (1 << OMAP_UHH_HOSTCONFIG_ULPI_BYPASS_SHIFT)));
97 dev_dbg(hcd->self.controller, "\nEntered UTMI MODE: success\n");
99 /* Program the 3 TLL channels upfront */
101 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
103 /* Disable AutoIdle */
104 omap_writel(omap_readl(OMAP_TLL_CHANNEL_CONF(i)) &
105 ~(1<<OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE_SHIFT),
106 OMAP_TLL_CHANNEL_CONF(i));
107 /* Disable BitStuffing */
108 omap_writel(omap_readl(OMAP_TLL_CHANNEL_CONF(i)) &
109 ~(1<<OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF_SHIFT),
110 OMAP_TLL_CHANNEL_CONF(i));
112 omap_writel(omap_readl(OMAP_TLL_CHANNEL_CONF(i)) &
113 ~(1<<OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE_SHIFT),
114 OMAP_TLL_CHANNEL_CONF(i));
118 /* Program Common TLL register */
119 omap_writel((1 << OMAP_TLL_SHARED_CONF_FCLK_IS_ON_SHIFT) |
120 (1 << OMAP_TLL_SHARED_CONF_USB_DIVRATION_SHIFT) |
121 (0 << OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN_SHIFT) |
122 (0 << OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN_SHFT),
123 OMAP_TLL_SHARED_CONF);
125 /* Enable channels now */
126 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
128 /* Enable only the channel that is needed */
129 if (!(tll_channel_mask & 1<<i))
132 omap_writel(omap_readl(OMAP_TLL_CHANNEL_CONF(i)) |
133 (1<<OMAP_TLL_CHANNEL_CONF_CHANEN_SHIFT),
134 OMAP_TLL_CHANNEL_CONF(i));
136 omap_writeb(0xBE, OMAP_TLL_ULPI_SCRATCH_REGISTER(i));
137 dev_dbg(hcd->self.controller, "\nULPI_SCRATCH_REG[ch=%d]"
139 i+1, omap_readb(OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
144 # define omap_usb_utmi_init(x, y) 0
149 * - Start the TI USBHOST controller
151 static int omap_start_ehc(struct platform_device *dev, struct usb_hcd *hcd)
153 struct ehci_omap_clock_defs *ehci_clocks;
155 dev_dbg(hcd->self.controller, ": starting TI EHCI USB Controller\n");
157 ehci_clocks = (struct ehci_omap_clock_defs *)(
158 ((char *)hcd_to_ehci(hcd)) +
159 sizeof(struct ehci_hcd));
161 /* Start DPLL5 Programming:
162 * Clock Framework is not doing this now:
163 * This will be done in clock framework later
165 /* Enable DPLL 5 : Based on Input of 13Mhz*/
166 cm_write_mod_reg((12 << OMAP3430ES2_PERIPH2_DPLL_DIV_SHIFT)|
167 (120 << OMAP3430ES2_PERIPH2_DPLL_MULT_SHIFT),
168 PLL_MOD, OMAP3430ES2_CM_CLKSEL4);
170 cm_write_mod_reg(1 << OMAP3430ES2_DIV_120M_SHIFT,
171 PLL_MOD, OMAP3430ES2_CM_CLKSEL5);
173 cm_write_mod_reg((7 << OMAP3430ES2_PERIPH2_DPLL_FREQSEL_SHIFT) |
174 (7 << OMAP3430ES2_EN_PERIPH2_DPLL_SHIFT),
175 PLL_MOD, OMAP3430ES2_CM_CLKEN2);
177 while (!(cm_read_mod_reg(PLL_MOD, CM_IDLEST2) &
178 OMAP3430_ST_PERIPH2_CLK))
179 dev_dbg(hcd->self.controller,
181 cm_read_mod_reg(PLL_MOD, CM_IDLEST2));
182 /* End DPLL5 programming */
185 /* PRCM settings for USBHOST:
186 * Interface clk un-related to domain transition
188 cm_write_mod_reg(0 << OMAP3430ES2_AUTO_USBHOST_SHIFT,
189 OMAP3430ES2_USBHOST_MOD, CM_AUTOIDLE);
191 /* Disable sleep dependency with MPU and IVA */
192 cm_write_mod_reg((0 << OMAP3430ES2_EN_MPU_SHIFT) |
193 (0 << OMAP3430ES2_EN_IVA2_SHIFT),
194 OMAP3430ES2_USBHOST_MOD, OMAP3430_CM_SLEEPDEP);
196 /* Disable Automatic transition of clock */
197 cm_write_mod_reg(0 << OMAP3430ES2_CLKTRCTRL_USBHOST_SHIFT,
198 OMAP3430ES2_USBHOST_MOD, CM_CLKSTCTRL);
200 /* Enable Clocks for USBHOST */
201 ehci_clocks->usbhost_ick_clk = clk_get(&dev->dev,
203 if (IS_ERR(ehci_clocks->usbhost_ick_clk))
204 return PTR_ERR(ehci_clocks->usbhost_ick_clk);
205 clk_enable(ehci_clocks->usbhost_ick_clk);
208 ehci_clocks->usbhost2_120m_fck_clk = clk_get(&dev->dev,
210 if (IS_ERR(ehci_clocks->usbhost2_120m_fck_clk))
211 return PTR_ERR(ehci_clocks->usbhost2_120m_fck_clk);
212 clk_enable(ehci_clocks->usbhost2_120m_fck_clk);
214 ehci_clocks->usbhost1_48m_fck_clk = clk_get(&dev->dev,
216 if (IS_ERR(ehci_clocks->usbhost1_48m_fck_clk))
217 return PTR_ERR(ehci_clocks->usbhost1_48m_fck_clk);
218 clk_enable(ehci_clocks->usbhost1_48m_fck_clk);
221 #ifdef EXTERNAL_PHY_RESET
223 omap_request_gpio(EXT_PHY_RESET_GPIO_PORT1);
224 omap_set_gpio_direction(EXT_PHY_RESET_GPIO_PORT1, 0);
225 omap_request_gpio(EXT_PHY_RESET_GPIO_PORT2);
226 omap_set_gpio_direction(EXT_PHY_RESET_GPIO_PORT2, 0);
227 omap_set_gpio_dataout(EXT_PHY_RESET_GPIO_PORT1, 0);
228 omap_set_gpio_dataout(EXT_PHY_RESET_GPIO_PORT2, 0);
229 /* Hold the PHY in RESET for enough time till DIR is high */
230 udelay(EXT_PHY_RESET_DELAY);
233 /* Configure TLL for 60Mhz clk for ULPI */
234 ehci_clocks->usbtll_fck_clk = clk_get(&dev->dev, USBHOST_TLL_FCLK);
235 if (IS_ERR(ehci_clocks->usbtll_fck_clk))
236 return PTR_ERR(ehci_clocks->usbtll_fck_clk);
237 clk_enable(ehci_clocks->usbtll_fck_clk);
239 ehci_clocks->usbtll_ick_clk = clk_get(&dev->dev, USBHOST_TLL_ICKL);
240 if (IS_ERR(ehci_clocks->usbtll_ick_clk))
241 return PTR_ERR(ehci_clocks->usbtll_ick_clk);
242 clk_enable(ehci_clocks->usbtll_ick_clk);
244 /* Disable Auto Idle of USBTLL */
245 cm_write_mod_reg((0 << OMAP3430_AUTO_USBTLL_SHIFT),
246 CORE_MOD, OMAP3430_CM_AUTOIDLE3_CORE);
248 /* Wait for TLL to be Active */
249 while ((cm_read_mod_reg(CORE_MOD, OMAP3430_CM_IDLEST3_CORE) &
250 (1 << OMAP3430_ST_USBTLL_SHIFT)));
252 /* perform TLL soft reset, and wait until reset is complete */
253 omap_writel(1 << OMAP_USBTLL_SYSCONFIG_SOFTRESET_SHIFT,
254 OMAP_USBTLL_SYSCONFIG);
255 /* Wait for TLL reset to complete */
256 while (!(omap_readl(OMAP_USBTLL_SYSSTATUS) &
257 (1 << OMAP_USBTLL_SYSSTATUS_RESETDONE_SHIFT)));
259 dev_dbg(hcd->self.controller, "\n TLL RESET DONE\n");
261 /* (1<<3) = no idle mode only for initial debugging */
262 omap_writel((1 << OMAP_USBTLL_SYSCONFIG_ENAWAKEUP_SHIFT) |
263 (1 << OMAP_USBTLL_SYSCONFIG_SIDLEMODE_SHIFT) |
264 (1 << OMAP_USBTLL_SYSCONFIG_CACTIVITY_SHIFT),
265 OMAP_USBTLL_SYSCONFIG);
268 /* Put UHH in NoIdle/NoStandby mode */
269 omap_writel((0 << OMAP_UHH_SYSCONFIG_AUTOIDLE_SHIFT) |
270 (1 << OMAP_UHH_SYSCONFIG_ENAWAKEUP_SHIFT) |
271 (1 << OMAP_UHH_SYSCONFIG_SIDLEMODE_SHIFT) |
272 (1 << OMAP_UHH_SYSCONFIG_CACTIVITY_SHIFT) |
273 (1 << OMAP_UHH_SYSCONFIG_MIDLEMODE_SHIFT),
276 #ifdef CONFIG_OMAP_EHCI_PHY_MODE
277 /* Bypass the TLL module for PHY mode operation */
278 omap_writel((0 << OMAP_UHH_HOSTCONFIG_ULPI_BYPASS_SHIFT),
279 OMAP_UHH_HOSTCONFIG);
280 /* Ensure that BYPASS is set */
281 while (omap_readl(OMAP_UHH_HOSTCONFIG) &
282 (1 << OMAP_UHH_HOSTCONFIG_ULPI_BYPASS_SHIFT));
284 dev_dbg(hcd->self.controller, "Entered ULPI PHY MODE: success");
287 /* Enable UTMI mode for all 3 TLL channels */
288 omap_usb_utmi_init(hcd,
289 OMAP_TLL_CHANNEL_1_EN_MASK |
290 OMAP_TLL_CHANNEL_2_EN_MASK |
291 OMAP_TLL_CHANNEL_3_EN_MASK
295 #ifdef EXTERNAL_PHY_RESET
297 * Hold the PHY in RESET for enough time till PHY is settled and ready
299 udelay(EXT_PHY_RESET_DELAY);
300 omap_set_gpio_dataout(EXT_PHY_RESET_GPIO_PORT1, 1);
301 omap_set_gpio_dataout(EXT_PHY_RESET_GPIO_PORT2, 1);
304 #ifdef VBUS_INTERNAL_CHARGEPUMP_HACK
305 /* Refer ISSUE2: LINK assumes external charge pump */
307 /* use Port1 VBUS to charge externally Port2:
308 * So for PHY mode operation use Port2 only
310 omap_writel((0xA << EHCI_INSNREG05_ULPI_REGADD_SHIFT) |/* OTG ctrl reg*/
311 (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) |/* Write */
312 (1 << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) |/* Port1 */
313 (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT) |/* Start */
315 EHCI_INSNREG05_ULPI);
317 while (!(omap_readl(EHCI_INSNREG05_ULPI) &
318 (1<<EHCI_INSNREG05_ULPI_CONTROL_SHIFT)));
325 /*-------------------------------------------------------------------------*/
327 static void omap_stop_ehc(struct platform_device *dev, struct usb_hcd *hcd)
329 struct ehci_omap_clock_defs *ehci_clocks;
331 ehci_clocks = (struct ehci_omap_clock_defs *)
332 (((char *)hcd_to_ehci(hcd)) + sizeof(struct ehci_hcd));
334 dev_dbg(hcd->self.controller, ": stopping TI EHCI USB Controller\n");
336 /* Reset OMAP modules for insmod/rmmod to work */
337 omap_writel((1<<1), OMAP_UHH_SYSCONFIG);
338 while (!(omap_readl(OMAP_UHH_SYSSTATUS) & (1<<0)));
339 while (!(omap_readl(OMAP_UHH_SYSSTATUS) & (1<<1)));
340 while (!(omap_readl(OMAP_UHH_SYSSTATUS) & (1<<2)));
341 dev_dbg(hcd->self.controller,
342 "UHH RESET DONE OMAP_UHH_SYSSTATUS %x !!\n",
343 omap_readl(OMAP_UHH_SYSSTATUS));
345 omap_writel((1<<1), OMAP_USBTLL_SYSCONFIG);
346 while (!(omap_readl(OMAP_USBTLL_SYSSTATUS) & (1<<0)));
347 dev_dbg(hcd->self.controller, ":TLL RESEET DONE");
349 if (ehci_clocks->usbtll_fck_clk != NULL) {
350 clk_disable(ehci_clocks->usbtll_fck_clk);
351 clk_put(ehci_clocks->usbtll_fck_clk);
352 ehci_clocks->usbtll_fck_clk = NULL;
355 if (ehci_clocks->usbhost_ick_clk != NULL) {
356 clk_disable(ehci_clocks->usbhost_ick_clk);
357 clk_put(ehci_clocks->usbhost_ick_clk);
358 ehci_clocks->usbhost_ick_clk = NULL;
361 if (ehci_clocks->usbhost1_48m_fck_clk != NULL) {
362 clk_disable(ehci_clocks->usbhost1_48m_fck_clk);
363 clk_put(ehci_clocks->usbhost1_48m_fck_clk);
364 ehci_clocks->usbhost1_48m_fck_clk = NULL;
367 if (ehci_clocks->usbhost2_120m_fck_clk != NULL) {
368 clk_disable(ehci_clocks->usbhost2_120m_fck_clk);
369 clk_put(ehci_clocks->usbhost2_120m_fck_clk);
370 ehci_clocks->usbhost2_120m_fck_clk = NULL;
373 if (ehci_clocks->usbtll_ick_clk != NULL) {
374 clk_disable(ehci_clocks->usbtll_ick_clk);
375 clk_put(ehci_clocks->usbtll_ick_clk);
376 ehci_clocks->usbtll_ick_clk = NULL;
380 #ifdef EXTERNAL_PHY_RESET
381 omap_free_gpio(EXT_PHY_RESET_GPIO_PORT1);
382 omap_free_gpio(EXT_PHY_RESET_GPIO_PORT2);
385 dev_dbg(hcd->self.controller,
386 ": Clock to USB host has been disabled\n");
389 static const struct hc_driver ehci_omap_hc_driver;
391 /*-------------------------------------------------------------------------*/
392 /* configure so an HC device and id are always provided */
393 /* always called with process context; sleeping is OK */
396 * ehci_hcd_omap_drv_probe - initialize TI-based HCDs
397 * Context: !in_interrupt()
399 * Allocates basic resources for this USB host controller, and
400 * then invokes the start() method for the HCD associated with it
401 * through the hotplug entry's driver_data.
404 static int ehci_hcd_omap_drv_probe(struct platform_device *dev)
408 struct ehci_hcd *ehci;
410 dev_dbg(&dev->dev, "ehci_hcd_omap_drv_probe()");
415 if (dev->resource[1].flags != IORESOURCE_IRQ) {
416 dev_dbg(&dev->dev, "resource[1] is not IORESOURCE_IRQ");
420 hcd = usb_create_hcd(&ehci_omap_hc_driver, &dev->dev, dev->dev.bus_id);
424 retval = omap_start_ehc(dev, hcd);
430 hcd->rsrc_start = dev->resource[0].start;
431 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
433 hcd->regs = (void __iomem *) (int) IO_ADDRESS(hcd->rsrc_start);
435 ehci = hcd_to_ehci(hcd);
436 ehci->caps = hcd->regs;
438 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
439 /* cache this readonly data; minimize chip reads */
440 ehci->hcs_params = readl(&ehci->caps->hcs_params);
442 /* SET 1 micro-frame Interrupt interval */
443 writel(readl(&ehci->regs->command) | (1<<16), &ehci->regs->command);
445 retval = usb_add_hcd(hcd, dev->resource[1].start,
446 IRQF_DISABLED | IRQF_SHARED);
450 dev_dbg(hcd->self.controller, "ERR: add_hcd");
451 omap_stop_ehc(dev, hcd);
457 /*-------------------------------------------------------------------------*/
459 /* may be called without controller electrically present */
460 /* may be called with controller, bus, and devices active */
463 * ehci_hcd_omap_drv_remove - shutdown processing for EHCI HCDs
464 * @dev: USB Host Controller being removed
465 * Context: !in_interrupt()
467 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
468 * the HCD's stop() method. It is always called from a thread
469 * context, normally "rmmod", "apmd", or something similar.
472 static int ehci_hcd_omap_drv_remove(struct platform_device *dev)
474 struct usb_hcd *hcd = platform_get_drvdata(dev);
476 dev_dbg(&dev->dev, "ehci_hcd_omap_drv_remove()");
480 omap_stop_ehc(dev, hcd);
485 /*-------------------------------------------------------------------------*/
487 static int omap_ehci_bus_suspend(struct usb_hcd *hcd)
489 return ehci_bus_suspend(hcd);
492 static int omap_ehci_bus_resume(struct usb_hcd *hcd)
494 return ehci_bus_resume(hcd);
497 /*-------------------------------------------------------------------------*/
499 static const struct hc_driver ehci_omap_hc_driver = {
500 .description = hcd_name,
501 .product_desc = "OMAP-EHCI Host Controller",
502 .hcd_priv_size = sizeof(struct ehci_hcd)
503 + sizeof(struct ehci_omap_clock_defs),
506 * generic hardware linkage
509 .flags = HCD_MEMORY | HCD_USB2,
512 * basic lifecycle operations
517 .shutdown = ehci_shutdown,
520 * managing i/o requests and associated device resources
522 .urb_enqueue = ehci_urb_enqueue,
523 .urb_dequeue = ehci_urb_dequeue,
524 .endpoint_disable = ehci_endpoint_disable,
529 .get_frame_number = ehci_get_frame,
534 .hub_status_data = ehci_hub_status_data,
535 .hub_control = ehci_hub_control,
537 .bus_suspend = omap_ehci_bus_suspend,
538 .bus_resume = omap_ehci_bus_resume,
542 /*-------------------------------------------------------------------------*/
543 MODULE_ALIAS("omap-ehci");
544 static struct platform_driver ehci_hcd_omap_driver = {
545 .probe = ehci_hcd_omap_drv_probe,
546 .remove = ehci_hcd_omap_drv_remove,
547 .shutdown = usb_hcd_platform_shutdown,
548 /*.suspend = ehci_hcd_omap_drv_suspend, */
549 /*.resume = ehci_hcd_omap_drv_resume, */
552 .bus = &platform_bus_type