From: Dinh Nguyen <dingu...@altera.com>

Update gadget.c to use the dwc2_hsotg data structure and gadget pointers
that have been moved into the common dwc2_hsotg structure. Along
with the updating the gadget driver to use the common dwc2_hsotg structure,
a few other things are required in order for this patch to build properly.
Those are:

- Add proper externs for functions that need to be shared between host
  and peripheral drivers.
- Remove gadget module defines. Since the driver probing will be handled
  by either the platform or pci code.
- Change the gadget probe function into gadget_init.

Signed-off-by: Dinh Nguyen <dingu...@altera.com>
---
v2: Left the function parameter name as 'hsotg' and just changed its type.
---
 drivers/usb/dwc2/core.h   |   25 ++-
 drivers/usb/dwc2/gadget.c |  451 ++++++++++++++++++++-------------------------
 drivers/usb/dwc2/hcd.h    |   10 -
 3 files changed, 221 insertions(+), 265 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index ee34ee1..8d901b3 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -84,7 +84,7 @@ static const char * const s3c_hsotg_supply_names[] = {
  */
 #define EP0_MPS_LIMIT   64
 
-struct s3c_hsotg;
+struct dwc2_hsotg;
 struct s3c_hsotg_req;
 
 /**
@@ -130,7 +130,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;
 
@@ -956,4 +956,25 @@ extern void dwc2_dump_global_registers(struct dwc2_hsotg 
*hsotg);
  */
 extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
 
+#if defined(CONFIG_USB_DWC2_HOST) || defined(CONFIG_USB_DWC2_DUAL_ROLE)
+/**
+ * dwc2_hcd_get_frame_number() - Returns current frame number
+ *
+ * @hsotg: The DWC2 HCD
+ */
+extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
+extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
+extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
+#else
+static inline void dwc2_set_all_params(struct dwc2_core_params *params, int 
value) {}
+static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
+{ return 0; }
+static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
+static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
+static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
+static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
+               const struct dwc2_core_params *params)
+{ return 0; }
+#endif
+
 #endif /* __DWC2_CORE_H__ */
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index c62f6c2..c9c0d51 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -38,6 +38,7 @@
 #include <linux/platform_data/s3c-hsotg.h>
 
 #include "core.h"
+#include "hw.h"
 
 /* conversion functions */
 static inline struct s3c_hsotg_req *our_req(struct usb_request *req)
@@ -50,9 +51,9 @@ static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep)
        return container_of(ep, struct s3c_hsotg_ep, ep);
 }
 
-static inline struct s3c_hsotg *to_hsotg(struct usb_gadget *gadget)
+static inline struct dwc2_hsotg *to_hsotg(struct usb_gadget *gadget)
 {
-       return container_of(gadget, struct s3c_hsotg, gadget);
+       return container_of(gadget, struct dwc2_hsotg, gadget);
 }
 
 static inline void __orr32(void __iomem *ptr, u32 val)
@@ -66,7 +67,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 *hsotg);
 
 /**
  * using_dma - return the DMA status of the driver.
@@ -97,7 +98,7 @@ 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 *hsotg, u32 ints)
 {
        u32 gsintmsk = readl(hsotg->regs + GINTMSK);
        u32 new_gsintmsk;
@@ -115,7 +116,7 @@ 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 *hsotg, u32 ints)
 {
        u32 gsintmsk = readl(hsotg->regs + GINTMSK);
        u32 new_gsintmsk;
@@ -136,7 +137,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 *hsotg,
                                 unsigned int ep, unsigned int dir_in,
                                 unsigned int en)
 {
@@ -161,7 +162,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 *hsotg)
 {
        unsigned int ep;
        unsigned int addr;
@@ -198,7 +199,7 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
        for (ep = 1; ep <= 4; ep++) {
                val = addr;
                val |= size << FIFOSIZE_DEPTH_SHIFT;
-               WARN_ONCE(addr + size > hsotg->fifo_mem,
+               WARN_ONCE(addr + size > hsotg->s3c_hsotg->fifo_mem,
                          "insufficient fifo memory");
                addr += size;
 
@@ -209,7 +210,7 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
        for (ep = 5; ep <= 8; ep++) {
                val = addr;
                val |= size << FIFOSIZE_DEPTH_SHIFT;
-               WARN_ONCE(addr + size > hsotg->fifo_mem,
+               WARN_ONCE(addr + size > hsotg->s3c_hsotg->fifo_mem,
                          "insufficient fifo memory");
                addr += size;
 
@@ -285,7 +286,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 *hsotg,
                                struct s3c_hsotg_ep *hs_ep,
                                struct s3c_hsotg_req *hs_req)
 {
@@ -314,7 +315,7 @@ 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 *hsotg,
                                struct s3c_hsotg_ep *hs_ep,
                                struct s3c_hsotg_req *hs_req)
 {
@@ -333,7 +334,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
        if (to_write == 0)
                return 0;
 
-       if (periodic && !hsotg->dedicated_fifos) {
+       if (periodic && !hsotg->s3c_hsotg->dedicated_fifos) {
                u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index));
                int size_left;
                int size_done;
@@ -374,7 +375,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
                        s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP);
                        return -ENOSPC;
                }
-       } else if (hsotg->dedicated_fifos && hs_ep->index != 0) {
+       } else if (hsotg->s3c_hsotg->dedicated_fifos && hs_ep->index != 0) {
                can_write = readl(hsotg->regs + DTXFSTS(hs_ep->index));
 
                can_write &= 0xffff;
@@ -415,7 +416,7 @@ 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)
+               if (!hsotg->s3c_hsotg->dedicated_fifos)
                        s3c_hsotg_en_gsint(hsotg,
                                           periodic ? GINTSTS_PTXFEMP :
                                           GINTSTS_NPTXFEMP);
@@ -444,7 +445,7 @@ 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)
+               if (!hsotg->s3c_hsotg->dedicated_fifos)
                        s3c_hsotg_en_gsint(hsotg,
                                           periodic ? GINTSTS_PTXFEMP :
                                           GINTSTS_NPTXFEMP);
@@ -519,7 +520,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 *hsotg,
                                struct s3c_hsotg_ep *hs_ep,
                                struct s3c_hsotg_req *hs_req,
                                bool continuing)
@@ -626,7 +627,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
        /* write size / packets */
        writel(epsize, hsotg->regs + epsize_reg);
 
