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 | |
| 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 | |
Matthieu CASTET | 2cb30bb | 2011-07-02 20:59:46 +0200 | [diff] [blame] | 45 | retval = ehci_setup(hcd); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 46 | if (retval) |
| 47 | return retval; |
| 48 | |
| 49 | /* bursts of unspecified length. */ |
| 50 | writel(0, USB_AHBBURST); |
| 51 | /* Use the AHB transactor */ |
| 52 | writel(0, USB_AHBMODE); |
| 53 | /* Disable streaming mode and select host mode */ |
| 54 | writel(0x13, USB_USBMODE); |
| 55 | |
| 56 | ehci_port_power(ehci, 1); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static struct hc_driver msm_hc_driver = { |
| 61 | .description = hcd_name, |
| 62 | .product_desc = "Qualcomm On-Chip EHCI Host Controller", |
| 63 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 64 | |
| 65 | /* |
| 66 | * generic hardware linkage |
| 67 | */ |
| 68 | .irq = ehci_irq, |
| 69 | .flags = HCD_USB2 | HCD_MEMORY, |
| 70 | |
| 71 | .reset = ehci_msm_reset, |
Matthieu CASTET | 5c8d61b | 2011-02-15 18:41:54 +0100 | [diff] [blame] | 72 | .start = ehci_run, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 73 | |
| 74 | .stop = ehci_stop, |
| 75 | .shutdown = ehci_shutdown, |
| 76 | |
| 77 | /* |
| 78 | * managing i/o requests and associated device resources |
| 79 | */ |
| 80 | .urb_enqueue = ehci_urb_enqueue, |
| 81 | .urb_dequeue = ehci_urb_dequeue, |
| 82 | .endpoint_disable = ehci_endpoint_disable, |
| 83 | .endpoint_reset = ehci_endpoint_reset, |
| 84 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 85 | |
| 86 | /* |
| 87 | * scheduling support |
| 88 | */ |
| 89 | .get_frame_number = ehci_get_frame, |
| 90 | |
| 91 | /* |
| 92 | * root hub support |
| 93 | */ |
| 94 | .hub_status_data = ehci_hub_status_data, |
| 95 | .hub_control = ehci_hub_control, |
| 96 | .relinquish_port = ehci_relinquish_port, |
| 97 | .port_handed_over = ehci_port_handed_over, |
| 98 | |
| 99 | /* |
| 100 | * PM support |
| 101 | */ |
| 102 | .bus_suspend = ehci_bus_suspend, |
| 103 | .bus_resume = ehci_bus_resume, |
| 104 | }; |
| 105 | |
| 106 | static int ehci_msm_probe(struct platform_device *pdev) |
| 107 | { |
| 108 | struct usb_hcd *hcd; |
| 109 | struct resource *res; |
| 110 | int ret; |
| 111 | |
| 112 | dev_dbg(&pdev->dev, "ehci_msm proble\n"); |
| 113 | |
| 114 | hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev)); |
| 115 | if (!hcd) { |
| 116 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 117 | return -ENOMEM; |
| 118 | } |
| 119 | |
| 120 | hcd->irq = platform_get_irq(pdev, 0); |
| 121 | if (hcd->irq < 0) { |
| 122 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 123 | ret = hcd->irq; |
| 124 | goto put_hcd; |
| 125 | } |
| 126 | |
| 127 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 128 | if (!res) { |
| 129 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 130 | ret = -ENODEV; |
| 131 | goto put_hcd; |
| 132 | } |
| 133 | |
| 134 | hcd->rsrc_start = res->start; |
| 135 | hcd->rsrc_len = resource_size(res); |
Julia Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 136 | hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 137 | if (!hcd->regs) { |
| 138 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 139 | ret = -ENOMEM; |
| 140 | goto put_hcd; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * OTG driver takes care of PHY initialization, clock management, |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 145 | * powering up VBUS, mapping of registers address space and power |
| 146 | * management. |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 147 | */ |
Julia Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 148 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
Kishon Vijay Abraham I | ded017e | 2012-06-26 17:40:32 +0530 | [diff] [blame] | 149 | if (IS_ERR_OR_NULL(phy)) { |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 150 | dev_err(&pdev->dev, "unable to find transceiver\n"); |
| 151 | ret = -ENODEV; |
Julia Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 152 | goto put_hcd; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 153 | } |
| 154 | |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 155 | ret = otg_set_host(phy->otg, &hcd->self); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 156 | if (ret < 0) { |
| 157 | dev_err(&pdev->dev, "unable to register with transceiver\n"); |
Julia Lawall | df5eb3f | 2012-07-29 21:46:11 +0200 | [diff] [blame] | 158 | goto put_hcd; |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | device_init_wakeup(&pdev->dev, 1); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 162 | /* |
| 163 | * OTG device parent of HCD takes care of putting |
| 164 | * hardware into low power mode. |
| 165 | */ |
| 166 | pm_runtime_no_callbacks(&pdev->dev); |
| 167 | pm_runtime_enable(&pdev->dev); |
| 168 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 169 | return 0; |
| 170 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 171 | put_hcd: |
| 172 | usb_put_hcd(hcd); |
| 173 | |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | static int __devexit ehci_msm_remove(struct platform_device *pdev) |
| 178 | { |
| 179 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 180 | |
| 181 | device_init_wakeup(&pdev->dev, 0); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 182 | pm_runtime_disable(&pdev->dev); |
| 183 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 184 | |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 185 | otg_set_host(phy->otg, NULL); |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 186 | |
| 187 | usb_put_hcd(hcd); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 192 | #ifdef CONFIG_PM |
| 193 | static int ehci_msm_pm_suspend(struct device *dev) |
| 194 | { |
| 195 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 196 | bool do_wakeup = device_may_wakeup(dev); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 197 | |
| 198 | dev_dbg(dev, "ehci-msm PM suspend\n"); |
| 199 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 200 | return ehci_suspend(hcd, do_wakeup); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static int ehci_msm_pm_resume(struct device *dev) |
| 204 | { |
| 205 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 206 | |
| 207 | dev_dbg(dev, "ehci-msm PM resume\n"); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 208 | ehci_resume(hcd, false); |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | #else |
| 213 | #define ehci_msm_pm_suspend NULL |
| 214 | #define ehci_msm_pm_resume NULL |
| 215 | #endif |
| 216 | |
| 217 | static const struct dev_pm_ops ehci_msm_dev_pm_ops = { |
| 218 | .suspend = ehci_msm_pm_suspend, |
| 219 | .resume = ehci_msm_pm_resume, |
| 220 | }; |
| 221 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 222 | static struct platform_driver ehci_msm_driver = { |
| 223 | .probe = ehci_msm_probe, |
| 224 | .remove = __devexit_p(ehci_msm_remove), |
| 225 | .driver = { |
| 226 | .name = "msm_hsusb_host", |
Pavankumar Kondeti | 8bb6a16 | 2010-12-07 17:53:57 +0530 | [diff] [blame] | 227 | .pm = &ehci_msm_dev_pm_ops, |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 228 | }, |
| 229 | }; |