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