1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24
25#include <asm/hardware.h>
26#include <asm/arch/usb-control.h>
27
28#define valid_port(idx) ((idx) == 1 || (idx) == 2)
29
30
31
32static struct clk *clk;
33static struct clk *usb_clk;
34
35
36
37static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
38
39
40
41static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
42{
43 return hcd->self.controller->platform_data;
44}
45
46static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
47{
48 struct s3c2410_hcd_info *info = dev->dev.platform_data;
49
50 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
51
52 clk_enable(usb_clk);
53 mdelay(2);
54
55 clk_enable(clk);
56
57 if (info != NULL) {
58 info->hcd = hcd;
59 info->report_oc = s3c2410_hcd_oc;
60
61 if (info->enable_oc != NULL) {
62 (info->enable_oc)(info, 1);
63 }
64 }
65}
66
67static void s3c2410_stop_hc(struct platform_device *dev)
68{
69 struct s3c2410_hcd_info *info = dev->dev.platform_data;
70
71 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
72
73 if (info != NULL) {
74 info->report_oc = NULL;
75 info->hcd = NULL;
76
77 if (info->enable_oc != NULL) {
78 (info->enable_oc)(info, 0);
79 }
80 }
81
82 clk_disable(clk);
83 clk_disable(usb_clk);
84}
85
86
87
88
89
90
91
92static int
93ohci_s3c2410_hub_status_data (struct usb_hcd *hcd, char *buf)
94{
95 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
96 struct s3c2410_hcd_port *port;
97 int orig;
98 int portno;
99
100 orig = ohci_hub_status_data (hcd, buf);
101
102 if (info == NULL)
103 return orig;
104
105 port = &info->port[0];
106
107
108
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);
114
115 if (orig < 1)
116 orig = 1;
117
118 buf[0] |= 1<<(portno+1);
119 }
120 }
121
122 return orig;
123}
124
125
126
127
128
129
130
131static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
132 int port, int to)
133{
134 if (info == NULL)
135 return;
136
137 if (info->power_control != NULL) {
138 info->port[port-1].power = to;
139 (info->power_control)(port-1, to);
140 }
141}
142
143
144
145
146
147
148
149
150static 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)
157{
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;
162
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);
166
167
168
169
170 if (info == NULL) {
171 ret = ohci_hub_control(hcd, typeReq, wValue,
172 wIndex, buf, wLength);
173 goto out;
174 }
175
176
177
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;
184 }
185 break;
186
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");
192
193 if (valid_port(wIndex)) {
194 info->port[wIndex-1].oc_changed = 0;
195 info->port[wIndex-1].oc_status = 0;
196 }
197
198 goto out;
199
200 case USB_PORT_FEAT_OVER_CURRENT:
201 dev_dbg(hcd->self.controller,
202 "ClearPortFeature: OVER_CURRENT\n");
203
204 if (valid_port(wIndex)) {
205 info->port[wIndex-1].oc_status = 0;
206 }
207
208 goto out;
209
210 case USB_PORT_FEAT_POWER:
211 dev_dbg(hcd->self.controller,
212 "ClearPortFeature: POWER\n");
213
214 if (valid_port(wIndex)) {
215 s3c2410_usb_set_power(info, wIndex, 0);
216 return 0;
217 }
218 }
219 break;
220 }
221
222 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
223 if (ret)
224 goto out;
225
226 switch (typeReq) {
227 case GetHubDescriptor:
228
229
230
231 desc = (struct usb_hub_descriptor *)buf;
232
233 if (info->power_control == NULL)
234 return ret;
235
236 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
237 desc->wHubCharacteristics);
238
239
240
241
242
243 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
244 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
245
246 if (info->enable_oc) {
247 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
248 desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
249 }
250
251 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
252 desc->wHubCharacteristics);
253
254 return ret;
255
256 case GetPortStatus:
257
258
259 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
260
261 if (valid_port(wIndex)) {
262 if (info->port[wIndex-1].oc_changed) {
263 *data |= cpu_to_le32(RH_PS_OCIC);
264 }
265
266 if (info->port[wIndex-1].oc_status) {
267 *data |= cpu_to_le32(RH_PS_POCI);
268 }
269 }
270 }
271
272 out:
273 return ret;
274}
275
276
277
278
279
280
281static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
282{
283 struct s3c2410_hcd_port *port;
284 struct usb_hcd *hcd;
285 unsigned long flags;
286 int portno;
287
288 if (info == NULL)
289 return;
290
291 port = &info->port[0];
292 hcd = info->hcd;
293
294 local_irq_save(flags);
295
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;
301
302
303
304 s3c2410_usb_set_power(info, portno+1, 0);
305 }
306 }
307
308 local_irq_restore(flags);
309}
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325static void
326usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
327{
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);
333}
334
335
336
337
338
339
340
341
342
343
344static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
345 struct platform_device *dev)
346{
347 struct usb_hcd *hcd = NULL;
348 int retval;
349
350 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);
351 s3c2410_usb_set_power(dev->dev.platform_data, 2, 1);
352
353 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
354 if (hcd == NULL)
355 return -ENOMEM;
356
357 hcd->rsrc_start = dev->resource[0].start;
358 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
359
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;
364 }
365
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;
371 }
372
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;
378 }
379
380 s3c2410_start_hc(dev, hcd);
381
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;
387 }
388
389 ohci_hcd_init(hcd_to_ohci(hcd));
390
391 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
392 if (retval != 0)
393 goto err_ioremap;
394
395 return 0;
396
397 err_ioremap:
398 s3c2410_stop_hc(dev);
399 iounmap(hcd->regs);
400 clk_put(usb_clk);
401
402 err_clk:
403 clk_put(clk);
404
405 err_mem:
406 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
407
408 err_put:
409 usb_put_hcd(hcd);
410 return retval;
411}
412
413
414
415static int
416ohci_s3c2410_start (struct usb_hcd *hcd)
417{
418 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
419 int ret;
420
421 if ((ret = ohci_init(ohci)) < 0)
422 return ret;
423
424 if ((ret = ohci_run (ohci)) < 0) {
425 err ("can't start %s", hcd->self.bus_name);
426 ohci_stop (hcd);
427 return ret;
428 }
429
430 return 0;
431}
432
433
434static 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),
438
439
440
441
442 .irq = ohci_irq,
443 .flags = HCD_USB11 | HCD_MEMORY,
444
445
446
447
448 .start = ohci_s3c2410_start,
449 .stop = ohci_stop,
450 .shutdown = ohci_shutdown,
451
452
453
454
455 .urb_enqueue = ohci_urb_enqueue,
456 .urb_dequeue = ohci_urb_dequeue,
457 .endpoint_disable = ohci_endpoint_disable,
458
459
460
461
462 .get_frame_number = ohci_get_frame,
463
464
465
466
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,
475};
476
477
478
479static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
480{
481 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev);
482}
483
484static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
485{
486 struct usb_hcd *hcd = platform_get_drvdata(pdev);
487
488 usb_hcd_s3c2410_remove(hcd, pdev);
489 return 0;
490}
491
492static 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
497
498 .driver = {
499 .owner = THIS_MODULE,
500 .name = "s3c2410-ohci",
501 },
502};
503
504