-       if (using_dma(hsotg) && !continuing) {
+       if (using_dma(hsotg->s3c_hsotg) && !continuing) {
                unsigned int dma_reg;
 
                /*
@@ -644,11 +645,11 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
        ctrl |= DXEPCTL_EPENA;  /* ensure ep enabled */
        ctrl |= DXEPCTL_USBACTEP;
 
-       dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->setup);
+       dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->s3c_hsotg->setup);
 
        /* For Setup request do not clear NAK */
-       if (hsotg->setup && index == 0)
-               hsotg->setup = 0;
+       if (hsotg->s3c_hsotg->setup && index == 0)
+               hsotg->s3c_hsotg->setup = 0;
        else
                ctrl |= DXEPCTL_CNAK;   /* clear NAK set by core */
 
@@ -664,7 +665,7 @@ 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(hsotg->s3c_hsotg)) {
                /* set these anyway, we may need them for non-periodic in */
                hs_ep->fifo_load = 0;
 
@@ -709,7 +710,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 *hsotg,
                             struct s3c_hsotg_ep *hs_ep,
                             struct usb_request *req)
 {
@@ -738,7 +739,7 @@ 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 *hs = hs_ep->parent;
        bool first;
 
        dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n",
@@ -751,7 +752,7 @@ 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)) {
+       if (using_dma(hs->s3c_hsotg)) {
                int ret = s3c_hsotg_map_dma(hs, hs_ep, req);
                if (ret)
                        return ret;
@@ -770,7 +771,7 @@ 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 *hs = hs_ep->parent;
        unsigned long flags = 0;
        int ret = 0;
 
@@ -801,7 +802,7 @@ 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 *hsotg = hs_ep->parent;
 
        dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req);
 
@@ -816,7 +817,7 @@ 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 *hsotg,
                                           u32 windex)
 {
        struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F];
@@ -826,7 +827,7 @@ static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg 
*hsotg,
        if (windex >= 0x100)
                return NULL;
 
-       if (idx > hsotg->num_of_eps)
+       if (idx > hsotg->s3c_hsotg->num_of_eps)
                return NULL;
 
        if (idx && ep->dir_in != dir)
@@ -845,7 +846,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 *hsotg,
                                struct s3c_hsotg_ep *ep,
                                void *buff,
                                int length)
@@ -856,13 +857,13 @@ static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg,
        dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length);
 
        req = s3c_hsotg_ep_alloc_request(&ep->ep, GFP_ATOMIC);
-       hsotg->ep0_reply = req;
+       hsotg->s3c_hsotg->ep0_reply = req;
        if (!req) {
                dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__);
                return -ENOMEM;
        }
 
-       req->buf = hsotg->ep0_buff;
+       req->buf = hsotg->s3c_hsotg->ep0_buff;
        req->length = length;
        req->zero = 1; /* always do zero-length final transfer */
        req->complete = s3c_hsotg_complete_oursetup;
@@ -886,7 +887,7 @@ 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 *hsotg,
                                        struct usb_ctrlrequest *ctrl)
 {
        struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
@@ -957,7 +958,7 @@ 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 *hsotg,
                                         struct usb_ctrlrequest *ctrl)
 {
        struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
@@ -1030,8 +1031,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 *hsotg);
+static void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg);
 
 /**
  * s3c_hsotg_stall_ep0 - stall ep0
@@ -1039,7 +1040,8 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg);
  *
  * Set stall for ep0 as response for setup request.
  */
