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 | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 22 | #include <linux/clk.h> |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 23 | #include <linux/io.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/platform_device.h> |
Arnd Bergmann | 436d42c | 2012-08-24 15:22:12 +0200 | [diff] [blame] | 27 | #include <linux/platform_data/usb-ohci-s3c2410.h> |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 28 | #include <linux/usb.h> |
| 29 | #include <linux/usb/hcd.h> |
| 30 | |
| 31 | #include "ohci.h" |
| 32 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 33 | |
| 34 | #define valid_port(idx) ((idx) == 1 || (idx) == 2) |
| 35 | |
| 36 | /* clock device associated with the hcd */ |
| 37 | |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 38 | |
| 39 | #define DRIVER_DESC "OHCI S3C2410 driver" |
| 40 | |
| 41 | static const char hcd_name[] = "ohci-s3c2410"; |
| 42 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 43 | static struct clk *clk; |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 44 | static struct clk *usb_clk; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 45 | |
| 46 | /* forward definitions */ |
| 47 | |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 48 | static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, |
| 49 | u16 wValue, u16 wIndex, char *buf, u16 wLength); |
| 50 | static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); |
| 51 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 52 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); |
| 53 | |
| 54 | /* conversion functions */ |
| 55 | |
Ben Dooks | f096e04 | 2006-03-21 22:54:47 +0000 | [diff] [blame] | 56 | static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 57 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 58 | return dev_get_platdata(hcd->self.controller); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd) |
| 62 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 63 | struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 64 | |
| 65 | dev_dbg(&dev->dev, "s3c2410_start_hc:\n"); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 66 | |
Tomasz Figa | d0127f6 | 2013-08-26 02:00:37 +0900 | [diff] [blame] | 67 | clk_prepare_enable(usb_clk); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 68 | mdelay(2); /* let the bus clock stabilise */ |
| 69 | |
Tomasz Figa | d0127f6 | 2013-08-26 02:00:37 +0900 | [diff] [blame] | 70 | clk_prepare_enable(clk); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 71 | |
| 72 | if (info != NULL) { |
| 73 | info->hcd = hcd; |
| 74 | info->report_oc = s3c2410_hcd_oc; |
| 75 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 76 | if (info->enable_oc != NULL) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 77 | (info->enable_oc)(info, 1); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
| 81 | static void s3c2410_stop_hc(struct platform_device *dev) |
| 82 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 83 | struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 84 | |
| 85 | dev_dbg(&dev->dev, "s3c2410_stop_hc:\n"); |
| 86 | |
| 87 | if (info != NULL) { |
| 88 | info->report_oc = NULL; |
| 89 | info->hcd = NULL; |
| 90 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 91 | if (info->enable_oc != NULL) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 92 | (info->enable_oc)(info, 0); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Tomasz Figa | d0127f6 | 2013-08-26 02:00:37 +0900 | [diff] [blame] | 95 | clk_disable_unprepare(clk); |
| 96 | clk_disable_unprepare(usb_clk); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* ohci_s3c2410_hub_status_data |
| 100 | * |
| 101 | * update the status data from the hub with anything that |
| 102 | * has been detected by our system |
| 103 | */ |
| 104 | |
| 105 | static int |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 106 | ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 107 | { |
| 108 | struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); |
| 109 | struct s3c2410_hcd_port *port; |
| 110 | int orig; |
| 111 | int portno; |
| 112 | |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 113 | orig = orig_ohci_hub_status_data(hcd, buf); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 114 | |
| 115 | if (info == NULL) |
| 116 | return orig; |
| 117 | |
| 118 | port = &info->port[0]; |
| 119 | |
| 120 | /* mark any changed port as changed */ |
| 121 | |
| 122 | for (portno = 0; portno < 2; port++, portno++) { |
| 123 | if (port->oc_changed == 1 && |
| 124 | port->flags & S3C_HCDFLG_USED) { |
| 125 | dev_dbg(hcd->self.controller, |
| 126 | "oc change on port %d\n", portno); |
| 127 | |
| 128 | if (orig < 1) |
| 129 | orig = 1; |
| 130 | |
| 131 | buf[0] |= 1<<(portno+1); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return orig; |
| 136 | } |
| 137 | |
| 138 | /* s3c2410_usb_set_power |
| 139 | * |
| 140 | * configure the power on a port, by calling the platform device |
| 141 | * routine registered with the platform device |
| 142 | */ |
| 143 | |
| 144 | static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info, |
| 145 | int port, int to) |
| 146 | { |
| 147 | if (info == NULL) |
| 148 | return; |
| 149 | |
| 150 | if (info->power_control != NULL) { |
| 151 | info->port[port-1].power = to; |
Ben Dooks | ba44e7c | 2005-08-09 15:04:00 +0100 | [diff] [blame] | 152 | (info->power_control)(port-1, to); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| 156 | /* ohci_s3c2410_hub_control |
| 157 | * |
| 158 | * look at control requests to the hub, and see if we need |
| 159 | * to take any action or over-ride the results from the |
| 160 | * request. |
| 161 | */ |
| 162 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 163 | static int ohci_s3c2410_hub_control( |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 164 | struct usb_hcd *hcd, |
| 165 | u16 typeReq, |
| 166 | u16 wValue, |
| 167 | u16 wIndex, |
| 168 | char *buf, |
| 169 | u16 wLength) |
| 170 | { |
| 171 | struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); |
| 172 | struct usb_hub_descriptor *desc; |
| 173 | int ret = -EINVAL; |
| 174 | u32 *data = (u32 *)buf; |
| 175 | |
| 176 | dev_dbg(hcd->self.controller, |
| 177 | "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", |
| 178 | hcd, typeReq, wValue, wIndex, buf, wLength); |
| 179 | |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 180 | /* if we are only an humble host without any special capabilities |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 181 | * process the request straight away and exit */ |
| 182 | |
| 183 | if (info == NULL) { |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 184 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 185 | wIndex, buf, wLength); |
| 186 | goto out; |
| 187 | } |
| 188 | |
| 189 | /* check the request to see if it needs handling */ |
| 190 | |
| 191 | switch (typeReq) { |
| 192 | case SetPortFeature: |
| 193 | if (wValue == USB_PORT_FEAT_POWER) { |
| 194 | dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); |
| 195 | s3c2410_usb_set_power(info, wIndex, 1); |
| 196 | goto out; |
| 197 | } |
| 198 | break; |
| 199 | |
| 200 | case ClearPortFeature: |
| 201 | switch (wValue) { |
| 202 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 203 | dev_dbg(hcd->self.controller, |
| 204 | "ClearPortFeature: C_OVER_CURRENT\n"); |
| 205 | |
| 206 | if (valid_port(wIndex)) { |
| 207 | info->port[wIndex-1].oc_changed = 0; |
| 208 | info->port[wIndex-1].oc_status = 0; |
| 209 | } |
| 210 | |
| 211 | goto out; |
| 212 | |
| 213 | case USB_PORT_FEAT_OVER_CURRENT: |
| 214 | dev_dbg(hcd->self.controller, |
| 215 | "ClearPortFeature: OVER_CURRENT\n"); |
| 216 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 217 | if (valid_port(wIndex)) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 218 | info->port[wIndex-1].oc_status = 0; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 219 | |
| 220 | goto out; |
| 221 | |
| 222 | case USB_PORT_FEAT_POWER: |
| 223 | dev_dbg(hcd->self.controller, |
| 224 | "ClearPortFeature: POWER\n"); |
| 225 | |
| 226 | if (valid_port(wIndex)) { |
| 227 | s3c2410_usb_set_power(info, wIndex, 0); |
| 228 | return 0; |
| 229 | } |
| 230 | } |
| 231 | break; |
| 232 | } |
| 233 | |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 234 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 235 | if (ret) |
| 236 | goto out; |
| 237 | |
| 238 | switch (typeReq) { |
| 239 | case GetHubDescriptor: |
| 240 | |
| 241 | /* update the hub's descriptor */ |
| 242 | |
| 243 | desc = (struct usb_hub_descriptor *)buf; |
| 244 | |
| 245 | if (info->power_control == NULL) |
| 246 | return ret; |
| 247 | |
| 248 | dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", |
| 249 | desc->wHubCharacteristics); |
| 250 | |
| 251 | /* remove the old configurations for power-switching, and |
| 252 | * over-current protection, and insert our new configuration |
| 253 | */ |
| 254 | |
| 255 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); |
| 256 | desc->wHubCharacteristics |= cpu_to_le16(0x0001); |
| 257 | |
| 258 | if (info->enable_oc) { |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 259 | desc->wHubCharacteristics &= ~cpu_to_le16( |
| 260 | HUB_CHAR_OCPM); |
| 261 | desc->wHubCharacteristics |= cpu_to_le16( |
| 262 | 0x0008 | |
| 263 | 0x0001); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", |
| 267 | desc->wHubCharacteristics); |
| 268 | |
| 269 | return ret; |
| 270 | |
| 271 | case GetPortStatus: |
| 272 | /* check port status */ |
| 273 | |
| 274 | dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); |
| 275 | |
| 276 | if (valid_port(wIndex)) { |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 277 | if (info->port[wIndex-1].oc_changed) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 278 | *data |= cpu_to_le32(RH_PS_OCIC); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 279 | |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 280 | if (info->port[wIndex-1].oc_status) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 281 | *data |= cpu_to_le32(RH_PS_POCI); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | out: |
| 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | /* s3c2410_hcd_oc |
| 290 | * |
| 291 | * handle an over-current report |
| 292 | */ |
| 293 | |
| 294 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc) |
| 295 | { |
| 296 | struct s3c2410_hcd_port *port; |
| 297 | struct usb_hcd *hcd; |
| 298 | unsigned long flags; |
| 299 | int portno; |
| 300 | |
| 301 | if (info == NULL) |
| 302 | return; |
| 303 | |
| 304 | port = &info->port[0]; |
| 305 | hcd = info->hcd; |
| 306 | |
| 307 | local_irq_save(flags); |
| 308 | |
| 309 | for (portno = 0; portno < 2; port++, portno++) { |
| 310 | if (port_oc & (1<<portno) && |
| 311 | port->flags & S3C_HCDFLG_USED) { |
| 312 | port->oc_status = 1; |
| 313 | port->oc_changed = 1; |
| 314 | |
| 315 | /* ok, once over-current is detected, |
| 316 | the port needs to be powered down */ |
| 317 | s3c2410_usb_set_power(info, portno+1, 0); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | local_irq_restore(flags); |
| 322 | } |
| 323 | |
| 324 | /* may be called without controller electrically present */ |
| 325 | /* may be called with controller, bus, and devices active */ |
| 326 | |
| 327 | /* |
| 328 | * usb_hcd_s3c2410_remove - shutdown processing for HCD |
| 329 | * @dev: USB Host Controller being removed |
| 330 | * Context: !in_interrupt() |
| 331 | * |
| 332 | * Reverses the effect of usb_hcd_3c2410_probe(), first invoking |
| 333 | * the HCD's stop() method. It is always called from a thread |
| 334 | * context, normally "rmmod", "apmd", or something similar. |
| 335 | * |
| 336 | */ |
| 337 | |
Ben Dooks | f096e04 | 2006-03-21 22:54:47 +0000 | [diff] [blame] | 338 | static void |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 339 | usb_hcd_s3c2410_remove(struct usb_hcd *hcd, struct platform_device *dev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 340 | { |
| 341 | usb_remove_hcd(hcd); |
| 342 | s3c2410_stop_hc(dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 343 | usb_put_hcd(hcd); |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs |
| 348 | * Context: !in_interrupt() |
| 349 | * |
| 350 | * Allocates basic resources for this USB host controller, and |
| 351 | * then invokes the start() method for the HCD associated with it |
| 352 | * through the hotplug entry's driver_data. |
| 353 | * |
| 354 | */ |
Jingoo Han | 7af85a8 | 2011-05-04 16:45:47 +0900 | [diff] [blame] | 355 | static int usb_hcd_s3c2410_probe(const struct hc_driver *driver, |
Ben Dooks | f096e04 | 2006-03-21 22:54:47 +0000 | [diff] [blame] | 356 | struct platform_device *dev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 357 | { |
| 358 | struct usb_hcd *hcd = NULL; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 359 | struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 360 | int retval; |
| 361 | |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 362 | s3c2410_usb_set_power(info, 1, 1); |
| 363 | s3c2410_usb_set_power(info, 2, 1); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 364 | |
| 365 | hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx"); |
| 366 | if (hcd == NULL) |
| 367 | return -ENOMEM; |
| 368 | |
| 369 | hcd->rsrc_start = dev->resource[0].start; |
Jingoo Han | 3c86c07 | 2011-04-14 21:09:16 +0900 | [diff] [blame] | 370 | hcd->rsrc_len = resource_size(&dev->resource[0]); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 371 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 372 | hcd->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); |
| 373 | if (IS_ERR(hcd->regs)) { |
| 374 | retval = PTR_ERR(hcd->regs); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 375 | goto err_put; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 378 | clk = devm_clk_get(&dev->dev, "usb-host"); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 379 | if (IS_ERR(clk)) { |
| 380 | dev_err(&dev->dev, "cannot get usb-host clock\n"); |
Jingoo Han | 69248d4 | 2011-05-05 08:46:07 +0900 | [diff] [blame] | 381 | retval = PTR_ERR(clk); |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 382 | goto err_put; |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 385 | usb_clk = devm_clk_get(&dev->dev, "usb-bus-host"); |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 386 | if (IS_ERR(usb_clk)) { |
Ben Dooks | 2dfa319 | 2009-02-26 23:03:15 +0000 | [diff] [blame] | 387 | dev_err(&dev->dev, "cannot get usb-bus-host clock\n"); |
Jingoo Han | 69248d4 | 2011-05-05 08:46:07 +0900 | [diff] [blame] | 388 | retval = PTR_ERR(usb_clk); |
Jingoo Han | 801f006 | 2012-10-08 11:28:25 +0900 | [diff] [blame] | 389 | goto err_put; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 392 | s3c2410_start_hc(dev, hcd); |
| 393 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 394 | retval = usb_add_hcd(hcd, dev->resource[1].start, 0); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 395 | if (retval != 0) |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 396 | goto err_ioremap; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 397 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 398 | device_wakeup_enable(hcd->self.controller); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 399 | return 0; |
| 400 | |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 401 | err_ioremap: |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 402 | s3c2410_stop_hc(dev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 403 | |
Ben Dooks | 3799c40 | 2006-04-02 01:45:00 +0100 | [diff] [blame] | 404 | err_put: |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 405 | usb_put_hcd(hcd); |
| 406 | return retval; |
| 407 | } |
| 408 | |
| 409 | /*-------------------------------------------------------------------------*/ |
| 410 | |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 411 | static struct hc_driver __read_mostly ohci_s3c2410_hc_driver; |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 412 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 413 | static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 414 | { |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 415 | return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev); |
| 416 | } |
| 417 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 418 | static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev) |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 419 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 420 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 421 | |
| 422 | usb_hcd_s3c2410_remove(hcd, pdev); |
| 423 | return 0; |
| 424 | } |
| 425 | |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 426 | #ifdef CONFIG_PM |
| 427 | static int ohci_hcd_s3c2410_drv_suspend(struct device *dev) |
| 428 | { |
| 429 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 430 | struct platform_device *pdev = to_platform_device(dev); |
Majunath Goudar | 0ded36d | 2013-11-13 17:40:18 +0530 | [diff] [blame] | 431 | bool do_wakeup = device_may_wakeup(dev); |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 432 | int rc = 0; |
| 433 | |
Majunath Goudar | 0ded36d | 2013-11-13 17:40:18 +0530 | [diff] [blame] | 434 | rc = ohci_suspend(hcd, do_wakeup); |
| 435 | if (rc) |
| 436 | return rc; |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 437 | |
| 438 | s3c2410_stop_hc(pdev); |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 439 | |
| 440 | return rc; |
| 441 | } |
| 442 | |
| 443 | static int ohci_hcd_s3c2410_drv_resume(struct device *dev) |
| 444 | { |
| 445 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 446 | struct platform_device *pdev = to_platform_device(dev); |
| 447 | |
| 448 | s3c2410_start_hc(pdev, hcd); |
| 449 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 450 | ohci_resume(hcd, false); |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | #else |
| 455 | #define ohci_hcd_s3c2410_drv_suspend NULL |
| 456 | #define ohci_hcd_s3c2410_drv_resume NULL |
| 457 | #endif |
| 458 | |
| 459 | static const struct dev_pm_ops ohci_hcd_s3c2410_pm_ops = { |
| 460 | .suspend = ohci_hcd_s3c2410_drv_suspend, |
| 461 | .resume = ohci_hcd_s3c2410_drv_resume, |
| 462 | }; |
| 463 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 464 | static struct platform_driver ohci_hcd_s3c2410_driver = { |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 465 | .probe = ohci_hcd_s3c2410_drv_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 466 | .remove = ohci_hcd_s3c2410_drv_remove, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 467 | .shutdown = usb_hcd_platform_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 468 | .driver = { |
| 469 | .owner = THIS_MODULE, |
| 470 | .name = "s3c2410-ohci", |
Jingoo Han | b870def | 2011-11-28 15:56:06 +0900 | [diff] [blame] | 471 | .pm = &ohci_hcd_s3c2410_pm_ops, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 472 | }, |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 473 | }; |
| 474 | |
Manjunath Goudar | f23b71f | 2013-09-21 16:38:43 +0530 | [diff] [blame] | 475 | static int __init ohci_s3c2410_init(void) |
| 476 | { |
| 477 | if (usb_disabled()) |
| 478 | return -ENODEV; |
| 479 | |
| 480 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 481 | ohci_init_driver(&ohci_s3c2410_hc_driver, NULL); |
| 482 | |
| 483 | /* |
| 484 | * The Samsung HW has some unusual quirks, which require |
| 485 | * Sumsung-specific workarounds. We override certain hc_driver |
| 486 | * functions here to achieve that. We explicitly do not enhance |
| 487 | * ohci_driver_overrides to allow this more easily, since this |
| 488 | * is an unusual case, and we don't want to encourage others to |
| 489 | * override these functions by making it too easy. |
| 490 | */ |
| 491 | |
| 492 | orig_ohci_hub_control = ohci_s3c2410_hc_driver.hub_control; |
| 493 | orig_ohci_hub_status_data = ohci_s3c2410_hc_driver.hub_status_data; |
| 494 | |
| 495 | ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data; |
| 496 | ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control; |
| 497 | |
| 498 | return platform_driver_register(&ohci_hcd_s3c2410_driver); |
| 499 | } |
| 500 | module_init(ohci_s3c2410_init); |
| 501 | |
| 502 | static void __exit ohci_s3c2410_cleanup(void) |
| 503 | { |
| 504 | platform_driver_unregister(&ohci_hcd_s3c2410_driver); |
| 505 | } |
| 506 | module_exit(ohci_s3c2410_cleanup); |
| 507 | |
| 508 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 509 | MODULE_LICENSE("GPL"); |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 510 | MODULE_ALIAS("platform:s3c2410-ohci"); |