1 /* drivers/usb/gadget/s3c_udc_otg_xfer_dma.c
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
6 * Samsung S3C on-chip full/high speed USB OTG 2.0 device controllers
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #define GINTMSK_INIT (INT_OUT_EP | INT_IN_EP | INT_RESUME |\
14 INT_ENUMDONE|INT_RESET|INT_SUSPEND)
15 #define DOEPMSK_INIT (CTRL_OUT_EP_SETUP_PHASE_DONE | AHB_ERROR | BACK2BACK_SETUP_RECEIVED |\
17 #define DIEPMSK_INIT (NON_ISO_IN_EP_TIMEOUT|AHB_ERROR|TRANSFER_DONE)
18 #define GAHBCFG_INIT (PTXFE_HALF | NPTXFE_HALF | MODE_DMA | BURST_INCR4 |\
21 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
23 static u8 clear_feature_num;
24 static int clear_feature_flag;
25 static int set_conf_done;
27 /* Bulk-Only Mass Storage Reset (class-specific request) */
28 #define GET_MAX_LUN_REQUEST 0xFE
29 #define BOT_RESET_REQUEST 0xFF
31 /* TEST MODE in set_feature request */
32 #define TEST_SELECTOR_MASK 0xFF
33 #define TEST_PKT_SIZE 53
35 static u8 test_pkt[TEST_PKT_SIZE] __attribute__((aligned(8))) = {
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
41 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
42 /* JJJJJJJKKKKKKK x8 - '1' */
43 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
44 /* '1' + JJJJJJJK x 8 */
45 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
46 /* {JKKKKKKK x 10},JK */
47 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
50 void s3c_udc_ep_set_stall(struct s3c_ep *ep);
51 #if defined (CONFIG_BATTERY_S3C)
52 extern void s3c_cable_check_status(int flag);
54 void s3c_udc_cable_connect(struct s3c_udc *dev)
56 s3c_cable_check_status(1);
59 void s3c_udc_cable_disconnect(struct s3c_udc *dev)
61 s3c_cable_check_status(0);
64 static inline void s3c_udc_ep0_zlp(void)
68 __raw_writel(virt_to_phys(usb_ctrl), S3C_UDC_OTG_DIEPDMA(EP0_CON));
69 __raw_writel((1<<19 | 0<<0), S3C_UDC_OTG_DIEPTSIZ(EP0_CON));
71 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON));
72 __raw_writel(ep_ctrl | DEPCTL_EPENA | DEPCTL_CNAK,
73 S3C_UDC_OTG_DIEPCTL(EP0_CON));
75 DEBUG_EP0("%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
76 __func__, __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON)));
79 static inline void s3c_udc_pre_setup(void)
83 DEBUG_IN_EP("%s : Prepare Setup packets.\n", __func__);
85 __raw_writel((3<<29)| (1<<19) | sizeof(struct usb_ctrlrequest),
86 S3C_UDC_OTG_DOEPTSIZ(EP0_CON));
87 __raw_writel(virt_to_phys(usb_ctrl), S3C_UDC_OTG_DOEPDMA(EP0_CON));
89 ep_ctrl = __raw_readl(S3C_UDC_OTG_DOEPCTL(EP0_CON));
90 __raw_writel(ep_ctrl|DEPCTL_EPENA|DEPCTL_CNAK, S3C_UDC_OTG_DOEPCTL(EP0_CON));
93 static int setdma_rx(struct s3c_ep *ep, struct s3c_request *req)
97 u32 ep_num = ep_index(ep);
98 struct device *dev = &the_controller->dev->dev;
100 buf = req->req.buf + req->req.actual;
103 length = req->req.length - req->req.actual;
105 req->req.dma = dma_map_single(dev, buf,
106 length, DMA_FROM_DEVICE);
112 pktcnt = (length - 1)/(ep->ep.maxpacket) + 1;
114 ctrl = __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num));
116 __raw_writel(virt_to_phys(buf), S3C_UDC_OTG_DOEPDMA(ep_num));
117 __raw_writel((pktcnt<<19) | (length<<0), S3C_UDC_OTG_DOEPTSIZ(ep_num));
118 __raw_writel(DEPCTL_EPENA | DEPCTL_CNAK | ctrl, S3C_UDC_OTG_DOEPCTL(ep_num));
120 DEBUG_OUT_EP("%s: EP%d RX DMA start : DOEPDMA = 0x%x,"
121 "DOEPTSIZ = 0x%x, DOEPCTL = 0x%x\n"
122 "\tbuf = 0x%p, pktcnt = %d, xfersize = %d\n",
124 __raw_readl(S3C_UDC_OTG_DOEPDMA(ep_num)),
125 __raw_readl(S3C_UDC_OTG_DOEPTSIZ(ep_num)),
126 __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num)),
127 buf, pktcnt, length);
132 static int setdma_tx(struct s3c_ep *ep, struct s3c_request *req)
136 u32 ep_num = ep_index(ep);
137 struct device *dev = &the_controller->dev->dev;
139 buf = req->req.buf + req->req.actual;
141 length = req->req.length - req->req.actual;
143 if (ep_num == EP0_CON)
144 length = min(length, (u32)ep_maxpacket(ep));
146 req->req.actual += length;
148 req->req.dma = dma_map_single(dev, buf,
149 length, DMA_TO_DEVICE);
155 pktcnt = (length - 1)/(ep->ep.maxpacket) + 1;
158 /* Write the FIFO number to be used for this endpoint */
159 ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num));
160 ctrl &= ~DEPCTL_TXFNUM_MASK;;
161 ctrl |= (ep_num << DEPCTL_TXFNUM_BIT);
162 __raw_writel(ctrl , S3C_UDC_OTG_DIEPCTL(ep_num));
165 __raw_writel(virt_to_phys(buf), S3C_UDC_OTG_DIEPDMA(ep_num));
166 __raw_writel((pktcnt<<19)|(length<<0), S3C_UDC_OTG_DIEPTSIZ(ep_num));
167 ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num));
168 __raw_writel(DEPCTL_EPENA|DEPCTL_CNAK|ctrl, S3C_UDC_OTG_DIEPCTL(ep_num));
171 ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON));
172 ctrl = (ctrl & ~(EP_MASK<<DEPCTL_NEXT_EP_BIT)) |
173 (ep_num<<DEPCTL_NEXT_EP_BIT);
174 __raw_writel(ctrl, S3C_UDC_OTG_DIEPCTL(EP0_CON));
177 DEBUG_IN_EP("%s:EP%d TX DMA start : DIEPDMA0 = 0x%x,"
178 "DIEPTSIZ0 = 0x%x, DIEPCTL0 = 0x%x\n"
179 "\tbuf = 0x%p, pktcnt = %d, xfersize = %d\n",
181 __raw_readl(S3C_UDC_OTG_DIEPDMA(ep_num)),
182 __raw_readl(S3C_UDC_OTG_DIEPTSIZ(ep_num)),
183 __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num)),
184 buf, pktcnt, length);
189 static void complete_rx(struct s3c_udc *dev, u8 ep_num)
191 struct s3c_ep *ep = &dev->ep[ep_num];
192 struct s3c_request *req = NULL;
193 u32 ep_tsr = 0, xfer_size = 0, xfer_length, is_short = 0;
195 if (list_empty(&ep->queue)) {
196 DEBUG_OUT_EP("%s: RX DMA done : NULL REQ on OUT EP-%d\n",
202 req = list_entry(ep->queue.next, struct s3c_request, queue);
204 ep_tsr = __raw_readl(S3C_UDC_OTG_DOEPTSIZ(ep_num));
206 if (ep_num == EP0_CON)
207 xfer_size = (ep_tsr & 0x7f);
210 xfer_size = (ep_tsr & 0x7fff);
212 __dma_single_cpu_to_dev(req->req.buf, req->req.length, DMA_FROM_DEVICE);
213 xfer_length = req->req.length - xfer_size;
214 req->req.actual += min(xfer_length, req->req.length - req->req.actual);
215 is_short = (xfer_length < ep->ep.maxpacket);
217 DEBUG_OUT_EP("%s: RX DMA done : ep = %d, rx bytes = %d/%d, "
218 "is_short = %d, DOEPTSIZ = 0x%x, remained bytes = %d\n",
219 __func__, ep_num, req->req.actual, req->req.length,
220 is_short, ep_tsr, xfer_size);
222 if (is_short || req->req.actual == xfer_length) {
223 if (ep_num == EP0_CON && dev->ep0state == DATA_STATE_RECV) {
224 DEBUG_OUT_EP(" => Send ZLP\n");
225 dev->ep0state = WAIT_FOR_SETUP;
231 if (!list_empty(&ep->queue)) {
232 req = list_entry(ep->queue.next,
233 struct s3c_request, queue);
234 DEBUG_OUT_EP("%s: Next Rx request start...\n",
242 static void complete_tx(struct s3c_udc *dev, u8 ep_num)
244 struct s3c_ep *ep = &dev->ep[ep_num];
245 struct s3c_request *req;
246 u32 ep_tsr = 0, xfer_size = 0, xfer_length, is_short = 0;
249 if (list_empty(&ep->queue)) {
250 DEBUG_IN_EP("%s: TX DMA done : NULL REQ on IN EP-%d\n",
256 req = list_entry(ep->queue.next, struct s3c_request, queue);
258 if (dev->ep0state == DATA_STATE_XMIT) {
259 DEBUG_IN_EP("%s: ep_num = %d, ep0stat == DATA_STATE_XMIT\n",
262 last = write_fifo_ep0(ep, req);
265 dev->ep0state = WAIT_FOR_SETUP;
270 ep_tsr = __raw_readl(S3C_UDC_OTG_DIEPTSIZ(ep_num));
272 if (ep_num == EP0_CON)
273 xfer_size = (ep_tsr & 0x7f);
275 xfer_size = (ep_tsr & 0x7fff);
277 req->req.actual = req->req.length - xfer_size;
278 xfer_length = req->req.length - xfer_size;
279 req->req.actual += min(xfer_length, req->req.length - req->req.actual);
280 is_short = (xfer_length < ep->ep.maxpacket);
282 DEBUG_IN_EP("%s: TX DMA done : ep = %d, tx bytes = %d/%d, "
283 "is_short = %d, DIEPTSIZ = 0x%x, remained bytes = %d\n",
284 __func__, ep_num, req->req.actual, req->req.length,
285 is_short, ep_tsr, xfer_size);
287 if (req->req.actual == req->req.length) {
288 /* send ZLP when req.zero is set for Non-ep0 */
289 if (ep_num > 0 && req->req.zero) {
291 write_fifo_ep0(ep, req);
296 if (!list_empty(&ep->queue)) {
297 req = list_entry(ep->queue.next, struct s3c_request,
299 DEBUG_IN_EP("%s: Next Tx request start...\n", __func__);
304 static inline void s3c_udc_check_tx_queue(struct s3c_udc *dev, u8 ep_num)
306 struct s3c_ep *ep = &dev->ep[ep_num];
307 struct s3c_request *req;
309 DEBUG_IN_EP("%s: Check queue, ep_num = %d\n", __func__, ep_num);
311 if (!list_empty(&ep->queue)) {
312 req = list_entry(ep->queue.next, struct s3c_request, queue);
313 DEBUG_IN_EP("%s: Next Tx request(0x%p) start...\n",
321 DEBUG_IN_EP("%s: NULL REQ on IN EP-%d\n", __func__, ep_num);
328 static void process_ep_in_intr(struct s3c_udc *dev)
330 u32 ep_intr, ep_intr_status;
333 ep_intr = __raw_readl(S3C_UDC_OTG_DAINT);
334 DEBUG_IN_EP("*** %s: EP In interrupt : DAINT = 0x%x\n",
337 ep_intr &= DAINT_MASK;
341 ep_intr_status = __raw_readl(S3C_UDC_OTG_DIEPINT(ep_num));
342 DEBUG_IN_EP("\tEP%d-IN : DIEPINT = 0x%x\n",
343 ep_num, ep_intr_status);
345 /* Interrupt Clear */
346 __raw_writel(ep_intr_status, S3C_UDC_OTG_DIEPINT(ep_num));
348 if (ep_intr_status & TRANSFER_DONE) {
349 complete_tx(dev, ep_num);
352 if (dev->ep0state == WAIT_FOR_SETUP)
355 /* continue transfer after
356 set_clear_halt for DMA mode */
357 if (clear_feature_flag == 1) {
358 s3c_udc_check_tx_queue(dev,
360 clear_feature_flag = 0;
371 static void process_ep_out_intr(struct s3c_udc *dev)
373 u32 ep_intr, ep_intr_status;
377 ep_intr = __raw_readl(S3C_UDC_OTG_DAINT);
378 DEBUG_OUT_EP("*** %s: EP OUT interrupt : DAINT = 0x%x\n",
381 ep_intr = (ep_intr >> DAINT_OUT_BIT) & DAINT_MASK;
385 ep_intr_status = __raw_readl(S3C_UDC_OTG_DOEPINT(ep_num));
386 DEBUG_OUT_EP("\tEP%d-OUT : DOEPINT = 0x%x\n",
387 ep_num, ep_intr_status);
389 /* Interrupt Clear */
390 __raw_writel(ep_intr_status, S3C_UDC_OTG_DOEPINT(ep_num));
394 CTRL_OUT_EP_SETUP_PHASE_DONE) {
395 DEBUG_OUT_EP("\tSETUP"
396 "packet(transaction)"
398 if (likely((ep_intr_status & BACK2BACK_SETUP_RECEIVED)==0)) {
399 if(((__raw_readl(S3C_UDC_OTG_DOEPTSIZ(0))>>29)&0x3) < 2) {
400 /* Got more than 1 setup packets */
401 /* Get the last valid setup packet (next setup pkt)*/
403 printk(KERN_DEBUG "b2bs\n");
410 if (ep_intr_status & TRANSFER_DONE) {
411 complete_rx(dev, ep_num);
412 writel((3<<29)|(1 << 19)|sizeof(struct usb_ctrlrequest), S3C_UDC_OTG_DOEPTSIZ(EP0_CON));
413 writel(virt_to_phys(usb_ctrl), S3C_UDC_OTG_DOEPDMA(EP0_CON));
415 ep_ctrl = readl(S3C_UDC_OTG_DOEPCTL(EP0_CON));
416 writel(ep_ctrl|DEPCTL_EPENA|DEPCTL_SNAK, S3C_UDC_OTG_DOEPCTL(EP0_CON));
421 if (ep_intr_status & TRANSFER_DONE)
422 complete_rx(dev, ep_num);
432 * usb client interrupt handler.
434 static irqreturn_t s3c_udc_irq(int irq, void *_dev)
436 struct s3c_udc *dev = _dev;
438 u32 usb_status, gintmsk;
441 spin_lock_irqsave(&dev->lock, flags);
443 intr_status = __raw_readl(S3C_UDC_OTG_GINTSTS);
444 gintmsk = __raw_readl(S3C_UDC_OTG_GINTMSK);
446 DEBUG_ISR("\n*** %s : GINTSTS=0x%x(on state %s), GINTMSK :"
447 "0x%x, DAINT : 0x%x, DAINTMSK : 0x%x\n",
448 __func__, intr_status,
449 state_names[dev->ep0state], gintmsk,
450 __raw_readl(S3C_UDC_OTG_DAINT), __raw_readl(S3C_UDC_OTG_DAINTMSK));
453 spin_unlock_irqrestore(&dev->lock, flags);
457 if (intr_status & INT_ENUMDONE) {
458 DEBUG_ISR("\tSpeed Detection interrupt\n");
460 __raw_writel(INT_ENUMDONE, S3C_UDC_OTG_GINTSTS);
461 usb_status = (__raw_readl(S3C_UDC_OTG_DSTS) & 0x6);
463 if (usb_status & (USB_FULL_30_60MHZ | USB_FULL_48MHZ)) {
464 DEBUG_ISR("\t\tFull Speed Detection\n");
465 set_max_pktsize(dev, USB_SPEED_FULL);
468 DEBUG_ISR("\t\tHigh Speed Detection : 0x%x\n",
470 set_max_pktsize(dev, USB_SPEED_HIGH);
474 if (intr_status & INT_EARLY_SUSPEND) {
475 DEBUG_ISR("\tEarly suspend interrupt\n");
476 __raw_writel(INT_EARLY_SUSPEND, S3C_UDC_OTG_GINTSTS);
479 if (intr_status & INT_SUSPEND) {
480 usb_status = __raw_readl(S3C_UDC_OTG_DSTS);
481 DEBUG_ISR("\tSuspend interrupt :(DSTS):0x%x\n", usb_status);
482 __raw_writel(INT_SUSPEND, S3C_UDC_OTG_GINTSTS);
484 if (dev->gadget.speed != USB_SPEED_UNKNOWN
486 && dev->driver->suspend) {
488 dev->driver->suspend(&dev->gadget);
490 /* report disconnect; the driver is already quiesced */
492 spin_unlock(&dev->lock);
493 dev->driver->disconnect(&dev->gadget);
494 spin_lock(&dev->lock);
496 #if defined (CONFIG_BATTERY_S3C)
497 s3c_udc_cable_disconnect(dev);
502 if (intr_status & INT_RESUME) {
503 DEBUG_ISR("\tResume interrupt\n");
504 __raw_writel(INT_RESUME, S3C_UDC_OTG_GINTSTS);
506 if (dev->gadget.speed != USB_SPEED_UNKNOWN
508 && dev->driver->resume) {
510 dev->driver->resume(&dev->gadget);
514 if (intr_status & INT_RESET) {
515 usb_status = __raw_readl(S3C_UDC_OTG_GOTGCTL);
516 DEBUG_ISR("\tReset interrupt - (GOTGCTL):0x%x\n", usb_status);
517 __raw_writel(INT_RESET, S3C_UDC_OTG_GINTSTS);
521 if ((usb_status & 0xc0000) == (0x3 << 18)) {
522 if (reset_available) {
523 DEBUG_ISR("\t\tOTG core got reset (%d)!!\n",
526 dev->ep0state = WAIT_FOR_SETUP;
534 DEBUG_ISR("\t\tRESET handling skipped\n");
538 if (intr_status & INT_IN_EP)
539 process_ep_in_intr(dev);
541 if (intr_status & INT_OUT_EP)
542 process_ep_out_intr(dev);
544 spin_unlock_irqrestore(&dev->lock, flags);
549 /** Queue one request
550 * Kickstart transfer if needed
552 static int s3c_queue(struct usb_ep *_ep, struct usb_request *_req,
555 struct s3c_request *req;
561 req = container_of(_req, struct s3c_request, req);
562 if (unlikely(!_req || !_req->complete ||
563 !_req->buf || !list_empty(&req->queue))) {
565 DEBUG("%s: bad params\n", __func__);
569 ep = container_of(_ep, struct s3c_ep, ep);
571 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
573 DEBUG("%s: bad ep\n", __func__);
577 ep_num = ep_index(ep);
579 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
581 DEBUG("%s: bogus device state %p\n", __func__, dev->driver);
585 spin_lock_irqsave(&dev->lock, flags);
587 _req->status = -EINPROGRESS;
590 /* kickstart this i/o queue? */
591 DEBUG("\n*** %s: %s-%s req = %p, len = %d, buf = %p"
592 "Q empty = %d, stopped = %d\n",
593 __func__, _ep->name, ep_is_in(ep) ? "in" : "out",
594 _req, _req->length, _req->buf,
595 list_empty(&ep->queue), ep->stopped);
597 if (list_empty(&ep->queue) && !ep->stopped) {
601 list_add_tail(&req->queue, &ep->queue);
602 s3c_ep0_kick(dev, ep);
605 } else if (ep_is_in(ep)) {
606 gintsts = __raw_readl(S3C_UDC_OTG_GINTSTS);
607 DEBUG_IN_EP("%s: ep_is_in, S3C_UDC_OTG_GINTSTS=0x%x\n",
610 if (set_conf_done == 1) {
614 DEBUG("%s: Not yet Set_configureation,"
615 "ep_num = %d, req = %p\n",
616 __func__, ep_num, req);
621 gintsts = __raw_readl(S3C_UDC_OTG_GINTSTS);
622 DEBUG_OUT_EP("%s: ep_is_out,"
623 "S3C_UDC_OTG_GINTSTS=0x%x\n",
630 /* pio or dma irq handler advances the queue. */
631 if (likely(req != 0))
632 list_add_tail(&req->queue, &ep->queue);
634 spin_unlock_irqrestore(&dev->lock, flags);
639 /****************************************************************/
640 /* End Point 0 related functions */
641 /****************************************************************/
643 /* return: 0 = still running, 1 = completed, negative = errno */
644 static int write_fifo_ep0(struct s3c_ep *ep, struct s3c_request *req)
650 max = ep_maxpacket(ep);
652 DEBUG_EP0("%s: max = %d\n", __func__, max);
654 count = setdma_tx(ep, req);
656 /* last packet is usually short (or a zlp) */
657 if (likely(count != max))
660 if (likely(req->req.length != req->req.actual) || req->req.zero)
666 DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __func__,
668 is_last ? "/L" : "", req->req.length - req->req.actual, req);
670 /* requests complete when all IN data is in the FIFO */
672 ep->dev->ep0state = WAIT_FOR_SETUP;
679 static inline int s3c_fifo_read(struct s3c_ep *ep, u32 *cp, int max)
683 bytes = sizeof(struct usb_ctrlrequest);
684 __dma_single_dev_to_cpu(usb_ctrl, bytes, DMA_FROM_DEVICE);
685 DEBUG_EP0("%s: bytes=%d, ep_index=%d\n", __func__, bytes, ep_index(ep));
691 * udc_set_address - set the USB address for this device
694 * Called from control endpoint function
695 * after it decodes a set address setup packet.
697 static void udc_set_address(struct s3c_udc *dev, unsigned char address)
699 u32 ctrl = __raw_readl(S3C_UDC_OTG_DCFG);
700 __raw_writel(address << 4 | ctrl, S3C_UDC_OTG_DCFG);
704 DEBUG_EP0("%s: USB OTG 2.0 Device address=%d, DCFG=0x%x\n",
705 __func__, address, __raw_readl(S3C_UDC_OTG_DCFG));
707 dev->usb_address = address;
710 static inline void s3c_udc_ep0_set_stall(struct s3c_ep *ep)
716 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON));
718 /* set the disable and stall bits */
719 if (ep_ctrl & DEPCTL_EPENA)
720 ep_ctrl |= DEPCTL_EPDIS;
722 ep_ctrl |= DEPCTL_STALL;
724 __raw_writel(ep_ctrl, S3C_UDC_OTG_DIEPCTL(EP0_CON));
726 DEBUG_EP0("%s: set ep%d stall, DIEPCTL0 = 0x%x\n",
727 __func__, ep_index(ep), __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON)));
729 * The application can only set this bit, and the core clears it,
730 * when a SETUP token is received for this endpoint
732 dev->ep0state = WAIT_FOR_SETUP;
737 static void s3c_ep0_read(struct s3c_udc *dev)
739 struct s3c_request *req;
740 struct s3c_ep *ep = &dev->ep[0];
743 if (!list_empty(&ep->queue)) {
744 req = list_entry(ep->queue.next, struct s3c_request, queue);
747 DEBUG("%s: ---> BUG\n", __func__);
752 DEBUG_EP0("%s: req = %p, req.length = 0x%x, req.actual = 0x%x\n",
753 __func__, req, req->req.length, req->req.actual);
755 if (req->req.length == 0) {
756 /* zlp for Set_configuration, Set_interface,
757 * or Bulk-Only mass storge reset */
759 dev->ep0state = WAIT_FOR_SETUP;
763 DEBUG_EP0("%s: req.length = 0, bRequest = %d\n",
764 __func__, usb_ctrl->bRequest);
768 ret = setdma_rx(ep, req);
774 static int s3c_ep0_write(struct s3c_udc *dev)
776 struct s3c_request *req;
777 struct s3c_ep *ep = &dev->ep[0];
778 int ret, need_zlp = 0;
780 if (list_empty(&ep->queue))
783 req = list_entry(ep->queue.next, struct s3c_request, queue);
786 DEBUG_EP0("%s: NULL REQ\n", __func__);
790 DEBUG_EP0("%s: req = %p, req.length = 0x%x, req.actual = 0x%x\n",
791 __func__, req, req->req.length, req->req.actual);
793 if (req->req.length - req->req.actual == ep0_fifo_size) {
794 /* Next write will end with the packet size, */
795 /* so we need Zero-length-packet */
799 ret = write_fifo_ep0(ep, req);
801 if ((ret == 1) && !need_zlp) {
803 dev->ep0state = WAIT_FOR_SETUP;
804 DEBUG_EP0("%s: finished, waiting for status\n", __func__);
807 dev->ep0state = DATA_STATE_XMIT;
808 DEBUG_EP0("%s: not finished\n", __func__);
812 dev->ep0state = DATA_STATE_NEED_ZLP;
813 DEBUG_EP0("%s: Need ZLP!\n", __func__);
819 u16 g_status __attribute__((aligned(8)));
821 static int s3c_udc_get_status(struct s3c_udc *dev,
822 struct usb_ctrlrequest *crq)
824 u8 ep_num = crq->wIndex & 0x7F;
827 DEBUG_SETUP("%s: *** USB_REQ_GET_STATUS\n", __func__);
829 switch (crq->bRequestType & USB_RECIP_MASK) {
830 case USB_RECIP_INTERFACE:
832 DEBUG_SETUP("\tGET_STATUS: USB_RECIP_INTERFACE,"
833 "g_stauts = %d\n", g_status);
836 case USB_RECIP_DEVICE:
837 g_status = 0x1; /* Self powered */
838 DEBUG_SETUP("\tGET_STATUS: USB_RECIP_DEVICE,"
839 "g_stauts = %d\n", g_status);
842 case USB_RECIP_ENDPOINT:
843 if (crq->wLength > 2) {
844 DEBUG_SETUP("\tGET_STATUS:"
845 "Not support EP or wLength\n");
849 g_status = dev->ep[ep_num].stopped;
850 DEBUG_SETUP("\tGET_STATUS: USB_RECIP_ENDPOINT,"
851 "g_stauts = %d\n", g_status);
859 __dma_single_cpu_to_dev(&g_status, 2, DMA_TO_DEVICE);
861 __raw_writel(virt_to_phys(&g_status), S3C_UDC_OTG_DIEPDMA(EP0_CON));
862 __raw_writel((1<<19)|(2<<0), S3C_UDC_OTG_DIEPTSIZ(EP0_CON));
864 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON));
865 __raw_writel(ep_ctrl|DEPCTL_EPENA|DEPCTL_CNAK, S3C_UDC_OTG_DIEPCTL(EP0_CON));
866 dev->ep0state = WAIT_FOR_SETUP;
871 static void s3c_udc_set_nak(struct s3c_ep *ep)
876 ep_num = ep_index(ep);
877 DEBUG("%s: ep_num = %d, ep_type = %d\n", __func__, ep_num, ep->ep_type);
880 ep_ctrl = readl(S3C_UDC_OTG_DIEPCTL(ep_num));
881 ep_ctrl |= DEPCTL_SNAK;
882 writel(ep_ctrl, S3C_UDC_OTG_DIEPCTL(ep_num));
883 DEBUG("%s: set NAK, DIEPCTL%d = 0x%x\n",
884 __func__, ep_num, readl(S3C_UDC_OTG_DIEPCTL(ep_num)));
886 ep_ctrl = readl(S3C_UDC_OTG_DOEPCTL(ep_num));
887 ep_ctrl |= DEPCTL_SNAK;
888 writel(ep_ctrl, S3C_UDC_OTG_DOEPCTL(ep_num));
889 DEBUG("%s: set NAK, DOEPCTL%d = 0x%x\n",
890 __func__, ep_num, readl(S3C_UDC_OTG_DOEPCTL(ep_num)));
896 void s3c_udc_ep_set_stall(struct s3c_ep *ep)
901 ep_num = ep_index(ep);
902 DEBUG("%s: ep_num = %d, ep_type = %d\n", __func__, ep_num, ep->ep_type);
905 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num));
907 /* set the disable and stall bits */
908 if (ep_ctrl & DEPCTL_EPENA)
909 ep_ctrl |= DEPCTL_EPDIS;
911 ep_ctrl |= DEPCTL_STALL;
913 __raw_writel(ep_ctrl, S3C_UDC_OTG_DIEPCTL(ep_num));
914 DEBUG("%s: set stall, DIEPCTL%d = 0x%x\n",
915 __func__, ep_num, __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num)));
918 ep_ctrl = __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num));
920 /* set the stall bit */
921 ep_ctrl |= DEPCTL_STALL;
923 __raw_writel(ep_ctrl, S3C_UDC_OTG_DOEPCTL(ep_num));
924 DEBUG("%s: set stall, DOEPCTL%d = 0x%x\n",
925 __func__, ep_num, __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num)));
931 void s3c_udc_ep_clear_stall(struct s3c_ep *ep)
936 ep_num = ep_index(ep);
937 DEBUG("%s: ep_num = %d, ep_type = %d\n", __func__, ep_num, ep->ep_type);
940 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num));
942 /* clear stall bit */
943 ep_ctrl &= ~DEPCTL_STALL;
946 * USB Spec 9.4.5: For endpoints using data toggle, regardless
947 * of whether an endpoint has the Halt feature set, a
948 * ClearFeature(ENDPOINT_HALT) request always results in the
949 * data toggle being reinitialized to DATA0.
951 if (ep->bmAttributes == USB_ENDPOINT_XFER_INT
952 || ep->bmAttributes == USB_ENDPOINT_XFER_BULK) {
953 ep_ctrl |= DEPCTL_SETD0PID; /* DATA0 */
956 __raw_writel(ep_ctrl, S3C_UDC_OTG_DIEPCTL(ep_num));
957 DEBUG("%s: cleared stall, DIEPCTL%d = 0x%x\n",
958 __func__, ep_num, __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num)));
961 ep_ctrl = __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num));
963 /* clear stall bit */
964 ep_ctrl &= ~DEPCTL_STALL;
966 if (ep->bmAttributes == USB_ENDPOINT_XFER_INT
967 || ep->bmAttributes == USB_ENDPOINT_XFER_BULK) {
968 ep_ctrl |= DEPCTL_SETD0PID; /* DATA0 */
971 __raw_writel(ep_ctrl, S3C_UDC_OTG_DOEPCTL(ep_num));
972 DEBUG("%s: cleared stall, DOEPCTL%d = 0x%x\n",
973 __func__, ep_num, __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num)));
979 static int s3c_udc_set_halt(struct usb_ep *_ep, int value)
986 ep = container_of(_ep, struct s3c_ep, ep);
987 ep_num = ep_index(ep);
989 if (unlikely(!_ep || !ep->desc || ep_num == EP0_CON ||
990 ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC)) {
991 DEBUG("%s: %s bad ep or descriptor\n", __func__, ep->ep.name);
995 /* Attempt to halt IN ep will fail if any transfer requests
997 if (value && ep_is_in(ep) && !list_empty(&ep->queue)) {
998 DEBUG("%s: %s queue not empty, req = %p\n",
999 __func__, ep->ep.name,
1000 list_entry(ep->queue.next, struct s3c_request, queue));
1006 DEBUG("%s: ep_num = %d, value = %d\n", __func__, ep_num, value);
1008 spin_lock_irqsave(&dev->lock, flags);
1012 s3c_udc_ep_clear_stall(ep);
1015 s3c_udc_ep_set_stall(ep);
1018 spin_unlock_irqrestore(&dev->lock, flags);
1023 void s3c_udc_ep_activate(struct s3c_ep *ep)
1026 u32 ep_ctrl = 0, daintmsk = 0;
1028 ep_num = ep_index(ep);
1030 /* Read DEPCTLn register */
1032 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num));
1033 daintmsk = 1 << ep_num;
1035 ep_ctrl = __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num));
1036 daintmsk = (1 << ep_num) << DAINT_OUT_BIT;
1039 DEBUG("%s: EPCTRL%d = 0x%x, ep_is_in = %d\n",
1040 __func__, ep_num, ep_ctrl, ep_is_in(ep));
1042 /* If the EP is already active don't change the EP Control
1044 if (!(ep_ctrl & DEPCTL_USBACTEP)) {
1045 ep_ctrl = (ep_ctrl & ~DEPCTL_TYPE_MASK) |
1046 (ep->bmAttributes << DEPCTL_TYPE_BIT);
1047 ep_ctrl = (ep_ctrl & ~DEPCTL_MPS_MASK) |
1048 (ep->ep.maxpacket << DEPCTL_MPS_BIT);
1049 ep_ctrl |= (DEPCTL_SETD0PID | DEPCTL_USBACTEP);
1052 __raw_writel(ep_ctrl, S3C_UDC_OTG_DIEPCTL(ep_num));
1053 DEBUG("%s: USB Ative EP%d, DIEPCTRL%d = 0x%x\n",
1054 __func__, ep_num, ep_num,
1055 __raw_readl(S3C_UDC_OTG_DIEPCTL(ep_num)));
1057 __raw_writel(ep_ctrl, S3C_UDC_OTG_DOEPCTL(ep_num));
1058 DEBUG("%s: USB Ative EP%d, DOEPCTRL%d = 0x%x\n",
1059 __func__, ep_num, ep_num,
1060 __raw_readl(S3C_UDC_OTG_DOEPCTL(ep_num)));
1064 /* Unmask EP Interrtupt */
1065 __raw_writel(__raw_readl(S3C_UDC_OTG_DAINTMSK)|daintmsk, S3C_UDC_OTG_DAINTMSK);
1066 DEBUG("%s: DAINTMSK = 0x%x\n", __func__, __raw_readl(S3C_UDC_OTG_DAINTMSK));
1070 static int s3c_udc_clear_feature(struct usb_ep *_ep)
1075 ep = container_of(_ep, struct s3c_ep, ep);
1076 ep_num = ep_index(ep);
1078 DEBUG_SETUP("%s: ep_num = %d, is_in = %d, clear_feature_flag = %d\n",
1079 __func__, ep_num, ep_is_in(ep), clear_feature_flag);
1081 if (usb_ctrl->wLength != 0) {
1082 DEBUG_SETUP("\tCLEAR_FEATURE:"
1083 "wLength is not zero.....\n");
1087 switch (usb_ctrl->bRequestType & USB_RECIP_MASK) {
1088 case USB_RECIP_DEVICE:
1089 switch (usb_ctrl->wValue) {
1090 case USB_DEVICE_REMOTE_WAKEUP:
1091 DEBUG_SETUP("\tCLEAR_FEATURE:"
1092 "USB_DEVICE_REMOTE_WAKEUP\n");
1095 case USB_DEVICE_TEST_MODE:
1096 DEBUG_SETUP("\tCLEAR_FEATURE:"
1097 "USB_DEVICE_TEST_MODE\n");
1098 /** @todo Add CLEAR_FEATURE for TEST modes. */
1101 /* When a device receives the BAD CLEAR FEATURE request,
1102 the device has to change its status to STALL.
1103 This action based on USB2.0 spec. ch9.
1104 We already talked with S.LSI team about this problem.
1105 and they also reviewed & agree to adopt following patch.
1106 (added default case to change STALL status)
1107 2011.12.02 yongsul96.oh@samsung.com
1110 printk(KERN_INFO "\tCLEAR_FEATURE: INVAILD CASE\n");
1111 s3c_udc_ep0_set_stall(ep);
1118 case USB_RECIP_ENDPOINT:
1119 DEBUG_SETUP("\tCLEAR_FEATURE: USB_RECIP_ENDPOINT,"
1120 "wValue = %d\n", usb_ctrl->wValue);
1122 if (usb_ctrl->wValue == USB_ENDPOINT_HALT) {
1124 s3c_udc_ep0_set_stall(ep);
1130 s3c_udc_ep_clear_stall(ep);
1131 s3c_udc_ep_activate(ep);
1134 clear_feature_num = ep_num;
1135 clear_feature_flag = 1;
1143 /* Set into the test mode for Test Mode set_feature request */
1144 static inline void set_test_mode(void)
1147 u8 test_selector = (usb_ctrl->wIndex>>8) & TEST_SELECTOR_MASK;
1149 if (test_selector > 0 && test_selector < 6) {
1150 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON));
1152 __raw_writel(1<<19 | 0<<0, S3C_UDC_OTG_DIEPTSIZ(EP0_CON));
1153 __raw_writel(ep_ctrl | DEPCTL_EPENA | DEPCTL_CNAK
1154 | EP0_CON<<DEPCTL_NEXT_EP_BIT,
1155 S3C_UDC_OTG_DIEPCTL(EP0_CON));
1158 switch (test_selector) {
1160 /* some delay is necessary like printk() or udelay() */
1161 printk(KERN_INFO "Test mode selector in set_feature request is"
1164 dctl = __raw_readl(S3C_UDC_OTG_DCTL);
1165 __raw_writel((dctl & ~(TEST_CONTROL_MASK)) | TEST_J_MODE,
1169 /* some delay is necessary like printk() or udelay() */
1170 printk(KERN_INFO "Test mode selector in set_feature request is"
1173 dctl = __raw_readl(S3C_UDC_OTG_DCTL);
1174 __raw_writel((dctl&~(TEST_CONTROL_MASK))|TEST_K_MODE,
1177 case TEST_SE0_NAK_SEL:
1178 /* some delay is necessary like printk() or udelay() */
1179 printk(KERN_INFO "Test mode selector in set_feature request is"
1182 dctl = __raw_readl(S3C_UDC_OTG_DCTL);
1183 __raw_writel((dctl & ~(TEST_CONTROL_MASK)) | TEST_SE0_NAK_MODE,
1186 case TEST_PACKET_SEL:
1187 /* some delay is necessary like printk() or udelay() */
1188 printk(KERN_INFO "Test mode selector in set_feature request is"
1191 __dma_single_cpu_to_dev(test_pkt, TEST_PKT_SIZE, DMA_TO_DEVICE);
1192 __raw_writel(virt_to_phys(test_pkt), S3C_UDC_OTG_DIEPDMA(EP0_CON));
1194 ep_ctrl = __raw_readl(S3C_UDC_OTG_DIEPCTL(EP0_CON));
1196 __raw_writel(1<<19 | TEST_PKT_SIZE<<0, S3C_UDC_OTG_DIEPTSIZ(EP0_CON));
1197 __raw_writel(ep_ctrl | DEPCTL_EPENA | DEPCTL_CNAK
1198 | EP0_CON<<DEPCTL_NEXT_EP_BIT,
1199 S3C_UDC_OTG_DIEPCTL(EP0_CON));
1201 dctl = __raw_readl(S3C_UDC_OTG_DCTL);
1202 __raw_writel((dctl & ~(TEST_CONTROL_MASK)) | TEST_PACKET_MODE,
1205 case TEST_FORCE_ENABLE_SEL:
1206 /* some delay is necessary like printk() or udelay() */
1207 printk(KERN_INFO "Test mode selector in set_feature request is"
1208 "TEST FORCE ENABLE\n");
1210 dctl = __raw_readl(S3C_UDC_OTG_DCTL);
1211 __raw_writel((dctl & ~(TEST_CONTROL_MASK)) | TEST_FORCE_ENABLE_MODE,
1217 static int s3c_udc_set_feature(struct usb_ep *_ep)
1222 ep = container_of(_ep, struct s3c_ep, ep);
1223 ep_num = ep_index(ep);
1225 DEBUG_SETUP("%s: *** USB_REQ_SET_FEATURE,"
1226 "ep_num = %d\n", __func__, ep_num);
1228 if (usb_ctrl->wLength != 0) {
1229 DEBUG_SETUP("\tSET_FEATURE: wLength is not zero.....\n");
1233 switch (usb_ctrl->bRequestType & USB_RECIP_MASK) {
1234 case USB_RECIP_DEVICE:
1235 switch (usb_ctrl->wValue) {
1236 case USB_DEVICE_REMOTE_WAKEUP:
1237 DEBUG_SETUP("\tSET_FEATURE:"
1238 "USB_DEVICE_REMOTE_WAKEUP\n");
1241 case USB_DEVICE_TEST_MODE:
1242 DEBUG_SETUP("\tSET_FEATURE: USB_DEVICE_TEST_MODE\n");
1246 case USB_DEVICE_B_HNP_ENABLE:
1247 DEBUG_SETUP("\tSET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
1250 case USB_DEVICE_A_HNP_SUPPORT:
1251 /* RH port supports HNP */
1252 DEBUG_SETUP("\tSET_FEATURE:"
1253 "USB_DEVICE_A_HNP_SUPPORT\n");
1256 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1257 /* other RH port does */
1258 DEBUG_SETUP("\tSET_FEATURE:"
1259 "USB_DEVICE_A_ALT_HNP_SUPPORT\n");
1262 /* When a device receives the BAD SET FEATURE request,
1263 the device has to change its status to STALL.
1264 This action based on USB2.0 spec. ch9.
1265 We already talked with S.LSI team about this problem.
1266 and they also reviewed & agree to adopt following patch.
1267 (added default case to change STALL status)
1268 2011.12.02 yongsul96.oh@samsung.com
1271 printk(KERN_INFO "\tSET_FEATURE: INVAILD CASE\n");
1272 s3c_udc_ep0_set_stall(ep);
1279 case USB_RECIP_INTERFACE:
1280 DEBUG_SETUP("\tSET_FEATURE: USB_RECIP_INTERFACE\n");
1283 case USB_RECIP_ENDPOINT:
1284 DEBUG_SETUP("\tSET_FEATURE: USB_RECIP_ENDPOINT\n");
1285 if (usb_ctrl->wValue == USB_ENDPOINT_HALT) {
1287 s3c_udc_ep0_set_stall(ep);
1291 s3c_udc_ep_set_stall(ep);
1302 * WAIT_FOR_SETUP (OUT_PKT_RDY)
1304 static void s3c_ep0_setup(struct s3c_udc *dev)
1306 struct s3c_ep *ep = &dev->ep[0];
1307 int i, bytes, is_in;
1310 /* Nuke all previous transfers */
1313 /* read control req from fifo (8 bytes) */
1314 bytes = s3c_fifo_read(ep, (u32 *)usb_ctrl, 8);
1316 DEBUG_SETUP("%s: bRequestType = 0x%x(%s), bRequest = 0x%x"
1317 "\twLength = 0x%x, wValue = 0x%x, wIndex= 0x%x\n",
1318 __func__, usb_ctrl->bRequestType,
1319 (usb_ctrl->bRequestType & USB_DIR_IN) ? "IN" : "OUT",
1320 usb_ctrl->bRequest, usb_ctrl->wLength, usb_ctrl->wValue,
1323 if (usb_ctrl->bRequest == GET_MAX_LUN_REQUEST && usb_ctrl->wLength != 1) {
1324 DEBUG_SETUP("\t%s:GET_MAX_LUN_REQUEST:invalid wLength = %d,"
1325 "setup returned\n", __func__, usb_ctrl->wLength);
1327 s3c_udc_ep0_set_stall(ep);
1328 dev->ep0state = WAIT_FOR_SETUP;
1331 } else if (usb_ctrl->bRequest ==
1332 BOT_RESET_REQUEST && usb_ctrl->wLength != 0) {
1333 /* Bulk-Only *mass storge reset of class-specific request */
1334 DEBUG_SETUP("\t%s:BOT Rest:invalid wLength = %d,"
1336 __func__, usb_ctrl->wLength);
1338 s3c_udc_ep0_set_stall(ep);
1339 dev->ep0state = WAIT_FOR_SETUP;
1344 /* Set direction of EP0 */
1345 if (likely(usb_ctrl->bRequestType & USB_DIR_IN)) {
1346 ep->bEndpointAddress |= USB_DIR_IN;
1350 ep->bEndpointAddress &= ~USB_DIR_IN;
1353 /* cope with automagic for some standard requests. */
1354 dev->req_std = (usb_ctrl->bRequestType & USB_TYPE_MASK)
1355 == USB_TYPE_STANDARD;
1356 dev->req_config = 0;
1357 dev->req_pending = 1;
1359 /* Handle some SETUP packets ourselves */
1360 switch (usb_ctrl->bRequest) {
1361 case USB_REQ_SET_ADDRESS:
1362 DEBUG_SETUP("%s: *** USB_REQ_SET_ADDRESS (%d)\n",
1363 __func__, usb_ctrl->wValue);
1365 if (usb_ctrl->bRequestType
1366 != (USB_TYPE_STANDARD | USB_RECIP_DEVICE))
1369 udc_set_address(dev, usb_ctrl->wValue);
1372 case USB_REQ_SET_CONFIGURATION:
1373 DEBUG_SETUP("============================================\n");
1374 DEBUG_SETUP("%s: USB_REQ_SET_CONFIGURATION (%d)\n",
1375 __func__, usb_ctrl->wValue);
1377 if (usb_ctrl->bRequestType == USB_RECIP_DEVICE) {
1378 reset_available = 1;
1379 dev->req_config = 1;
1381 #if defined (CONFIG_BATTERY_S3C)
1382 s3c_udc_cable_connect(dev);
1386 case USB_REQ_GET_DESCRIPTOR:
1387 DEBUG_SETUP("%s: *** USB_REQ_GET_DESCRIPTOR\n", __func__);
1390 case USB_REQ_SET_INTERFACE:
1391 DEBUG_SETUP("%s: *** USB_REQ_SET_INTERFACE (%d)\n",
1392 __func__, usb_ctrl->wValue);
1394 if (usb_ctrl->bRequestType == USB_RECIP_INTERFACE) {
1395 reset_available = 1;
1396 dev->req_config = 1;
1400 case USB_REQ_GET_CONFIGURATION:
1401 DEBUG_SETUP("%s: *** USB_REQ_GET_CONFIGURATION\n", __func__);
1404 case USB_REQ_GET_STATUS:
1406 if (!s3c_udc_get_status(dev, usb_ctrl))
1412 case USB_REQ_CLEAR_FEATURE:
1413 ep_num = usb_ctrl->wIndex & 0x7f;
1415 if (!s3c_udc_clear_feature(&dev->ep[ep_num].ep))
1420 case USB_REQ_SET_FEATURE:
1421 ep_num = usb_ctrl->wIndex & 0x7f;
1423 if (!s3c_udc_set_feature(&dev->ep[ep_num].ep))
1429 DEBUG_SETUP("%s: *** Default of usb_ctrl->bRequest=0x%x"
1430 "happened.\n", __func__, usb_ctrl->bRequest);
1434 if (likely(dev->driver)) {
1435 /* device-2-host (IN) or no data setup command,
1436 * process immediately */
1437 DEBUG_SETUP("%s: usb_ctrlrequest will be passed to"
1438 "fsg_setup()\n", __func__);
1440 spin_unlock(&dev->lock);
1441 i = dev->driver->setup(&dev->gadget, usb_ctrl);
1442 spin_lock(&dev->lock);
1445 if (dev->req_config) {
1446 DEBUG_SETUP("\tconfig change 0x%02x fail %d?\n",
1447 (u32*)usb_ctrl->bRequest, i);
1451 /* setup processing failed, force stall */
1452 s3c_udc_ep0_set_stall(ep);
1453 dev->ep0state = WAIT_FOR_SETUP;
1455 DEBUG_SETUP("\tdev->driver->setup failed (%d),"
1457 i, usb_ctrl->bRequest);
1460 } else if (dev->req_pending) {
1461 dev->req_pending = 0;
1462 DEBUG_SETUP("\tdev->req_pending...\n");
1465 DEBUG_SETUP("\tep0state = %s\n", state_names[dev->ep0state]);
1471 * handle ep0 interrupt
1473 static void s3c_handle_ep0(struct s3c_udc *dev)
1475 if (dev->ep0state == WAIT_FOR_SETUP) {
1476 DEBUG_OUT_EP("%s: WAIT_FOR_SETUP\n", __func__);
1480 DEBUG_OUT_EP("%s: strange state!!(state = %s)\n",
1481 __func__, state_names[dev->ep0state]);
1485 static void s3c_ep0_kick(struct s3c_udc *dev, struct s3c_ep *ep)
1487 DEBUG_EP0("%s: ep_is_in = %d\n", __func__, ep_is_in(ep));
1489 dev->ep0state = DATA_STATE_XMIT;
1493 dev->ep0state = DATA_STATE_RECV;