From: Dinh Nguyen <dinguyen@xxxxxxxxxx> Update gadget.c to use the dwc2_hsotg and new placement of the gadget data structure that has been moved into the common structure. Signed-off-by: Dinh Nguyen <dinguyen@xxxxxxxxxx> --- drivers/usb/dwc2/gadget.c | 1066 ++++++++++++++++++++++----------------------- 1 file changed, 531 insertions(+), 535 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index f3c56a2..171ed28 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -38,6 +38,7 @@ #include <linux/platform_data/s3c-hsotg.h> #include "core.h" +#include "hw.h" /* conversion functions */ static inline struct s3c_hsotg_req *our_req(struct usb_request *req) @@ -50,9 +51,9 @@ static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep) return container_of(ep, struct s3c_hsotg_ep, ep); } -static inline struct s3c_hsotg *to_hsotg(struct usb_gadget *gadget) +static inline struct dwc2_hsotg *to_hsotg(struct usb_gadget *gadget) { - return container_of(gadget, struct s3c_hsotg, gadget); + return container_of(gadget, struct dwc2_hsotg, gadget); } static inline void __orr32(void __iomem *ptr, u32 val) @@ -65,9 +66,6 @@ static inline void __bic32(void __iomem *ptr, u32 val) writel(readl(ptr) & ~val, ptr); } -/* forward decleration of functions */ -static void s3c_hsotg_dump(struct s3c_hsotg *hsotg); - /** * using_dma - return the DMA status of the driver. * @hsotg: The driver state. @@ -97,16 +95,16 @@ static inline bool using_dma(struct s3c_hsotg *hsotg) * @hsotg: The device state * @ints: A bitmask of the interrupts to enable */ -static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) +void s3c_hsotg_en_gsint(struct dwc2_hsotg *dwc2, u32 ints) { - u32 gsintmsk = readl(hsotg->regs + GINTMSK); + u32 gsintmsk = readl(dwc2->regs + GINTMSK); u32 new_gsintmsk; new_gsintmsk = gsintmsk | ints; if (new_gsintmsk != gsintmsk) { - dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); - writel(new_gsintmsk, hsotg->regs + GINTMSK); + dev_dbg(dwc2->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); + writel(new_gsintmsk, dwc2->regs + GINTMSK); } } @@ -115,15 +113,15 @@ static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) * @hsotg: The device state * @ints: A bitmask of the interrupts to enable */ -static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints) +void s3c_hsotg_disable_gsint(struct dwc2_hsotg *dwc2, u32 ints) { - u32 gsintmsk = readl(hsotg->regs + GINTMSK); + u32 gsintmsk = readl(dwc2->regs + GINTMSK); u32 new_gsintmsk; new_gsintmsk = gsintmsk & ~ints; if (new_gsintmsk != gsintmsk) - writel(new_gsintmsk, hsotg->regs + GINTMSK); + writel(new_gsintmsk, dwc2->regs + GINTMSK); } /** @@ -136,7 +134,7 @@ static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints) * Set or clear the mask for an individual endpoint's interrupt * request. */ -static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg, +static void s3c_hsotg_ctrl_epint(struct dwc2_hsotg *dwc2, unsigned int ep, unsigned int dir_in, unsigned int en) { @@ -148,12 +146,12 @@ static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg, bit <<= 16; local_irq_save(flags); - daint = readl(hsotg->regs + DAINTMSK); + daint = readl(dwc2->regs + DAINTMSK); if (en) daint |= bit; else daint &= ~bit; - writel(daint, hsotg->regs + DAINTMSK); + writel(daint, dwc2->regs + DAINTMSK); local_irq_restore(flags); } @@ -161,7 +159,7 @@ static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg, * s3c_hsotg_init_fifo - initialise non-periodic FIFOs * @hsotg: The device instance. */ -static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) +static void s3c_hsotg_init_fifo(struct dwc2_hsotg *dwc2) { unsigned int ep; unsigned int addr; @@ -171,9 +169,9 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) /* set FIFO sizes to 2048/1024 */ - writel(2048, hsotg->regs + GRXFSIZ); + writel(2048, dwc2->regs + GRXFSIZ); writel((2048 << FIFOSIZE_STARTADDR_SHIFT) | - (1024 << FIFOSIZE_DEPTH_SHIFT), hsotg->regs + GNPTXFSIZ); + (1024 << FIFOSIZE_DEPTH_SHIFT), dwc2->regs + GNPTXFSIZ); /* * arange all the rest of the TX FIFOs, as some versions of this @@ -196,7 +194,7 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) val |= size << FIFOSIZE_DEPTH_SHIFT; addr += size; - writel(val, hsotg->regs + DPTXFSIZN(ep)); + writel(val, dwc2->regs + DPTXFSIZN(ep)); } /* @@ -205,18 +203,18 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) */ writel(GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | - GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL); + GRSTCTL_RXFFLSH, dwc2->regs + GRSTCTL); /* wait until the fifos are both flushed */ timeout = 100; while (1) { - val = readl(hsotg->regs + GRSTCTL); + val = readl(dwc2->regs + GRSTCTL); if ((val & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH)) == 0) break; if (--timeout == 0) { - dev_err(hsotg->dev, + dev_err(dwc2->dev, "%s: timeout flushing fifos (GRSTCTL=%08x)\n", __func__, val); } @@ -224,7 +222,7 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) udelay(1); } - dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout); + dev_dbg(dwc2->dev, "FIFOs reset, timeout at %d\n", timeout); } /** @@ -268,7 +266,7 @@ static inline int is_ep_periodic(struct s3c_hsotg_ep *hs_ep) * This is the reverse of s3c_hsotg_map_dma(), called for the completion * of a request to ensure the buffer is ready for access by the caller. */ -static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, +static void s3c_hsotg_unmap_dma(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep, struct s3c_hsotg_req *hs_req) { @@ -278,7 +276,7 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, if (hs_req->req.length == 0) return; - usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); + usb_gadget_unmap_request(&dwc2->gadget, req, hs_ep->dir_in); } /** @@ -297,12 +295,12 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, * * This routine is only needed for PIO */ -static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, +static int s3c_hsotg_write_fifo(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep, struct s3c_hsotg_req *hs_req) { bool periodic = is_ep_periodic(hs_ep); - u32 gnptxsts = readl(hsotg->regs + GNPTXSTS); + u32 gnptxsts = readl(dwc2->regs + GNPTXSTS); int buf_pos = hs_req->req.actual; int to_write = hs_ep->size_loaded; void *data; @@ -316,8 +314,8 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, if (to_write == 0) return 0; - if (periodic && !hsotg->dedicated_fifos) { - u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); + if (periodic && !dwc2->s3c_hsotg->dedicated_fifos) { + u32 epsize = readl(dwc2->regs + DIEPTSIZ(hs_ep->index)); int size_left; int size_done; @@ -333,11 +331,11 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, * previous data has been completely sent. */ if (hs_ep->fifo_load != 0) { - s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); + s3c_hsotg_en_gsint(dwc2, GINTSTS_PTXFEMP); return -ENOSPC; } - dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", + dev_dbg(dwc2->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", __func__, size_left, hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size); @@ -346,29 +344,29 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, /* how much data is left in the fifo */ can_write = hs_ep->fifo_load - size_done; - dev_dbg(hsotg->dev, "%s: => can_write1=%d\n", + dev_dbg(dwc2->dev, "%s: => can_write1=%d\n", __func__, can_write); can_write = hs_ep->fifo_size - can_write; - dev_dbg(hsotg->dev, "%s: => can_write2=%d\n", + dev_dbg(dwc2->dev, "%s: => can_write2=%d\n", __func__, can_write); if (can_write <= 0) { - s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); + s3c_hsotg_en_gsint(dwc2, GINTSTS_PTXFEMP); return -ENOSPC; } - } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { - can_write = readl(hsotg->regs + DTXFSTS(hs_ep->index)); + } else if (dwc2->s3c_hsotg->dedicated_fifos && hs_ep->index != 0) { + can_write = readl(dwc2->regs + DTXFSTS(hs_ep->index)); can_write &= 0xffff; can_write *= 4; } else { if (GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(gnptxsts) == 0) { - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "%s: no queue slots available (0x%08x)\n", __func__, gnptxsts); - s3c_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); + s3c_hsotg_en_gsint(dwc2, GINTSTS_NPTXFEMP); return -ENOSPC; } @@ -378,7 +376,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, max_transfer = hs_ep->ep.maxpacket * hs_ep->mc; - dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", + dev_dbg(dwc2->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", __func__, gnptxsts, can_write, to_write, max_transfer); /* @@ -398,8 +396,8 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, to_write = max_transfer; /* it's needed only when we do not use dedicated fifos */ - if (!hsotg->dedicated_fifos) - s3c_hsotg_en_gsint(hsotg, + if (!dwc2->s3c_hsotg->dedicated_fifos) + s3c_hsotg_en_gsint(dwc2, periodic ? GINTSTS_PTXFEMP : GINTSTS_NPTXFEMP); } @@ -427,13 +425,13 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, */ /* it's needed only when we do not use dedicated fifos */ - if (!hsotg->dedicated_fifos) - s3c_hsotg_en_gsint(hsotg, + if (!dwc2->s3c_hsotg->dedicated_fifos) + s3c_hsotg_en_gsint(dwc2, periodic ? GINTSTS_PTXFEMP : GINTSTS_NPTXFEMP); } - dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", + dev_dbg(dwc2->dev, "write %d/%d, can_write %d, done %d\n", to_write, hs_req->req.length, can_write, buf_pos); if (to_write <= 0) @@ -448,7 +446,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, to_write = DIV_ROUND_UP(to_write, 4); data = hs_req->req.buf + buf_pos; - iowrite32_rep(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); + iowrite32_rep(dwc2->regs + EPFIFO(hs_ep->index), data, to_write); return (to_write >= can_write) ? -ENOSPC : 0; } @@ -502,7 +500,7 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) * Start the given request running by setting the endpoint registers * appropriately, and writing any data to the FIFOs. */ -static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, +static void s3c_hsotg_start_req(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep, struct s3c_hsotg_req *hs_req, bool continuing) @@ -520,11 +518,11 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, if (index != 0) { if (hs_ep->req && !continuing) { - dev_err(hsotg->dev, "%s: active request\n", __func__); + dev_err(dwc2->dev, "%s: active request\n", __func__); WARN_ON(1); return; } else if (hs_ep->req != hs_req && continuing) { - dev_err(hsotg->dev, + dev_err(dwc2->dev, "%s: continue different req\n", __func__); WARN_ON(1); return; @@ -534,23 +532,23 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); epsize_reg = dir_in ? DIEPTSIZ(index) : DOEPTSIZ(index); - dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", - __func__, readl(hsotg->regs + epctrl_reg), index, + dev_dbg(dwc2->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", + __func__, readl(dwc2->regs + epctrl_reg), index, hs_ep->dir_in ? "in" : "out"); /* If endpoint is stalled, we will restart request later */ - ctrl = readl(hsotg->regs + epctrl_reg); + ctrl = readl(dwc2->regs + epctrl_reg); if (ctrl & DXEPCTL_STALL) { - dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); + dev_warn(dwc2->dev, "%s: ep%d is stalled\n", __func__, index); return; } length = ureq->length - ureq->actual; - dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", + dev_dbg(dwc2->dev, "ureq->length:%d ureq->actual:%d\n", ureq->length, ureq->actual); if (0) - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "REQ buf %p len %d dma %pad noi=%d zp=%d snok=%d\n", ureq->buf, length, &ureq->dma, ureq->no_interrupt, ureq->zero, ureq->short_not_ok); @@ -559,7 +557,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, if (length > maxreq) { int round = maxreq % hs_ep->ep.maxpacket; - dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n", + dev_dbg(dwc2->dev, "%s: length %d, max-req %d, r %d\n", __func__, length, maxreq, round); /* round down to multiple of packets */ @@ -575,7 +573,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, packets = 1; /* send one packet if length is zero. */ if (hs_ep->isochronous && length > (hs_ep->mc * hs_ep->ep.maxpacket)) { - dev_err(hsotg->dev, "req length > maxpacket*mc\n"); + dev_err(dwc2->dev, "req length > maxpacket*mc\n"); return; } @@ -600,16 +598,16 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, epsize |= DXEPTSIZ_PKTCNT(packets); epsize |= DXEPTSIZ_XFERSIZE(length); - dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", + dev_dbg(dwc2->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", __func__, packets, length, ureq->length, epsize, epsize_reg); /* store the request as the current one we're doing */ hs_ep->req = hs_req; /* write size / packets */ - writel(epsize, hsotg->regs + epsize_reg); + writel(epsize, dwc2->regs + epsize_reg); - if (using_dma(hsotg) && !continuing) { + if (using_dma(dwc2->s3c_hsotg) && !continuing) { unsigned int dma_reg; /* @@ -618,26 +616,26 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, */ dma_reg = dir_in ? DIEPDMA(index) : DOEPDMA(index); - writel(ureq->dma, hsotg->regs + dma_reg); + writel(ureq->dma, dwc2->regs + dma_reg); - dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", + dev_dbg(dwc2->dev, "%s: %pad => 0x%08x\n", __func__, &ureq->dma, dma_reg); } ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ ctrl |= DXEPCTL_USBACTEP; - dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->setup); + dev_dbg(dwc2->dev, "setup req:%d\n", dwc2->s3c_hsotg->setup); /* For Setup request do not clear NAK */ - if (hsotg->setup && index == 0) - hsotg->setup = 0; + if (dwc2->s3c_hsotg->setup && index == 0) + dwc2->s3c_hsotg->setup = 0; else ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ - dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); - writel(ctrl, hsotg->regs + epctrl_reg); + dev_dbg(dwc2->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); + writel(ctrl, dwc2->regs + epctrl_reg); /* * set these, it seems that DMA support increments past the end @@ -647,11 +645,11 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, hs_ep->size_loaded = length; hs_ep->last_load = ureq->actual; - if (dir_in && !using_dma(hsotg)) { + if (dir_in && !using_dma(dwc2->s3c_hsotg)) { /* set these anyway, we may need them for non-periodic in */ hs_ep->fifo_load = 0; - s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); + s3c_hsotg_write_fifo(dwc2, hs_ep, hs_req); } /* @@ -660,7 +658,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, */ if (dir_in) writel(DIEPMSK_INTKNTXFEMPMSK, - hsotg->regs + DIEPINT(index)); + dwc2->regs + DIEPINT(index)); /* * Note, trying to clear the NAK here causes problems with transmit @@ -668,16 +666,16 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, */ /* check ep is enabled */ - if (!(readl(hsotg->regs + epctrl_reg) & DXEPCTL_EPENA)) - dev_warn(hsotg->dev, + if (!(readl(dwc2->regs + epctrl_reg) & DXEPCTL_EPENA)) + dev_warn(dwc2->dev, "ep%d: failed to become enabled (DXEPCTL=0x%08x)?\n", - index, readl(hsotg->regs + epctrl_reg)); + index, readl(dwc2->regs + epctrl_reg)); - dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", - __func__, readl(hsotg->regs + epctrl_reg)); + dev_dbg(dwc2->dev, "%s: DXEPCTL=0x%08x\n", + __func__, readl(dwc2->regs + epctrl_reg)); /* enable ep interrupts */ - s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); + s3c_hsotg_ctrl_epint(dwc2, hs_ep->index, hs_ep->dir_in, 1); } /** @@ -692,7 +690,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, * DMA memory, then we map the memory and mark our request to allow us to * cleanup on completion. */ -static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, +static int s3c_hsotg_map_dma(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep, struct usb_request *req) { @@ -703,14 +701,14 @@ static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, if (hs_req->req.length == 0) return 0; - ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); + ret = usb_gadget_map_request(&dwc2->gadget, req, hs_ep->dir_in); if (ret) goto dma_error; return 0; dma_error: - dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n", + dev_err(dwc2->dev, "%s: failed to map buffer %p, %d bytes\n", __func__, req->buf, req->length); return -EIO; @@ -721,10 +719,10 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, { struct s3c_hsotg_req *hs_req = our_req(req); struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hs = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; bool first; - dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n", + dev_dbg(dwc2->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n", ep->name, req, req->length, req->buf, req->no_interrupt, req->zero, req->short_not_ok); @@ -734,8 +732,8 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, req->status = -EINPROGRESS; /* if we're using DMA, sync the buffers as necessary */ - if (using_dma(hs)) { - int ret = s3c_hsotg_map_dma(hs, hs_ep, req); + if (using_dma(dwc2->s3c_hsotg)) { + int ret = s3c_hsotg_map_dma(dwc2, hs_ep, req); if (ret) return ret; } @@ -744,7 +742,7 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, list_add_tail(&hs_req->queue, &hs_ep->queue); if (first) - s3c_hsotg_start_req(hs, hs_ep, hs_req, false); + s3c_hsotg_start_req(dwc2, hs_ep, hs_req, false); return 0; } @@ -753,13 +751,13 @@ static int s3c_hsotg_ep_queue_lock(struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hs = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; unsigned long flags = 0; int ret = 0; - spin_lock_irqsave(&hs->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); ret = s3c_hsotg_ep_queue(ep, req, gfp_flags); - spin_unlock_irqrestore(&hs->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); return ret; } @@ -784,9 +782,9 @@ static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, struct usb_request *req) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hsotg = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; - dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); + dev_dbg(dwc2->dev, "%s: ep %p, req %p\n", __func__, ep, req); s3c_hsotg_ep_free_request(ep, req); } @@ -799,17 +797,17 @@ static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, * Convert the given wIndex into a pointer to an driver endpoint * structure, or return NULL if it is not a valid endpoint. */ -static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, +static struct s3c_hsotg_ep *ep_from_windex(struct dwc2_hsotg *dwc2, u32 windex) { - struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F]; + struct s3c_hsotg_ep *ep = &dwc2->eps[windex & 0x7F]; int dir = (windex & USB_DIR_IN) ? 1 : 0; int idx = windex & 0x7F; if (windex >= 0x100) return NULL; - if (idx > hsotg->num_of_eps) + if (idx > dwc2->s3c_hsotg->num_of_eps) return NULL; if (idx && ep->dir_in != dir) @@ -828,7 +826,7 @@ static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, * Create a request and queue it on the given endpoint. This is useful as * an internal method of sending replies to certain control requests, etc. */ -static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg, +static int s3c_hsotg_send_reply(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *ep, void *buff, int length) @@ -836,16 +834,16 @@ static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg, struct usb_request *req; int ret; - dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length); + dev_dbg(dwc2->dev, "%s: buff %p, len %d\n", __func__, buff, length); req = s3c_hsotg_ep_alloc_request(&ep->ep, GFP_ATOMIC); - hsotg->ep0_reply = req; + dwc2->s3c_hsotg->ep0_reply = req; if (!req) { - dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__); + dev_warn(dwc2->dev, "%s: cannot alloc req\n", __func__); return -ENOMEM; } - req->buf = hsotg->ep0_buff; + req->buf = dwc2->s3c_hsotg->ep0_buff; req->length = length; req->zero = 1; /* always do zero-length final transfer */ req->complete = s3c_hsotg_complete_oursetup; @@ -857,7 +855,7 @@ static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg, ret = s3c_hsotg_ep_queue(&ep->ep, req, GFP_ATOMIC); if (ret) { - dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__); + dev_warn(dwc2->dev, "%s: cannot queue req\n", __func__); return ret; } @@ -869,18 +867,18 @@ static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg, * @hsotg: The device state * @ctrl: USB control request */ -static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg, +static int s3c_hsotg_process_req_status(struct dwc2_hsotg *dwc2, struct usb_ctrlrequest *ctrl) { - struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; + struct s3c_hsotg_ep *ep0 = &dwc2->eps[0]; struct s3c_hsotg_ep *ep; __le16 reply; int ret; - dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__); + dev_dbg(dwc2->dev, "%s: USB_REQ_GET_STATUS\n", __func__); if (!ep0->dir_in) { - dev_warn(hsotg->dev, "%s: direction out?\n", __func__); + dev_warn(dwc2->dev, "%s: direction out?\n", __func__); return -EINVAL; } @@ -896,7 +894,7 @@ static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg, break; case USB_RECIP_ENDPOINT: - ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); + ep = ep_from_windex(dwc2, le16_to_cpu(ctrl->wIndex)); if (!ep) return -ENOENT; @@ -910,9 +908,9 @@ static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg, if (le16_to_cpu(ctrl->wLength) != 2) return -EINVAL; - ret = s3c_hsotg_send_reply(hsotg, ep0, &reply, 2); + ret = s3c_hsotg_send_reply(dwc2, ep0, &reply, 2); if (ret) { - dev_err(hsotg->dev, "%s: failed to send reply\n", __func__); + dev_err(dwc2->dev, "%s: failed to send reply\n", __func__); return ret; } @@ -940,10 +938,10 @@ static struct s3c_hsotg_req *get_ep_head(struct s3c_hsotg_ep *hs_ep) * @hsotg: The device state * @ctrl: USB control request */ -static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, +static int s3c_hsotg_process_req_feature(struct dwc2_hsotg *dwc2, struct usb_ctrlrequest *ctrl) { - struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; + struct s3c_hsotg_ep *ep0 = &dwc2->eps[0]; struct s3c_hsotg_req *hs_req; bool restart; bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); @@ -951,13 +949,13 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, int ret; bool halted; - dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", + dev_dbg(dwc2->dev, "%s: %s_FEATURE\n", __func__, set ? "SET" : "CLEAR"); if (ctrl->bRequestType == USB_RECIP_ENDPOINT) { - ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); + ep = ep_from_windex(dwc2, le16_to_cpu(ctrl->wIndex)); if (!ep) { - dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n", + dev_dbg(dwc2->dev, "%s: no endpoint for 0x%04x\n", __func__, le16_to_cpu(ctrl->wIndex)); return -ENOENT; } @@ -968,9 +966,9 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, s3c_hsotg_ep_sethalt(&ep->ep, set); - ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); + ret = s3c_hsotg_send_reply(dwc2, ep0, NULL, 0); if (ret) { - dev_err(hsotg->dev, + dev_err(dwc2->dev, "%s: failed to send reply\n", __func__); return ret; } @@ -997,7 +995,7 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, restart = !list_empty(&ep->queue); if (restart) { hs_req = get_ep_head(ep); - s3c_hsotg_start_req(hsotg, ep, + s3c_hsotg_start_req(dwc2, ep, hs_req, false); } } @@ -1013,8 +1011,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, return 1; } -static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); +static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *dwc2); +static void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2); /** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1022,12 +1020,13 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); * * Set stall for ep0 as response for setup request. */ -static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) { - struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; +static void s3c_hsotg_stall_ep0(struct dwc2_hsotg *dwc2) +{ + struct s3c_hsotg_ep *ep0 = &dwc2->eps[0]; u32 reg; u32 ctrl; - dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); + dev_dbg(dwc2->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); reg = (ep0->dir_in) ? DIEPCTL0 : DOEPCTL0; /* @@ -1035,20 +1034,20 @@ static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) { * taken effect, so no need to clear later. */ - ctrl = readl(hsotg->regs + reg); + ctrl = readl(dwc2->regs + reg); ctrl |= DXEPCTL_STALL; ctrl |= DXEPCTL_CNAK; - writel(ctrl, hsotg->regs + reg); + writel(ctrl, dwc2->regs + reg); - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "written DXEPCTL=0x%08x to %08x (DXEPCTL=0x%08x)\n", - ctrl, reg, readl(hsotg->regs + reg)); + ctrl, reg, readl(dwc2->regs + reg)); /* * complete won't be called, so we enqueue * setup request here */ - s3c_hsotg_enqueue_setup(hsotg); + s3c_hsotg_enqueue_setup(dwc2); } /** @@ -1060,16 +1059,16 @@ static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) { * needs to work out what to do next (and whether to pass it on to the * gadget driver). */ -static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, +static void s3c_hsotg_process_control(struct dwc2_hsotg *dwc2, struct usb_ctrlrequest *ctrl) { - struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; + struct s3c_hsotg_ep *ep0 = &dwc2->eps[0]; int ret = 0; u32 dcfg; ep0->sent_zlp = 0; - dev_dbg(hsotg->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n", + dev_dbg(dwc2->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n", ctrl->bRequest, ctrl->bRequestType, ctrl->wValue, ctrl->wLength); @@ -1079,7 +1078,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, */ ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; - dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in); + dev_dbg(dwc2->dev, "ctrl: dir_in=%d\n", ep0->dir_in); /* * if we've no data with this request, then the last part of the @@ -1091,37 +1090,37 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { switch (ctrl->bRequest) { case USB_REQ_SET_ADDRESS: - s3c_hsotg_disconnect(hsotg); - dcfg = readl(hsotg->regs + DCFG); + s3c_hsotg_disconnect(dwc2); + dcfg = readl(dwc2->regs + DCFG); dcfg &= ~DCFG_DEVADDR_MASK; dcfg |= (le16_to_cpu(ctrl->wValue) << DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK; - writel(dcfg, hsotg->regs + DCFG); + writel(dcfg, dwc2->regs + DCFG); - dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); + dev_info(dwc2->dev, "new address %d\n", ctrl->wValue); - ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); + ret = s3c_hsotg_send_reply(dwc2, ep0, NULL, 0); return; case USB_REQ_GET_STATUS: - ret = s3c_hsotg_process_req_status(hsotg, ctrl); + ret = s3c_hsotg_process_req_status(dwc2, ctrl); break; case USB_REQ_CLEAR_FEATURE: case USB_REQ_SET_FEATURE: - ret = s3c_hsotg_process_req_feature(hsotg, ctrl); + ret = s3c_hsotg_process_req_feature(dwc2, ctrl); break; } } /* as a fallback, try delivering it to the driver to deal with */ - if (ret == 0 && hsotg->driver) { - spin_unlock(&hsotg->lock); - ret = hsotg->driver->setup(&hsotg->gadget, ctrl); - spin_lock(&hsotg->lock); + if (ret == 0 && dwc2->driver) { + spin_unlock(&dwc2->lock); + ret = dwc2->driver->setup(&dwc2->gadget, ctrl); + spin_lock(&dwc2->lock); if (ret < 0) - dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); + dev_dbg(dwc2->dev, "driver->setup() ret %d\n", ret); } /* @@ -1130,7 +1129,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, */ if (ret < 0) - s3c_hsotg_stall_ep0(hsotg); + s3c_hsotg_stall_ep0(dwc2); } /** @@ -1145,19 +1144,19 @@ static void s3c_hsotg_complete_setup(struct usb_ep *ep, struct usb_request *req) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hsotg = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; if (req->status < 0) { - dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); + dev_dbg(dwc2->dev, "%s: failed %d\n", __func__, req->status); return; } - spin_lock(&hsotg->lock); + spin_lock(&dwc2->lock); if (req->actual == 0) - s3c_hsotg_enqueue_setup(hsotg); + s3c_hsotg_enqueue_setup(dwc2); else - s3c_hsotg_process_control(hsotg, req->buf); - spin_unlock(&hsotg->lock); + s3c_hsotg_process_control(dwc2, req->buf); + spin_unlock(&dwc2->lock); } /** @@ -1167,29 +1166,29 @@ static void s3c_hsotg_complete_setup(struct usb_ep *ep, * Enqueue a request on EP0 if necessary to received any SETUP packets * received from the host. */ -static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) +static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *dwc2) { - struct usb_request *req = hsotg->ctrl_req; + struct usb_request *req = dwc2->s3c_hsotg->ctrl_req; struct s3c_hsotg_req *hs_req = our_req(req); int ret; - dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); + dev_dbg(dwc2->dev, "%s: queueing setup request\n", __func__); req->zero = 0; req->length = 8; - req->buf = hsotg->ctrl_buff; + req->buf = dwc2->s3c_hsotg->ctrl_buff; req->complete = s3c_hsotg_complete_setup; if (!list_empty(&hs_req->queue)) { - dev_dbg(hsotg->dev, "%s already queued???\n", __func__); + dev_dbg(dwc2->dev, "%s already queued???\n", __func__); return; } - hsotg->eps[0].dir_in = 0; + dwc2->eps[0].dir_in = 0; - ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC); + ret = s3c_hsotg_ep_queue(&dwc2->eps[0].ep, req, GFP_ATOMIC); if (ret < 0) { - dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); + dev_err(dwc2->dev, "%s: failed queue (%d)\n", __func__, ret); /* * Don't think there's much we can do other than watch the * driver fail. @@ -1210,7 +1209,7 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) * * Note, expects the ep to already be locked as appropriate. */ -static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, +static void s3c_hsotg_complete_request(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep, struct s3c_hsotg_req *hs_req, int result) @@ -1218,11 +1217,11 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, bool restart; if (!hs_req) { - dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); + dev_dbg(dwc2->dev, "%s: nothing to complete?\n", __func__); return; } - dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", + dev_dbg(dwc2->dev, "complete: ep %p %s, req %p, %d => %p\n", hs_ep, hs_ep->ep.name, hs_req, result, hs_req->req.complete); /* @@ -1236,8 +1235,8 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, hs_ep->req = NULL; list_del_init(&hs_req->queue); - if (using_dma(hsotg)) - s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); + if (using_dma(dwc2->s3c_hsotg)) + s3c_hsotg_unmap_dma(dwc2, hs_ep, hs_req); /* * call the complete request with the locks off, just in case the @@ -1245,9 +1244,9 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, */ if (hs_req->req.complete) { - spin_unlock(&hsotg->lock); + spin_unlock(&dwc2->lock); hs_req->req.complete(&hs_ep->ep, &hs_req->req); - spin_lock(&hsotg->lock); + spin_lock(&dwc2->lock); } /* @@ -1260,7 +1259,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, restart = !list_empty(&hs_ep->queue); if (restart) { hs_req = get_ep_head(hs_ep); - s3c_hsotg_start_req(hsotg, hs_ep, hs_req, false); + s3c_hsotg_start_req(dwc2, hs_ep, hs_req, false); } } } @@ -1275,21 +1274,21 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, * endpoint, so sort out whether we need to read the data into a request * that has been made for that endpoint. */ -static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) +static void s3c_hsotg_rx_data(struct dwc2_hsotg *dwc2, int ep_idx, int size) { - struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; + struct s3c_hsotg_ep *hs_ep = &dwc2->eps[ep_idx]; struct s3c_hsotg_req *hs_req = hs_ep->req; - void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); + void __iomem *fifo = dwc2->regs + EPFIFO(ep_idx); int to_read; int max_req; int read_ptr; if (!hs_req) { - u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx)); + u32 epctl = readl(dwc2->regs + DOEPCTL(ep_idx)); int ptr; - dev_warn(hsotg->dev, + dev_warn(dwc2->dev, "%s: FIFO %d bytes on ep%d but no req (DXEPCTl=0x%08x)\n", __func__, size, ep_idx, epctl); @@ -1304,7 +1303,7 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) read_ptr = hs_req->req.actual; max_req = hs_req->req.length - read_ptr; - dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", + dev_dbg(dwc2->dev, "%s: read %d/%d, done %d/%d\n", __func__, to_read, max_req, read_ptr, hs_req->req.length); if (to_read > max_req) { @@ -1340,36 +1339,36 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) * currently believed that we do not need to wait for any space in * the TxFIFO. */ -static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, +static void s3c_hsotg_send_zlp(struct dwc2_hsotg *dwc2, struct s3c_hsotg_req *req) { u32 ctrl; if (!req) { - dev_warn(hsotg->dev, "%s: no request?\n", __func__); + dev_warn(dwc2->dev, "%s: no request?\n", __func__); return; } if (req->req.length == 0) { - hsotg->eps[0].sent_zlp = 1; - s3c_hsotg_enqueue_setup(hsotg); + dwc2->eps[0].sent_zlp = 1; + s3c_hsotg_enqueue_setup(dwc2); return; } - hsotg->eps[0].dir_in = 1; - hsotg->eps[0].sent_zlp = 1; + dwc2->eps[0].dir_in = 1; + dwc2->eps[0].sent_zlp = 1; - dev_dbg(hsotg->dev, "sending zero-length packet\n"); + dev_dbg(dwc2->dev, "sending zero-length packet\n"); /* issue a zero-sized packet to terminate this */ writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | - DXEPTSIZ_XFERSIZE(0), hsotg->regs + DIEPTSIZ(0)); + DXEPTSIZ_XFERSIZE(0), dwc2->regs + DIEPTSIZ(0)); - ctrl = readl(hsotg->regs + DIEPCTL0); + ctrl = readl(dwc2->regs + DIEPCTL0); ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ ctrl |= DXEPCTL_USBACTEP; - writel(ctrl, hsotg->regs + DIEPCTL0); + writel(ctrl, dwc2->regs + DIEPCTL0); } /** @@ -1382,22 +1381,22 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, * transfer for an OUT endpoint has been completed, either by a short * packet or by the finish of a transfer. */ -static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, +static void s3c_hsotg_handle_outdone(struct dwc2_hsotg *dwc2, int epnum, bool was_setup) { - u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); - struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; + u32 epsize = readl(dwc2->regs + DOEPTSIZ(epnum)); + struct s3c_hsotg_ep *hs_ep = &dwc2->eps[epnum]; struct s3c_hsotg_req *hs_req = hs_ep->req; struct usb_request *req = &hs_req->req; unsigned size_left = DXEPTSIZ_XFERSIZE_GET(epsize); int result = 0; if (!hs_req) { - dev_dbg(hsotg->dev, "%s: no request active\n", __func__); + dev_dbg(dwc2->dev, "%s: no request active\n", __func__); return; } - if (using_dma(hsotg)) { + if (using_dma(dwc2->s3c_hsotg)) { unsigned size_done; /* @@ -1417,18 +1416,18 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, /* if there is more request to do, schedule new transfer */ if (req->actual < req->length && size_left == 0) { - s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); + s3c_hsotg_start_req(dwc2, hs_ep, hs_req, true); return; } else if (epnum == 0) { /* * After was_setup = 1 => * set CNAK for non Setup requests */ - hsotg->setup = was_setup ? 0 : 1; + dwc2->s3c_hsotg->setup = was_setup ? 0 : 1; } if (req->actual < req->length && req->short_not_ok) { - dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", + dev_dbg(dwc2->dev, "%s: got %d/%d (short not ok) => error\n", __func__, req->actual, req->length); /* @@ -1443,10 +1442,10 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, * send ZLP when we have an asynchronous request from gadget */ if (!was_setup && req->complete != s3c_hsotg_complete_setup) - s3c_hsotg_send_zlp(hsotg, hs_req); + s3c_hsotg_send_zlp(dwc2, hs_req); } - s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result); + s3c_hsotg_complete_request(dwc2, hs_ep, hs_req, result); } /** @@ -1455,11 +1454,11 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, * * Return the current frame number */ -static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) +static u32 s3c_hsotg_read_frameno(struct dwc2_hsotg *dwc2) { u32 dsts; - dsts = readl(hsotg->regs + DSTS); + dsts = readl(dwc2->regs + DSTS); dsts &= DSTS_SOFFN_MASK; dsts >>= DSTS_SOFFN_SHIFT; @@ -1482,12 +1481,12 @@ static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) * as the actual data should be sent to the memory directly and we turn * on the completion interrupts to get notifications of transfer completion. */ -static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) +void s3c_hsotg_handle_rx(struct dwc2_hsotg *dwc2) { - u32 grxstsr = readl(hsotg->regs + GRXSTSP); + u32 grxstsr = readl(dwc2->regs + GRXSTSP); u32 epnum, status, size; - WARN_ON(using_dma(hsotg)); + WARN_ON(using_dma(dwc2->s3c_hsotg)); epnum = grxstsr & GRXSTS_EPNUM_MASK; status = grxstsr & GRXSTS_PKTSTS_MASK; @@ -1496,49 +1495,49 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) size >>= GRXSTS_BYTECNT_SHIFT; if (1) - dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", + dev_dbg(dwc2->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", __func__, grxstsr, size, epnum); switch ((status & GRXSTS_PKTSTS_MASK) >> GRXSTS_PKTSTS_SHIFT) { case GRXSTS_PKTSTS_GLOBALOUTNAK: - dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); + dev_dbg(dwc2->dev, "GLOBALOUTNAK\n"); break; case GRXSTS_PKTSTS_OUTDONE: - dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", - s3c_hsotg_read_frameno(hsotg)); + dev_dbg(dwc2->dev, "OutDone (Frame=0x%08x)\n", + s3c_hsotg_read_frameno(dwc2)); - if (!using_dma(hsotg)) - s3c_hsotg_handle_outdone(hsotg, epnum, false); + if (!using_dma(dwc2->s3c_hsotg)) + s3c_hsotg_handle_outdone(dwc2, epnum, false); break; case GRXSTS_PKTSTS_SETUPDONE: - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", - s3c_hsotg_read_frameno(hsotg), - readl(hsotg->regs + DOEPCTL(0))); + s3c_hsotg_read_frameno(dwc2), + readl(dwc2->regs + DOEPCTL(0))); - s3c_hsotg_handle_outdone(hsotg, epnum, true); + s3c_hsotg_handle_outdone(dwc2, epnum, true); break; case GRXSTS_PKTSTS_OUTRX: - s3c_hsotg_rx_data(hsotg, epnum, size); + s3c_hsotg_rx_data(dwc2, epnum, size); break; case GRXSTS_PKTSTS_SETUPRX: - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", - s3c_hsotg_read_frameno(hsotg), - readl(hsotg->regs + DOEPCTL(0))); + s3c_hsotg_read_frameno(dwc2), + readl(dwc2->regs + DOEPCTL(0))); - s3c_hsotg_rx_data(hsotg, epnum, size); + s3c_hsotg_rx_data(dwc2, epnum, size); break; default: - dev_warn(hsotg->dev, "%s: unknown status %08x\n", + dev_warn(dwc2->dev, "%s: unknown status %08x\n", __func__, grxstsr); - s3c_hsotg_dump(hsotg); + s3c_hsotg_dump(dwc2); break; } } @@ -1574,11 +1573,11 @@ static u32 s3c_hsotg_ep0_mps(unsigned int mps) * Configure the maximum packet size for the given endpoint, updating * the hardware control registers to reflect this. */ -static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, +static void s3c_hsotg_set_ep_maxpacket(struct dwc2_hsotg *dwc2, unsigned int ep, unsigned int mps) { - struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; - void __iomem *regs = hsotg->regs; + struct s3c_hsotg_ep *hs_ep = &dwc2->eps[ep]; + void __iomem *regs = dwc2->regs; u32 mpsval; u32 mcval; u32 reg; @@ -1621,7 +1620,7 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, return; bad_mps: - dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); + dev_err(dwc2->dev, "ep%d: bad mps of %d\n", ep, mps); } /** @@ -1629,25 +1628,25 @@ bad_mps: * @hsotg: The driver state * @idx: The index for the endpoint (0..15) */ -static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) +static void s3c_hsotg_txfifo_flush(struct dwc2_hsotg *dwc2, unsigned int idx) { int timeout; int val; writel(GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, - hsotg->regs + GRSTCTL); + dwc2->regs + GRSTCTL); /* wait until the fifo is flushed */ timeout = 100; while (1) { - val = readl(hsotg->regs + GRSTCTL); + val = readl(dwc2->regs + GRSTCTL); if ((val & (GRSTCTL_TXFFLSH)) == 0) break; if (--timeout == 0) { - dev_err(hsotg->dev, + dev_err(dwc2->dev, "%s: timeout flushing fifo (GRSTCTL=%08x)\n", __func__, val); } @@ -1664,7 +1663,7 @@ static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) * Check to see if there is a request that has data to send, and if so * make an attempt to write data into the FIFO. */ -static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg, +static int s3c_hsotg_trytx(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep) { struct s3c_hsotg_req *hs_req = hs_ep->req; @@ -1675,15 +1674,15 @@ static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg, * for endpoints, excepting ep0 */ if (hs_ep->index != 0) - s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, + s3c_hsotg_ctrl_epint(dwc2, hs_ep->index, hs_ep->dir_in, 0); return 0; } if (hs_req->req.actual < hs_req->req.length) { - dev_dbg(hsotg->dev, "trying to write more for ep%d\n", + dev_dbg(dwc2->dev, "trying to write more for ep%d\n", hs_ep->index); - return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); + return s3c_hsotg_write_fifo(dwc2, hs_ep, hs_req); } return 0; @@ -1697,22 +1696,22 @@ static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg, * An IN transfer has been completed, update the transfer's state and then * call the relevant completion routines. */ -static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, +static void s3c_hsotg_complete_in(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep) { struct s3c_hsotg_req *hs_req = hs_ep->req; - u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); + u32 epsize = readl(dwc2->regs + DIEPTSIZ(hs_ep->index)); int size_left, size_done; if (!hs_req) { - dev_dbg(hsotg->dev, "XferCompl but no req\n"); + dev_dbg(dwc2->dev, "XferCompl but no req\n"); return; } /* Finish ZLP handling for IN EP0 transactions */ - if (hsotg->eps[0].sent_zlp) { - dev_dbg(hsotg->dev, "zlp packet received\n"); - s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); + if (dwc2->eps[0].sent_zlp) { + dev_dbg(dwc2->dev, "zlp packet received\n"); + s3c_hsotg_complete_request(dwc2, hs_ep, hs_req, 0); return; } @@ -1732,11 +1731,11 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, size_done += hs_ep->last_load; if (hs_req->req.actual != size_done) - dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", + dev_dbg(dwc2->dev, "%s: adjusting size done %d => %d\n", __func__, hs_req->req.actual, size_done); hs_req->req.actual = size_done; - dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", + dev_dbg(dwc2->dev, "req->length:%d req->actual:%d req->zero:%d\n", hs_req->req.length, hs_req->req.actual, hs_req->req.zero); /* @@ -1753,17 +1752,17 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, hs_req->req.length == hs_req->req.actual && !(hs_req->req.length % hs_ep->ep.maxpacket)) { - dev_dbg(hsotg->dev, "ep0 zlp IN packet sent\n"); - s3c_hsotg_send_zlp(hsotg, hs_req); + dev_dbg(dwc2->dev, "ep0 zlp IN packet sent\n"); + s3c_hsotg_send_zlp(dwc2, hs_req); return; } if (!size_left && hs_req->req.actual < hs_req->req.length) { - dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); - s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); + dev_dbg(dwc2->dev, "%s trying more for req...\n", __func__); + s3c_hsotg_start_req(dwc2, hs_ep, hs_req, true); } else - s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); + s3c_hsotg_complete_request(dwc2, hs_ep, hs_req, 0); } /** @@ -1774,23 +1773,23 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, * * Process and clear any interrupt pending for an individual endpoint */ -static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, +void s3c_hsotg_epint(struct dwc2_hsotg *dwc2, unsigned int idx, int dir_in) { - struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; + struct s3c_hsotg_ep *hs_ep = &dwc2->eps[idx]; u32 epint_reg = dir_in ? DIEPINT(idx) : DOEPINT(idx); u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); u32 ints; u32 ctrl; - ints = readl(hsotg->regs + epint_reg); - ctrl = readl(hsotg->regs + epctl_reg); + ints = readl(dwc2->regs + epint_reg); + ctrl = readl(dwc2->regs + epctl_reg); /* Clear endpoint interrupts */ - writel(ints, hsotg->regs + epint_reg); + writel(ints, dwc2->regs + epint_reg); - dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", + dev_dbg(dwc2->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", __func__, idx, dir_in ? "in" : "out", ints); if (ints & DXEPINT_XFERCOMPL) { @@ -1799,58 +1798,58 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, ctrl |= DXEPCTL_SETEVENFR; else ctrl |= DXEPCTL_SETODDFR; - writel(ctrl, hsotg->regs + epctl_reg); + writel(ctrl, dwc2->regs + epctl_reg); } - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "%s: XferCompl: DxEPCTL=0x%08x, DXEPTSIZ=%08x\n", - __func__, readl(hsotg->regs + epctl_reg), - readl(hsotg->regs + epsiz_reg)); + __func__, readl(dwc2->regs + epctl_reg), + readl(dwc2->regs + epsiz_reg)); /* * we get OutDone from the FIFO, so we only need to look * at completing IN requests here */ if (dir_in) { - s3c_hsotg_complete_in(hsotg, hs_ep); + s3c_hsotg_complete_in(dwc2, hs_ep); if (idx == 0 && !hs_ep->req) - s3c_hsotg_enqueue_setup(hsotg); - } else if (using_dma(hsotg)) { + s3c_hsotg_enqueue_setup(dwc2); + } else if (using_dma(dwc2->s3c_hsotg)) { /* * We're using DMA, we need to fire an OutDone here * as we ignore the RXFIFO. */ - s3c_hsotg_handle_outdone(hsotg, idx, false); + s3c_hsotg_handle_outdone(dwc2, idx, false); } } if (ints & DXEPINT_EPDISBLD) { - dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); + dev_dbg(dwc2->dev, "%s: EPDisbld\n", __func__); if (dir_in) { - int epctl = readl(hsotg->regs + epctl_reg); + int epctl = readl(dwc2->regs + epctl_reg); - s3c_hsotg_txfifo_flush(hsotg, idx); + s3c_hsotg_txfifo_flush(dwc2, idx); if ((epctl & DXEPCTL_STALL) && (epctl & DXEPCTL_EPTYPE_BULK)) { - int dctl = readl(hsotg->regs + DCTL); + int dctl = readl(dwc2->regs + DCTL); dctl |= DCTL_CGNPINNAK; - writel(dctl, hsotg->regs + DCTL); + writel(dctl, dwc2->regs + DCTL); } } } if (ints & DXEPINT_AHBERR) - dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); + dev_dbg(dwc2->dev, "%s: AHBErr\n", __func__); if (ints & DXEPINT_SETUP) { /* Setup or Timeout */ - dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); + dev_dbg(dwc2->dev, "%s: Setup/Timeout\n", __func__); - if (using_dma(hsotg) && idx == 0) { + if (using_dma(dwc2->s3c_hsotg) && idx == 0) { /* * this is the notification we've received a * setup packet. In non-DMA mode we'd get this @@ -1861,33 +1860,33 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, if (dir_in) WARN_ON_ONCE(1); else - s3c_hsotg_handle_outdone(hsotg, 0, true); + s3c_hsotg_handle_outdone(dwc2, 0, true); } } if (ints & DXEPINT_BACK2BACKSETUP) - dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); + dev_dbg(dwc2->dev, "%s: B2BSetup/INEPNakEff\n", __func__); if (dir_in && !hs_ep->isochronous) { /* not sure if this is important, but we'll clear it anyway */ if (ints & DIEPMSK_INTKNTXFEMPMSK) { - dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", + dev_dbg(dwc2->dev, "%s: ep%d: INTknTXFEmpMsk\n", __func__, idx); } /* this probably means something bad is happening */ if (ints & DIEPMSK_INTKNEPMISMSK) { - dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", + dev_warn(dwc2->dev, "%s: ep%d: INTknEP\n", __func__, idx); } /* FIFO has space or is empty (see GAHBCFG) */ - if (hsotg->dedicated_fifos && + if (dwc2->s3c_hsotg->dedicated_fifos && ints & DIEPMSK_TXFIFOEMPTY) { - dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", + dev_dbg(dwc2->dev, "%s: ep%d: TxFIFOEmpty\n", __func__, idx); - if (!using_dma(hsotg)) - s3c_hsotg_trytx(hsotg, hs_ep); + if (!using_dma(dwc2->s3c_hsotg)) + s3c_hsotg_trytx(dwc2, hs_ep); } } } @@ -1899,9 +1898,9 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, * Handle updating the device settings after the enumeration phase has * been completed. */ -static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) +void s3c_hsotg_irq_enumdone(struct dwc2_hsotg *dwc2) { - u32 dsts = readl(hsotg->regs + DSTS); + u32 dsts = readl(dwc2->regs + DSTS); int ep0_mps = 0, ep_mps; /* @@ -1910,7 +1909,7 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) * we connected at. */ - dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); + dev_dbg(dwc2->dev, "EnumDone (DSTS=0x%08x)\n", dsts); /* * note, since we're limited by the size of transfer on EP0, and @@ -1922,19 +1921,19 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) switch (dsts & DSTS_ENUMSPD_MASK) { case DSTS_ENUMSPD_FS: case DSTS_ENUMSPD_FS48: - hsotg->gadget.speed = USB_SPEED_FULL; + dwc2->gadget.speed = USB_SPEED_FULL; ep0_mps = EP0_MPS_LIMIT; ep_mps = 1023; break; case DSTS_ENUMSPD_HS: - hsotg->gadget.speed = USB_SPEED_HIGH; + dwc2->gadget.speed = USB_SPEED_HIGH; ep0_mps = EP0_MPS_LIMIT; ep_mps = 1024; break; case DSTS_ENUMSPD_LS: - hsotg->gadget.speed = USB_SPEED_LOW; + dwc2->gadget.speed = USB_SPEED_LOW; /* * note, we don't actually support LS in this driver at the * moment, and the documentation seems to imply that it isn't @@ -1942,8 +1941,8 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) */ break; } - dev_info(hsotg->dev, "new device is %s\n", - usb_speed_string(hsotg->gadget.speed)); + dev_info(dwc2->dev, "new device is %s\n", + usb_speed_string(dwc2->gadget.speed)); /* * we should now know the maximum packet size for an @@ -1952,18 +1951,18 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) if (ep0_mps) { int i; - s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps); - for (i = 1; i < hsotg->num_of_eps; i++) - s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps); + s3c_hsotg_set_ep_maxpacket(dwc2, 0, ep0_mps); + for (i = 1; i < dwc2->s3c_hsotg->num_of_eps; i++) + s3c_hsotg_set_ep_maxpacket(dwc2, i, ep_mps); } /* ensure after enumeration our EP0 is active */ - s3c_hsotg_enqueue_setup(hsotg); + s3c_hsotg_enqueue_setup(dwc2); - dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", - readl(hsotg->regs + DIEPCTL0), - readl(hsotg->regs + DOEPCTL0)); + dev_dbg(dwc2->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", + readl(dwc2->regs + DIEPCTL0), + readl(dwc2->regs + DOEPCTL0)); } /** @@ -1976,7 +1975,7 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) * Go through the requests on the given endpoint and mark them * completed with the given result code. */ -static void kill_all_requests(struct s3c_hsotg *hsotg, +void kill_all_requests(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *ep, int result, bool force) { @@ -1991,12 +1990,12 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, if (ep->req == req && ep->dir_in && !force) continue; - s3c_hsotg_complete_request(hsotg, ep, req, + s3c_hsotg_complete_request(dwc2, ep, req, result); } - if(hsotg->dedicated_fifos) - if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) - s3c_hsotg_txfifo_flush(hsotg, ep->index); + if (dwc2->s3c_hsotg->dedicated_fifos) + if ((readl(dwc2->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) + s3c_hsotg_txfifo_flush(dwc2, ep->index); } /** @@ -2007,14 +2006,14 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, * transactions and signal the gadget driver that this * has happened. */ -static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) +static void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) { unsigned ep; - for (ep = 0; ep < hsotg->num_of_eps; ep++) - kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); + for (ep = 0; ep < dwc2->s3c_hsotg->num_of_eps; ep++) + kill_all_requests(dwc2, &dwc2->eps[ep], -ESHUTDOWN, true); - call_gadget(hsotg, disconnect); + call_gadget(dwc2, disconnect); } /** @@ -2022,15 +2021,15 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) * @hsotg: The device state: * @periodic: True if this is a periodic FIFO interrupt */ -static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) +void s3c_hsotg_irq_fifoempty(struct dwc2_hsotg *dwc2, bool periodic) { struct s3c_hsotg_ep *ep; int epno, ret; /* look through for any more data to transmit */ - for (epno = 0; epno < hsotg->num_of_eps; epno++) { - ep = &hsotg->eps[epno]; + for (epno = 0; epno < dwc2->s3c_hsotg->num_of_eps; epno++) { + ep = &dwc2->eps[epno]; if (!ep->dir_in) continue; @@ -2039,7 +2038,7 @@ static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) (!periodic && ep->periodic)) continue; - ret = s3c_hsotg_trytx(hsotg, ep); + ret = s3c_hsotg_trytx(dwc2, ep); if (ret < 0) break; } @@ -2056,33 +2055,33 @@ static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) * * Issue a soft reset to the core, and await the core finishing it. */ -static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) +static int s3c_hsotg_corereset(struct dwc2_hsotg *dwc2) { int timeout; u32 grstctl; - dev_dbg(hsotg->dev, "resetting core\n"); + dev_dbg(dwc2->dev, "resetting core\n"); /* issue soft reset */ - writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); + writel(GRSTCTL_CSFTRST, dwc2->regs + GRSTCTL); timeout = 10000; do { - grstctl = readl(hsotg->regs + GRSTCTL); + grstctl = readl(dwc2->regs + GRSTCTL); } while ((grstctl & GRSTCTL_CSFTRST) && timeout-- > 0); if (grstctl & GRSTCTL_CSFTRST) { - dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); + dev_err(dwc2->dev, "Failed to get CSftRst asserted\n"); return -EINVAL; } timeout = 10000; while (1) { - u32 grstctl = readl(hsotg->regs + GRSTCTL); + u32 grstctl = readl(dwc2->regs + GRSTCTL); if (timeout-- < 0) { - dev_info(hsotg->dev, + dev_info(dwc2->dev, "%s: reset failed, GRSTCTL=%08x\n", __func__, grstctl); return -ETIMEDOUT; @@ -2094,7 +2093,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) break; /* reset done */ } - dev_dbg(hsotg->dev, "reset successful\n"); + dev_dbg(dwc2->dev, "reset successful\n"); return 0; } @@ -2104,9 +2103,9 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) * * Issue a soft reset to the core, and await the core finishing it. */ -static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) +void s3c_hsotg_core_init(struct dwc2_hsotg *dwc2) { - s3c_hsotg_corereset(hsotg); + s3c_hsotg_corereset(dwc2); /* * we must now enable ep0 ready for host detection and then @@ -2114,37 +2113,37 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) */ /* set the PLL on, remove the HNP/SRP and set the PHY */ - writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | - (0x5 << 10), hsotg->regs + GUSBCFG); + writel(dwc2->s3c_hsotg->phyif | GUSBCFG_TOUTCAL(7) | + (0x5 << 10), dwc2->regs + GUSBCFG); - s3c_hsotg_init_fifo(hsotg); + s3c_hsotg_init_fifo(dwc2); - __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); + __orr32(dwc2->regs + DCTL, DCTL_SFTDISCON); - writel(1 << 18 | DCFG_DEVSPD_HS, hsotg->regs + DCFG); + writel(1 << 18 | DCFG_DEVSPD_HS, dwc2->regs + DCFG); /* Clear any pending OTG interrupts */ - writel(0xffffffff, hsotg->regs + GOTGINT); + writel(0xffffffff, dwc2->regs + GOTGINT); /* Clear any pending interrupts */ - writel(0xffffffff, hsotg->regs + GINTSTS); + writel(0xffffffff, dwc2->regs + GINTSTS); writel(GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT | GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF | GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST | GINTSTS_ENUMDONE | GINTSTS_OTGINT | GINTSTS_USBSUSP | GINTSTS_WKUPINT, - hsotg->regs + GINTMSK); + dwc2->regs + GINTMSK); - if (using_dma(hsotg)) + if (using_dma(dwc2->s3c_hsotg)) writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | GAHBCFG_HBSTLEN_INCR4, - hsotg->regs + GAHBCFG); + dwc2->regs + GAHBCFG); else - writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL | + writel(((dwc2->s3c_hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL | GAHBCFG_P_TXF_EMP_LVL) : 0) | GAHBCFG_GLBL_INTR_EN, - hsotg->regs + GAHBCFG); + dwc2->regs + GAHBCFG); /* * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts @@ -2152,49 +2151,49 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) * interrupts. */ - writel(((hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY | + writel(((dwc2->s3c_hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY | DIEPMSK_INTKNTXFEMPMSK : 0) | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK | DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | DIEPMSK_INTKNEPMISMSK, - hsotg->regs + DIEPMSK); + dwc2->regs + DIEPMSK); /* * don't need XferCompl, we get that from RXFIFO in slave mode. In * DMA mode we may need this. */ - writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | + writel((using_dma(dwc2->s3c_hsotg) ? (DIEPMSK_XFERCOMPLMSK | DIEPMSK_TIMEOUTMSK) : 0) | DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK | DOEPMSK_SETUPMSK, - hsotg->regs + DOEPMSK); + dwc2->regs + DOEPMSK); - writel(0, hsotg->regs + DAINTMSK); + writel(0, dwc2->regs + DAINTMSK); - dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", - readl(hsotg->regs + DIEPCTL0), - readl(hsotg->regs + DOEPCTL0)); + dev_dbg(dwc2->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", + readl(dwc2->regs + DIEPCTL0), + readl(dwc2->regs + DOEPCTL0)); /* enable in and out endpoint interrupts */ - s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); + s3c_hsotg_en_gsint(dwc2, GINTSTS_OEPINT | GINTSTS_IEPINT); /* * Enable the RXFIFO when in slave mode, as this is how we collect * the data. In DMA mode, we get events from the FIFO but also * things we cannot process, so do not use it. */ - if (!using_dma(hsotg)) - s3c_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); + if (!using_dma(dwc2->s3c_hsotg)) + s3c_hsotg_en_gsint(dwc2, GINTSTS_RXFLVL); /* Enable interrupts for EP0 in and out */ - s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); - s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); + s3c_hsotg_ctrl_epint(dwc2, 0, 0, 1); + s3c_hsotg_ctrl_epint(dwc2, 0, 1, 1); - __orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); + __orr32(dwc2->regs + DCTL, DCTL_PWRONPRGDONE); udelay(10); /* see openiboot */ - __bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); + __bic32(dwc2->regs + DCTL, DCTL_PWRONPRGDONE); - dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); + dev_dbg(dwc2->dev, "DCTL=0x%08x\n", readl(dwc2->regs + DCTL)); /* * DxEPCTL_USBActEp says RO in manual, but seems to be set by @@ -2203,32 +2202,32 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) /* set to read 1 8byte packet */ writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | - DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); + DXEPTSIZ_XFERSIZE(8), dwc2->regs + DOEPTSIZ0); - writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | + writel(s3c_hsotg_ep0_mps(dwc2->eps[0].ep.maxpacket) | DXEPCTL_CNAK | DXEPCTL_EPENA | DXEPCTL_USBACTEP, - hsotg->regs + DOEPCTL0); + dwc2->regs + DOEPCTL0); /* enable, but don't activate EP0in */ - writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | - DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); + writel(s3c_hsotg_ep0_mps(dwc2->eps[0].ep.maxpacket) | + DXEPCTL_USBACTEP, dwc2->regs + DIEPCTL0); - s3c_hsotg_enqueue_setup(hsotg); + s3c_hsotg_enqueue_setup(dwc2); - dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", - readl(hsotg->regs + DIEPCTL0), - readl(hsotg->regs + DOEPCTL0)); + dev_dbg(dwc2->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", + readl(dwc2->regs + DIEPCTL0), + readl(dwc2->regs + DOEPCTL0)); /* clear global NAKs */ writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK, - hsotg->regs + DCTL); + dwc2->regs + DCTL); /* must be at-least 3ms to allow bus to see disconnect */ mdelay(3); /* remove the soft-disconnect and let's go */ - __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); + __bic32(dwc2->regs + DCTL, DCTL_SFTDISCON); } /** @@ -2430,7 +2429,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, const struct usb_endpoint_descriptor *desc) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hsotg = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; unsigned long flags; int index = hs_ep->index; u32 epctrl_reg; @@ -2439,7 +2438,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, int dir_in; int ret = 0; - dev_dbg(hsotg->dev, + dev_dbg(dwc2->dev, "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n", __func__, ep->name, desc->bEndpointAddress, desc->bmAttributes, desc->wMaxPacketSize, desc->bInterval); @@ -2449,7 +2448,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; if (dir_in != hs_ep->dir_in) { - dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); + dev_err(dwc2->dev, "%s: direction mismatch!\n", __func__); return -EINVAL; } @@ -2458,12 +2457,12 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); - epctrl = readl(hsotg->regs + epctrl_reg); + epctrl = readl(dwc2->regs + epctrl_reg); - dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", + dev_dbg(dwc2->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", __func__, epctrl, epctrl_reg); - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); epctrl &= ~(DXEPCTL_EPTYPE_MASK | DXEPCTL_MPS_MASK); epctrl |= DXEPCTL_MPS(mps); @@ -2484,7 +2483,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, epctrl |= DXEPCTL_SNAK; /* update the endpoint state */ - s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); + s3c_hsotg_set_ep_maxpacket(dwc2, hs_ep->index, mps); /* default, set to non-periodic */ hs_ep->isochronous = 0; @@ -2493,7 +2492,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, hs_ep->interval = desc->bInterval; if (hs_ep->interval > 1 && hs_ep->mc > 1) - dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); + dev_err(dwc2->dev, "MC > 1 when interval is not 1\n"); switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { case USB_ENDPOINT_XFER_ISOC: @@ -2533,24 +2532,24 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, * if the hardware has dedicated fifos, we must give each IN EP * a unique tx-fifo even if it is non-periodic. */ - if (dir_in && hsotg->dedicated_fifos) + if (dir_in && dwc2->s3c_hsotg->dedicated_fifos) epctrl |= DXEPCTL_TXFNUM(index); /* for non control endpoints, set PID to D0 */ if (index) epctrl |= DXEPCTL_SETD0PID; - dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", + dev_dbg(dwc2->dev, "%s: write DxEPCTL=0x%08x\n", __func__, epctrl); - writel(epctrl, hsotg->regs + epctrl_reg); - dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", - __func__, readl(hsotg->regs + epctrl_reg)); + writel(epctrl, dwc2->regs + epctrl_reg); + dev_dbg(dwc2->dev, "%s: read DxEPCTL=0x%08x\n", + __func__, readl(dwc2->regs + epctrl_reg)); /* enable the endpoint interrupt */ - s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); + s3c_hsotg_ctrl_epint(dwc2, index, dir_in, 1); - spin_unlock_irqrestore(&hsotg->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); return ret; } @@ -2561,39 +2560,39 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, static int s3c_hsotg_ep_disable(struct usb_ep *ep) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hsotg = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; int dir_in = hs_ep->dir_in; int index = hs_ep->index; unsigned long flags; u32 epctrl_reg; u32 ctrl; - dev_info(hsotg->dev, "%s(ep %p)\n", __func__, ep); + dev_info(dwc2->dev, "%s(ep %p)\n", __func__, ep); - if (ep == &hsotg->eps[0].ep) { - dev_err(hsotg->dev, "%s: called for ep0\n", __func__); + if (ep == &dwc2->eps[0].ep) { + dev_err(dwc2->dev, "%s: called for ep0\n", __func__); return -EINVAL; } epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); /* terminate all requests with shutdown */ - kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); + kill_all_requests(dwc2, hs_ep, -ESHUTDOWN, false); - ctrl = readl(hsotg->regs + epctrl_reg); + ctrl = readl(dwc2->regs + epctrl_reg); ctrl &= ~DXEPCTL_EPENA; ctrl &= ~DXEPCTL_USBACTEP; ctrl |= DXEPCTL_SNAK; - dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); - writel(ctrl, hsotg->regs + epctrl_reg); + dev_dbg(dwc2->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); + writel(ctrl, dwc2->regs + epctrl_reg); /* disable endpoint interrupts */ - s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); + s3c_hsotg_ctrl_epint(dwc2, hs_ep->index, hs_ep->dir_in, 0); - spin_unlock_irqrestore(&hsotg->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); return 0; } @@ -2623,20 +2622,20 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) { struct s3c_hsotg_req *hs_req = our_req(req); struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hs = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; unsigned long flags; - dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); + dev_info(dwc2->dev, "ep_dequeue(%p,%p)\n", ep, req); - spin_lock_irqsave(&hs->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); if (!on_list(hs_ep, hs_req)) { - spin_unlock_irqrestore(&hs->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); return -EINVAL; } - s3c_hsotg_complete_request(hs, hs_ep, hs_req, -ECONNRESET); - spin_unlock_irqrestore(&hs->lock, flags); + s3c_hsotg_complete_request(dwc2, hs_ep, hs_req, -ECONNRESET); + spin_unlock_irqrestore(&dwc2->lock, flags); return 0; } @@ -2649,19 +2648,19 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hs = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; int index = hs_ep->index; u32 epreg; u32 epctl; u32 xfertype; - dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value); + dev_info(dwc2->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value); if (index == 0) { if (value) - s3c_hsotg_stall_ep0(hs); + s3c_hsotg_stall_ep0(dwc2); else - dev_warn(hs->dev, + dev_warn(dwc2->dev, "%s: can't clear halt on ep0\n", __func__); return 0; } @@ -2669,7 +2668,7 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) /* write both IN and OUT control registers */ epreg = DIEPCTL(index); - epctl = readl(hs->regs + epreg); + epctl = readl(dwc2->regs + epreg); if (value) { epctl |= DXEPCTL_STALL + DXEPCTL_SNAK; @@ -2683,10 +2682,10 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) epctl |= DXEPCTL_SETD0PID; } - writel(epctl, hs->regs + epreg); + writel(epctl, dwc2->regs + epreg); epreg = DOEPCTL(index); - epctl = readl(hs->regs + epreg); + epctl = readl(dwc2->regs + epreg); if (value) epctl |= DXEPCTL_STALL; @@ -2698,7 +2697,7 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) epctl |= DXEPCTL_SETD0PID; } - writel(epctl, hs->regs + epreg); + writel(epctl, dwc2->regs + epreg); hs_ep->halted = value; @@ -2713,13 +2712,13 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) static int s3c_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value) { struct s3c_hsotg_ep *hs_ep = our_ep(ep); - struct s3c_hsotg *hs = hs_ep->parent; + struct dwc2_hsotg *dwc2 = hs_ep->parent; unsigned long flags = 0; int ret = 0; - spin_lock_irqsave(&hs->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); ret = s3c_hsotg_ep_sethalt(ep, value); - spin_unlock_irqrestore(&hs->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); return ret; } @@ -2742,19 +2741,19 @@ static struct usb_ep_ops s3c_hsotg_ep_ops = { * A wrapper for platform code responsible for controlling * low-level USB code */ -static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) +static void s3c_hsotg_phy_enable(struct dwc2_hsotg *dwc2) { - struct platform_device *pdev = to_platform_device(hsotg->dev); + struct platform_device *pdev = to_platform_device(dwc2->dev); - dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); + dev_dbg(dwc2->dev, "pdev 0x%p\n", pdev); - if (hsotg->phy) { - phy_init(hsotg->phy); - phy_power_on(hsotg->phy); - } else if (hsotg->uphy) - usb_phy_init(hsotg->uphy); - else if (hsotg->plat->phy_init) - hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); + if (dwc2->s3c_hsotg->phy) { + phy_init(dwc2->s3c_hsotg->phy); + phy_power_on(dwc2->s3c_hsotg->phy); + } else if (dwc2->s3c_hsotg->uphy) + usb_phy_init(dwc2->s3c_hsotg->uphy); + else if (dwc2->s3c_hsotg->plat->phy_init) + dwc2->s3c_hsotg->plat->phy_init(pdev, dwc2->s3c_hsotg->plat->phy_type); } /** @@ -2764,60 +2763,60 @@ static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) * A wrapper for platform code responsible for controlling * low-level USB code */ -static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) +static void s3c_hsotg_phy_disable(struct dwc2_hsotg *dwc2) { - struct platform_device *pdev = to_platform_device(hsotg->dev); + struct platform_device *pdev = to_platform_device(dwc2->dev); - if (hsotg->phy) { - phy_power_off(hsotg->phy); - phy_exit(hsotg->phy); - } else if (hsotg->uphy) - usb_phy_shutdown(hsotg->uphy); - else if (hsotg->plat->phy_exit) - hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); + if (dwc2->s3c_hsotg->phy) { + phy_power_off(dwc2->s3c_hsotg->phy); + phy_exit(dwc2->s3c_hsotg->phy); + } else if (dwc2->s3c_hsotg->uphy) + usb_phy_shutdown(dwc2->s3c_hsotg->uphy); + else if (dwc2->s3c_hsotg->plat->phy_exit) + dwc2->s3c_hsotg->plat->phy_exit(pdev, dwc2->s3c_hsotg->plat->phy_type); } /** * s3c_hsotg_init - initalize the usb core * @hsotg: The driver state */ -static void s3c_hsotg_init(struct s3c_hsotg *hsotg) +static void s3c_hsotg_init(struct dwc2_hsotg *dwc2) { /* unmask subset of endpoint interrupts */ writel(DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK, - hsotg->regs + DIEPMSK); + dwc2->regs + DIEPMSK); writel(DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | DOEPMSK_EPDISBLDMSK | DOEPMSK_XFERCOMPLMSK, - hsotg->regs + DOEPMSK); + dwc2->regs + DOEPMSK); - writel(0, hsotg->regs + DAINTMSK); + writel(0, dwc2->regs + DAINTMSK); /* Be in disconnected state until gadget is registered */ - __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); + __orr32(dwc2->regs + DCTL, DCTL_SFTDISCON); if (0) { /* post global nak until we're ready */ writel(DCTL_SGNPINNAK | DCTL_SGOUTNAK, - hsotg->regs + DCTL); + dwc2->regs + DCTL); } /* setup fifos */ - dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", - readl(hsotg->regs + GRXFSIZ), - readl(hsotg->regs + GNPTXFSIZ)); + dev_dbg(dwc2->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", + readl(dwc2->regs + GRXFSIZ), + readl(dwc2->regs + GNPTXFSIZ)); - s3c_hsotg_init_fifo(hsotg); + s3c_hsotg_init_fifo(dwc2); /* set the PLL on, remove the HNP/SRP and set the PHY */ writel(GUSBCFG_PHYIF16 | GUSBCFG_TOUTCAL(7) | (0x5 << 10), - hsotg->regs + GUSBCFG); + dwc2->regs + GUSBCFG); - writel(using_dma(hsotg) ? GAHBCFG_DMA_EN : 0x0, - hsotg->regs + GAHBCFG); + writel(using_dma(dwc2->s3c_hsotg) ? GAHBCFG_DMA_EN : 0x0, + dwc2->regs + GAHBCFG); } /** @@ -2831,47 +2830,47 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) static int s3c_hsotg_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *driver) { - struct s3c_hsotg *hsotg = to_hsotg(gadget); + struct dwc2_hsotg *dwc2 = to_hsotg(gadget); int ret; - if (!hsotg) { + if (!dwc2) { pr_err("%s: called with no device\n", __func__); return -ENODEV; } if (!driver) { - dev_err(hsotg->dev, "%s: no driver\n", __func__); + dev_err(dwc2->dev, "%s: no driver\n", __func__); return -EINVAL; } if (driver->max_speed < USB_SPEED_FULL) - dev_err(hsotg->dev, "%s: bad speed\n", __func__); + dev_err(dwc2->dev, "%s: bad speed\n", __func__); if (!driver->setup) { - dev_err(hsotg->dev, "%s: missing entry points\n", __func__); + dev_err(dwc2->dev, "%s: missing entry points\n", __func__); return -EINVAL; } - WARN_ON(hsotg->driver); + WARN_ON(dwc2->driver); driver->driver.bus = NULL; - hsotg->driver = driver; - hsotg->gadget.dev.of_node = hsotg->dev->of_node; - hsotg->gadget.speed = USB_SPEED_UNKNOWN; + dwc2->driver = driver; + dwc2->gadget.dev.of_node = dwc2->dev->of_node; + dwc2->gadget.speed = USB_SPEED_UNKNOWN; - ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); + ret = regulator_bulk_enable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies), + dwc2->s3c_hsotg->supplies); if (ret) { - dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); + dev_err(dwc2->dev, "failed to enable supplies: %d\n", ret); goto err; } - hsotg->last_rst = jiffies; - dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); + dwc2->s3c_hsotg->last_rst = jiffies; + dev_info(dwc2->dev, "bound driver %s\n", driver->driver.name); return 0; err: - hsotg->driver = NULL; + dwc2->driver = NULL; return ret; } @@ -2885,29 +2884,30 @@ err: static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, struct usb_gadget_driver *driver) { - struct s3c_hsotg *hsotg = to_hsotg(gadget); + struct dwc2_hsotg *dwc2 = to_hsotg(gadget); unsigned long flags = 0; int ep; - if (!hsotg) + if (!dwc2) return -ENODEV; /* all endpoints should be shutdown */ - for (ep = 0; ep < hsotg->num_of_eps; ep++) - s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); + for (ep = 0; ep < dwc2->s3c_hsotg->num_of_eps; ep++) + s3c_hsotg_ep_disable(&dwc2->eps[ep].ep); - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); - s3c_hsotg_phy_disable(hsotg); + s3c_hsotg_phy_disable(dwc2); if (!driver) - hsotg->driver = NULL; + dwc2->driver = NULL; - hsotg->gadget.speed = USB_SPEED_UNKNOWN; + dwc2->gadget.speed = USB_SPEED_UNKNOWN; - spin_unlock_irqrestore(&hsotg->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); - regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); + regulator_bulk_disable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies), + dwc2->s3c_hsotg->supplies); return 0; } @@ -2932,22 +2932,22 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) */ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) { - struct s3c_hsotg *hsotg = to_hsotg(gadget); + struct dwc2_hsotg *dwc2 = to_hsotg(gadget); unsigned long flags = 0; - dev_dbg(hsotg->dev, "%s: is_in: %d\n", __func__, is_on); + dev_dbg(dwc2->dev, "%s: is_in: %d\n", __func__, is_on); - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); if (is_on) { - s3c_hsotg_phy_enable(hsotg); - s3c_hsotg_core_init(hsotg); + s3c_hsotg_phy_enable(dwc2); + s3c_hsotg_core_init(dwc2); } else { - s3c_hsotg_disconnect(hsotg); - s3c_hsotg_phy_disable(hsotg); + s3c_hsotg_disconnect(dwc2); + s3c_hsotg_phy_disable(dwc2); } - hsotg->gadget.speed = USB_SPEED_UNKNOWN; - spin_unlock_irqrestore(&hsotg->lock, flags); + dwc2->gadget.speed = USB_SPEED_UNKNOWN; + spin_unlock_irqrestore(&dwc2->lock, flags); return 0; } @@ -2969,7 +2969,7 @@ static const struct usb_gadget_ops s3c_hsotg_gadget_ops = { * creation) to give to the gadget driver. Setup the endpoint name, any * direction information and other state that may be required. */ -static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, +static void s3c_hsotg_initep(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *hs_ep, int epnum) { @@ -2994,9 +2994,9 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, /* add to the list of endpoints known by the gadget driver */ if (epnum) - list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); + list_add_tail(&hs_ep->ep.ep_list, &dwc2->gadget.ep_list); - hs_ep->parent = hsotg; + hs_ep->parent = dwc2; hs_ep->ep.name = hs_ep->name; usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT); hs_ep->ep.ops = &s3c_hsotg_ep_ops; @@ -3007,7 +3007,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, * code is changed to make each endpoint's direction changeable. */ - ptxfifo = readl(hsotg->regs + DPTXFSIZN(epnum)); + ptxfifo = readl(dwc2->regs + DPTXFSIZN(epnum)); hs_ep->fifo_size = FIFOSIZE_DEPTH_GET(ptxfifo) * 4; /* @@ -3015,10 +3015,10 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, * to be something valid. */ - if (using_dma(hsotg)) { + if (using_dma(dwc2->s3c_hsotg)) { u32 next = DXEPCTL_NEXTEP((epnum + 1) % 15); - writel(next, hsotg->regs + DIEPCTL(epnum)); - writel(next, hsotg->regs + DOEPCTL(epnum)); + writel(next, dwc2->regs + DIEPCTL(epnum)); + writel(next, dwc2->regs + DOEPCTL(epnum)); } } @@ -3028,32 +3028,32 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, * * Read the USB core HW configuration registers */ -static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) +static void s3c_hsotg_hw_cfg(struct dwc2_hsotg *dwc2) { u32 cfg2, cfg4; /* check hardware configuration */ - cfg2 = readl(hsotg->regs + 0x48); - hsotg->num_of_eps = (cfg2 >> 10) & 0xF; + cfg2 = readl(dwc2->regs + 0x48); + dwc2->s3c_hsotg->num_of_eps = (cfg2 >> 10) & 0xF; - dev_info(hsotg->dev, "EPs:%d\n", hsotg->num_of_eps); + dev_info(dwc2->dev, "EPs:%d\n", dwc2->s3c_hsotg->num_of_eps); - cfg4 = readl(hsotg->regs + 0x50); - hsotg->dedicated_fifos = (cfg4 >> 25) & 1; + cfg4 = readl(dwc2->regs + 0x50); + dwc2->s3c_hsotg->dedicated_fifos = (cfg4 >> 25) & 1; - dev_info(hsotg->dev, "%s fifos\n", - hsotg->dedicated_fifos ? "dedicated" : "shared"); + dev_info(dwc2->dev, "%s fifos\n", + dwc2->s3c_hsotg->dedicated_fifos ? "dedicated" : "shared"); } /** * s3c_hsotg_dump - dump state of the udc * @param: The device state */ -static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) +void s3c_hsotg_dump(struct dwc2_hsotg *dwc2) { #ifdef DEBUG - struct device *dev = hsotg->dev; - void __iomem *regs = hsotg->regs; + struct device *dev = dwc2->dev; + void __iomem *regs = dwc2->regs; u32 val; int idx; @@ -3108,8 +3108,8 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) */ static int state_show(struct seq_file *seq, void *v) { - struct s3c_hsotg *hsotg = seq->private; - void __iomem *regs = hsotg->regs; + struct dwc2_hsotg *dwc2 = seq->private; + void __iomem *regs = dwc2->regs; int idx; seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", @@ -3178,8 +3178,8 @@ static const struct file_operations state_fops = { */ static int fifo_show(struct seq_file *seq, void *v) { - struct s3c_hsotg *hsotg = seq->private; - void __iomem *regs = hsotg->regs; + struct dwc2_hsotg *dwc2 = seq->private; + void __iomem *regs = dwc2->regs; u32 val; int idx; @@ -3234,9 +3234,9 @@ static const char *decode_direction(int is_in) static int ep_show(struct seq_file *seq, void *v) { struct s3c_hsotg_ep *ep = seq->private; - struct s3c_hsotg *hsotg = ep->parent; + struct dwc2_hsotg *dwc2 = ep->parent; struct s3c_hsotg_req *req; - void __iomem *regs = hsotg->regs; + void __iomem *regs = dwc2->regs; int index = ep->index; int show_limit = 15; unsigned long flags; @@ -3269,7 +3269,7 @@ static int ep_show(struct seq_file *seq, void *v) seq_printf(seq, "request list (%p,%p):\n", ep->queue.next, ep->queue.prev); - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); list_for_each_entry(req, &ep->queue, queue) { if (--show_limit < 0) { @@ -3284,7 +3284,7 @@ static int ep_show(struct seq_file *seq, void *v) req->req.actual, req->req.status); } - spin_unlock_irqrestore(&hsotg->lock, flags); + spin_unlock_irqrestore(&dwc2->lock, flags); return 0; } @@ -3311,42 +3311,42 @@ static const struct file_operations ep_fops = { * with the same name as the device itself, in case we end up * with multiple blocks in future systems. */ -static void s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) +static void s3c_hsotg_create_debug(struct dwc2_hsotg *dwc2) { struct dentry *root; unsigned epidx; - root = debugfs_create_dir(dev_name(hsotg->dev), NULL); - hsotg->debug_root = root; + root = debugfs_create_dir(dev_name(dwc2->dev), NULL); + dwc2->s3c_hsotg->debug_root = root; if (IS_ERR(root)) { - dev_err(hsotg->dev, "cannot create debug root\n"); + dev_err(dwc2->dev, "cannot create debug root\n"); return; } /* create general state file */ - hsotg->debug_file = debugfs_create_file("state", 0444, root, - hsotg, &state_fops); + dwc2->s3c_hsotg->debug_file = debugfs_create_file("state", 0444, root, + dwc2, &state_fops); - if (IS_ERR(hsotg->debug_file)) - dev_err(hsotg->dev, "%s: failed to create state\n", __func__); + if (IS_ERR(dwc2->s3c_hsotg->debug_file)) + dev_err(dwc2->dev, "%s: failed to create state\n", __func__); - hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root, - hsotg, &fifo_fops); + dwc2->s3c_hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root, + dwc2, &fifo_fops); - if (IS_ERR(hsotg->debug_fifo)) - dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__); + if (IS_ERR(dwc2->s3c_hsotg->debug_fifo)) + dev_err(dwc2->dev, "%s: failed to create fifo\n", __func__); /* create one file for each endpoint */ - for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { - struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; + for (epidx = 0; epidx < dwc2->s3c_hsotg->num_of_eps; epidx++) { + struct s3c_hsotg_ep *ep = &dwc2->eps[epidx]; ep->debugfs = debugfs_create_file(ep->name, 0444, root, ep, &ep_fops); if (IS_ERR(ep->debugfs)) - dev_err(hsotg->dev, "failed to create %s debug file\n", + dev_err(dwc2->dev, "failed to create %s debug file\n", ep->name); } } @@ -3357,18 +3357,18 @@ static void s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) * * Cleanup (remove) the debugfs files for use on module exit. */ -static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) +static void s3c_hsotg_delete_debug(struct dwc2_hsotg *dwc2) { unsigned epidx; - for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { - struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; + for (epidx = 0; epidx < dwc2->s3c_hsotg->num_of_eps; epidx++) { + struct s3c_hsotg_ep *ep = &dwc2->eps[epidx]; debugfs_remove(ep->debugfs); } - debugfs_remove(hsotg->debug_file); - debugfs_remove(hsotg->debug_fifo); - debugfs_remove(hsotg->debug_root); + debugfs_remove(dwc2->s3c_hsotg->debug_file); + debugfs_remove(dwc2->s3c_hsotg->debug_fifo); + debugfs_remove(dwc2->s3c_hsotg->debug_root); } /** @@ -3573,73 +3573,69 @@ err_clk: * s3c_hsotg_remove - remove function for hsotg driver * @pdev: The platform information for the driver */ -static int s3c_hsotg_remove(struct platform_device *pdev) +static int s3c_hsotg_remove(struct dwc2_hsotg *dwc2) { - struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); + usb_del_gadget_udc(&dwc2->gadget); - usb_del_gadget_udc(&hsotg->gadget); + s3c_hsotg_delete_debug(dwc2); - s3c_hsotg_delete_debug(hsotg); - - if (hsotg->driver) { + if (dwc2->driver) { /* should have been done already by driver model core */ - usb_gadget_unregister_driver(hsotg->driver); + usb_gadget_unregister_driver(dwc2->driver); } - s3c_hsotg_phy_disable(hsotg); - if (hsotg->phy) - phy_exit(hsotg->phy); - clk_disable_unprepare(hsotg->clk); + s3c_hsotg_phy_disable(dwc2); + if (dwc2->s3c_hsotg->phy) + phy_exit(dwc2->s3c_hsotg->phy); + clk_disable_unprepare(dwc2->s3c_hsotg->clk); return 0; } -static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) +static int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2) { - struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); unsigned long flags; int ret = 0; - if (hsotg->driver) - dev_info(hsotg->dev, "suspending usb gadget %s\n", - hsotg->driver->driver.name); + if (dwc2->driver) + dev_info(dwc2->dev, "suspending usb gadget %s\n", + dwc2->driver->driver.name); - spin_lock_irqsave(&hsotg->lock, flags); - s3c_hsotg_disconnect(hsotg); - s3c_hsotg_phy_disable(hsotg); - hsotg->gadget.speed = USB_SPEED_UNKNOWN; - spin_unlock_irqrestore(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); + s3c_hsotg_disconnect(dwc2); + s3c_hsotg_phy_disable(dwc2); + dwc2->gadget.speed = USB_SPEED_UNKNOWN; + spin_unlock_irqrestore(&dwc2->lock, flags); - if (hsotg->driver) { + if (dwc2->driver) { int ep; - for (ep = 0; ep < hsotg->num_of_eps; ep++) - s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); + for (ep = 0; ep < dwc2->s3c_hsotg->num_of_eps; ep++) + s3c_hsotg_ep_disable(&dwc2->eps[ep].ep); - ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); + ret = regulator_bulk_disable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies), + dwc2->s3c_hsotg->supplies); } return ret; } -static int s3c_hsotg_resume(struct platform_device *pdev) +static int s3c_hsotg_resume(struct dwc2_hsotg *dwc2) { - struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); unsigned long flags; int ret = 0; - if (hsotg->driver) { - dev_info(hsotg->dev, "resuming usb gadget %s\n", - hsotg->driver->driver.name); - ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); + if (dwc2->driver) { + dev_info(dwc2->dev, "resuming usb gadget %s\n", + dwc2->driver->driver.name); + ret = regulator_bulk_enable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies), + dwc2->s3c_hsotg->supplies); } - spin_lock_irqsave(&hsotg->lock, flags); - hsotg->last_rst = jiffies; - s3c_hsotg_phy_enable(hsotg); - s3c_hsotg_core_init(hsotg); - spin_unlock_irqrestore(&hsotg->lock, flags); + spin_lock_irqsave(&dwc2->lock, flags); + dwc2->s3c_hsotg->last_rst = jiffies; + s3c_hsotg_phy_enable(dwc2); + s3c_hsotg_core_init(dwc2); + spin_unlock_irqrestore(&dwc2->lock, flags); return ret; } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html