2 * OHCI HCD (Host Controller Driver) for USB.
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
8 * USB Bus Glue for Samsung S3C2410
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
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
17 * Thanks to basprog@mail.ru for updates to newer kernels
19 * This file is licenced under the GPL.
22 #include <linux/clk.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/platform_data/usb-ohci-s3c2410.h>
28 #include <linux/usb.h>
29 #include <linux/usb/hcd.h>
34 #define valid_port(idx) ((idx) == 1 || (idx) == 2)
36 /* clock device associated with the hcd */
39 #define DRIVER_DESC "OHCI S3C2410 driver"
41 static const char hcd_name
[] = "ohci-s3c2410";
43 static struct clk
*clk
;
44 static struct clk
*usb_clk
;
46 /* forward definitions */
48 static void s3c2410_hcd_oc(struct s3c2410_hcd_info
*info
, int port_oc
);
50 /* conversion functions */
52 static struct s3c2410_hcd_info
*to_s3c2410_info(struct usb_hcd
*hcd
)
54 return dev_get_platdata(hcd
->self
.controller
);
57 static void s3c2410_start_hc(struct platform_device
*dev
, struct usb_hcd
*hcd
)
59 struct s3c2410_hcd_info
*info
= dev_get_platdata(&dev
->dev
);
61 dev_dbg(&dev
->dev
, "s3c2410_start_hc:\n");
63 clk_prepare_enable(usb_clk
);
64 mdelay(2); /* let the bus clock stabilise */
66 clk_prepare_enable(clk
);
70 info
->report_oc
= s3c2410_hcd_oc
;
72 if (info
->enable_oc
!= NULL
)
73 (info
->enable_oc
)(info
, 1);
77 static void s3c2410_stop_hc(struct platform_device
*dev
)
79 struct s3c2410_hcd_info
*info
= dev_get_platdata(&dev
->dev
);
81 dev_dbg(&dev
->dev
, "s3c2410_stop_hc:\n");
84 info
->report_oc
= NULL
;
87 if (info
->enable_oc
!= NULL
)
88 (info
->enable_oc
)(info
, 0);
91 clk_disable_unprepare(clk
);
92 clk_disable_unprepare(usb_clk
);
95 /* ohci_s3c2410_hub_status_data
97 * update the status data from the hub with anything that
98 * has been detected by our system
102 ohci_s3c2410_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
104 struct s3c2410_hcd_info
*info
= to_s3c2410_info(hcd
);
105 struct s3c2410_hcd_port
*port
;
109 orig
= ohci_hub_status_data(hcd
, buf
);
114 port
= &info
->port
[0];
116 /* mark any changed port as changed */
118 for (portno
= 0; portno
< 2; port
++, portno
++) {
119 if (port
->oc_changed
== 1 &&
120 port
->flags
& S3C_HCDFLG_USED
) {
121 dev_dbg(hcd
->self
.controller
,
122 "oc change on port %d\n", portno
);
127 buf
[0] |= 1<<(portno
+1);
134 /* s3c2410_usb_set_power
136 * configure the power on a port, by calling the platform device
137 * routine registered with the platform device
140 static void s3c2410_usb_set_power(struct s3c2410_hcd_info
*info
,
146 if (info
->power_control
!= NULL
) {
147 info
->port
[port
-1].power
= to
;
148 (info
->power_control
)(port
-1, to
);
152 /* ohci_s3c2410_hub_control
154 * look at control requests to the hub, and see if we need
155 * to take any action or over-ride the results from the
159 static int ohci_s3c2410_hub_control(
167 struct s3c2410_hcd_info
*info
= to_s3c2410_info(hcd
);
168 struct usb_hub_descriptor
*desc
;
170 u32
*data
= (u32
*)buf
;
172 dev_dbg(hcd
->self
.controller
,
173 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
174 hcd
, typeReq
, wValue
, wIndex
, buf
, wLength
);
176 /* if we are only an humble host without any special capabilities
177 * process the request straight away and exit */
180 ret
= ohci_hub_control(hcd
, typeReq
, wValue
,
181 wIndex
, buf
, wLength
);
185 /* check the request to see if it needs handling */
189 if (wValue
== USB_PORT_FEAT_POWER
) {
190 dev_dbg(hcd
->self
.controller
, "SetPortFeat: POWER\n");
191 s3c2410_usb_set_power(info
, wIndex
, 1);
196 case ClearPortFeature
:
198 case USB_PORT_FEAT_C_OVER_CURRENT
:
199 dev_dbg(hcd
->self
.controller
,
200 "ClearPortFeature: C_OVER_CURRENT\n");
202 if (valid_port(wIndex
)) {
203 info
->port
[wIndex
-1].oc_changed
= 0;
204 info
->port
[wIndex
-1].oc_status
= 0;
209 case USB_PORT_FEAT_OVER_CURRENT
:
210 dev_dbg(hcd
->self
.controller
,
211 "ClearPortFeature: OVER_CURRENT\n");
213 if (valid_port(wIndex
))
214 info
->port
[wIndex
-1].oc_status
= 0;
218 case USB_PORT_FEAT_POWER
:
219 dev_dbg(hcd
->self
.controller
,
220 "ClearPortFeature: POWER\n");
222 if (valid_port(wIndex
)) {
223 s3c2410_usb_set_power(info
, wIndex
, 0);
230 ret
= ohci_hub_control(hcd
, typeReq
, wValue
, wIndex
, buf
, wLength
);
235 case GetHubDescriptor
:
237 /* update the hub's descriptor */
239 desc
= (struct usb_hub_descriptor
*)buf
;
241 if (info
->power_control
== NULL
)
244 dev_dbg(hcd
->self
.controller
, "wHubCharacteristics 0x%04x\n",
245 desc
->wHubCharacteristics
);
247 /* remove the old configurations for power-switching, and
248 * over-current protection, and insert our new configuration
251 desc
->wHubCharacteristics
&= ~cpu_to_le16(HUB_CHAR_LPSM
);
252 desc
->wHubCharacteristics
|= cpu_to_le16(
253 HUB_CHAR_INDV_PORT_LPSM
);
255 if (info
->enable_oc
) {
256 desc
->wHubCharacteristics
&= ~cpu_to_le16(
258 desc
->wHubCharacteristics
|= cpu_to_le16(
259 HUB_CHAR_INDV_PORT_OCPM
);
262 dev_dbg(hcd
->self
.controller
, "wHubCharacteristics after 0x%04x\n",
263 desc
->wHubCharacteristics
);
268 /* check port status */
270 dev_dbg(hcd
->self
.controller
, "GetPortStatus(%d)\n", wIndex
);
272 if (valid_port(wIndex
)) {
273 if (info
->port
[wIndex
-1].oc_changed
)
274 *data
|= cpu_to_le32(RH_PS_OCIC
);
276 if (info
->port
[wIndex
-1].oc_status
)
277 *data
|= cpu_to_le32(RH_PS_POCI
);
287 * handle an over-current report
290 static void s3c2410_hcd_oc(struct s3c2410_hcd_info
*info
, int port_oc
)
292 struct s3c2410_hcd_port
*port
;
300 port
= &info
->port
[0];
303 local_irq_save(flags
);
305 for (portno
= 0; portno
< 2; port
++, portno
++) {
306 if (port_oc
& (1<<portno
) &&
307 port
->flags
& S3C_HCDFLG_USED
) {
309 port
->oc_changed
= 1;
311 /* ok, once over-current is detected,
312 the port needs to be powered down */
313 s3c2410_usb_set_power(info
, portno
+1, 0);
317 local_irq_restore(flags
);
320 /* may be called without controller electrically present */
321 /* may be called with controller, bus, and devices active */
324 * usb_hcd_s3c2410_remove - shutdown processing for HCD
325 * @dev: USB Host Controller being removed
326 * Context: !in_interrupt()
328 * Reverses the effect of usb_hcd_3c2410_probe(), first invoking
329 * the HCD's stop() method. It is always called from a thread
330 * context, normally "rmmod", "apmd", or something similar.
335 usb_hcd_s3c2410_remove(struct usb_hcd
*hcd
, struct platform_device
*dev
)
338 s3c2410_stop_hc(dev
);
343 * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs
344 * Context: !in_interrupt()
346 * Allocates basic resources for this USB host controller, and
347 * then invokes the start() method for the HCD associated with it
348 * through the hotplug entry's driver_data.
351 static int usb_hcd_s3c2410_probe(const struct hc_driver
*driver
,
352 struct platform_device
*dev
)
354 struct usb_hcd
*hcd
= NULL
;
355 struct s3c2410_hcd_info
*info
= dev_get_platdata(&dev
->dev
);
358 s3c2410_usb_set_power(info
, 1, 1);
359 s3c2410_usb_set_power(info
, 2, 1);
361 hcd
= usb_create_hcd(driver
, &dev
->dev
, "s3c24xx");
365 hcd
->rsrc_start
= dev
->resource
[0].start
;
366 hcd
->rsrc_len
= resource_size(&dev
->resource
[0]);
368 hcd
->regs
= devm_ioremap_resource(&dev
->dev
, &dev
->resource
[0]);
369 if (IS_ERR(hcd
->regs
)) {
370 retval
= PTR_ERR(hcd
->regs
);
374 clk
= devm_clk_get(&dev
->dev
, "usb-host");
376 dev_err(&dev
->dev
, "cannot get usb-host clock\n");
377 retval
= PTR_ERR(clk
);
381 usb_clk
= devm_clk_get(&dev
->dev
, "usb-bus-host");
382 if (IS_ERR(usb_clk
)) {
383 dev_err(&dev
->dev
, "cannot get usb-bus-host clock\n");
384 retval
= PTR_ERR(usb_clk
);
388 s3c2410_start_hc(dev
, hcd
);
390 retval
= usb_add_hcd(hcd
, dev
->resource
[1].start
, 0);
394 device_wakeup_enable(hcd
->self
.controller
);
398 s3c2410_stop_hc(dev
);
405 /*-------------------------------------------------------------------------*/
407 static struct hc_driver __read_mostly ohci_s3c2410_hc_driver
;
409 static int ohci_hcd_s3c2410_drv_probe(struct platform_device
*pdev
)
411 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver
, pdev
);
414 static int ohci_hcd_s3c2410_drv_remove(struct platform_device
*pdev
)
416 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
418 usb_hcd_s3c2410_remove(hcd
, pdev
);
423 static int ohci_hcd_s3c2410_drv_suspend(struct device
*dev
)
425 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
426 struct platform_device
*pdev
= to_platform_device(dev
);
427 bool do_wakeup
= device_may_wakeup(dev
);
430 rc
= ohci_suspend(hcd
, do_wakeup
);
434 s3c2410_stop_hc(pdev
);
439 static int ohci_hcd_s3c2410_drv_resume(struct device
*dev
)
441 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
442 struct platform_device
*pdev
= to_platform_device(dev
);
444 s3c2410_start_hc(pdev
, hcd
);
446 ohci_resume(hcd
, false);
451 #define ohci_hcd_s3c2410_drv_suspend NULL
452 #define ohci_hcd_s3c2410_drv_resume NULL
455 static const struct dev_pm_ops ohci_hcd_s3c2410_pm_ops
= {
456 .suspend
= ohci_hcd_s3c2410_drv_suspend
,
457 .resume
= ohci_hcd_s3c2410_drv_resume
,
460 static struct platform_driver ohci_hcd_s3c2410_driver
= {
461 .probe
= ohci_hcd_s3c2410_drv_probe
,
462 .remove
= ohci_hcd_s3c2410_drv_remove
,
463 .shutdown
= usb_hcd_platform_shutdown
,
465 .name
= "s3c2410-ohci",
466 .pm
= &ohci_hcd_s3c2410_pm_ops
,
470 static int __init
ohci_s3c2410_init(void)
475 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
476 ohci_init_driver(&ohci_s3c2410_hc_driver
, NULL
);
479 * The Samsung HW has some unusual quirks, which require
480 * Sumsung-specific workarounds. We override certain hc_driver
481 * functions here to achieve that. We explicitly do not enhance
482 * ohci_driver_overrides to allow this more easily, since this
483 * is an unusual case, and we don't want to encourage others to
484 * override these functions by making it too easy.
487 ohci_s3c2410_hc_driver
.hub_status_data
= ohci_s3c2410_hub_status_data
;
488 ohci_s3c2410_hc_driver
.hub_control
= ohci_s3c2410_hub_control
;
490 return platform_driver_register(&ohci_hcd_s3c2410_driver
);
492 module_init(ohci_s3c2410_init
);
494 static void __exit
ohci_s3c2410_cleanup(void)
496 platform_driver_unregister(&ohci_hcd_s3c2410_driver
);
498 module_exit(ohci_s3c2410_cleanup
);
500 MODULE_DESCRIPTION(DRIVER_DESC
);
501 MODULE_LICENSE("GPL");
502 MODULE_ALIAS("platform:s3c2410-ohci");