Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 1 | /* |
| 2 | * OHCI HCD (Host Controller Driver) for USB. |
| 3 | * |
| 4 | * TI DA8xx (OMAP-L1x) Bus Glue |
| 5 | * |
| 6 | * Derived from: ohci-omap.c and ohci-s3c2410.c |
| 7 | * Copyright (C) 2008-2009 MontaVista Software, Inc. <source@mvista.com> |
| 8 | * |
| 9 | * This file is licensed under the terms of the GNU General Public License |
| 10 | * version 2. This program is licensed "as is" without any warranty of any |
| 11 | * kind, whether express or implied. |
| 12 | */ |
| 13 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 14 | #include <linux/clk.h> |
| 15 | #include <linux/io.h> |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/jiffies.h> |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 21 | #include <linux/phy/phy.h> |
Arnd Bergmann | ec2a083 | 2012-08-24 15:11:34 +0200 | [diff] [blame] | 22 | #include <linux/platform_data/usb-davinci.h> |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 23 | #include <linux/usb.h> |
| 24 | #include <linux/usb/hcd.h> |
| 25 | #include <asm/unaligned.h> |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 26 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 27 | #include "ohci.h" |
| 28 | |
| 29 | #define DRIVER_DESC "DA8XX" |
| 30 | #define DRV_NAME "ohci" |
| 31 | |
| 32 | static struct hc_driver __read_mostly ohci_da8xx_hc_driver; |
| 33 | |
| 34 | static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, |
| 35 | u16 wValue, u16 wIndex, char *buf, u16 wLength); |
| 36 | static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 37 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 38 | static struct clk *usb11_clk; |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 39 | static struct phy *usb11_phy; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 40 | |
| 41 | /* Over-current indicator change bitmask */ |
| 42 | static volatile u16 ocic_mask; |
| 43 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 44 | static int ohci_da8xx_enable(void) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 45 | { |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 46 | int ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 47 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 48 | ret = clk_prepare_enable(usb11_clk); |
| 49 | if (ret) |
| 50 | return ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 51 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 52 | ret = phy_init(usb11_phy); |
| 53 | if (ret) |
| 54 | goto err_phy_init; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 55 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 56 | ret = phy_power_on(usb11_phy); |
| 57 | if (ret) |
| 58 | goto err_phy_power_on; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 59 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 60 | return 0; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 61 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 62 | err_phy_power_on: |
| 63 | phy_exit(usb11_phy); |
| 64 | err_phy_init: |
| 65 | clk_disable_unprepare(usb11_clk); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 66 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | static void ohci_da8xx_disable(void) |
| 71 | { |
| 72 | phy_power_off(usb11_phy); |
| 73 | phy_exit(usb11_phy); |
| 74 | clk_disable_unprepare(usb11_clk); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Handle the port over-current indicator change. |
| 79 | */ |
| 80 | static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub, |
| 81 | unsigned port) |
| 82 | { |
| 83 | ocic_mask |= 1 << port; |
| 84 | |
| 85 | /* Once over-current is detected, the port needs to be powered down */ |
| 86 | if (hub->get_oci(port) > 0) |
| 87 | hub->set_power(port, 0); |
| 88 | } |
| 89 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 90 | static int ohci_da8xx_reset(struct usb_hcd *hcd) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 91 | { |
| 92 | struct device *dev = hcd->self.controller; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 93 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 94 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 95 | int result; |
| 96 | u32 rh_a; |
| 97 | |
| 98 | dev_dbg(dev, "starting USB controller\n"); |
| 99 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 100 | result = ohci_da8xx_enable(); |
| 101 | if (result < 0) |
| 102 | return result; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * DA8xx only have 1 port connected to the pins but the HC root hub |
| 106 | * register A reports 2 ports, thus we'll have to override it... |
| 107 | */ |
| 108 | ohci->num_ports = 1; |
| 109 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 110 | result = ohci_setup(hcd); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 111 | if (result < 0) { |
| 112 | ohci_da8xx_disable(); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 113 | return result; |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 114 | } |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Since we're providing a board-specific root hub port power control |
| 118 | * and over-current reporting, we have to override the HC root hub A |
| 119 | * register's default value, so that ohci_hub_control() could return |
| 120 | * the correct hub descriptor... |
| 121 | */ |
| 122 | rh_a = ohci_readl(ohci, &ohci->regs->roothub.a); |
| 123 | if (hub->set_power) { |
| 124 | rh_a &= ~RH_A_NPS; |
| 125 | rh_a |= RH_A_PSM; |
| 126 | } |
| 127 | if (hub->get_oci) { |
| 128 | rh_a &= ~RH_A_NOCP; |
| 129 | rh_a |= RH_A_OCPM; |
| 130 | } |
| 131 | rh_a &= ~RH_A_POTPGT; |
| 132 | rh_a |= hub->potpgt << 24; |
| 133 | ohci_writel(ohci, rh_a, &ohci->regs->roothub.a); |
| 134 | |
| 135 | return result; |
| 136 | } |
| 137 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 138 | /* |
| 139 | * Update the status data from the hub with the over-current indicator change. |
| 140 | */ |
| 141 | static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 142 | { |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 143 | int length = orig_ohci_hub_status_data(hcd, buf); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 144 | |
| 145 | /* See if we have OCIC bit set on port 1 */ |
| 146 | if (ocic_mask & (1 << 1)) { |
| 147 | dev_dbg(hcd->self.controller, "over-current indicator change " |
| 148 | "on port 1\n"); |
| 149 | |
| 150 | if (!length) |
| 151 | length = 1; |
| 152 | |
| 153 | buf[0] |= 1 << 1; |
| 154 | } |
| 155 | return length; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Look at the control requests to the root hub and see if we need to override. |
| 160 | */ |
| 161 | static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 162 | u16 wIndex, char *buf, u16 wLength) |
| 163 | { |
| 164 | struct device *dev = hcd->self.controller; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 165 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 166 | int temp; |
| 167 | |
| 168 | switch (typeReq) { |
| 169 | case GetPortStatus: |
| 170 | /* Check the port number */ |
| 171 | if (wIndex != 1) |
| 172 | break; |
| 173 | |
| 174 | dev_dbg(dev, "GetPortStatus(%u)\n", wIndex); |
| 175 | |
| 176 | temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1); |
| 177 | |
| 178 | /* The port power status (PPS) bit defaults to 1 */ |
| 179 | if (hub->get_power && hub->get_power(wIndex) == 0) |
| 180 | temp &= ~RH_PS_PPS; |
| 181 | |
| 182 | /* The port over-current indicator (POCI) bit is always 0 */ |
| 183 | if (hub->get_oci && hub->get_oci(wIndex) > 0) |
| 184 | temp |= RH_PS_POCI; |
| 185 | |
| 186 | /* The over-current indicator change (OCIC) bit is 0 too */ |
| 187 | if (ocic_mask & (1 << wIndex)) |
| 188 | temp |= RH_PS_OCIC; |
| 189 | |
| 190 | put_unaligned(cpu_to_le32(temp), (__le32 *)buf); |
| 191 | return 0; |
| 192 | case SetPortFeature: |
| 193 | temp = 1; |
| 194 | goto check_port; |
| 195 | case ClearPortFeature: |
| 196 | temp = 0; |
| 197 | |
| 198 | check_port: |
| 199 | /* Check the port number */ |
| 200 | if (wIndex != 1) |
| 201 | break; |
| 202 | |
| 203 | switch (wValue) { |
| 204 | case USB_PORT_FEAT_POWER: |
| 205 | dev_dbg(dev, "%sPortFeature(%u): %s\n", |
| 206 | temp ? "Set" : "Clear", wIndex, "POWER"); |
| 207 | |
| 208 | if (!hub->set_power) |
| 209 | return -EPIPE; |
| 210 | |
| 211 | return hub->set_power(wIndex, temp) ? -EPIPE : 0; |
| 212 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 213 | dev_dbg(dev, "%sPortFeature(%u): %s\n", |
| 214 | temp ? "Set" : "Clear", wIndex, |
| 215 | "C_OVER_CURRENT"); |
| 216 | |
| 217 | if (temp) |
| 218 | ocic_mask |= 1 << wIndex; |
| 219 | else |
| 220 | ocic_mask &= ~(1 << wIndex); |
| 221 | return 0; |
| 222 | } |
| 223 | } |
| 224 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 225 | return orig_ohci_hub_control(hcd, typeReq, wValue, |
| 226 | wIndex, buf, wLength); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 227 | } |
| 228 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 229 | /*-------------------------------------------------------------------------*/ |
| 230 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 231 | static int ohci_da8xx_probe(struct platform_device *pdev) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 232 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 233 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 234 | struct usb_hcd *hcd; |
| 235 | struct resource *mem; |
| 236 | int error, irq; |
| 237 | |
| 238 | if (hub == NULL) |
| 239 | return -ENODEV; |
| 240 | |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 241 | usb11_clk = devm_clk_get(&pdev->dev, "usb11"); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 242 | if (IS_ERR(usb11_clk)) { |
| 243 | if (PTR_ERR(usb11_clk) != -EPROBE_DEFER) |
| 244 | dev_err(&pdev->dev, "Failed to get clock.\n"); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 245 | return PTR_ERR(usb11_clk); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 246 | } |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 247 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 248 | usb11_phy = devm_phy_get(&pdev->dev, "usb-phy"); |
| 249 | if (IS_ERR(usb11_phy)) { |
| 250 | if (PTR_ERR(usb11_phy) != -EPROBE_DEFER) |
| 251 | dev_err(&pdev->dev, "Failed to get phy.\n"); |
| 252 | return PTR_ERR(usb11_phy); |
| 253 | } |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 254 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 255 | hcd = usb_create_hcd(&ohci_da8xx_hc_driver, &pdev->dev, |
| 256 | dev_name(&pdev->dev)); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 257 | if (!hcd) |
| 258 | return -ENOMEM; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 259 | |
| 260 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 261 | hcd->regs = devm_ioremap_resource(&pdev->dev, mem); |
| 262 | if (IS_ERR(hcd->regs)) { |
| 263 | error = PTR_ERR(hcd->regs); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 264 | dev_err(&pdev->dev, "failed to map ohci.\n"); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 265 | goto err; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 266 | } |
Varka Bhadram | 54891d7 | 2014-11-04 07:51:09 +0530 | [diff] [blame] | 267 | hcd->rsrc_start = mem->start; |
| 268 | hcd->rsrc_len = resource_size(mem); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 269 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 270 | irq = platform_get_irq(pdev, 0); |
| 271 | if (irq < 0) { |
| 272 | error = -ENODEV; |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 273 | goto err; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 274 | } |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 275 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 276 | error = usb_add_hcd(hcd, irq, 0); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 277 | if (error) |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 278 | goto err; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 279 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 280 | device_wakeup_enable(hcd->self.controller); |
| 281 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 282 | if (hub->ocic_notify) { |
| 283 | error = hub->ocic_notify(ohci_da8xx_ocic_handler); |
| 284 | if (!error) |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | usb_remove_hcd(hcd); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 289 | err: |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 290 | usb_put_hcd(hcd); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 291 | return error; |
| 292 | } |
| 293 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 294 | static int ohci_da8xx_remove(struct platform_device *pdev) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 295 | { |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 296 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 297 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 298 | |
| 299 | hub->ocic_notify(NULL); |
| 300 | usb_remove_hcd(hcd); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 301 | usb_put_hcd(hcd); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | #ifdef CONFIG_PM |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 307 | static int ohci_da8xx_suspend(struct platform_device *pdev, |
| 308 | pm_message_t message) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 309 | { |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 310 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 311 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 312 | bool do_wakeup = device_may_wakeup(&pdev->dev); |
| 313 | int ret; |
| 314 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 315 | |
| 316 | if (time_before(jiffies, ohci->next_statechange)) |
| 317 | msleep(5); |
| 318 | ohci->next_statechange = jiffies; |
| 319 | |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 320 | ret = ohci_suspend(hcd, do_wakeup); |
| 321 | if (ret) |
| 322 | return ret; |
| 323 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 324 | ohci_da8xx_disable(); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 325 | hcd->state = HC_STATE_SUSPENDED; |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 326 | |
| 327 | return ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static int ohci_da8xx_resume(struct platform_device *dev) |
| 331 | { |
| 332 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 333 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 334 | int ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 335 | |
| 336 | if (time_before(jiffies, ohci->next_statechange)) |
| 337 | msleep(5); |
| 338 | ohci->next_statechange = jiffies; |
| 339 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 340 | ret = ohci_da8xx_enable(); |
| 341 | if (ret) |
| 342 | return ret; |
| 343 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 344 | dev->dev.power.power_state = PMSG_ON; |
| 345 | usb_hcd_resume_root_hub(hcd); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame] | 346 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | #endif |
| 350 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 351 | static const struct ohci_driver_overrides da8xx_overrides __initconst = { |
| 352 | .reset = ohci_da8xx_reset, |
| 353 | }; |
| 354 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 355 | /* |
| 356 | * Driver definition to register with platform structure. |
| 357 | */ |
| 358 | static struct platform_driver ohci_hcd_da8xx_driver = { |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 359 | .probe = ohci_da8xx_probe, |
| 360 | .remove = ohci_da8xx_remove, |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 361 | .shutdown = usb_hcd_platform_shutdown, |
| 362 | #ifdef CONFIG_PM |
| 363 | .suspend = ohci_da8xx_suspend, |
| 364 | .resume = ohci_da8xx_resume, |
| 365 | #endif |
| 366 | .driver = { |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 367 | .name = DRV_NAME, |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 368 | }, |
| 369 | }; |
Jan Luebbe | ab59ac01 | 2012-05-07 10:25:16 +0200 | [diff] [blame] | 370 | |
Manjunath Goudar | 6c21caa | 2016-10-27 15:52:29 +0200 | [diff] [blame^] | 371 | static int __init ohci_da8xx_init(void) |
| 372 | { |
| 373 | |
| 374 | if (usb_disabled()) |
| 375 | return -ENODEV; |
| 376 | |
| 377 | pr_info("%s: " DRIVER_DESC "\n", DRV_NAME); |
| 378 | ohci_init_driver(&ohci_da8xx_hc_driver, &da8xx_overrides); |
| 379 | |
| 380 | /* |
| 381 | * The Davinci da8xx HW has some unusual quirks, which require |
| 382 | * da8xx-specific workarounds. We override certain hc_driver |
| 383 | * functions here to achieve that. We explicitly do not enhance |
| 384 | * ohci_driver_overrides to allow this more easily, since this |
| 385 | * is an unusual case, and we don't want to encourage others to |
| 386 | * override these functions by making it too easy. |
| 387 | */ |
| 388 | |
| 389 | orig_ohci_hub_control = ohci_da8xx_hc_driver.hub_control; |
| 390 | orig_ohci_hub_status_data = ohci_da8xx_hc_driver.hub_status_data; |
| 391 | |
| 392 | ohci_da8xx_hc_driver.hub_status_data = ohci_da8xx_hub_status_data; |
| 393 | ohci_da8xx_hc_driver.hub_control = ohci_da8xx_hub_control; |
| 394 | |
| 395 | return platform_driver_register(&ohci_hcd_da8xx_driver); |
| 396 | } |
| 397 | module_init(ohci_da8xx_init); |
| 398 | |
| 399 | static void __exit ohci_da8xx_exit(void) |
| 400 | { |
| 401 | platform_driver_unregister(&ohci_hcd_da8xx_driver); |
| 402 | } |
| 403 | module_exit(ohci_da8xx_exit); |
| 404 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 405 | MODULE_LICENSE("GPL"); |
| 406 | MODULE_ALIAS("platform:" DRV_NAME); |