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>
25 #include <mach/usb-control.h>
27 #define valid_port(idx) ((idx) == 1 || (idx) == 2)
29 /* clock device associated with the hcd */
31 static struct clk *clk;
32 static struct clk *usb_clk;
34 /* forward definitions */
36 static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
38 /* conversion functions */
40 static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
42 return hcd->self.controller->platform_data;
45 static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
47 struct s3c2410_hcd_info *info = dev->dev.platform_data;
49 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
52 mdelay(2); /* let the bus clock stabilise */
58 info->report_oc = s3c2410_hcd_oc;
60 if (info->enable_oc != NULL) {
61 (info->enable_oc)(info, 1);
66 static void s3c2410_stop_hc(struct platform_device *dev)
68 struct s3c2410_hcd_info *info = dev->dev.platform_data;
70 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
73 info->report_oc = NULL;
76 if (info->enable_oc != NULL) {
77 (info->enable_oc)(info, 0);
85 /* ohci_s3c2410_hub_status_data
87 * update the status data from the hub with anything that
88 * has been detected by our system
92 ohci_s3c2410_hub_status_data (struct usb_hcd *hcd, char *buf)
94 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
95 struct s3c2410_hcd_port *port;
99 orig = ohci_hub_status_data (hcd, buf);
104 port = &info->port[0];
106 /* mark any changed port as changed */
108 for (portno = 0; portno < 2; port++, portno++) {
109 if (port->oc_changed == 1 &&
110 port->flags & S3C_HCDFLG_USED) {
111 dev_dbg(hcd->self.controller,
112 "oc change on port %d\n", portno);
117 buf[0] |= 1<<(portno+1);
124 /* s3c2410_usb_set_power
126 * configure the power on a port, by calling the platform device
127 * routine registered with the platform device
130 static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
136 if (info->power_control != NULL) {
137 info->port[port-1].power = to;
138 (info->power_control)(port-1, to);
142 /* ohci_s3c2410_hub_control
144 * look at control requests to the hub, and see if we need
145 * to take any action or over-ride the results from the
149 static int ohci_s3c2410_hub_control (
157 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
158 struct usb_hub_descriptor *desc;
160 u32 *data = (u32 *)buf;
162 dev_dbg(hcd->self.controller,
163 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
164 hcd, typeReq, wValue, wIndex, buf, wLength);
166 /* if we are only an humble host without any special capabilities
167 * process the request straight away and exit */
170 ret = ohci_hub_control(hcd, typeReq, wValue,
171 wIndex, buf, wLength);
175 /* check the request to see if it needs handling */
179 if (wValue == USB_PORT_FEAT_POWER) {
180 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
181 s3c2410_usb_set_power(info, wIndex, 1);
186 case ClearPortFeature:
188 case USB_PORT_FEAT_C_OVER_CURRENT:
189 dev_dbg(hcd->self.controller,
190 "ClearPortFeature: C_OVER_CURRENT\n");
192 if (valid_port(wIndex)) {
193 info->port[wIndex-1].oc_changed = 0;
194 info->port[wIndex-1].oc_status = 0;
199 case USB_PORT_FEAT_OVER_CURRENT:
200 dev_dbg(hcd->self.controller,
201 "ClearPortFeature: OVER_CURRENT\n");
203 if (valid_port(wIndex)) {
204 info->port[wIndex-1].oc_status = 0;
209 case USB_PORT_FEAT_POWER:
210 dev_dbg(hcd->self.controller,
211 "ClearPortFeature: POWER\n");
213 if (valid_port(wIndex)) {
214 s3c2410_usb_set_power(info, wIndex, 0);
221 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
226 case GetHubDescriptor:
228 /* update the hub's descriptor */
230 desc = (struct usb_hub_descriptor *)buf;
232 if (info->power_control == NULL)
235 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
236 desc->wHubCharacteristics);
238 /* remove the old configurations for power-switching, and
239 * over-current protection, and insert our new configuration
242 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
243 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
245 if (info->enable_oc) {
246 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
247 desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
250 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
251 desc->wHubCharacteristics);
256 /* check port status */
258 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
260 if (valid_port(wIndex)) {
261 if (info->port[wIndex-1].oc_changed) {
262 *data |= cpu_to_le32(RH_PS_OCIC);
265 if (info->port[wIndex-1].oc_status) {
266 *data |= cpu_to_le32(RH_PS_POCI);
277 * handle an over-current report
280 static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
282 struct s3c2410_hcd_port *port;
290 port = &info->port[0];
293 local_irq_save(flags);
295 for (portno = 0; portno < 2; port++, portno++) {
296 if (port_oc & (1<<portno) &&
297 port->flags & S3C_HCDFLG_USED) {
299 port->oc_changed = 1;
301 /* ok, once over-current is detected,
302 the port needs to be powered down */
303 s3c2410_usb_set_power(info, portno+1, 0);
307 local_irq_restore(flags);
310 /* may be called without controller electrically present */
311 /* may be called with controller, bus, and devices active */
314 * usb_hcd_s3c2410_remove - shutdown processing for HCD
315 * @dev: USB Host Controller being removed
316 * Context: !in_interrupt()
318 * Reverses the effect of usb_hcd_3c2410_probe(), first invoking
319 * the HCD's stop() method. It is always called from a thread
320 * context, normally "rmmod", "apmd", or something similar.
325 usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
328 s3c2410_stop_hc(dev);
330 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
335 * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs
336 * Context: !in_interrupt()
338 * Allocates basic resources for this USB host controller, and
339 * then invokes the start() method for the HCD associated with it
340 * through the hotplug entry's driver_data.
343 static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
344 struct platform_device *dev)
346 struct usb_hcd *hcd = NULL;
349 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);
350 s3c2410_usb_set_power(dev->dev.platform_data, 2, 1);
352 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
356 hcd->rsrc_start = dev->resource[0].start;
357 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
359 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
360 dev_err(&dev->dev, "request_mem_region failed\n");
365 clk = clk_get(&dev->dev, "usb-host");
367 dev_err(&dev->dev, "cannot get usb-host clock\n");
372 usb_clk = clk_get(&dev->dev, "usb-bus-host");
373 if (IS_ERR(usb_clk)) {
374 dev_err(&dev->dev, "cannot get usb-bus-host clock\n");
379 s3c2410_start_hc(dev, hcd);
381 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
383 dev_err(&dev->dev, "ioremap failed\n");
388 ohci_hcd_init(hcd_to_ohci(hcd));
390 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
397 s3c2410_stop_hc(dev);
405 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
412 /*-------------------------------------------------------------------------*/
415 ohci_s3c2410_start (struct usb_hcd *hcd)
417 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
420 if ((ret = ohci_init(ohci)) < 0)
423 if ((ret = ohci_run (ohci)) < 0) {
424 err ("can't start %s", hcd->self.bus_name);
433 static const struct hc_driver ohci_s3c2410_hc_driver = {
434 .description = hcd_name,
435 .product_desc = "S3C24XX OHCI",
436 .hcd_priv_size = sizeof(struct ohci_hcd),
439 * generic hardware linkage
442 .flags = HCD_USB11 | HCD_MEMORY,
445 * basic lifecycle operations
447 .start = ohci_s3c2410_start,
449 .shutdown = ohci_shutdown,
452 * managing i/o requests and associated device resources
454 .urb_enqueue = ohci_urb_enqueue,
455 .urb_dequeue = ohci_urb_dequeue,
456 .endpoint_disable = ohci_endpoint_disable,
461 .get_frame_number = ohci_get_frame,
466 .hub_status_data = ohci_s3c2410_hub_status_data,
467 .hub_control = ohci_s3c2410_hub_control,
469 .bus_suspend = ohci_bus_suspend,
470 .bus_resume = ohci_bus_resume,
472 .start_port_reset = ohci_start_port_reset,
477 static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
479 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev);
482 static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
484 struct usb_hcd *hcd = platform_get_drvdata(pdev);
486 usb_hcd_s3c2410_remove(hcd, pdev);
490 static struct platform_driver ohci_hcd_s3c2410_driver = {
491 .probe = ohci_hcd_s3c2410_drv_probe,
492 .remove = ohci_hcd_s3c2410_drv_remove,
493 .shutdown = usb_hcd_platform_shutdown,
494 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
495 /*.resume = ohci_hcd_s3c2410_drv_resume, */
497 .owner = THIS_MODULE,
498 .name = "s3c2410-ohci",
502 MODULE_ALIAS("platform:s3c2410-ohci");