2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-10-27 08:36:46 +00:00
|
|
|
/*
|
2015-12-04 01:34:46 +00:00
|
|
|
* drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
|
2015-12-04 01:55:37 +00:00
|
|
|
* Designware DWC2 on-chip full/high speed USB OTG 2.0 device controllers
|
2011-10-27 08:36:46 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 for Samsung Electronics
|
|
|
|
*
|
|
|
|
* BSP Support for Samsung's UDC driver
|
|
|
|
* available at:
|
|
|
|
* git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git
|
|
|
|
*
|
|
|
|
* State machine bugfixes:
|
|
|
|
* Marek Szyprowski <m.szyprowski@samsung.com>
|
|
|
|
*
|
|
|
|
* Ported to u-boot:
|
|
|
|
* Marek Szyprowski <m.szyprowski@samsung.com>
|
|
|
|
* Lukasz Majewski <l.majewski@samsumg.com>
|
|
|
|
*/
|
|
|
|
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <cpu_func.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-05-10 17:40:08 +00:00
|
|
|
#include <linux/bug.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
|
2011-10-27 08:36:46 +00:00
|
|
|
static u8 clear_feature_num;
|
|
|
|
int clear_feature_flag;
|
|
|
|
|
|
|
|
/* Bulk-Only Mass Storage Reset (class-specific request) */
|
|
|
|
#define GET_MAX_LUN_REQUEST 0xFE
|
|
|
|
#define BOT_RESET_REQUEST 0xFF
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static inline void dwc2_udc_ep0_zlp(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 ep_ctrl;
|
|
|
|
|
2019-12-02 11:11:17 +00:00
|
|
|
writel(phys_to_bus((unsigned long)usb_ctrl_dma_addr), ®->in_endp[EP0_CON].diepdma);
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(DIEPT_SIZ_PKT_CNT(1), ®->in_endp[EP0_CON].dieptsiz);
|
|
|
|
|
|
|
|
ep_ctrl = readl(®->in_endp[EP0_CON].diepctl);
|
|
|
|
writel(ep_ctrl|DEPCTL_EPENA|DEPCTL_CNAK,
|
|
|
|
®->in_endp[EP0_CON].diepctl);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->in_endp[EP0_CON].diepctl));
|
|
|
|
dev->ep0state = WAIT_FOR_IN_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static void dwc2_udc_pre_setup(void)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 ep_ctrl;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s : Prepare Setup packets.\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
writel(DOEPT_SIZ_PKT_CNT(1) | sizeof(struct usb_ctrlrequest),
|
|
|
|
®->out_endp[EP0_CON].doeptsiz);
|
2019-12-02 11:11:17 +00:00
|
|
|
writel(phys_to_bus((unsigned long)usb_ctrl_dma_addr), ®->out_endp[EP0_CON].doepdma);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep_ctrl = readl(®->out_endp[EP0_CON].doepctl);
|
|
|
|
writel(ep_ctrl|DEPCTL_EPENA, ®->out_endp[EP0_CON].doepctl);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->in_endp[EP0_CON].diepctl));
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DOEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->out_endp[EP0_CON].doepctl));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:59:12 +00:00
|
|
|
static inline void dwc2_ep0_complete_out(void)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 ep_ctrl;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->in_endp[EP0_CON].diepctl));
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DOEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->out_endp[EP0_CON].doepctl));
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s : Prepare Complete Out packet.\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
writel(DOEPT_SIZ_PKT_CNT(1) | sizeof(struct usb_ctrlrequest),
|
|
|
|
®->out_endp[EP0_CON].doeptsiz);
|
2019-12-02 11:11:17 +00:00
|
|
|
writel(phys_to_bus((unsigned long)usb_ctrl_dma_addr), ®->out_endp[EP0_CON].doepdma);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep_ctrl = readl(®->out_endp[EP0_CON].doepctl);
|
|
|
|
writel(ep_ctrl|DEPCTL_EPENA|DEPCTL_CNAK,
|
|
|
|
®->out_endp[EP0_CON].doepctl);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DIEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->in_endp[EP0_CON].diepctl));
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s:EP0 ZLP DOEPCTL0 = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, readl(®->out_endp[EP0_CON].doepctl));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-04 00:51:07 +00:00
|
|
|
static int setdma_rx(struct dwc2_ep *ep, struct dwc2_request *req)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 *buf, ctrl;
|
|
|
|
u32 length, pktcnt;
|
|
|
|
u32 ep_num = ep_index(ep);
|
|
|
|
|
|
|
|
buf = req->req.buf + req->req.actual;
|
linux/kernel.h: sync min, max, min3, max3 macros with Linux
U-Boot has never cared about the type when we get max/min of two
values, but Linux Kernel does. This commit gets min, max, min3, max3
macros synced with the kernel introducing type checks.
Many of references of those macros must be fixed to suppress warnings.
We have two options:
- Use min, max, min3, max3 only when the arguments have the same type
(or add casts to the arguments)
- Use min_t/max_t instead with the appropriate type for the first
argument
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Pavel Machek <pavel@denx.de>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
[trini: Fixup arch/blackfin/lib/string.c]
Signed-off-by: Tom Rini <trini@ti.com>
2014-11-06 18:03:31 +00:00
|
|
|
length = min_t(u32, req->req.length - req->req.actual,
|
|
|
|
ep_num ? DMA_BUFFER_SIZE : ep->ep.maxpacket);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep->len = length;
|
|
|
|
ep->dma_buf = buf;
|
|
|
|
|
2014-02-05 09:10:43 +00:00
|
|
|
if (ep_num == EP0_CON || length == 0)
|
2011-10-27 08:36:46 +00:00
|
|
|
pktcnt = 1;
|
|
|
|
else
|
|
|
|
pktcnt = (length - 1)/(ep->ep.maxpacket) + 1;
|
|
|
|
|
|
|
|
ctrl = readl(®->out_endp[ep_num].doepctl);
|
|
|
|
|
2016-07-14 06:52:35 +00:00
|
|
|
invalidate_dcache_range((unsigned long) ep->dma_buf,
|
2017-07-31 09:08:10 +00:00
|
|
|
(unsigned long) ep->dma_buf +
|
|
|
|
ROUND(ep->len, CONFIG_SYS_CACHELINE_SIZE));
|
2016-07-14 06:52:35 +00:00
|
|
|
|
2019-12-02 11:11:17 +00:00
|
|
|
writel(phys_to_bus((unsigned long)ep->dma_buf), ®->out_endp[ep_num].doepdma);
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(DOEPT_SIZ_PKT_CNT(pktcnt) | DOEPT_SIZ_XFER_SIZE(length),
|
|
|
|
®->out_endp[ep_num].doeptsiz);
|
|
|
|
writel(DEPCTL_EPENA|DEPCTL_CNAK|ctrl, ®->out_endp[ep_num].doepctl);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"%s: EP%d RX DMA start : DOEPDMA = 0x%x,"
|
|
|
|
"DOEPTSIZ = 0x%x, DOEPCTL = 0x%x\n"
|
|
|
|
"\tbuf = 0x%p, pktcnt = %d, xfersize = %d\n",
|
|
|
|
__func__, ep_num,
|
|
|
|
readl(®->out_endp[ep_num].doepdma),
|
|
|
|
readl(®->out_endp[ep_num].doeptsiz),
|
|
|
|
readl(®->out_endp[ep_num].doepctl),
|
|
|
|
buf, pktcnt, length);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:56:30 +00:00
|
|
|
static int setdma_tx(struct dwc2_ep *ep, struct dwc2_request *req)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 *buf, ctrl = 0;
|
|
|
|
u32 length, pktcnt;
|
|
|
|
u32 ep_num = ep_index(ep);
|
|
|
|
|
|
|
|
buf = req->req.buf + req->req.actual;
|
|
|
|
length = req->req.length - req->req.actual;
|
|
|
|
|
|
|
|
if (ep_num == EP0_CON)
|
2012-04-26 02:34:44 +00:00
|
|
|
length = min(length, (u32)ep_maxpacket(ep));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep->len = length;
|
|
|
|
ep->dma_buf = buf;
|
|
|
|
|
2014-02-05 09:10:44 +00:00
|
|
|
flush_dcache_range((unsigned long) ep->dma_buf,
|
|
|
|
(unsigned long) ep->dma_buf +
|
|
|
|
ROUND(ep->len, CONFIG_SYS_CACHELINE_SIZE));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
pktcnt = 1;
|
|
|
|
else
|
|
|
|
pktcnt = (length - 1)/(ep->ep.maxpacket) + 1;
|
|
|
|
|
|
|
|
/* Flush the endpoint's Tx FIFO */
|
|
|
|
writel(TX_FIFO_NUMBER(ep->fifo_num), ®->grstctl);
|
|
|
|
writel(TX_FIFO_NUMBER(ep->fifo_num) | TX_FIFO_FLUSH, ®->grstctl);
|
|
|
|
while (readl(®->grstctl) & TX_FIFO_FLUSH)
|
|
|
|
;
|
|
|
|
|
2019-12-02 11:11:17 +00:00
|
|
|
writel(phys_to_bus((unsigned long)ep->dma_buf), ®->in_endp[ep_num].diepdma);
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(DIEPT_SIZ_PKT_CNT(pktcnt) | DIEPT_SIZ_XFER_SIZE(length),
|
|
|
|
®->in_endp[ep_num].dieptsiz);
|
|
|
|
|
|
|
|
ctrl = readl(®->in_endp[ep_num].diepctl);
|
|
|
|
|
|
|
|
/* Write the FIFO number to be used for this endpoint */
|
|
|
|
ctrl &= DIEPCTL_TX_FIFO_NUM_MASK;
|
|
|
|
ctrl |= DIEPCTL_TX_FIFO_NUM(ep->fifo_num);
|
|
|
|
|
|
|
|
/* Clear reserved (Next EP) bits */
|
|
|
|
ctrl = (ctrl&~(EP_MASK<<DEPCTL_NEXT_EP_BIT));
|
|
|
|
|
|
|
|
writel(DEPCTL_EPENA|DEPCTL_CNAK|ctrl, ®->in_endp[ep_num].diepctl);
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s:EP%d TX DMA start : DIEPDMA0 = 0x%x,"
|
|
|
|
"DIEPTSIZ0 = 0x%x, DIEPCTL0 = 0x%x\n"
|
|
|
|
"\tbuf = 0x%p, pktcnt = %d, xfersize = %d\n",
|
|
|
|
__func__, ep_num,
|
|
|
|
readl(®->in_endp[ep_num].diepdma),
|
|
|
|
readl(®->in_endp[ep_num].dieptsiz),
|
|
|
|
readl(®->in_endp[ep_num].diepctl),
|
|
|
|
buf, pktcnt, length);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void complete_rx(struct dwc2_udc *dev, u8 ep_num)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[ep_num];
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req = NULL;
|
2011-10-27 08:36:46 +00:00
|
|
|
u32 ep_tsr = 0, xfer_size = 0, is_short = 0;
|
|
|
|
|
|
|
|
if (list_empty(&ep->queue)) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"%s: RX DMA done : NULL REQ on OUT EP-%d\n",
|
|
|
|
__func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-10-27 08:36:46 +00:00
|
|
|
ep_tsr = readl(®->out_endp[ep_num].doeptsiz);
|
|
|
|
|
|
|
|
if (ep_num == EP0_CON)
|
|
|
|
xfer_size = (ep_tsr & DOEPT_SIZ_XFER_SIZE_MAX_EP0);
|
|
|
|
else
|
|
|
|
xfer_size = (ep_tsr & DOEPT_SIZ_XFER_SIZE_MAX_EP);
|
|
|
|
|
|
|
|
xfer_size = ep->len - xfer_size;
|
|
|
|
|
2014-02-05 09:10:44 +00:00
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
*
|
|
|
|
* Please be careful with proper buffer allocation for USB request,
|
|
|
|
* which needs to be aligned to CONFIG_SYS_CACHELINE_SIZE, not only
|
|
|
|
* with starting address, but also its size shall be a cache line
|
|
|
|
* multiplication.
|
|
|
|
*
|
|
|
|
* This will prevent from corruption of data allocated immediatelly
|
|
|
|
* before or after the buffer.
|
|
|
|
*
|
|
|
|
* For armv7, the cache_v7.c provides proper code to emit "ERROR"
|
|
|
|
* message to warn users.
|
|
|
|
*/
|
|
|
|
invalidate_dcache_range((unsigned long) ep->dma_buf,
|
|
|
|
(unsigned long) ep->dma_buf +
|
|
|
|
ROUND(xfer_size, CONFIG_SYS_CACHELINE_SIZE));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
req->req.actual += min(xfer_size, req->req.length - req->req.actual);
|
2016-04-19 12:20:39 +00:00
|
|
|
is_short = !!(xfer_size % ep->ep.maxpacket);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"%s: RX DMA done : ep = %d, rx bytes = %d/%d, "
|
|
|
|
"is_short = %d, DOEPTSIZ = 0x%x, remained bytes = %d\n",
|
|
|
|
__func__, ep_num, req->req.actual, req->req.length,
|
2016-04-22 09:02:06 +00:00
|
|
|
is_short, ep_tsr, req->req.length - req->req.actual);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (is_short || req->req.actual == req->req.length) {
|
|
|
|
if (ep_num == EP0_CON && dev->ep0state == DATA_STATE_RECV) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0, " => Send ZLP\n");
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
/* packet will be completed in complete_tx() */
|
|
|
|
dev->ep0state = WAIT_FOR_IN_COMPLETE;
|
|
|
|
} else {
|
|
|
|
done(ep, req, 0);
|
|
|
|
|
|
|
|
if (!list_empty(&ep->queue)) {
|
|
|
|
req = list_entry(ep->queue.next,
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request, queue);
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"%s: Next Rx request start...\n",
|
|
|
|
__func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
setdma_rx(ep, req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
setdma_rx(ep, req);
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void complete_tx(struct dwc2_udc *dev, u8 ep_num)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[ep_num];
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2011-10-27 08:36:46 +00:00
|
|
|
u32 ep_tsr = 0, xfer_size = 0, is_short = 0;
|
|
|
|
u32 last;
|
|
|
|
|
|
|
|
if (dev->ep0state == WAIT_FOR_NULL_COMPLETE) {
|
|
|
|
dev->ep0state = WAIT_FOR_OUT_COMPLETE;
|
2015-12-04 00:59:12 +00:00
|
|
|
dwc2_ep0_complete_out();
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_empty(&ep->queue)) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: TX DMA done : NULL REQ on IN EP-%d\n",
|
|
|
|
__func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep_tsr = readl(®->in_endp[ep_num].dieptsiz);
|
|
|
|
|
|
|
|
xfer_size = ep->len;
|
|
|
|
is_short = (xfer_size < ep->ep.maxpacket);
|
|
|
|
req->req.actual += min(xfer_size, req->req.length - req->req.actual);
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: TX DMA done : ep = %d, tx bytes = %d/%d, "
|
|
|
|
"is_short = %d, DIEPTSIZ = 0x%x, remained bytes = %d\n",
|
|
|
|
__func__, ep_num, req->req.actual, req->req.length,
|
2016-04-22 09:02:06 +00:00
|
|
|
is_short, ep_tsr, req->req.length - req->req.actual);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (ep_num == 0) {
|
|
|
|
if (dev->ep0state == DATA_STATE_XMIT) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: ep_num = %d, ep0stat =="
|
|
|
|
"DATA_STATE_XMIT\n",
|
|
|
|
__func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
last = write_fifo_ep0(ep, req);
|
|
|
|
if (last)
|
|
|
|
dev->ep0state = WAIT_FOR_COMPLETE;
|
|
|
|
} else if (dev->ep0state == WAIT_FOR_IN_COMPLETE) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: ep_num = %d, completing request\n",
|
|
|
|
__func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
done(ep, req, 0);
|
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
} else if (dev->ep0state == WAIT_FOR_COMPLETE) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: ep_num = %d, completing request\n",
|
|
|
|
__func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
done(ep, req, 0);
|
|
|
|
dev->ep0state = WAIT_FOR_OUT_COMPLETE;
|
2015-12-04 00:59:12 +00:00
|
|
|
dwc2_ep0_complete_out();
|
2011-10-27 08:36:46 +00:00
|
|
|
} else {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: ep_num = %d, invalid ep state\n",
|
|
|
|
__func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->req.actual == req->req.length)
|
|
|
|
done(ep, req, 0);
|
|
|
|
|
|
|
|
if (!list_empty(&ep->queue)) {
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: Next Tx request start...\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
setdma_tx(ep, req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static inline void dwc2_udc_check_tx_queue(struct dwc2_udc *dev, u8 ep_num)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[ep_num];
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: Check queue, ep_num = %d\n", __func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (!list_empty(&ep->queue)) {
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: Next Tx request(0x%p) start...\n",
|
|
|
|
__func__, req);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (ep_is_in(ep))
|
|
|
|
setdma_tx(ep, req);
|
|
|
|
else
|
|
|
|
setdma_rx(ep, req);
|
|
|
|
} else {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"%s: NULL REQ on IN EP-%d\n", __func__, ep_num);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void process_ep_in_intr(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 ep_intr, ep_intr_status;
|
|
|
|
u8 ep_num = 0;
|
|
|
|
|
|
|
|
ep_intr = readl(®->daint);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"*** %s: EP In interrupt : DAINT = 0x%x\n", __func__, ep_intr);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep_intr &= DAINT_MASK;
|
|
|
|
|
|
|
|
while (ep_intr) {
|
|
|
|
if (ep_intr & DAINT_IN_EP_INT(1)) {
|
|
|
|
ep_intr_status = readl(®->in_endp[ep_num].diepint);
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
|
|
|
"\tEP%d-IN : DIEPINT = 0x%x\n",
|
|
|
|
ep_num, ep_intr_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* Interrupt Clear */
|
|
|
|
writel(ep_intr_status, ®->in_endp[ep_num].diepint);
|
|
|
|
|
|
|
|
if (ep_intr_status & TRANSFER_DONE) {
|
|
|
|
complete_tx(dev, ep_num);
|
|
|
|
|
|
|
|
if (ep_num == 0) {
|
|
|
|
if (dev->ep0state ==
|
|
|
|
WAIT_FOR_IN_COMPLETE)
|
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
|
|
|
if (dev->ep0state == WAIT_FOR_SETUP)
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_pre_setup();
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* continue transfer after
|
|
|
|
set_clear_halt for DMA mode */
|
|
|
|
if (clear_feature_flag == 1) {
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_check_tx_queue(dev,
|
2011-10-27 08:36:46 +00:00
|
|
|
clear_feature_num);
|
|
|
|
clear_feature_flag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ep_num++;
|
|
|
|
ep_intr >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void process_ep_out_intr(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 ep_intr, ep_intr_status;
|
|
|
|
u8 ep_num = 0;
|
2020-10-06 02:55:49 +00:00
|
|
|
u32 ep_tsr = 0, xfer_size = 0;
|
|
|
|
u32 epsiz_reg = reg->out_endp[ep_num].doeptsiz;
|
|
|
|
u32 req_size = sizeof(struct usb_ctrlrequest);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep_intr = readl(®->daint);
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"*** %s: EP OUT interrupt : DAINT = 0x%x\n",
|
|
|
|
__func__, ep_intr);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep_intr = (ep_intr >> DAINT_OUT_BIT) & DAINT_MASK;
|
|
|
|
|
|
|
|
while (ep_intr) {
|
|
|
|
if (ep_intr & 0x1) {
|
|
|
|
ep_intr_status = readl(®->out_endp[ep_num].doepint);
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"\tEP%d-OUT : DOEPINT = 0x%x\n",
|
|
|
|
ep_num, ep_intr_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* Interrupt Clear */
|
|
|
|
writel(ep_intr_status, ®->out_endp[ep_num].doepint);
|
|
|
|
|
|
|
|
if (ep_num == 0) {
|
|
|
|
if (ep_intr_status & TRANSFER_DONE) {
|
2020-10-06 02:55:49 +00:00
|
|
|
ep_tsr = readl(&epsiz_reg);
|
|
|
|
xfer_size = ep_tsr &
|
|
|
|
DOEPT_SIZ_XFER_SIZE_MAX_EP0;
|
|
|
|
|
|
|
|
if (xfer_size == req_size &&
|
|
|
|
dev->ep0state == WAIT_FOR_SETUP) {
|
|
|
|
dwc2_udc_pre_setup();
|
|
|
|
} else if (dev->ep0state !=
|
|
|
|
WAIT_FOR_OUT_COMPLETE) {
|
2011-10-27 08:36:46 +00:00
|
|
|
complete_rx(dev, ep_num);
|
2020-10-06 02:55:49 +00:00
|
|
|
} else {
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_pre_setup();
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ep_intr_status &
|
|
|
|
CTRL_OUT_EP_SETUP_PHASE_DONE) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"SETUP packet arrived\n");
|
2015-12-04 01:17:40 +00:00
|
|
|
dwc2_handle_ep0(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ep_intr_status & TRANSFER_DONE)
|
|
|
|
complete_rx(dev, ep_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ep_num++;
|
|
|
|
ep_intr >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usb client interrupt handler.
|
|
|
|
*/
|
2015-12-04 01:03:45 +00:00
|
|
|
static int dwc2_udc_irq(int irq, void *_dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev = _dev;
|
2019-04-17 14:46:13 +00:00
|
|
|
u32 intr_status, gotgint;
|
2011-10-27 08:36:46 +00:00
|
|
|
u32 usb_status, gintmsk;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->lock, flags);
|
|
|
|
|
|
|
|
intr_status = readl(®->gintsts);
|
|
|
|
gintmsk = readl(®->gintmsk);
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\n*** %s : GINTSTS=0x%x(on state %s), GINTMSK : 0x%x,"
|
2011-10-27 08:36:46 +00:00
|
|
|
"DAINT : 0x%x, DAINTMSK : 0x%x\n",
|
|
|
|
__func__, intr_status, state_names[dev->ep0state], gintmsk,
|
|
|
|
readl(®->daint), readl(®->daintmsk));
|
|
|
|
|
|
|
|
if (!intr_status) {
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_ENUMDONE) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR, "\tSpeed Detection interrupt\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
writel(INT_ENUMDONE, ®->gintsts);
|
|
|
|
usb_status = (readl(®->dsts) & 0x6);
|
|
|
|
|
|
|
|
if (usb_status & (USB_FULL_30_60MHZ | USB_FULL_48MHZ)) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\t\tFull Speed Detection\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
set_max_pktsize(dev, USB_SPEED_FULL);
|
|
|
|
|
|
|
|
} else {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\t\tHigh Speed Detection : 0x%x\n",
|
|
|
|
usb_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
set_max_pktsize(dev, USB_SPEED_HIGH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_EARLY_SUSPEND) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR, "\tEarly suspend interrupt\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(INT_EARLY_SUSPEND, ®->gintsts);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_SUSPEND) {
|
|
|
|
usb_status = readl(®->dsts);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\tSuspend interrupt :(DSTS):0x%x\n", usb_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(INT_SUSPEND, ®->gintsts);
|
|
|
|
|
|
|
|
if (dev->gadget.speed != USB_SPEED_UNKNOWN
|
|
|
|
&& dev->driver) {
|
|
|
|
if (dev->driver->suspend)
|
|
|
|
dev->driver->suspend(&dev->gadget);
|
2019-04-17 14:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_OTG) {
|
|
|
|
gotgint = readl(®->gotgint);
|
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\tOTG interrupt: (GOTGINT):0x%x\n", gotgint);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2019-04-17 14:46:13 +00:00
|
|
|
if (gotgint & GOTGINT_SES_END_DET) {
|
|
|
|
debug_cond(DEBUG_ISR, "\t\tSession End Detected\n");
|
|
|
|
/* Let gadget detect disconnected state */
|
2011-10-27 08:36:46 +00:00
|
|
|
if (dev->driver->disconnect) {
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
dev->driver->disconnect(&dev->gadget);
|
|
|
|
spin_lock_irqsave(&dev->lock, flags);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 14:46:13 +00:00
|
|
|
writel(gotgint, ®->gotgint);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_RESUME) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR, "\tResume interrupt\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(INT_RESUME, ®->gintsts);
|
|
|
|
|
|
|
|
if (dev->gadget.speed != USB_SPEED_UNKNOWN
|
|
|
|
&& dev->driver
|
|
|
|
&& dev->driver->resume) {
|
|
|
|
|
|
|
|
dev->driver->resume(&dev->gadget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_RESET) {
|
|
|
|
usb_status = readl(®->gotgctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\tReset interrupt - (GOTGCTL):0x%x\n", usb_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(INT_RESET, ®->gintsts);
|
|
|
|
|
|
|
|
if ((usb_status & 0xc0000) == (0x3 << 18)) {
|
|
|
|
if (reset_available) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\t\tOTG core got reset (%d)!!\n",
|
|
|
|
reset_available);
|
2014-11-04 03:23:25 +00:00
|
|
|
reconfig_usbd(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
reset_available = 0;
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_pre_setup();
|
2011-10-27 08:36:46 +00:00
|
|
|
} else
|
|
|
|
reset_available = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
reset_available = 1;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_ISR,
|
|
|
|
"\t\tRESET handling skipped\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intr_status & INT_IN_EP)
|
|
|
|
process_ep_in_intr(dev);
|
|
|
|
|
|
|
|
if (intr_status & INT_OUT_EP)
|
|
|
|
process_ep_out_intr(dev);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Queue one request
|
|
|
|
* Kickstart transfer if needed
|
|
|
|
*/
|
2015-12-04 01:17:40 +00:00
|
|
|
static int dwc2_queue(struct usb_ep *_ep, struct usb_request *_req,
|
2011-10-27 08:36:46 +00:00
|
|
|
gfp_t gfp_flags)
|
|
|
|
{
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
u32 ep_num, gintsts;
|
|
|
|
|
2015-12-04 00:51:07 +00:00
|
|
|
req = container_of(_req, struct dwc2_request, req);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (unlikely(!_req || !_req->complete || !_req->buf
|
|
|
|
|| !list_empty(&req->queue))) {
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bad params\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bad ep: %s, %d, %p\n", __func__,
|
2011-10-27 08:36:46 +00:00
|
|
|
ep->ep.name, !ep->desc, _ep);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ep_num = ep_index(ep);
|
|
|
|
dev = ep->dev;
|
|
|
|
if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bogus device state %p\n", __func__, dev->driver);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -ESHUTDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->lock, flags);
|
|
|
|
|
|
|
|
_req->status = -EINPROGRESS;
|
|
|
|
_req->actual = 0;
|
|
|
|
|
|
|
|
/* kickstart this i/o queue? */
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("\n*** %s: %s-%s req = %p, len = %d, buf = %p"
|
2011-10-27 08:36:46 +00:00
|
|
|
"Q empty = %d, stopped = %d\n",
|
|
|
|
__func__, _ep->name, ep_is_in(ep) ? "in" : "out",
|
|
|
|
_req, _req->length, _req->buf,
|
|
|
|
list_empty(&ep->queue), ep->stopped);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
int i, len = _req->length;
|
|
|
|
|
|
|
|
printf("pkt = ");
|
|
|
|
if (len > 64)
|
|
|
|
len = 64;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
printf("%02x", ((u8 *)_req->buf)[i]);
|
|
|
|
if ((i & 7) == 7)
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (list_empty(&ep->queue) && !ep->stopped) {
|
|
|
|
|
|
|
|
if (ep_num == 0) {
|
|
|
|
/* EP0 */
|
|
|
|
list_add_tail(&req->queue, &ep->queue);
|
2015-12-04 00:59:12 +00:00
|
|
|
dwc2_ep0_kick(dev, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
req = 0;
|
|
|
|
|
|
|
|
} else if (ep_is_in(ep)) {
|
|
|
|
gintsts = readl(®->gintsts);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug_cond(DEBUG_IN_EP,
|
2015-12-04 01:44:33 +00:00
|
|
|
"%s: ep_is_in, DWC2_UDC_OTG_GINTSTS=0x%x\n",
|
2012-05-02 11:11:35 +00:00
|
|
|
__func__, gintsts);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
setdma_tx(ep, req);
|
|
|
|
} else {
|
|
|
|
gintsts = readl(®->gintsts);
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
2015-12-04 01:44:33 +00:00
|
|
|
"%s:ep_is_out, DWC2_UDC_OTG_GINTSTS=0x%x\n",
|
2012-05-02 11:11:35 +00:00
|
|
|
__func__, gintsts);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
setdma_rx(ep, req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pio or dma irq handler advances the queue. */
|
|
|
|
if (likely(req != 0))
|
|
|
|
list_add_tail(&req->queue, &ep->queue);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
/* End Point 0 related functions */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
/* return: 0 = still running, 1 = completed, negative = errno */
|
2015-12-04 00:51:07 +00:00
|
|
|
static int write_fifo_ep0(struct dwc2_ep *ep, struct dwc2_request *req)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 max;
|
|
|
|
unsigned count;
|
|
|
|
int is_last;
|
|
|
|
|
|
|
|
max = ep_maxpacket(ep);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s: max = %d\n", __func__, max);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
count = setdma_tx(ep, req);
|
|
|
|
|
|
|
|
/* last packet is usually short (or a zlp) */
|
|
|
|
if (likely(count != max))
|
|
|
|
is_last = 1;
|
|
|
|
else {
|
|
|
|
if (likely(req->req.length != req->req.actual + count)
|
|
|
|
|| req->req.zero)
|
|
|
|
is_last = 0;
|
|
|
|
else
|
|
|
|
is_last = 1;
|
|
|
|
}
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: wrote %s %d bytes%s %d left %p\n", __func__,
|
|
|
|
ep->ep.name, count,
|
|
|
|
is_last ? "/L" : "",
|
|
|
|
req->req.length - req->req.actual - count, req);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* requests complete when all IN data is in the FIFO */
|
|
|
|
if (is_last) {
|
|
|
|
ep->dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-21 21:15:23 +00:00
|
|
|
static int dwc2_fifo_read(struct dwc2_ep *ep, void *cp, int max)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2014-02-05 09:10:44 +00:00
|
|
|
invalidate_dcache_range((unsigned long)cp, (unsigned long)cp +
|
|
|
|
ROUND(max, CONFIG_SYS_CACHELINE_SIZE));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
2014-02-05 09:10:44 +00:00
|
|
|
"%s: bytes=%d, ep_index=%d 0x%p\n", __func__,
|
|
|
|
max, ep_index(ep), cp);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2014-02-05 09:10:44 +00:00
|
|
|
return max;
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* udc_set_address - set the USB address for this device
|
|
|
|
* @address:
|
|
|
|
*
|
|
|
|
* Called from control endpoint function
|
|
|
|
* after it decodes a set address setup packet.
|
|
|
|
*/
|
2015-12-03 23:57:58 +00:00
|
|
|
static void udc_set_address(struct dwc2_udc *dev, unsigned char address)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 ctrl = readl(®->dcfg);
|
|
|
|
writel(DEVICE_ADDRESS(address) | ctrl, ®->dcfg);
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: USB OTG 2.0 Device address=%d, DCFG=0x%x\n",
|
|
|
|
__func__, address, readl(®->dcfg));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
dev->usb_address = address;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static inline void dwc2_udc_ep0_set_stall(struct dwc2_ep *ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev;
|
2011-10-27 08:36:46 +00:00
|
|
|
u32 ep_ctrl = 0;
|
|
|
|
|
|
|
|
dev = ep->dev;
|
|
|
|
ep_ctrl = readl(®->in_endp[EP0_CON].diepctl);
|
|
|
|
|
|
|
|
/* set the disable and stall bits */
|
|
|
|
if (ep_ctrl & DEPCTL_EPENA)
|
|
|
|
ep_ctrl |= DEPCTL_EPDIS;
|
|
|
|
|
|
|
|
ep_ctrl |= DEPCTL_STALL;
|
|
|
|
|
|
|
|
writel(ep_ctrl, ®->in_endp[EP0_CON].diepctl);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: set ep%d stall, DIEPCTL0 = 0x%p\n",
|
|
|
|
__func__, ep_index(ep), ®->in_endp[EP0_CON].diepctl);
|
2011-10-27 08:36:46 +00:00
|
|
|
/*
|
|
|
|
* The application can only set this bit, and the core clears it,
|
|
|
|
* when a SETUP token is received for this endpoint
|
|
|
|
*/
|
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_pre_setup();
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 00:59:12 +00:00
|
|
|
static void dwc2_ep0_read(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[0];
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (!list_empty(&ep->queue)) {
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
} else {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: ---> BUG\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
BUG();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: req = %p, req.length = 0x%x, req.actual = 0x%x\n",
|
|
|
|
__func__, req, req->req.length, req->req.actual);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (req->req.length == 0) {
|
|
|
|
/* zlp for Set_configuration, Set_interface,
|
|
|
|
* or Bulk-Only mass storge reset */
|
|
|
|
|
|
|
|
ep->len = 0;
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: req.length = 0, bRequest = %d\n",
|
|
|
|
__func__, usb_ctrl->bRequest);
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
setdma_rx(ep, req);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DATA_STATE_XMIT
|
|
|
|
*/
|
2015-12-04 00:59:12 +00:00
|
|
|
static int dwc2_ep0_write(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[0];
|
2011-10-27 08:36:46 +00:00
|
|
|
int ret, need_zlp = 0;
|
|
|
|
|
|
|
|
if (list_empty(&ep->queue))
|
|
|
|
req = 0;
|
|
|
|
else
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (!req) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0, "%s: NULL REQ\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: req = %p, req.length = 0x%x, req.actual = 0x%x\n",
|
|
|
|
__func__, req, req->req.length, req->req.actual);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (req->req.length - req->req.actual == ep0_fifo_size) {
|
|
|
|
/* Next write will end with the packet size, */
|
|
|
|
/* so we need Zero-length-packet */
|
|
|
|
need_zlp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = write_fifo_ep0(ep, req);
|
|
|
|
|
|
|
|
if ((ret == 1) && !need_zlp) {
|
|
|
|
/* Last packet */
|
|
|
|
dev->ep0state = WAIT_FOR_COMPLETE;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: finished, waiting for status\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
dev->ep0state = DATA_STATE_XMIT;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: not finished\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static int dwc2_udc_get_status(struct dwc2_udc *dev,
|
2011-10-27 08:36:46 +00:00
|
|
|
struct usb_ctrlrequest *crq)
|
|
|
|
{
|
|
|
|
u8 ep_num = crq->wIndex & 0x7F;
|
2014-02-05 09:10:44 +00:00
|
|
|
u16 g_status = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
u32 ep_ctrl;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** USB_REQ_GET_STATUS\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
printf("crq->brequest:0x%x\n", crq->bRequestType & USB_RECIP_MASK);
|
|
|
|
switch (crq->bRequestType & USB_RECIP_MASK) {
|
|
|
|
case USB_RECIP_INTERFACE:
|
|
|
|
g_status = 0;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tGET_STATUS:USB_RECIP_INTERFACE, g_stauts = %d\n",
|
|
|
|
g_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_RECIP_DEVICE:
|
|
|
|
g_status = 0x1; /* Self powered */
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tGET_STATUS: USB_RECIP_DEVICE, g_stauts = %d\n",
|
|
|
|
g_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_RECIP_ENDPOINT:
|
|
|
|
if (crq->wLength > 2) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tGET_STATUS:Not support EP or wLength\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_status = dev->ep[ep_num].stopped;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tGET_STATUS: USB_RECIP_ENDPOINT, g_stauts = %d\n",
|
|
|
|
g_status);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-02-05 09:10:44 +00:00
|
|
|
memcpy(usb_ctrl, &g_status, sizeof(g_status));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2014-02-05 09:10:44 +00:00
|
|
|
flush_dcache_range((unsigned long) usb_ctrl,
|
|
|
|
(unsigned long) usb_ctrl +
|
|
|
|
ROUND(sizeof(g_status), CONFIG_SYS_CACHELINE_SIZE));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2019-12-02 11:11:17 +00:00
|
|
|
writel(phys_to_bus(usb_ctrl_dma_addr), ®->in_endp[EP0_CON].diepdma);
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(DIEPT_SIZ_PKT_CNT(1) | DIEPT_SIZ_XFER_SIZE(2),
|
|
|
|
®->in_endp[EP0_CON].dieptsiz);
|
|
|
|
|
|
|
|
ep_ctrl = readl(®->in_endp[EP0_CON].diepctl);
|
|
|
|
writel(ep_ctrl|DEPCTL_EPENA|DEPCTL_CNAK,
|
|
|
|
®->in_endp[EP0_CON].diepctl);
|
|
|
|
dev->ep0state = WAIT_FOR_NULL_COMPLETE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static void dwc2_udc_set_nak(struct dwc2_ep *ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u8 ep_num;
|
|
|
|
u32 ep_ctrl = 0;
|
|
|
|
|
|
|
|
ep_num = ep_index(ep);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: ep_num = %d, ep_type = %d\n", __func__, ep_num, ep->ep_type);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (ep_is_in(ep)) {
|
|
|
|
ep_ctrl = readl(®->in_endp[ep_num].diepctl);
|
|
|
|
ep_ctrl |= DEPCTL_SNAK;
|
|
|
|
writel(ep_ctrl, ®->in_endp[ep_num].diepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: set NAK, DIEPCTL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, readl(®->in_endp[ep_num].diepctl));
|
|
|
|
} else {
|
|
|
|
ep_ctrl = readl(®->out_endp[ep_num].doepctl);
|
|
|
|
ep_ctrl |= DEPCTL_SNAK;
|
|
|
|
writel(ep_ctrl, ®->out_endp[ep_num].doepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: set NAK, DOEPCTL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, readl(®->out_endp[ep_num].doepctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static void dwc2_udc_ep_set_stall(struct dwc2_ep *ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u8 ep_num;
|
|
|
|
u32 ep_ctrl = 0;
|
|
|
|
|
|
|
|
ep_num = ep_index(ep);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: ep_num = %d, ep_type = %d\n", __func__, ep_num, ep->ep_type);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (ep_is_in(ep)) {
|
|
|
|
ep_ctrl = readl(®->in_endp[ep_num].diepctl);
|
|
|
|
|
|
|
|
/* set the disable and stall bits */
|
|
|
|
if (ep_ctrl & DEPCTL_EPENA)
|
|
|
|
ep_ctrl |= DEPCTL_EPDIS;
|
|
|
|
|
|
|
|
ep_ctrl |= DEPCTL_STALL;
|
|
|
|
|
|
|
|
writel(ep_ctrl, ®->in_endp[ep_num].diepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: set stall, DIEPCTL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, readl(®->in_endp[ep_num].diepctl));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ep_ctrl = readl(®->out_endp[ep_num].doepctl);
|
|
|
|
|
|
|
|
/* set the stall bit */
|
|
|
|
ep_ctrl |= DEPCTL_STALL;
|
|
|
|
|
|
|
|
writel(ep_ctrl, ®->out_endp[ep_num].doepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: set stall, DOEPCTL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, readl(®->out_endp[ep_num].doepctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static void dwc2_udc_ep_clear_stall(struct dwc2_ep *ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u8 ep_num;
|
|
|
|
u32 ep_ctrl = 0;
|
|
|
|
|
|
|
|
ep_num = ep_index(ep);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: ep_num = %d, ep_type = %d\n", __func__, ep_num, ep->ep_type);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (ep_is_in(ep)) {
|
|
|
|
ep_ctrl = readl(®->in_endp[ep_num].diepctl);
|
|
|
|
|
|
|
|
/* clear stall bit */
|
|
|
|
ep_ctrl &= ~DEPCTL_STALL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* USB Spec 9.4.5: For endpoints using data toggle, regardless
|
|
|
|
* of whether an endpoint has the Halt feature set, a
|
|
|
|
* ClearFeature(ENDPOINT_HALT) request always results in the
|
|
|
|
* data toggle being reinitialized to DATA0.
|
|
|
|
*/
|
|
|
|
if (ep->bmAttributes == USB_ENDPOINT_XFER_INT
|
|
|
|
|| ep->bmAttributes == USB_ENDPOINT_XFER_BULK) {
|
|
|
|
ep_ctrl |= DEPCTL_SETD0PID; /* DATA0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(ep_ctrl, ®->in_endp[ep_num].diepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: cleared stall, DIEPCTL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, readl(®->in_endp[ep_num].diepctl));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ep_ctrl = readl(®->out_endp[ep_num].doepctl);
|
|
|
|
|
|
|
|
/* clear stall bit */
|
|
|
|
ep_ctrl &= ~DEPCTL_STALL;
|
|
|
|
|
|
|
|
if (ep->bmAttributes == USB_ENDPOINT_XFER_INT
|
|
|
|
|| ep->bmAttributes == USB_ENDPOINT_XFER_BULK) {
|
|
|
|
ep_ctrl |= DEPCTL_SETD0PID; /* DATA0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(ep_ctrl, ®->out_endp[ep_num].doepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: cleared stall, DOEPCTL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, readl(®->out_endp[ep_num].doepctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static int dwc2_udc_set_halt(struct usb_ep *_ep, int value)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
u8 ep_num;
|
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
ep_num = ep_index(ep);
|
|
|
|
|
|
|
|
if (unlikely(!_ep || !ep->desc || ep_num == EP0_CON ||
|
|
|
|
ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC)) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s bad ep or descriptor\n", __func__, ep->ep.name);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to halt IN ep will fail if any transfer requests
|
|
|
|
* are still queue */
|
|
|
|
if (value && ep_is_in(ep) && !list_empty(&ep->queue)) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s queue not empty, req = %p\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep->ep.name,
|
2015-12-04 00:51:07 +00:00
|
|
|
list_entry(ep->queue.next, struct dwc2_request, queue));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = ep->dev;
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: ep_num = %d, value = %d\n", __func__, ep_num, value);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->lock, flags);
|
|
|
|
|
|
|
|
if (value == 0) {
|
|
|
|
ep->stopped = 0;
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep_clear_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
} else {
|
|
|
|
if (ep_num == 0)
|
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
|
|
|
ep->stopped = 1;
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static void dwc2_udc_ep_activate(struct dwc2_ep *ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u8 ep_num;
|
|
|
|
u32 ep_ctrl = 0, daintmsk = 0;
|
|
|
|
|
|
|
|
ep_num = ep_index(ep);
|
|
|
|
|
|
|
|
/* Read DEPCTLn register */
|
|
|
|
if (ep_is_in(ep)) {
|
|
|
|
ep_ctrl = readl(®->in_endp[ep_num].diepctl);
|
|
|
|
daintmsk = 1 << ep_num;
|
|
|
|
} else {
|
|
|
|
ep_ctrl = readl(®->out_endp[ep_num].doepctl);
|
|
|
|
daintmsk = (1 << ep_num) << DAINT_OUT_BIT;
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: EPCTRL%d = 0x%x, ep_is_in = %d\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, ep_ctrl, ep_is_in(ep));
|
|
|
|
|
|
|
|
/* If the EP is already active don't change the EP Control
|
|
|
|
* register. */
|
|
|
|
if (!(ep_ctrl & DEPCTL_USBACTEP)) {
|
|
|
|
ep_ctrl = (ep_ctrl & ~DEPCTL_TYPE_MASK) |
|
|
|
|
(ep->bmAttributes << DEPCTL_TYPE_BIT);
|
|
|
|
ep_ctrl = (ep_ctrl & ~DEPCTL_MPS_MASK) |
|
|
|
|
(ep->ep.maxpacket << DEPCTL_MPS_BIT);
|
|
|
|
ep_ctrl |= (DEPCTL_SETD0PID | DEPCTL_USBACTEP | DEPCTL_SNAK);
|
|
|
|
|
|
|
|
if (ep_is_in(ep)) {
|
|
|
|
writel(ep_ctrl, ®->in_endp[ep_num].diepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: USB Ative EP%d, DIEPCTRL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, ep_num,
|
|
|
|
readl(®->in_endp[ep_num].diepctl));
|
|
|
|
} else {
|
|
|
|
writel(ep_ctrl, ®->out_endp[ep_num].doepctl);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: USB Ative EP%d, DOEPCTRL%d = 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num, ep_num,
|
|
|
|
readl(®->out_endp[ep_num].doepctl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unmask EP Interrtupt */
|
|
|
|
writel(readl(®->daintmsk)|daintmsk, ®->daintmsk);
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: DAINTMSK = 0x%x\n", __func__, readl(®->daintmsk));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static int dwc2_udc_clear_feature(struct usb_ep *_ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev;
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2011-10-27 08:36:46 +00:00
|
|
|
u8 ep_num;
|
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
ep_num = ep_index(ep);
|
|
|
|
|
|
|
|
dev = ep->dev;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: ep_num = %d, is_in = %d, clear_feature_flag = %d\n",
|
|
|
|
__func__, ep_num, ep_is_in(ep), clear_feature_flag);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (usb_ctrl->wLength != 0) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tCLEAR_FEATURE: wLength is not zero.....\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (usb_ctrl->bRequestType & USB_RECIP_MASK) {
|
|
|
|
case USB_RECIP_DEVICE:
|
|
|
|
switch (usb_ctrl->wValue) {
|
|
|
|
case USB_DEVICE_REMOTE_WAKEUP:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tOFF:USB_DEVICE_REMOTE_WAKEUP\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_DEVICE_TEST_MODE:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tCLEAR_FEATURE: USB_DEVICE_TEST_MODE\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
/** @todo Add CLEAR_FEATURE for TEST modes. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_RECIP_ENDPOINT:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tCLEAR_FEATURE:USB_RECIP_ENDPOINT, wValue = %d\n",
|
|
|
|
usb_ctrl->wValue);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (usb_ctrl->wValue == USB_ENDPOINT_HALT) {
|
|
|
|
if (ep_num == 0) {
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep_clear_stall(ep);
|
|
|
|
dwc2_udc_ep_activate(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
ep->stopped = 0;
|
|
|
|
|
|
|
|
clear_feature_num = ep_num;
|
|
|
|
clear_feature_flag = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static int dwc2_udc_set_feature(struct usb_ep *_ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev;
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2011-10-27 08:36:46 +00:00
|
|
|
u8 ep_num;
|
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
ep_num = ep_index(ep);
|
|
|
|
dev = ep->dev;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** USB_REQ_SET_FEATURE , ep_num = %d\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep_num);
|
|
|
|
|
|
|
|
if (usb_ctrl->wLength != 0) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET_FEATURE: wLength is not zero.....\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (usb_ctrl->bRequestType & USB_RECIP_MASK) {
|
|
|
|
case USB_RECIP_DEVICE:
|
|
|
|
switch (usb_ctrl->wValue) {
|
|
|
|
case USB_DEVICE_REMOTE_WAKEUP:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET_FEATURE:USB_DEVICE_REMOTE_WAKEUP\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
case USB_DEVICE_B_HNP_ENABLE:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_DEVICE_A_HNP_SUPPORT:
|
|
|
|
/* RH port supports HNP */
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET_FEATURE:USB_DEVICE_A_HNP_SUPPORT\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_DEVICE_A_ALT_HNP_SUPPORT:
|
|
|
|
/* other RH port does */
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case USB_RECIP_INTERFACE:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET_FEATURE: USB_RECIP_INTERFACE\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_RECIP_ENDPOINT:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tSET_FEATURE: USB_RECIP_ENDPOINT\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
if (usb_ctrl->wValue == USB_ENDPOINT_HALT) {
|
|
|
|
if (ep_num == 0) {
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ep->stopped = 1;
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_zlp(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WAIT_FOR_SETUP (OUT_PKT_RDY)
|
|
|
|
*/
|
2015-12-04 00:59:12 +00:00
|
|
|
static void dwc2_ep0_setup(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[0];
|
2011-12-19 04:20:35 +00:00
|
|
|
int i;
|
2011-10-27 08:36:46 +00:00
|
|
|
u8 ep_num;
|
|
|
|
|
|
|
|
/* Nuke all previous transfers */
|
|
|
|
nuke(ep, -EPROTO);
|
|
|
|
|
|
|
|
/* read control req from fifo (8 bytes) */
|
2019-11-21 21:15:23 +00:00
|
|
|
dwc2_fifo_read(ep, usb_ctrl, 8);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: bRequestType = 0x%x(%s), bRequest = 0x%x"
|
|
|
|
"\twLength = 0x%x, wValue = 0x%x, wIndex= 0x%x\n",
|
|
|
|
__func__, usb_ctrl->bRequestType,
|
|
|
|
(usb_ctrl->bRequestType & USB_DIR_IN) ? "IN" : "OUT",
|
|
|
|
usb_ctrl->bRequest,
|
|
|
|
usb_ctrl->wLength, usb_ctrl->wValue, usb_ctrl->wIndex);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
int i, len = sizeof(*usb_ctrl);
|
2011-12-19 04:20:35 +00:00
|
|
|
char *p = (char *)usb_ctrl;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
printf("pkt = ");
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
printf("%02x", ((u8 *)p)[i]);
|
|
|
|
if ((i & 7) == 7)
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (usb_ctrl->bRequest == GET_MAX_LUN_REQUEST &&
|
|
|
|
usb_ctrl->wLength != 1) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\t%s:GET_MAX_LUN_REQUEST:invalid",
|
|
|
|
__func__);
|
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"wLength = %d, setup returned\n",
|
|
|
|
usb_ctrl->wLength);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else if (usb_ctrl->bRequest == BOT_RESET_REQUEST &&
|
|
|
|
usb_ctrl->wLength != 0) {
|
|
|
|
/* Bulk-Only *mass storge reset of class-specific request */
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s:BOT Rest:invalid wLength =%d, setup returned\n",
|
|
|
|
__func__, usb_ctrl->wLength);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set direction of EP0 */
|
|
|
|
if (likely(usb_ctrl->bRequestType & USB_DIR_IN)) {
|
|
|
|
ep->bEndpointAddress |= USB_DIR_IN;
|
|
|
|
} else {
|
|
|
|
ep->bEndpointAddress &= ~USB_DIR_IN;
|
|
|
|
}
|
|
|
|
/* cope with automagic for some standard requests. */
|
|
|
|
dev->req_std = (usb_ctrl->bRequestType & USB_TYPE_MASK)
|
|
|
|
== USB_TYPE_STANDARD;
|
2012-03-12 22:08:06 +00:00
|
|
|
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->req_pending = 1;
|
|
|
|
|
|
|
|
/* Handle some SETUP packets ourselves */
|
|
|
|
if (dev->req_std) {
|
|
|
|
switch (usb_ctrl->bRequest) {
|
|
|
|
case USB_REQ_SET_ADDRESS:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** USB_REQ_SET_ADDRESS (%d)\n",
|
|
|
|
__func__, usb_ctrl->wValue);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (usb_ctrl->bRequestType
|
|
|
|
!= (USB_TYPE_STANDARD | USB_RECIP_DEVICE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
udc_set_address(dev, usb_ctrl->wValue);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case USB_REQ_SET_CONFIGURATION:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"=====================================\n");
|
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: USB_REQ_SET_CONFIGURATION (%d)\n",
|
|
|
|
__func__, usb_ctrl->wValue);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-03-12 22:08:06 +00:00
|
|
|
if (usb_ctrl->bRequestType == USB_RECIP_DEVICE)
|
2011-10-27 08:36:46 +00:00
|
|
|
reset_available = 1;
|
2012-03-12 22:08:06 +00:00
|
|
|
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_GET_DESCRIPTOR:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** USB_REQ_GET_DESCRIPTOR\n",
|
|
|
|
__func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_SET_INTERFACE:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** USB_REQ_SET_INTERFACE (%d)\n",
|
|
|
|
__func__, usb_ctrl->wValue);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-03-12 22:08:06 +00:00
|
|
|
if (usb_ctrl->bRequestType == USB_RECIP_INTERFACE)
|
2011-10-27 08:36:46 +00:00
|
|
|
reset_available = 1;
|
2012-03-12 22:08:06 +00:00
|
|
|
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_GET_CONFIGURATION:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** USB_REQ_GET_CONFIGURATION\n",
|
|
|
|
__func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_GET_STATUS:
|
2015-12-04 01:03:45 +00:00
|
|
|
if (!dwc2_udc_get_status(dev, usb_ctrl))
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_CLEAR_FEATURE:
|
|
|
|
ep_num = usb_ctrl->wIndex & 0x7f;
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
if (!dwc2_udc_clear_feature(&dev->ep[ep_num].ep))
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_SET_FEATURE:
|
|
|
|
ep_num = usb_ctrl->wIndex & 0x7f;
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
if (!dwc2_udc_set_feature(&dev->ep[ep_num].ep))
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: *** Default of usb_ctrl->bRequest=0x%x"
|
|
|
|
"happened.\n", __func__, usb_ctrl->bRequest);
|
2011-10-27 08:36:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (likely(dev->driver)) {
|
|
|
|
/* device-2-host (IN) or no data setup command,
|
|
|
|
* process immediately */
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s:usb_ctrlreq will be passed to fsg_setup()\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__);
|
|
|
|
|
|
|
|
spin_unlock(&dev->lock);
|
|
|
|
i = dev->driver->setup(&dev->gadget, usb_ctrl);
|
|
|
|
spin_lock(&dev->lock);
|
|
|
|
|
|
|
|
if (i < 0) {
|
|
|
|
/* setup processing failed, force stall */
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep0_set_stall(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tdev->driver->setup failed (%d),"
|
2011-10-27 08:36:46 +00:00
|
|
|
" bRequest = %d\n",
|
|
|
|
i, usb_ctrl->bRequest);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (dev->req_pending) {
|
|
|
|
dev->req_pending = 0;
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tdev->req_pending...\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"\tep0state = %s\n", state_names[dev->ep0state]);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle ep0 interrupt
|
|
|
|
*/
|
2015-12-04 01:17:40 +00:00
|
|
|
static void dwc2_handle_ep0(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
if (dev->ep0state == WAIT_FOR_SETUP) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"%s: WAIT_FOR_SETUP\n", __func__);
|
2015-12-04 00:59:12 +00:00
|
|
|
dwc2_ep0_setup(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
} else {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_OUT_EP != 0,
|
|
|
|
"%s: strange state!!(state = %s)\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, state_names[dev->ep0state]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:59:12 +00:00
|
|
|
static void dwc2_ep0_kick(struct dwc2_udc *dev, struct dwc2_ep *ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_EP0 != 0,
|
|
|
|
"%s: ep_is_in = %d\n", __func__, ep_is_in(ep));
|
2011-10-27 08:36:46 +00:00
|
|
|
if (ep_is_in(ep)) {
|
|
|
|
dev->ep0state = DATA_STATE_XMIT;
|
2015-12-04 00:59:12 +00:00
|
|
|
dwc2_ep0_write(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
dev->ep0state = DATA_STATE_RECV;
|
2015-12-04 00:59:12 +00:00
|
|
|
dwc2_ep0_read(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
}
|