From: Dinh Nguyen <dinguyen@xxxxxxxxxx> The dwc2_hsotg will be the main data structure for both the dwc2 and s3c-hsotg drivers. This patch adds the appropriate data structures into the dwc2_hsotg data structure in order for it to support both host and gadget functionality. This commit still keeps the dwc2 host and s3c_hsotg gadget driver separate. The only commonality is a single data structure, clock, register base, and irq. The majority of changes in this commit are edits to the s3c-hsotg.c file. The edits are dominated by changes in how the s3c_hsotg data structure are accessed directly that now have to be accessed through a pointer in the dwc2_hsotg structure. The gadget data structure is now also part of the dwc2_hsotg structure. The dwc2_hsotg data structure now has a pointer to the clk structure. The "otg" clock that was needed for the s3c_hsotg driver is now needed for both the dwc2 and s3c_hsotg drivers. Signed-off-by: Dinh Nguyen <dinguyen@xxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Paul Zimmerman <paulz@xxxxxxxxxxxx> Cc: Felipe Balbi <balbi@xxxxxx> Cc: Ben Dooks <ben-linux@xxxxxxxxx> Cc: Matt Porter <mporter@xxxxxxxxxx> Cc: Kukjin Kim <kgene.kim@xxxxxxxxxxx> Cc: Stephen Warren <swarren@xxxxxxxxxxxxx> Cc: Matthijs Kooijman <matthijs@xxxxxxxx> Cc: Jingoo Han <jg1.han@xxxxxxxxxxx> Cc: Sachin Kamat <sachin.kamat@xxxxxxxxxx> Cc: Robert Baldyga <r.baldyga@xxxxxxxxxxx> --- drivers/usb/dwc2/core.h | 29 +- drivers/usb/dwc2/platform.c | 30 +- drivers/usb/dwc2/s3c-hsotg.c | 1251 ++++++++++++++++++++---------------------- 3 files changed, 632 insertions(+), 678 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 1efd10c..1dae260 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -84,6 +84,8 @@ static const char * const s3c_hsotg_supply_names[] = { */ #define EP0_MPS_LIMIT 64 +struct dwc2_hsotg; +struct dwc2_host_chan; struct s3c_hsotg; struct s3c_hsotg_req; @@ -130,7 +132,7 @@ struct s3c_hsotg_req; struct s3c_hsotg_ep { struct usb_ep ep; struct list_head queue; - struct s3c_hsotg *parent; + struct dwc2_hsotg *parent; struct s3c_hsotg_req *req; struct dentry *debugfs; @@ -162,7 +164,6 @@ struct s3c_hsotg_ep { * @plat: The platform specific configuration data. This can be removed once * all SoCs support usb transceiver. * @regs: The memory area mapped for accessing registers. - * @irq: The IRQ number we are using * @supplies: Definition of USB power supplies * @phyif: PHY interface width * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. @@ -179,18 +180,10 @@ struct s3c_hsotg_ep { * @eps: The endpoints being supplied to the gadget framework */ struct s3c_hsotg { - struct device *dev; - struct usb_gadget_driver *driver; struct phy *phy; struct usb_phy *uphy; struct s3c_hsotg_plat *plat; - spinlock_t lock; - - void __iomem *regs; - int irq; - struct clk *clk; - struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; u32 phyif; @@ -206,10 +199,8 @@ struct s3c_hsotg { u8 ep0_buff[8]; u8 ctrl_buff[8]; - struct usb_gadget gadget; unsigned int setup; unsigned long last_rst; - struct s3c_hsotg_ep *eps; }; /** @@ -236,9 +227,6 @@ do { \ } \ } while (0) -struct dwc2_hsotg; -struct dwc2_host_chan; - /* Device States */ enum dwc2_lx_state { DWC2_L0, /* On state */ @@ -587,6 +575,8 @@ struct dwc2_hw_params { struct dwc2_hsotg { struct device *dev; void __iomem *regs; + struct clk *clk; + /** Params detected from hardware */ struct dwc2_hw_params hw_params; /** Params to actually use */ @@ -601,6 +591,11 @@ struct dwc2_hsotg { struct timer_list wkp_timer; enum dwc2_lx_state lx_state; + struct s3c_hsotg *s3c_hsotg; + struct usb_gadget gadget; + struct usb_gadget_driver *driver; + struct s3c_hsotg_ep *eps; + union dwc2_hcd_internal_flags { u32 d32; struct { @@ -947,4 +942,8 @@ extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg); */ extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg); +/* Gadget externs */ +extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq); +extern void s3c_hsotg_remove(struct dwc2_hsotg *dwc2); + #endif /* __DWC2_CORE_H__ */ diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index d01d0d3..c6fb4f2 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -34,6 +34,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <linux/clk.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> @@ -90,12 +91,16 @@ static int dwc2_driver_remove(struct platform_device *dev) { struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); - dwc2_hcd_remove(hsotg); + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) + dwc2_hcd_remove(hsotg); + else /* s3c-hsotg gadget */ + s3c_hsotg_remove(hsotg); return 0; } static const struct of_device_id dwc2_of_match_table[] = { + { .compatible = "samsung,s3c6400-hsotg", }, { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, { .compatible = "snps,dwc2", .data = NULL }, {}, @@ -129,7 +134,8 @@ static int dwc2_driver_probe(struct platform_device *dev) params = match->data; } else { /* Default all params to autodetect */ - dwc2_set_all_params(&defparams, -1); + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) + dwc2_set_all_params(&defparams, -1); params = &defparams; } @@ -162,9 +168,23 @@ static int dwc2_driver_probe(struct platform_device *dev) dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", (unsigned long)res->start, hsotg->regs); - retval = dwc2_hcd_init(hsotg, irq, params); - if (retval) - return retval; + /* Get clock */ + hsotg->clk = devm_clk_get(hsotg->dev, "otg"); + if (IS_ERR(hsotg->clk)) { + dev_err(hsotg->dev, "cannot get otg clock\n"); + return PTR_ERR(hsotg->clk); + } + clk_prepare_enable(hsotg->clk); + + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) { + retval = dwc2_hcd_init(hsotg, irq, params); + if (retval) + return retval; + } else {/* Enable s3c_hsotg gadget driver */ + retval = dwc2_gadget_init(hsotg, irq); + if (retval) + return retval; + } platform_set_drvdata(dev, hsotg); diff --git a/drivers/usb/dwc2/s3c-hsotg.c b/drivers/usb/dwc2/s3c-hsotg.c index f2766ab..59a97ee 100644 --- a/drivers/usb/dwc2/s3c-hsotg.c +++ b/drivers/usb/dwc2/s3c-hsotg.c @@ -50,9 +50,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) @@ -66,7 +66,7 @@ static inline void __bic32(void __iomem *ptr, u32 val) } /* forward decleration of functions */ -static void s3c_hsotg_dump(struct s3c_hsotg *hsotg); +static void s3c_hsotg_dump(struct dwc2_hsotg *dwc2); /** * using_dma - return the DMA status of the driver. @@ -97,16 +97,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) +static 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 +115,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) +static 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 +136,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 +148,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 +161,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,10 +171,10 @@ 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(DPTXFSIZN_DPTXFADDR(2048) | DPTXFSIZN_DPTXFSIZE(1024), - hsotg->regs + GNPTXFSIZ); + dwc2->regs + GNPTXFSIZ); /* * arange all the rest of the TX FIFOs, as some versions of this @@ -197,7 +197,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)); } /* @@ -206,18 +206,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); } @@ -225,7 +225,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); } /** @@ -269,7 +269,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) { @@ -279,7 +279,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); } /** @@ -298,12 +298,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; @@ -317,8 +317,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; @@ -334,11 +334,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); @@ -347,29 +347,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; } @@ -379,7 +379,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); /* @@ -399,8 +399,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); } @@ -428,13 +428,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) @@ -449,7 +449,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; - writesl(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); + writesl(dwc2->regs + EPFIFO(hs_ep->index), data, to_write); return (to_write >= can_write) ? -ENOSPC : 0; } @@ -503,7 +503,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) @@ -521,11 +521,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; @@ -535,23 +535,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 0x%08x noi=%d zp=%d snok=%d\n", ureq->buf, length, ureq->dma, ureq->no_interrupt, ureq->zero, ureq->short_not_ok); @@ -560,7 +560,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 */ @@ -576,7 +576,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; } @@ -601,16 +601,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; /* @@ -619,26 +619,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: 0x%08x => 0x%08x\n", + dev_dbg(dwc2->dev, "%s: 0x%08x => 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 @@ -648,11 +648,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); } /* @@ -661,7 +661,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 @@ -669,16 +669,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); } /** @@ -693,7 +693,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) { @@ -704,14 +704,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; @@ -722,10 +722,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); @@ -735,8 +735,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; } @@ -745,7 +745,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; } @@ -754,13 +754,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; } @@ -785,9 +785,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); } @@ -800,17 +800,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) @@ -829,7 +829,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) @@ -837,16 +837,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; @@ -858,7 +858,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; } @@ -870,18 +870,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; } @@ -897,7 +897,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; @@ -911,9 +911,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; } @@ -941,10 +941,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); @@ -952,13 +952,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; } @@ -969,9 +969,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; } @@ -998,7 +998,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); } } @@ -1014,8 +1014,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_process_control - process a control request @@ -1026,16 +1026,16 @@ static void s3c_hsotg_disconnect(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); @@ -1045,7 +1045,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 @@ -1057,36 +1057,36 @@ 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 |= ctrl->wValue << DCFG_DEVADDR_SHIFT; - 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); } /* @@ -1098,7 +1098,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, 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; /* @@ -1106,14 +1106,14 @@ static void s3c_hsotg_process_control(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)); /* * don't believe we need to anything more to get the EP @@ -1124,7 +1124,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, * complete won't be called, so we enqueue * setup request here */ - s3c_hsotg_enqueue_setup(hsotg); + s3c_hsotg_enqueue_setup(dwc2); } } @@ -1140,19 +1140,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); } /** @@ -1162,29 +1162,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. @@ -1205,7 +1205,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) @@ -1213,11 +1213,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); /* @@ -1231,8 +1231,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 @@ -1240,9 +1240,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); } /* @@ -1255,7 +1255,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); } } } @@ -1270,21 +1270,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); @@ -1299,7 +1299,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) { @@ -1335,36 +1335,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); } /** @@ -1377,22 +1377,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; /* @@ -1412,18 +1412,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); /* @@ -1438,10 +1438,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); } /** @@ -1450,11 +1450,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; @@ -1477,12 +1477,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) +static 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; @@ -1491,51 +1491,51 @@ 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); #define __status(x) ((x) >> GRXSTS_PKTSTS_SHIFT) switch (status >> GRXSTS_PKTSTS_SHIFT) { case __status(GRXSTS_PKTSTS_GLOBALOUTNAK): - dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); + dev_dbg(dwc2->dev, "GLOBALOUTNAK\n"); break; case __status(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 __status(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 __status(GRXSTS_PKTSTS_OUTRX): - s3c_hsotg_rx_data(hsotg, epnum, size); + s3c_hsotg_rx_data(dwc2, epnum, size); break; case __status(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; } } @@ -1571,11 +1571,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; @@ -1618,7 +1618,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); } /** @@ -1626,25 +1626,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); } @@ -1661,7 +1661,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; @@ -1672,15 +1672,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; @@ -1694,22 +1694,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; } @@ -1729,11 +1729,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); /* @@ -1750,17 +1750,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); } /** @@ -1771,23 +1771,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, +static 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) { @@ -1796,58 +1796,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 @@ -1858,33 +1858,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); } } } @@ -1896,9 +1896,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) +static 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; /* @@ -1907,7 +1907,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 @@ -1919,19 +1919,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 @@ -1939,8 +1939,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 @@ -1949,18 +1949,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)); } /** @@ -1973,7 +1973,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, +static void kill_all_requests(struct dwc2_hsotg *dwc2, struct s3c_hsotg_ep *ep, int result, bool force) { @@ -1988,12 +1988,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); } /** @@ -2004,14 +2004,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); } /** @@ -2019,15 +2019,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) +static 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; @@ -2036,7 +2036,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; } @@ -2053,33 +2053,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; @@ -2091,7 +2091,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; } @@ -2101,9 +2101,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) +static 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 @@ -2111,37 +2111,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 @@ -2149,49 +2149,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 @@ -2200,32 +2200,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); } /** @@ -2235,51 +2235,51 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) */ static irqreturn_t s3c_hsotg_irq(int irq, void *pw) { - struct s3c_hsotg *hsotg = pw; + struct dwc2_hsotg *dwc2 = pw; int retry_count = 8; u32 gintsts; u32 gintmsk; - spin_lock(&hsotg->lock); + spin_lock(&dwc2->lock); irq_retry: - gintsts = readl(hsotg->regs + GINTSTS); - gintmsk = readl(hsotg->regs + GINTMSK); + gintsts = readl(dwc2->regs + GINTSTS); + gintmsk = readl(dwc2->regs + GINTMSK); - dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", + dev_dbg(dwc2->dev, "%s: %08x %08x (%08x) retry %d\n", __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count); gintsts &= gintmsk; if (gintsts & GINTSTS_OTGINT) { - u32 otgint = readl(hsotg->regs + GOTGINT); + u32 otgint = readl(dwc2->regs + GOTGINT); - dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); + dev_info(dwc2->dev, "OTGInt: %08x\n", otgint); - writel(otgint, hsotg->regs + GOTGINT); + writel(otgint, dwc2->regs + GOTGINT); } if (gintsts & GINTSTS_SESSREQINT) { - dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); - writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); + dev_dbg(dwc2->dev, "%s: SessReqInt\n", __func__); + writel(GINTSTS_SESSREQINT, dwc2->regs + GINTSTS); } if (gintsts & GINTSTS_ENUMDONE) { - writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); + writel(GINTSTS_ENUMDONE, dwc2->regs + GINTSTS); - s3c_hsotg_irq_enumdone(hsotg); + s3c_hsotg_irq_enumdone(dwc2); } if (gintsts & GINTSTS_CONIDSTSCHNG) { - dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", - readl(hsotg->regs + DSTS), - readl(hsotg->regs + GOTGCTL)); + dev_dbg(dwc2->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", + readl(dwc2->regs + DSTS), + readl(dwc2->regs + GOTGCTL)); - writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); + writel(GINTSTS_CONIDSTSCHNG, dwc2->regs + GINTSTS); } if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { - u32 daint = readl(hsotg->regs + DAINT); - u32 daintmsk = readl(hsotg->regs + DAINTMSK); + u32 daint = readl(dwc2->regs + DAINT); + u32 daintmsk = readl(dwc2->regs + DAINTMSK); u32 daint_out, daint_in; int ep; @@ -2287,38 +2287,38 @@ irq_retry: daint_out = daint >> DAINT_OUTEP_SHIFT; daint_in = daint & ~(daint_out << DAINT_OUTEP_SHIFT); - dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); + dev_dbg(dwc2->dev, "%s: daint=%08x\n", __func__, daint); for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { if (daint_out & 1) - s3c_hsotg_epint(hsotg, ep, 0); + s3c_hsotg_epint(dwc2, ep, 0); } for (ep = 0; ep < 15 && daint_in; ep++, daint_in >>= 1) { if (daint_in & 1) - s3c_hsotg_epint(hsotg, ep, 1); + s3c_hsotg_epint(dwc2, ep, 1); } } if (gintsts & GINTSTS_USBRST) { - u32 usb_status = readl(hsotg->regs + GOTGCTL); + u32 usb_status = readl(dwc2->regs + GOTGCTL); - dev_info(hsotg->dev, "%s: USBRst\n", __func__); - dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", - readl(hsotg->regs + GNPTXSTS)); + dev_info(dwc2->dev, "%s: USBRst\n", __func__); + dev_dbg(dwc2->dev, "GNPTXSTS=%08x\n", + readl(dwc2->regs + GNPTXSTS)); - writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); + writel(GINTSTS_USBRST, dwc2->regs + GINTSTS); if (usb_status & GOTGCTL_BSESVLD) { - if (time_after(jiffies, hsotg->last_rst + + if (time_after(jiffies, dwc2->s3c_hsotg->last_rst + msecs_to_jiffies(200))) { - kill_all_requests(hsotg, &hsotg->eps[0], + kill_all_requests(dwc2, &dwc2->eps[0], -ECONNRESET, true); - s3c_hsotg_core_init(hsotg); - hsotg->last_rst = jiffies; + s3c_hsotg_core_init(dwc2); + dwc2->s3c_hsotg->last_rst = jiffies; } } } @@ -2326,7 +2326,7 @@ irq_retry: /* check both FIFOs */ if (gintsts & GINTSTS_NPTXFEMP) { - dev_dbg(hsotg->dev, "NPTxFEmp\n"); + dev_dbg(dwc2->dev, "NPTxFEmp\n"); /* * Disable the interrupt to stop it happening again @@ -2334,17 +2334,17 @@ irq_retry: * it needs re-enabling */ - s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); - s3c_hsotg_irq_fifoempty(hsotg, false); + s3c_hsotg_disable_gsint(dwc2, GINTSTS_NPTXFEMP); + s3c_hsotg_irq_fifoempty(dwc2, false); } if (gintsts & GINTSTS_PTXFEMP) { - dev_dbg(hsotg->dev, "PTxFEmp\n"); + dev_dbg(dwc2->dev, "PTxFEmp\n"); /* See note in GINTSTS_NPTxFEmp */ - s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); - s3c_hsotg_irq_fifoempty(hsotg, true); + s3c_hsotg_disable_gsint(dwc2, GINTSTS_PTXFEMP); + s3c_hsotg_irq_fifoempty(dwc2, true); } if (gintsts & GINTSTS_RXFLVL) { @@ -2354,31 +2354,31 @@ irq_retry: * set. */ - s3c_hsotg_handle_rx(hsotg); + s3c_hsotg_handle_rx(dwc2); } if (gintsts & GINTSTS_MODEMIS) { - dev_warn(hsotg->dev, "warning, mode mismatch triggered\n"); - writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); + dev_warn(dwc2->dev, "warning, mode mismatch triggered\n"); + writel(GINTSTS_MODEMIS, dwc2->regs + GINTSTS); } if (gintsts & GINTSTS_USBSUSP) { - dev_info(hsotg->dev, "GINTSTS_USBSusp\n"); - writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); + dev_info(dwc2->dev, "GINTSTS_USBSusp\n"); + writel(GINTSTS_USBSUSP, dwc2->regs + GINTSTS); - call_gadget(hsotg, suspend); + call_gadget(dwc2, suspend); } if (gintsts & GINTSTS_WKUPINT) { - dev_info(hsotg->dev, "GINTSTS_WkUpIn\n"); - writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); + dev_info(dwc2->dev, "GINTSTS_WkUpIn\n"); + writel(GINTSTS_WKUPINT, dwc2->regs + GINTSTS); - call_gadget(hsotg, resume); + call_gadget(dwc2, resume); } if (gintsts & GINTSTS_ERLYSUSP) { - dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); - writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); + dev_dbg(dwc2->dev, "GINTSTS_ErlySusp\n"); + writel(GINTSTS_ERLYSUSP, dwc2->regs + GINTSTS); } /* @@ -2388,19 +2388,19 @@ irq_retry: */ if (gintsts & GINTSTS_GOUTNAKEFF) { - dev_info(hsotg->dev, "GOUTNakEff triggered\n"); + dev_info(dwc2->dev, "GOUTNakEff triggered\n"); - writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); + writel(DCTL_CGOUTNAK, dwc2->regs + DCTL); - s3c_hsotg_dump(hsotg); + s3c_hsotg_dump(dwc2); } if (gintsts & GINTSTS_GINNAKEFF) { - dev_info(hsotg->dev, "GINNakEff triggered\n"); + dev_info(dwc2->dev, "GINNakEff triggered\n"); - writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); + writel(DCTL_CGNPINNAK, dwc2->regs + DCTL); - s3c_hsotg_dump(hsotg); + s3c_hsotg_dump(dwc2); } /* @@ -2411,7 +2411,7 @@ irq_retry: if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) goto irq_retry; - spin_unlock(&hsotg->lock); + spin_unlock(&dwc2->lock); return IRQ_HANDLED; } @@ -2427,7 +2427,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; @@ -2436,7 +2436,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); @@ -2446,7 +2446,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; } @@ -2455,12 +2455,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); @@ -2481,7 +2481,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; @@ -2490,7 +2490,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: @@ -2530,24 +2530,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; } @@ -2558,39 +2558,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; } @@ -2620,7 +2620,7 @@ 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 *hs = hs_ep->parent; unsigned long flags; dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); @@ -2646,7 +2646,7 @@ 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 *hs = hs_ep->parent; int index = hs_ep->index; u32 epreg; u32 epctl; @@ -2701,7 +2701,7 @@ 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 *hs = hs_ep->parent; unsigned long flags = 0; int ret = 0; @@ -2730,19 +2730,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); } /** @@ -2752,60 +2752,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); } /** @@ -2819,47 +2819,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; } @@ -2873,29 +2873,29 @@ 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; } @@ -2920,22 +2920,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; } @@ -2957,7 +2957,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) { @@ -2982,9 +2982,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; @@ -2995,7 +2995,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 = DPTXFSIZN_DPTXFSIZE_GET(ptxfifo) * 4; /* @@ -3003,10 +3003,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)); } } @@ -3016,32 +3016,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) +static 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; @@ -3096,8 +3096,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", @@ -3166,8 +3166,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; @@ -3222,9 +3222,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; @@ -3257,7 +3257,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) { @@ -3272,7 +3272,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; } @@ -3299,42 +3299,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->s3c_hsotg, &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->s3c_hsotg, &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); } } @@ -3345,18 +3345,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); } /** @@ -3364,21 +3364,19 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) * @pdev: The platform information for the driver */ -static int s3c_hsotg_probe(struct platform_device *pdev) +int dwc2_gadget_init(struct dwc2_hsotg *dwc2, int irq) { - struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); + struct s3c_hsotg_plat *plat = dev_get_platdata(dwc2->dev); struct phy *phy; struct usb_phy *uphy; - struct device *dev = &pdev->dev; + struct device *dev = dwc2->dev; struct s3c_hsotg_ep *eps; - struct s3c_hsotg *hsotg; - struct resource *res; int epnum; int ret; int i; - hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); - if (!hsotg) { + dwc2->s3c_hsotg = devm_kzalloc(dwc2->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); + if (!dwc2->s3c_hsotg) { dev_err(dev, "cannot get memory\n"); return -ENOMEM; } @@ -3387,117 +3385,85 @@ static int s3c_hsotg_probe(struct platform_device *pdev) * Attempt to find a generic PHY, then look for an old style * USB PHY, finally fall back to pdata */ - phy = devm_phy_get(&pdev->dev, "usb2-phy"); + phy = devm_phy_get(dwc2->dev, "usb2-phy"); if (IS_ERR(phy)) { uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); if (IS_ERR(uphy)) { /* Fallback for pdata */ - plat = dev_get_platdata(&pdev->dev); + plat = dev_get_platdata(dwc2->dev); if (!plat) { - dev_err(&pdev->dev, + dev_err(dwc2->dev, "no platform data or transceiver defined\n"); return -EPROBE_DEFER; } - hsotg->plat = plat; + dwc2->s3c_hsotg->plat = plat; } else - hsotg->uphy = uphy; + dwc2->s3c_hsotg->uphy = uphy; } else - hsotg->phy = phy; - - hsotg->dev = dev; - - hsotg->clk = devm_clk_get(&pdev->dev, "otg"); - if (IS_ERR(hsotg->clk)) { - dev_err(dev, "cannot get otg clock\n"); - return PTR_ERR(hsotg->clk); - } - - platform_set_drvdata(pdev, hsotg); - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + dwc2->s3c_hsotg->phy = phy; - hsotg->regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(hsotg->regs)) { - ret = PTR_ERR(hsotg->regs); - goto err_clk; - } + spin_lock_init(&dwc2->lock); - ret = platform_get_irq(pdev, 0); - if (ret < 0) { - dev_err(dev, "cannot find IRQ\n"); - goto err_clk; - } - - spin_lock_init(&hsotg->lock); - - hsotg->irq = ret; - - ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0, - dev_name(dev), hsotg); + ret = devm_request_irq(dwc2->dev, irq, s3c_hsotg_irq, 0, + dev_name(dev), dwc2); if (ret < 0) { dev_err(dev, "cannot claim IRQ\n"); - goto err_clk; + return ret; } - dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); - - hsotg->gadget.max_speed = USB_SPEED_HIGH; - hsotg->gadget.ops = &s3c_hsotg_gadget_ops; - hsotg->gadget.name = dev_name(dev); - - /* reset the system */ - - clk_prepare_enable(hsotg->clk); + dwc2->gadget.max_speed = USB_SPEED_HIGH; + dwc2->gadget.ops = &s3c_hsotg_gadget_ops; + dwc2->gadget.name = dev_name(dev); /* regulators */ - for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) - hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; + for (i = 0; i < ARRAY_SIZE(dwc2->s3c_hsotg->supplies); i++) + dwc2->s3c_hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; - ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(dwc2->s3c_hsotg->supplies), + dwc2->s3c_hsotg->supplies); if (ret) { dev_err(dev, "failed to request supplies: %d\n", ret); - goto err_clk; + goto err_supplies; } - 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_supplies; } /* Set default UTMI width */ - hsotg->phyif = GUSBCFG_PHYIF16; + dwc2->s3c_hsotg->phyif = GUSBCFG_PHYIF16; /* * If using the generic PHY framework, check if the PHY bus * width is 8-bit and set the phyif appropriately. */ - if (hsotg->phy && (phy_get_bus_width(phy) == 8)) - hsotg->phyif = GUSBCFG_PHYIF8; + if (dwc2->s3c_hsotg->phy && (phy_get_bus_width(phy) == 8)) + dwc2->s3c_hsotg->phyif = GUSBCFG_PHYIF8; - if (hsotg->phy) - phy_init(hsotg->phy); + if (dwc2->s3c_hsotg->phy) + phy_init(dwc2->s3c_hsotg->phy); /* usb phy enable */ - s3c_hsotg_phy_enable(hsotg); + s3c_hsotg_phy_enable(dwc2); - s3c_hsotg_corereset(hsotg); - s3c_hsotg_init(hsotg); - s3c_hsotg_hw_cfg(hsotg); + s3c_hsotg_corereset(dwc2); + s3c_hsotg_init(dwc2); + s3c_hsotg_hw_cfg(dwc2); /* hsotg->num_of_eps holds number of EPs other than ep0 */ - if (hsotg->num_of_eps == 0) { + if (dwc2->s3c_hsotg->num_of_eps == 0) { dev_err(dev, "wrong number of EPs (zero)\n"); ret = -EINVAL; goto err_supplies; } - eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), + eps = kcalloc(dwc2->s3c_hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), GFP_KERNEL); if (!eps) { dev_err(dev, "cannot get memory\n"); @@ -3505,54 +3471,52 @@ static int s3c_hsotg_probe(struct platform_device *pdev) goto err_supplies; } - hsotg->eps = eps; + dwc2->eps = eps; /* setup endpoint information */ - INIT_LIST_HEAD(&hsotg->gadget.ep_list); - hsotg->gadget.ep0 = &hsotg->eps[0].ep; + INIT_LIST_HEAD(&dwc2->gadget.ep_list); + dwc2->gadget.ep0 = &dwc2->eps[0].ep; /* allocate EP0 request */ - hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep, + dwc2->s3c_hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&dwc2->eps[0].ep, GFP_KERNEL); - if (!hsotg->ctrl_req) { + if (!dwc2->s3c_hsotg->ctrl_req) { dev_err(dev, "failed to allocate ctrl req\n"); ret = -ENOMEM; goto err_ep_mem; } /* initialise the endpoints now the core has been initialised */ - for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) - s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); + for (epnum = 0; epnum < dwc2->s3c_hsotg->num_of_eps; epnum++) + s3c_hsotg_initep(dwc2, &dwc2->eps[epnum], epnum); /* disable power and clock */ - ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); + ret = regulator_bulk_disable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies), + dwc2->s3c_hsotg->supplies); if (ret) { - dev_err(hsotg->dev, "failed to disable supplies: %d\n", ret); + dev_err(dwc2->dev, "failed to disable supplies: %d\n", ret); goto err_ep_mem; } - s3c_hsotg_phy_disable(hsotg); + s3c_hsotg_phy_disable(dwc2); - ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); + ret = usb_add_gadget_udc(dwc2->dev, &dwc2->gadget); if (ret) goto err_ep_mem; - s3c_hsotg_create_debug(hsotg); + s3c_hsotg_create_debug(dwc2); - s3c_hsotg_dump(hsotg); + s3c_hsotg_dump(dwc2); return 0; err_ep_mem: kfree(eps); err_supplies: - s3c_hsotg_phy_disable(hsotg); -err_clk: - clk_disable_unprepare(hsotg->clk); + s3c_hsotg_phy_disable(dwc2); return ret; } @@ -3561,54 +3525,25 @@ 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) +void 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); - - return 0; + s3c_hsotg_phy_disable(dwc2); + if (dwc2->s3c_hsotg->phy) + phy_exit(dwc2->s3c_hsotg->phy); + clk_disable_unprepare(dwc2->clk); } -#if 1 #define s3c_hsotg_suspend NULL #define s3c_hsotg_resume NULL -#endif - -#ifdef CONFIG_OF -static const struct of_device_id s3c_hsotg_of_ids[] = { - { .compatible = "samsung,s3c6400-hsotg", }, - { .compatible = "snps,dwc2", }, - { /* sentinel */ } -}; -MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids); -#endif - -static struct platform_driver s3c_hsotg_driver = { - .driver = { - .name = "s3c-hsotg", - .owner = THIS_MODULE, - .of_match_table = of_match_ptr(s3c_hsotg_of_ids), - }, - .probe = s3c_hsotg_probe, - .remove = s3c_hsotg_remove, - .suspend = s3c_hsotg_suspend, - .resume = s3c_hsotg_resume, -}; - -module_platform_driver(s3c_hsotg_driver); MODULE_DESCRIPTION("Samsung S3C USB High-speed/OtG device"); MODULE_AUTHOR("Ben Dooks <ben@xxxxxxxxxxxx>"); -- 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