Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.0 226 lines 5.5 kB view raw
1/* ehci-msm.c - HSUSB Host Controller Driver Implementation 2 * 3 * Copyright (c) 2008-2011, 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/clk.h> 26#include <linux/err.h> 27#include <linux/io.h> 28#include <linux/kernel.h> 29#include <linux/module.h> 30#include <linux/platform_device.h> 31#include <linux/pm_runtime.h> 32#include <linux/usb/otg.h> 33#include <linux/usb/msm_hsusb_hw.h> 34#include <linux/usb.h> 35#include <linux/usb/hcd.h> 36 37#include "ehci.h" 38 39#define MSM_USB_BASE (hcd->regs) 40 41#define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller" 42 43static const char hcd_name[] = "ehci-msm"; 44static struct hc_driver __read_mostly msm_hc_driver; 45 46static 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; 52 hcd->has_tt = 1; 53 54 retval = ehci_setup(hcd); 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 65 return 0; 66} 67 68static int ehci_msm_probe(struct platform_device *pdev) 69{ 70 struct usb_hcd *hcd; 71 struct resource *res; 72 struct usb_phy *phy; 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 hcd->regs = devm_ioremap_resource(&pdev->dev, res); 92 if (IS_ERR(hcd->regs)) { 93 ret = PTR_ERR(hcd->regs); 94 goto put_hcd; 95 } 96 hcd->rsrc_start = res->start; 97 hcd->rsrc_len = resource_size(res); 98 99 /* 100 * OTG driver takes care of PHY initialization, clock management, 101 * powering up VBUS, mapping of registers address space and power 102 * management. 103 */ 104 if (pdev->dev.of_node) 105 phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); 106 else 107 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 108 109 if (IS_ERR(phy)) { 110 dev_err(&pdev->dev, "unable to find transceiver\n"); 111 ret = -EPROBE_DEFER; 112 goto put_hcd; 113 } 114 115 ret = otg_set_host(phy->otg, &hcd->self); 116 if (ret < 0) { 117 dev_err(&pdev->dev, "unable to register with transceiver\n"); 118 goto put_hcd; 119 } 120 121 hcd->usb_phy = phy; 122 device_init_wakeup(&pdev->dev, 1); 123 /* 124 * OTG device parent of HCD takes care of putting 125 * hardware into low power mode. 126 */ 127 pm_runtime_no_callbacks(&pdev->dev); 128 pm_runtime_enable(&pdev->dev); 129 130 /* FIXME: need to call usb_add_hcd() here? */ 131 132 return 0; 133 134put_hcd: 135 usb_put_hcd(hcd); 136 137 return ret; 138} 139 140static int ehci_msm_remove(struct platform_device *pdev) 141{ 142 struct usb_hcd *hcd = platform_get_drvdata(pdev); 143 144 device_init_wakeup(&pdev->dev, 0); 145 pm_runtime_disable(&pdev->dev); 146 pm_runtime_set_suspended(&pdev->dev); 147 148 otg_set_host(hcd->usb_phy->otg, NULL); 149 150 /* FIXME: need to call usb_remove_hcd() here? */ 151 152 usb_put_hcd(hcd); 153 154 return 0; 155} 156 157#ifdef CONFIG_PM 158static int ehci_msm_pm_suspend(struct device *dev) 159{ 160 struct usb_hcd *hcd = dev_get_drvdata(dev); 161 bool do_wakeup = device_may_wakeup(dev); 162 163 dev_dbg(dev, "ehci-msm PM suspend\n"); 164 165 return ehci_suspend(hcd, do_wakeup); 166} 167 168static int ehci_msm_pm_resume(struct device *dev) 169{ 170 struct usb_hcd *hcd = dev_get_drvdata(dev); 171 172 dev_dbg(dev, "ehci-msm PM resume\n"); 173 ehci_resume(hcd, false); 174 175 return 0; 176} 177#else 178#define ehci_msm_pm_suspend NULL 179#define ehci_msm_pm_resume NULL 180#endif 181 182static const struct dev_pm_ops ehci_msm_dev_pm_ops = { 183 .suspend = ehci_msm_pm_suspend, 184 .resume = ehci_msm_pm_resume, 185}; 186 187static const struct of_device_id msm_ehci_dt_match[] = { 188 { .compatible = "qcom,ehci-host", }, 189 {} 190}; 191MODULE_DEVICE_TABLE(of, msm_ehci_dt_match); 192 193static struct platform_driver ehci_msm_driver = { 194 .probe = ehci_msm_probe, 195 .remove = ehci_msm_remove, 196 .driver = { 197 .name = "msm_hsusb_host", 198 .pm = &ehci_msm_dev_pm_ops, 199 .of_match_table = msm_ehci_dt_match, 200 }, 201}; 202 203static const struct ehci_driver_overrides msm_overrides __initdata = { 204 .reset = ehci_msm_reset, 205}; 206 207static int __init ehci_msm_init(void) 208{ 209 if (usb_disabled()) 210 return -ENODEV; 211 212 pr_info("%s: " DRIVER_DESC "\n", hcd_name); 213 ehci_init_driver(&msm_hc_driver, &msm_overrides); 214 return platform_driver_register(&ehci_msm_driver); 215} 216module_init(ehci_msm_init); 217 218static void __exit ehci_msm_cleanup(void) 219{ 220 platform_driver_unregister(&ehci_msm_driver); 221} 222module_exit(ehci_msm_cleanup); 223 224MODULE_DESCRIPTION(DRIVER_DESC); 225MODULE_ALIAS("platform:msm-ehci"); 226MODULE_LICENSE("GPL");