Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OHCI HCD (Host Controller Driver) for USB. |
| 3 | * |
| 4 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> |
| 5 | * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> |
| 6 | * (C) Copyright 2002 Hewlett-Packard Company |
| 7 | * |
| 8 | * USB Bus Glue for Samsung S3C2410 |
| 9 | * |
| 10 | * Written by Christopher Hoover <ch@hpl.hp.com> |
Uwe Kleine-König | ac310bb | 2008-07-10 17:30:46 -0700 | [diff] [blame] | 11 | * Based on fragments of previous driver by Russell King et al. |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 12 | * |
| 13 | * Modified for S3C2410 from ohci-sa1111.c, ohci-omap.c and ohci-lh7a40.c |
| 14 | * by Ben Dooks, <ben@simtec.co.uk> |
| 15 | * Copyright (C) 2004 Simtec Electronics |
| 16 | * |
| 17 | * Thanks to basprog@mail.ru for updates to newer kernels |
| 18 | * |
| 19 | * This file is licenced under the GPL. |
| 20 | */ |
| 21 | |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 23 | #include <linux/clk.h> |
Arnd Bergmann | 436d42c | 2012-08-24 15:22:12 +0200 | [diff] [blame] | 24 | #include <linux/platform_data/usb-ohci-s3c2410.h> |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 25 | |
| 26 | #define valid_port(idx) ((idx) == 1 || (idx) == 2) |
| 27 | |
| 28 | /* clock device associated with the hcd */ |
| 29 | |
| 30 | static struct clk *clk; |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 31 | static struct clk *usb_clk; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 32 | |
| 33 | /* forward definitions */ |
| 34 | |
| 35 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); |
| 36 | |
| 37 | /* conversion functions */ |
| 38 | |
Ben Dooks | f096e04 | 2006-03-21 22:54:47 +0000 | [diff] [blame] | 39 | static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 40 | { |
| 41 | return hcd->self.controller->platform_data; |
| 42 | } |
| 43 | |
| 44 | static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd) |
| 45 | { |
| 46 | struct s3c2410_hcd_info *info = dev->dev.platform_data; |
| 47 | |
| 48 | dev_dbg(&dev->dev, "s3c2410_start_hc:\n"); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 49 | |
| 50 | clk_enable(usb_clk); |
| 51 | mdelay(2); /* let the bus clock stabilise */ |
| 52 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 53 | clk_enable(clk); |
| 54 | |
| 55 | if (info != NULL) { |
| 56 | info->hcd = hcd; |
| 57 | info->report_oc = s3c2410_hcd_oc; |
| 58 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 59 | if (info->enable_oc != NULL) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 60 | (info->enable_oc)(info, 1); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | static void s3c2410_stop_hc(struct platform_device *dev) |
| 65 | { |
| 66 | struct s3c2410_hcd_info *info = dev->dev.platform_data; |
| 67 | |
| 68 | dev_dbg(&dev->dev, "s3c2410_stop_hc:\n"); |
| 69 | |
| 70 | if (info != NULL) { |
| 71 | info->report_oc = NULL; |
| 72 | info->hcd = NULL; |
| 73 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 74 | if (info->enable_oc != NULL) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 75 | (info->enable_oc)(info, 0); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | clk_disable(clk); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 79 | clk_disable(usb_clk); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* ohci_s3c2410_hub_status_data |
| 83 | * |
| 84 | * update the status data from the hub with anything that |
| 85 | * has been detected by our system |
| 86 | */ |
| 87 | |
| 88 | static int |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 89 | ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 90 | { |
| 91 | struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); |
| 92 | struct s3c2410_hcd_port *port; |
| 93 | int orig; |
| 94 | int portno; |
| 95 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 96 | orig = ohci_hub_status_data(hcd, buf); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 97 | |
| 98 | if (info == NULL) |
| 99 | return orig; |
| 100 | |
| 101 | port = &info->port[0]; |
| 102 | |
| 103 | /* mark any changed port as changed */ |
| 104 | |
| 105 | for (portno = 0; portno < 2; port++, portno++) { |
| 106 | if (port->oc_changed == 1 && |
| 107 | port->flags & S3C_HCDFLG_USED) { |
| 108 | dev_dbg(hcd->self.controller, |
| 109 | "oc change on port %d\n", portno); |
| 110 | |
| 111 | if (orig < 1) |
| 112 | orig = 1; |
| 113 | |
| 114 | buf[0] |= 1<<(portno+1); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return orig; |
| 119 | } |
| 120 | |
| 121 | /* s3c2410_usb_set_power |
| 122 | * |
| 123 | * configure the power on a port, by calling the platform device |
| 124 | * routine registered with the platform device |
| 125 | */ |
| 126 | |
| 127 | static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info, |
| 128 | int port, int to) |
| 129 | { |
| 130 | if (info == NULL) |
| 131 | return; |
| 132 | |
| 133 | if (info->power_control != NULL) { |
| 134 | info->port[port-1].power = to; |
Ben Dooks | ba44e7c | 2005-08-09 15:04:00 +0100 | [diff] [blame] | 135 | (info->power_control)(port-1, to); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | /* ohci_s3c2410_hub_control |
| 140 | * |
| 141 | * look at control requests to the hub, and see if we need |
| 142 | * to take any action or over-ride the results from the |
| 143 | * request. |
| 144 | */ |
| 145 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 146 | static int ohci_s3c2410_hub_control( |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 147 | struct usb_hcd *hcd, |
| 148 | u16 typeReq, |
| 149 | u16 wValue, |
| 150 | u16 wIndex, |
| 151 | char *buf, |
| 152 | u16 wLength) |
| 153 | { |
| 154 | struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); |
| 155 | struct usb_hub_descriptor *desc; |
| 156 | int ret = -EINVAL; |
| 157 | u32 *data = (u32 *)buf; |
| 158 | |
| 159 | dev_dbg(hcd->self.controller, |
| 160 | "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", |
| 161 | hcd, typeReq, wValue, wIndex, buf, wLength); |
| 162 | |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 163 | /* if we are only an humble host without any special capabilities |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 164 | * process the request straight away and exit */ |
| 165 | |
| 166 | if (info == NULL) { |
| 167 | ret = ohci_hub_control(hcd, typeReq, wValue, |
| 168 | wIndex, buf, wLength); |
| 169 | goto out; |
| 170 | } |
| 171 | |
| 172 | /* check the request to see if it needs handling */ |
| 173 | |
| 174 | switch (typeReq) { |
| 175 | case SetPortFeature: |
| 176 | if (wValue == USB_PORT_FEAT_POWER) { |
| 177 | dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); |
| 178 | s3c2410_usb_set_power(info, wIndex, 1); |
| 179 | goto out; |
| 180 | } |
| 181 | break; |
| 182 | |
| 183 | case ClearPortFeature: |
| 184 | switch (wValue) { |
| 185 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 186 | dev_dbg(hcd->self.controller, |
| 187 | "ClearPortFeature: C_OVER_CURRENT\n"); |
| 188 | |
| 189 | if (valid_port(wIndex)) { |
| 190 | info->port[wIndex-1].oc_changed = 0; |
| 191 | info->port[wIndex-1].oc_status = 0; |
| 192 | } |
| 193 | |
| 194 | goto out; |
| 195 | |
| 196 | case USB_PORT_FEAT_OVER_CURRENT: |
| 197 | dev_dbg(hcd->self.controller, |
| 198 | "ClearPortFeature: OVER_CURRENT\n"); |
| 199 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 200 | if (valid_port(wIndex)) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 201 | info->port[wIndex-1].oc_status = 0; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 202 | |
| 203 | goto out; |
| 204 | |
| 205 | case USB_PORT_FEAT_POWER: |
| 206 | dev_dbg(hcd->self.controller, |
| 207 | "ClearPortFeature: POWER\n"); |
| 208 | |
| 209 | if (valid_port(wIndex)) { |
| 210 | s3c2410_usb_set_power(info, wIndex, 0); |
| 211 | return 0; |
| 212 | } |
| 213 | } |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
| 218 | if (ret) |
| 219 | goto out; |
| 220 | |
| 221 | switch (typeReq) { |
| 222 | case GetHubDescriptor: |
| 223 | |
| 224 | /* update the hub's descriptor */ |
| 225 | |
| 226 | desc = (struct usb_hub_descriptor *)buf; |
| 227 | |
| 228 | if (info->power_control == NULL) |
| 229 | return ret; |
| 230 | |
| 231 | dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", |
| 232 | desc->wHubCharacteristics); |
| 233 | |
| 234 | /* remove the old configurations for power-switching, and |
| 235 | * over-current protection, and insert our new configuration |
| 236 | */ |
| 237 | |
| 238 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); |
| 239 | desc->wHubCharacteristics |= cpu_to_le16(0x0001); |
| 240 | |
| 241 | if (info->enable_oc) { |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 242 | desc->wHubCharacteristics &= ~cpu_to_le16( |
| 243 | HUB_CHAR_OCPM); |
| 244 | desc->wHubCharacteristics |= cpu_to_le16( |
| 245 | 0x0008 | |
| 246 | 0x0001); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", |
| 250 | desc->wHubCharacteristics); |
| 251 | |
| 252 | return ret; |
| 253 | |
| 254 | case GetPortStatus: |
| 255 | /* check port status */ |
| 256 | |
| 257 | dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); |
| 258 | |
| 259 | if (valid_port(wIndex)) { |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 260 | if (info->port[wIndex-1].oc_changed) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 261 | *data |= cpu_to_le32(RH_PS_OCIC); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 262 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 263 | if (info->port[wIndex-1].oc_status) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 264 | *data |= cpu_to_le32(RH_PS_POCI); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | out: |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | /* s3c2410_hcd_oc |
| 273 | * |
| 274 | * handle an over-current report |
| 275 | */ |
| 276 | |
| 277 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc) |
| 278 | { |
| 279 | struct s3c2410_hcd_port *port; |
| 280 | struct usb_hcd *hcd; |
| 281 | unsigned long flags; |
| 282 | int portno; |
| 283 | |
| 284 | if (info == NULL) |
| 285 | return; |
| 286 | |
| 287 | port = &info->port[0]; |
| 288 | hcd = info->hcd; |
| 289 | |
| 290 | local_irq_save(flags); |
| 291 | |
| 292 | for (portno = 0; portno < 2; port++, portno++) { |
| 293 | if (port_oc & (1<<portno) && |
| 294 | port->flags & S3C_HCDFLG_USED) { |
| 295 | port->oc_status = 1; |
| 296 | port->oc_changed = 1; |
| 297 | |
| 298 | /* ok, once over-current is detected, |
| 299 | the port needs to be powered down */ |
| 300 | s3c2410_usb_set_power(info, portno+1, 0); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | local_irq_restore(flags); |
| 305 | } |
| 306 | |
| 307 | /* may be called without controller electrically present */ |
| 308 | /* may be called with controller, bus, and devices active */ |
| 309 | |
| 310 | /* |
| 311 | * usb_hcd_s3c2410_remove - shutdown processing for HCD |
| 312 | * @dev: USB Host Controller being removed |
| 313 | * Context: !in_interrupt() |
| 314 | * |
| 315 | * Reverses the effect of usb_hcd_3c2410_probe(), first invoking |
| 316 | * the HCD's stop() method. It is always called from a thread |
| 317 | * context, normally "rmmod", "apmd", or something similar. |
| 318 | * |
| 319 | */ |
| 320 | |
Ben Dooks | f096e04 | 2006-03-21 22:54:47 +0000 | [diff] [blame] | 321 | static void |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 322 | usb_hcd_s3c2410_remove(struct usb_hcd *hcd, struct platform_device *dev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 323 | { |
| 324 | usb_remove_hcd(hcd); |
| 325 | s3c2410_stop_hc(dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 326 | usb_put_hcd(hcd); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs |
| 331 | * Context: !in_interrupt() |
| 332 | * |
| 333 | * Allocates basic resources for this USB host controller, and |
| 334 | * then invokes the start() method for the HCD associated with it |
| 335 | * through the hotplug entry's driver_data. |
| 336 | * |
| 337 | */ |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 338 | static int usb_hcd_s3c2410_probe(const struct hc_driver *driver, |
Ben Dooks | f096e04 | 2006-03-21 22:54:47 +0000 | [diff] [blame] | 339 | struct platform_device *dev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 340 | { |
| 341 | struct usb_hcd *hcd = NULL; |
| 342 | int retval; |
| 343 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 344 | s3c2410_usb_set_power(dev->dev.platform_data, 1, 1); |
Ben Dooks | ba44e7c | 2005-08-09 15:04:00 +0100 | [diff] [blame] | 345 | s3c2410_usb_set_power(dev->dev.platform_data, 2, 1); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 346 | |
| 347 | hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx"); |
| 348 | if (hcd == NULL) |
| 349 | return -ENOMEM; |
| 350 | |
| 351 | hcd->rsrc_start = dev->resource[0].start; |
Jingoo Han | 3c86c07 | 2011-04-14 21:09:16 +0900 | [diff] [blame] | 352 | hcd->rsrc_len = resource_size(&dev->resource[0]); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 353 | |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 354 | hcd->regs = devm_request_and_ioremap(&dev->dev, &dev->resource[0]); |
| 355 | if (!hcd->regs) { |
| 356 | dev_err(&dev->dev, "devm_request_and_ioremap failed\n"); |
| 357 | retval = -ENOMEM; |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 358 | goto err_put; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 361 | clk = devm_clk_get(&dev->dev, "usb-host"); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 362 | if (IS_ERR(clk)) { |
| 363 | dev_err(&dev->dev, "cannot get usb-host clock\n"); |
Jingoo Han | 69248d4 | 2011-05-05 08:46:07 +0900 | [diff] [blame] | 364 | retval = PTR_ERR(clk); |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 365 | goto err_put; |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 366 | } |
| 367 | |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 368 | usb_clk = devm_clk_get(&dev->dev, "usb-bus-host"); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 369 | if (IS_ERR(usb_clk)) { |
Ben Dooks | 2dfa319 | 2009-02-26 23:03:15 +0000 | [diff] [blame] | 370 | dev_err(&dev->dev, "cannot get usb-bus-host clock\n"); |
Jingoo Han | 69248d4 | 2011-05-05 08:46:07 +0900 | [diff] [blame] | 371 | retval = PTR_ERR(usb_clk); |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 372 | goto err_put; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 375 | s3c2410_start_hc(dev, hcd); |
| 376 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 377 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 378 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 379 | retval = usb_add_hcd(hcd, dev->resource[1].start, 0); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 380 | if (retval != 0) |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 381 | goto err_ioremap; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 382 | |
| 383 | return 0; |
| 384 | |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 385 | err_ioremap: |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 386 | s3c2410_stop_hc(dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 387 | |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 388 | err_put: |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 389 | usb_put_hcd(hcd); |
| 390 | return retval; |
| 391 | } |
| 392 | |
| 393 | /*-------------------------------------------------------------------------*/ |
| 394 | |
| 395 | static int |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 396 | ohci_s3c2410_start(struct usb_hcd *hcd) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 397 | { |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 398 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 399 | int ret; |
| 400 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 401 | ret = ohci_init(ohci); |
| 402 | if (ret < 0) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 403 | return ret; |
| 404 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 405 | ret = ohci_run(ohci); |
| 406 | if (ret < 0) { |
Greg Kroah-Hartman | 1041ac1 | 2012-04-27 11:24:43 -0700 | [diff] [blame] | 407 | dev_err(hcd->self.controller, "can't start %s\n", |
| 408 | hcd->self.bus_name); |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 409 | ohci_stop(hcd); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | |
| 417 | static const struct hc_driver ohci_s3c2410_hc_driver = { |
| 418 | .description = hcd_name, |
| 419 | .product_desc = "S3C24XX OHCI", |
| 420 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 421 | |
| 422 | /* |
| 423 | * generic hardware linkage |
| 424 | */ |
| 425 | .irq = ohci_irq, |
| 426 | .flags = HCD_USB11 | HCD_MEMORY, |
| 427 | |
| 428 | /* |
| 429 | * basic lifecycle operations |
| 430 | */ |
| 431 | .start = ohci_s3c2410_start, |
| 432 | .stop = ohci_stop, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 433 | .shutdown = ohci_shutdown, |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 434 | |
| 435 | /* |
| 436 | * managing i/o requests and associated device resources |
| 437 | */ |
| 438 | .urb_enqueue = ohci_urb_enqueue, |
| 439 | .urb_dequeue = ohci_urb_dequeue, |
| 440 | .endpoint_disable = ohci_endpoint_disable, |
| 441 | |
| 442 | /* |
| 443 | * scheduling support |
| 444 | */ |
| 445 | .get_frame_number = ohci_get_frame, |
| 446 | |
| 447 | /* |
| 448 | * root hub support |
| 449 | */ |
| 450 | .hub_status_data = ohci_s3c2410_hub_status_data, |
| 451 | .hub_control = ohci_s3c2410_hub_control, |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 452 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 453 | .bus_suspend = ohci_bus_suspend, |
| 454 | .bus_resume = ohci_bus_resume, |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 455 | #endif |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 456 | .start_port_reset = ohci_start_port_reset, |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | /* device driver */ |
| 460 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame^] | 461 | static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 462 | { |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 463 | return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev); |
| 464 | } |
| 465 | |
Jingoo Han | e7f8433 | 2011-04-14 21:09:37 +0900 | [diff] [blame] | 466 | static int __devexit ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 467 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 468 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 469 | |
| 470 | usb_hcd_s3c2410_remove(hcd, pdev); |
| 471 | return 0; |
| 472 | } |
| 473 | |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 474 | #ifdef CONFIG_PM |
| 475 | static int ohci_hcd_s3c2410_drv_suspend(struct device *dev) |
| 476 | { |
| 477 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 478 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 479 | struct platform_device *pdev = to_platform_device(dev); |
| 480 | unsigned long flags; |
| 481 | int rc = 0; |
| 482 | |
| 483 | /* |
| 484 | * Root hub was already suspended. Disable irq emission and |
| 485 | * mark HW unaccessible, bail out if RH has been resumed. Use |
| 486 | * the spinlock to properly synchronize with possible pending |
| 487 | * RH suspend or resume activity. |
| 488 | */ |
| 489 | spin_lock_irqsave(&ohci->lock, flags); |
| 490 | if (ohci->rh_state != OHCI_RH_SUSPENDED) { |
| 491 | rc = -EINVAL; |
| 492 | goto bail; |
| 493 | } |
| 494 | |
| 495 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 496 | |
| 497 | s3c2410_stop_hc(pdev); |
| 498 | bail: |
| 499 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 500 | |
| 501 | return rc; |
| 502 | } |
| 503 | |
| 504 | static int ohci_hcd_s3c2410_drv_resume(struct device *dev) |
| 505 | { |
| 506 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 507 | struct platform_device *pdev = to_platform_device(dev); |
| 508 | |
| 509 | s3c2410_start_hc(pdev, hcd); |
| 510 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 511 | ohci_resume(hcd, false); |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | #else |
| 516 | #define ohci_hcd_s3c2410_drv_suspend NULL |
| 517 | #define ohci_hcd_s3c2410_drv_resume NULL |
| 518 | #endif |
| 519 | |
| 520 | static const struct dev_pm_ops ohci_hcd_s3c2410_pm_ops = { |
| 521 | .suspend = ohci_hcd_s3c2410_drv_suspend, |
| 522 | .resume = ohci_hcd_s3c2410_drv_resume, |
| 523 | }; |
| 524 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 525 | static struct platform_driver ohci_hcd_s3c2410_driver = { |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 526 | .probe = ohci_hcd_s3c2410_drv_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 527 | .remove = ohci_hcd_s3c2410_drv_remove, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 528 | .shutdown = usb_hcd_platform_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 529 | .driver = { |
| 530 | .owner = THIS_MODULE, |
| 531 | .name = "s3c2410-ohci", |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 532 | .pm = &ohci_hcd_s3c2410_pm_ops, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 533 | }, |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 534 | }; |
| 535 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 536 | MODULE_ALIAS("platform:s3c2410-ohci"); |