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 | |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/jiffies.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/clk.h> |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 18 | #include <linux/phy/phy.h> |
Arnd Bergmann | ec2a083 | 2012-08-24 15:11:34 +0200 | [diff] [blame] | 19 | #include <linux/platform_data/usb-davinci.h> |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 20 | |
| 21 | #ifndef CONFIG_ARCH_DAVINCI_DA8XX |
| 22 | #error "This file is DA8xx bus glue. Define CONFIG_ARCH_DAVINCI_DA8XX." |
| 23 | #endif |
| 24 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 25 | static struct clk *usb11_clk; |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 26 | static struct phy *usb11_phy; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 27 | |
| 28 | /* Over-current indicator change bitmask */ |
| 29 | static volatile u16 ocic_mask; |
| 30 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 31 | static int ohci_da8xx_enable(void) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 32 | { |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 33 | int ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 34 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 35 | ret = clk_prepare_enable(usb11_clk); |
| 36 | if (ret) |
| 37 | return ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 38 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 39 | ret = phy_init(usb11_phy); |
| 40 | if (ret) |
| 41 | goto err_phy_init; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 42 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 43 | ret = phy_power_on(usb11_phy); |
| 44 | if (ret) |
| 45 | goto err_phy_power_on; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 46 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 47 | return 0; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 48 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 49 | err_phy_power_on: |
| 50 | phy_exit(usb11_phy); |
| 51 | err_phy_init: |
| 52 | clk_disable_unprepare(usb11_clk); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 53 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | static void ohci_da8xx_disable(void) |
| 58 | { |
| 59 | phy_power_off(usb11_phy); |
| 60 | phy_exit(usb11_phy); |
| 61 | clk_disable_unprepare(usb11_clk); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Handle the port over-current indicator change. |
| 66 | */ |
| 67 | static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub, |
| 68 | unsigned port) |
| 69 | { |
| 70 | ocic_mask |= 1 << port; |
| 71 | |
| 72 | /* Once over-current is detected, the port needs to be powered down */ |
| 73 | if (hub->get_oci(port) > 0) |
| 74 | hub->set_power(port, 0); |
| 75 | } |
| 76 | |
| 77 | static int ohci_da8xx_init(struct usb_hcd *hcd) |
| 78 | { |
| 79 | struct device *dev = hcd->self.controller; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 80 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 81 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 82 | int result; |
| 83 | u32 rh_a; |
| 84 | |
| 85 | dev_dbg(dev, "starting USB controller\n"); |
| 86 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 87 | result = ohci_da8xx_enable(); |
| 88 | if (result < 0) |
| 89 | return result; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * DA8xx only have 1 port connected to the pins but the HC root hub |
| 93 | * register A reports 2 ports, thus we'll have to override it... |
| 94 | */ |
| 95 | ohci->num_ports = 1; |
| 96 | |
| 97 | result = ohci_init(ohci); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 98 | if (result < 0) { |
| 99 | ohci_da8xx_disable(); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 100 | return result; |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 101 | } |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * Since we're providing a board-specific root hub port power control |
| 105 | * and over-current reporting, we have to override the HC root hub A |
| 106 | * register's default value, so that ohci_hub_control() could return |
| 107 | * the correct hub descriptor... |
| 108 | */ |
| 109 | rh_a = ohci_readl(ohci, &ohci->regs->roothub.a); |
| 110 | if (hub->set_power) { |
| 111 | rh_a &= ~RH_A_NPS; |
| 112 | rh_a |= RH_A_PSM; |
| 113 | } |
| 114 | if (hub->get_oci) { |
| 115 | rh_a &= ~RH_A_NOCP; |
| 116 | rh_a |= RH_A_OCPM; |
| 117 | } |
| 118 | rh_a &= ~RH_A_POTPGT; |
| 119 | rh_a |= hub->potpgt << 24; |
| 120 | ohci_writel(ohci, rh_a, &ohci->regs->roothub.a); |
| 121 | |
| 122 | return result; |
| 123 | } |
| 124 | |
| 125 | static void ohci_da8xx_stop(struct usb_hcd *hcd) |
| 126 | { |
| 127 | ohci_stop(hcd); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 128 | ohci_da8xx_disable(); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static int ohci_da8xx_start(struct usb_hcd *hcd) |
| 132 | { |
| 133 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 134 | int result; |
| 135 | |
| 136 | result = ohci_run(ohci); |
| 137 | if (result < 0) |
| 138 | ohci_da8xx_stop(hcd); |
| 139 | |
| 140 | return result; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Update the status data from the hub with the over-current indicator change. |
| 145 | */ |
| 146 | static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 147 | { |
| 148 | int length = ohci_hub_status_data(hcd, buf); |
| 149 | |
| 150 | /* See if we have OCIC bit set on port 1 */ |
| 151 | if (ocic_mask & (1 << 1)) { |
| 152 | dev_dbg(hcd->self.controller, "over-current indicator change " |
| 153 | "on port 1\n"); |
| 154 | |
| 155 | if (!length) |
| 156 | length = 1; |
| 157 | |
| 158 | buf[0] |= 1 << 1; |
| 159 | } |
| 160 | return length; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Look at the control requests to the root hub and see if we need to override. |
| 165 | */ |
| 166 | static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 167 | u16 wIndex, char *buf, u16 wLength) |
| 168 | { |
| 169 | struct device *dev = hcd->self.controller; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 170 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 171 | int temp; |
| 172 | |
| 173 | switch (typeReq) { |
| 174 | case GetPortStatus: |
| 175 | /* Check the port number */ |
| 176 | if (wIndex != 1) |
| 177 | break; |
| 178 | |
| 179 | dev_dbg(dev, "GetPortStatus(%u)\n", wIndex); |
| 180 | |
| 181 | temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1); |
| 182 | |
| 183 | /* The port power status (PPS) bit defaults to 1 */ |
| 184 | if (hub->get_power && hub->get_power(wIndex) == 0) |
| 185 | temp &= ~RH_PS_PPS; |
| 186 | |
| 187 | /* The port over-current indicator (POCI) bit is always 0 */ |
| 188 | if (hub->get_oci && hub->get_oci(wIndex) > 0) |
| 189 | temp |= RH_PS_POCI; |
| 190 | |
| 191 | /* The over-current indicator change (OCIC) bit is 0 too */ |
| 192 | if (ocic_mask & (1 << wIndex)) |
| 193 | temp |= RH_PS_OCIC; |
| 194 | |
| 195 | put_unaligned(cpu_to_le32(temp), (__le32 *)buf); |
| 196 | return 0; |
| 197 | case SetPortFeature: |
| 198 | temp = 1; |
| 199 | goto check_port; |
| 200 | case ClearPortFeature: |
| 201 | temp = 0; |
| 202 | |
| 203 | check_port: |
| 204 | /* Check the port number */ |
| 205 | if (wIndex != 1) |
| 206 | break; |
| 207 | |
| 208 | switch (wValue) { |
| 209 | case USB_PORT_FEAT_POWER: |
| 210 | dev_dbg(dev, "%sPortFeature(%u): %s\n", |
| 211 | temp ? "Set" : "Clear", wIndex, "POWER"); |
| 212 | |
| 213 | if (!hub->set_power) |
| 214 | return -EPIPE; |
| 215 | |
| 216 | return hub->set_power(wIndex, temp) ? -EPIPE : 0; |
| 217 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 218 | dev_dbg(dev, "%sPortFeature(%u): %s\n", |
| 219 | temp ? "Set" : "Clear", wIndex, |
| 220 | "C_OVER_CURRENT"); |
| 221 | |
| 222 | if (temp) |
| 223 | ocic_mask |= 1 << wIndex; |
| 224 | else |
| 225 | ocic_mask &= ~(1 << wIndex); |
| 226 | return 0; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
| 231 | } |
| 232 | |
| 233 | static const struct hc_driver ohci_da8xx_hc_driver = { |
| 234 | .description = hcd_name, |
| 235 | .product_desc = "DA8xx OHCI", |
| 236 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 237 | |
| 238 | /* |
| 239 | * generic hardware linkage |
| 240 | */ |
| 241 | .irq = ohci_irq, |
| 242 | .flags = HCD_USB11 | HCD_MEMORY, |
| 243 | |
| 244 | /* |
| 245 | * basic lifecycle operations |
| 246 | */ |
| 247 | .reset = ohci_da8xx_init, |
| 248 | .start = ohci_da8xx_start, |
| 249 | .stop = ohci_da8xx_stop, |
| 250 | .shutdown = ohci_shutdown, |
| 251 | |
| 252 | /* |
| 253 | * managing i/o requests and associated device resources |
| 254 | */ |
| 255 | .urb_enqueue = ohci_urb_enqueue, |
| 256 | .urb_dequeue = ohci_urb_dequeue, |
| 257 | .endpoint_disable = ohci_endpoint_disable, |
| 258 | |
| 259 | /* |
| 260 | * scheduling support |
| 261 | */ |
| 262 | .get_frame_number = ohci_get_frame, |
| 263 | |
| 264 | /* |
| 265 | * root hub support |
| 266 | */ |
| 267 | .hub_status_data = ohci_da8xx_hub_status_data, |
| 268 | .hub_control = ohci_da8xx_hub_control, |
| 269 | |
| 270 | #ifdef CONFIG_PM |
| 271 | .bus_suspend = ohci_bus_suspend, |
| 272 | .bus_resume = ohci_bus_resume, |
| 273 | #endif |
| 274 | .start_port_reset = ohci_start_port_reset, |
| 275 | }; |
| 276 | |
| 277 | /*-------------------------------------------------------------------------*/ |
| 278 | |
| 279 | |
| 280 | /** |
| 281 | * usb_hcd_da8xx_probe - initialize DA8xx-based HCDs |
| 282 | * Context: !in_interrupt() |
| 283 | * |
| 284 | * Allocates basic resources for this USB host controller, and |
| 285 | * then invokes the start() method for the HCD associated with it |
| 286 | * through the hotplug entry's driver_data. |
| 287 | */ |
| 288 | static int usb_hcd_da8xx_probe(const struct hc_driver *driver, |
| 289 | struct platform_device *pdev) |
| 290 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 291 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 292 | struct usb_hcd *hcd; |
| 293 | struct resource *mem; |
| 294 | int error, irq; |
| 295 | |
| 296 | if (hub == NULL) |
| 297 | return -ENODEV; |
| 298 | |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 299 | usb11_clk = devm_clk_get(&pdev->dev, "usb11"); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 300 | if (IS_ERR(usb11_clk)) { |
| 301 | if (PTR_ERR(usb11_clk) != -EPROBE_DEFER) |
| 302 | dev_err(&pdev->dev, "Failed to get clock.\n"); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 303 | return PTR_ERR(usb11_clk); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 304 | } |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 305 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 306 | usb11_phy = devm_phy_get(&pdev->dev, "usb-phy"); |
| 307 | if (IS_ERR(usb11_phy)) { |
| 308 | if (PTR_ERR(usb11_phy) != -EPROBE_DEFER) |
| 309 | dev_err(&pdev->dev, "Failed to get phy.\n"); |
| 310 | return PTR_ERR(usb11_phy); |
| 311 | } |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 312 | |
| 313 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 314 | if (!hcd) |
| 315 | return -ENOMEM; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 316 | |
| 317 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 318 | hcd->regs = devm_ioremap_resource(&pdev->dev, mem); |
| 319 | if (IS_ERR(hcd->regs)) { |
| 320 | error = PTR_ERR(hcd->regs); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 321 | dev_err(&pdev->dev, "failed to map ohci.\n"); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 322 | goto err; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 323 | } |
Varka Bhadram | 54891d7 | 2014-11-04 07:51:09 +0530 | [diff] [blame] | 324 | hcd->rsrc_start = mem->start; |
| 325 | hcd->rsrc_len = resource_size(mem); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 326 | |
| 327 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 328 | |
| 329 | irq = platform_get_irq(pdev, 0); |
| 330 | if (irq < 0) { |
| 331 | error = -ENODEV; |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 332 | goto err; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 333 | } |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 334 | error = usb_add_hcd(hcd, irq, 0); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 335 | if (error) |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 336 | goto err; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 337 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 338 | device_wakeup_enable(hcd->self.controller); |
| 339 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 340 | if (hub->ocic_notify) { |
| 341 | error = hub->ocic_notify(ohci_da8xx_ocic_handler); |
| 342 | if (!error) |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | usb_remove_hcd(hcd); |
Jingoo Han | 644db16 | 2013-12-11 16:23:39 +0900 | [diff] [blame] | 347 | err: |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 348 | usb_put_hcd(hcd); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 349 | return error; |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * usb_hcd_da8xx_remove - shutdown processing for DA8xx-based HCDs |
| 354 | * @dev: USB Host Controller being removed |
| 355 | * Context: !in_interrupt() |
| 356 | * |
| 357 | * Reverses the effect of usb_hcd_da8xx_probe(), first invoking |
| 358 | * the HCD's stop() method. It is always called from a thread |
| 359 | * context, normally "rmmod", "apmd", or something similar. |
| 360 | */ |
| 361 | static inline void |
| 362 | usb_hcd_da8xx_remove(struct usb_hcd *hcd, struct platform_device *pdev) |
| 363 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 364 | struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 365 | |
| 366 | hub->ocic_notify(NULL); |
| 367 | usb_remove_hcd(hcd); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 368 | usb_put_hcd(hcd); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static int ohci_hcd_da8xx_drv_probe(struct platform_device *dev) |
| 372 | { |
| 373 | return usb_hcd_da8xx_probe(&ohci_da8xx_hc_driver, dev); |
| 374 | } |
| 375 | |
| 376 | static int ohci_hcd_da8xx_drv_remove(struct platform_device *dev) |
| 377 | { |
| 378 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 379 | |
| 380 | usb_hcd_da8xx_remove(hcd, dev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | #ifdef CONFIG_PM |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 386 | static int ohci_da8xx_suspend(struct platform_device *pdev, |
| 387 | pm_message_t message) |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 388 | { |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 389 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 390 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 391 | bool do_wakeup = device_may_wakeup(&pdev->dev); |
| 392 | int ret; |
| 393 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 394 | |
| 395 | if (time_before(jiffies, ohci->next_statechange)) |
| 396 | msleep(5); |
| 397 | ohci->next_statechange = jiffies; |
| 398 | |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 399 | ret = ohci_suspend(hcd, do_wakeup); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 403 | ohci_da8xx_disable(); |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 404 | hcd->state = HC_STATE_SUSPENDED; |
Majunath Goudar | 933bb1f | 2013-11-13 17:40:19 +0530 | [diff] [blame] | 405 | |
| 406 | return ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static int ohci_da8xx_resume(struct platform_device *dev) |
| 410 | { |
| 411 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 412 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 413 | int ret; |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 414 | |
| 415 | if (time_before(jiffies, ohci->next_statechange)) |
| 416 | msleep(5); |
| 417 | ohci->next_statechange = jiffies; |
| 418 | |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 419 | ret = ohci_da8xx_enable(); |
| 420 | if (ret) |
| 421 | return ret; |
| 422 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 423 | dev->dev.power.power_state = PMSG_ON; |
| 424 | usb_hcd_resume_root_hub(hcd); |
David Lechner | 6110c42 | 2016-10-12 20:44:46 -0500 | [diff] [blame^] | 425 | |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | #endif |
| 429 | |
| 430 | /* |
| 431 | * Driver definition to register with platform structure. |
| 432 | */ |
| 433 | static struct platform_driver ohci_hcd_da8xx_driver = { |
| 434 | .probe = ohci_hcd_da8xx_drv_probe, |
| 435 | .remove = ohci_hcd_da8xx_drv_remove, |
| 436 | .shutdown = usb_hcd_platform_shutdown, |
| 437 | #ifdef CONFIG_PM |
| 438 | .suspend = ohci_da8xx_suspend, |
| 439 | .resume = ohci_da8xx_resume, |
| 440 | #endif |
| 441 | .driver = { |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 442 | .name = "ohci", |
| 443 | }, |
| 444 | }; |
Jan Luebbe | ab59ac01 | 2012-05-07 10:25:16 +0200 | [diff] [blame] | 445 | |
| 446 | MODULE_ALIAS("platform:ohci"); |