Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 1 | /* ehci-msm.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2008-2012, The Linux Foundation. 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 | |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/err.h> |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 28 | #include <linux/pm_runtime.h> |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 29 | |
| 30 | #include <linux/usb/otg.h> |
| 31 | #include <linux/usb/msm_hsusb_hw.h> |
| 32 | |
| 33 | #define MSM_USB_BASE (hcd->regs) |
| 34 | |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 35 | static struct usb_phy *phy; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 36 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 37 | static int ehci_msm_reset(struct usb_hcd *hcd) |
| 38 | { |
| 39 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 40 | int retval; |
| 41 | |
| 42 | ehci->caps = USB_CAPLENGTH; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 43 | hcd->has_tt = 1; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 44 | |
Parth Dixit | bb63412 | 2013-10-07 16:19:09 +0530 | [diff] [blame] | 45 | ehci->log2_irq_thresh = 5; |
| 46 | |
Matthieu CASTET | 2cb30bb | 2011-07-02 20:59:46 +0200 | [diff] [blame] | 47 | retval = ehci_setup(hcd); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 48 | if (retval) |
| 49 | return retval; |
| 50 | |
| 51 | /* bursts of unspecified length. */ |
| 52 | writel(0, USB_AHBBURST); |
| 53 | /* Use the AHB transactor */ |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 54 | writel_relaxed(0x08, USB_AHBMODE); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 55 | /* Disable streaming mode and select host mode */ |
| 56 | writel(0x13, USB_USBMODE); |
| 57 | |
| 58 | ehci_port_power(ehci, 1); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static struct hc_driver msm_hc_driver = { |
| 63 | .description = hcd_name, |
| 64 | .product_desc = "Qualcomm On-Chip EHCI Host Controller", |
| 65 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 66 | |
| 67 | /* |
| 68 | * generic hardware linkage |
| 69 | */ |
| 70 | .irq = ehci_irq, |
| 71 | .flags = HCD_USB2 | HCD_MEMORY, |
| 72 | |
| 73 | .reset = ehci_msm_reset, |
Matthieu CASTET | 5c8d61b | 2011-02-15 18:41:54 +0100 | [diff] [blame] | 74 | .start = ehci_run, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 75 | |
| 76 | .stop = ehci_stop, |
| 77 | .shutdown = ehci_shutdown, |
| 78 | |
| 79 | /* |
| 80 | * managing i/o requests and associated device resources |
| 81 | */ |
| 82 | .urb_enqueue = ehci_urb_enqueue, |
| 83 | .urb_dequeue = ehci_urb_dequeue, |
| 84 | .endpoint_disable = ehci_endpoint_disable, |
| 85 | .endpoint_reset = ehci_endpoint_reset, |
| 86 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 87 | |
| 88 | /* |
| 89 | * scheduling support |
| 90 | */ |
| 91 | .get_frame_number = ehci_get_frame, |
| 92 | |
| 93 | /* |
| 94 | * root hub support |
| 95 | */ |
| 96 | .hub_status_data = ehci_hub_status_data, |
| 97 | .hub_control = ehci_hub_control, |
| 98 | .relinquish_port = ehci_relinquish_port, |
| 99 | .port_handed_over = ehci_port_handed_over, |
| 100 | |
| 101 | /* |
| 102 | * PM support |
| 103 | */ |
| 104 | .bus_suspend = ehci_bus_suspend, |
| 105 | .bus_resume = ehci_bus_resume, |
| 106 | }; |
| 107 | |
Manu Gautam | 2ab6498 | 2013-06-04 16:43:25 +0530 | [diff] [blame] | 108 | static u64 msm_ehci_dma_mask = DMA_BIT_MASK(64); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 109 | static int ehci_msm_probe(struct platform_device *pdev) |
| 110 | { |
| 111 | struct usb_hcd *hcd; |
| 112 | struct resource *res; |
| 113 | int ret; |
| 114 | |
| 115 | dev_dbg(&pdev->dev, "ehci_msm proble\n"); |
| 116 | |
Manu Gautam | 2ab6498 | 2013-06-04 16:43:25 +0530 | [diff] [blame] | 117 | if (!pdev->dev.dma_mask) |
| 118 | pdev->dev.dma_mask = &msm_ehci_dma_mask; |
| 119 | if (!pdev->dev.coherent_dma_mask) |
| 120 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 121 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 122 | hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev)); |
| 123 | if (!hcd) { |
| 124 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 125 | return -ENOMEM; |
| 126 | } |
| 127 | |
Manu Gautam | da465fc | 2013-03-19 15:30:08 +0530 | [diff] [blame] | 128 | hcd_to_bus(hcd)->skip_resume = true; |
| 129 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 130 | hcd->irq = platform_get_irq(pdev, 0); |
| 131 | if (hcd->irq < 0) { |
| 132 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 133 | ret = hcd->irq; |
| 134 | goto put_hcd; |
| 135 | } |
| 136 | |
| 137 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 138 | if (!res) { |
| 139 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 140 | ret = -ENODEV; |
| 141 | goto put_hcd; |
| 142 | } |
| 143 | |
| 144 | hcd->rsrc_start = res->start; |
| 145 | hcd->rsrc_len = resource_size(res); |
| 146 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 147 | if (!hcd->regs) { |
| 148 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 149 | ret = -ENOMEM; |
| 150 | goto put_hcd; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * OTG driver takes care of PHY initialization, clock management, |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 155 | * powering up VBUS, mapping of registers address space and power |
| 156 | * management. |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 157 | */ |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 158 | phy = usb_get_transceiver(); |
| 159 | if (!phy) { |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 160 | dev_err(&pdev->dev, "unable to find transceiver\n"); |
| 161 | ret = -ENODEV; |
| 162 | goto unmap; |
| 163 | } |
| 164 | |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 165 | ret = otg_set_host(phy->otg, &hcd->self); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 166 | if (ret < 0) { |
| 167 | dev_err(&pdev->dev, "unable to register with transceiver\n"); |
| 168 | goto put_transceiver; |
| 169 | } |
| 170 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 171 | hcd_to_ehci(hcd)->transceiver = phy; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 172 | device_init_wakeup(&pdev->dev, 1); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 173 | pm_runtime_enable(&pdev->dev); |
| 174 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 175 | return 0; |
| 176 | |
| 177 | put_transceiver: |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 178 | usb_put_transceiver(phy); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 179 | unmap: |
| 180 | iounmap(hcd->regs); |
| 181 | put_hcd: |
| 182 | usb_put_hcd(hcd); |
| 183 | |
| 184 | return ret; |
| 185 | } |
| 186 | |
| 187 | static int __devexit ehci_msm_remove(struct platform_device *pdev) |
| 188 | { |
| 189 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 190 | |
| 191 | device_init_wakeup(&pdev->dev, 0); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 192 | pm_runtime_disable(&pdev->dev); |
| 193 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 194 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 195 | hcd_to_ehci(hcd)->transceiver = NULL; |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 196 | otg_set_host(phy->otg, NULL); |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 197 | usb_put_transceiver(phy); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 198 | |
| 199 | usb_put_hcd(hcd); |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 204 | #ifdef CONFIG_PM_RUNTIME |
| 205 | static int ehci_msm_runtime_idle(struct device *dev) |
| 206 | { |
| 207 | dev_dbg(dev, "ehci runtime idle\n"); |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static int ehci_msm_runtime_suspend(struct device *dev) |
| 212 | { |
| 213 | dev_dbg(dev, "ehci runtime suspend\n"); |
| 214 | /* |
| 215 | * Notify OTG about suspend. It takes care of |
| 216 | * putting the hardware in LPM. |
| 217 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 218 | return usb_phy_set_suspend(phy, 1); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int ehci_msm_runtime_resume(struct device *dev) |
| 222 | { |
| 223 | dev_dbg(dev, "ehci runtime resume\n"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 224 | return usb_phy_set_suspend(phy, 0); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 225 | } |
| 226 | #endif |
| 227 | |
| 228 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 229 | static int ehci_msm_pm_suspend(struct device *dev) |
| 230 | { |
| 231 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 232 | bool wakeup = device_may_wakeup(dev); |
| 233 | |
| 234 | dev_dbg(dev, "ehci-msm PM suspend\n"); |
| 235 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 236 | if (!hcd->rh_registered) |
| 237 | return 0; |
| 238 | |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 239 | /* |
| 240 | * EHCI helper function has also the same check before manipulating |
| 241 | * port wakeup flags. We do check here the same condition before |
| 242 | * calling the same helper function to avoid bringing hardware |
| 243 | * from Low power mode when there is no need for adjusting port |
| 244 | * wakeup flags. |
| 245 | */ |
| 246 | if (hcd->self.root_hub->do_remote_wakeup && !wakeup) { |
| 247 | pm_runtime_resume(dev); |
| 248 | ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), |
| 249 | wakeup); |
| 250 | } |
| 251 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 252 | return usb_phy_set_suspend(phy, 1); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static int ehci_msm_pm_resume(struct device *dev) |
| 256 | { |
| 257 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 258 | |
| 259 | dev_dbg(dev, "ehci-msm PM resume\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | |
| 261 | if (!hcd->rh_registered) |
| 262 | return 0; |
| 263 | |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 264 | ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); |
| 265 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 266 | return usb_phy_set_suspend(phy, 0); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 267 | } |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 268 | #endif |
| 269 | |
| 270 | static const struct dev_pm_ops ehci_msm_dev_pm_ops = { |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 271 | SET_SYSTEM_SLEEP_PM_OPS(ehci_msm_pm_suspend, ehci_msm_pm_resume) |
| 272 | SET_RUNTIME_PM_OPS(ehci_msm_runtime_suspend, ehci_msm_runtime_resume, |
| 273 | ehci_msm_runtime_idle) |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 274 | }; |
| 275 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 276 | static struct platform_driver ehci_msm_driver = { |
| 277 | .probe = ehci_msm_probe, |
| 278 | .remove = __devexit_p(ehci_msm_remove), |
| 279 | .driver = { |
| 280 | .name = "msm_hsusb_host", |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 281 | .pm = &ehci_msm_dev_pm_ops, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 282 | }, |
| 283 | }; |