Staging: emxx_udc: Fix do not add new typedefs and remove volatile
[firefly-linux-kernel-4.4.55.git] / drivers / staging / emxx_udc / emxx_udc.c
index eb178fcb7954d0ee44964f851f477220867a39ed..a9bbf8e3d6ea14179176ed96547b3782ccec3f85 100644 (file)
@@ -201,7 +201,7 @@ static u32 _nbu2ss_get_begin_ram_address(struct nbu2ss_udc *udc)
        u32             num, buf_type;
        u32             data, last_ram_adr, use_ram_size;
 
-       PT_EP_REGS      p_ep_regs;
+       struct ep_regs *p_ep_regs;
 
        last_ram_adr = (D_RAM_SIZE_CTRL / sizeof(u32)) * 2;
        use_ram_size = 0;
@@ -394,7 +394,7 @@ static void _nbu2ss_ep_dma_exit(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep)
 {
        u32             num;
        u32             data;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (udc->vbus_active == 0)
                return;         /* VBUS OFF */
@@ -425,7 +425,7 @@ static void _nbu2ss_ep_dma_exit(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep)
 /* Abort DMA */
 static void _nbu2ss_ep_dma_abort(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep)
 {
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        _nbu2ss_bitclr(&preg->EP_DCR[ep->epnum-1].EP_DCR1, DCR1_EPn_REQEN);
        mdelay(DMA_DISABLE_TIME);       /* DCR1_EPn_REQEN Clear */
@@ -443,7 +443,7 @@ static void _nbu2ss_ep_in_end(
 {
        u32             data;
        u32             num;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (length >= sizeof(u32))
                return;
@@ -567,7 +567,7 @@ static int EP0_out_PIO(struct nbu2ss_udc *udc, u8 *pBuf, u32 length)
        u32             i;
        int             nret   = 0;
        u32             iWordLength = 0;
-       USB_REG_ACCESS *pBuf32 = (USB_REG_ACCESS *)pBuf;
+       union usb_reg_access *pBuf32 = (union usb_reg_access *)pBuf;
 
        /*------------------------------------------------------------*/
        /* Read Length */
@@ -592,8 +592,8 @@ static int EP0_out_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 length)
 {
        u32             i;
        u32             iReadSize = 0;
-       USB_REG_ACCESS  Temp32;
-       USB_REG_ACCESS *pBuf32 = (USB_REG_ACCESS *)pBuf;
+       union usb_reg_access  Temp32;
+       union usb_reg_access  *pBuf32 = (union usb_reg_access *)pBuf;
 
        if ((0 < length) && (length < sizeof(u32))) {
                Temp32.dw = _nbu2ss_readl(&udc->p_regs->EP0_READ);
@@ -613,7 +613,7 @@ static int EP0_in_PIO(struct nbu2ss_udc *udc, u8 *pBuf, u32 length)
        u32             iMaxLength   = EP0_PACKETSIZE;
        u32             iWordLength  = 0;
        u32             iWriteLength = 0;
-       USB_REG_ACCESS *pBuf32 = (USB_REG_ACCESS *)pBuf;
+       union usb_reg_access  *pBuf32 = (union usb_reg_access *)pBuf;
 
        /*------------------------------------------------------------*/
        /* Transfer Length */
@@ -638,8 +638,8 @@ static int EP0_in_PIO(struct nbu2ss_udc *udc, u8 *pBuf, u32 length)
 static int EP0_in_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 iRemainSize)
 {
        u32             i;
-       USB_REG_ACCESS Temp32;
-       USB_REG_ACCESS *pBuf32 = (USB_REG_ACCESS *)pBuf;
+       union usb_reg_access  Temp32;
+       union usb_reg_access  *pBuf32 = (union usb_reg_access *)pBuf;
 
        if ((0 < iRemainSize) && (iRemainSize < sizeof(u32))) {
                for (i = 0 ; i < iRemainSize ; i++)
@@ -840,7 +840,7 @@ static int _nbu2ss_out_dma(
        u32             burst = 1;
        u32             data;
        int             result = -EINVAL;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (req->dma_flag)
                return 1;               /* DMA is forwarded */
@@ -900,10 +900,10 @@ static int _nbu2ss_epn_out_pio(
        u32             i;
        u32             data;
        u32             iWordLength;
-       USB_REG_ACCESS  Temp32;
-       USB_REG_ACCESS  *pBuf32;
+       union usb_reg_access    Temp32;
+       union usb_reg_access    *pBuf32;
        int             result = 0;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (req->dma_flag)
                return 1;               /* DMA is forwarded */
@@ -912,7 +912,7 @@ static int _nbu2ss_epn_out_pio(
                return 0;
 
        pBuffer = (u8 *)req->req.buf;
-       pBuf32 = (USB_REG_ACCESS *)(pBuffer + req->req.actual);
+       pBuf32 = (union usb_reg_access *)(pBuffer + req->req.actual);
 
        iWordLength = length / sizeof(u32);
        if (iWordLength > 0) {
@@ -988,7 +988,7 @@ static int _nbu2ss_epn_out_transfer(
        u32             num;
        u32             iRecvLength;
        int             result = 1;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (ep->epnum == 0)
                return -EINVAL;
@@ -1051,7 +1051,7 @@ static int _nbu2ss_in_dma(
        u32             iWriteLength;
        u32             data;
        int             result = -EINVAL;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (req->dma_flag)
                return 1;               /* DMA is forwarded */
@@ -1123,17 +1123,17 @@ static int _nbu2ss_epn_in_pio(
        u32             i;
        u32             data;
        u32             iWordLength;
-       USB_REG_ACCESS  Temp32;
-       USB_REG_ACCESS  *pBuf32 = NULL;
+       union usb_reg_access    Temp32;
+       union usb_reg_access    *pBuf32 = NULL;
        int             result = 0;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (req->dma_flag)
                return 1;               /* DMA is forwarded */
 
        if (length > 0) {
                pBuffer = (u8 *)req->req.buf;
-               pBuf32 = (USB_REG_ACCESS *)(pBuffer + req->req.actual);
+               pBuf32 = (union usb_reg_access *)(pBuffer + req->req.actual);
 
                iWordLength = length / sizeof(u32);
                if (iWordLength > 0) {
@@ -1347,7 +1347,7 @@ static void _nbu2ss_set_endpoint_stall(
        u8              num, epnum;
        u32             data;
        struct nbu2ss_ep *ep;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if ((ep_adrs == 0) || (ep_adrs == 0x80)) {
                if (bstall) {
@@ -1454,7 +1454,7 @@ static int _nbu2ss_set_feature_device(
                break;
 
        case USB_DEVICE_TEST_MODE:
-               wIndex = wIndex >> 8;
+               wIndex >>= 8;
                if (wIndex <= MAX_TEST_MODE_NUM)
                        result = 0;
                break;
@@ -1471,7 +1471,7 @@ static int _nbu2ss_get_ep_stall(struct nbu2ss_udc *udc, u8 ep_adrs)
 {
        u8              epnum;
        u32             data = 0, bit_data;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        epnum = ep_adrs & ~USB_ENDPOINT_DIR_MASK;
        if (epnum == 0) {
@@ -1566,7 +1566,7 @@ static void _nbu2ss_epn_set_stall(
        u32     regdata;
        int     limit_cnt = 0;
 
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (ep->direct == USB_DIR_IN) {
                for (limit_cnt = 0
@@ -1608,7 +1608,7 @@ static int std_req_get_status(struct nbu2ss_udc *udc)
        switch (recipient) {
        case USB_RECIP_DEVICE:
                if (udc->ctrl.wIndex == 0x0000) {
-                       if (udc->self_powered)
+                       if (udc->gadget.is_selfpowered)
                                status_data |= (1 << USB_DEVICE_SELF_POWERED);
 
                        if (udc->remote_wakeup)
@@ -1671,7 +1671,7 @@ static int std_req_set_address(struct nbu2ss_udc *udc)
        if (wValue != (wValue & 0x007F))
                return -EINVAL;
 
-       wValue = wValue << USB_ADRS_SHIFT;
+       wValue <<= USB_ADRS_SHIFT;
 
        _nbu2ss_writel(&udc->p_regs->USB_ADDRESS, wValue);
        _nbu2ss_create_ep0_packet(udc, udc->ep0_buf, 0);
@@ -1994,7 +1994,7 @@ static inline void _nbu2ss_epn_in_int(
        int     result = 0;
        u32     status;
 
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (req->dma_flag)
                return;         /* DMA is forwarded */
@@ -2090,7 +2090,7 @@ static inline void _nbu2ss_epn_out_dma_int(
        u32             num;
        u32             dmacnt, ep_dmacnt;
        u32             mpkt;
-       PT_FC_REGS      preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        num = ep->epnum - 1;
 
@@ -2293,7 +2293,7 @@ static int _nbu2ss_pullup(struct nbu2ss_udc *udc, int is_on)
 /*-------------------------------------------------------------------------*/
 static void _nbu2ss_fifo_flush(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep)
 {
-       PT_FC_REGS      p = udc->p_regs;
+       struct fc_regs  *p = udc->p_regs;
 
        if (udc->vbus_active == 0)
                return;
@@ -2536,7 +2536,7 @@ static irqreturn_t _nbu2ss_udc_irq(int irq, void *_udc)
        u32     epnum, int_bit;
 
        struct nbu2ss_udc       *udc = (struct nbu2ss_udc *)_udc;
-       PT_FC_REGS              preg = udc->p_regs;
+       struct fc_regs  *preg = udc->p_regs;
 
        if (gpio_get_value(VBUS_VALUE) == 0) {
                _nbu2ss_writel(&preg->USB_INT_STA, ~USB_INT_STA_RW);
@@ -2794,7 +2794,7 @@ static int nbu2ss_ep_queue(
                if (ep->virt_buf == NULL)
                        ep->virt_buf = (u8 *)dma_alloc_coherent(
                                NULL, PAGE_SIZE,
-                               &ep->phys_buf, GFP_KERNEL | GFP_DMA);
+                               &ep->phys_buf, GFP_ATOMIC | GFP_DMA);
                if (ep->epnum > 0)  {
                        if (ep->direct == USB_DIR_IN)
                                memcpy(ep->virt_buf, req->req.buf,
@@ -2944,7 +2944,7 @@ static int nbu2ss_ep_fifo_status(struct usb_ep *_ep)
        struct nbu2ss_ep        *ep;
        struct nbu2ss_udc       *udc;
        unsigned long           flags;
-       PT_FC_REGS              preg;
+       struct fc_regs          *preg;
 
 /*     INFO("=== %s()\n", __func__); */
 
@@ -3117,7 +3117,7 @@ static int nbu2ss_gad_wakeup(struct usb_gadget *pgadget)
 static int nbu2ss_gad_set_selfpowered(struct usb_gadget *pgadget,
                                        int is_selfpowered)
 {
-       struct nbu2ss_udc       *udc;
+       struct nbu2ss_udc       *udc;
        unsigned long           flags;
 
 /*     INFO("=== %s()\n", __func__); */
@@ -3130,7 +3130,7 @@ static int nbu2ss_gad_set_selfpowered(struct usb_gadget *pgadget,
        udc = container_of(pgadget, struct nbu2ss_udc, gadget);
 
        spin_lock_irqsave(&udc->lock, flags);
-       udc->self_powered = (is_selfpowered != 0);
+       pgadget->is_selfpowered = (is_selfpowered != 0);
        spin_unlock_irqrestore(&udc->lock, flags);
 
        return 0;
@@ -3248,42 +3248,6 @@ static const char *gp_ep_name[NUM_ENDPOINTS] = {
        g_epd_name,
 };
 
-/*-------------------------------------------------------------------------*/
-static void __init nbu2ss_drv_set_ep_info(
-       struct nbu2ss_udc       *udc,
-       struct nbu2ss_ep        *ep,
-       const char *name)
-{
-       ep->udc = udc;
-       ep->desc = NULL;
-
-       ep->ep.driver_data = NULL;
-       ep->ep.name = name;
-       ep->ep.ops = &nbu2ss_ep_ops;
-
-       if (isdigit(name[2])) {
-
-               long    num;
-               int     res;
-               char    tempbuf[2];
-
-               tempbuf[0] = name[2];
-               tempbuf[1] = '\0';
-               res = kstrtol(tempbuf, 16, &num);
-
-               if (num == 0)
-                       ep->ep.maxpacket = EP0_PACKETSIZE;
-               else
-                       ep->ep.maxpacket = EP_PACKETSIZE;
-
-       } else {
-               ep->ep.maxpacket = EP_PACKETSIZE;
-       }
-
-       list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
-       INIT_LIST_HEAD(&ep->queue);
-}
-
 /*-------------------------------------------------------------------------*/
 static void __init nbu2ss_drv_ep_init(struct nbu2ss_udc *udc)
 {
@@ -3292,9 +3256,21 @@ static void __init nbu2ss_drv_ep_init(struct nbu2ss_udc *udc)
        INIT_LIST_HEAD(&udc->gadget.ep_list);
        udc->gadget.ep0 = &udc->ep[0].ep;
 
+       for (i = 0; i < NUM_ENDPOINTS; i++) {
+               struct nbu2ss_ep *ep = &udc->ep[i];
+
+               ep->udc = udc;
+               ep->desc = NULL;
+
+               ep->ep.driver_data = NULL;
+               ep->ep.name = gp_ep_name[i];
+               ep->ep.ops = &nbu2ss_ep_ops;
 
-       for (i = 0; i < NUM_ENDPOINTS; i++)
-               nbu2ss_drv_set_ep_info(udc, &udc->ep[i], gp_ep_name[i]);
+               ep->ep.maxpacket = (i == 0 ? EP0_PACKETSIZE : EP_PACKETSIZE);
+
+               list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
+               INIT_LIST_HEAD(&ep->queue);
+       }
 
        list_del_init(&udc->ep[0].ep.ep_list);
 }
@@ -3308,7 +3284,7 @@ static int __init nbu2ss_drv_contest_init(
        spin_lock_init(&udc->lock);
        udc->dev = &pdev->dev;
 
-       udc->self_powered = 1;
+       udc->gadget.is_selfpowered = 1;
        udc->devstate = USB_STATE_NOTATTACHED;
        udc->pdev = pdev;
        udc->mA = 0;
@@ -3365,7 +3341,7 @@ static int nbu2ss_drv_probe(struct platform_device *pdev)
                                  0, driver_name, udc);
 
        /* IO Memory */
-       udc->p_regs = (PT_FC_REGS)mmio_base;
+       udc->p_regs = (struct fc_regs *)mmio_base;
 
        /* USB Function Controller Interrupt */
        if (status != 0) {