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