-static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) {
+static void s3c_hsotg_stall_ep0(struct dwc2_hsotg *hsotg)
+{
        struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
        u32 reg;
        u32 ctrl;
@@ -1077,7 +1079,7 @@ static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) {
  * needs to work out what to do next (and whether to pass it on to the
  * gadget driver).
  */
-static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
+static void s3c_hsotg_process_control(struct dwc2_hsotg *hsotg,
                                      struct usb_ctrlrequest *ctrl)
 {
        struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
@@ -1162,7 +1164,7 @@ 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 *hsotg = hs_ep->parent;
 
        if (req->status < 0) {
                dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status);
@@ -1184,9 +1186,9 @@ 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 *hsotg)
 {
-       struct usb_request *req = hsotg->ctrl_req;
+       struct usb_request *req = hsotg->s3c_hsotg->ctrl_req;
        struct s3c_hsotg_req *hs_req = our_req(req);
        int ret;
 
@@ -1194,7 +1196,7 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg 
*hsotg)
 
        req->zero = 0;
        req->length = 8;
-       req->buf = hsotg->ctrl_buff;
+       req->buf = hsotg->s3c_hsotg->ctrl_buff;
        req->complete = s3c_hsotg_complete_setup;
 
        if (!list_empty(&hs_req->queue)) {
@@ -1227,7 +1229,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 *hsotg,
                                       struct s3c_hsotg_ep *hs_ep,
                                       struct s3c_hsotg_req *hs_req,
                                       int result)
@@ -1253,7 +1255,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg 
*hsotg,
        hs_ep->req = NULL;
        list_del_init(&hs_req->queue);
 
-       if (using_dma(hsotg))
+       if (using_dma(hsotg->s3c_hsotg))
                s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req);
 
        /*
@@ -1292,7 +1294,7 @@ 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 *hsotg, int ep_idx, int size)
 {
        struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx];
        struct s3c_hsotg_req *hs_req = hs_ep->req;
@@ -1357,7 +1359,7 @@ 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 *hsotg,
                               struct s3c_hsotg_req *req)
 {
        u32 ctrl;
@@ -1399,7 +1401,7 @@ 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 *hsotg,
                                     int epnum, bool was_setup)
 {
        u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum));
@@ -1414,7 +1416,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg 
*hsotg,
                return;
        }
 
-       if (using_dma(hsotg)) {
+       if (using_dma(hsotg->s3c_hsotg)) {
                unsigned size_done;
 
                /*
@@ -1441,7 +1443,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg 
*hsotg,
                 * After was_setup = 1 =>
                 * set CNAK for non Setup requests
                 */
-               hsotg->setup = was_setup ? 0 : 1;
+               hsotg->s3c_hsotg->setup = was_setup ? 0 : 1;
        }
 
        if (req->actual < req->length && req->short_not_ok) {
@@ -1472,7 +1474,7 @@ 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 *hsotg)
 {
        u32 dsts;
 
@@ -1499,12 +1501,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 *hsotg)
 {
        u32 grxstsr = readl(hsotg->regs + GRXSTSP);
        u32 epnum, status, size;
 
-       WARN_ON(using_dma(hsotg));
+       WARN_ON(using_dma(hsotg->s3c_hsotg));
 
        epnum = grxstsr & GRXSTS_EPNUM_MASK;
        status = grxstsr & GRXSTS_PKTSTS_MASK;
@@ -1525,7 +1527,7 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg)
                dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n",
                        s3c_hsotg_read_frameno(hsotg));
 
-               if (!using_dma(hsotg))
+               if (!using_dma(hsotg->s3c_hsotg))
                        s3c_hsotg_handle_outdone(hsotg, epnum, false);
                break;
 
@@ -1591,7 +1593,7 @@ 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 *hsotg,
                                       unsigned int ep, unsigned int mps)
 {
        struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep];
@@ -1646,7 +1648,7 @@ 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 *hsotg, unsigned int idx)
 {
        int timeout;
        int val;
@@ -1682,7 +1684,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 *hsotg,
                           struct s3c_hsotg_ep *hs_ep)
 {
        struct s3c_hsotg_req *hs_req = hs_ep->req;
@@ -1715,7 +1717,7 @@ 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 *hsotg,
                                  struct s3c_hsotg_ep *hs_ep)
 {
        struct s3c_hsotg_req *hs_req = hs_ep->req;
@@ -1792,7 +1794,7 @@ 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 *hsotg, unsigned int idx,
                            int dir_in)
 {
        struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx];
@@ -1834,7 +1836,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, 
unsigned int idx,
 
                        if (idx == 0 && !hs_ep->req)
                                s3c_hsotg_enqueue_setup(hsotg);
-               } else if (using_dma(hsotg)) {
+               } else if (using_dma(hsotg->s3c_hsotg)) {
                        /*
                         * We're using DMA, we need to fire an OutDone here
                         * as we ignore the RXFIFO.
@@ -1868,7 +1870,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, 
unsigned int idx,
        if (ints & DXEPINT_SETUP) {  /* Setup or Timeout */
                dev_dbg(hsotg->dev, "%s: Setup/Timeout\n",  __func__);
 
-               if (using_dma(hsotg) && idx == 0) {
+               if (using_dma(hsotg->s3c_hsotg) && idx == 0) {
                        /*
                         * this is the notification we've received a
                         * setup packet. In non-DMA mode we'd get this
@@ -1900,11 +1902,11 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, 
unsigned int idx,
                }
 
                /* FIFO has space or is empty (see GAHBCFG) */
-               if (hsotg->dedicated_fifos &&
+               if (hsotg->s3c_hsotg->dedicated_fifos &&
                    ints & DIEPMSK_TXFIFOEMPTY) {
                        dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n",
                                __func__, idx);
-                       if (!using_dma(hsotg))
+                       if (!using_dma(hsotg->s3c_hsotg))
                                s3c_hsotg_trytx(hsotg, hs_ep);
                }
        }
@@ -1917,7 +1919,7 @@ 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 *hsotg)
 {
        u32 dsts = readl(hsotg->regs + DSTS);
        int ep0_mps = 0, ep_mps;
@@ -1971,7 +1973,7 @@ 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++)
+               for (i = 1; i < hsotg->s3c_hsotg->num_of_eps; i++)
                        s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps);
        }
 
