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