15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-1.0+
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * OHCI HCD (Host Controller Driver) for USB.
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
61da177e4SLinus Torvalds * (C) Copyright 2000-2005 David Brownell
71da177e4SLinus Torvalds * (C) Copyright 2002 Hewlett-Packard Company
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * OMAP Bus Glue
101da177e4SLinus Torvalds *
111da177e4SLinus Torvalds * Modified for OMAP by Tony Lindgren <tony@atomide.com>
121da177e4SLinus Torvalds * Based on the 2.4 OMAP OHCI driver originally done by MontaVista Software Inc.
131da177e4SLinus Torvalds * and on ohci-sa1111.c by Christopher Hoover <ch@hpl.hp.com>
141da177e4SLinus Torvalds *
151da177e4SLinus Torvalds * This file is licenced under the GPL.
161da177e4SLinus Torvalds */
171da177e4SLinus Torvalds
18f8ce2547SRussell King #include <linux/clk.h>
19de57a154SManjunath Goudar #include <linux/dma-mapping.h>
20ded017eeSKishon Vijay Abraham I #include <linux/err.h>
2115d157e8SLinus Walleij #include <linux/gpio/consumer.h>
22de57a154SManjunath Goudar #include <linux/io.h>
23de57a154SManjunath Goudar #include <linux/jiffies.h>
24de57a154SManjunath Goudar #include <linux/kernel.h>
25de57a154SManjunath Goudar #include <linux/module.h>
26de57a154SManjunath Goudar #include <linux/usb/otg.h>
27de57a154SManjunath Goudar #include <linux/platform_device.h>
28e8e77e97SArnd Bergmann #include <linux/platform_data/usb-omap1.h>
29e8e77e97SArnd Bergmann #include <linux/soc/ti/omap1-usb.h>
3011e00292SArnd Bergmann #include <linux/soc/ti/omap1-mux.h>
3111e00292SArnd Bergmann #include <linux/soc/ti/omap1-soc.h>
3211e00292SArnd Bergmann #include <linux/soc/ti/omap1-io.h>
33de57a154SManjunath Goudar #include <linux/signal.h>
34de57a154SManjunath Goudar #include <linux/usb.h>
35de57a154SManjunath Goudar #include <linux/usb/hcd.h>
36de57a154SManjunath Goudar
37de57a154SManjunath Goudar #include "ohci.h"
384e57b681STim Schmielau
391da177e4SLinus Torvalds #include <asm/io.h>
401da177e4SLinus Torvalds #include <asm/mach-types.h>
411da177e4SLinus Torvalds
42de57a154SManjunath Goudar #define DRIVER_DESC "OHCI OMAP driver"
431da177e4SLinus Torvalds
4423341863SLinus Walleij struct ohci_omap_priv {
4523341863SLinus Walleij struct clk *usb_host_ck;
4623341863SLinus Walleij struct clk *usb_dc_ck;
4715d157e8SLinus Walleij struct gpio_desc *power;
4815d157e8SLinus Walleij struct gpio_desc *overcurrent;
4923341863SLinus Walleij };
50de57a154SManjunath Goudar
51de57a154SManjunath Goudar static const char hcd_name[] = "ohci-omap";
52de57a154SManjunath Goudar static struct hc_driver __read_mostly ohci_omap_hc_driver;
531da177e4SLinus Torvalds
5423341863SLinus Walleij #define hcd_to_ohci_omap_priv(h) \
5523341863SLinus Walleij ((struct ohci_omap_priv *)hcd_to_ohci(h)->priv)
5623341863SLinus Walleij
omap_ohci_clock_power(struct ohci_omap_priv * priv,int on)5723341863SLinus Walleij static void omap_ohci_clock_power(struct ohci_omap_priv *priv, int on)
581da177e4SLinus Torvalds {
591da177e4SLinus Torvalds if (on) {
6023341863SLinus Walleij clk_enable(priv->usb_dc_ck);
6123341863SLinus Walleij clk_enable(priv->usb_host_ck);
621da177e4SLinus Torvalds /* guesstimate for T5 == 1x 32K clock + APLL lock time */
631da177e4SLinus Torvalds udelay(100);
641da177e4SLinus Torvalds } else {
6523341863SLinus Walleij clk_disable(priv->usb_host_ck);
6623341863SLinus Walleij clk_disable(priv->usb_dc_ck);
671da177e4SLinus Torvalds }
681da177e4SLinus Torvalds }
691da177e4SLinus Torvalds
start_hnp(struct ohci_hcd * ohci)701da177e4SLinus Torvalds static void start_hnp(struct ohci_hcd *ohci)
711da177e4SLinus Torvalds {
72c2e935a7SRichard Zhao struct usb_hcd *hcd = ohci_to_hcd(ohci);
73c2e935a7SRichard Zhao const unsigned port = hcd->self.otg_port - 1;
741da177e4SLinus Torvalds unsigned long flags;
75f35ae634STony Lindgren u32 l;
761da177e4SLinus Torvalds
773d46e73dSAntoine Tenart otg_start_hnp(hcd->usb_phy->otg);
781da177e4SLinus Torvalds
791da177e4SLinus Torvalds local_irq_save(flags);
807e1bbeb4SFelipe Balbi hcd->usb_phy->otg->state = OTG_STATE_A_SUSPEND;
811da177e4SLinus Torvalds writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
82f35ae634STony Lindgren l = omap_readl(OTG_CTRL);
83f35ae634STony Lindgren l &= ~OTG_A_BUSREQ;
84f35ae634STony Lindgren omap_writel(l, OTG_CTRL);
851da177e4SLinus Torvalds local_irq_restore(flags);
861da177e4SLinus Torvalds }
871da177e4SLinus Torvalds
881da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
891da177e4SLinus Torvalds
ohci_omap_reset(struct usb_hcd * hcd)90de57a154SManjunath Goudar static int ohci_omap_reset(struct usb_hcd *hcd)
911da177e4SLinus Torvalds {
92bd35078fSDavid Brownell struct ohci_hcd *ohci = hcd_to_ohci(hcd);
93d4f09e28SJingoo Han struct omap_usb_config *config = dev_get_platdata(hcd->self.controller);
9423341863SLinus Walleij struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd);
951da177e4SLinus Torvalds int need_transceiver = (config->otg != 0);
961da177e4SLinus Torvalds int ret;
971da177e4SLinus Torvalds
98bd35078fSDavid Brownell dev_dbg(hcd->self.controller, "starting USB Controller\n");
991da177e4SLinus Torvalds
1001da177e4SLinus Torvalds if (config->otg) {
101de57a154SManjunath Goudar hcd->self.otg_port = config->otg;
1021da177e4SLinus Torvalds /* default/minimum OTG power budget: 8 mA */
103de57a154SManjunath Goudar hcd->power_budget = 8;
1041da177e4SLinus Torvalds }
1051da177e4SLinus Torvalds
106d3645d39SPaul Walmsley /* XXX OMAP16xx only */
107d3645d39SPaul Walmsley if (config->ocpi_enable)
108d3645d39SPaul Walmsley config->ocpi_enable();
1091da177e4SLinus Torvalds
110903b39e1SArnd Bergmann if (IS_ENABLED(CONFIG_USB_OTG) && need_transceiver) {
1113d46e73dSAntoine Tenart hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
1123d46e73dSAntoine Tenart if (!IS_ERR_OR_NULL(hcd->usb_phy)) {
1133d46e73dSAntoine Tenart int status = otg_set_host(hcd->usb_phy->otg,
1141da177e4SLinus Torvalds &ohci_to_hcd(ohci)->self);
115c2e935a7SRichard Zhao dev_dbg(hcd->self.controller, "init %s phy, status %d\n",
1163d46e73dSAntoine Tenart hcd->usb_phy->label, status);
1171da177e4SLinus Torvalds if (status) {
1183d46e73dSAntoine Tenart usb_put_phy(hcd->usb_phy);
1191da177e4SLinus Torvalds return status;
1201da177e4SLinus Torvalds }
1211da177e4SLinus Torvalds } else {
122bf2b419aSAaro Koskinen return -EPROBE_DEFER;
1231da177e4SLinus Torvalds }
1244e88d4c0SMartin Blumenstingl hcd->skip_phy_initialization = 1;
125e8b24450SDmitry Baryshkov ohci->start_hnp = start_hnp;
1261da177e4SLinus Torvalds }
1271da177e4SLinus Torvalds
12823341863SLinus Walleij omap_ohci_clock_power(priv, 1);
1291da177e4SLinus Torvalds
13094ad8aacSArnd Bergmann if (config->lb_reset)
13194ad8aacSArnd Bergmann config->lb_reset();
1321da177e4SLinus Torvalds
133de57a154SManjunath Goudar ret = ohci_setup(hcd);
134de57a154SManjunath Goudar if (ret < 0)
1351da177e4SLinus Torvalds return ret;
1361da177e4SLinus Torvalds
137de57a154SManjunath Goudar if (config->otg || config->rwc) {
138de57a154SManjunath Goudar ohci->hc_control = OHCI_CTRL_RWC;
139de57a154SManjunath Goudar writel(OHCI_CTRL_RWC, &ohci->regs->control);
140de57a154SManjunath Goudar }
141de57a154SManjunath Goudar
1421da177e4SLinus Torvalds /* board-specific power switching and overcurrent support */
1438825acd7SArnd Bergmann if (machine_is_omap_osk()) {
1441da177e4SLinus Torvalds u32 rh = roothub_a (ohci);
1451da177e4SLinus Torvalds
1461da177e4SLinus Torvalds /* power switching (ganged by default) */
1471da177e4SLinus Torvalds rh &= ~RH_A_NPS;
1481da177e4SLinus Torvalds
1491da177e4SLinus Torvalds /* TPS2045 switch for internal transceiver (port 1) */
1501da177e4SLinus Torvalds if (machine_is_omap_osk()) {
151bc96c0adSAlan Stern ohci_to_hcd(ohci)->power_budget = 250;
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds rh &= ~RH_A_NOCP;
1541da177e4SLinus Torvalds
1551da177e4SLinus Torvalds /* gpio9 for overcurrent detction */
1561da177e4SLinus Torvalds omap_cfg_reg(W8_1610_GPIO9);
1571da177e4SLinus Torvalds
1581da177e4SLinus Torvalds /* for paranoia's sake: disable USB.PUEN */
1591da177e4SLinus Torvalds omap_cfg_reg(W4_USB_HIGHZ);
1601da177e4SLinus Torvalds }
1611da177e4SLinus Torvalds ohci_writel(ohci, rh, &ohci->regs->roothub.a);
1621133cd8aSDmitry Baryshkov ohci->flags &= ~OHCI_QUIRK_HUB_POWER;
163bd35078fSDavid Brownell } else if (machine_is_nokia770()) {
164bd35078fSDavid Brownell /* We require a self-powered hub, which should have
165bd35078fSDavid Brownell * plenty of power. */
166bd35078fSDavid Brownell ohci_to_hcd(ohci)->power_budget = 0;
1671da177e4SLinus Torvalds }
1681da177e4SLinus Torvalds
16937ebb549SPetr Mladek /* FIXME hub_wq hub requests should manage power switching */
1709fe15316SArnd Bergmann if (config->transceiver_power)
1719fe15316SArnd Bergmann return config->transceiver_power(1);
1729fe15316SArnd Bergmann
1739fe15316SArnd Bergmann if (priv->power)
1749fe15316SArnd Bergmann gpiod_set_value_cansleep(priv->power, 0);
1751da177e4SLinus Torvalds
1761da177e4SLinus Torvalds /* board init will have already handled HMC and mux setup.
1771da177e4SLinus Torvalds * any external transceiver should already be initialized
1781da177e4SLinus Torvalds * too, so all configured ports use the right signaling now.
1791da177e4SLinus Torvalds */
1801da177e4SLinus Torvalds
1811da177e4SLinus Torvalds return 0;
1821da177e4SLinus Torvalds }
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1851da177e4SLinus Torvalds
1861da177e4SLinus Torvalds /**
1871b43a852SManjunath Goudar * ohci_hcd_omap_probe - initialize OMAP-based HCDs
18819220bacSAhmed S. Darwish * @pdev: USB controller to probe
18919220bacSAhmed S. Darwish *
19019220bacSAhmed S. Darwish * Context: task context, might sleep
1911da177e4SLinus Torvalds *
1921da177e4SLinus Torvalds * Allocates basic resources for this USB host controller, and
1931da177e4SLinus Torvalds * then invokes the start() method for the HCD associated with it
1941da177e4SLinus Torvalds * through the hotplug entry's driver_data.
1951da177e4SLinus Torvalds */
ohci_hcd_omap_probe(struct platform_device * pdev)1961b43a852SManjunath Goudar static int ohci_hcd_omap_probe(struct platform_device *pdev)
1971da177e4SLinus Torvalds {
19848944738SDavid Vrabel int retval, irq;
1991da177e4SLinus Torvalds struct usb_hcd *hcd = 0;
20023341863SLinus Walleij struct ohci_omap_priv *priv;
2011da177e4SLinus Torvalds
2021da177e4SLinus Torvalds if (pdev->num_resources != 2) {
2030a3aa0d3SJingoo Han dev_err(&pdev->dev, "invalid num_resources: %i\n",
2041da177e4SLinus Torvalds pdev->num_resources);
2051da177e4SLinus Torvalds return -ENODEV;
2061da177e4SLinus Torvalds }
2071da177e4SLinus Torvalds
2081da177e4SLinus Torvalds if (pdev->resource[0].flags != IORESOURCE_MEM
2091da177e4SLinus Torvalds || pdev->resource[1].flags != IORESOURCE_IRQ) {
2100a3aa0d3SJingoo Han dev_err(&pdev->dev, "invalid resource type\n");
2111da177e4SLinus Torvalds return -ENODEV;
2121da177e4SLinus Torvalds }
2131da177e4SLinus Torvalds
2141b43a852SManjunath Goudar hcd = usb_create_hcd(&ohci_omap_hc_driver, &pdev->dev,
2151b43a852SManjunath Goudar dev_name(&pdev->dev));
21623341863SLinus Walleij if (!hcd)
21723341863SLinus Walleij return -ENOMEM;
21823341863SLinus Walleij
2191da177e4SLinus Torvalds hcd->rsrc_start = pdev->resource[0].start;
2201da177e4SLinus Torvalds hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
22123341863SLinus Walleij priv = hcd_to_ohci_omap_priv(hcd);
22223341863SLinus Walleij
22315d157e8SLinus Walleij /* Obtain two optional GPIO lines */
22415d157e8SLinus Walleij priv->power = devm_gpiod_get_optional(&pdev->dev, "power", GPIOD_ASIS);
22515d157e8SLinus Walleij if (IS_ERR(priv->power)) {
22615d157e8SLinus Walleij retval = PTR_ERR(priv->power);
22715d157e8SLinus Walleij goto err_put_hcd;
22815d157e8SLinus Walleij }
22915d157e8SLinus Walleij if (priv->power)
23015d157e8SLinus Walleij gpiod_set_consumer_name(priv->power, "OHCI power");
23115d157e8SLinus Walleij
23215d157e8SLinus Walleij /*
23315d157e8SLinus Walleij * This "overcurrent" GPIO line isn't really used in the code,
23415d157e8SLinus Walleij * but has a designated hardware function.
23515d157e8SLinus Walleij * TODO: implement proper overcurrent handling.
23615d157e8SLinus Walleij */
23715d157e8SLinus Walleij priv->overcurrent = devm_gpiod_get_optional(&pdev->dev, "overcurrent",
23815d157e8SLinus Walleij GPIOD_IN);
23915d157e8SLinus Walleij if (IS_ERR(priv->overcurrent)) {
24015d157e8SLinus Walleij retval = PTR_ERR(priv->overcurrent);
24115d157e8SLinus Walleij goto err_put_hcd;
24215d157e8SLinus Walleij }
24315d157e8SLinus Walleij if (priv->overcurrent)
24415d157e8SLinus Walleij gpiod_set_consumer_name(priv->overcurrent, "OHCI overcurrent");
24515d157e8SLinus Walleij
24623341863SLinus Walleij priv->usb_host_ck = clk_get(&pdev->dev, "usb_hhc_ck");
24723341863SLinus Walleij if (IS_ERR(priv->usb_host_ck)) {
24823341863SLinus Walleij retval = PTR_ERR(priv->usb_host_ck);
24923341863SLinus Walleij goto err_put_hcd;
25023341863SLinus Walleij }
25123341863SLinus Walleij
252a85f0230SJanusz Krzysztofik retval = clk_prepare(priv->usb_host_ck);
253a85f0230SJanusz Krzysztofik if (retval)
254a85f0230SJanusz Krzysztofik goto err_put_host_ck;
255a85f0230SJanusz Krzysztofik
25623341863SLinus Walleij if (!cpu_is_omap15xx())
25723341863SLinus Walleij priv->usb_dc_ck = clk_get(&pdev->dev, "usb_dc_ck");
25823341863SLinus Walleij else
25923341863SLinus Walleij priv->usb_dc_ck = clk_get(&pdev->dev, "lb_ck");
26023341863SLinus Walleij
26123341863SLinus Walleij if (IS_ERR(priv->usb_dc_ck)) {
26223341863SLinus Walleij retval = PTR_ERR(priv->usb_dc_ck);
263a85f0230SJanusz Krzysztofik goto err_unprepare_host_ck;
26423341863SLinus Walleij }
2651da177e4SLinus Torvalds
266a85f0230SJanusz Krzysztofik retval = clk_prepare(priv->usb_dc_ck);
267a85f0230SJanusz Krzysztofik if (retval)
268a85f0230SJanusz Krzysztofik goto err_put_dc_ck;
269a85f0230SJanusz Krzysztofik
2701da177e4SLinus Torvalds if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
2711da177e4SLinus Torvalds dev_dbg(&pdev->dev, "request_mem_region failed\n");
2721da177e4SLinus Torvalds retval = -EBUSY;
273a85f0230SJanusz Krzysztofik goto err_unprepare_dc_ck;
2741da177e4SLinus Torvalds }
2751da177e4SLinus Torvalds
27655c381e4SRussell King hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
27755c381e4SRussell King if (!hcd->regs) {
27855c381e4SRussell King dev_err(&pdev->dev, "can't ioremap OHCI HCD\n");
27955c381e4SRussell King retval = -ENOMEM;
28055c381e4SRussell King goto err2;
28155c381e4SRussell King }
2821da177e4SLinus Torvalds
28348944738SDavid Vrabel irq = platform_get_irq(pdev, 0);
28448944738SDavid Vrabel if (irq < 0) {
2854de5bd9aSSergey Shtylyov retval = irq;
28655c381e4SRussell King goto err3;
28748944738SDavid Vrabel }
288b5dd18d8SYong Zhang retval = usb_add_hcd(hcd, irq, 0);
289bd35078fSDavid Brownell if (retval)
29055c381e4SRussell King goto err3;
2911da177e4SLinus Torvalds
2923c9740a1SPeter Chen device_wakeup_enable(hcd->self.controller);
293bd35078fSDavid Brownell return 0;
29455c381e4SRussell King err3:
29555c381e4SRussell King iounmap(hcd->regs);
2961da177e4SLinus Torvalds err2:
2971da177e4SLinus Torvalds release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
298a85f0230SJanusz Krzysztofik err_unprepare_dc_ck:
299a85f0230SJanusz Krzysztofik clk_unprepare(priv->usb_dc_ck);
30023341863SLinus Walleij err_put_dc_ck:
30123341863SLinus Walleij clk_put(priv->usb_dc_ck);
302a85f0230SJanusz Krzysztofik err_unprepare_host_ck:
303a85f0230SJanusz Krzysztofik clk_unprepare(priv->usb_host_ck);
30423341863SLinus Walleij err_put_host_ck:
30523341863SLinus Walleij clk_put(priv->usb_host_ck);
30623341863SLinus Walleij err_put_hcd:
3071da177e4SLinus Torvalds usb_put_hcd(hcd);
3081da177e4SLinus Torvalds return retval;
3091da177e4SLinus Torvalds }
3101da177e4SLinus Torvalds
3111da177e4SLinus Torvalds
3121da177e4SLinus Torvalds /* may be called with controller, bus, and devices active */
3131da177e4SLinus Torvalds
3141da177e4SLinus Torvalds /**
3151b43a852SManjunath Goudar * ohci_hcd_omap_remove - shutdown processing for OMAP-based HCDs
31619220bacSAhmed S. Darwish * @pdev: USB Host Controller being removed
31719220bacSAhmed S. Darwish *
31819220bacSAhmed S. Darwish * Context: task context, might sleep
3191da177e4SLinus Torvalds *
3201b43a852SManjunath Goudar * Reverses the effect of ohci_hcd_omap_probe(), first invoking
3211da177e4SLinus Torvalds * the HCD's stop() method. It is always called from a thread
3221da177e4SLinus Torvalds * context, normally "rmmod", "apmd", or something similar.
3231da177e4SLinus Torvalds */
ohci_hcd_omap_remove(struct platform_device * pdev)324*e399d014SUwe Kleine-König static void ohci_hcd_omap_remove(struct platform_device *pdev)
3251da177e4SLinus Torvalds {
3261b43a852SManjunath Goudar struct usb_hcd *hcd = platform_get_drvdata(pdev);
32723341863SLinus Walleij struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd);
3281b43a852SManjunath Goudar
329de57a154SManjunath Goudar dev_dbg(hcd->self.controller, "stopping USB Controller\n");
3301da177e4SLinus Torvalds usb_remove_hcd(hcd);
33123341863SLinus Walleij omap_ohci_clock_power(priv, 0);
3323d46e73dSAntoine Tenart if (!IS_ERR_OR_NULL(hcd->usb_phy)) {
3333d46e73dSAntoine Tenart (void) otg_set_host(hcd->usb_phy->otg, 0);
3343d46e73dSAntoine Tenart usb_put_phy(hcd->usb_phy);
335bd35078fSDavid Brownell }
33655c381e4SRussell King iounmap(hcd->regs);
3371da177e4SLinus Torvalds release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
338a85f0230SJanusz Krzysztofik clk_unprepare(priv->usb_dc_ck);
33923341863SLinus Walleij clk_put(priv->usb_dc_ck);
340a85f0230SJanusz Krzysztofik clk_unprepare(priv->usb_host_ck);
34123341863SLinus Walleij clk_put(priv->usb_host_ck);
3421da177e4SLinus Torvalds usb_put_hcd(hcd);
3431da177e4SLinus Torvalds }
3441da177e4SLinus Torvalds
3451da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3461da177e4SLinus Torvalds
3471da177e4SLinus Torvalds #ifdef CONFIG_PM
3481da177e4SLinus Torvalds
ohci_omap_suspend(struct platform_device * pdev,pm_message_t message)34910abfa13SManjunath Goudar static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t message)
3501da177e4SLinus Torvalds {
35110abfa13SManjunath Goudar struct usb_hcd *hcd = platform_get_drvdata(pdev);
35210abfa13SManjunath Goudar struct ohci_hcd *ohci = hcd_to_ohci(hcd);
35323341863SLinus Walleij struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd);
35410abfa13SManjunath Goudar bool do_wakeup = device_may_wakeup(&pdev->dev);
35510abfa13SManjunath Goudar int ret;
3561da177e4SLinus Torvalds
357f197b2c5SDavid Brownell if (time_before(jiffies, ohci->next_statechange))
358f197b2c5SDavid Brownell msleep(5);
359f197b2c5SDavid Brownell ohci->next_statechange = jiffies;
360f197b2c5SDavid Brownell
36110abfa13SManjunath Goudar ret = ohci_suspend(hcd, do_wakeup);
36210abfa13SManjunath Goudar if (ret)
36310abfa13SManjunath Goudar return ret;
36410abfa13SManjunath Goudar
36523341863SLinus Walleij omap_ohci_clock_power(priv, 0);
36610abfa13SManjunath Goudar return ret;
3671da177e4SLinus Torvalds }
3681da177e4SLinus Torvalds
ohci_omap_resume(struct platform_device * dev)3693ae5eaecSRussell King static int ohci_omap_resume(struct platform_device *dev)
3701da177e4SLinus Torvalds {
37143bbb7e0SAlan Stern struct usb_hcd *hcd = platform_get_drvdata(dev);
37243bbb7e0SAlan Stern struct ohci_hcd *ohci = hcd_to_ohci(hcd);
37323341863SLinus Walleij struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd);
3741da177e4SLinus Torvalds
3751da177e4SLinus Torvalds if (time_before(jiffies, ohci->next_statechange))
3761da177e4SLinus Torvalds msleep(5);
3771da177e4SLinus Torvalds ohci->next_statechange = jiffies;
378f197b2c5SDavid Brownell
37923341863SLinus Walleij omap_ohci_clock_power(priv, 1);
380cfa49b4bSFlorian Fainelli ohci_resume(hcd, false);
381f197b2c5SDavid Brownell return 0;
3821da177e4SLinus Torvalds }
3831da177e4SLinus Torvalds
3841da177e4SLinus Torvalds #endif
3851da177e4SLinus Torvalds
3861da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3871da177e4SLinus Torvalds
3881da177e4SLinus Torvalds /*
3891da177e4SLinus Torvalds * Driver definition to register with the OMAP bus
3901da177e4SLinus Torvalds */
3913ae5eaecSRussell King static struct platform_driver ohci_hcd_omap_driver = {
3921b43a852SManjunath Goudar .probe = ohci_hcd_omap_probe,
393*e399d014SUwe Kleine-König .remove_new = ohci_hcd_omap_remove,
39464a21d02SAleksey Gorelov .shutdown = usb_hcd_platform_shutdown,
3951da177e4SLinus Torvalds #ifdef CONFIG_PM
3961da177e4SLinus Torvalds .suspend = ohci_omap_suspend,
3971da177e4SLinus Torvalds .resume = ohci_omap_resume,
3981da177e4SLinus Torvalds #endif
3993ae5eaecSRussell King .driver = {
4003ae5eaecSRussell King .name = "ohci",
4013ae5eaecSRussell King },
4021da177e4SLinus Torvalds };
4031da177e4SLinus Torvalds
404de57a154SManjunath Goudar static const struct ohci_driver_overrides omap_overrides __initconst = {
405de57a154SManjunath Goudar .product_desc = "OMAP OHCI",
40623341863SLinus Walleij .reset = ohci_omap_reset,
40723341863SLinus Walleij .extra_priv_size = sizeof(struct ohci_omap_priv),
408de57a154SManjunath Goudar };
409de57a154SManjunath Goudar
ohci_omap_init(void)410de57a154SManjunath Goudar static int __init ohci_omap_init(void)
411de57a154SManjunath Goudar {
412de57a154SManjunath Goudar if (usb_disabled())
413de57a154SManjunath Goudar return -ENODEV;
414de57a154SManjunath Goudar
415de57a154SManjunath Goudar ohci_init_driver(&ohci_omap_hc_driver, &omap_overrides);
416de57a154SManjunath Goudar return platform_driver_register(&ohci_hcd_omap_driver);
417de57a154SManjunath Goudar }
418de57a154SManjunath Goudar module_init(ohci_omap_init);
419de57a154SManjunath Goudar
ohci_omap_cleanup(void)420de57a154SManjunath Goudar static void __exit ohci_omap_cleanup(void)
421de57a154SManjunath Goudar {
422de57a154SManjunath Goudar platform_driver_unregister(&ohci_hcd_omap_driver);
423de57a154SManjunath Goudar }
424de57a154SManjunath Goudar module_exit(ohci_omap_cleanup);
425de57a154SManjunath Goudar
426de57a154SManjunath Goudar MODULE_DESCRIPTION(DRIVER_DESC);
427f4fce61dSKay Sievers MODULE_ALIAS("platform:ohci");
428de57a154SManjunath Goudar MODULE_LICENSE("GPL");
429