@@ -1994,7 +1996,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 *hsotg,
                              struct s3c_hsotg_ep *ep,
                              int result, bool force)
 {
@@ -2013,7 +2015,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
                s3c_hsotg_complete_request(hsotg, ep, req,
                                           result);
        }
-       if (!hsotg->dedicated_fifos)
+       if (!hsotg->s3c_hsotg->dedicated_fifos)
                return;
        size = (readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4;
        if (size < ep->fifo_size)
@@ -2028,11 +2030,11 @@ 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 *hsotg)
 {
        unsigned ep;
 
-       for (ep = 0; ep < hsotg->num_of_eps; ep++)
+       for (ep = 0; ep < hsotg->s3c_hsotg->num_of_eps; ep++)
                kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true);
 
        call_gadget(hsotg, disconnect);
@@ -2043,14 +2045,14 @@ 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 *hsotg, 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++) {
+       for (epno = 0; epno < hsotg->s3c_hsotg->num_of_eps; epno++) {
                ep = &hsotg->eps[epno];
 
                if (!ep->dir_in)
@@ -2077,7 +2079,7 @@ 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 *hsotg)
 {
        int timeout;
        u32 grstctl;
@@ -2125,7 +2127,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
  *
  * Issue a soft reset to the core, and await the core finishing it.
  */
-static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
+void s3c_hsotg_core_init(struct dwc2_hsotg *hsotg)
 {
        s3c_hsotg_corereset(hsotg);
 
@@ -2135,7 +2137,7 @@ 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) |
+       writel(hsotg->s3c_hsotg->phyif | GUSBCFG_TOUTCAL(7) |
               (0x5 << 10), hsotg->regs + GUSBCFG);
 
        s3c_hsotg_init_fifo(hsotg);
@@ -2157,12 +2159,12 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
                GINTSTS_USBSUSP | GINTSTS_WKUPINT,
                hsotg->regs + GINTMSK);
 
-       if (using_dma(hsotg))
+       if (using_dma(hsotg->s3c_hsotg))
                writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN |
                       GAHBCFG_HBSTLEN_INCR4,
                       hsotg->regs + GAHBCFG);
        else
-               writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL |
+               writel(((hsotg->s3c_hsotg->dedicated_fifos) ? 
(GAHBCFG_NP_TXF_EMP_LVL |
                                                    GAHBCFG_P_TXF_EMP_LVL) : 0) 
|
                       GAHBCFG_GLBL_INTR_EN,
                       hsotg->regs + GAHBCFG);
@@ -2173,7 +2175,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
         * interrupts.
         */
 
-       writel(((hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY |
+       writel(((hsotg->s3c_hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY |
                DIEPMSK_INTKNTXFEMPMSK : 0) |
                DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK |
                DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK |
@@ -2184,7 +2186,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
         * 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(hsotg->s3c_hsotg) ? (DIEPMSK_XFERCOMPLMSK |
                                    DIEPMSK_TIMEOUTMSK) : 0) |
                DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK |
                DOEPMSK_SETUPMSK,
@@ -2204,7 +2206,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
         * 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))
+       if (!using_dma(hsotg->s3c_hsotg))
                s3c_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL);
 
        /* Enable interrupts for EP0 in and out */
@@ -2259,7 +2261,7 @@ 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 *hsotg = pw;
        int retry_count = 8;
        u32 gintsts;
        u32 gintmsk;
@@ -2335,14 +2337,14 @@ irq_retry:
                writel(GINTSTS_USBRST, hsotg->regs + GINTSTS);
 
                if (usb_status & GOTGCTL_BSESVLD) {
-                       if (time_after(jiffies, hsotg->last_rst +
+                       if (time_after(jiffies, hsotg->s3c_hsotg->last_rst +
                                       msecs_to_jiffies(200))) {
 
                                kill_all_requests(hsotg, &hsotg->eps[0],
                                                          -ECONNRESET, true);
 
                                s3c_hsotg_core_init(hsotg);
-                               hsotg->last_rst = jiffies;
+                               hsotg->s3c_hsotg->last_rst = jiffies;
                        }
                }
        }
@@ -2451,7 +2453,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 *hsotg = hs_ep->parent;
        unsigned long flags;
        int index = hs_ep->index;
        u32 epctrl_reg;
@@ -2546,16 +2548,16 @@ 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 && hsotg->s3c_hsotg->dedicated_fifos) {
                size = hs_ep->ep.maxpacket*hs_ep->mc;
                for (i = 1; i <= 8; ++i) {
-                       if (hsotg->fifo_map & (1<<i))
+                       if (hsotg->s3c_hsotg->fifo_map & (1<<i))
                                continue;
                        val = readl(hsotg->regs + DPTXFSIZN(i));
                        val = (val >> FIFOSIZE_DEPTH_SHIFT)*4;
                        if (val < size)
                                continue;
-                       hsotg->fifo_map |= 1<<i;
+                       hsotg->s3c_hsotg->fifo_map |= 1<<i;
 
                        epctrl |= DXEPCTL_TXFNUM(i);
                        hs_ep->fifo_index = i;
@@ -2591,7 +2593,7 @@ 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 *hsotg = hs_ep->parent;
        int dir_in = hs_ep->dir_in;
        int index = hs_ep->index;
        unsigned long flags;
@@ -2611,7 +2613,7 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep)
        /* terminate all requests with shutdown */
        kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false);
 
-       hsotg->fifo_map &= ~(1<<hs_ep->fifo_index);
+       hsotg->s3c_hsotg->fifo_map &= ~(1<<hs_ep->fifo_index);
        hs_ep->fifo_index = 0;
        hs_ep->fifo_size = 0;
 
@@ -2656,7 +2658,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_dbg(hs->dev, "ep_dequeue(%p,%p)\n", ep, req);
@@ -2682,7 +2684,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;
@@ -2746,7 +2748,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;
 
@@ -2775,19 +2777,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 *hsotg)
 {
        struct platform_device *pdev = to_platform_device(hsotg->dev);
 
        dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev);
 
