usb: s3c-otg: Rename struct s3c_ep
[oweals/u-boot.git] / drivers / usb / gadget / s3c_udc_otg.c
index ba17a04265ebbbb11a06679874ed9ef23f35fa1a..4caa390773c45e6552ef03f0fd763cf752e276ab 100644 (file)
@@ -31,9 +31,9 @@
 #include <asm/io.h>
 
 #include <asm/mach-types.h>
-#include <asm/arch/gpio.h>
 
-#include "regs-otg.h"
+#include "s3c_udc_otg_regs.h"
+#include "s3c_udc_otg_priv.h"
 #include <usb/lin_gadget_compat.h>
 
 /***********************************************************/
@@ -66,7 +66,7 @@ static char *state_names[] = {
 #define DRIVER_DESC "S3C HS USB OTG Device Driver, (c) Samsung Electronics"
 #define DRIVER_VERSION "15 March 2009"
 
-struct s3c_udc *the_controller;
+struct dwc2_udc        *the_controller;
 
 static const char driver_name[] = "s3c-udc";
 static const char driver_desc[] = DRIVER_DESC;
@@ -95,21 +95,21 @@ static int s3c_queue(struct usb_ep *ep, struct usb_request *, gfp_t gfp_flags);
 static int s3c_dequeue(struct usb_ep *ep, struct usb_request *);
 static int s3c_fifo_status(struct usb_ep *ep);
 static void s3c_fifo_flush(struct usb_ep *ep);
-static void s3c_ep0_read(struct s3c_udc *dev);
-static void s3c_ep0_kick(struct s3c_udc *dev, struct s3c_ep *ep);
-static void s3c_handle_ep0(struct s3c_udc *dev);
-static int s3c_ep0_write(struct s3c_udc *dev);
-static int write_fifo_ep0(struct s3c_ep *ep, struct s3c_request *req);
-static void done(struct s3c_ep *ep, struct s3c_request *req, int status);
-static void stop_activity(struct s3c_udc *dev,
+static void s3c_ep0_read(struct dwc2_udc *dev);
+static void s3c_ep0_kick(struct dwc2_udc *dev, struct dwc2_ep *ep);
+static void s3c_handle_ep0(struct dwc2_udc *dev);
+static int s3c_ep0_write(struct dwc2_udc *dev);
+static int write_fifo_ep0(struct dwc2_ep *ep, struct s3c_request *req);
+static void done(struct dwc2_ep *ep, struct s3c_request *req, int status);
+static void stop_activity(struct dwc2_udc *dev,
                          struct usb_gadget_driver *driver);
-static int udc_enable(struct s3c_udc *dev);
-static void udc_set_address(struct s3c_udc *dev, unsigned char address);
-static void reconfig_usbd(void);
-static void set_max_pktsize(struct s3c_udc *dev, enum usb_device_speed speed);
-static void nuke(struct s3c_ep *ep, int status);
+static int udc_enable(struct dwc2_udc *dev);
+static void udc_set_address(struct dwc2_udc *dev, unsigned char address);
+static void reconfig_usbd(struct dwc2_udc *dev);
+static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed);
+static void nuke(struct dwc2_ep *ep, int status);
 static int s3c_udc_set_halt(struct usb_ep *_ep, int value);
-static void s3c_udc_set_nak(struct s3c_ep *ep);
+static void s3c_udc_set_nak(struct dwc2_ep *ep);
 
 void set_udc_gadget_private_data(void *p)
 {
@@ -145,64 +145,15 @@ static struct usb_ep_ops s3c_ep_ops = {
 /***********************************************************/
 
 void __iomem           *regs_otg;
-struct s3c_usbotg_reg *reg;
-struct s3c_usbotg_phy *phy;
-static unsigned int usb_phy_ctrl;
+struct dwc2_usbotg_reg *reg;
 
-void otg_phy_init(struct s3c_udc *dev)
+bool dfu_usb_get_reset(void)
 {
-       dev->pdata->phy_control(1);
-
-       /*USB PHY0 Enable */
-       printf("USB PHY0 Enable\n");
-
-       /* Enable PHY */
-       writel(readl(usb_phy_ctrl) | USB_PHY_CTRL_EN0, usb_phy_ctrl);
-
-       if (dev->pdata->usb_flags == PHY0_SLEEP) /* C210 Universal */
-               writel((readl(&phy->phypwr)
-                       &~(PHY_0_SLEEP | OTG_DISABLE_0 | ANALOG_PWRDOWN)
-                       &~FORCE_SUSPEND_0), &phy->phypwr);
-       else /* C110 GONI */
-               writel((readl(&phy->phypwr) &~(OTG_DISABLE_0 | ANALOG_PWRDOWN)
-                       &~FORCE_SUSPEND_0), &phy->phypwr);
-
-       if (s5p_cpu_id == 0x4412)
-               writel((readl(&phy->phyclk) & ~(EXYNOS4X12_ID_PULLUP0 |
-                       EXYNOS4X12_COMMON_ON_N0)) | EXYNOS4X12_CLK_SEL_24MHZ,
-                      &phy->phyclk); /* PLL 24Mhz */
-       else
-               writel((readl(&phy->phyclk) & ~(ID_PULLUP0 | COMMON_ON_N0)) |
-                      CLK_SEL_24MHZ, &phy->phyclk); /* PLL 24Mhz */
-
-       writel((readl(&phy->rstcon) &~(LINK_SW_RST | PHYLNK_SW_RST))
-              | PHY_SW_RST0, &phy->rstcon);
-       udelay(10);
-       writel(readl(&phy->rstcon)
-              &~(PHY_SW_RST0 | LINK_SW_RST | PHYLNK_SW_RST), &phy->rstcon);
-       udelay(10);
+       return !!(readl(&reg->gintsts) & INT_RESET);
 }
 
-void otg_phy_off(struct s3c_udc *dev)
-{
-       /* reset controller just in case */
-       writel(PHY_SW_RST0, &phy->rstcon);
-       udelay(20);
-       writel(readl(&phy->phypwr) &~PHY_SW_RST0, &phy->rstcon);
-       udelay(20);
-
-       writel(readl(&phy->phypwr) | OTG_DISABLE_0 | ANALOG_PWRDOWN
-              | FORCE_SUSPEND_0, &phy->phypwr);
-
-       writel(readl(usb_phy_ctrl) &~USB_PHY_CTRL_EN0, usb_phy_ctrl);
-
-       writel((readl(&phy->phyclk) & ~(ID_PULLUP0 | COMMON_ON_N0)),
-             &phy->phyclk);
-
-       udelay(10000);
-
-       dev->pdata->phy_control(0);
-}
+__weak void otg_phy_init(struct dwc2_udc *dev) {}
+__weak void otg_phy_off(struct dwc2_udc *dev) {}
 
 /***********************************************************/
 
@@ -211,7 +162,7 @@ void otg_phy_off(struct s3c_udc *dev)
 /*
  *     udc_disable - disable USB device controller
  */
-static void udc_disable(struct s3c_udc *dev)
+static void udc_disable(struct dwc2_udc *dev)
 {
        debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
 
@@ -227,7 +178,7 @@ static void udc_disable(struct s3c_udc *dev)
 /*
  *     udc_reinit - initialize software state
  */
-static void udc_reinit(struct s3c_udc *dev)
+static void udc_reinit(struct dwc2_udc *dev)
 {
        unsigned int i;
 
@@ -240,7 +191,7 @@ static void udc_reinit(struct s3c_udc *dev)
 
        /* basic endpoint records init */
        for (i = 0; i < S3C_MAX_ENDPOINTS; i++) {
-               struct s3c_ep *ep = &dev->ep[i];
+               struct dwc2_ep *ep = &dev->ep[i];
 
                if (i != 0)
                        list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
@@ -260,12 +211,12 @@ static void udc_reinit(struct s3c_udc *dev)
 /* until it's enabled, this UDC should be completely invisible
  * to any USB host.
  */
-static int udc_enable(struct s3c_udc *dev)
+static int udc_enable(struct dwc2_udc *dev)
 {
        debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
 
        otg_phy_init(dev);
-       reconfig_usbd();
+       reconfig_usbd(dev);
 
        debug_cond(DEBUG_SETUP != 0,
                   "S3C USB 2.0 OTG Controller Core Initialized : 0x%x\n",
@@ -281,9 +232,9 @@ static int udc_enable(struct s3c_udc *dev)
 */
 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
-       struct s3c_udc *dev = the_controller;
+       struct dwc2_udc *dev = the_controller;
        int retval = 0;
-       unsigned long flags;
+       unsigned long flags = 0;
 
        debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
@@ -330,8 +281,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
  */
 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 {
-       struct s3c_udc *dev = the_controller;
-       unsigned long flags;
+       struct dwc2_udc *dev = the_controller;
+       unsigned long flags = 0;
 
        if (!dev)
                return -ENODEV;
@@ -354,7 +305,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 /*
  *     done - retire a request; caller blocked irqs
  */
-static void done(struct s3c_ep *ep, struct s3c_request *req, int status)
+static void done(struct dwc2_ep *ep, struct s3c_request *req, int status)
 {
        unsigned int stopped = ep->stopped;
 
@@ -405,7 +356,7 @@ static void done(struct s3c_ep *ep, struct s3c_request *req, int status)
 /*
  *     nuke - dequeue ALL requests
  */
-static void nuke(struct s3c_ep *ep, int status)
+static void nuke(struct dwc2_ep *ep, int status)
 {
        struct s3c_request *req;
 
@@ -418,7 +369,7 @@ static void nuke(struct s3c_ep *ep, int status)
        }
 }
 
-static void stop_activity(struct s3c_udc *dev,
+static void stop_activity(struct dwc2_udc *dev,
                          struct usb_gadget_driver *driver)
 {
        int i;
@@ -430,7 +381,7 @@ static void stop_activity(struct s3c_udc *dev,
 
        /* prevent new request submissions, kill any outstanding requests  */
        for (i = 0; i < S3C_MAX_ENDPOINTS; i++) {
-               struct s3c_ep *ep = &dev->ep[i];
+               struct dwc2_ep *ep = &dev->ep[i];
                ep->stopped = 1;
                nuke(ep, -ESHUTDOWN);
        }
@@ -446,15 +397,17 @@ static void stop_activity(struct s3c_udc *dev,
        udc_reinit(dev);
 }
 
-static void reconfig_usbd(void)
+static void reconfig_usbd(struct dwc2_udc *dev)
 {
        /* 2. Soft-reset OTG Core and then unreset again. */
        int i;
        unsigned int uTemp = writel(CORE_SOFT_RESET, &reg->grstctl);
+       uint32_t dflt_gusbcfg;
 
        debug("Reseting OTG controller\n");
 
-       writel(0<<15            /* PHY Low Power Clock sel*/
+       dflt_gusbcfg =
+               0<<15           /* PHY Low Power Clock sel*/
                |1<<14          /* Non-Periodic TxFIFO Rewind Enable*/
                |0x5<<10        /* Turnaround time*/
                |0<<9 | 0<<8    /* [0:HNP disable,1:HNP enable][ 0:SRP disable*/
@@ -463,8 +416,12 @@ static void reconfig_usbd(void)
                |0<<6           /* 0: high speed utmi+, 1: full speed serial*/
                |0<<4           /* 0: utmi+, 1:ulpi*/
                |1<<3           /* phy i/f  0:8bit, 1:16bit*/
-               |0x7<<0,        /* HS/FS Timeout**/
-               &reg->gusbcfg);
+               |0x7<<0;        /* HS/FS Timeout**/
+
+       if (dev->pdata->usb_gusbcfg)
+               dflt_gusbcfg = dev->pdata->usb_gusbcfg;
+
+       writel(dflt_gusbcfg, &reg->gusbcfg);
 
        /* 3. Put the OTG device core in the disconnected state.*/
        uTemp = readl(&reg->dctl);
@@ -540,7 +497,7 @@ static void reconfig_usbd(void)
        writel(GAHBCFG_INIT, &reg->gahbcfg);
 }
 
-static void set_max_pktsize(struct s3c_udc *dev, enum usb_device_speed speed)
+static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed)
 {
        unsigned int ep_ctrl;
        int i;
@@ -573,13 +530,13 @@ static void set_max_pktsize(struct s3c_udc *dev, enum usb_device_speed speed)
 static int s3c_ep_enable(struct usb_ep *_ep,
                         const struct usb_endpoint_descriptor *desc)
 {
-       struct s3c_ep *ep;
-       struct s3c_udc *dev;
-       unsigned long flags;
+       struct dwc2_ep *ep;
+       struct dwc2_udc *dev;
+       unsigned long flags = 0;
 
        debug("%s: %p\n", __func__, _ep);
 
-       ep = container_of(_ep, struct s3c_ep, ep);
+       ep = container_of(_ep, struct dwc2_ep, ep);
        if (!_ep || !desc || ep->desc || _ep->name == ep0name
            || desc->bDescriptorType != USB_DT_ENDPOINT
            || ep->bEndpointAddress != desc->bEndpointAddress
@@ -638,12 +595,12 @@ static int s3c_ep_enable(struct usb_ep *_ep,
  */
 static int s3c_ep_disable(struct usb_ep *_ep)
 {
-       struct s3c_ep *ep;
-       unsigned long flags;
+       struct dwc2_ep *ep;
+       unsigned long flags = 0;
 
        debug("%s: %p\n", __func__, _ep);
 
-       ep = container_of(_ep, struct s3c_ep, ep);
+       ep = container_of(_ep, struct dwc2_ep, ep);
        if (!_ep || !ep->desc) {
                debug("%s: %s not enabled\n", __func__,
                      _ep ? ep->ep.name : NULL);
@@ -695,13 +652,13 @@ static void s3c_free_request(struct usb_ep *ep, struct usb_request *_req)
 /* dequeue JUST ONE request */
 static int s3c_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 {
-       struct s3c_ep *ep;
+       struct dwc2_ep *ep;
        struct s3c_request *req;
-       unsigned long flags;
+       unsigned long flags = 0;
 
        debug("%s: %p\n", __func__, _ep);
 
-       ep = container_of(_ep, struct s3c_ep, ep);
+       ep = container_of(_ep, struct dwc2_ep, ep);
        if (!_ep || ep->ep.name == ep0name)
                return -EINVAL;
 
@@ -729,9 +686,9 @@ static int s3c_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 static int s3c_fifo_status(struct usb_ep *_ep)
 {
        int count = 0;
-       struct s3c_ep *ep;
+       struct dwc2_ep *ep;
 
-       ep = container_of(_ep, struct s3c_ep, ep);
+       ep = container_of(_ep, struct dwc2_ep, ep);
        if (!_ep) {
                debug("%s: bad ep\n", __func__);
                return -ENODEV;
@@ -751,9 +708,9 @@ static int s3c_fifo_status(struct usb_ep *_ep)
  */
 static void s3c_fifo_flush(struct usb_ep *_ep)
 {
-       struct s3c_ep *ep;
+       struct dwc2_ep *ep;
 
-       ep = container_of(_ep, struct s3c_ep, ep);
+       ep = container_of(_ep, struct dwc2_ep, ep);
        if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
                debug("%s: bad ep\n", __func__);
                return;
@@ -766,7 +723,7 @@ static const struct usb_gadget_ops s3c_udc_ops = {
        /* current versions must always be self-powered */
 };
 
-static struct s3c_udc memory = {
+static struct dwc2_udc memory = {
        .usb_address = 0,
        .gadget = {
                .ops = &s3c_udc_ops,
@@ -842,16 +799,14 @@ static struct s3c_udc memory = {
 
 int s3c_udc_probe(struct s3c_plat_otg_data *pdata)
 {
-       struct s3c_udc *dev = &memory;
-       int retval = 0, i;
+       struct dwc2_udc *dev = &memory;
+       int retval = 0;
 
        debug("%s: %p\n", __func__, pdata);
 
        dev->pdata = pdata;
 
-       phy = (struct s3c_usbotg_phy *)pdata->regs_phy;
-       reg = (struct s3c_usbotg_reg *)pdata->regs_otg;
-       usb_phy_ctrl = pdata->usb_phy_ctrl;
+       reg = (struct dwc2_usbotg_reg *)pdata->regs_otg;
 
        /* regs_otg = (void *)pdata->regs_otg; */
 
@@ -864,23 +819,22 @@ int s3c_udc_probe(struct s3c_plat_otg_data *pdata)
 
        the_controller = dev;
 
-       for (i = 0; i < S3C_MAX_ENDPOINTS+1; i++) {
-               dev->dma_buf[i] = memalign(CONFIG_SYS_CACHELINE_SIZE,
-                                          DMA_BUFFER_SIZE);
-               dev->dma_addr[i] = (dma_addr_t) dev->dma_buf[i];
-               invalidate_dcache_range((unsigned long) dev->dma_buf[i],
-                                       (unsigned long) (dev->dma_buf[i]
-                                                        + DMA_BUFFER_SIZE));
+       usb_ctrl = memalign(CONFIG_SYS_CACHELINE_SIZE,
+                           ROUND(sizeof(struct usb_ctrlrequest),
+                                 CONFIG_SYS_CACHELINE_SIZE));
+       if (!usb_ctrl) {
+               error("No memory available for UDC!\n");
+               return -ENOMEM;
        }
-       usb_ctrl = dev->dma_buf[0];
-       usb_ctrl_dma_addr = dev->dma_addr[0];
+
+       usb_ctrl_dma_addr = (dma_addr_t) usb_ctrl;
 
        udc_reinit(dev);
 
        return retval;
 }
 
-int usb_gadget_handle_interrupts()
+int usb_gadget_handle_interrupts(int index)
 {
        u32 intr_status = readl(&reg->gintsts);
        u32 gintmsk = readl(&reg->gintmsk);