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/platform_device.h>
23 #include <linux/clk.h>
24 #include <linux/platform_data/usb-ohci-s3c2410.h>
26 #define valid_port(idx) ((idx) == 1 || (idx) == 2)
28 /* clock device associated with the hcd */
30 static struct clk *clk;
31 static struct clk *usb_clk;
33 /* forward definitions */
35 static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
37 /* conversion functions */
39 static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
41 return dev_get_platdata(hcd->self.controller);
44 static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
46 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
48 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
51 mdelay(2); /* let the bus clock stabilise */
57 info->report_oc = s3c2410_hcd_oc;
59 if (info->enable_oc != NULL)
60 (info->enable_oc)(info, 1);
64 static void s3c2410_stop_hc(struct platform_device *dev)
66 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
68 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
71 info->report_oc = NULL;
74 if (info->enable_oc != NULL)
75 (info->enable_oc)(info, 0);
82 /* ohci_s3c2410_hub_status_data
84 * update the status data from the hub with anything that
85 * has been detected by our system
89 ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf)
91 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
92 struct s3c2410_hcd_port *port;
96 orig = ohci_hub_status_data(hcd, buf);
101 port = &info->port[0];
103 /* mark any changed port as changed */
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);
114 buf[0] |= 1<<(portno+1);
121 /* s3c2410_usb_set_power
123 * configure the power on a port, by calling the platform device
124 * routine registered with the platform device
127 static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
133 if (info->power_control != NULL) {
134 info->port[port-1].power = to;
135 (info->power_control)(port-1, to);
139 /* ohci_s3c2410_hub_control
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
146 static int ohci_s3c2410_hub_control(
154 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
155 struct usb_hub_descriptor *desc;
157 u32 *data = (u32 *)buf;
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);
163 /* if we are only an humble host without any special capabilities
164 * process the request straight away and exit */
167 ret = ohci_hub_control(hcd, typeReq, wValue,
168 wIndex, buf, wLength);
172 /* check the request to see if it needs handling */
176 if (wValue == USB_PORT_FEAT_POWER) {
177 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
178 s3c2410_usb_set_power(info, wIndex, 1);
183 case ClearPortFeature:
185 case USB_PORT_FEAT_C_OVER_CURRENT:
186 dev_dbg(hcd->self.controller,
187 "ClearPortFeature: C_OVER_CURRENT\n");
189 if (valid_port(wIndex)) {
190 info->port[wIndex-1].oc_changed = 0;
191 info->port[wIndex-1].oc_status = 0;
196 case USB_PORT_FEAT_OVER_CURRENT:
197 dev_dbg(hcd->self.controller,
198 "ClearPortFeature: OVER_CURRENT\n");
200 if (valid_port(wIndex))
201 info->port[wIndex-1].oc_status = 0;
205 case USB_PORT_FEAT_POWER:
206 dev_dbg(hcd->self.controller,
207 "ClearPortFeature: POWER\n");
209 if (valid_port(wIndex)) {
210 s3c2410_usb_set_power(info, wIndex, 0);
217 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
222 case GetHubDescriptor:
224 /* update the hub's descriptor */
226 desc = (struct usb_hub_descriptor *)buf;
228 if (info->power_control == NULL)
231 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
232 desc->wHubCharacteristics);
234 /* remove the old configurations for power-switching, and
235 * over-current protection, and insert our new configuration
238 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
239 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
241 if (info->enable_oc) {
242 desc->wHubCharacteristics &= ~cpu_to_le16(
244 desc->wHubCharacteristics |= cpu_to_le16(
249 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
250 desc->wHubCharacteristics);
255 /* check port status */
257 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
259 if (valid_port(wIndex)) {
260 if (info->port[wIndex-1].oc_changed)
261 *data |= cpu_to_le32(RH_PS_OCIC);
263 if (info->port[wIndex-1].oc_status)
264 *data |= cpu_to_le32(RH_PS_POCI);
274 * handle an over-current report
277 static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
279 struct s3c2410_hcd_port *port;
287 port = &info->port[0];
290 local_irq_save(flags);
292 for (portno = 0; portno < 2; port++, portno++) {
293 if (port_oc & (1<<portno) &&
294 port->flags & S3C_HCDFLG_USED) {
296 port->oc_changed = 1;
298 /* ok, once over-current is detected,
299 the port needs to be powered down */
300 s3c2410_usb_set_power(info, portno+1, 0);
304 local_irq_restore(flags);
307 /* may be called without controller electrically present */
308 /* may be called with controller, bus, and devices active */
311 * usb_hcd_s3c2410_remove - shutdown processing for HCD
312 * @dev: USB Host Controller being removed
313 * Context: !in_interrupt()
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.
322 usb_hcd_s3c2410_remove(struct usb_hcd *hcd, struct platform_device *dev)
325 s3c2410_stop_hc(dev);
330 * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs
331 * Context: !in_interrupt()
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.
338 static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
339 struct platform_device *dev)
341 struct usb_hcd *hcd = NULL;
342 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
345 s3c2410_usb_set_power(info, 1, 1);
346 s3c2410_usb_set_power(info, 2, 1);
348 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
352 hcd->rsrc_start = dev->resource[0].start;
353 hcd->rsrc_len = resource_size(&dev->resource[0]);
355 hcd->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]);
356 if (IS_ERR(hcd->regs)) {
357 retval = PTR_ERR(hcd->regs);
361 clk = devm_clk_get(&dev->dev, "usb-host");
363 dev_err(&dev->dev, "cannot get usb-host clock\n");
364 retval = PTR_ERR(clk);
368 usb_clk = devm_clk_get(&dev->dev, "usb-bus-host");
369 if (IS_ERR(usb_clk)) {
370 dev_err(&dev->dev, "cannot get usb-bus-host clock\n");
371 retval = PTR_ERR(usb_clk);
375 s3c2410_start_hc(dev, hcd);
377 ohci_hcd_init(hcd_to_ohci(hcd));
379 retval = usb_add_hcd(hcd, dev->resource[1].start, 0);
386 s3c2410_stop_hc(dev);
393 /*-------------------------------------------------------------------------*/
396 ohci_s3c2410_start(struct usb_hcd *hcd)
398 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
401 ret = ohci_init(ohci);
405 ret = ohci_run(ohci);
407 dev_err(hcd->self.controller, "can't start %s\n",
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),
423 * generic hardware linkage
426 .flags = HCD_USB11 | HCD_MEMORY,
429 * basic lifecycle operations
431 .start = ohci_s3c2410_start,
433 .shutdown = ohci_shutdown,
436 * managing i/o requests and associated device resources
438 .urb_enqueue = ohci_urb_enqueue,
439 .urb_dequeue = ohci_urb_dequeue,
440 .endpoint_disable = ohci_endpoint_disable,
445 .get_frame_number = ohci_get_frame,
450 .hub_status_data = ohci_s3c2410_hub_status_data,
451 .hub_control = ohci_s3c2410_hub_control,
453 .bus_suspend = ohci_bus_suspend,
454 .bus_resume = ohci_bus_resume,
456 .start_port_reset = ohci_start_port_reset,
461 static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
463 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev);
466 static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
468 struct usb_hcd *hcd = platform_get_drvdata(pdev);
470 usb_hcd_s3c2410_remove(hcd, pdev);
475 static int ohci_hcd_s3c2410_drv_suspend(struct device *dev)
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);
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.
489 spin_lock_irqsave(&ohci->lock, flags);
490 if (ohci->rh_state != OHCI_RH_SUSPENDED) {
495 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
497 s3c2410_stop_hc(pdev);
499 spin_unlock_irqrestore(&ohci->lock, flags);
504 static int ohci_hcd_s3c2410_drv_resume(struct device *dev)
506 struct usb_hcd *hcd = dev_get_drvdata(dev);
507 struct platform_device *pdev = to_platform_device(dev);
509 s3c2410_start_hc(pdev, hcd);
511 ohci_resume(hcd, false);
516 #define ohci_hcd_s3c2410_drv_suspend NULL
517 #define ohci_hcd_s3c2410_drv_resume NULL
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,
525 static struct platform_driver ohci_hcd_s3c2410_driver = {
526 .probe = ohci_hcd_s3c2410_drv_probe,
527 .remove = ohci_hcd_s3c2410_drv_remove,
528 .shutdown = usb_hcd_platform_shutdown,
530 .owner = THIS_MODULE,
531 .name = "s3c2410-ohci",
532 .pm = &ohci_hcd_s3c2410_pm_ops,
536 MODULE_ALIAS("platform:s3c2410-ohci");