-       if (hsotg->uphy)
-               usb_phy_init(hsotg->uphy);
-       else if (hsotg->plat && hsotg->plat->phy_init)
-               hsotg->plat->phy_init(pdev, hsotg->plat->phy_type);
+       if (hsotg->s3c_hsotg->uphy)
+               usb_phy_init(hsotg->s3c_hsotg->uphy);
+       else if (hsotg->s3c_hsotg->plat && hsotg->s3c_hsotg->plat->phy_init)
+               hsotg->s3c_hsotg->plat->phy_init(pdev, 
hsotg->s3c_hsotg->plat->phy_type);
        else {
-               phy_init(hsotg->phy);
-               phy_power_on(hsotg->phy);
+               phy_init(hsotg->s3c_hsotg->phy);
+               phy_power_on(hsotg->s3c_hsotg->phy);
        }
 }
 
@@ -2798,17 +2800,17 @@ 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 *hsotg)
 {
        struct platform_device *pdev = to_platform_device(hsotg->dev);
 
-       if (hsotg->uphy)
-               usb_phy_shutdown(hsotg->uphy);
-       else if (hsotg->plat && hsotg->plat->phy_exit)
-               hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type);
+       if (hsotg->s3c_hsotg->uphy)
+               usb_phy_shutdown(hsotg->s3c_hsotg->uphy);
+       else if (hsotg->s3c_hsotg->plat && hsotg->s3c_hsotg->plat->phy_exit)
+               hsotg->s3c_hsotg->plat->phy_exit(pdev, 
hsotg->s3c_hsotg->plat->phy_type);
        else {
-               phy_power_off(hsotg->phy);
-               phy_exit(hsotg->phy);
+               phy_power_off(hsotg->s3c_hsotg->phy);
+               phy_exit(hsotg->s3c_hsotg->phy);
        }
 }
 
@@ -2816,7 +2818,7 @@ static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg)
  * 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 *hsotg)
 {
        /* unmask subset of endpoint interrupts */
 
@@ -2851,7 +2853,7 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
        writel(GUSBCFG_PHYIF16 | GUSBCFG_TOUTCAL(7) | (0x5 << 10),
               hsotg->regs + GUSBCFG);
 
-       writel(using_dma(hsotg) ? GAHBCFG_DMA_EN : 0x0,
+       writel(using_dma(hsotg->s3c_hsotg) ? GAHBCFG_DMA_EN : 0x0,
               hsotg->regs + GAHBCFG);
 }
 
@@ -2866,7 +2868,7 @@ 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 *hsotg = to_hsotg(gadget);
        int ret;
 
        if (!hsotg) {
@@ -2894,16 +2896,16 @@ static int s3c_hsotg_udc_start(struct usb_gadget 
*gadget,
        hsotg->gadget.dev.of_node = hsotg->dev->of_node;
        hsotg->gadget.speed = USB_SPEED_UNKNOWN;
 
-       clk_enable(hsotg->clk);
+       clk_enable(hsotg->s3c_hsotg->clk);
 
-       ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
-                                   hsotg->supplies);
+       ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                                   hsotg->s3c_hsotg->supplies);
        if (ret) {
                dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret);
                goto err;
        }
 
-       hsotg->last_rst = jiffies;
+       hsotg->s3c_hsotg->last_rst = jiffies;
        dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name);
        return 0;
 
@@ -2922,7 +2924,7 @@ 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 *hsotg = to_hsotg(gadget);
        unsigned long flags = 0;
        int ep;
 
@@ -2930,7 +2932,7 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
                return -ENODEV;
 
        /* all endpoints should be shutdown */
-       for (ep = 1; ep < hsotg->num_of_eps; ep++)
+       for (ep = 1; ep < hsotg->s3c_hsotg->num_of_eps; ep++)
                s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
 
        spin_lock_irqsave(&hsotg->lock, flags);
