Merge git://www.linux-watchdog.org/linux-watchdog
[linux/fpc-iii.git] / drivers / usb / host / ehci-msm.c
blob0f717dc688b7276fb75f65a9920bb799facfb164
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
10 * where indicated.
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>
27 #include <linux/io.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>
37 #include "ehci.h"
39 #define MSM_USB_BASE (hcd->regs)
41 #define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
43 static const char hcd_name[] = "ehci-msm";
44 static struct hc_driver __read_mostly msm_hc_driver;
45 static struct usb_phy *phy;
47 static int ehci_msm_reset(struct usb_hcd *hcd)
49 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
50 int retval;
52 ehci->caps = USB_CAPLENGTH;
53 hcd->has_tt = 1;
55 retval = ehci_setup(hcd);
56 if (retval)
57 return retval;
59 /* bursts of unspecified length. */
60 writel(0, USB_AHBBURST);
61 /* Use the AHB transactor */
62 writel(0, USB_AHBMODE);
63 /* Disable streaming mode and select host mode */
64 writel(0x13, USB_USBMODE);
66 return 0;
69 static int ehci_msm_probe(struct platform_device *pdev)
71 struct usb_hcd *hcd;
72 struct resource *res;
73 int ret;
75 dev_dbg(&pdev->dev, "ehci_msm proble\n");
77 hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
78 if (!hcd) {
79 dev_err(&pdev->dev, "Unable to create HCD\n");
80 return -ENOMEM;
83 hcd->irq = platform_get_irq(pdev, 0);
84 if (hcd->irq < 0) {
85 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
86 ret = hcd->irq;
87 goto put_hcd;
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 if (!res) {
92 dev_err(&pdev->dev, "Unable to get memory resource\n");
93 ret = -ENODEV;
94 goto put_hcd;
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = resource_size(res);
99 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
100 if (!hcd->regs) {
101 dev_err(&pdev->dev, "ioremap failed\n");
102 ret = -ENOMEM;
103 goto put_hcd;
107 * OTG driver takes care of PHY initialization, clock management,
108 * powering up VBUS, mapping of registers address space and power
109 * management.
111 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
112 if (IS_ERR(phy)) {
113 dev_err(&pdev->dev, "unable to find transceiver\n");
114 ret = -ENODEV;
115 goto put_hcd;
118 ret = otg_set_host(phy->otg, &hcd->self);
119 if (ret < 0) {
120 dev_err(&pdev->dev, "unable to register with transceiver\n");
121 goto put_hcd;
124 device_init_wakeup(&pdev->dev, 1);
126 * OTG device parent of HCD takes care of putting
127 * hardware into low power mode.
129 pm_runtime_no_callbacks(&pdev->dev);
130 pm_runtime_enable(&pdev->dev);
132 /* FIXME: need to call usb_add_hcd() here? */
134 return 0;
136 put_hcd:
137 usb_put_hcd(hcd);
139 return ret;
142 static int ehci_msm_remove(struct platform_device *pdev)
144 struct usb_hcd *hcd = platform_get_drvdata(pdev);
146 device_init_wakeup(&pdev->dev, 0);
147 pm_runtime_disable(&pdev->dev);
148 pm_runtime_set_suspended(&pdev->dev);
150 otg_set_host(phy->otg, NULL);
152 /* FIXME: need to call usb_remove_hcd() here? */
154 usb_put_hcd(hcd);
156 return 0;
159 #ifdef CONFIG_PM
160 static int ehci_msm_pm_suspend(struct device *dev)
162 struct usb_hcd *hcd = dev_get_drvdata(dev);
163 bool do_wakeup = device_may_wakeup(dev);
165 dev_dbg(dev, "ehci-msm PM suspend\n");
167 return ehci_suspend(hcd, do_wakeup);
170 static int ehci_msm_pm_resume(struct device *dev)
172 struct usb_hcd *hcd = dev_get_drvdata(dev);
174 dev_dbg(dev, "ehci-msm PM resume\n");
175 ehci_resume(hcd, false);
177 return 0;
179 #else
180 #define ehci_msm_pm_suspend NULL
181 #define ehci_msm_pm_resume NULL
182 #endif
184 static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
185 .suspend = ehci_msm_pm_suspend,
186 .resume = ehci_msm_pm_resume,
189 static struct platform_driver ehci_msm_driver = {
190 .probe = ehci_msm_probe,
191 .remove = ehci_msm_remove,
192 .driver = {
193 .name = "msm_hsusb_host",
194 .pm = &ehci_msm_dev_pm_ops,
198 static const struct ehci_driver_overrides msm_overrides __initdata = {
199 .reset = ehci_msm_reset,
202 static int __init ehci_msm_init(void)
204 if (usb_disabled())
205 return -ENODEV;
207 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
208 ehci_init_driver(&msm_hc_driver, &msm_overrides);
209 return platform_driver_register(&ehci_msm_driver);
211 module_init(ehci_msm_init);
213 static void __exit ehci_msm_cleanup(void)
215 platform_driver_unregister(&ehci_msm_driver);
217 module_exit(ehci_msm_cleanup);
219 MODULE_DESCRIPTION(DRIVER_DESC);
220 MODULE_ALIAS("platform:msm-ehci");
221 MODULE_LICENSE("GPL");