Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 1 | /* |
| 2 | * ohci-omap3.c - driver for OHCI on OMAP3 and later processors |
| 3 | * |
| 4 | * Bus Glue for OMAP3 USBHOST 3 port OHCI controller |
| 5 | * This controller is also used in later OMAPs and AM35x chips |
| 6 | * |
| 7 | * Copyright (C) 2007-2010 Texas Instruments, Inc. |
| 8 | * Author: Vikram Pandita <vikram.pandita@ti.com> |
| 9 | * Author: Anand Gadiyar <gadiyar@ti.com> |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 10 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 11 | * |
| 12 | * Based on ehci-omap.c and some other ohci glue layers |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 | * |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 28 | * TODO (last updated Feb 27, 2011): |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 29 | * - add kernel-doc |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 30 | */ |
| 31 | |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 32 | #include <linux/dma-mapping.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/of.h> |
| 36 | #include <linux/usb/otg.h> |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 37 | #include <linux/platform_device.h> |
Keshava Munegowda | 6c984b0 | 2011-10-11 13:22:11 +0530 | [diff] [blame] | 38 | #include <linux/pm_runtime.h> |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 39 | #include <linux/usb.h> |
| 40 | #include <linux/usb/hcd.h> |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 41 | |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 42 | #include "ohci.h" |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 43 | |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 44 | #define DRIVER_DESC "OHCI OMAP3 driver" |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 45 | |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 46 | static const char hcd_name[] = "ohci-omap3"; |
| 47 | static struct hc_driver __read_mostly ohci_omap3_hc_driver; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * configure so an HC device and id are always provided |
| 51 | * always called with process context; sleeping is OK |
| 52 | */ |
| 53 | |
| 54 | /** |
| 55 | * ohci_hcd_omap3_probe - initialize OMAP-based HCDs |
| 56 | * |
| 57 | * Allocates basic resources for this USB host controller, and |
| 58 | * then invokes the start() method for the HCD associated with it |
| 59 | * through the hotplug entry's driver_data. |
| 60 | */ |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 61 | static int ohci_hcd_omap3_probe(struct platform_device *pdev) |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 62 | { |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 63 | struct device *dev = &pdev->dev; |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 64 | struct ohci_hcd *ohci; |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 65 | struct usb_hcd *hcd = NULL; |
| 66 | void __iomem *regs = NULL; |
| 67 | struct resource *res; |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 68 | int ret; |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 69 | int irq; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 70 | |
| 71 | if (usb_disabled()) |
Keshava Munegowda | 6c984b0 | 2011-10-11 13:22:11 +0530 | [diff] [blame] | 72 | return -ENODEV; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 73 | |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 74 | if (!dev->parent) { |
| 75 | dev_err(dev, "Missing parent device\n"); |
| 76 | return -ENODEV; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 77 | } |
| 78 | |
Roger Quadros | 8c3ec38 | 2013-03-12 12:44:46 +0200 | [diff] [blame] | 79 | irq = platform_get_irq(pdev, 0); |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 80 | if (irq < 0) { |
| 81 | dev_err(dev, "OHCI irq failed\n"); |
| 82 | return -ENODEV; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 83 | } |
| 84 | |
Roger Quadros | 8c3ec38 | 2013-03-12 12:44:46 +0200 | [diff] [blame] | 85 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Julia Lawall | d80cba6 | 2011-08-22 16:00:35 +0200 | [diff] [blame] | 86 | if (!res) { |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 87 | dev_err(dev, "UHH OHCI get resource failed\n"); |
| 88 | return -ENOMEM; |
| 89 | } |
| 90 | |
| 91 | regs = ioremap(res->start, resource_size(res)); |
| 92 | if (!regs) { |
| 93 | dev_err(dev, "UHH OHCI ioremap failed\n"); |
| 94 | return -ENOMEM; |
| 95 | } |
| 96 | |
Roger Quadros | 5867320 | 2013-03-12 12:44:47 +0200 | [diff] [blame] | 97 | /* |
| 98 | * Right now device-tree probed devices don't get dma_mask set. |
| 99 | * Since shared usb code relies on it, set it here for now. |
| 100 | * Once we have dma capability bindings this can go away. |
| 101 | */ |
Russell King | e1fd734 | 2013-06-27 12:36:37 +0100 | [diff] [blame] | 102 | ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 103 | if (ret) |
| 104 | goto err_io; |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 105 | |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 106 | ret = -ENODEV; |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 107 | hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev, |
| 108 | dev_name(dev)); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 109 | if (!hcd) { |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 110 | dev_err(dev, "usb_create_hcd failed\n"); |
| 111 | goto err_io; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 112 | } |
| 113 | |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 114 | hcd->rsrc_start = res->start; |
| 115 | hcd->rsrc_len = resource_size(res); |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 116 | hcd->regs = regs; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 117 | |
Keshava Munegowda | 6c984b0 | 2011-10-11 13:22:11 +0530 | [diff] [blame] | 118 | pm_runtime_enable(dev); |
| 119 | pm_runtime_get_sync(dev); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 120 | |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 121 | ohci = hcd_to_ohci(hcd); |
| 122 | /* |
| 123 | * RemoteWakeupConnected has to be set explicitly before |
| 124 | * calling ohci_run. The reset value of RWC is 0. |
| 125 | */ |
| 126 | ohci->hc_control = OHCI_CTRL_RWC; |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 127 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 128 | ret = usb_add_hcd(hcd, irq, 0); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 129 | if (ret) { |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 130 | dev_dbg(dev, "failed to add hcd with err %d\n", ret); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 131 | goto err_add_hcd; |
| 132 | } |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 133 | device_wakeup_enable(hcd->self.controller); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 134 | |
| 135 | return 0; |
| 136 | |
| 137 | err_add_hcd: |
Keshava Munegowda | 6c984b0 | 2011-10-11 13:22:11 +0530 | [diff] [blame] | 138 | pm_runtime_put_sync(dev); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 139 | usb_put_hcd(hcd); |
| 140 | |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 141 | err_io: |
| 142 | iounmap(regs); |
| 143 | |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * may be called without controller electrically present |
| 149 | * may be called with controller, bus, and devices active |
| 150 | */ |
| 151 | |
| 152 | /** |
| 153 | * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs |
| 154 | * @pdev: USB Host Controller being removed |
| 155 | * |
| 156 | * Reverses the effect of ohci_hcd_omap3_probe(), first invoking |
| 157 | * the HCD's stop() method. It is always called from a thread |
| 158 | * context, normally "rmmod", "apmd", or something similar. |
| 159 | */ |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 160 | static int ohci_hcd_omap3_remove(struct platform_device *pdev) |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 161 | { |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 162 | struct device *dev = &pdev->dev; |
| 163 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 164 | |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 165 | iounmap(hcd->regs); |
Keshava Munegowda | 1940316 | 2011-03-01 20:08:21 +0530 | [diff] [blame] | 166 | usb_remove_hcd(hcd); |
Keshava Munegowda | 6c984b0 | 2011-10-11 13:22:11 +0530 | [diff] [blame] | 167 | pm_runtime_put_sync(dev); |
| 168 | pm_runtime_disable(dev); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 169 | usb_put_hcd(hcd); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
Roger Quadros | 5867320 | 2013-03-12 12:44:47 +0200 | [diff] [blame] | 173 | static const struct of_device_id omap_ohci_dt_ids[] = { |
| 174 | { .compatible = "ti,ohci-omap3" }, |
| 175 | { } |
| 176 | }; |
| 177 | |
| 178 | MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids); |
| 179 | |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 180 | static struct platform_driver ohci_hcd_omap3_driver = { |
| 181 | .probe = ohci_hcd_omap3_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 182 | .remove = ohci_hcd_omap3_remove, |
Roger Quadros | aaf6b52 | 2013-07-22 15:04:50 +0300 | [diff] [blame] | 183 | .shutdown = usb_hcd_platform_shutdown, |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 184 | .driver = { |
| 185 | .name = "ohci-omap3", |
Sachin Kamat | 7a1cc24 | 2013-05-21 17:17:19 +0530 | [diff] [blame] | 186 | .of_match_table = omap_ohci_dt_ids, |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 187 | }, |
| 188 | }; |
| 189 | |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 190 | static int __init ohci_omap3_init(void) |
| 191 | { |
| 192 | if (usb_disabled()) |
| 193 | return -ENODEV; |
| 194 | |
| 195 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 196 | |
| 197 | ohci_init_driver(&ohci_omap3_hc_driver, NULL); |
| 198 | return platform_driver_register(&ohci_hcd_omap3_driver); |
| 199 | } |
| 200 | module_init(ohci_omap3_init); |
| 201 | |
| 202 | static void __exit ohci_omap3_cleanup(void) |
| 203 | { |
| 204 | platform_driver_unregister(&ohci_hcd_omap3_driver); |
| 205 | } |
| 206 | module_exit(ohci_omap3_cleanup); |
| 207 | |
| 208 | MODULE_DESCRIPTION(DRIVER_DESC); |
Anand Gadiyar | 88ed0c9 | 2010-05-10 21:56:11 +0530 | [diff] [blame] | 209 | MODULE_ALIAS("platform:ohci-omap3"); |
| 210 | MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>"); |
Manjunath Goudar | 3a48fef | 2013-09-21 16:38:40 +0530 | [diff] [blame] | 211 | MODULE_LICENSE("GPL"); |