@@ -2942,9 +2944,10 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
 
        spin_unlock_irqrestore(&hsotg->lock, flags);
 
-       regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
+       regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                               hsotg->s3c_hsotg->supplies);
 
-       clk_disable(hsotg->clk);
+       clk_disable(hsotg->s3c_hsotg->clk);
 
        return 0;
 }
@@ -2969,7 +2972,7 @@ 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 *hsotg = to_hsotg(gadget);
        unsigned long flags = 0;
 
        dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on);
@@ -2977,10 +2980,10 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, 
int is_on)
        spin_lock_irqsave(&hsotg->lock, flags);
        if (is_on) {
                s3c_hsotg_phy_enable(hsotg);
-               clk_enable(hsotg->clk);
+               clk_enable(hsotg->s3c_hsotg->clk);
                s3c_hsotg_core_init(hsotg);
        } else {
-               clk_disable(hsotg->clk);
+               clk_disable(hsotg->s3c_hsotg->clk);
                s3c_hsotg_phy_disable(hsotg);
        }
 
@@ -3007,7 +3010,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 *hsotg,
                                       struct s3c_hsotg_ep *hs_ep,
                                       int epnum)
 {
@@ -3043,7 +3046,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg,
         * to be something valid.
         */
 
-       if (using_dma(hsotg)) {
+       if (using_dma(hsotg->s3c_hsotg)) {
                u32 next = DXEPCTL_NEXTEP((epnum + 1) % 15);
                writel(next, hsotg->regs + DIEPCTL(epnum));
                writel(next, hsotg->regs + DOEPCTL(epnum));
@@ -3056,31 +3059,31 @@ 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 *hsotg)
 {
        u32 cfg2, cfg3, cfg4;
        /* check hardware configuration */
 
        cfg2 = readl(hsotg->regs + 0x48);
-       hsotg->num_of_eps = (cfg2 >> 10) & 0xF;
+       hsotg->s3c_hsotg->num_of_eps = (cfg2 >> 10) & 0xF;
 
        cfg3 = readl(hsotg->regs + 0x4C);
-       hsotg->fifo_mem = (cfg3 >> 16);
+       hsotg->s3c_hsotg->fifo_mem = (cfg3 >> 16);
 
        cfg4 = readl(hsotg->regs + 0x50);
-       hsotg->dedicated_fifos = (cfg4 >> 25) & 1;
+       hsotg->s3c_hsotg->dedicated_fifos = (cfg4 >> 25) & 1;
 
        dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n",
-                hsotg->num_of_eps,
-                hsotg->dedicated_fifos ? "dedicated" : "shared",
-                hsotg->fifo_mem);
+                hsotg->s3c_hsotg->num_of_eps,
+                hsotg->s3c_hsotg->dedicated_fifos ? "dedicated" : "shared",
+                hsotg->s3c_hsotg->fifo_mem);
 }
 
 /**
  * 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 *hsotg)
 {
 #ifdef DEBUG
        struct device *dev = hsotg->dev;
@@ -3139,7 +3142,7 @@ 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;
+       struct dwc2_hsotg *hsotg = seq->private;
        void __iomem *regs = hsotg->regs;
        int idx;
 
@@ -3209,7 +3212,7 @@ static const struct file_operations state_fops = {
  */
 static int fifo_show(struct seq_file *seq, void *v)
 {
-       struct s3c_hsotg *hsotg = seq->private;
+       struct dwc2_hsotg *hsotg = seq->private;
        void __iomem *regs = hsotg->regs;
        u32 val;
        int idx;
@@ -3265,7 +3268,7 @@ 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 *hsotg = ep->parent;
        struct s3c_hsotg_req *req;
        void __iomem *regs = hsotg->regs;
        int index = ep->index;
@@ -3342,13 +3345,13 @@ 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 *hsotg)
 {
        struct dentry *root;
        unsigned epidx;
 
        root = debugfs_create_dir(dev_name(hsotg->dev), NULL);
-       hsotg->debug_root = root;
+       hsotg->s3c_hsotg->debug_root = root;
        if (IS_ERR(root)) {
                dev_err(hsotg->dev, "cannot create debug root\n");
                return;
@@ -3356,21 +3359,21 @@ static void s3c_hsotg_create_debug(struct s3c_hsotg 
*hsotg)
 
        /* create general state file */
 
-       hsotg->debug_file = debugfs_create_file("state", 0444, root,
+       hsotg->s3c_hsotg->debug_file = debugfs_create_file("state", 0444, root,
                                                hsotg, &state_fops);
 
-       if (IS_ERR(hsotg->debug_file))
+       if (IS_ERR(hsotg->s3c_hsotg->debug_file))
                dev_err(hsotg->dev, "%s: failed to create state\n", __func__);
 
-       hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root,
+       hsotg->s3c_hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root,
                                                hsotg, &fifo_fops);
 
-       if (IS_ERR(hsotg->debug_fifo))
+       if (IS_ERR(hsotg->s3c_hsotg->debug_fifo))
                dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__);
 
        /* create one file for each endpoint */
 
-       for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) {
+       for (epidx = 0; epidx < hsotg->s3c_hsotg->num_of_eps; epidx++) {
                struct s3c_hsotg_ep *ep = &hsotg->eps[epidx];
 
                ep->debugfs = debugfs_create_file(ep->name, 0444,
@@ -3388,130 +3391,103 @@ 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 *hsotg)
 {
        unsigned epidx;
 
-       for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) {
+       for (epidx = 0; epidx < hsotg->s3c_hsotg->num_of_eps; epidx++) {
                struct s3c_hsotg_ep *ep = &hsotg->eps[epidx];
                debugfs_remove(ep->debugfs);
        }
 
-       debugfs_remove(hsotg->debug_file);
-       debugfs_remove(hsotg->debug_fifo);
-       debugfs_remove(hsotg->debug_root);
+       debugfs_remove(hsotg->s3c_hsotg->debug_file);
+       debugfs_remove(hsotg->s3c_hsotg->debug_fifo);
+       debugfs_remove(hsotg->s3c_hsotg->debug_root);
 }
 
 /**
- * s3c_hsotg_probe - probe function for hsotg driver
- * @pdev: The platform information for the driver
+ * dwc2_gadget_init - init function for gadget
+ * @dwc2: The data structure for the DWC2 driver.
+ * @irq: The IRQ number for the controller.
  */
 
-static int s3c_hsotg_probe(struct platform_device *pdev)
+int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
 {
-       struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev);
+       struct s3c_hsotg_plat *plat = hsotg->dev->platform_data;
        struct phy *phy;
        struct usb_phy *uphy;
-       struct device *dev = &pdev->dev;
+       struct device *dev = hsotg->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) {
+       hsotg->s3c_hsotg = devm_kzalloc(dev, sizeof(struct s3c_hsotg), 
GFP_KERNEL);
+       if (!hsotg->s3c_hsotg) {
                dev_err(dev, "cannot get memory\n");
                return -ENOMEM;
        }
 
        /* Set default UTMI width */
-       hsotg->phyif = GUSBCFG_PHYIF16;
+       hsotg->s3c_hsotg->phyif = GUSBCFG_PHYIF16;
 
        /*
         * 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(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(dev);
                        if (!plat) {
-                               dev_err(&pdev->dev,
+                               dev_err(dev,
                                "no platform data or transceiver defined\n");
                                return -EPROBE_DEFER;
                        }
-                       hsotg->plat = plat;
+                       hsotg->s3c_hsotg->plat = plat;
                } else
-                       hsotg->uphy = uphy;
+                       hsotg->s3c_hsotg->uphy = uphy;
        } else {
-               hsotg->phy = phy;
+               hsotg->s3c_hsotg->phy = phy;
                /*
                 * If using the generic PHY framework, check if the PHY bus
                 * width is 8-bit and set the phyif appropriately.
                 */
                if (phy_get_bus_width(phy) == 8)
-                       hsotg->phyif = GUSBCFG_PHYIF8;
+                       hsotg->s3c_hsotg->phyif = GUSBCFG_PHYIF8;
        }
 
-       hsotg->dev = dev;
-
-       hsotg->clk = devm_clk_get(&pdev->dev, "otg");
-       if (IS_ERR(hsotg->clk)) {
+       hsotg->s3c_hsotg->clk = devm_clk_get(dev, "otg");
+       if (IS_ERR(hsotg->s3c_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);
-
-       hsotg->regs = devm_ioremap_resource(&pdev->dev, res);
-       if (IS_ERR(hsotg->regs)) {
-               ret = PTR_ERR(hsotg->regs);
-               goto err_clk;
-       }
-
-       ret = platform_get_irq(pdev, 0);
-       if (ret < 0) {
-               dev_err(dev, "cannot find IRQ\n");
-               goto err_clk;
+               return PTR_ERR(hsotg->s3c_hsotg->clk);
        }
 
-       spin_lock_init(&hsotg->lock);
-
-       hsotg->irq = 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);
+       clk_prepare_enable(hsotg->s3c_hsotg->clk);
 
        /* 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(hsotg->s3c_hsotg->supplies); i++)
+               hsotg->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(hsotg->s3c_hsotg->supplies),
+                                hsotg->s3c_hsotg->supplies);
        if (ret) {
                dev_err(dev, "failed to request supplies: %d\n", ret);
                goto err_clk;
        }
 
-       ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
-                                   hsotg->supplies);
+       ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                                   hsotg->s3c_hsotg->supplies);
 
        if (ret) {
-               dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret);
+               dev_err(dev, "failed to enable supplies: %d\n", ret);
                goto err_supplies;
        }
 
@@ -3522,26 +3498,26 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
        s3c_hsotg_hw_cfg(hsotg);
        s3c_hsotg_init(hsotg);
 
-       ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0,
+       ret = devm_request_irq(dev, irq, s3c_hsotg_irq, 0,
                                dev_name(dev), hsotg);
        if (ret < 0) {
                s3c_hsotg_phy_disable(hsotg);
-               clk_disable_unprepare(hsotg->clk);
-               regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
-                                      hsotg->supplies);
+               clk_disable_unprepare(hsotg->s3c_hsotg->clk);
+               regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                                      hsotg->s3c_hsotg->supplies);
                dev_err(dev, "cannot claim IRQ\n");
                goto err_clk;
        }
 
        /* hsotg->num_of_eps holds number of EPs other than ep0 */
 
-       if (hsotg->num_of_eps == 0) {
+       if (hsotg->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(hsotg->s3c_hsotg->num_of_eps + 1, sizeof(struct 
s3c_hsotg_ep),
                      GFP_KERNEL);
        if (!eps) {
                dev_err(dev, "cannot get memory\n");
@@ -3558,30 +3534,30 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
 
        /* allocate EP0 request */
 
-       hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep,
+       hsotg->s3c_hsotg->ctrl_req = 
s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep,
                                                     GFP_KERNEL);
-       if (!hsotg->ctrl_req) {
+       if (!hsotg->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++)
+       for (epnum = 0; epnum < hsotg->s3c_hsotg->num_of_eps; epnum++)
                s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum);
 
        /* disable power and clock */
 
-       ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
-                                   hsotg->supplies);
+       ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                                   hsotg->s3c_hsotg->supplies);
        if (ret) {
-               dev_err(hsotg->dev, "failed to disable supplies: %d\n", ret);
+               dev_err(dev, "failed to disable supplies: %d\n", ret);
                goto err_ep_mem;
        }
 
        s3c_hsotg_phy_disable(hsotg);
 
-       ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget);
+       ret = usb_add_gadget_udc(dev, &hsotg->gadget);
        if (ret)
                goto err_ep_mem;
 
@@ -3596,7 +3572,7 @@ err_ep_mem:
 err_supplies:
        s3c_hsotg_phy_disable(hsotg);
 err_clk:
-       clk_disable_unprepare(hsotg->clk);
+       clk_disable_unprepare(hsotg->s3c_hsotg->clk);
 
        return ret;
 }
