X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=kernel%2Fdrivers%2Fstaging%2Femxx_udc%2Femxx_udc.c;fp=kernel%2Fdrivers%2Fstaging%2Femxx_udc%2Femxx_udc.c;h=4e6c16af40fc5f8fa2065dacb946ad2a78adf0e9;hb=e09b41010ba33a20a87472ee821fa407a5b8da36;hp=fbf82bc735cff6c6249ddae0c923b29e640699f8;hpb=f93b97fd65072de626c074dbe099a1fff05ce060;p=kvmfornfv.git diff --git a/kernel/drivers/staging/emxx_udc/emxx_udc.c b/kernel/drivers/staging/emxx_udc/emxx_udc.c index fbf82bc73..4e6c16af4 100644 --- a/kernel/drivers/staging/emxx_udc/emxx_udc.c +++ b/kernel/drivers/staging/emxx_udc/emxx_udc.c @@ -12,14 +12,10 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. */ #include -#include +#include #include #include #include @@ -44,11 +40,9 @@ #include "emxx_udc.h" -#define DRIVER_DESC "EMXX UDC driver" #define DMA_ADDR_INVALID (~(dma_addr_t)0) static const char driver_name[] = "emxx_udc"; -static const char driver_desc[] = DRIVER_DESC; /*===========================================================================*/ /* Prototype */ @@ -67,12 +61,10 @@ static void _nbu2ss_fifo_flush(struct nbu2ss_udc *, struct nbu2ss_ep *); #define _nbu2ss_zero_len_pkt(udc, epnum) \ _nbu2ss_ep_in_end(udc, epnum, 0, 0) - /*===========================================================================*/ /* Global */ struct nbu2ss_udc udc_controller; - /*-------------------------------------------------------------------------*/ /* Read */ static inline u32 _nbu2ss_readl(void *address) @@ -114,7 +106,7 @@ static void _nbu2ss_dump_register(struct nbu2ss_udc *udc) pr_info("=== %s()\n", __func__); - if (udc == NULL) { + if (!udc) { pr_err("%s udc == NULL\n", __func__); return; } @@ -155,7 +147,7 @@ static void _nbu2ss_ep0_complete(struct usb_ep *_ep, struct usb_request *_req) struct usb_ctrlrequest *p_ctrl; struct nbu2ss_udc *udc; - if ((_ep == NULL) || (_req == NULL)) + if ((!_ep) || (!_req)) return; udc = (struct nbu2ss_udc *)_req->context; @@ -219,7 +211,7 @@ static u32 _nbu2ss_get_begin_ram_address(struct nbu2ss_udc *udc) } if ((data >> 16) > last_ram_adr) - last_ram_adr = data>>16; + last_ram_adr = data >> 16; } return last_ram_adr + use_ram_size; @@ -595,7 +587,7 @@ static int EP0_out_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 length) union usb_reg_access Temp32; union usb_reg_access *pBuf32 = (union usb_reg_access *)pBuf; - if ((0 < length) && (length < sizeof(u32))) { + if ((length > 0) && (length < sizeof(u32))) { Temp32.dw = _nbu2ss_readl(&udc->p_regs->EP0_READ); for (i = 0 ; i < length ; i++) pBuf32->byte.DATA[i] = Temp32.byte.DATA[i]; @@ -641,7 +633,7 @@ static int EP0_in_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 iRemainSize) union usb_reg_access Temp32; union usb_reg_access *pBuf32 = (union usb_reg_access *)pBuf; - if ((0 < iRemainSize) && (iRemainSize < sizeof(u32))) { + if ((iRemainSize > 0) && (iRemainSize < sizeof(u32))) { for (i = 0 ; i < iRemainSize ; i++) Temp32.byte.DATA[i] = pBuf32->byte.DATA[i]; _nbu2ss_ep_in_end(udc, 0, Temp32.dw, iRemainSize); @@ -691,7 +683,6 @@ static int EP0_receive_NULL(struct nbu2ss_udc *udc, bool pid_flag) /*-------------------------------------------------------------------------*/ static int _nbu2ss_ep0_in_transfer( struct nbu2ss_udc *udc, - struct nbu2ss_ep *ep, struct nbu2ss_req *req ) { @@ -749,7 +740,6 @@ static int _nbu2ss_ep0_in_transfer( /*-------------------------------------------------------------------------*/ static int _nbu2ss_ep0_out_transfer( struct nbu2ss_udc *udc, - struct nbu2ss_ep *ep, struct nbu2ss_req *req ) { @@ -778,7 +768,7 @@ static int _nbu2ss_ep0_out_transfer( req->req.actual += result; iRecvLength -= result; - if ((0 < iRecvLength) && (iRecvLength < sizeof(u32))) { + if ((iRecvLength > 0) && (iRecvLength < sizeof(u32))) { pBuffer += result; iRemainSize -= result; @@ -857,11 +847,11 @@ static int _nbu2ss_out_dma( dmacnt = (length / mpkt); lmpkt = (length % mpkt) & ~(u32)0x03; - if (DMA_MAX_COUNT < dmacnt) { + if (dmacnt > DMA_MAX_COUNT) { dmacnt = DMA_MAX_COUNT; lmpkt = 0; - } else if (0 != lmpkt) { - if (0 == dmacnt) + } else if (lmpkt != 0) { + if (dmacnt == 0) burst = 0; /* Burst OFF */ dmacnt++; } @@ -872,7 +862,7 @@ static int _nbu2ss_out_dma( data = ((dmacnt & 0xff) << 16) | DCR1_EPn_DIR0 | DCR1_EPn_REQEN; _nbu2ss_writel(&preg->EP_DCR[num].EP_DCR1, data); - if (0 == burst) { + if (burst == 0) { _nbu2ss_writel(&preg->EP_REGS[num].EP_LEN_DCNT, 0); _nbu2ss_bitclr(&preg->EP_REGS[num].EP_DMA_CTRL, EPn_BURST_SET); } else { @@ -1223,7 +1213,7 @@ static int _nbu2ss_epn_in_transfer( } /*-------------------------------------------------------------*/ - /* Start tranfer */ + /* Start transfer */ iBufSize = req->req.length - req->req.actual; if (iBufSize > 0) result = _nbu2ss_epn_in_data(udc, ep, req, iBufSize); @@ -1258,11 +1248,11 @@ static int _nbu2ss_start_transfer( /* EP0 */ switch (udc->ep0state) { case EP0_IN_DATA_PHASE: - nret = _nbu2ss_ep0_in_transfer(udc, ep, req); + nret = _nbu2ss_ep0_in_transfer(udc, req); break; case EP0_OUT_DATA_PHASE: - nret = _nbu2ss_ep0_out_transfer(udc, ep, req); + nret = _nbu2ss_ep0_out_transfer(udc, req); break; case EP0_IN_STATUS_PHASE: @@ -1277,7 +1267,7 @@ static int _nbu2ss_start_transfer( /* EPn */ if (ep->direct == USB_DIR_OUT) { /* OUT */ - if (bflag == FALSE) + if (!bflag) nret = _nbu2ss_epn_out_transfer(udc, ep, req); } else { /* IN */ @@ -1300,7 +1290,7 @@ static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) + if (!req) return; if (ep->epnum > 0) { @@ -1398,7 +1388,6 @@ static void _nbu2ss_set_endpoint_stall( } } - /*-------------------------------------------------------------------------*/ /* Device Descriptor */ static struct usb_device_descriptor device_desc = { @@ -1447,7 +1436,7 @@ static int _nbu2ss_set_feature_device( switch (selector) { case USB_DEVICE_REMOTE_WAKEUP: - if (0x0000 == wIndex) { + if (wIndex == 0x0000) { udc->remote_wakeup = U2F_ENABLE; result = 0; } @@ -1504,8 +1493,8 @@ static inline int _nbu2ss_req_feature(struct nbu2ss_udc *udc, bool bset) u8 ep_adrs; int result = -EOPNOTSUPP; - if ((0x0000 != udc->ctrl.wLength) || - (USB_DIR_OUT != direction)) { + if ((udc->ctrl.wLength != 0x0000) || + (direction != USB_DIR_OUT)) { return -EINVAL; } @@ -1518,9 +1507,9 @@ static inline int _nbu2ss_req_feature(struct nbu2ss_udc *udc, bool bset) case USB_RECIP_ENDPOINT: if (0x0000 == (wIndex & 0xFF70)) { - if (USB_ENDPOINT_HALT == selector) { + if (selector == USB_ENDPOINT_HALT) { ep_adrs = wIndex & 0xFF; - if (bset == FALSE) { + if (!bset) { _nbu2ss_endpoint_toggle_reset( udc, ep_adrs); } @@ -1597,8 +1586,8 @@ static int std_req_get_status(struct nbu2ss_udc *udc) u8 ep_adrs; int result = -EINVAL; - if ((0x0000 != udc->ctrl.wValue) - || (USB_DIR_IN != direction)) { + if ((udc->ctrl.wValue != 0x0000) + || (direction != USB_DIR_IN)) { return result; } @@ -1635,7 +1624,7 @@ static int std_req_get_status(struct nbu2ss_udc *udc) if (result >= 0) { memcpy(udc->ep0_buf, &status_data, length); _nbu2ss_create_ep0_packet(udc, udc->ep0_buf, length); - _nbu2ss_ep0_in_transfer(udc, &udc->ep[0], &udc->ep0_req); + _nbu2ss_ep0_in_transfer(udc, &udc->ep0_req); } else { dev_err(udc->dev, " Error GET_STATUS\n"); @@ -1662,9 +1651,9 @@ static int std_req_set_address(struct nbu2ss_udc *udc) int result = 0; u32 wValue = udc->ctrl.wValue; - if ((0x00 != udc->ctrl.bRequestType) || - (0x0000 != udc->ctrl.wIndex) || - (0x0000 != udc->ctrl.wLength)) { + if ((udc->ctrl.bRequestType != 0x00) || + (udc->ctrl.wIndex != 0x0000) || + (udc->ctrl.wLength != 0x0000)) { return -EINVAL; } @@ -1684,9 +1673,9 @@ static int std_req_set_configuration(struct nbu2ss_udc *udc) { u32 ConfigValue = (u32)(udc->ctrl.wValue & 0x00ff); - if ((0x0000 != udc->ctrl.wIndex) || - (0x0000 != udc->ctrl.wLength) || - (0x00 != udc->ctrl.bRequestType)) { + if ((udc->ctrl.wIndex != 0x0000) || + (udc->ctrl.wLength != 0x0000) || + (udc->ctrl.bRequestType != 0x00)) { return -EINVAL; } @@ -1707,7 +1696,7 @@ static int std_req_set_configuration(struct nbu2ss_udc *udc) /*-------------------------------------------------------------------------*/ static inline void _nbu2ss_read_request_data(struct nbu2ss_udc *udc, u32 *pdata) { - if ((udc == NULL) && (pdata == NULL)) + if ((!udc) && (!pdata)) return; *pdata = _nbu2ss_readl(&udc->p_regs->SETUP_DATA0); @@ -1767,7 +1756,7 @@ static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc) } } - if (bcall_back == FALSE) { + if (!bcall_back) { if (udc->ep0state == EP0_IN_STATUS_PHASE) { if (nret >= 0) { /*--------------------------------------*/ @@ -1800,13 +1789,13 @@ static inline int _nbu2ss_ep0_in_data_stage(struct nbu2ss_udc *udc) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) + if (!req) req = &udc->ep0_req; req->req.actual += req->div_len; req->div_len = 0; - nret = _nbu2ss_ep0_in_transfer(udc, ep, req); + nret = _nbu2ss_ep0_in_transfer(udc, req); if (nret == 0) { udc->ep0state = EP0_OUT_STATUS_PAHSE; EP0_receive_NULL(udc, TRUE); @@ -1827,10 +1816,10 @@ static inline int _nbu2ss_ep0_out_data_stage(struct nbu2ss_udc *udc) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) + if (!req) req = &udc->ep0_req; - nret = _nbu2ss_ep0_out_transfer(udc, ep, req); + nret = _nbu2ss_ep0_out_transfer(udc, req); if (nret == 0) { udc->ep0state = EP0_IN_STATUS_PHASE; EP0_send_NULL(udc, TRUE); @@ -1854,7 +1843,7 @@ static inline int _nbu2ss_ep0_status_stage(struct nbu2ss_udc *udc) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) { + if (!req) { req = &udc->ep0_req; if (req->req.complete) req->req.complete(&ep->ep, &req->req); @@ -2055,7 +2044,7 @@ static inline void _nbu2ss_epn_in_dma_int( preq = &req->req; - if (req->dma_flag == FALSE) + if (!req->dma_flag) return; preq->actual += req->div_len; @@ -2161,7 +2150,7 @@ static inline void _nbu2ss_epn_int(struct nbu2ss_udc *udc, u32 epnum) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) { + if (!req) { /* pr_warn("=== %s(%d) req == NULL\n", __func__, epnum); */ return; } @@ -2199,19 +2188,6 @@ static void _nbu2ss_ep0_enable(struct nbu2ss_udc *udc) _nbu2ss_writel(&udc->p_regs->EP0_INT_ENA, EP0_INT_EN_BIT); } -#if 0 -/*-------------------------------------------------------------------------*/ -static void _nbu2ss_ep0_disable(struct nbu2ss_udc *udc) -{ - _nbu2ss_bitclr(&udc->p_regs->EP0_INT_ENA, EP0_INT_EN_BIT); - - _nbu2ss_bitset(&udc->p_regs->EP0_CONTROL - , (EP0_BCLR | EP0_INAK | EP0_ONAK | EP0_BCLR)); - - _nbu2ss_bitclr(&udc->p_regs->EP0_CONTROL, EP0_AUTO); -} -#endif - /*-------------------------------------------------------------------------*/ static int _nbu2ss_nuke(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep, @@ -2261,8 +2237,6 @@ static int _nbu2ss_pullup(struct nbu2ss_udc *udc, int is_on) if (is_on) { /* D+ Pullup */ -/* INFO(" --- D+ Pullup\n"); */ - if (udc->driver) { reg_dt = (_nbu2ss_readl(&udc->p_regs->USB_CONTROL) | PUE2) & ~(u32)CONNECTB; @@ -2272,8 +2246,6 @@ static int _nbu2ss_pullup(struct nbu2ss_udc *udc, int is_on) } else { /* D+ Pulldown */ -/* INFO(" --- D+ Pulldown\n"); */ - reg_dt = (_nbu2ss_readl(&udc->p_regs->USB_CONTROL) | CONNECTB) & ~(u32)PUE2; @@ -2311,12 +2283,6 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc) if (udc->udc_enabled) return 0; -#if 0 - emxx_open_clockgate(EMXX_CLK_USB1); - /* emxx_clkctrl_off(EMXX_CLKCTRL_USB1); */ - /* emxx_clkctrl_on(EMXX_CLKCTRL_USB1); */ - emxx_unreset_device(EMXX_RST_USB1); -#endif /* Reset */ @@ -2330,13 +2296,6 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc) _nbu2ss_writel(&udc->p_regs->AHBSCTR, WAIT_MODE); -#if 0 - /* DMA Mode Setting */ - if ((system_rev & EMXX_REV_MASK) == EMXX_REV_ES1) { - _nbu2ss_bitset(&udc->p_regs->AHBMCTR, BURST_TYPE); - _nbu2ss_bitclr(&udc->p_regs->AHBMCTR, HTRANS_MODE); - } else -#endif _nbu2ss_writel(&udc->p_regs->AHBMCTR, HBUSREQ_MODE | HTRANS_MODE | WBURST_TYPE); @@ -2347,11 +2306,8 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc) dev_err(udc->dev, "*** Reset Cancel failed\n"); return -EINVAL; } - }; + } -#if 0 - if ((system_rev & EMXX_REV_MASK) < EMXX_REV_ES3) -#endif _nbu2ss_bitset(&udc->p_regs->UTMI_CHARACTER_1, USB_SQUSET); _nbu2ss_bitset(&udc->p_regs->USB_CONTROL, (INT_SEL | SOF_RCV)); @@ -2367,7 +2323,6 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc) return 0; } - /*-------------------------------------------------------------------------*/ static void _nbu2ss_reset_controller(struct nbu2ss_udc *udc) { @@ -2383,11 +2338,6 @@ static void _nbu2ss_disable_controller(struct nbu2ss_udc *udc) _nbu2ss_reset_controller(udc); _nbu2ss_bitset(&udc->p_regs->EPCTR, (DIRPD | EPC_RST)); } -#if 0 - emxx_reset_device(EMXX_RST_USB1); - /* emxx_clkctrl_on(EMXX_CLKCTRL_USB1); */ - emxx_close_clockgate(EMXX_CLK_USB1); -#endif } /*-------------------------------------------------------------------------*/ @@ -2605,13 +2555,13 @@ static int nbu2ss_ep_enable( struct nbu2ss_ep *ep; struct nbu2ss_udc *udc; - if ((_ep == NULL) || (desc == NULL)) { + if ((!_ep) || (!desc)) { pr_err(" *** %s, bad param\n", __func__); return -EINVAL; } ep = container_of(_ep, struct nbu2ss_ep, ep); - if ((ep == NULL) || (ep->udc == NULL)) { + if ((!ep) || (!ep->udc)) { pr_err(" *** %s, ep == NULL !!\n", __func__); return -EINVAL; } @@ -2628,7 +2578,7 @@ static int nbu2ss_ep_enable( if (udc->vbus_active == 0) return -ESHUTDOWN; - if ((udc->driver == NULL) + if ((!udc->driver) || (udc->gadget.speed == USB_SPEED_UNKNOWN)) { dev_err(ep->udc->dev, " *** %s, udc !!\n", __func__); @@ -2665,13 +2615,13 @@ static int nbu2ss_ep_disable(struct usb_ep *_ep) struct nbu2ss_udc *udc; unsigned long flags; - if (_ep == NULL) { + if (!_ep) { pr_err(" *** %s, bad param\n", __func__); return -EINVAL; } ep = container_of(_ep, struct nbu2ss_ep, ep); - if ((ep == NULL) || (ep->udc == NULL)) { + if ((!ep) || (!ep->udc)) { pr_err("udc: *** %s, ep == NULL !!\n", __func__); return -EINVAL; } @@ -2713,7 +2663,7 @@ static void nbu2ss_ep_free_request( { struct nbu2ss_req *req; - if (_req != NULL) { + if (_req) { req = container_of(_req, struct nbu2ss_req, req); kfree(req); @@ -2734,11 +2684,11 @@ static int nbu2ss_ep_queue( int result = -EINVAL; /* catch various bogus parameters */ - if ((_ep == NULL) || (_req == NULL)) { - if (_ep == NULL) + if ((!_ep) || (!_req)) { + if (!_ep) pr_err("udc: %s --- _ep == NULL\n", __func__); - if (_req == NULL) + if (!_req) pr_err("udc: %s --- _req == NULL\n", __func__); return -EINVAL; @@ -2764,8 +2714,6 @@ static int nbu2ss_ep_queue( ep = container_of(_ep, struct nbu2ss_ep, ep); udc = ep->udc; -/* INFO("=== %s(ep%d), zero=%d\n", __func__, ep->epnum, _req->zero); */ - if (udc->vbus_active == 0) { dev_info(udc->dev, "Can't ep_queue (VBUS OFF)\n"); return -ESHUTDOWN; @@ -2786,7 +2734,7 @@ static int nbu2ss_ep_queue( req->unaligned = FALSE; if (req->unaligned) { - if (ep->virt_buf == NULL) + if (!ep->virt_buf) ep->virt_buf = (u8 *)dma_alloc_coherent( NULL, PAGE_SIZE, &ep->phys_buf, GFP_ATOMIC | GFP_DMA); @@ -2808,7 +2756,7 @@ static int nbu2ss_ep_queue( bflag = list_empty(&ep->queue); list_add_tail(&req->queue, &ep->queue); - if ((bflag != FALSE) && (ep->stalled == FALSE)) { + if (bflag && !ep->stalled) { result = _nbu2ss_start_transfer(udc, ep, req, FALSE); if (result < 0) { @@ -2841,10 +2789,8 @@ static int nbu2ss_ep_dequeue( struct nbu2ss_udc *udc; unsigned long flags; - /*INFO("=== %s()\n", __func__);*/ - /* catch various bogus parameters */ - if ((_ep == NULL) || (_req == NULL)) { + if ((!_ep) || (!_req)) { /* pr_err("%s, bad param(1)\n", __func__); */ return -EINVAL; } @@ -2856,7 +2802,7 @@ static int nbu2ss_ep_dequeue( } udc = ep->udc; - if (udc == NULL) + if (!udc) return -EINVAL; spin_lock_irqsave(&udc->lock, flags); @@ -2888,8 +2834,6 @@ static int nbu2ss_ep_set_halt(struct usb_ep *_ep, int value) struct nbu2ss_ep *ep; struct nbu2ss_udc *udc; -/* INFO("=== %s()\n", __func__); */ - if (!_ep) { pr_err("%s, bad param\n", __func__); return -EINVAL; @@ -2942,8 +2886,6 @@ static int nbu2ss_ep_fifo_status(struct usb_ep *_ep) unsigned long flags; struct fc_regs *preg; -/* INFO("=== %s()\n", __func__); */ - if (!_ep) { pr_err("%s, bad param\n", __func__); return -EINVAL; @@ -2990,15 +2932,13 @@ static void nbu2ss_ep_fifo_flush(struct usb_ep *_ep) struct nbu2ss_udc *udc; unsigned long flags; -/* INFO("=== %s()\n", __func__); */ - if (!_ep) { pr_err("udc: %s, bad param\n", __func__); return; } ep = container_of(_ep, struct nbu2ss_ep, ep); - if (!_ep) { + if (!ep) { pr_err("udc: %s, bad ep\n", __func__); return; } @@ -3036,7 +2976,6 @@ static struct usb_ep_ops nbu2ss_ep_ops = { .fifo_flush = nbu2ss_ep_fifo_flush, }; - /*-------------------------------------------------------------------------*/ /* usb_gadget_ops */ @@ -3046,15 +2985,13 @@ static int nbu2ss_gad_get_frame(struct usb_gadget *pgadget) u32 data; struct nbu2ss_udc *udc; -/* INFO("=== %s()\n", __func__); */ - - if (pgadget == NULL) { + if (!pgadget) { pr_err("udc: %s, bad param\n", __func__); return -EINVAL; } udc = container_of(pgadget, struct nbu2ss_udc, gadget); - if (udc == NULL) { + if (!udc) { dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__); return -EINVAL; } @@ -3076,15 +3013,13 @@ static int nbu2ss_gad_wakeup(struct usb_gadget *pgadget) struct nbu2ss_udc *udc; -/* INFO("=== %s()\n", __func__); */ - - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } udc = container_of(pgadget, struct nbu2ss_udc, gadget); - if (udc == NULL) { + if (!udc) { dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__); return -EINVAL; } @@ -3116,9 +3051,7 @@ static int nbu2ss_gad_set_selfpowered(struct usb_gadget *pgadget, struct nbu2ss_udc *udc; unsigned long flags; -/* INFO("=== %s()\n", __func__); */ - - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } @@ -3135,7 +3068,6 @@ static int nbu2ss_gad_set_selfpowered(struct usb_gadget *pgadget, /*-------------------------------------------------------------------------*/ static int nbu2ss_gad_vbus_session(struct usb_gadget *pgadget, int is_active) { -/* INFO("=== %s()\n", __func__); */ return 0; } @@ -3145,9 +3077,7 @@ static int nbu2ss_gad_vbus_draw(struct usb_gadget *pgadget, unsigned mA) struct nbu2ss_udc *udc; unsigned long flags; -/* INFO("=== %s()\n", __func__); */ - - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } @@ -3167,16 +3097,14 @@ static int nbu2ss_gad_pullup(struct usb_gadget *pgadget, int is_on) struct nbu2ss_udc *udc; unsigned long flags; -/* INFO("=== %s()\n", __func__); */ - - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } udc = container_of(pgadget, struct nbu2ss_udc, gadget); - if (udc->driver == NULL) { + if (!udc->driver) { pr_warn("%s, Not Regist Driver\n", __func__); return -EINVAL; } @@ -3197,11 +3125,9 @@ static int nbu2ss_gad_ioctl( unsigned code, unsigned long param) { -/* INFO("=== %s()\n", __func__); */ return 0; } - static const struct usb_gadget_ops nbu2ss_gadget_ops = { .get_frame = nbu2ss_gad_get_frame, .wakeup = nbu2ss_gad_wakeup, @@ -3212,36 +3138,46 @@ static const struct usb_gadget_ops nbu2ss_gadget_ops = { .ioctl = nbu2ss_gad_ioctl, }; -static const char g_ep0_name[] = "ep0"; -static const char g_ep1_name[] = "ep1-bulk"; -static const char g_ep2_name[] = "ep2-bulk"; -static const char g_ep3_name[] = "ep3in-int"; -static const char g_ep4_name[] = "ep4-iso"; -static const char g_ep5_name[] = "ep5-iso"; -static const char g_ep6_name[] = "ep6-bulk"; -static const char g_ep7_name[] = "ep7-bulk"; -static const char g_ep8_name[] = "ep8in-int"; -static const char g_ep9_name[] = "ep9-iso"; -static const char g_epa_name[] = "epa-iso"; -static const char g_epb_name[] = "epb-bulk"; -static const char g_epc_name[] = "epc-nulk"; -static const char g_epd_name[] = "epdin-int"; - -static const char *gp_ep_name[NUM_ENDPOINTS] = { - g_ep0_name, - g_ep1_name, - g_ep2_name, - g_ep3_name, - g_ep4_name, - g_ep5_name, - g_ep6_name, - g_ep7_name, - g_ep8_name, - g_ep9_name, - g_epa_name, - g_epb_name, - g_epc_name, - g_epd_name, +static const struct { + const char *name; + const struct usb_ep_caps caps; +} ep_info[NUM_ENDPOINTS] = { +#define EP_INFO(_name, _caps) \ + { \ + .name = _name, \ + .caps = _caps, \ + } + + EP_INFO("ep0", + USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep1-bulk", + USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep2-bulk", + USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep3in-int", + USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)), + EP_INFO("ep4-iso", + USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep5-iso", + USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep6-bulk", + USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep7-bulk", + USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)), + EP_INFO("ep8in-int", + USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)), + EP_INFO("ep9-iso", + USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)), + EP_INFO("epa-iso", + USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)), + EP_INFO("epb-bulk", + USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)), + EP_INFO("epc-bulk", + USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)), + EP_INFO("epdin-int", + USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)), + +#undef EP_INFO }; /*-------------------------------------------------------------------------*/ @@ -3259,10 +3195,12 @@ static void __init nbu2ss_drv_ep_init(struct nbu2ss_udc *udc) ep->desc = NULL; ep->ep.driver_data = NULL; - ep->ep.name = gp_ep_name[i]; + ep->ep.name = ep_info[i].name; + ep->ep.caps = ep_info[i].caps; ep->ep.ops = &nbu2ss_ep_ops; - ep->ep.maxpacket = (i == 0 ? EP0_PACKETSIZE : EP_PACKETSIZE); + usb_ep_set_maxpacket_limit(&ep->ep, + i == 0 ? EP0_PACKETSIZE : EP_PACKETSIZE); list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); INIT_LIST_HEAD(&ep->queue); @@ -3342,14 +3280,14 @@ static int nbu2ss_drv_probe(struct platform_device *pdev) /* USB Function Controller Interrupt */ if (status != 0) { dev_err(udc->dev, "request_irq(USB_UDC_IRQ_1) failed\n"); - goto cleanup1; + return status; } /* Driver Initialization */ status = nbu2ss_drv_contest_init(pdev, udc); if (status < 0) { /* Error */ - goto cleanup1; + return status; } /* VBUS Interrupt */ @@ -3362,13 +3300,10 @@ static int nbu2ss_drv_probe(struct platform_device *pdev) if (status != 0) { dev_err(udc->dev, "request_irq(INT_VBUS) failed\n"); - goto cleanup1; + return status; } return status; - -cleanup1: - return status; } /*-------------------------------------------------------------------------*/ @@ -3377,41 +3312,19 @@ static void nbu2ss_drv_shutdown(struct platform_device *pdev) struct nbu2ss_udc *udc; udc = platform_get_drvdata(pdev); - if (udc == NULL) + if (!udc) return; _nbu2ss_disable_controller(udc); } -/*-------------------------------------------------------------------------*/ -static int __exit nbu2ss_drv_remove(struct platform_device *pdev) -{ - struct nbu2ss_udc *udc; - struct nbu2ss_ep *ep; - int i; - - udc = &udc_controller; - - for (i = 0; i < NUM_ENDPOINTS; i++) { - ep = &udc->ep[i]; - if (ep->virt_buf) - dma_free_coherent(NULL, PAGE_SIZE, - (void *)ep->virt_buf, ep->phys_buf); - } - - /* Interrupt Handler - Release */ - free_irq(INT_VBUS, udc); - - return 0; -} - /*-------------------------------------------------------------------------*/ static int nbu2ss_drv_suspend(struct platform_device *pdev, pm_message_t state) { struct nbu2ss_udc *udc; udc = platform_get_drvdata(pdev); - if (udc == NULL) + if (!udc) return 0; if (udc->vbus_active) { @@ -3438,7 +3351,7 @@ static int nbu2ss_drv_resume(struct platform_device *pdev) struct nbu2ss_udc *udc; udc = platform_get_drvdata(pdev); - if (udc == NULL) + if (!udc) return 0; data = gpio_get_value(VBUS_VALUE); @@ -3454,22 +3367,15 @@ static int nbu2ss_drv_resume(struct platform_device *pdev) return 0; } - static struct platform_driver udc_driver = { .probe = nbu2ss_drv_probe, .shutdown = nbu2ss_drv_shutdown, - .remove = __exit_p(nbu2ss_drv_remove), .suspend = nbu2ss_drv_suspend, .resume = nbu2ss_drv_resume, .driver = { - .name = driver_name, + .name = driver_name, + .suppress_bind_attrs = true, }, }; -module_platform_driver(udc_driver); - -MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_AUTHOR("Renesas Electronics Corporation"); -MODULE_LICENSE("GPL"); - - +builtin_platform_driver(udc_driver);