Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 1 | /* ehci-msm.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
Pavankumar Kondeti | 18f5346 | 2011-02-18 17:30:11 +0530 | [diff] [blame] | 3 | * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved. |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 4 | * |
| 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 Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 25 | #include <linux/clk.h> |
| 26 | #include <linux/err.h> |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 27 | #include <linux/io.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/platform_device.h> |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 31 | #include <linux/pm_runtime.h> |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 32 | #include <linux/usb/otg.h> |
| 33 | #include <linux/usb/msm_hsusb_hw.h> |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 34 | #include <linux/usb.h> |
| 35 | #include <linux/usb/hcd.h> |
Jack Pham | f13f0e6 | 2015-12-10 18:28:55 -0600 | [diff] [blame] | 36 | #include <linux/acpi.h> |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 37 | |
| 38 | #include "ehci.h" |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 39 | |
| 40 | #define MSM_USB_BASE (hcd->regs) |
| 41 | |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 42 | #define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller" |
| 43 | |
| 44 | static const char hcd_name[] = "ehci-msm"; |
| 45 | static struct hc_driver __read_mostly msm_hc_driver; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 46 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 47 | static 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 Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 53 | hcd->has_tt = 1; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 54 | |
Matthieu CASTET | 2cb30bb | 2011-07-02 20:59:46 +0200 | [diff] [blame] | 55 | retval = ehci_setup(hcd); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 56 | if (retval) |
| 57 | return retval; |
| 58 | |
Jack Pham | e8f55b9 | 2015-12-10 18:28:56 -0600 | [diff] [blame] | 59 | /* select ULPI phy and clear other status/control bits in PORTSC */ |
| 60 | writel(PORTSC_PTS_ULPI, USB_PORTSC); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 61 | /* bursts of unspecified length. */ |
| 62 | writel(0, USB_AHBBURST); |
Andy Gross | c56a2b2 | 2015-11-06 00:04:07 -0600 | [diff] [blame] | 63 | /* Use the AHB transactor, allow posted data writes */ |
| 64 | writel(0x8, USB_AHBMODE); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 65 | /* Disable streaming mode and select host mode */ |
| 66 | writel(0x13, USB_USBMODE); |
Jack Pham | 132f500 | 2015-12-10 18:28:53 -0600 | [diff] [blame] | 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); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 69 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 73 | static int ehci_msm_probe(struct platform_device *pdev) |
| 74 | { |
| 75 | struct usb_hcd *hcd; |
| 76 | struct resource *res; |
Ivan T. Ivanov | e4f0da0 | 2013-10-11 14:46:09 +0300 | [diff] [blame] | 77 | struct usb_phy *phy; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 78 | int ret; |
| 79 | |
| 80 | dev_dbg(&pdev->dev, "ehci_msm proble\n"); |
| 81 | |
| 82 | hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev)); |
| 83 | if (!hcd) { |
| 84 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 85 | return -ENOMEM; |
| 86 | } |
| 87 | |
Andrzej Hajda | 0c43e9d | 2015-09-21 15:33:39 +0200 | [diff] [blame] | 88 | ret = platform_get_irq(pdev, 0); |
| 89 | if (ret < 0) { |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 90 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 91 | goto put_hcd; |
| 92 | } |
Andrzej Hajda | 0c43e9d | 2015-09-21 15:33:39 +0200 | [diff] [blame] | 93 | hcd->irq = ret; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 94 | |
| 95 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Ivan T. Ivanov | bb304b7 | 2015-04-27 15:27:36 +0300 | [diff] [blame] | 96 | if (!res) { |
| 97 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 98 | ret = -ENODEV; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 99 | goto put_hcd; |
| 100 | } |
Ivan T. Ivanov | bb304b7 | 2015-04-27 15:27:36 +0300 | [diff] [blame] | 101 | |
Varka Bhadram | e507bf5 | 2014-11-04 07:51:20 +0530 | [diff] [blame] | 102 | hcd->rsrc_start = res->start; |
| 103 | hcd->rsrc_len = resource_size(res); |
Ivan T. Ivanov | bb304b7 | 2015-04-27 15:27:36 +0300 | [diff] [blame] | 104 | hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); |
| 105 | if (!hcd->regs) { |
| 106 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 107 | ret = -ENOMEM; |
| 108 | goto put_hcd; |
| 109 | } |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 110 | |
| 111 | /* |
Jack Pham | c4398ef | 2015-12-10 18:28:54 -0600 | [diff] [blame] | 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. |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 115 | */ |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 116 | if (pdev->dev.of_node) |
| 117 | phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); |
| 118 | else |
| 119 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
| 120 | |
Felipe Balbi | e299bd9 | 2013-03-15 11:02:56 +0200 | [diff] [blame] | 121 | if (IS_ERR(phy)) { |
Jack Pham | c4398ef | 2015-12-10 18:28:54 -0600 | [diff] [blame] | 122 | if (PTR_ERR(phy) == -EPROBE_DEFER) { |
| 123 | dev_err(&pdev->dev, "unable to find transceiver\n"); |
| 124 | ret = -EPROBE_DEFER; |
| 125 | goto put_hcd; |
| 126 | } |
| 127 | phy = NULL; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 128 | } |
| 129 | |
Antoine Tenart | 3d46e73 | 2014-09-24 23:05:50 +0400 | [diff] [blame] | 130 | hcd->usb_phy = phy; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 131 | device_init_wakeup(&pdev->dev, 1); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 132 | |
Jack Pham | c4398ef | 2015-12-10 18:28:54 -0600 | [diff] [blame] | 133 | if (phy && phy->otg) { |
| 134 | /* |
| 135 | * MSM OTG driver takes care of adding the HCD and |
| 136 | * placing hardware into low power mode via runtime PM. |
| 137 | */ |
| 138 | ret = otg_set_host(phy->otg, &hcd->self); |
| 139 | if (ret < 0) { |
| 140 | dev_err(&pdev->dev, "unable to register with transceiver\n"); |
| 141 | goto put_hcd; |
| 142 | } |
| 143 | |
| 144 | pm_runtime_no_callbacks(&pdev->dev); |
| 145 | pm_runtime_enable(&pdev->dev); |
| 146 | } else { |
| 147 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 148 | if (ret) |
| 149 | goto put_hcd; |
| 150 | } |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 151 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 152 | return 0; |
| 153 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 154 | put_hcd: |
| 155 | usb_put_hcd(hcd); |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 160 | static int ehci_msm_remove(struct platform_device *pdev) |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 161 | { |
| 162 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 163 | |
| 164 | device_init_wakeup(&pdev->dev, 0); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 165 | pm_runtime_disable(&pdev->dev); |
| 166 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 167 | |
Jack Pham | c4398ef | 2015-12-10 18:28:54 -0600 | [diff] [blame] | 168 | if (hcd->usb_phy && hcd->usb_phy->otg) |
| 169 | otg_set_host(hcd->usb_phy->otg, NULL); |
| 170 | else |
| 171 | usb_remove_hcd(hcd); |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 172 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 173 | usb_put_hcd(hcd); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 178 | #ifdef CONFIG_PM |
| 179 | static int ehci_msm_pm_suspend(struct device *dev) |
| 180 | { |
| 181 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Andy Gross | 815c9d6 | 2016-05-20 16:35:07 -0500 | [diff] [blame] | 182 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 183 | bool do_wakeup = device_may_wakeup(dev); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 184 | |
| 185 | dev_dbg(dev, "ehci-msm PM suspend\n"); |
| 186 | |
Andy Gross | 815c9d6 | 2016-05-20 16:35:07 -0500 | [diff] [blame] | 187 | /* Only call ehci_suspend if ehci_setup has been done */ |
| 188 | if (ehci->sbrn) |
| 189 | return ehci_suspend(hcd, do_wakeup); |
| 190 | |
| 191 | return 0; |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static int ehci_msm_pm_resume(struct device *dev) |
| 195 | { |
| 196 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Andy Gross | 815c9d6 | 2016-05-20 16:35:07 -0500 | [diff] [blame] | 197 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 198 | |
| 199 | dev_dbg(dev, "ehci-msm PM resume\n"); |
Andy Gross | 815c9d6 | 2016-05-20 16:35:07 -0500 | [diff] [blame] | 200 | |
| 201 | /* Only call ehci_resume if ehci_setup has been done */ |
| 202 | if (ehci->sbrn) |
| 203 | ehci_resume(hcd, false); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 204 | |
| 205 | return 0; |
| 206 | } |
Andy Gross | 815c9d6 | 2016-05-20 16:35:07 -0500 | [diff] [blame] | 207 | |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 208 | #else |
| 209 | #define ehci_msm_pm_suspend NULL |
| 210 | #define ehci_msm_pm_resume NULL |
| 211 | #endif |
| 212 | |
| 213 | static const struct dev_pm_ops ehci_msm_dev_pm_ops = { |
| 214 | .suspend = ehci_msm_pm_suspend, |
| 215 | .resume = ehci_msm_pm_resume, |
| 216 | }; |
| 217 | |
Jack Pham | f13f0e6 | 2015-12-10 18:28:55 -0600 | [diff] [blame] | 218 | static const struct acpi_device_id msm_ehci_acpi_ids[] = { |
| 219 | { "QCOM8040", 0 }, |
| 220 | { } |
| 221 | }; |
| 222 | MODULE_DEVICE_TABLE(acpi, msm_ehci_acpi_ids); |
| 223 | |
Jingoo Han | 3587fb3 | 2014-06-18 13:33:17 +0900 | [diff] [blame] | 224 | static const struct of_device_id msm_ehci_dt_match[] = { |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 225 | { .compatible = "qcom,ehci-host", }, |
| 226 | {} |
| 227 | }; |
| 228 | MODULE_DEVICE_TABLE(of, msm_ehci_dt_match); |
| 229 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 230 | static struct platform_driver ehci_msm_driver = { |
| 231 | .probe = ehci_msm_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 232 | .remove = ehci_msm_remove, |
Azriel Samson | 4bb3cad | 2015-12-10 18:28:57 -0600 | [diff] [blame] | 233 | .shutdown = usb_hcd_platform_shutdown, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 234 | .driver = { |
| 235 | .name = "msm_hsusb_host", |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 236 | .pm = &ehci_msm_dev_pm_ops, |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 237 | .of_match_table = msm_ehci_dt_match, |
Jack Pham | f13f0e6 | 2015-12-10 18:28:55 -0600 | [diff] [blame] | 238 | .acpi_match_table = ACPI_PTR(msm_ehci_acpi_ids), |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 239 | }, |
| 240 | }; |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 241 | |
Nicolas Pitre | edc8c54 | 2016-04-27 13:28:32 -0400 | [diff] [blame] | 242 | static const struct ehci_driver_overrides msm_overrides __initconst = { |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 243 | .reset = ehci_msm_reset, |
| 244 | }; |
| 245 | |
| 246 | static int __init ehci_msm_init(void) |
| 247 | { |
| 248 | if (usb_disabled()) |
| 249 | return -ENODEV; |
| 250 | |
| 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); |
| 254 | } |
| 255 | module_init(ehci_msm_init); |
| 256 | |
| 257 | static void __exit ehci_msm_cleanup(void) |
| 258 | { |
| 259 | platform_driver_unregister(&ehci_msm_driver); |
| 260 | } |
| 261 | module_exit(ehci_msm_cleanup); |
| 262 | |
| 263 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 264 | MODULE_ALIAS("platform:msm-ehci"); |
| 265 | MODULE_LICENSE("GPL"); |