@@ -3605,10 +3581,8 @@ err_clk:
  * s3c_hsotg_remove - remove function for hsotg driver
  * @pdev: The platform information for the driver
  */
-static int s3c_hsotg_remove(struct platform_device *pdev)
+static int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
 {
-       struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
-
        usb_del_gadget_udc(&hsotg->gadget);
 
        s3c_hsotg_delete_debug(hsotg);
@@ -3618,14 +3592,13 @@ static int s3c_hsotg_remove(struct platform_device 
*pdev)
                usb_gadget_unregister_driver(hsotg->driver);
        }
 
-       clk_disable_unprepare(hsotg->clk);
+       clk_disable_unprepare(hsotg->s3c_hsotg->clk);
 
        return 0;
 }
 
-static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)
+static int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
 {
-       struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
        unsigned long flags;
        int ret = 0;
 
@@ -3641,20 +3614,19 @@ static int s3c_hsotg_suspend(struct platform_device 
*pdev, pm_message_t state)
 
        if (hsotg->driver) {
                int ep;
-               for (ep = 0; ep < hsotg->num_of_eps; ep++)
+               for (ep = 0; ep < hsotg->s3c_hsotg->num_of_eps; ep++)
                        s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
 
-               ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
-                                            hsotg->supplies);
-               clk_disable(hsotg->clk);
+               ret = 
regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                                            hsotg->s3c_hsotg->supplies);
+               clk_disable(hsotg->s3c_hsotg->clk);
        }
 
        return ret;
 }
 
