1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#include <common.h>
35#include <asm/errno.h>
36#include <linux/list.h>
37#include <malloc.h>
38
39#include <linux/usb/ch9.h>
40#include <linux/usb/gadget.h>
41
42#include <asm/byteorder.h>
43#include <asm/unaligned.h>
44#include <asm/io.h>
45
46#include <asm/mach-types.h>
47#include <asm/arch/gpio.h>
48
49#include "regs-otg.h"
50#include <usb/lin_gadget_compat.h>
51
52
53
54#define OTG_DMA_MODE 1
55
56#undef DEBUG_S3C_UDC_SETUP
57#undef DEBUG_S3C_UDC_EP0
58#undef DEBUG_S3C_UDC_ISR
59#undef DEBUG_S3C_UDC_OUT_EP
60#undef DEBUG_S3C_UDC_IN_EP
61#undef DEBUG_S3C_UDC
62
63
64
65
66
67
68
69
70#include <usb/s3c_udc.h>
71
72#define EP0_CON 0
73#define EP_MASK 0xF
74
75static char *state_names[] = {
76 "WAIT_FOR_SETUP",
77 "DATA_STATE_XMIT",
78 "DATA_STATE_NEED_ZLP",
79 "WAIT_FOR_OUT_STATUS",
80 "DATA_STATE_RECV",
81 "WAIT_FOR_COMPLETE",
82 "WAIT_FOR_OUT_COMPLETE",
83 "WAIT_FOR_IN_COMPLETE",
84 "WAIT_FOR_NULL_COMPLETE",
85};
86
87#define DRIVER_DESC "S3C HS USB OTG Device Driver, (c) Samsung Electronics"
88#define DRIVER_VERSION "15 March 2009"
89
90struct s3c_udc *the_controller;
91
92static const char driver_name[] = "s3c-udc";
93static const char driver_desc[] = DRIVER_DESC;
94static const char ep0name[] = "ep0-control";
95
96
97static unsigned int ep0_fifo_size = 64;
98static unsigned int ep_fifo_size = 512;
99static unsigned int ep_fifo_size2 = 1024;
100static int reset_available = 1;
101
102static struct usb_ctrlrequest *usb_ctrl;
103static dma_addr_t usb_ctrl_dma_addr;
104
105
106
107
108static int s3c_ep_enable(struct usb_ep *ep,
109 const struct usb_endpoint_descriptor *);
110static int s3c_ep_disable(struct usb_ep *ep);
111static struct usb_request *s3c_alloc_request(struct usb_ep *ep,
112 gfp_t gfp_flags);
113static void s3c_free_request(struct usb_ep *ep, struct usb_request *);
114
115static int s3c_queue(struct usb_ep *ep, struct usb_request *, gfp_t gfp_flags);
116static int s3c_dequeue(struct usb_ep *ep, struct usb_request *);
117static int s3c_fifo_status(struct usb_ep *ep);
118static void s3c_fifo_flush(struct usb_ep *ep);
119static void s3c_ep0_read(struct s3c_udc *dev);
120static void s3c_ep0_kick(struct s3c_udc *dev, struct s3c_ep *ep);
121static void s3c_handle_ep0(struct s3c_udc *dev);
122static int s3c_ep0_write(struct s3c_udc *dev);
123static int write_fifo_ep0(struct s3c_ep *ep, struct s3c_request *req);
124static void done(struct s3c_ep *ep, struct s3c_request *req, int status);
125static void stop_activity(struct s3c_udc *dev,
126 struct usb_gadget_driver *driver);
127static int udc_enable(struct s3c_udc *dev);
128static void udc_set_address(struct s3c_udc *dev, unsigned char address);
129static void reconfig_usbd(void);
130static void set_max_pktsize(struct s3c_udc *dev, enum usb_device_speed speed);
131static void nuke(struct s3c_ep *ep, int status);
132static int s3c_udc_set_halt(struct usb_ep *_ep, int value);
133static void s3c_udc_set_nak(struct s3c_ep *ep);
134
135static struct usb_ep_ops s3c_ep_ops = {
136 .enable = s3c_ep_enable,
137 .disable = s3c_ep_disable,
138
139 .alloc_request = s3c_alloc_request,
140 .free_request = s3c_free_request,
141
142 .queue = s3c_queue,
143 .dequeue = s3c_dequeue,
144
145 .set_halt = s3c_udc_set_halt,
146 .fifo_status = s3c_fifo_status,
147 .fifo_flush = s3c_fifo_flush,
148};
149
150#define create_proc_files() do {} while (0)
151#define remove_proc_files() do {} while (0)
152
153
154
155void __iomem *regs_otg;
156struct s3c_usbotg_reg *reg;
157struct s3c_usbotg_phy *phy;
158static unsigned int usb_phy_ctrl;
159
160void otg_phy_init(struct s3c_udc *dev)
161{
162 dev->pdata->phy_control(1);
163
164
165 printf("USB PHY0 Enable\n");
166
167
168 writel(readl(usb_phy_ctrl) | USB_PHY_CTRL_EN0, usb_phy_ctrl);
169
170 if (dev->pdata->usb_flags == PHY0_SLEEP)
171 writel((readl(&phy->phypwr)
172 &~(PHY_0_SLEEP | OTG_DISABLE_0 | ANALOG_PWRDOWN)
173 &~FORCE_SUSPEND_0), &phy->phypwr);
174 else
175 writel((readl(&phy->phypwr) &~(OTG_DISABLE_0 | ANALOG_PWRDOWN)
176 &~FORCE_SUSPEND_0), &phy->phypwr);
177
178 writel((readl(&phy->phyclk) &~(ID_PULLUP0 | COMMON_ON_N0)) |
179 CLK_SEL_24MHZ, &phy->phyclk);
180
181 writel((readl(&phy->rstcon) &~(LINK_SW_RST | PHYLNK_SW_RST))
182 | PHY_SW_RST0, &phy->rstcon);
183 udelay(10);
184 writel(readl(&phy->rstcon)
185 &~(PHY_SW_RST0 | LINK_SW_RST | PHYLNK_SW_RST), &phy->rstcon);
186 udelay(10);
187}
188
189void otg_phy_off(struct s3c_udc *dev)
190{
191
192 writel(PHY_SW_RST0, &phy->rstcon);
193 udelay(20);
194 writel(readl(&phy->phypwr) &~PHY_SW_RST0, &phy->rstcon);
195 udelay(20);
196
197 writel(readl(&phy->phypwr) | OTG_DISABLE_0 | ANALOG_PWRDOWN
198 | FORCE_SUSPEND_0, &phy->phypwr);
199
200 writel(readl(usb_phy_ctrl) &~USB_PHY_CTRL_EN0, usb_phy_ctrl);
201
202 writel((readl(&phy->phyclk) & ~(ID_PULLUP0 | COMMON_ON_N0)),
203 &phy->phyclk);
204
205 udelay(10000);
206
207 dev->pdata->phy_control(0);
208}
209
210
211
212#include "s3c_udc_otg_xfer_dma.c"
213
214
215
216
217static void udc_disable(struct s3c_udc *dev)
218{
219 DEBUG_SETUP("%s: %p\n", __func__, dev);
220
221 udc_set_address(dev, 0);
222
223 dev->ep0state = WAIT_FOR_SETUP;
224 dev->gadget.speed = USB_SPEED_UNKNOWN;
225 dev->usb_address = 0;
226
227 otg_phy_off(dev);
228}
229
230
231
232
233static void udc_reinit(struct s3c_udc *dev)
234{
235 unsigned int i;
236
237 DEBUG_SETUP("%s: %p\n", __func__, dev);
238
239
240 INIT_LIST_HEAD(&dev->gadget.ep_list);
241 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
242 dev->ep0state = WAIT_FOR_SETUP;
243
244
245 for (i = 0; i < S3C_MAX_ENDPOINTS; i++) {
246 struct s3c_ep *ep = &dev->ep[i];
247
248 if (i != 0)
249 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
250
251 ep->desc = 0;
252 ep->stopped = 0;
253 INIT_LIST_HEAD(&ep->queue);
254 ep->pio_irqs = 0;
255 }
256
257
258}
259
260#define BYTES2MAXP(x) (x / 8)
261#define MAXP2BYTES(x) (x * 8)
262
263
264
265
266static int udc_enable(struct s3c_udc *dev)
267{
268 DEBUG_SETUP("%s: %p\n", __func__, dev);
269
270 otg_phy_init(dev);
271 reconfig_usbd();
272
273 DEBUG_SETUP("S3C USB 2.0 OTG Controller Core Initialized : 0x%x\n",
274 readl(®->gintmsk));
275
276 dev->gadget.speed = USB_SPEED_UNKNOWN;
277
278 return 0;
279}
280
281
282
283
284int usb_gadget_register_driver(struct usb_gadget_driver *driver)
285{
286 struct s3c_udc *dev = the_controller;
287 int retval = 0;
288 unsigned long flags;
289
290 DEBUG_SETUP("%s: %s\n", __func__, "no name");
291
292 if (!driver
293 || (driver->speed != USB_SPEED_FULL
294 && driver->speed != USB_SPEED_HIGH)
295 || !driver->bind || !driver->disconnect || !driver->setup)
296 return -EINVAL;
297 if (!dev)
298 return -ENODEV;
299 if (dev->driver)
300 return -EBUSY;
301
302 spin_lock_irqsave(&dev->lock, flags);
303
304 dev->driver = driver;
305 spin_unlock_irqrestore(&dev->lock, flags);
306
307 if (retval) {
308 printf("target device_add failed, error %d\n", retval);
309 return retval;
310 }
311
312 retval = driver->bind(&dev->gadget);
313 if (retval) {
314 DEBUG_SETUP("%s: bind to driver --> error %d\n",
315 dev->gadget.name, retval);
316 dev->driver = 0;
317 return retval;
318 }
319
320 enable_irq(IRQ_OTG);
321
322 DEBUG_SETUP("Registered gadget driver %s\n", dev->gadget.name);
323 udc_enable(dev);
324
325 return 0;
326}
327
328
329
330
331int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
332{
333 struct s3c_udc *dev = the_controller;
334 unsigned long flags;
335
336 if (!dev)
337 return -ENODEV;
338 if (!driver || driver != dev->driver)
339 return -EINVAL;
340
341 spin_lock_irqsave(&dev->lock, flags);
342 dev->driver = 0;
343 stop_activity(dev, driver);
344 spin_unlock_irqrestore(&dev->lock, flags);
345
346 driver->unbind(&dev->gadget);
347
348 disable_irq(IRQ_OTG);
349
350 udc_disable(dev);
351 return 0;
352}
353
354
355
356
357static void done(struct s3c_ep *ep, struct s3c_request *req, int status)
358{
359 unsigned int stopped = ep->stopped;
360
361 debug("%s: %s %p, req = %p, stopped = %d\n",
362 __func__, ep->ep.name, ep, &req->req, stopped);
363
364 list_del_init(&req->queue);
365
366 if (likely(req->req.status == -EINPROGRESS))
367 req->req.status = status;
368 else
369 status = req->req.status;
370
371 if (status && status != -ESHUTDOWN) {
372 debug("complete %s req %p stat %d len %u/%u\n",
373 ep->ep.name, &req->req, status,
374 req->req.actual, req->req.length);
375 }
376
377
378 ep->stopped = 1;
379
380#ifdef DEBUG_S3C_UDC
381 printf("calling complete callback\n");
382 {
383 int i, len = req->req.length;
384
385 printf("pkt[%d] = ", req->req.length);
386 if (len > 64)
387 len = 64;
388 for (i = 0; i < len; i++) {
389 printf("%02x", ((u8 *)req->req.buf)[i]);
390 if ((i & 7) == 7)
391 printf(" ");
392 }
393 printf("\n");
394 }
395#endif
396 spin_unlock(&ep->dev->lock);
397 req->req.complete(&ep->ep, &req->req);
398 spin_lock(&ep->dev->lock);
399
400 debug("callback completed\n");
401
402 ep->stopped = stopped;
403}
404
405
406
407
408static void nuke(struct s3c_ep *ep, int status)
409{
410 struct s3c_request *req;
411
412 debug("%s: %s %p\n", __func__, ep->ep.name, ep);
413
414
415 while (!list_empty(&ep->queue)) {
416 req = list_entry(ep->queue.next, struct s3c_request, queue);
417 done(ep, req, status);
418 }
419}
420
421static void stop_activity(struct s3c_udc *dev,
422 struct usb_gadget_driver *driver)
423{
424 int i;
425
426
427 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
428 driver = 0;
429 dev->gadget.speed = USB_SPEED_UNKNOWN;
430
431
432 for (i = 0; i < S3C_MAX_ENDPOINTS; i++) {
433 struct s3c_ep *ep = &dev->ep[i];
434 ep->stopped = 1;
435 nuke(ep, -ESHUTDOWN);
436 }
437
438
439 if (driver) {
440 spin_unlock(&dev->lock);
441 driver->disconnect(&dev->gadget);
442 spin_lock(&dev->lock);
443 }
444
445
446 udc_reinit(dev);
447}
448
449static void reconfig_usbd(void)
450{
451
452 int i;
453 unsigned int uTemp = writel(CORE_SOFT_RESET, ®->grstctl);
454
455 debug("Reseting OTG controller\n");
456
457 writel(0<<15
458 |1<<14
459 |0x5<<10
460 |0<<9 | 0<<8
461
462 |0<<7
463 |0<<6
464 |0<<4
465 |1<<3
466 |0x7<<0,
467 ®->gusbcfg);
468
469
470 uTemp = readl(®->dctl);
471 uTemp |= SOFT_DISCONNECT;
472 writel(uTemp, ®->dctl);
473
474 udelay(20);
475
476
477 uTemp = readl(®->dctl);
478 uTemp = uTemp & ~SOFT_DISCONNECT;
479 writel(uTemp, ®->dctl);
480
481
482
483 writel(EP_MISS_CNT(1) | DEV_SPEED_HIGH_SPEED_20, ®->dcfg);
484
485 mdelay(1);
486
487
488 writel(GINTMSK_INIT, ®->gintmsk);
489
490
491 writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->out_endp[EP0_CON].doepctl);
492 writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->in_endp[EP0_CON].diepctl);
493
494 for (i = 1; i < S3C_MAX_ENDPOINTS; i++) {
495 writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->out_endp[i].doepctl);
496 writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->in_endp[i].diepctl);
497 }
498
499
500 writel(((1 << EP0_CON) << DAINT_OUT_BIT)
501 | (1 << EP0_CON), ®->daintmsk);
502
503
504 writel(DOEPMSK_INIT, ®->doepmsk);
505
506
507 writel(DIEPMSK_INIT, ®->diepmsk);
508
509
510 writel(RX_FIFO_SIZE >> 2, ®->grxfsiz);
511
512
513 writel((NPTX_FIFO_SIZE >> 2) << 16 | ((RX_FIFO_SIZE >> 2)) << 0,
514 ®->gnptxfsiz);
515
516 for (i = 1; i < S3C_MAX_HW_ENDPOINTS; i++)
517 writel((PTX_FIFO_SIZE >> 2) << 16 |
518 ((RX_FIFO_SIZE + NPTX_FIFO_SIZE +
519 PTX_FIFO_SIZE*(i-1)) >> 2) << 0,
520 ®->dieptxf[i-1]);
521
522
523 writel(RX_FIFO_FLUSH, ®->grstctl);
524 while (readl(®->grstctl) & RX_FIFO_FLUSH)
525 debug("%s: waiting for S3C_UDC_OTG_GRSTCTL\n", __func__);
526
527
528 writel(TX_FIFO_FLUSH_ALL, ®->grstctl);
529 writel(TX_FIFO_FLUSH_ALL | TX_FIFO_FLUSH, ®->grstctl);
530 while (readl(®->grstctl) & TX_FIFO_FLUSH)
531 debug("%s: waiting for S3C_UDC_OTG_GRSTCTL\n", __func__);
532
533
534
535
536 writel(DEPCTL_EPDIS | DEPCTL_CNAK,
537 ®->out_endp[EP0_CON].doepctl);
538
539
540 writel(GAHBCFG_INIT, ®->gahbcfg);
541}
542
543static void set_max_pktsize(struct s3c_udc *dev, enum usb_device_speed speed)
544{
545 unsigned int ep_ctrl;
546 int i;
547
548 if (speed == USB_SPEED_HIGH) {
549 ep0_fifo_size = 64;
550 ep_fifo_size = 512;
551 ep_fifo_size2 = 1024;
552 dev->gadget.speed = USB_SPEED_HIGH;
553 } else {
554 ep0_fifo_size = 64;
555 ep_fifo_size = 64;
556 ep_fifo_size2 = 64;
557 dev->gadget.speed = USB_SPEED_FULL;
558 }
559
560 dev->ep[0].ep.maxpacket = ep0_fifo_size;
561 for (i = 1; i < S3C_MAX_ENDPOINTS; i++)
562 dev->ep[i].ep.maxpacket = ep_fifo_size;
563
564
565 ep_ctrl = readl(®->in_endp[EP0_CON].diepctl);
566 writel(ep_ctrl|(0<<0), ®->in_endp[EP0_CON].diepctl);
567
568
569 ep_ctrl = readl(®->out_endp[EP0_CON].doepctl);
570 writel(ep_ctrl|(0<<0), ®->out_endp[EP0_CON].doepctl);
571}
572
573static int s3c_ep_enable(struct usb_ep *_ep,
574 const struct usb_endpoint_descriptor *desc)
575{
576 struct s3c_ep *ep;
577 struct s3c_udc *dev;
578 unsigned long flags;
579
580 debug("%s: %p\n", __func__, _ep);
581
582 ep = container_of(_ep, struct s3c_ep, ep);
583 if (!_ep || !desc || ep->desc || _ep->name == ep0name
584 || desc->bDescriptorType != USB_DT_ENDPOINT
585 || ep->bEndpointAddress != desc->bEndpointAddress
586 || ep_maxpacket(ep) <
587 le16_to_cpu(get_unaligned(&desc->wMaxPacketSize))) {
588
589 debug("%s: bad ep or descriptor\n", __func__);
590 return -EINVAL;
591 }
592
593
594 if (ep->bmAttributes != desc->bmAttributes
595 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
596 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
597
598 debug("%s: %s type mismatch\n", __func__, _ep->name);
599 return -EINVAL;
600 }
601
602
603 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
604 && le16_to_cpu(get_unaligned(&desc->wMaxPacketSize)) !=
605 ep_maxpacket(ep)) || !get_unaligned(&desc->wMaxPacketSize)) {
606
607 debug("%s: bad %s maxpacket\n", __func__, _ep->name);
608 return -ERANGE;
609 }
610
611 dev = ep->dev;
612 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
613
614 debug("%s: bogus device state\n", __func__);
615 return -ESHUTDOWN;
616 }
617
618 ep->stopped = 0;
619 ep->desc = desc;
620 ep->pio_irqs = 0;
621 ep->ep.maxpacket = le16_to_cpu(get_unaligned(&desc->wMaxPacketSize));
622
623
624 s3c_udc_set_nak(ep);
625 s3c_udc_set_halt(_ep, 0);
626
627 spin_lock_irqsave(&ep->dev->lock, flags);
628 s3c_udc_ep_activate(ep);
629 spin_unlock_irqrestore(&ep->dev->lock, flags);
630
631 debug("%s: enabled %s, stopped = %d, maxpacket = %d\n",
632 __func__, _ep->name, ep->stopped, ep->ep.maxpacket);
633 return 0;
634}
635
636
637
638
639static int s3c_ep_disable(struct usb_ep *_ep)
640{
641 struct s3c_ep *ep;
642 unsigned long flags;
643
644 debug("%s: %p\n", __func__, _ep);
645
646 ep = container_of(_ep, struct s3c_ep, ep);
647 if (!_ep || !ep->desc) {
648 debug("%s: %s not enabled\n", __func__,
649 _ep ? ep->ep.name : NULL);
650 return -EINVAL;
651 }
652
653 spin_lock_irqsave(&ep->dev->lock, flags);
654
655
656 nuke(ep, -ESHUTDOWN);
657
658 ep->desc = 0;
659 ep->stopped = 1;
660
661 spin_unlock_irqrestore(&ep->dev->lock, flags);
662
663 debug("%s: disabled %s\n", __func__, _ep->name);
664 return 0;
665}
666
667static struct usb_request *s3c_alloc_request(struct usb_ep *ep,
668 gfp_t gfp_flags)
669{
670 struct s3c_request *req;
671
672 debug("%s: %s %p\n", __func__, ep->name, ep);
673
674 req = kmalloc(sizeof *req, gfp_flags);
675 if (!req)
676 return 0;
677
678 memset(req, 0, sizeof *req);
679 INIT_LIST_HEAD(&req->queue);
680
681 return &req->req;
682}
683
684static void s3c_free_request(struct usb_ep *ep, struct usb_request *_req)
685{
686 struct s3c_request *req;
687
688 debug("%s: %p\n", __func__, ep);
689
690 req = container_of(_req, struct s3c_request, req);
691 WARN_ON(!list_empty(&req->queue));
692 kfree(req);
693}
694
695
696static int s3c_dequeue(struct usb_ep *_ep, struct usb_request *_req)
697{
698 struct s3c_ep *ep;
699 struct s3c_request *req;
700 unsigned long flags;
701
702 debug("%s: %p\n", __func__, _ep);
703
704 ep = container_of(_ep, struct s3c_ep, ep);
705 if (!_ep || ep->ep.name == ep0name)
706 return -EINVAL;
707
708 spin_lock_irqsave(&ep->dev->lock, flags);
709
710
711 list_for_each_entry(req, &ep->queue, queue) {
712 if (&req->req == _req)
713 break;
714 }
715 if (&req->req != _req) {
716 spin_unlock_irqrestore(&ep->dev->lock, flags);
717 return -EINVAL;
718 }
719
720 done(ep, req, -ECONNRESET);
721
722 spin_unlock_irqrestore(&ep->dev->lock, flags);
723 return 0;
724}
725
726
727
728
729static int s3c_fifo_status(struct usb_ep *_ep)
730{
731 int count = 0;
732 struct s3c_ep *ep;
733
734 ep = container_of(_ep, struct s3c_ep, ep);
735 if (!_ep) {
736 debug("%s: bad ep\n", __func__);
737 return -ENODEV;
738 }
739
740 debug("%s: %d\n", __func__, ep_index(ep));
741
742
743 if (ep_is_in(ep))
744 return -EOPNOTSUPP;
745
746 return count;
747}
748
749
750
751
752static void s3c_fifo_flush(struct usb_ep *_ep)
753{
754 struct s3c_ep *ep;
755
756 ep = container_of(_ep, struct s3c_ep, ep);
757 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
758 debug("%s: bad ep\n", __func__);
759 return;
760 }
761
762 debug("%s: %d\n", __func__, ep_index(ep));
763}
764
765static const struct usb_gadget_ops s3c_udc_ops = {
766
767};
768
769static struct s3c_udc memory = {
770 .usb_address = 0,
771 .gadget = {
772 .ops = &s3c_udc_ops,
773 .ep0 = &memory.ep[0].ep,
774 .name = driver_name,
775 },
776
777
778 .ep[0] = {
779 .ep = {
780 .name = ep0name,
781 .ops = &s3c_ep_ops,
782 .maxpacket = EP0_FIFO_SIZE,
783 },
784 .dev = &memory,
785
786 .bEndpointAddress = 0,
787 .bmAttributes = 0,
788
789 .ep_type = ep_control,
790 },
791
792
793 .ep[1] = {
794 .ep = {
795 .name = "ep1in-bulk",
796 .ops = &s3c_ep_ops,
797 .maxpacket = EP_FIFO_SIZE,
798 },
799 .dev = &memory,
800
801 .bEndpointAddress = USB_DIR_IN | 1,
802 .bmAttributes = USB_ENDPOINT_XFER_BULK,
803
804 .ep_type = ep_bulk_out,
805 .fifo_num = 1,
806 },
807
808 .ep[2] = {
809 .ep = {
810 .name = "ep2out-bulk",
811 .ops = &s3c_ep_ops,
812 .maxpacket = EP_FIFO_SIZE,
813 },
814 .dev = &memory,
815
816 .bEndpointAddress = USB_DIR_OUT | 2,
817 .bmAttributes = USB_ENDPOINT_XFER_BULK,
818
819 .ep_type = ep_bulk_in,
820 .fifo_num = 2,
821 },
822
823 .ep[3] = {
824 .ep = {
825 .name = "ep3in-int",
826 .ops = &s3c_ep_ops,
827 .maxpacket = EP_FIFO_SIZE,
828 },
829 .dev = &memory,
830
831 .bEndpointAddress = USB_DIR_IN | 3,
832 .bmAttributes = USB_ENDPOINT_XFER_INT,
833
834 .ep_type = ep_interrupt,
835 .fifo_num = 3,
836 },
837};
838
839
840
841
842
843int s3c_udc_probe(struct s3c_plat_otg_data *pdata)
844{
845 struct s3c_udc *dev = &memory;
846 int retval = 0, i;
847
848 debug("%s: %p\n", __func__, pdata);
849
850 dev->pdata = pdata;
851
852 phy = (struct s3c_usbotg_phy *)pdata->regs_phy;
853 reg = (struct s3c_usbotg_reg *)pdata->regs_otg;
854 usb_phy_ctrl = pdata->usb_phy_ctrl;
855
856
857
858 dev->gadget.is_dualspeed = 1;
859 dev->gadget.is_otg = 0;
860 dev->gadget.is_a_peripheral = 0;
861 dev->gadget.b_hnp_enable = 0;
862 dev->gadget.a_hnp_support = 0;
863 dev->gadget.a_alt_hnp_support = 0;
864
865 the_controller = dev;
866
867 for (i = 0; i < S3C_MAX_ENDPOINTS+1; i++) {
868 dev->dma_buf[i] = kmalloc(DMA_BUFFER_SIZE, GFP_KERNEL);
869 dev->dma_addr[i] = (dma_addr_t) dev->dma_buf[i];
870 invalidate_dcache_range((unsigned long) dev->dma_buf[i],
871 (unsigned long) (dev->dma_buf[i]
872 + DMA_BUFFER_SIZE));
873 }
874 usb_ctrl = dev->dma_buf[0];
875 usb_ctrl_dma_addr = dev->dma_addr[0];
876
877 udc_reinit(dev);
878
879 return retval;
880}
881
882int usb_gadget_handle_interrupts()
883{
884 u32 intr_status = readl(®->gintsts);
885 u32 gintmsk = readl(®->gintmsk);
886
887 if (intr_status & gintmsk)
888 return s3c_udc_irq(1, (void *)the_controller);
889 return 0;
890}
891