USB: host: mark const variable tables as "const"
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / usb / host / ohci-s3c2410.c
blob3c7a740cfe0ca6fbf1ab14a69972c6d6002c7dce
1 /*
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");
52 clk_enable(usb_clk);
53 mdelay(2); /* let the bus clock stabilise */
55 clk_enable(clk);
57 if (info != NULL) {
58 info->hcd = hcd;
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");
73 if (info != NULL) {
74 info->report_oc = NULL;
75 info->hcd = NULL;
77 if (info->enable_oc != NULL) {
78 (info->enable_oc)(info, 0);
82 clk_disable(clk);
83 clk_disable(usb_clk);
86 /* ohci_s3c2410_hub_status_data
88 * update the status data from the hub with anything that
89 * has been detected by our system
92 static int
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;
97 int orig;
98 int portno;
100 orig = ohci_hub_status_data (hcd, buf);
102 if (info == NULL)
103 return orig;
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);
115 if (orig < 1)
116 orig = 1;
118 buf[0] |= 1<<(portno+1);
122 return orig;
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,
132 int port, int to)
134 if (info == NULL)
135 return;
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
147 * request.
150 static int ohci_s3c2410_hub_control (
151 struct usb_hcd *hcd,
152 u16 typeReq,
153 u16 wValue,
154 u16 wIndex,
155 char *buf,
156 u16 wLength)
158 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
159 struct usb_hub_descriptor *desc;
160 int ret = -EINVAL;
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 */
170 if (info == NULL) {
171 ret = ohci_hub_control(hcd, typeReq, wValue,
172 wIndex, buf, wLength);
173 goto out;
176 /* check the request to see if it needs handling */
178 switch (typeReq) {
179 case SetPortFeature:
180 if (wValue == USB_PORT_FEAT_POWER) {
181 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
182 s3c2410_usb_set_power(info, wIndex, 1);
183 goto out;
185 break;
187 case ClearPortFeature:
188 switch (wValue) {
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;
198 goto out;
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;
208 goto out;
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);
216 return 0;
219 break;
222 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
223 if (ret)
224 goto out;
226 switch (typeReq) {
227 case GetHubDescriptor:
229 /* update the hub's descriptor */
231 desc = (struct usb_hub_descriptor *)buf;
233 if (info->power_control == NULL)
234 return ret;
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);
254 return ret;
256 case GetPortStatus:
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);
272 out:
273 return ret;
276 /* s3c2410_hcd_oc
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;
284 struct usb_hcd *hcd;
285 unsigned long flags;
286 int portno;
288 if (info == NULL)
289 return;
291 port = &info->port[0];
292 hcd = info->hcd;
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) {
299 port->oc_status = 1;
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.
325 static void
326 usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
328 usb_remove_hcd(hcd);
329 s3c2410_stop_hc(dev);
330 iounmap(hcd->regs);
331 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
332 usb_put_hcd(hcd);
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;
348 int retval;
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");
354 if (hcd == NULL)
355 return -ENOMEM;
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");
362 retval = -EBUSY;
363 goto err_put;
366 clk = clk_get(&dev->dev, "usb-host");
367 if (IS_ERR(clk)) {
368 dev_err(&dev->dev, "cannot get usb-host clock\n");
369 retval = -ENOENT;
370 goto err_mem;
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");
376 retval = -ENOENT;
377 goto err_clk;
380 s3c2410_start_hc(dev, hcd);
382 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
383 if (!hcd->regs) {
384 dev_err(&dev->dev, "ioremap failed\n");
385 retval = -ENOMEM;
386 goto err_ioremap;
389 ohci_hcd_init(hcd_to_ohci(hcd));
391 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
392 if (retval != 0)
393 goto err_ioremap;
395 return 0;
397 err_ioremap:
398 s3c2410_stop_hc(dev);
399 iounmap(hcd->regs);
400 clk_put(usb_clk);
402 err_clk:
403 clk_put(clk);
405 err_mem:
406 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
408 err_put:
409 usb_put_hcd(hcd);
410 return retval;
413 /*-------------------------------------------------------------------------*/
415 static int
416 ohci_s3c2410_start (struct usb_hcd *hcd)
418 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
419 int ret;
421 if ((ret = ohci_init(ohci)) < 0)
422 return ret;
424 if ((ret = ohci_run (ohci)) < 0) {
425 err ("can't start %s", hcd->self.bus_name);
426 ohci_stop (hcd);
427 return ret;
430 return 0;
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
442 .irq = ohci_irq,
443 .flags = HCD_USB11 | HCD_MEMORY,
446 * basic lifecycle operations
448 .start = ohci_s3c2410_start,
449 .stop = ohci_stop,
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,
460 * scheduling support
462 .get_frame_number = ohci_get_frame,
465 * root hub support
467 .hub_status_data = ohci_s3c2410_hub_status_data,
468 .hub_control = ohci_s3c2410_hub_control,
469 .hub_irq_enable = ohci_rhsc_enable,
470 #ifdef CONFIG_PM
471 .bus_suspend = ohci_bus_suspend,
472 .bus_resume = ohci_bus_resume,
473 #endif
474 .start_port_reset = ohci_start_port_reset,
477 /* device driver */
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);
489 return 0;
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, */
498 .driver = {
499 .owner = THIS_MODULE,
500 .name = "s3c2410-ohci",
504 MODULE_ALIAS("platform:s3c2410-ohci");