-static int s3c_hsotg_resume(struct platform_device *pdev)
+static int s3c_hsotg_resume(struct dwc2_hsotg *hsotg)
 {
-       struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
        unsigned long flags;
        int ret = 0;
 
@@ -3662,43 +3634,16 @@ static int s3c_hsotg_resume(struct platform_device 
*pdev)
                dev_info(hsotg->dev, "resuming usb gadget %s\n",
                         hsotg->driver->driver.name);
 
-               clk_enable(hsotg->clk);
-               ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
-                                     hsotg->supplies);
+               clk_enable(hsotg->s3c_hsotg->clk);
+               ret = 
regulator_bulk_enable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
+                                     hsotg->s3c_hsotg->supplies);
        }
 
        spin_lock_irqsave(&hsotg->lock, flags);
-       hsotg->last_rst = jiffies;
+       hsotg->s3c_hsotg->last_rst = jiffies;
        s3c_hsotg_phy_enable(hsotg);
        s3c_hsotg_core_init(hsotg);
        spin_unlock_irqrestore(&hsotg->lock, flags);
 
        return ret;
 }
-
-#ifdef CONFIG_OF
-static const struct of_device_id s3c_hsotg_of_ids[] = {
-       { .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 <b...@simtec.co.uk>");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:s3c-hsotg");
diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h
index fdc6d48..08db5c0 100644
--- a/drivers/usb/dwc2/hcd.h
+++ b/drivers/usb/dwc2/hcd.h
@@ -666,9 +666,6 @@ extern irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg 
*hsotg);
  */
 extern void dwc2_hcd_stop(struct dwc2_hsotg *hsotg);
 
-extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
-extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
-
 /**
  * dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host,
  * and 0 otherwise
@@ -678,13 +675,6 @@ extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
 extern int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg);
 
 /**
- * dwc2_hcd_get_frame_number() - Returns current frame number
- *
- * @hsotg: The DWC2 HCD
- */
-extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
-
-/**
  * dwc2_hcd_dump_state() - Dumps hsotg state
  *
  * @hsotg: The DWC2 HCD
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to