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> |
| 36 | |
| 37 | #include "ehci.h" |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 38 | |
| 39 | #define MSM_USB_BASE (hcd->regs) |
| 40 | |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 41 | #define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller" |
| 42 | |
| 43 | static const char hcd_name[] = "ehci-msm"; |
| 44 | static struct hc_driver __read_mostly msm_hc_driver; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 45 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 46 | static int ehci_msm_reset(struct usb_hcd *hcd) |
| 47 | { |
| 48 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 49 | int retval; |
| 50 | |
| 51 | ehci->caps = USB_CAPLENGTH; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 52 | hcd->has_tt = 1; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 53 | |
Matthieu CASTET | 2cb30bb | 2011-07-02 20:59:46 +0200 | [diff] [blame] | 54 | retval = ehci_setup(hcd); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 55 | if (retval) |
| 56 | return retval; |
| 57 | |
| 58 | /* bursts of unspecified length. */ |
| 59 | writel(0, USB_AHBBURST); |
| 60 | /* Use the AHB transactor */ |
| 61 | writel(0, USB_AHBMODE); |
| 62 | /* Disable streaming mode and select host mode */ |
| 63 | writel(0x13, USB_USBMODE); |
| 64 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 68 | static int ehci_msm_probe(struct platform_device *pdev) |
| 69 | { |
| 70 | struct usb_hcd *hcd; |
| 71 | struct resource *res; |
Ivan T. Ivanov | e4f0da0 | 2013-10-11 14:46:09 +0300 | [diff] [blame] | 72 | struct usb_phy *phy; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 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 Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 99 | hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 100 | 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 Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 108 | * powering up VBUS, mapping of registers address space and power |
| 109 | * management. |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 110 | */ |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 111 | if (pdev->dev.of_node) |
| 112 | phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); |
| 113 | else |
| 114 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
| 115 | |
Felipe Balbi | e299bd9 | 2013-03-15 11:02:56 +0200 | [diff] [blame] | 116 | if (IS_ERR(phy)) { |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 117 | dev_err(&pdev->dev, "unable to find transceiver\n"); |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 118 | ret = -EPROBE_DEFER; |
Julia Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 119 | goto put_hcd; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 120 | } |
| 121 | |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 122 | ret = otg_set_host(phy->otg, &hcd->self); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 123 | if (ret < 0) { |
| 124 | dev_err(&pdev->dev, "unable to register with transceiver\n"); |
Julia Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 125 | goto put_hcd; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 126 | } |
| 127 | |
Ivan T. Ivanov | e4f0da0 | 2013-10-11 14:46:09 +0300 | [diff] [blame] | 128 | hcd->phy = phy; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 129 | device_init_wakeup(&pdev->dev, 1); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 130 | /* |
| 131 | * OTG device parent of HCD takes care of putting |
| 132 | * hardware into low power mode. |
| 133 | */ |
| 134 | pm_runtime_no_callbacks(&pdev->dev); |
| 135 | pm_runtime_enable(&pdev->dev); |
| 136 | |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 137 | /* FIXME: need to call usb_add_hcd() here? */ |
| 138 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 139 | return 0; |
| 140 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 141 | put_hcd: |
| 142 | usb_put_hcd(hcd); |
| 143 | |
| 144 | return ret; |
| 145 | } |
| 146 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 147 | static int ehci_msm_remove(struct platform_device *pdev) |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 148 | { |
| 149 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 150 | |
| 151 | device_init_wakeup(&pdev->dev, 0); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 152 | pm_runtime_disable(&pdev->dev); |
| 153 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 154 | |
Ivan T. Ivanov | e4f0da0 | 2013-10-11 14:46:09 +0300 | [diff] [blame] | 155 | otg_set_host(hcd->phy->otg, NULL); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 156 | |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 157 | /* FIXME: need to call usb_remove_hcd() here? */ |
| 158 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 159 | usb_put_hcd(hcd); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 164 | #ifdef CONFIG_PM |
| 165 | static int ehci_msm_pm_suspend(struct device *dev) |
| 166 | { |
| 167 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 168 | bool do_wakeup = device_may_wakeup(dev); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 169 | |
| 170 | dev_dbg(dev, "ehci-msm PM suspend\n"); |
| 171 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 172 | return ehci_suspend(hcd, do_wakeup); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static int ehci_msm_pm_resume(struct device *dev) |
| 176 | { |
| 177 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 178 | |
| 179 | dev_dbg(dev, "ehci-msm PM resume\n"); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 180 | ehci_resume(hcd, false); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | #else |
| 185 | #define ehci_msm_pm_suspend NULL |
| 186 | #define ehci_msm_pm_resume NULL |
| 187 | #endif |
| 188 | |
| 189 | static const struct dev_pm_ops ehci_msm_dev_pm_ops = { |
| 190 | .suspend = ehci_msm_pm_suspend, |
| 191 | .resume = ehci_msm_pm_resume, |
| 192 | }; |
| 193 | |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 194 | static struct of_device_id msm_ehci_dt_match[] = { |
| 195 | { .compatible = "qcom,ehci-host", }, |
| 196 | {} |
| 197 | }; |
| 198 | MODULE_DEVICE_TABLE(of, msm_ehci_dt_match); |
| 199 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 200 | static struct platform_driver ehci_msm_driver = { |
| 201 | .probe = ehci_msm_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 202 | .remove = ehci_msm_remove, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 203 | .driver = { |
| 204 | .name = "msm_hsusb_host", |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 205 | .pm = &ehci_msm_dev_pm_ops, |
Ivan T. Ivanov | 0fc924b | 2013-10-11 14:46:10 +0300 | [diff] [blame] | 206 | .of_match_table = msm_ehci_dt_match, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 207 | }, |
| 208 | }; |
Manjunath Goudar | 8c68e84 | 2013-04-02 18:24:03 +0200 | [diff] [blame] | 209 | |
| 210 | static const struct ehci_driver_overrides msm_overrides __initdata = { |
| 211 | .reset = ehci_msm_reset, |
| 212 | }; |
| 213 | |
| 214 | static int __init ehci_msm_init(void) |
| 215 | { |
| 216 | if (usb_disabled()) |
| 217 | return -ENODEV; |
| 218 | |
| 219 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 220 | ehci_init_driver(&msm_hc_driver, &msm_overrides); |
| 221 | return platform_driver_register(&ehci_msm_driver); |
| 222 | } |
| 223 | module_init(ehci_msm_init); |
| 224 | |
| 225 | static void __exit ehci_msm_cleanup(void) |
| 226 | { |
| 227 | platform_driver_unregister(&ehci_msm_driver); |
| 228 | } |
| 229 | module_exit(ehci_msm_cleanup); |
| 230 | |
| 231 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 232 | MODULE_ALIAS("platform:msm-ehci"); |
| 233 | MODULE_LICENSE("GPL"); |