Loading...
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
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
7 *
8 * USB Bus Glue for Samsung S3C2410
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
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
16 *
17 * Thanks to basprog@mail.ru for updates to newer kernels
18 *
19 * This file is licenced under the GPL.
20*/
21
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24#include <plat/usb-control.h>
25
26#define valid_port(idx) ((idx) == 1 || (idx) == 2)
27
28/* clock device associated with the hcd */
29
30static struct clk *clk;
31static struct clk *usb_clk;
32
33/* forward definitions */
34
35static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
36
37/* conversion functions */
38
39static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
40{
41 return hcd->self.controller->platform_data;
42}
43
44static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
45{
46 struct s3c2410_hcd_info *info = dev->dev.platform_data;
47
48 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
49
50 clk_enable(usb_clk);
51 mdelay(2); /* let the bus clock stabilise */
52
53 clk_enable(clk);
54
55 if (info != NULL) {
56 info->hcd = hcd;
57 info->report_oc = s3c2410_hcd_oc;
58
59 if (info->enable_oc != NULL)
60 (info->enable_oc)(info, 1);
61 }
62}
63
64static void s3c2410_stop_hc(struct platform_device *dev)
65{
66 struct s3c2410_hcd_info *info = dev->dev.platform_data;
67
68 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
69
70 if (info != NULL) {
71 info->report_oc = NULL;
72 info->hcd = NULL;
73
74 if (info->enable_oc != NULL)
75 (info->enable_oc)(info, 0);
76 }
77
78 clk_disable(clk);
79 clk_disable(usb_clk);
80}
81
82/* ohci_s3c2410_hub_status_data
83 *
84 * update the status data from the hub with anything that
85 * has been detected by our system
86*/
87
88static int
89ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf)
90{
91 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
92 struct s3c2410_hcd_port *port;
93 int orig;
94 int portno;
95
96 orig = ohci_hub_status_data(hcd, buf);
97
98 if (info == NULL)
99 return orig;
100
101 port = &info->port[0];
102
103 /* mark any changed port as changed */
104
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);
110
111 if (orig < 1)
112 orig = 1;
113
114 buf[0] |= 1<<(portno+1);
115 }
116 }
117
118 return orig;
119}
120
121/* s3c2410_usb_set_power
122 *
123 * configure the power on a port, by calling the platform device
124 * routine registered with the platform device
125*/
126
127static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
128 int port, int to)
129{
130 if (info == NULL)
131 return;
132
133 if (info->power_control != NULL) {
134 info->port[port-1].power = to;
135 (info->power_control)(port-1, to);
136 }
137}
138
139/* ohci_s3c2410_hub_control
140 *
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
143 * request.
144*/
145
146static int ohci_s3c2410_hub_control(
147 struct usb_hcd *hcd,
148 u16 typeReq,
149 u16 wValue,
150 u16 wIndex,
151 char *buf,
152 u16 wLength)
153{
154 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
155 struct usb_hub_descriptor *desc;
156 int ret = -EINVAL;
157 u32 *data = (u32 *)buf;
158
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);
162
163 /* if we are only an humble host without any special capabilities
164 * process the request straight away and exit */
165
166 if (info == NULL) {
167 ret = ohci_hub_control(hcd, typeReq, wValue,
168 wIndex, buf, wLength);
169 goto out;
170 }
171
172 /* check the request to see if it needs handling */
173
174 switch (typeReq) {
175 case SetPortFeature:
176 if (wValue == USB_PORT_FEAT_POWER) {
177 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
178 s3c2410_usb_set_power(info, wIndex, 1);
179 goto out;
180 }
181 break;
182
183 case ClearPortFeature:
184 switch (wValue) {
185 case USB_PORT_FEAT_C_OVER_CURRENT:
186 dev_dbg(hcd->self.controller,
187 "ClearPortFeature: C_OVER_CURRENT\n");
188
189 if (valid_port(wIndex)) {
190 info->port[wIndex-1].oc_changed = 0;
191 info->port[wIndex-1].oc_status = 0;
192 }
193
194 goto out;
195
196 case USB_PORT_FEAT_OVER_CURRENT:
197 dev_dbg(hcd->self.controller,
198 "ClearPortFeature: OVER_CURRENT\n");
199
200 if (valid_port(wIndex))
201 info->port[wIndex-1].oc_status = 0;
202
203 goto out;
204
205 case USB_PORT_FEAT_POWER:
206 dev_dbg(hcd->self.controller,
207 "ClearPortFeature: POWER\n");
208
209 if (valid_port(wIndex)) {
210 s3c2410_usb_set_power(info, wIndex, 0);
211 return 0;
212 }
213 }
214 break;
215 }
216
217 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
218 if (ret)
219 goto out;
220
221 switch (typeReq) {
222 case GetHubDescriptor:
223
224 /* update the hub's descriptor */
225
226 desc = (struct usb_hub_descriptor *)buf;
227
228 if (info->power_control == NULL)
229 return ret;
230
231 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
232 desc->wHubCharacteristics);
233
234 /* remove the old configurations for power-switching, and
235 * over-current protection, and insert our new configuration
236 */
237
238 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
239 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
240
241 if (info->enable_oc) {
242 desc->wHubCharacteristics &= ~cpu_to_le16(
243 HUB_CHAR_OCPM);
244 desc->wHubCharacteristics |= cpu_to_le16(
245 0x0008 |
246 0x0001);
247 }
248
249 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
250 desc->wHubCharacteristics);
251
252 return ret;
253
254 case GetPortStatus:
255 /* check port status */
256
257 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
258
259 if (valid_port(wIndex)) {
260 if (info->port[wIndex-1].oc_changed)
261 *data |= cpu_to_le32(RH_PS_OCIC);
262
263 if (info->port[wIndex-1].oc_status)
264 *data |= cpu_to_le32(RH_PS_POCI);
265 }
266 }
267
268 out:
269 return ret;
270}
271
272/* s3c2410_hcd_oc
273 *
274 * handle an over-current report
275*/
276
277static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
278{
279 struct s3c2410_hcd_port *port;
280 struct usb_hcd *hcd;
281 unsigned long flags;
282 int portno;
283
284 if (info == NULL)
285 return;
286
287 port = &info->port[0];
288 hcd = info->hcd;
289
290 local_irq_save(flags);
291
292 for (portno = 0; portno < 2; port++, portno++) {
293 if (port_oc & (1<<portno) &&
294 port->flags & S3C_HCDFLG_USED) {
295 port->oc_status = 1;
296 port->oc_changed = 1;
297
298 /* ok, once over-current is detected,
299 the port needs to be powered down */
300 s3c2410_usb_set_power(info, portno+1, 0);
301 }
302 }
303
304 local_irq_restore(flags);
305}
306
307/* may be called without controller electrically present */
308/* may be called with controller, bus, and devices active */
309
310/*
311 * usb_hcd_s3c2410_remove - shutdown processing for HCD
312 * @dev: USB Host Controller being removed
313 * Context: !in_interrupt()
314 *
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.
318 *
319*/
320
321static void
322usb_hcd_s3c2410_remove(struct usb_hcd *hcd, struct platform_device *dev)
323{
324 usb_remove_hcd(hcd);
325 s3c2410_stop_hc(dev);
326 iounmap(hcd->regs);
327 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
328 usb_put_hcd(hcd);
329}
330
331/**
332 * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs
333 * Context: !in_interrupt()
334 *
335 * Allocates basic resources for this USB host controller, and
336 * then invokes the start() method for the HCD associated with it
337 * through the hotplug entry's driver_data.
338 *
339 */
340static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
341 struct platform_device *dev)
342{
343 struct usb_hcd *hcd = NULL;
344 int retval;
345
346 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);
347 s3c2410_usb_set_power(dev->dev.platform_data, 2, 1);
348
349 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
350 if (hcd == NULL)
351 return -ENOMEM;
352
353 hcd->rsrc_start = dev->resource[0].start;
354 hcd->rsrc_len = resource_size(&dev->resource[0]);
355
356 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
357 dev_err(&dev->dev, "request_mem_region failed\n");
358 retval = -EBUSY;
359 goto err_put;
360 }
361
362 clk = clk_get(&dev->dev, "usb-host");
363 if (IS_ERR(clk)) {
364 dev_err(&dev->dev, "cannot get usb-host clock\n");
365 retval = PTR_ERR(clk);
366 goto err_mem;
367 }
368
369 usb_clk = clk_get(&dev->dev, "usb-bus-host");
370 if (IS_ERR(usb_clk)) {
371 dev_err(&dev->dev, "cannot get usb-bus-host clock\n");
372 retval = PTR_ERR(usb_clk);
373 goto err_clk;
374 }
375
376 s3c2410_start_hc(dev, hcd);
377
378 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
379 if (!hcd->regs) {
380 dev_err(&dev->dev, "ioremap failed\n");
381 retval = -ENOMEM;
382 goto err_ioremap;
383 }
384
385 ohci_hcd_init(hcd_to_ohci(hcd));
386
387 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
388 if (retval != 0)
389 goto err_ioremap;
390
391 return 0;
392
393 err_ioremap:
394 s3c2410_stop_hc(dev);
395 iounmap(hcd->regs);
396 clk_put(usb_clk);
397
398 err_clk:
399 clk_put(clk);
400
401 err_mem:
402 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
403
404 err_put:
405 usb_put_hcd(hcd);
406 return retval;
407}
408
409/*-------------------------------------------------------------------------*/
410
411static int
412ohci_s3c2410_start(struct usb_hcd *hcd)
413{
414 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
415 int ret;
416
417 ret = ohci_init(ohci);
418 if (ret < 0)
419 return ret;
420
421 ret = ohci_run(ohci);
422 if (ret < 0) {
423 err("can't start %s", hcd->self.bus_name);
424 ohci_stop(hcd);
425 return ret;
426 }
427
428 return 0;
429}
430
431
432static const struct hc_driver ohci_s3c2410_hc_driver = {
433 .description = hcd_name,
434 .product_desc = "S3C24XX OHCI",
435 .hcd_priv_size = sizeof(struct ohci_hcd),
436
437 /*
438 * generic hardware linkage
439 */
440 .irq = ohci_irq,
441 .flags = HCD_USB11 | HCD_MEMORY,
442
443 /*
444 * basic lifecycle operations
445 */
446 .start = ohci_s3c2410_start,
447 .stop = ohci_stop,
448 .shutdown = ohci_shutdown,
449
450 /*
451 * managing i/o requests and associated device resources
452 */
453 .urb_enqueue = ohci_urb_enqueue,
454 .urb_dequeue = ohci_urb_dequeue,
455 .endpoint_disable = ohci_endpoint_disable,
456
457 /*
458 * scheduling support
459 */
460 .get_frame_number = ohci_get_frame,
461
462 /*
463 * root hub support
464 */
465 .hub_status_data = ohci_s3c2410_hub_status_data,
466 .hub_control = ohci_s3c2410_hub_control,
467#ifdef CONFIG_PM
468 .bus_suspend = ohci_bus_suspend,
469 .bus_resume = ohci_bus_resume,
470#endif
471 .start_port_reset = ohci_start_port_reset,
472};
473
474/* device driver */
475
476static int __devinit ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
477{
478 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev);
479}
480
481static int __devexit ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
482{
483 struct usb_hcd *hcd = platform_get_drvdata(pdev);
484
485 usb_hcd_s3c2410_remove(hcd, pdev);
486 return 0;
487}
488
489static struct platform_driver ohci_hcd_s3c2410_driver = {
490 .probe = ohci_hcd_s3c2410_drv_probe,
491 .remove = __devexit_p(ohci_hcd_s3c2410_drv_remove),
492 .shutdown = usb_hcd_platform_shutdown,
493 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
494 /*.resume = ohci_hcd_s3c2410_drv_resume, */
495 .driver = {
496 .owner = THIS_MODULE,
497 .name = "s3c2410-ohci",
498 },
499};
500
501MODULE_ALIAS("platform:s3c2410-ohci");
1// SPDX-License-Identifier: GPL-1.0+
2/*
3 * OHCI HCD (Host Controller Driver) for USB.
4 *
5 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * (C) Copyright 2002 Hewlett-Packard Company
8 *
9 * USB Bus Glue for Samsung S3C2410
10 *
11 * Written by Christopher Hoover <ch@hpl.hp.com>
12 * Based on fragments of previous driver by Russell King et al.
13 *
14 * Modified for S3C2410 from ohci-sa1111.c, ohci-omap.c and ohci-lh7a40.c
15 * by Ben Dooks, <ben@simtec.co.uk>
16 * Copyright (C) 2004 Simtec Electronics
17 *
18 * Thanks to basprog@mail.ru for updates to newer kernels
19 *
20 * This file is licenced under the GPL.
21*/
22
23#include <linux/clk.h>
24#include <linux/io.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/platform_data/usb-ohci-s3c2410.h>
29#include <linux/usb.h>
30#include <linux/usb/hcd.h>
31
32#include "ohci.h"
33
34
35#define valid_port(idx) ((idx) == 1 || (idx) == 2)
36
37/* clock device associated with the hcd */
38
39
40#define DRIVER_DESC "OHCI S3C2410 driver"
41
42static const char hcd_name[] = "ohci-s3c2410";
43
44static struct clk *clk;
45static struct clk *usb_clk;
46
47static struct hc_driver __read_mostly ohci_s3c2410_hc_driver;
48
49/* forward definitions */
50
51static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
52
53/* conversion functions */
54
55static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
56{
57 return dev_get_platdata(hcd->self.controller);
58}
59
60static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
61{
62 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
63
64 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
65
66 clk_prepare_enable(usb_clk);
67 mdelay(2); /* let the bus clock stabilise */
68
69 clk_prepare_enable(clk);
70
71 if (info != NULL) {
72 info->hcd = hcd;
73 info->report_oc = s3c2410_hcd_oc;
74
75 if (info->enable_oc != NULL)
76 (info->enable_oc)(info, 1);
77 }
78}
79
80static void s3c2410_stop_hc(struct platform_device *dev)
81{
82 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
83
84 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
85
86 if (info != NULL) {
87 info->report_oc = NULL;
88 info->hcd = NULL;
89
90 if (info->enable_oc != NULL)
91 (info->enable_oc)(info, 0);
92 }
93
94 clk_disable_unprepare(clk);
95 clk_disable_unprepare(usb_clk);
96}
97
98/* ohci_s3c2410_hub_status_data
99 *
100 * update the status data from the hub with anything that
101 * has been detected by our system
102*/
103
104static int
105ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf)
106{
107 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
108 struct s3c2410_hcd_port *port;
109 int orig;
110 int portno;
111
112 orig = ohci_hub_status_data(hcd, buf);
113
114 if (info == NULL)
115 return orig;
116
117 port = &info->port[0];
118
119 /* mark any changed port as changed */
120
121 for (portno = 0; portno < 2; port++, portno++) {
122 if (port->oc_changed == 1 &&
123 port->flags & S3C_HCDFLG_USED) {
124 dev_dbg(hcd->self.controller,
125 "oc change on port %d\n", portno);
126
127 if (orig < 1)
128 orig = 1;
129
130 buf[0] |= 1<<(portno+1);
131 }
132 }
133
134 return orig;
135}
136
137/* s3c2410_usb_set_power
138 *
139 * configure the power on a port, by calling the platform device
140 * routine registered with the platform device
141*/
142
143static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
144 int port, int to)
145{
146 if (info == NULL)
147 return;
148
149 if (info->power_control != NULL) {
150 info->port[port-1].power = to;
151 (info->power_control)(port-1, to);
152 }
153}
154
155/* ohci_s3c2410_hub_control
156 *
157 * look at control requests to the hub, and see if we need
158 * to take any action or over-ride the results from the
159 * request.
160*/
161
162static int ohci_s3c2410_hub_control(
163 struct usb_hcd *hcd,
164 u16 typeReq,
165 u16 wValue,
166 u16 wIndex,
167 char *buf,
168 u16 wLength)
169{
170 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
171 struct usb_hub_descriptor *desc;
172 int ret = -EINVAL;
173 u32 *data = (u32 *)buf;
174
175 dev_dbg(hcd->self.controller,
176 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
177 hcd, typeReq, wValue, wIndex, buf, wLength);
178
179 /* if we are only an humble host without any special capabilities
180 * process the request straight away and exit */
181
182 if (info == NULL) {
183 ret = ohci_hub_control(hcd, typeReq, wValue,
184 wIndex, buf, wLength);
185 goto out;
186 }
187
188 /* check the request to see if it needs handling */
189
190 switch (typeReq) {
191 case SetPortFeature:
192 if (wValue == USB_PORT_FEAT_POWER) {
193 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
194 s3c2410_usb_set_power(info, wIndex, 1);
195 goto out;
196 }
197 break;
198
199 case ClearPortFeature:
200 switch (wValue) {
201 case USB_PORT_FEAT_C_OVER_CURRENT:
202 dev_dbg(hcd->self.controller,
203 "ClearPortFeature: C_OVER_CURRENT\n");
204
205 if (valid_port(wIndex)) {
206 info->port[wIndex-1].oc_changed = 0;
207 info->port[wIndex-1].oc_status = 0;
208 }
209
210 goto out;
211
212 case USB_PORT_FEAT_OVER_CURRENT:
213 dev_dbg(hcd->self.controller,
214 "ClearPortFeature: OVER_CURRENT\n");
215
216 if (valid_port(wIndex))
217 info->port[wIndex-1].oc_status = 0;
218
219 goto out;
220
221 case USB_PORT_FEAT_POWER:
222 dev_dbg(hcd->self.controller,
223 "ClearPortFeature: POWER\n");
224
225 if (valid_port(wIndex)) {
226 s3c2410_usb_set_power(info, wIndex, 0);
227 return 0;
228 }
229 }
230 break;
231 }
232
233 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
234 if (ret)
235 goto out;
236
237 switch (typeReq) {
238 case GetHubDescriptor:
239
240 /* update the hub's descriptor */
241
242 desc = (struct usb_hub_descriptor *)buf;
243
244 if (info->power_control == NULL)
245 return ret;
246
247 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
248 desc->wHubCharacteristics);
249
250 /* remove the old configurations for power-switching, and
251 * over-current protection, and insert our new configuration
252 */
253
254 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
255 desc->wHubCharacteristics |= cpu_to_le16(
256 HUB_CHAR_INDV_PORT_LPSM);
257
258 if (info->enable_oc) {
259 desc->wHubCharacteristics &= ~cpu_to_le16(
260 HUB_CHAR_OCPM);
261 desc->wHubCharacteristics |= cpu_to_le16(
262 HUB_CHAR_INDV_PORT_OCPM);
263 }
264
265 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
266 desc->wHubCharacteristics);
267
268 return ret;
269
270 case GetPortStatus:
271 /* check port status */
272
273 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
274
275 if (valid_port(wIndex)) {
276 if (info->port[wIndex-1].oc_changed)
277 *data |= cpu_to_le32(RH_PS_OCIC);
278
279 if (info->port[wIndex-1].oc_status)
280 *data |= cpu_to_le32(RH_PS_POCI);
281 }
282 }
283
284 out:
285 return ret;
286}
287
288/* s3c2410_hcd_oc
289 *
290 * handle an over-current report
291*/
292
293static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
294{
295 struct s3c2410_hcd_port *port;
296 unsigned long flags;
297 int portno;
298
299 if (info == NULL)
300 return;
301
302 port = &info->port[0];
303
304 local_irq_save(flags);
305
306 for (portno = 0; portno < 2; port++, portno++) {
307 if (port_oc & (1<<portno) &&
308 port->flags & S3C_HCDFLG_USED) {
309 port->oc_status = 1;
310 port->oc_changed = 1;
311
312 /* ok, once over-current is detected,
313 the port needs to be powered down */
314 s3c2410_usb_set_power(info, portno+1, 0);
315 }
316 }
317
318 local_irq_restore(flags);
319}
320
321/* may be called without controller electrically present */
322/* may be called with controller, bus, and devices active */
323
324/*
325 * ohci_hcd_s3c2410_remove - shutdown processing for HCD
326 * @dev: USB Host Controller being removed
327 * Context: !in_interrupt()
328 *
329 * Reverses the effect of ohci_hcd_3c2410_probe(), first invoking
330 * the HCD's stop() method. It is always called from a thread
331 * context, normally "rmmod", "apmd", or something similar.
332 *
333*/
334
335static int
336ohci_hcd_s3c2410_remove(struct platform_device *dev)
337{
338 struct usb_hcd *hcd = platform_get_drvdata(dev);
339
340 usb_remove_hcd(hcd);
341 s3c2410_stop_hc(dev);
342 usb_put_hcd(hcd);
343 return 0;
344}
345
346/**
347 * ohci_hcd_s3c2410_probe - initialize S3C2410-based HCDs
348 * Context: !in_interrupt()
349 *
350 * Allocates basic resources for this USB host controller, and
351 * then invokes the start() method for the HCD associated with it
352 * through the hotplug entry's driver_data.
353 *
354 */
355static int ohci_hcd_s3c2410_probe(struct platform_device *dev)
356{
357 struct usb_hcd *hcd = NULL;
358 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
359 int retval;
360
361 s3c2410_usb_set_power(info, 1, 1);
362 s3c2410_usb_set_power(info, 2, 1);
363
364 hcd = usb_create_hcd(&ohci_s3c2410_hc_driver, &dev->dev, "s3c24xx");
365 if (hcd == NULL)
366 return -ENOMEM;
367
368 hcd->rsrc_start = dev->resource[0].start;
369 hcd->rsrc_len = resource_size(&dev->resource[0]);
370
371 hcd->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]);
372 if (IS_ERR(hcd->regs)) {
373 retval = PTR_ERR(hcd->regs);
374 goto err_put;
375 }
376
377 clk = devm_clk_get(&dev->dev, "usb-host");
378 if (IS_ERR(clk)) {
379 dev_err(&dev->dev, "cannot get usb-host clock\n");
380 retval = PTR_ERR(clk);
381 goto err_put;
382 }
383
384 usb_clk = devm_clk_get(&dev->dev, "usb-bus-host");
385 if (IS_ERR(usb_clk)) {
386 dev_err(&dev->dev, "cannot get usb-bus-host clock\n");
387 retval = PTR_ERR(usb_clk);
388 goto err_put;
389 }
390
391 s3c2410_start_hc(dev, hcd);
392
393 retval = usb_add_hcd(hcd, dev->resource[1].start, 0);
394 if (retval != 0)
395 goto err_ioremap;
396
397 device_wakeup_enable(hcd->self.controller);
398 return 0;
399
400 err_ioremap:
401 s3c2410_stop_hc(dev);
402
403 err_put:
404 usb_put_hcd(hcd);
405 return retval;
406}
407
408/*-------------------------------------------------------------------------*/
409
410#ifdef CONFIG_PM
411static int ohci_hcd_s3c2410_drv_suspend(struct device *dev)
412{
413 struct usb_hcd *hcd = dev_get_drvdata(dev);
414 struct platform_device *pdev = to_platform_device(dev);
415 bool do_wakeup = device_may_wakeup(dev);
416 int rc = 0;
417
418 rc = ohci_suspend(hcd, do_wakeup);
419 if (rc)
420 return rc;
421
422 s3c2410_stop_hc(pdev);
423
424 return rc;
425}
426
427static int ohci_hcd_s3c2410_drv_resume(struct device *dev)
428{
429 struct usb_hcd *hcd = dev_get_drvdata(dev);
430 struct platform_device *pdev = to_platform_device(dev);
431
432 s3c2410_start_hc(pdev, hcd);
433
434 ohci_resume(hcd, false);
435
436 return 0;
437}
438#else
439#define ohci_hcd_s3c2410_drv_suspend NULL
440#define ohci_hcd_s3c2410_drv_resume NULL
441#endif
442
443static const struct dev_pm_ops ohci_hcd_s3c2410_pm_ops = {
444 .suspend = ohci_hcd_s3c2410_drv_suspend,
445 .resume = ohci_hcd_s3c2410_drv_resume,
446};
447
448static const struct of_device_id ohci_hcd_s3c2410_dt_ids[] = {
449 { .compatible = "samsung,s3c2410-ohci" },
450 { /* sentinel */ }
451};
452
453MODULE_DEVICE_TABLE(of, ohci_hcd_s3c2410_dt_ids);
454
455static struct platform_driver ohci_hcd_s3c2410_driver = {
456 .probe = ohci_hcd_s3c2410_probe,
457 .remove = ohci_hcd_s3c2410_remove,
458 .shutdown = usb_hcd_platform_shutdown,
459 .driver = {
460 .name = "s3c2410-ohci",
461 .pm = &ohci_hcd_s3c2410_pm_ops,
462 .of_match_table = ohci_hcd_s3c2410_dt_ids,
463 },
464};
465
466static int __init ohci_s3c2410_init(void)
467{
468 if (usb_disabled())
469 return -ENODEV;
470
471 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
472 ohci_init_driver(&ohci_s3c2410_hc_driver, NULL);
473
474 /*
475 * The Samsung HW has some unusual quirks, which require
476 * Sumsung-specific workarounds. We override certain hc_driver
477 * functions here to achieve that. We explicitly do not enhance
478 * ohci_driver_overrides to allow this more easily, since this
479 * is an unusual case, and we don't want to encourage others to
480 * override these functions by making it too easy.
481 */
482
483 ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data;
484 ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control;
485
486 return platform_driver_register(&ohci_hcd_s3c2410_driver);
487}
488module_init(ohci_s3c2410_init);
489
490static void __exit ohci_s3c2410_cleanup(void)
491{
492 platform_driver_unregister(&ohci_hcd_s3c2410_driver);
493}
494module_exit(ohci_s3c2410_cleanup);
495
496MODULE_DESCRIPTION(DRIVER_DESC);
497MODULE_LICENSE("GPL");
498MODULE_ALIAS("platform:s3c2410-ohci");