blob: 0f717dc688b7276fb75f65a9920bb799facfb164 [file] [log] [blame]
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +05301/* ehci-msm.c - HSUSB Host Controller Driver Implementation
2 *
Pavankumar Kondeti18f53462011-02-18 17:30:11 +05303 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +05304 *
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
8 *
9 * All source code in this file is licensed under the following license except
10 * where indicated.
11 *
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.
15 *
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.
19 *
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
23 */
24
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053025#include <linux/clk.h>
26#include <linux/err.h>
Manjunath Goudar8c68e842013-04-02 18:24:03 +020027#include <linux/io.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/platform_device.h>
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +053031#include <linux/pm_runtime.h>
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053032#include <linux/usb/otg.h>
33#include <linux/usb/msm_hsusb_hw.h>
Manjunath Goudar8c68e842013-04-02 18:24:03 +020034#include <linux/usb.h>
35#include <linux/usb/hcd.h>
36
37#include "ehci.h"
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053038
39#define MSM_USB_BASE (hcd->regs)
40
Manjunath Goudar8c68e842013-04-02 18:24:03 +020041#define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
42
43static const char hcd_name[] = "ehci-msm";
44static struct hc_driver __read_mostly msm_hc_driver;
Heikki Krogerusb96d3b02012-02-13 13:24:18 +020045static struct usb_phy *phy;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053046
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053047static int ehci_msm_reset(struct usb_hcd *hcd)
48{
49 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
50 int retval;
51
52 ehci->caps = USB_CAPLENGTH;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053053 hcd->has_tt = 1;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053054
Matthieu CASTET2cb30bb2011-07-02 20:59:46 +020055 retval = ehci_setup(hcd);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053056 if (retval)
57 return retval;
58
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);
65
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053066 return 0;
67}
68
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053069static int ehci_msm_probe(struct platform_device *pdev)
70{
71 struct usb_hcd *hcd;
72 struct resource *res;
73 int ret;
74
75 dev_dbg(&pdev->dev, "ehci_msm proble\n");
76
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;
81 }
82
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;
88 }
89
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;
95 }
96
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = resource_size(res);
Julia Lawalldf5eb3f2012-07-29 21:46:11 +020099 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530100 if (!hcd->regs) {
101 dev_err(&pdev->dev, "ioremap failed\n");
102 ret = -ENOMEM;
103 goto put_hcd;
104 }
105
106 /*
107 * OTG driver takes care of PHY initialization, clock management,
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530108 * powering up VBUS, mapping of registers address space and power
109 * management.
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530110 */
Julia Lawalldf5eb3f2012-07-29 21:46:11 +0200111 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
Felipe Balbie299bd92013-03-15 11:02:56 +0200112 if (IS_ERR(phy)) {
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530113 dev_err(&pdev->dev, "unable to find transceiver\n");
114 ret = -ENODEV;
Julia Lawalldf5eb3f2012-07-29 21:46:11 +0200115 goto put_hcd;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530116 }
117
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200118 ret = otg_set_host(phy->otg, &hcd->self);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530119 if (ret < 0) {
120 dev_err(&pdev->dev, "unable to register with transceiver\n");
Julia Lawalldf5eb3f2012-07-29 21:46:11 +0200121 goto put_hcd;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530122 }
123
124 device_init_wakeup(&pdev->dev, 1);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530125 /*
126 * OTG device parent of HCD takes care of putting
127 * hardware into low power mode.
128 */
129 pm_runtime_no_callbacks(&pdev->dev);
130 pm_runtime_enable(&pdev->dev);
131
Manjunath Goudar8c68e842013-04-02 18:24:03 +0200132 /* FIXME: need to call usb_add_hcd() here? */
133
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530134 return 0;
135
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530136put_hcd:
137 usb_put_hcd(hcd);
138
139 return ret;
140}
141
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500142static int ehci_msm_remove(struct platform_device *pdev)
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530143{
144 struct usb_hcd *hcd = platform_get_drvdata(pdev);
145
146 device_init_wakeup(&pdev->dev, 0);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530147 pm_runtime_disable(&pdev->dev);
148 pm_runtime_set_suspended(&pdev->dev);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530149
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200150 otg_set_host(phy->otg, NULL);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530151
Manjunath Goudar8c68e842013-04-02 18:24:03 +0200152 /* FIXME: need to call usb_remove_hcd() here? */
153
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530154 usb_put_hcd(hcd);
155
156 return 0;
157}
158
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530159#ifdef CONFIG_PM
160static int ehci_msm_pm_suspend(struct device *dev)
161{
162 struct usb_hcd *hcd = dev_get_drvdata(dev);
Alan Sternc5cf9212012-06-28 11:19:02 -0400163 bool do_wakeup = device_may_wakeup(dev);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530164
165 dev_dbg(dev, "ehci-msm PM suspend\n");
166
Alan Sternc5cf9212012-06-28 11:19:02 -0400167 return ehci_suspend(hcd, do_wakeup);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530168}
169
170static int ehci_msm_pm_resume(struct device *dev)
171{
172 struct usb_hcd *hcd = dev_get_drvdata(dev);
173
174 dev_dbg(dev, "ehci-msm PM resume\n");
Alan Sternc5cf9212012-06-28 11:19:02 -0400175 ehci_resume(hcd, false);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530176
177 return 0;
178}
179#else
180#define ehci_msm_pm_suspend NULL
181#define ehci_msm_pm_resume NULL
182#endif
183
184static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
185 .suspend = ehci_msm_pm_suspend,
186 .resume = ehci_msm_pm_resume,
187};
188
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530189static struct platform_driver ehci_msm_driver = {
190 .probe = ehci_msm_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500191 .remove = ehci_msm_remove,
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530192 .driver = {
193 .name = "msm_hsusb_host",
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530194 .pm = &ehci_msm_dev_pm_ops,
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530195 },
196};
Manjunath Goudar8c68e842013-04-02 18:24:03 +0200197
198static const struct ehci_driver_overrides msm_overrides __initdata = {
199 .reset = ehci_msm_reset,
200};
201
202static int __init ehci_msm_init(void)
203{
204 if (usb_disabled())
205 return -ENODEV;
206
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);
210}
211module_init(ehci_msm_init);
212
213static void __exit ehci_msm_cleanup(void)
214{
215 platform_driver_unregister(&ehci_msm_driver);
216}
217module_exit(ehci_msm_cleanup);
218
219MODULE_DESCRIPTION(DRIVER_DESC);
220MODULE_ALIAS("platform:msm-ehci");
221MODULE_LICENSE("GPL");