1 /* ehci-msm.c - HSUSB Host Controller Driver Implementation
3 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
5 * Partly derived from ehci-fsl.c and ehci-hcd.c
6 * Copyright (c) 2000-2004 by David Brownell
7 * Copyright (c) 2005 MontaVista Software
9 * All source code in this file is licensed under the following license except
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, you can find it at http://www.fsf.org
25 #include <linux/clk.h>
26 #include <linux/err.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/pm_runtime.h>
32 #include <linux/usb/otg.h>
33 #include <linux/usb/msm_hsusb_hw.h>
34 #include <linux/usb.h>
35 #include <linux/usb/hcd.h>
36 #include <linux/acpi.h>
40 #define MSM_USB_BASE (hcd->regs)
42 #define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
44 static const char hcd_name
[] = "ehci-msm";
45 static struct hc_driver __read_mostly msm_hc_driver
;
47 static int ehci_msm_reset(struct usb_hcd
*hcd
)
49 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
52 ehci
->caps
= USB_CAPLENGTH
;
55 retval
= ehci_setup(hcd
);
59 /* select ULPI phy and clear other status/control bits in PORTSC */
60 writel(PORTSC_PTS_ULPI
, USB_PORTSC
);
61 /* bursts of unspecified length. */
62 writel(0, USB_AHBBURST
);
63 /* Use the AHB transactor, allow posted data writes */
64 writel(0x8, USB_AHBMODE
);
65 /* Disable streaming mode and select host mode */
66 writel(0x13, USB_USBMODE
);
67 /* Disable ULPI_TX_PKT_EN_CLR_FIX which is valid only for HSIC */
68 writel(readl(USB_GENCONFIG_2
) & ~ULPI_TX_PKT_EN_CLR_FIX
, USB_GENCONFIG_2
);
73 static int ehci_msm_probe(struct platform_device
*pdev
)
80 dev_dbg(&pdev
->dev
, "ehci_msm proble\n");
82 hcd
= usb_create_hcd(&msm_hc_driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
84 dev_err(&pdev
->dev
, "Unable to create HCD\n");
88 ret
= platform_get_irq(pdev
, 0);
90 dev_err(&pdev
->dev
, "Unable to get IRQ resource\n");
95 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
97 dev_err(&pdev
->dev
, "Unable to get memory resource\n");
102 hcd
->rsrc_start
= res
->start
;
103 hcd
->rsrc_len
= resource_size(res
);
104 hcd
->regs
= devm_ioremap(&pdev
->dev
, hcd
->rsrc_start
, hcd
->rsrc_len
);
106 dev_err(&pdev
->dev
, "ioremap failed\n");
112 * If there is an OTG driver, let it take care of PHY initialization,
113 * clock management, powering up VBUS, mapping of registers address
114 * space and power management.
116 if (pdev
->dev
.of_node
)
117 phy
= devm_usb_get_phy_by_phandle(&pdev
->dev
, "usb-phy", 0);
119 phy
= devm_usb_get_phy(&pdev
->dev
, USB_PHY_TYPE_USB2
);
122 if (PTR_ERR(phy
) == -EPROBE_DEFER
) {
123 dev_err(&pdev
->dev
, "unable to find transceiver\n");
131 device_init_wakeup(&pdev
->dev
, 1);
133 if (phy
&& phy
->otg
) {
135 * MSM OTG driver takes care of adding the HCD and
136 * placing hardware into low power mode via runtime PM.
138 ret
= otg_set_host(phy
->otg
, &hcd
->self
);
140 dev_err(&pdev
->dev
, "unable to register with transceiver\n");
144 pm_runtime_no_callbacks(&pdev
->dev
);
145 pm_runtime_enable(&pdev
->dev
);
147 ret
= usb_add_hcd(hcd
, hcd
->irq
, IRQF_SHARED
);
160 static int ehci_msm_remove(struct platform_device
*pdev
)
162 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
164 device_init_wakeup(&pdev
->dev
, 0);
165 pm_runtime_disable(&pdev
->dev
);
166 pm_runtime_set_suspended(&pdev
->dev
);
168 if (hcd
->usb_phy
&& hcd
->usb_phy
->otg
)
169 otg_set_host(hcd
->usb_phy
->otg
, NULL
);
179 static int ehci_msm_pm_suspend(struct device
*dev
)
181 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
182 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
183 bool do_wakeup
= device_may_wakeup(dev
);
185 dev_dbg(dev
, "ehci-msm PM suspend\n");
187 /* Only call ehci_suspend if ehci_setup has been done */
189 return ehci_suspend(hcd
, do_wakeup
);
194 static int ehci_msm_pm_resume(struct device
*dev
)
196 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
197 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
199 dev_dbg(dev
, "ehci-msm PM resume\n");
201 /* Only call ehci_resume if ehci_setup has been done */
203 ehci_resume(hcd
, false);
209 #define ehci_msm_pm_suspend NULL
210 #define ehci_msm_pm_resume NULL
213 static const struct dev_pm_ops ehci_msm_dev_pm_ops
= {
214 .suspend
= ehci_msm_pm_suspend
,
215 .resume
= ehci_msm_pm_resume
,
218 static const struct acpi_device_id msm_ehci_acpi_ids
[] = {
222 MODULE_DEVICE_TABLE(acpi
, msm_ehci_acpi_ids
);
224 static const struct of_device_id msm_ehci_dt_match
[] = {
225 { .compatible
= "qcom,ehci-host", },
228 MODULE_DEVICE_TABLE(of
, msm_ehci_dt_match
);
230 static struct platform_driver ehci_msm_driver
= {
231 .probe
= ehci_msm_probe
,
232 .remove
= ehci_msm_remove
,
233 .shutdown
= usb_hcd_platform_shutdown
,
235 .name
= "msm_hsusb_host",
236 .pm
= &ehci_msm_dev_pm_ops
,
237 .of_match_table
= msm_ehci_dt_match
,
238 .acpi_match_table
= ACPI_PTR(msm_ehci_acpi_ids
),
242 static const struct ehci_driver_overrides msm_overrides __initconst
= {
243 .reset
= ehci_msm_reset
,
246 static int __init
ehci_msm_init(void)
251 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
252 ehci_init_driver(&msm_hc_driver
, &msm_overrides
);
253 return platform_driver_register(&ehci_msm_driver
);
255 module_init(ehci_msm_init
);
257 static void __exit
ehci_msm_cleanup(void)
259 platform_driver_unregister(&ehci_msm_driver
);
261 module_exit(ehci_msm_cleanup
);
263 MODULE_DESCRIPTION(DRIVER_DESC
);
264 MODULE_ALIAS("platform:msm-ehci");
265 MODULE_LICENSE("GPL");