2 * drivers/usb/gadget/s3c_udc_otg_xfer_dma.c
3 * Samsung S3C on-chip full/high speed USB OTG 2.0 device controllers
5 * Copyright (C) 2009 for Samsung Electronics
7 * BSP Support for Samsung's UDC driver
9 * git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git
11 * State machine bugfixes:
12 * Marek Szyprowski <m.szyprowski@samsung.com>
15 * Marek Szyprowski <m.szyprowski@samsung.com>
16 * Lukasz Majewski <l.majewski@samsumg.com>
18 * SPDX-License-Identifier: GPL-2.0+
21 static u8 clear_feature_num
;
22 int clear_feature_flag
;
24 /* Bulk-Only Mass Storage Reset (class-specific request) */
25 #define GET_MAX_LUN_REQUEST 0xFE
26 #define BOT_RESET_REQUEST 0xFF
28 static inline void s3c_udc_ep0_zlp(struct s3c_udc
*dev
)
32 writel(usb_ctrl_dma_addr
, ®
->in_endp
[EP0_CON
].diepdma
);
33 writel(DIEPT_SIZ_PKT_CNT(1), ®
->in_endp
[EP0_CON
].dieptsiz
);
35 ep_ctrl
= readl(®
->in_endp
[EP0_CON
].diepctl
);
36 writel(ep_ctrl
|DEPCTL_EPENA
|DEPCTL_CNAK
,
37 ®
->in_endp
[EP0_CON
].diepctl
);
39 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
40 __func__
, readl(®
->in_endp
[EP0_CON
].diepctl
));
41 dev
->ep0state
= WAIT_FOR_IN_COMPLETE
;
44 void s3c_udc_pre_setup(void)
48 debug_cond(DEBUG_IN_EP
,
49 "%s : Prepare Setup packets.\n", __func__
);
51 writel(DOEPT_SIZ_PKT_CNT(1) | sizeof(struct usb_ctrlrequest
),
52 ®
->out_endp
[EP0_CON
].doeptsiz
);
53 writel(usb_ctrl_dma_addr
, ®
->out_endp
[EP0_CON
].doepdma
);
55 ep_ctrl
= readl(®
->out_endp
[EP0_CON
].doepctl
);
56 writel(ep_ctrl
|DEPCTL_EPENA
, ®
->out_endp
[EP0_CON
].doepctl
);
58 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
59 __func__
, readl(®
->in_endp
[EP0_CON
].diepctl
));
60 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DOEPCTL0 = 0x%x\n",
61 __func__
, readl(®
->out_endp
[EP0_CON
].doepctl
));
65 static inline void s3c_ep0_complete_out(void)
69 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
70 __func__
, readl(®
->in_endp
[EP0_CON
].diepctl
));
71 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DOEPCTL0 = 0x%x\n",
72 __func__
, readl(®
->out_endp
[EP0_CON
].doepctl
));
74 debug_cond(DEBUG_IN_EP
,
75 "%s : Prepare Complete Out packet.\n", __func__
);
77 writel(DOEPT_SIZ_PKT_CNT(1) | sizeof(struct usb_ctrlrequest
),
78 ®
->out_endp
[EP0_CON
].doeptsiz
);
79 writel(usb_ctrl_dma_addr
, ®
->out_endp
[EP0_CON
].doepdma
);
81 ep_ctrl
= readl(®
->out_endp
[EP0_CON
].doepctl
);
82 writel(ep_ctrl
|DEPCTL_EPENA
|DEPCTL_CNAK
,
83 ®
->out_endp
[EP0_CON
].doepctl
);
85 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
86 __func__
, readl(®
->in_endp
[EP0_CON
].diepctl
));
87 debug_cond(DEBUG_EP0
!= 0, "%s:EP0 ZLP DOEPCTL0 = 0x%x\n",
88 __func__
, readl(®
->out_endp
[EP0_CON
].doepctl
));
93 static int setdma_rx(struct s3c_ep
*ep
, struct s3c_request
*req
)
97 u32 ep_num
= ep_index(ep
);
99 buf
= req
->req
.buf
+ req
->req
.actual
;
100 length
= min(req
->req
.length
- req
->req
.actual
,
101 ep_num
? DMA_BUFFER_SIZE
: ep
->ep
.maxpacket
);
106 if (ep_num
== EP0_CON
|| length
== 0)
109 pktcnt
= (length
- 1)/(ep
->ep
.maxpacket
) + 1;
111 ctrl
= readl(®
->out_endp
[ep_num
].doepctl
);
113 writel((unsigned int) ep
->dma_buf
, ®
->out_endp
[ep_num
].doepdma
);
114 writel(DOEPT_SIZ_PKT_CNT(pktcnt
) | DOEPT_SIZ_XFER_SIZE(length
),
115 ®
->out_endp
[ep_num
].doeptsiz
);
116 writel(DEPCTL_EPENA
|DEPCTL_CNAK
|ctrl
, ®
->out_endp
[ep_num
].doepctl
);
118 debug_cond(DEBUG_OUT_EP
!= 0,
119 "%s: EP%d RX DMA start : DOEPDMA = 0x%x,"
120 "DOEPTSIZ = 0x%x, DOEPCTL = 0x%x\n"
121 "\tbuf = 0x%p, pktcnt = %d, xfersize = %d\n",
123 readl(®
->out_endp
[ep_num
].doepdma
),
124 readl(®
->out_endp
[ep_num
].doeptsiz
),
125 readl(®
->out_endp
[ep_num
].doepctl
),
126 buf
, pktcnt
, length
);
131 int setdma_tx(struct s3c_ep
*ep
, struct s3c_request
*req
)
135 u32 ep_num
= ep_index(ep
);
137 buf
= req
->req
.buf
+ req
->req
.actual
;
138 length
= req
->req
.length
- req
->req
.actual
;
140 if (ep_num
== EP0_CON
)
141 length
= min(length
, (u32
)ep_maxpacket(ep
));
146 flush_dcache_range((unsigned long) ep
->dma_buf
,
147 (unsigned long) ep
->dma_buf
+
148 ROUND(ep
->len
, CONFIG_SYS_CACHELINE_SIZE
));
153 pktcnt
= (length
- 1)/(ep
->ep
.maxpacket
) + 1;
155 /* Flush the endpoint's Tx FIFO */
156 writel(TX_FIFO_NUMBER(ep
->fifo_num
), ®
->grstctl
);
157 writel(TX_FIFO_NUMBER(ep
->fifo_num
) | TX_FIFO_FLUSH
, ®
->grstctl
);
158 while (readl(®
->grstctl
) & TX_FIFO_FLUSH
)
161 writel((unsigned long) ep
->dma_buf
, ®
->in_endp
[ep_num
].diepdma
);
162 writel(DIEPT_SIZ_PKT_CNT(pktcnt
) | DIEPT_SIZ_XFER_SIZE(length
),
163 ®
->in_endp
[ep_num
].dieptsiz
);
165 ctrl
= readl(®
->in_endp
[ep_num
].diepctl
);
167 /* Write the FIFO number to be used for this endpoint */
168 ctrl
&= DIEPCTL_TX_FIFO_NUM_MASK
;
169 ctrl
|= DIEPCTL_TX_FIFO_NUM(ep
->fifo_num
);
171 /* Clear reserved (Next EP) bits */
172 ctrl
= (ctrl
&~(EP_MASK
<<DEPCTL_NEXT_EP_BIT
));
174 writel(DEPCTL_EPENA
|DEPCTL_CNAK
|ctrl
, ®
->in_endp
[ep_num
].diepctl
);
176 debug_cond(DEBUG_IN_EP
,
177 "%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 readl(®
->in_endp
[ep_num
].diepdma
),
182 readl(®
->in_endp
[ep_num
].dieptsiz
),
183 readl(®
->in_endp
[ep_num
].diepctl
),
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, is_short
= 0;
195 if (list_empty(&ep
->queue
)) {
196 debug_cond(DEBUG_OUT_EP
!= 0,
197 "%s: RX DMA done : NULL REQ on OUT EP-%d\n",
203 req
= list_entry(ep
->queue
.next
, struct s3c_request
, queue
);
204 ep_tsr
= readl(®
->out_endp
[ep_num
].doeptsiz
);
206 if (ep_num
== EP0_CON
)
207 xfer_size
= (ep_tsr
& DOEPT_SIZ_XFER_SIZE_MAX_EP0
);
209 xfer_size
= (ep_tsr
& DOEPT_SIZ_XFER_SIZE_MAX_EP
);
211 xfer_size
= ep
->len
- xfer_size
;
216 * Please be careful with proper buffer allocation for USB request,
217 * which needs to be aligned to CONFIG_SYS_CACHELINE_SIZE, not only
218 * with starting address, but also its size shall be a cache line
221 * This will prevent from corruption of data allocated immediatelly
222 * before or after the buffer.
224 * For armv7, the cache_v7.c provides proper code to emit "ERROR"
225 * message to warn users.
227 invalidate_dcache_range((unsigned long) ep
->dma_buf
,
228 (unsigned long) ep
->dma_buf
+
229 ROUND(xfer_size
, CONFIG_SYS_CACHELINE_SIZE
));
231 req
->req
.actual
+= min(xfer_size
, req
->req
.length
- req
->req
.actual
);
232 is_short
= (xfer_size
< ep
->ep
.maxpacket
);
234 debug_cond(DEBUG_OUT_EP
!= 0,
235 "%s: RX DMA done : ep = %d, rx bytes = %d/%d, "
236 "is_short = %d, DOEPTSIZ = 0x%x, remained bytes = %d\n",
237 __func__
, ep_num
, req
->req
.actual
, req
->req
.length
,
238 is_short
, ep_tsr
, xfer_size
);
240 if (is_short
|| req
->req
.actual
== req
->req
.length
) {
241 if (ep_num
== EP0_CON
&& dev
->ep0state
== DATA_STATE_RECV
) {
242 debug_cond(DEBUG_OUT_EP
!= 0, " => Send ZLP\n");
243 s3c_udc_ep0_zlp(dev
);
244 /* packet will be completed in complete_tx() */
245 dev
->ep0state
= WAIT_FOR_IN_COMPLETE
;
249 if (!list_empty(&ep
->queue
)) {
250 req
= list_entry(ep
->queue
.next
,
251 struct s3c_request
, queue
);
252 debug_cond(DEBUG_OUT_EP
!= 0,
253 "%s: Next Rx request start...\n",
262 static void complete_tx(struct s3c_udc
*dev
, u8 ep_num
)
264 struct s3c_ep
*ep
= &dev
->ep
[ep_num
];
265 struct s3c_request
*req
;
266 u32 ep_tsr
= 0, xfer_size
= 0, is_short
= 0;
269 if (dev
->ep0state
== WAIT_FOR_NULL_COMPLETE
) {
270 dev
->ep0state
= WAIT_FOR_OUT_COMPLETE
;
271 s3c_ep0_complete_out();
275 if (list_empty(&ep
->queue
)) {
276 debug_cond(DEBUG_IN_EP
,
277 "%s: TX DMA done : NULL REQ on IN EP-%d\n",
283 req
= list_entry(ep
->queue
.next
, struct s3c_request
, queue
);
285 ep_tsr
= readl(®
->in_endp
[ep_num
].dieptsiz
);
288 is_short
= (xfer_size
< ep
->ep
.maxpacket
);
289 req
->req
.actual
+= min(xfer_size
, req
->req
.length
- req
->req
.actual
);
291 debug_cond(DEBUG_IN_EP
,
292 "%s: TX DMA done : ep = %d, tx bytes = %d/%d, "
293 "is_short = %d, DIEPTSIZ = 0x%x, remained bytes = %d\n",
294 __func__
, ep_num
, req
->req
.actual
, req
->req
.length
,
295 is_short
, ep_tsr
, xfer_size
);
298 if (dev
->ep0state
== DATA_STATE_XMIT
) {
299 debug_cond(DEBUG_IN_EP
,
300 "%s: ep_num = %d, ep0stat =="
303 last
= write_fifo_ep0(ep
, req
);
305 dev
->ep0state
= WAIT_FOR_COMPLETE
;
306 } else if (dev
->ep0state
== WAIT_FOR_IN_COMPLETE
) {
307 debug_cond(DEBUG_IN_EP
,
308 "%s: ep_num = %d, completing request\n",
311 dev
->ep0state
= WAIT_FOR_SETUP
;
312 } else if (dev
->ep0state
== WAIT_FOR_COMPLETE
) {
313 debug_cond(DEBUG_IN_EP
,
314 "%s: ep_num = %d, completing request\n",
317 dev
->ep0state
= WAIT_FOR_OUT_COMPLETE
;
318 s3c_ep0_complete_out();
320 debug_cond(DEBUG_IN_EP
,
321 "%s: ep_num = %d, invalid ep state\n",
327 if (req
->req
.actual
== req
->req
.length
)
330 if (!list_empty(&ep
->queue
)) {
331 req
= list_entry(ep
->queue
.next
, struct s3c_request
, queue
);
332 debug_cond(DEBUG_IN_EP
,
333 "%s: Next Tx request start...\n", __func__
);
338 static inline void s3c_udc_check_tx_queue(struct s3c_udc
*dev
, u8 ep_num
)
340 struct s3c_ep
*ep
= &dev
->ep
[ep_num
];
341 struct s3c_request
*req
;
343 debug_cond(DEBUG_IN_EP
,
344 "%s: Check queue, ep_num = %d\n", __func__
, ep_num
);
346 if (!list_empty(&ep
->queue
)) {
347 req
= list_entry(ep
->queue
.next
, struct s3c_request
, queue
);
348 debug_cond(DEBUG_IN_EP
,
349 "%s: Next Tx request(0x%p) start...\n",
357 debug_cond(DEBUG_IN_EP
,
358 "%s: NULL REQ on IN EP-%d\n", __func__
, ep_num
);
365 static void process_ep_in_intr(struct s3c_udc
*dev
)
367 u32 ep_intr
, ep_intr_status
;
370 ep_intr
= readl(®
->daint
);
371 debug_cond(DEBUG_IN_EP
,
372 "*** %s: EP In interrupt : DAINT = 0x%x\n", __func__
, ep_intr
);
374 ep_intr
&= DAINT_MASK
;
377 if (ep_intr
& DAINT_IN_EP_INT(1)) {
378 ep_intr_status
= readl(®
->in_endp
[ep_num
].diepint
);
379 debug_cond(DEBUG_IN_EP
,
380 "\tEP%d-IN : DIEPINT = 0x%x\n",
381 ep_num
, ep_intr_status
);
383 /* Interrupt Clear */
384 writel(ep_intr_status
, ®
->in_endp
[ep_num
].diepint
);
386 if (ep_intr_status
& TRANSFER_DONE
) {
387 complete_tx(dev
, ep_num
);
391 WAIT_FOR_IN_COMPLETE
)
392 dev
->ep0state
= WAIT_FOR_SETUP
;
394 if (dev
->ep0state
== WAIT_FOR_SETUP
)
397 /* continue transfer after
398 set_clear_halt for DMA mode */
399 if (clear_feature_flag
== 1) {
400 s3c_udc_check_tx_queue(dev
,
402 clear_feature_flag
= 0;
412 static void process_ep_out_intr(struct s3c_udc
*dev
)
414 u32 ep_intr
, ep_intr_status
;
417 ep_intr
= readl(®
->daint
);
418 debug_cond(DEBUG_OUT_EP
!= 0,
419 "*** %s: EP OUT interrupt : DAINT = 0x%x\n",
422 ep_intr
= (ep_intr
>> DAINT_OUT_BIT
) & DAINT_MASK
;
426 ep_intr_status
= readl(®
->out_endp
[ep_num
].doepint
);
427 debug_cond(DEBUG_OUT_EP
!= 0,
428 "\tEP%d-OUT : DOEPINT = 0x%x\n",
429 ep_num
, ep_intr_status
);
431 /* Interrupt Clear */
432 writel(ep_intr_status
, ®
->out_endp
[ep_num
].doepint
);
435 if (ep_intr_status
& TRANSFER_DONE
) {
437 WAIT_FOR_OUT_COMPLETE
)
438 complete_rx(dev
, ep_num
);
440 dev
->ep0state
= WAIT_FOR_SETUP
;
446 CTRL_OUT_EP_SETUP_PHASE_DONE
) {
447 debug_cond(DEBUG_OUT_EP
!= 0,
448 "SETUP packet arrived\n");
452 if (ep_intr_status
& TRANSFER_DONE
)
453 complete_rx(dev
, ep_num
);
462 * usb client interrupt handler.
464 static int s3c_udc_irq(int irq
, void *_dev
)
466 struct s3c_udc
*dev
= _dev
;
468 u32 usb_status
, gintmsk
;
471 spin_lock_irqsave(&dev
->lock
, flags
);
473 intr_status
= readl(®
->gintsts
);
474 gintmsk
= readl(®
->gintmsk
);
476 debug_cond(DEBUG_ISR
,
477 "\n*** %s : GINTSTS=0x%x(on state %s), GINTMSK : 0x%x,"
478 "DAINT : 0x%x, DAINTMSK : 0x%x\n",
479 __func__
, intr_status
, state_names
[dev
->ep0state
], gintmsk
,
480 readl(®
->daint
), readl(®
->daintmsk
));
483 spin_unlock_irqrestore(&dev
->lock
, flags
);
487 if (intr_status
& INT_ENUMDONE
) {
488 debug_cond(DEBUG_ISR
, "\tSpeed Detection interrupt\n");
490 writel(INT_ENUMDONE
, ®
->gintsts
);
491 usb_status
= (readl(®
->dsts
) & 0x6);
493 if (usb_status
& (USB_FULL_30_60MHZ
| USB_FULL_48MHZ
)) {
494 debug_cond(DEBUG_ISR
,
495 "\t\tFull Speed Detection\n");
496 set_max_pktsize(dev
, USB_SPEED_FULL
);
499 debug_cond(DEBUG_ISR
,
500 "\t\tHigh Speed Detection : 0x%x\n",
502 set_max_pktsize(dev
, USB_SPEED_HIGH
);
506 if (intr_status
& INT_EARLY_SUSPEND
) {
507 debug_cond(DEBUG_ISR
, "\tEarly suspend interrupt\n");
508 writel(INT_EARLY_SUSPEND
, ®
->gintsts
);
511 if (intr_status
& INT_SUSPEND
) {
512 usb_status
= readl(®
->dsts
);
513 debug_cond(DEBUG_ISR
,
514 "\tSuspend interrupt :(DSTS):0x%x\n", usb_status
);
515 writel(INT_SUSPEND
, ®
->gintsts
);
517 if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
519 if (dev
->driver
->suspend
)
520 dev
->driver
->suspend(&dev
->gadget
);
522 /* HACK to let gadget detect disconnected state */
523 if (dev
->driver
->disconnect
) {
524 spin_unlock_irqrestore(&dev
->lock
, flags
);
525 dev
->driver
->disconnect(&dev
->gadget
);
526 spin_lock_irqsave(&dev
->lock
, flags
);
531 if (intr_status
& INT_RESUME
) {
532 debug_cond(DEBUG_ISR
, "\tResume interrupt\n");
533 writel(INT_RESUME
, ®
->gintsts
);
535 if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
537 && dev
->driver
->resume
) {
539 dev
->driver
->resume(&dev
->gadget
);
543 if (intr_status
& INT_RESET
) {
544 usb_status
= readl(®
->gotgctl
);
545 debug_cond(DEBUG_ISR
,
546 "\tReset interrupt - (GOTGCTL):0x%x\n", usb_status
);
547 writel(INT_RESET
, ®
->gintsts
);
549 if ((usb_status
& 0xc0000) == (0x3 << 18)) {
550 if (reset_available
) {
551 debug_cond(DEBUG_ISR
,
552 "\t\tOTG core got reset (%d)!!\n",
555 dev
->ep0state
= WAIT_FOR_SETUP
;
563 debug_cond(DEBUG_ISR
,
564 "\t\tRESET handling skipped\n");
568 if (intr_status
& INT_IN_EP
)
569 process_ep_in_intr(dev
);
571 if (intr_status
& INT_OUT_EP
)
572 process_ep_out_intr(dev
);
574 spin_unlock_irqrestore(&dev
->lock
, flags
);
579 /** Queue one request
580 * Kickstart transfer if needed
582 static int s3c_queue(struct usb_ep
*_ep
, struct usb_request
*_req
,
585 struct s3c_request
*req
;
591 req
= container_of(_req
, struct s3c_request
, req
);
592 if (unlikely(!_req
|| !_req
->complete
|| !_req
->buf
593 || !list_empty(&req
->queue
))) {
595 debug("%s: bad params\n", __func__
);
599 ep
= container_of(_ep
, struct s3c_ep
, ep
);
601 if (unlikely(!_ep
|| (!ep
->desc
&& ep
->ep
.name
!= ep0name
))) {
603 debug("%s: bad ep: %s, %d, %p\n", __func__
,
604 ep
->ep
.name
, !ep
->desc
, _ep
);
608 ep_num
= ep_index(ep
);
610 if (unlikely(!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)) {
612 debug("%s: bogus device state %p\n", __func__
, dev
->driver
);
616 spin_lock_irqsave(&dev
->lock
, flags
);
618 _req
->status
= -EINPROGRESS
;
621 /* kickstart this i/o queue? */
622 debug("\n*** %s: %s-%s req = %p, len = %d, buf = %p"
623 "Q empty = %d, stopped = %d\n",
624 __func__
, _ep
->name
, ep_is_in(ep
) ? "in" : "out",
625 _req
, _req
->length
, _req
->buf
,
626 list_empty(&ep
->queue
), ep
->stopped
);
630 int i
, len
= _req
->length
;
635 for (i
= 0; i
< len
; i
++) {
636 printf("%02x", ((u8
*)_req
->buf
)[i
]);
644 if (list_empty(&ep
->queue
) && !ep
->stopped
) {
648 list_add_tail(&req
->queue
, &ep
->queue
);
649 s3c_ep0_kick(dev
, ep
);
652 } else if (ep_is_in(ep
)) {
653 gintsts
= readl(®
->gintsts
);
654 debug_cond(DEBUG_IN_EP
,
655 "%s: ep_is_in, S3C_UDC_OTG_GINTSTS=0x%x\n",
660 gintsts
= readl(®
->gintsts
);
661 debug_cond(DEBUG_OUT_EP
!= 0,
662 "%s:ep_is_out, S3C_UDC_OTG_GINTSTS=0x%x\n",
669 /* pio or dma irq handler advances the queue. */
670 if (likely(req
!= 0))
671 list_add_tail(&req
->queue
, &ep
->queue
);
673 spin_unlock_irqrestore(&dev
->lock
, flags
);
678 /****************************************************************/
679 /* End Point 0 related functions */
680 /****************************************************************/
682 /* return: 0 = still running, 1 = completed, negative = errno */
683 static int write_fifo_ep0(struct s3c_ep
*ep
, struct s3c_request
*req
)
689 max
= ep_maxpacket(ep
);
691 debug_cond(DEBUG_EP0
!= 0, "%s: max = %d\n", __func__
, max
);
693 count
= setdma_tx(ep
, req
);
695 /* last packet is usually short (or a zlp) */
696 if (likely(count
!= max
))
699 if (likely(req
->req
.length
!= req
->req
.actual
+ count
)
706 debug_cond(DEBUG_EP0
!= 0,
707 "%s: wrote %s %d bytes%s %d left %p\n", __func__
,
710 req
->req
.length
- req
->req
.actual
- count
, req
);
712 /* requests complete when all IN data is in the FIFO */
714 ep
->dev
->ep0state
= WAIT_FOR_SETUP
;
721 int s3c_fifo_read(struct s3c_ep
*ep
, u32
*cp
, int max
)
723 invalidate_dcache_range((unsigned long)cp
, (unsigned long)cp
+
724 ROUND(max
, CONFIG_SYS_CACHELINE_SIZE
));
726 debug_cond(DEBUG_EP0
!= 0,
727 "%s: bytes=%d, ep_index=%d 0x%p\n", __func__
,
728 max
, ep_index(ep
), cp
);
734 * udc_set_address - set the USB address for this device
737 * Called from control endpoint function
738 * after it decodes a set address setup packet.
740 static void udc_set_address(struct s3c_udc
*dev
, unsigned char address
)
742 u32 ctrl
= readl(®
->dcfg
);
743 writel(DEVICE_ADDRESS(address
) | ctrl
, ®
->dcfg
);
745 s3c_udc_ep0_zlp(dev
);
747 debug_cond(DEBUG_EP0
!= 0,
748 "%s: USB OTG 2.0 Device address=%d, DCFG=0x%x\n",
749 __func__
, address
, readl(®
->dcfg
));
751 dev
->usb_address
= address
;
754 static inline void s3c_udc_ep0_set_stall(struct s3c_ep
*ep
)
760 ep_ctrl
= readl(®
->in_endp
[EP0_CON
].diepctl
);
762 /* set the disable and stall bits */
763 if (ep_ctrl
& DEPCTL_EPENA
)
764 ep_ctrl
|= DEPCTL_EPDIS
;
766 ep_ctrl
|= DEPCTL_STALL
;
768 writel(ep_ctrl
, ®
->in_endp
[EP0_CON
].diepctl
);
770 debug_cond(DEBUG_EP0
!= 0,
771 "%s: set ep%d stall, DIEPCTL0 = 0x%p\n",
772 __func__
, ep_index(ep
), ®
->in_endp
[EP0_CON
].diepctl
);
774 * The application can only set this bit, and the core clears it,
775 * when a SETUP token is received for this endpoint
777 dev
->ep0state
= WAIT_FOR_SETUP
;
782 static void s3c_ep0_read(struct s3c_udc
*dev
)
784 struct s3c_request
*req
;
785 struct s3c_ep
*ep
= &dev
->ep
[0];
787 if (!list_empty(&ep
->queue
)) {
788 req
= list_entry(ep
->queue
.next
, struct s3c_request
, queue
);
791 debug("%s: ---> BUG\n", __func__
);
796 debug_cond(DEBUG_EP0
!= 0,
797 "%s: req = %p, req.length = 0x%x, req.actual = 0x%x\n",
798 __func__
, req
, req
->req
.length
, req
->req
.actual
);
800 if (req
->req
.length
== 0) {
801 /* zlp for Set_configuration, Set_interface,
802 * or Bulk-Only mass storge reset */
805 s3c_udc_ep0_zlp(dev
);
807 debug_cond(DEBUG_EP0
!= 0,
808 "%s: req.length = 0, bRequest = %d\n",
809 __func__
, usb_ctrl
->bRequest
);
819 static int s3c_ep0_write(struct s3c_udc
*dev
)
821 struct s3c_request
*req
;
822 struct s3c_ep
*ep
= &dev
->ep
[0];
823 int ret
, need_zlp
= 0;
825 if (list_empty(&ep
->queue
))
828 req
= list_entry(ep
->queue
.next
, struct s3c_request
, queue
);
831 debug_cond(DEBUG_EP0
!= 0, "%s: NULL REQ\n", __func__
);
835 debug_cond(DEBUG_EP0
!= 0,
836 "%s: req = %p, req.length = 0x%x, req.actual = 0x%x\n",
837 __func__
, req
, req
->req
.length
, req
->req
.actual
);
839 if (req
->req
.length
- req
->req
.actual
== ep0_fifo_size
) {
840 /* Next write will end with the packet size, */
841 /* so we need Zero-length-packet */
845 ret
= write_fifo_ep0(ep
, req
);
847 if ((ret
== 1) && !need_zlp
) {
849 dev
->ep0state
= WAIT_FOR_COMPLETE
;
850 debug_cond(DEBUG_EP0
!= 0,
851 "%s: finished, waiting for status\n", __func__
);
854 dev
->ep0state
= DATA_STATE_XMIT
;
855 debug_cond(DEBUG_EP0
!= 0,
856 "%s: not finished\n", __func__
);
862 int s3c_udc_get_status(struct s3c_udc
*dev
,
863 struct usb_ctrlrequest
*crq
)
865 u8 ep_num
= crq
->wIndex
& 0x7F;
869 debug_cond(DEBUG_SETUP
!= 0,
870 "%s: *** USB_REQ_GET_STATUS\n", __func__
);
871 printf("crq->brequest:0x%x\n", crq
->bRequestType
& USB_RECIP_MASK
);
872 switch (crq
->bRequestType
& USB_RECIP_MASK
) {
873 case USB_RECIP_INTERFACE
:
875 debug_cond(DEBUG_SETUP
!= 0,
876 "\tGET_STATUS:USB_RECIP_INTERFACE, g_stauts = %d\n",
880 case USB_RECIP_DEVICE
:
881 g_status
= 0x1; /* Self powered */
882 debug_cond(DEBUG_SETUP
!= 0,
883 "\tGET_STATUS: USB_RECIP_DEVICE, g_stauts = %d\n",
887 case USB_RECIP_ENDPOINT
:
888 if (crq
->wLength
> 2) {
889 debug_cond(DEBUG_SETUP
!= 0,
890 "\tGET_STATUS:Not support EP or wLength\n");
894 g_status
= dev
->ep
[ep_num
].stopped
;
895 debug_cond(DEBUG_SETUP
!= 0,
896 "\tGET_STATUS: USB_RECIP_ENDPOINT, g_stauts = %d\n",
905 memcpy(usb_ctrl
, &g_status
, sizeof(g_status
));
907 flush_dcache_range((unsigned long) usb_ctrl
,
908 (unsigned long) usb_ctrl
+
909 ROUND(sizeof(g_status
), CONFIG_SYS_CACHELINE_SIZE
));
911 writel(usb_ctrl_dma_addr
, ®
->in_endp
[EP0_CON
].diepdma
);
912 writel(DIEPT_SIZ_PKT_CNT(1) | DIEPT_SIZ_XFER_SIZE(2),
913 ®
->in_endp
[EP0_CON
].dieptsiz
);
915 ep_ctrl
= readl(®
->in_endp
[EP0_CON
].diepctl
);
916 writel(ep_ctrl
|DEPCTL_EPENA
|DEPCTL_CNAK
,
917 ®
->in_endp
[EP0_CON
].diepctl
);
918 dev
->ep0state
= WAIT_FOR_NULL_COMPLETE
;
923 static void s3c_udc_set_nak(struct s3c_ep
*ep
)
928 ep_num
= ep_index(ep
);
929 debug("%s: ep_num = %d, ep_type = %d\n", __func__
, ep_num
, ep
->ep_type
);
932 ep_ctrl
= readl(®
->in_endp
[ep_num
].diepctl
);
933 ep_ctrl
|= DEPCTL_SNAK
;
934 writel(ep_ctrl
, ®
->in_endp
[ep_num
].diepctl
);
935 debug("%s: set NAK, DIEPCTL%d = 0x%x\n",
936 __func__
, ep_num
, readl(®
->in_endp
[ep_num
].diepctl
));
938 ep_ctrl
= readl(®
->out_endp
[ep_num
].doepctl
);
939 ep_ctrl
|= DEPCTL_SNAK
;
940 writel(ep_ctrl
, ®
->out_endp
[ep_num
].doepctl
);
941 debug("%s: set NAK, DOEPCTL%d = 0x%x\n",
942 __func__
, ep_num
, readl(®
->out_endp
[ep_num
].doepctl
));
949 void s3c_udc_ep_set_stall(struct s3c_ep
*ep
)
954 ep_num
= ep_index(ep
);
955 debug("%s: ep_num = %d, ep_type = %d\n", __func__
, ep_num
, ep
->ep_type
);
958 ep_ctrl
= readl(®
->in_endp
[ep_num
].diepctl
);
960 /* set the disable and stall bits */
961 if (ep_ctrl
& DEPCTL_EPENA
)
962 ep_ctrl
|= DEPCTL_EPDIS
;
964 ep_ctrl
|= DEPCTL_STALL
;
966 writel(ep_ctrl
, ®
->in_endp
[ep_num
].diepctl
);
967 debug("%s: set stall, DIEPCTL%d = 0x%x\n",
968 __func__
, ep_num
, readl(®
->in_endp
[ep_num
].diepctl
));
971 ep_ctrl
= readl(®
->out_endp
[ep_num
].doepctl
);
973 /* set the stall bit */
974 ep_ctrl
|= DEPCTL_STALL
;
976 writel(ep_ctrl
, ®
->out_endp
[ep_num
].doepctl
);
977 debug("%s: set stall, DOEPCTL%d = 0x%x\n",
978 __func__
, ep_num
, readl(®
->out_endp
[ep_num
].doepctl
));
984 void s3c_udc_ep_clear_stall(struct s3c_ep
*ep
)
989 ep_num
= ep_index(ep
);
990 debug("%s: ep_num = %d, ep_type = %d\n", __func__
, ep_num
, ep
->ep_type
);
993 ep_ctrl
= readl(®
->in_endp
[ep_num
].diepctl
);
995 /* clear stall bit */
996 ep_ctrl
&= ~DEPCTL_STALL
;
999 * USB Spec 9.4.5: For endpoints using data toggle, regardless
1000 * of whether an endpoint has the Halt feature set, a
1001 * ClearFeature(ENDPOINT_HALT) request always results in the
1002 * data toggle being reinitialized to DATA0.
1004 if (ep
->bmAttributes
== USB_ENDPOINT_XFER_INT
1005 || ep
->bmAttributes
== USB_ENDPOINT_XFER_BULK
) {
1006 ep_ctrl
|= DEPCTL_SETD0PID
; /* DATA0 */
1009 writel(ep_ctrl
, ®
->in_endp
[ep_num
].diepctl
);
1010 debug("%s: cleared stall, DIEPCTL%d = 0x%x\n",
1011 __func__
, ep_num
, readl(®
->in_endp
[ep_num
].diepctl
));
1014 ep_ctrl
= readl(®
->out_endp
[ep_num
].doepctl
);
1016 /* clear stall bit */
1017 ep_ctrl
&= ~DEPCTL_STALL
;
1019 if (ep
->bmAttributes
== USB_ENDPOINT_XFER_INT
1020 || ep
->bmAttributes
== USB_ENDPOINT_XFER_BULK
) {
1021 ep_ctrl
|= DEPCTL_SETD0PID
; /* DATA0 */
1024 writel(ep_ctrl
, ®
->out_endp
[ep_num
].doepctl
);
1025 debug("%s: cleared stall, DOEPCTL%d = 0x%x\n",
1026 __func__
, ep_num
, readl(®
->out_endp
[ep_num
].doepctl
));
1032 static int s3c_udc_set_halt(struct usb_ep
*_ep
, int value
)
1035 struct s3c_udc
*dev
;
1036 unsigned long flags
;
1039 ep
= container_of(_ep
, struct s3c_ep
, ep
);
1040 ep_num
= ep_index(ep
);
1042 if (unlikely(!_ep
|| !ep
->desc
|| ep_num
== EP0_CON
||
1043 ep
->desc
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
)) {
1044 debug("%s: %s bad ep or descriptor\n", __func__
, ep
->ep
.name
);
1048 /* Attempt to halt IN ep will fail if any transfer requests
1049 * are still queue */
1050 if (value
&& ep_is_in(ep
) && !list_empty(&ep
->queue
)) {
1051 debug("%s: %s queue not empty, req = %p\n",
1052 __func__
, ep
->ep
.name
,
1053 list_entry(ep
->queue
.next
, struct s3c_request
, queue
));
1059 debug("%s: ep_num = %d, value = %d\n", __func__
, ep_num
, value
);
1061 spin_lock_irqsave(&dev
->lock
, flags
);
1065 s3c_udc_ep_clear_stall(ep
);
1068 dev
->ep0state
= WAIT_FOR_SETUP
;
1071 s3c_udc_ep_set_stall(ep
);
1074 spin_unlock_irqrestore(&dev
->lock
, flags
);
1079 void s3c_udc_ep_activate(struct s3c_ep
*ep
)
1082 u32 ep_ctrl
= 0, daintmsk
= 0;
1084 ep_num
= ep_index(ep
);
1086 /* Read DEPCTLn register */
1088 ep_ctrl
= readl(®
->in_endp
[ep_num
].diepctl
);
1089 daintmsk
= 1 << ep_num
;
1091 ep_ctrl
= readl(®
->out_endp
[ep_num
].doepctl
);
1092 daintmsk
= (1 << ep_num
) << DAINT_OUT_BIT
;
1095 debug("%s: EPCTRL%d = 0x%x, ep_is_in = %d\n",
1096 __func__
, ep_num
, ep_ctrl
, ep_is_in(ep
));
1098 /* If the EP is already active don't change the EP Control
1100 if (!(ep_ctrl
& DEPCTL_USBACTEP
)) {
1101 ep_ctrl
= (ep_ctrl
& ~DEPCTL_TYPE_MASK
) |
1102 (ep
->bmAttributes
<< DEPCTL_TYPE_BIT
);
1103 ep_ctrl
= (ep_ctrl
& ~DEPCTL_MPS_MASK
) |
1104 (ep
->ep
.maxpacket
<< DEPCTL_MPS_BIT
);
1105 ep_ctrl
|= (DEPCTL_SETD0PID
| DEPCTL_USBACTEP
| DEPCTL_SNAK
);
1108 writel(ep_ctrl
, ®
->in_endp
[ep_num
].diepctl
);
1109 debug("%s: USB Ative EP%d, DIEPCTRL%d = 0x%x\n",
1110 __func__
, ep_num
, ep_num
,
1111 readl(®
->in_endp
[ep_num
].diepctl
));
1113 writel(ep_ctrl
, ®
->out_endp
[ep_num
].doepctl
);
1114 debug("%s: USB Ative EP%d, DOEPCTRL%d = 0x%x\n",
1115 __func__
, ep_num
, ep_num
,
1116 readl(®
->out_endp
[ep_num
].doepctl
));
1120 /* Unmask EP Interrtupt */
1121 writel(readl(®
->daintmsk
)|daintmsk
, ®
->daintmsk
);
1122 debug("%s: DAINTMSK = 0x%x\n", __func__
, readl(®
->daintmsk
));
1126 static int s3c_udc_clear_feature(struct usb_ep
*_ep
)
1128 struct s3c_udc
*dev
;
1132 ep
= container_of(_ep
, struct s3c_ep
, ep
);
1133 ep_num
= ep_index(ep
);
1136 debug_cond(DEBUG_SETUP
!= 0,
1137 "%s: ep_num = %d, is_in = %d, clear_feature_flag = %d\n",
1138 __func__
, ep_num
, ep_is_in(ep
), clear_feature_flag
);
1140 if (usb_ctrl
->wLength
!= 0) {
1141 debug_cond(DEBUG_SETUP
!= 0,
1142 "\tCLEAR_FEATURE: wLength is not zero.....\n");
1146 switch (usb_ctrl
->bRequestType
& USB_RECIP_MASK
) {
1147 case USB_RECIP_DEVICE
:
1148 switch (usb_ctrl
->wValue
) {
1149 case USB_DEVICE_REMOTE_WAKEUP
:
1150 debug_cond(DEBUG_SETUP
!= 0,
1151 "\tOFF:USB_DEVICE_REMOTE_WAKEUP\n");
1154 case USB_DEVICE_TEST_MODE
:
1155 debug_cond(DEBUG_SETUP
!= 0,
1156 "\tCLEAR_FEATURE: USB_DEVICE_TEST_MODE\n");
1157 /** @todo Add CLEAR_FEATURE for TEST modes. */
1161 s3c_udc_ep0_zlp(dev
);
1164 case USB_RECIP_ENDPOINT
:
1165 debug_cond(DEBUG_SETUP
!= 0,
1166 "\tCLEAR_FEATURE:USB_RECIP_ENDPOINT, wValue = %d\n",
1169 if (usb_ctrl
->wValue
== USB_ENDPOINT_HALT
) {
1171 s3c_udc_ep0_set_stall(ep
);
1175 s3c_udc_ep0_zlp(dev
);
1177 s3c_udc_ep_clear_stall(ep
);
1178 s3c_udc_ep_activate(ep
);
1181 clear_feature_num
= ep_num
;
1182 clear_feature_flag
= 1;
1190 static int s3c_udc_set_feature(struct usb_ep
*_ep
)
1192 struct s3c_udc
*dev
;
1196 ep
= container_of(_ep
, struct s3c_ep
, ep
);
1197 ep_num
= ep_index(ep
);
1200 debug_cond(DEBUG_SETUP
!= 0,
1201 "%s: *** USB_REQ_SET_FEATURE , ep_num = %d\n",
1204 if (usb_ctrl
->wLength
!= 0) {
1205 debug_cond(DEBUG_SETUP
!= 0,
1206 "\tSET_FEATURE: wLength is not zero.....\n");
1210 switch (usb_ctrl
->bRequestType
& USB_RECIP_MASK
) {
1211 case USB_RECIP_DEVICE
:
1212 switch (usb_ctrl
->wValue
) {
1213 case USB_DEVICE_REMOTE_WAKEUP
:
1214 debug_cond(DEBUG_SETUP
!= 0,
1215 "\tSET_FEATURE:USB_DEVICE_REMOTE_WAKEUP\n");
1217 case USB_DEVICE_B_HNP_ENABLE
:
1218 debug_cond(DEBUG_SETUP
!= 0,
1219 "\tSET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
1222 case USB_DEVICE_A_HNP_SUPPORT
:
1223 /* RH port supports HNP */
1224 debug_cond(DEBUG_SETUP
!= 0,
1225 "\tSET_FEATURE:USB_DEVICE_A_HNP_SUPPORT\n");
1228 case USB_DEVICE_A_ALT_HNP_SUPPORT
:
1229 /* other RH port does */
1230 debug_cond(DEBUG_SETUP
!= 0,
1231 "\tSET: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
1235 s3c_udc_ep0_zlp(dev
);
1238 case USB_RECIP_INTERFACE
:
1239 debug_cond(DEBUG_SETUP
!= 0,
1240 "\tSET_FEATURE: USB_RECIP_INTERFACE\n");
1243 case USB_RECIP_ENDPOINT
:
1244 debug_cond(DEBUG_SETUP
!= 0,
1245 "\tSET_FEATURE: USB_RECIP_ENDPOINT\n");
1246 if (usb_ctrl
->wValue
== USB_ENDPOINT_HALT
) {
1248 s3c_udc_ep0_set_stall(ep
);
1252 s3c_udc_ep_set_stall(ep
);
1255 s3c_udc_ep0_zlp(dev
);
1263 * WAIT_FOR_SETUP (OUT_PKT_RDY)
1265 void s3c_ep0_setup(struct s3c_udc
*dev
)
1267 struct s3c_ep
*ep
= &dev
->ep
[0];
1271 /* Nuke all previous transfers */
1274 /* read control req from fifo (8 bytes) */
1275 s3c_fifo_read(ep
, (u32
*)usb_ctrl
, 8);
1277 debug_cond(DEBUG_SETUP
!= 0,
1278 "%s: bRequestType = 0x%x(%s), bRequest = 0x%x"
1279 "\twLength = 0x%x, wValue = 0x%x, wIndex= 0x%x\n",
1280 __func__
, usb_ctrl
->bRequestType
,
1281 (usb_ctrl
->bRequestType
& USB_DIR_IN
) ? "IN" : "OUT",
1283 usb_ctrl
->wLength
, usb_ctrl
->wValue
, usb_ctrl
->wIndex
);
1287 int i
, len
= sizeof(*usb_ctrl
);
1288 char *p
= (char *)usb_ctrl
;
1291 for (i
= 0; i
< len
; i
++) {
1292 printf("%02x", ((u8
*)p
)[i
]);
1300 if (usb_ctrl
->bRequest
== GET_MAX_LUN_REQUEST
&&
1301 usb_ctrl
->wLength
!= 1) {
1302 debug_cond(DEBUG_SETUP
!= 0,
1303 "\t%s:GET_MAX_LUN_REQUEST:invalid",
1305 debug_cond(DEBUG_SETUP
!= 0,
1306 "wLength = %d, setup returned\n",
1309 s3c_udc_ep0_set_stall(ep
);
1310 dev
->ep0state
= WAIT_FOR_SETUP
;
1313 } else if (usb_ctrl
->bRequest
== BOT_RESET_REQUEST
&&
1314 usb_ctrl
->wLength
!= 0) {
1315 /* Bulk-Only *mass storge reset of class-specific request */
1316 debug_cond(DEBUG_SETUP
!= 0,
1317 "%s:BOT Rest:invalid wLength =%d, setup returned\n",
1318 __func__
, usb_ctrl
->wLength
);
1320 s3c_udc_ep0_set_stall(ep
);
1321 dev
->ep0state
= WAIT_FOR_SETUP
;
1326 /* Set direction of EP0 */
1327 if (likely(usb_ctrl
->bRequestType
& USB_DIR_IN
)) {
1328 ep
->bEndpointAddress
|= USB_DIR_IN
;
1330 ep
->bEndpointAddress
&= ~USB_DIR_IN
;
1332 /* cope with automagic for some standard requests. */
1333 dev
->req_std
= (usb_ctrl
->bRequestType
& USB_TYPE_MASK
)
1334 == USB_TYPE_STANDARD
;
1336 dev
->req_pending
= 1;
1338 /* Handle some SETUP packets ourselves */
1340 switch (usb_ctrl
->bRequest
) {
1341 case USB_REQ_SET_ADDRESS
:
1342 debug_cond(DEBUG_SETUP
!= 0,
1343 "%s: *** USB_REQ_SET_ADDRESS (%d)\n",
1344 __func__
, usb_ctrl
->wValue
);
1345 if (usb_ctrl
->bRequestType
1346 != (USB_TYPE_STANDARD
| USB_RECIP_DEVICE
))
1349 udc_set_address(dev
, usb_ctrl
->wValue
);
1352 case USB_REQ_SET_CONFIGURATION
:
1353 debug_cond(DEBUG_SETUP
!= 0,
1354 "=====================================\n");
1355 debug_cond(DEBUG_SETUP
!= 0,
1356 "%s: USB_REQ_SET_CONFIGURATION (%d)\n",
1357 __func__
, usb_ctrl
->wValue
);
1359 if (usb_ctrl
->bRequestType
== USB_RECIP_DEVICE
)
1360 reset_available
= 1;
1364 case USB_REQ_GET_DESCRIPTOR
:
1365 debug_cond(DEBUG_SETUP
!= 0,
1366 "%s: *** USB_REQ_GET_DESCRIPTOR\n",
1370 case USB_REQ_SET_INTERFACE
:
1371 debug_cond(DEBUG_SETUP
!= 0,
1372 "%s: *** USB_REQ_SET_INTERFACE (%d)\n",
1373 __func__
, usb_ctrl
->wValue
);
1375 if (usb_ctrl
->bRequestType
== USB_RECIP_INTERFACE
)
1376 reset_available
= 1;
1380 case USB_REQ_GET_CONFIGURATION
:
1381 debug_cond(DEBUG_SETUP
!= 0,
1382 "%s: *** USB_REQ_GET_CONFIGURATION\n",
1386 case USB_REQ_GET_STATUS
:
1387 if (!s3c_udc_get_status(dev
, usb_ctrl
))
1392 case USB_REQ_CLEAR_FEATURE
:
1393 ep_num
= usb_ctrl
->wIndex
& 0x7f;
1395 if (!s3c_udc_clear_feature(&dev
->ep
[ep_num
].ep
))
1400 case USB_REQ_SET_FEATURE
:
1401 ep_num
= usb_ctrl
->wIndex
& 0x7f;
1403 if (!s3c_udc_set_feature(&dev
->ep
[ep_num
].ep
))
1409 debug_cond(DEBUG_SETUP
!= 0,
1410 "%s: *** Default of usb_ctrl->bRequest=0x%x"
1411 "happened.\n", __func__
, usb_ctrl
->bRequest
);
1417 if (likely(dev
->driver
)) {
1418 /* device-2-host (IN) or no data setup command,
1419 * process immediately */
1420 debug_cond(DEBUG_SETUP
!= 0,
1421 "%s:usb_ctrlreq will be passed to fsg_setup()\n",
1424 spin_unlock(&dev
->lock
);
1425 i
= dev
->driver
->setup(&dev
->gadget
, usb_ctrl
);
1426 spin_lock(&dev
->lock
);
1429 /* setup processing failed, force stall */
1430 s3c_udc_ep0_set_stall(ep
);
1431 dev
->ep0state
= WAIT_FOR_SETUP
;
1433 debug_cond(DEBUG_SETUP
!= 0,
1434 "\tdev->driver->setup failed (%d),"
1436 i
, usb_ctrl
->bRequest
);
1439 } else if (dev
->req_pending
) {
1440 dev
->req_pending
= 0;
1441 debug_cond(DEBUG_SETUP
!= 0,
1442 "\tdev->req_pending...\n");
1445 debug_cond(DEBUG_SETUP
!= 0,
1446 "\tep0state = %s\n", state_names
[dev
->ep0state
]);
1452 * handle ep0 interrupt
1454 static void s3c_handle_ep0(struct s3c_udc
*dev
)
1456 if (dev
->ep0state
== WAIT_FOR_SETUP
) {
1457 debug_cond(DEBUG_OUT_EP
!= 0,
1458 "%s: WAIT_FOR_SETUP\n", __func__
);
1462 debug_cond(DEBUG_OUT_EP
!= 0,
1463 "%s: strange state!!(state = %s)\n",
1464 __func__
, state_names
[dev
->ep0state
]);
1468 static void s3c_ep0_kick(struct s3c_udc
*dev
, struct s3c_ep
*ep
)
1470 debug_cond(DEBUG_EP0
!= 0,
1471 "%s: ep_is_in = %d\n", __func__
, ep_is_in(ep
));
1473 dev
->ep0state
= DATA_STATE_XMIT
;
1477 dev
->ep0state
= DATA_STATE_RECV
;