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 <asm/hardware.h>
26 #include <asm/arch/usb-control.h>
28 #define valid_port(idx) ((idx) == 1 || (idx) == 2)
30 /* clock device associated with the hcd */
32 static struct clk
*clk
;
33 static struct clk
*usb_clk
;
35 /* forward definitions */
37 static void s3c2410_hcd_oc(struct s3c2410_hcd_info
*info
, int port_oc
);
39 /* conversion functions */
41 static struct s3c2410_hcd_info
*to_s3c2410_info(struct usb_hcd
*hcd
)
43 return hcd
->self
.controller
->platform_data
;
46 static void s3c2410_start_hc(struct platform_device
*dev
, struct usb_hcd
*hcd
)
48 struct s3c2410_hcd_info
*info
= dev
->dev
.platform_data
;
50 dev_dbg(&dev
->dev
, "s3c2410_start_hc:\n");
53 mdelay(2); /* let the bus clock stabilise */
59 info
->report_oc
= s3c2410_hcd_oc
;
61 if (info
->enable_oc
!= NULL
) {
62 (info
->enable_oc
)(info
, 1);
67 static void s3c2410_stop_hc(struct platform_device
*dev
)
69 struct s3c2410_hcd_info
*info
= dev
->dev
.platform_data
;
71 dev_dbg(&dev
->dev
, "s3c2410_stop_hc:\n");
74 info
->report_oc
= NULL
;
77 if (info
->enable_oc
!= NULL
) {
78 (info
->enable_oc
)(info
, 0);
86 /* ohci_s3c2410_hub_status_data
88 * update the status data from the hub with anything that
89 * has been detected by our system
93 ohci_s3c2410_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
95 struct s3c2410_hcd_info
*info
= to_s3c2410_info(hcd
);
96 struct s3c2410_hcd_port
*port
;
100 orig
= ohci_hub_status_data (hcd
, buf
);
105 port
= &info
->port
[0];
107 /* mark any changed port as changed */
109 for (portno
= 0; portno
< 2; port
++, portno
++) {
110 if (port
->oc_changed
== 1 &&
111 port
->flags
& S3C_HCDFLG_USED
) {
112 dev_dbg(hcd
->self
.controller
,
113 "oc change on port %d\n", portno
);
118 buf
[0] |= 1<<(portno
+1);
125 /* s3c2410_usb_set_power
127 * configure the power on a port, by calling the platform device
128 * routine registered with the platform device
131 static void s3c2410_usb_set_power(struct s3c2410_hcd_info
*info
,
137 if (info
->power_control
!= NULL
) {
138 info
->port
[port
-1].power
= to
;
139 (info
->power_control
)(port
-1, to
);
143 /* ohci_s3c2410_hub_control
145 * look at control requests to the hub, and see if we need
146 * to take any action or over-ride the results from the
150 static int ohci_s3c2410_hub_control (
158 struct s3c2410_hcd_info
*info
= to_s3c2410_info(hcd
);
159 struct usb_hub_descriptor
*desc
;
161 u32
*data
= (u32
*)buf
;
163 dev_dbg(hcd
->self
.controller
,
164 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
165 hcd
, typeReq
, wValue
, wIndex
, buf
, wLength
);
167 /* if we are only an humble host without any special capabilities
168 * process the request straight away and exit */
171 ret
= ohci_hub_control(hcd
, typeReq
, wValue
,
172 wIndex
, buf
, wLength
);
176 /* check the request to see if it needs handling */
180 if (wValue
== USB_PORT_FEAT_POWER
) {
181 dev_dbg(hcd
->self
.controller
, "SetPortFeat: POWER\n");
182 s3c2410_usb_set_power(info
, wIndex
, 1);
187 case ClearPortFeature
:
189 case USB_PORT_FEAT_C_OVER_CURRENT
:
190 dev_dbg(hcd
->self
.controller
,
191 "ClearPortFeature: C_OVER_CURRENT\n");
193 if (valid_port(wIndex
)) {
194 info
->port
[wIndex
-1].oc_changed
= 0;
195 info
->port
[wIndex
-1].oc_status
= 0;
200 case USB_PORT_FEAT_OVER_CURRENT
:
201 dev_dbg(hcd
->self
.controller
,
202 "ClearPortFeature: OVER_CURRENT\n");
204 if (valid_port(wIndex
)) {
205 info
->port
[wIndex
-1].oc_status
= 0;
210 case USB_PORT_FEAT_POWER
:
211 dev_dbg(hcd
->self
.controller
,
212 "ClearPortFeature: POWER\n");
214 if (valid_port(wIndex
)) {
215 s3c2410_usb_set_power(info
, wIndex
, 0);
222 ret
= ohci_hub_control(hcd
, typeReq
, wValue
, wIndex
, buf
, wLength
);
227 case GetHubDescriptor
:
229 /* update the hub's descriptor */
231 desc
= (struct usb_hub_descriptor
*)buf
;
233 if (info
->power_control
== NULL
)
236 dev_dbg(hcd
->self
.controller
, "wHubCharacteristics 0x%04x\n",
237 desc
->wHubCharacteristics
);
239 /* remove the old configurations for power-switching, and
240 * over-current protection, and insert our new configuration
243 desc
->wHubCharacteristics
&= ~cpu_to_le16(HUB_CHAR_LPSM
);
244 desc
->wHubCharacteristics
|= cpu_to_le16(0x0001);
246 if (info
->enable_oc
) {
247 desc
->wHubCharacteristics
&= ~cpu_to_le16(HUB_CHAR_OCPM
);
248 desc
->wHubCharacteristics
|= cpu_to_le16(0x0008|0x0001);
251 dev_dbg(hcd
->self
.controller
, "wHubCharacteristics after 0x%04x\n",
252 desc
->wHubCharacteristics
);
257 /* check port status */
259 dev_dbg(hcd
->self
.controller
, "GetPortStatus(%d)\n", wIndex
);
261 if (valid_port(wIndex
)) {
262 if (info
->port
[wIndex
-1].oc_changed
) {
263 *data
|= cpu_to_le32(RH_PS_OCIC
);
266 if (info
->port
[wIndex
-1].oc_status
) {
267 *data
|= cpu_to_le32(RH_PS_POCI
);
278 * handle an over-current report
281 static void s3c2410_hcd_oc(struct s3c2410_hcd_info
*info
, int port_oc
)
283 struct s3c2410_hcd_port
*port
;
291 port
= &info
->port
[0];
294 local_irq_save(flags
);
296 for (portno
= 0; portno
< 2; port
++, portno
++) {
297 if (port_oc
& (1<<portno
) &&
298 port
->flags
& S3C_HCDFLG_USED
) {
300 port
->oc_changed
= 1;
302 /* ok, once over-current is detected,
303 the port needs to be powered down */
304 s3c2410_usb_set_power(info
, portno
+1, 0);
308 local_irq_restore(flags
);
311 /* may be called without controller electrically present */
312 /* may be called with controller, bus, and devices active */
315 * usb_hcd_s3c2410_remove - shutdown processing for HCD
316 * @dev: USB Host Controller being removed
317 * Context: !in_interrupt()
319 * Reverses the effect of usb_hcd_3c2410_probe(), first invoking
320 * the HCD's stop() method. It is always called from a thread
321 * context, normally "rmmod", "apmd", or something similar.
326 usb_hcd_s3c2410_remove (struct usb_hcd
*hcd
, struct platform_device
*dev
)
329 s3c2410_stop_hc(dev
);
331 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
336 * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs
337 * Context: !in_interrupt()
339 * Allocates basic resources for this USB host controller, and
340 * then invokes the start() method for the HCD associated with it
341 * through the hotplug entry's driver_data.
344 static int usb_hcd_s3c2410_probe (const struct hc_driver
*driver
,
345 struct platform_device
*dev
)
347 struct usb_hcd
*hcd
= NULL
;
350 s3c2410_usb_set_power(dev
->dev
.platform_data
, 1, 1);
351 s3c2410_usb_set_power(dev
->dev
.platform_data
, 2, 1);
353 hcd
= usb_create_hcd(driver
, &dev
->dev
, "s3c24xx");
357 hcd
->rsrc_start
= dev
->resource
[0].start
;
358 hcd
->rsrc_len
= dev
->resource
[0].end
- dev
->resource
[0].start
+ 1;
360 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
361 dev_err(&dev
->dev
, "request_mem_region failed\n");
366 clk
= clk_get(&dev
->dev
, "usb-host");
368 dev_err(&dev
->dev
, "cannot get usb-host clock\n");
373 usb_clk
= clk_get(&dev
->dev
, "usb-bus-host");
374 if (IS_ERR(usb_clk
)) {
375 dev_err(&dev
->dev
, "cannot get usb-host clock\n");
380 s3c2410_start_hc(dev
, hcd
);
382 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
384 dev_err(&dev
->dev
, "ioremap failed\n");
389 ohci_hcd_init(hcd_to_ohci(hcd
));
391 retval
= usb_add_hcd(hcd
, dev
->resource
[1].start
, IRQF_DISABLED
);
398 s3c2410_stop_hc(dev
);
406 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
413 /*-------------------------------------------------------------------------*/
416 ohci_s3c2410_start (struct usb_hcd
*hcd
)
418 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
421 if ((ret
= ohci_init(ohci
)) < 0)
424 if ((ret
= ohci_run (ohci
)) < 0) {
425 err ("can't start %s", hcd
->self
.bus_name
);
434 static const struct hc_driver ohci_s3c2410_hc_driver
= {
435 .description
= hcd_name
,
436 .product_desc
= "S3C24XX OHCI",
437 .hcd_priv_size
= sizeof(struct ohci_hcd
),
440 * generic hardware linkage
443 .flags
= HCD_USB11
| HCD_MEMORY
,
446 * basic lifecycle operations
448 .start
= ohci_s3c2410_start
,
450 .shutdown
= ohci_shutdown
,
453 * managing i/o requests and associated device resources
455 .urb_enqueue
= ohci_urb_enqueue
,
456 .urb_dequeue
= ohci_urb_dequeue
,
457 .endpoint_disable
= ohci_endpoint_disable
,
462 .get_frame_number
= ohci_get_frame
,
467 .hub_status_data
= ohci_s3c2410_hub_status_data
,
468 .hub_control
= ohci_s3c2410_hub_control
,
469 .hub_irq_enable
= ohci_rhsc_enable
,
471 .bus_suspend
= ohci_bus_suspend
,
472 .bus_resume
= ohci_bus_resume
,
474 .start_port_reset
= ohci_start_port_reset
,
479 static int ohci_hcd_s3c2410_drv_probe(struct platform_device
*pdev
)
481 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver
, pdev
);
484 static int ohci_hcd_s3c2410_drv_remove(struct platform_device
*pdev
)
486 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
488 usb_hcd_s3c2410_remove(hcd
, pdev
);
492 static struct platform_driver ohci_hcd_s3c2410_driver
= {
493 .probe
= ohci_hcd_s3c2410_drv_probe
,
494 .remove
= ohci_hcd_s3c2410_drv_remove
,
495 .shutdown
= usb_hcd_platform_shutdown
,
496 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
497 /*.resume = ohci_hcd_s3c2410_drv_resume, */
499 .owner
= THIS_MODULE
,
500 .name
= "s3c2410-ohci",
504 MODULE_ALIAS("platform:s3c2410-ohci");