omap: ehci: remove DPLL5 programming
[linux-ginger.git] / drivers / usb / host / ehci-omap.c
blob7efc2f51bf5724dd752215249a9174ff728c011b
1 /*
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 23rd, 2009):
30 * - add kernel-doc
31 * - enable AUTOIDLE
32 * - move DPLL5 programming to clock fw
33 * - add suspend/resume
34 * - move workarounds to board-files
37 #include <linux/platform_device.h>
38 #include <linux/clk.h>
39 #include <linux/gpio.h>
40 #include <mach/usb.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)
112 #define OMAP_UHH_DEBUG_CSR (0x44)
114 /* EHCI Register Set */
115 #define EHCI_INSNREG05_ULPI (0xA4)
116 #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
117 #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
118 #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
119 #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
120 #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
121 #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
123 /*-------------------------------------------------------------------------*/
125 static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
127 __raw_writel(val, base + reg);
130 static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
132 return __raw_readl(base + reg);
135 static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
137 __raw_writeb(val, base + reg);
140 static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
142 return __raw_readb(base + reg);
145 /*-------------------------------------------------------------------------*/
147 struct ehci_hcd_omap {
148 struct ehci_hcd *ehci;
149 struct device *dev;
151 struct clk *usbhost_ick;
152 struct clk *usbhost2_120m_fck;
153 struct clk *usbhost1_48m_fck;
154 struct clk *usbtll_fck;
155 struct clk *usbtll_ick;
157 /* FIXME the following two workarounds are
158 * board specific not silicon-specific so these
159 * should be moved to board-file instead.
161 * Maybe someone from TI will know better which
162 * board is affected and needs the workarounds
163 * to be applied
166 /* gpio for resetting phy */
167 int reset_gpio_port[OMAP3_HS_USB_PORTS];
169 /* phy reset workaround */
170 int phy_reset;
172 /* desired phy_mode: TLL, PHY */
173 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
175 void __iomem *uhh_base;
176 void __iomem *tll_base;
177 void __iomem *ehci_base;
180 /*-------------------------------------------------------------------------*/
182 static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
184 unsigned reg;
185 int i;
187 /* Program the 3 TLL channels upfront */
188 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
189 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
191 /* Disable AutoIdle, BitStuffing and use SDR Mode */
192 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
193 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
194 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
195 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
198 /* Program Common TLL register */
199 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
200 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
201 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
202 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
203 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
205 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
207 /* Enable channels now */
208 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
209 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
211 /* Enable only the reg that is needed */
212 if (!(tll_channel_mask & 1<<i))
213 continue;
215 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
216 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
218 ehci_omap_writeb(omap->tll_base,
219 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
220 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
221 i+1, ehci_omap_readb(omap->tll_base,
222 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
226 /*-------------------------------------------------------------------------*/
228 /* omap_start_ehc
229 * - Start the TI USBHOST controller
231 static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
233 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
234 u8 tll_ch_mask = 0;
235 unsigned reg = 0;
236 int ret = 0;
238 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
240 /* Enable Clocks for USBHOST */
241 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
242 if (IS_ERR(omap->usbhost_ick)) {
243 ret = PTR_ERR(omap->usbhost_ick);
244 goto err_host_ick;
246 clk_enable(omap->usbhost_ick);
248 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
249 if (IS_ERR(omap->usbhost2_120m_fck)) {
250 ret = PTR_ERR(omap->usbhost2_120m_fck);
251 goto err_host_120m_fck;
253 clk_enable(omap->usbhost2_120m_fck);
255 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
256 if (IS_ERR(omap->usbhost1_48m_fck)) {
257 ret = PTR_ERR(omap->usbhost1_48m_fck);
258 goto err_host_48m_fck;
260 clk_enable(omap->usbhost1_48m_fck);
262 if (omap->phy_reset) {
263 /* Refer: ISSUE1 */
264 if (gpio_is_valid(omap->reset_gpio_port[0])) {
265 gpio_request(omap->reset_gpio_port[0],
266 "USB1 PHY reset");
267 gpio_direction_output(omap->reset_gpio_port[0], 0);
270 if (gpio_is_valid(omap->reset_gpio_port[1])) {
271 gpio_request(omap->reset_gpio_port[1],
272 "USB2 PHY reset");
273 gpio_direction_output(omap->reset_gpio_port[1], 0);
276 /* Hold the PHY in RESET for enough time till DIR is high */
277 udelay(10);
280 /* Configure TLL for 60Mhz clk for ULPI */
281 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
282 if (IS_ERR(omap->usbtll_fck)) {
283 ret = PTR_ERR(omap->usbtll_fck);
284 goto err_tll_fck;
286 clk_enable(omap->usbtll_fck);
288 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
289 if (IS_ERR(omap->usbtll_ick)) {
290 ret = PTR_ERR(omap->usbtll_ick);
291 goto err_tll_ick;
293 clk_enable(omap->usbtll_ick);
295 /* perform TLL soft reset, and wait until reset is complete */
296 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
297 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
299 /* Wait for TLL reset to complete */
300 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
301 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
302 cpu_relax();
304 if (time_after(jiffies, timeout)) {
305 dev_dbg(omap->dev, "operation timed out\n");
306 ret = -EINVAL;
307 goto err_sys_status;
311 dev_dbg(omap->dev, "TLL RESET DONE\n");
313 /* (1<<3) = no idle mode only for initial debugging */
314 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
315 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
316 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
317 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
320 /* Put UHH in NoIdle/NoStandby mode */
321 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
322 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
323 | OMAP_UHH_SYSCONFIG_SIDLEMODE
324 | OMAP_UHH_SYSCONFIG_CACTIVITY
325 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
326 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
328 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
330 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
332 /* setup ULPI bypass and burst configurations */
333 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
334 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
335 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
336 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
338 /* Bypass the TLL module for PHY mode operation */
339 if (omap_rev() <= OMAP3430_REV_ES2_1) {
340 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1 \n");
341 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
342 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
343 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
344 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
345 else
346 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
347 } else {
348 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
349 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
350 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
351 else if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
352 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
354 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
355 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
356 else if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
357 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
359 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)
360 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
361 else if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
362 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
365 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
366 dev_dbg(omap->dev, "UHH setup done, uhh_base=%x\n", reg);
369 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
370 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
371 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
373 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
374 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
375 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
376 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
377 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
378 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
380 /* Enable UTMI mode for required TLL channels */
381 omap_usb_utmi_init(omap, tll_ch_mask);
384 if (omap->phy_reset) {
385 /* Refer ISSUE1:
386 * Hold the PHY in RESET for enough time till
387 * PHY is settled and ready
389 udelay(10);
391 if (gpio_is_valid(omap->reset_gpio_port[0]))
392 gpio_set_value(omap->reset_gpio_port[0], 1);
394 if (gpio_is_valid(omap->reset_gpio_port[1]))
395 gpio_set_value(omap->reset_gpio_port[1], 1);
398 return 0;
400 err_sys_status:
401 clk_disable(omap->usbtll_ick);
402 clk_put(omap->usbtll_ick);
404 err_tll_ick:
405 clk_disable(omap->usbtll_fck);
406 clk_put(omap->usbtll_fck);
408 err_tll_fck:
409 clk_disable(omap->usbhost1_48m_fck);
410 clk_put(omap->usbhost1_48m_fck);
412 if (omap->phy_reset) {
413 if (gpio_is_valid(omap->reset_gpio_port[0]))
414 gpio_free(omap->reset_gpio_port[0]);
416 if (gpio_is_valid(omap->reset_gpio_port[1]))
417 gpio_free(omap->reset_gpio_port[1]);
420 err_host_48m_fck:
421 clk_disable(omap->usbhost2_120m_fck);
422 clk_put(omap->usbhost2_120m_fck);
424 err_host_120m_fck:
425 clk_disable(omap->usbhost_ick);
426 clk_put(omap->usbhost_ick);
428 err_host_ick:
429 return ret;
432 static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
434 unsigned long timeout = jiffies + msecs_to_jiffies(100);
436 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
438 /* Reset OMAP modules for insmod/rmmod to work */
439 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
440 OMAP_UHH_SYSCONFIG_SOFTRESET);
441 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
442 & (1 << 0))) {
443 cpu_relax();
445 if (time_after(jiffies, timeout))
446 dev_dbg(omap->dev, "operation timed out\n");
449 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
450 & (1 << 1))) {
451 cpu_relax();
453 if (time_after(jiffies, timeout))
454 dev_dbg(omap->dev, "operation timed out\n");
457 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
458 & (1 << 2))) {
459 cpu_relax();
461 if (time_after(jiffies, timeout))
462 dev_dbg(omap->dev, "operation timed out\n");
465 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
467 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
468 & (1 << 0))) {
469 cpu_relax();
471 if (time_after(jiffies, timeout))
472 dev_dbg(omap->dev, "operation timed out\n");
475 if (omap->usbtll_fck != NULL) {
476 clk_disable(omap->usbtll_fck);
477 clk_put(omap->usbtll_fck);
478 omap->usbtll_fck = NULL;
481 if (omap->usbhost_ick != NULL) {
482 clk_disable(omap->usbhost_ick);
483 clk_put(omap->usbhost_ick);
484 omap->usbhost_ick = NULL;
487 if (omap->usbhost1_48m_fck != NULL) {
488 clk_disable(omap->usbhost1_48m_fck);
489 clk_put(omap->usbhost1_48m_fck);
490 omap->usbhost1_48m_fck = NULL;
493 if (omap->usbhost2_120m_fck != NULL) {
494 clk_disable(omap->usbhost2_120m_fck);
495 clk_put(omap->usbhost2_120m_fck);
496 omap->usbhost2_120m_fck = NULL;
499 if (omap->usbtll_ick != NULL) {
500 clk_disable(omap->usbtll_ick);
501 clk_put(omap->usbtll_ick);
502 omap->usbtll_ick = NULL;
505 if (omap->phy_reset) {
506 if (gpio_is_valid(omap->reset_gpio_port[0]))
507 gpio_free(omap->reset_gpio_port[0]);
509 if (gpio_is_valid(omap->reset_gpio_port[1]))
510 gpio_free(omap->reset_gpio_port[1]);
513 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
516 /*-------------------------------------------------------------------------*/
518 static const struct hc_driver ehci_omap_hc_driver;
520 /* configure so an HC device and id are always provided */
521 /* always called with process context; sleeping is OK */
524 * ehci_hcd_omap_probe - initialize TI-based HCDs
526 * Allocates basic resources for this USB host controller, and
527 * then invokes the start() method for the HCD associated with it
528 * through the hotplug entry's driver_data.
530 static int ehci_hcd_omap_probe(struct platform_device *pdev)
532 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
533 struct ehci_hcd_omap *omap;
534 struct resource *res;
535 struct usb_hcd *hcd;
537 int irq = platform_get_irq(pdev, 0);
538 int ret = -ENODEV;
540 if (!pdata) {
541 dev_dbg(&pdev->dev, "missing platform_data\n");
542 goto err_pdata;
545 if (usb_disabled())
546 goto err_disabled;
548 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
549 if (!omap) {
550 ret = -ENOMEM;
551 goto err_create_hcd;
554 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
555 dev_name(&pdev->dev));
556 if (!hcd) {
557 dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
558 ret = -ENOMEM;
559 goto err_create_hcd;
562 platform_set_drvdata(pdev, omap);
563 omap->dev = &pdev->dev;
564 omap->phy_reset = pdata->phy_reset;
565 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
566 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
567 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
568 omap->port_mode[0] = pdata->port_mode[0];
569 omap->port_mode[1] = pdata->port_mode[1];
570 omap->port_mode[2] = pdata->port_mode[2];
571 omap->chargepump = pdata->chargepump;
572 omap->ehci = hcd_to_ehci(hcd);
573 omap->ehci->sbrn = 0x20;
575 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
577 hcd->rsrc_start = res->start;
578 hcd->rsrc_len = resource_size(res);
580 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
581 if (!hcd->regs) {
582 dev_err(&pdev->dev, "EHCI ioremap failed\n");
583 ret = -ENOMEM;
584 goto err_ioremap;
587 /* we know this is the memory we want, no need to ioremap again */
588 omap->ehci->caps = hcd->regs;
589 omap->ehci_base = hcd->regs;
591 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
592 omap->uhh_base = ioremap(res->start, resource_size(res));
593 if (!omap->uhh_base) {
594 dev_err(&pdev->dev, "UHH ioremap failed\n");
595 ret = -ENOMEM;
596 goto err_uhh_ioremap;
599 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
600 omap->tll_base = ioremap(res->start, resource_size(res));
601 if (!omap->tll_base) {
602 dev_err(&pdev->dev, "TLL ioremap failed\n");
603 ret = -ENOMEM;
604 goto err_tll_ioremap;
607 ret = omap_start_ehc(omap, hcd);
608 if (ret) {
609 dev_dbg(&pdev->dev, "failed to start ehci\n");
610 goto err_start;
613 omap->ehci->regs = hcd->regs
614 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
616 /* cache this readonly data; minimize chip reads */
617 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
619 /* SET 1 micro-frame Interrupt interval */
620 writel(readl(&omap->ehci->regs->command) | (1 << 16),
621 &omap->ehci->regs->command);
623 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
624 if (ret) {
625 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
626 goto err_add_hcd;
629 return 0;
631 err_add_hcd:
632 omap_stop_ehc(omap, hcd);
634 err_start:
635 iounmap(omap->tll_base);
637 err_tll_ioremap:
638 iounmap(omap->uhh_base);
640 err_uhh_ioremap:
641 iounmap(hcd->regs);
643 err_ioremap:
644 usb_put_hcd(hcd);
646 err_create_hcd:
647 err_disabled:
648 err_pdata:
649 return ret;
652 /* may be called without controller electrically present */
653 /* may be called with controller, bus, and devices active */
656 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
657 * @pdev: USB Host Controller being removed
659 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
660 * the HCD's stop() method. It is always called from a thread
661 * context, normally "rmmod", "apmd", or something similar.
663 static int ehci_hcd_omap_remove(struct platform_device *pdev)
665 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
666 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
668 usb_remove_hcd(hcd);
669 omap_stop_ehc(omap, hcd);
670 iounmap(hcd->regs);
671 iounmap(omap->tll_base);
672 iounmap(omap->uhh_base);
673 usb_put_hcd(hcd);
675 return 0;
678 static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
680 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
681 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
683 if (hcd->driver->shutdown)
684 hcd->driver->shutdown(hcd);
687 static struct platform_driver ehci_hcd_omap_driver = {
688 .probe = ehci_hcd_omap_probe,
689 .remove = ehci_hcd_omap_remove,
690 .shutdown = ehci_hcd_omap_shutdown,
691 /*.suspend = ehci_hcd_omap_suspend, */
692 /*.resume = ehci_hcd_omap_resume, */
693 .driver = {
694 .name = "ehci-omap",
698 /*-------------------------------------------------------------------------*/
700 static const struct hc_driver ehci_omap_hc_driver = {
701 .description = hcd_name,
702 .product_desc = "OMAP-EHCI Host Controller",
703 .hcd_priv_size = sizeof(struct ehci_hcd),
706 * generic hardware linkage
708 .irq = ehci_irq,
709 .flags = HCD_MEMORY | HCD_USB2,
712 * basic lifecycle operations
714 .reset = ehci_init,
715 .start = ehci_run,
716 .stop = ehci_stop,
717 .shutdown = ehci_shutdown,
720 * managing i/o requests and associated device resources
722 .urb_enqueue = ehci_urb_enqueue,
723 .urb_dequeue = ehci_urb_dequeue,
724 .endpoint_disable = ehci_endpoint_disable,
725 .endpoint_reset = ehci_endpoint_reset,
728 * scheduling support
730 .get_frame_number = ehci_get_frame,
733 * root hub support
735 .hub_status_data = ehci_hub_status_data,
736 .hub_control = ehci_hub_control,
737 .bus_suspend = ehci_bus_suspend,
738 .bus_resume = ehci_bus_resume,
740 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
743 MODULE_ALIAS("platform:omap-ehci");
744 MODULE_AUTHOR("Texas Instruments, Inc.");
745 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");