usb: gadget: lpc32xx_udc: Port to new start/stop interface
Subsystems (2)
PATCH v2 1/3 usb: gadget: lpc32xx_udc: Port to new start/stop interface
This patch adjusts the LPC32xx USB gadget driver to the new udc_start / udc_stop interface.
---
Applies to v3.6-rc2
Changes since v1:
* None
drivers/usb/gadget/lpc32xx_udc.c | 49 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 35 deletions(-)
drivers/usb/gadget/lpc32xx_udc.c +14 -35
@@ -2599,9 +2599,8 @@ static int lpc32xx_pullup(struct usb_gadreturn 0 ; } -static int lpc32xx_start (struct usb_gadget_driver *driver, -int (*bind)(struct usb_gadget *)); -static int lpc32xx_stop (struct usb_gadget_driver *driver); +static int lpc32xx_start (struct usb_gadget *,struct usb_gadget_driver *); +static int lpc32xx_stop (struct usb_gadget *,struct usb_gadget_driver *);static const struct usb_gadget_ops lpc32xx_udc_ops = { .get_frame = lpc32xx_get_frame,
@@ -2609,8 +2608,8 @@ static const struct usb_gadget_ops lpc32 .set_selfpowered = lpc32xx_set_selfpowered, .vbus_session = lpc32xx_vbus_session, .pullup = lpc32xx_pullup, - .start = lpc32xx_start, - .stop = lpc32xx_stop, + .udc_start = lpc32xx_start, + .udc_stop = lpc32xx_stop, };static void nop_release (struct device *dev)
@@ -2987,14 +2986,13 @@ static irqreturn_t lpc32xx_usb_vbus_irq(return IRQ_HANDLED ; } -static int lpc32xx_start (struct usb_gadget_driver *driver, -int (*bind)(struct usb_gadget *)) +static int lpc32xx_start (struct usb_gadget *gadget, +struct usb_gadget_driver *driver) { -struct lpc32xx_udc *udc = &controller; -int retval, i; +struct lpc32xx_udc *udc =to_udc (gadget); +int i; -if (!driver || driver->max_speed <USB_SPEED_FULL || - !bind || !driver->setup) { +if (!driver || driver->max_speed <USB_SPEED_FULL || !driver->setup) {dev_err (udc->dev,"bad parameter.\n" );return -EINVAL ; }
@@ -3011,18 +3009,6 @@ static int lpc32xx_start(struct usb_gadg udc->selfpowered =1 ; udc->vbus =0 ; - retval =bind (&udc->gadget); -if (retval) { -dev_err (udc->dev,"bind() returned %d\n" , retval); - udc->enabled =0 ; - udc->selfpowered =0 ; - udc->driver =NULL ; - udc->gadget.dev.driver =NULL ; -return retval; - } - -dev_dbg (udc->dev,"bound to %s\n" , driver->driver.name); -/* Force VBUS process once to check for cable insertion */ udc->last_vbus = udc->vbus =0 ;schedule_work (&udc->vbus_job);
@@ -3034,22 +3020,19 @@ static int lpc32xx_start(struct usb_gadgreturn 0 ; } -static int lpc32xx_stop (struct usb_gadget_driver *driver) +static int lpc32xx_stop (struct usb_gadget *gadget, +struct usb_gadget_driver *driver) {int i; -struct lpc32xx_udc *udc = &controller; +struct lpc32xx_udc *udc =to_udc (gadget); -if (!driver || driver != udc->driver || !driver->unbind) +if (!driver || driver != udc->driver)return -EINVAL ; -/* Disable USB pullup */ -isp1301_pullup_enable (udc,0 ,1 ); -for (i =IRQ_USB_LP ; i <=IRQ_USB_ATX ; i++)disable_irq (udc->udp_irq[i]);if (udc->clocked) { -spin_lock (&udc->lock);stop_activity (udc);spin_unlock (&udc->lock);
@@ -3069,20 +3052,16 @@ static int lpc32xx_stop(struct usb_gadge } udc->enabled =0 ; -pullup (udc,0 ); - - driver->unbind (&udc->gadget); udc->gadget.dev.driver =NULL ; udc->driver =NULL ; -dev_dbg (udc->dev,"unbound from %s\n" , driver->driver.name);return 0 ; }static void lpc32xx_udc_shutdown (struct platform_device *dev) {/* Force disconnect on reboot */ -struct lpc32xx_udc *udc = &controller; +struct lpc32xx_udc *udc =platform_get_drvdata (dev);pullup (udc,0 ); }
PATCH v2 2/3 usb: gadget: lpc32xx_udc: Remove usb_endpoint_descriptor
This patch removes the utilization of struct usb_endpoint_descriptor, as done by other drivers also. This was done on request by the USB gadget maintainers, since this API is obsoleted.
---
Changes since v1:
* None
drivers/usb/gadget/lpc32xx_udc.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/usb/gadget/lpc32xx_udc.c +7 -16
@@ -141,8 +141,6 @@ struct lpc32xx_ep {u32 totalints;bool wedge; - -const struct usb_endpoint_descriptor *desc; };/*
@@ -556,10 +554,8 @@ static int proc_udc_show(struct seq_fileif (udc->enabled && udc->vbus) {proc_ep_show (s, &udc->ep[0 ]); -list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { -if (ep->desc) -proc_ep_show (s, ep); - } +list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) +proc_ep_show (s, ep); }spin_unlock_irqrestore (&udc->lock, flags);
@@ -1453,7 +1449,6 @@ static void udc_reinit(struct lpc32xx_udif (i !=0 )list_add_tail (&ep->ep.ep_list, &udc->gadget.ep_list); - ep->desc =NULL ; ep->ep.maxpacket = ep->maxpacket;INIT_LIST_HEAD (&ep->queue); ep->req_pending =0 ;
@@ -1515,7 +1510,7 @@ static void nuke(struct lpc32xx_ep *ep,done (ep, req, status); } -if (ep->desc && status == -ESHUTDOWN ) { +if (status == -ESHUTDOWN ) {uda_disable_hwepint (ep->udc, ep->hwep_num);udc_disable_hwep (ep->udc, ep->hwep_num); }
@@ -1658,9 +1653,6 @@ static int lpc32xx_ep_disable(struct usbnuke (ep, -ESHUTDOWN ); -/* restore the endpoint's pristine config */ - ep->desc =NULL ; -/* Clear all DMA statuses for this EP */ udc_ep_dma_disable (udc, ep->hwep_num);writel (1 << ep->hwep_num,USBD_EOTINTCLR (udc->udp_baseaddr));
@@ -1696,7 +1688,7 @@ static int lpc32xx_ep_enable(struct usb_unsigned long flags;/* Verify EP data */ -if ((!_ep) || (!ep) || (!desc) || (ep->desc) || +if ((!_ep) || (!ep) || (!desc) || (desc->bDescriptorType !=USB_DT_ENDPOINT )) {dev_dbg (udc->dev,"bad ep or descriptor\n" );return -EINVAL ;
@@ -1754,7 +1746,6 @@ static int lpc32xx_ep_enable(struct usb_/* Initialize endpoint to match the selected descriptor */ ep->is_in = (desc->bEndpointAddress &USB_DIR_IN ) !=0 ; - ep->desc = desc; ep->ep.maxpacket = maxpacket;/* Map hardware endpoint from base and direction */
@@ -1837,7 +1828,7 @@ static int lpc32xx_ep_queue(struct usb_e udc = ep->udc; -if (!_ep || (!ep->desc && ep->hwep_num_base !=0 )) { +if (!_ep) {dev_dbg (udc->dev,"invalid ep\n" );return -EINVAL ; }
@@ -1976,7 +1967,7 @@ static int lpc32xx_ep_set_halt(struct usstruct lpc32xx_udc *udc = ep->udc;unsigned long flags; -if ((!ep) || (ep->desc ==NULL ) || (ep->hwep_num <=1 )) +if ((!ep) || (ep->hwep_num <=1 ))return -EINVAL ;/* Don't halt an IN EP */
@@ -2262,7 +2253,7 @@ static int udc_get_status(struct lpc32xxcase USB_RECIP_ENDPOINT : tmp = wIndex &USB_ENDPOINT_NUMBER_MASK ; ep = &udc->ep[tmp]; -if ((tmp ==0 ) || (tmp >=NUM_ENDPOINTS ) || (tmp && !ep->desc)) +if ((tmp ==0 ) || (tmp >=NUM_ENDPOINTS ))return -EOPNOTSUPP ;if (wIndex &USB_DIR_IN ) {
PATCH v2 3/3 usb: gadget: lpc32xx_udc: Support multiple controllers
In reply to Roland StiggeThe lpc32xx_udc driver supported only one controller by defining a global static struct for it. This patch enables multiple instances of the controller by dynamic allocation of the struct at probe(). A static struct is kept as a template on initialization since it does some complex preset, reflecting fixed hardware endpoint structure.
---
Changes since v1:
* Make controller_template const
drivers/usb/gadget/lpc32xx_udc.c | 55 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-)
drivers/usb/gadget/lpc32xx_udc.c +29 -26
@@ -2608,10 +2608,9 @@ static void nop_release(struct device *d/* nothing to free */ } -static struct lpc32xx_udc controller = { +static const struct lpc32xx_udc controller_template = { .gadget = { .ops = &lpc32xx_udc_ops, - .ep0 = &controller.ep[0 ].ep, .name = driver_name, .dev = { .init_name ="gadget" ,
@@ -2623,7 +2622,6 @@ static struct lpc32xx_udc controller = { .name = "ep0", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 0, .hwep_num = 0, /* Can be 0 or 1, has special handling */
@@ -2635,7 +2633,6 @@ static struct lpc32xx_udc controller = { .name = "ep1-int", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 2, .hwep_num = 0, /* 2 or 3, will be set later */
@@ -2647,7 +2644,6 @@ static struct lpc32xx_udc controller = { .name = "ep2-bulk", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 4, .hwep_num = 0, /* 4 or 5, will be set later */
@@ -2659,7 +2655,6 @@ static struct lpc32xx_udc controller = { .name = "ep3-iso", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 1023, .hwep_num_base = 6, .hwep_num = 0, /* 6 or 7, will be set later */
@@ -2671,7 +2666,6 @@ static struct lpc32xx_udc controller = { .name = "ep4-int", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 8, .hwep_num = 0, /* 8 or 9, will be set later */
@@ -2683,7 +2677,6 @@ static struct lpc32xx_udc controller = { .name = "ep5-bulk", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 10, .hwep_num = 0, /* 10 or 11, will be set later */
@@ -2695,7 +2688,6 @@ static struct lpc32xx_udc controller = { .name = "ep6-iso", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 1023, .hwep_num_base = 12, .hwep_num = 0, /* 12 or 13, will be set later */
@@ -2707,7 +2699,6 @@ static struct lpc32xx_udc controller = { .name = "ep7-int", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 14, .hwep_num = 0,
@@ -2719,7 +2710,6 @@ static struct lpc32xx_udc controller = { .name = "ep8-bulk", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 16, .hwep_num = 0,
@@ -2731,7 +2721,6 @@ static struct lpc32xx_udc controller = { .name = "ep9-iso", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 1023, .hwep_num_base = 18, .hwep_num = 0,
@@ -2743,7 +2732,6 @@ static struct lpc32xx_udc controller = { .name = "ep10-int", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 20, .hwep_num = 0,
@@ -2755,7 +2743,6 @@ static struct lpc32xx_udc controller = { .name = "ep11-bulk", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 22, .hwep_num = 0,
@@ -2767,7 +2754,6 @@ static struct lpc32xx_udc controller = { .name = "ep12-iso", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 1023, .hwep_num_base = 24, .hwep_num = 0,
@@ -2779,7 +2765,6 @@ static struct lpc32xx_udc controller = { .name = "ep13-int", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 26, .hwep_num = 0,
@@ -2791,7 +2776,6 @@ static struct lpc32xx_udc controller = { .name = "ep14-bulk", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 64, .hwep_num_base = 28, .hwep_num = 0,
@@ -2803,7 +2787,6 @@ static struct lpc32xx_udc controller = { .name = "ep15-bulk", .ops = &lpc32xx_ep_ops, }, - .udc = &controller, .maxpacket = 1023, .hwep_num_base = 30, .hwep_num = 0,
@@ -3090,12 +3073,21 @@ static u64 lpc32xx_usbd_dmamask = ~(u32)static int __init lpc32xx_udc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct lpc32xx_udc *udc = &controller; +struct lpc32xx_udc *udc;int retval, i;struct resource *res;dma_addr_t dma_handle;struct device_node *isp1301_node; + udc =kzalloc (sizeof (*udc),GFP_KERNEL ); +if (!udc) +return -ENOMEM ; + +memcpy (udc, &controller_template,sizeof (*udc)); +for (i =0 ; i <=15 ; i++) + udc->ep[i].udc = udc; + udc->gadget.ep0 = &udc->ep[0 ].ep; +/* init software state */ udc->gadget.dev.parent = dev; udc->pdev = pdev;
@@ -3110,8 +3102,10 @@ static int __init lpc32xx_udc_probe(stru } udc->isp1301_i2c_client =isp1301_get_client (isp1301_node); -if (!udc->isp1301_i2c_client) -return -EPROBE_DEFER ; +if (!udc->isp1301_i2c_client) { + retval = -EPROBE_DEFER ; + goto phy_fail; + }dev_info (udc->dev,"ISP1301 I2C device at address 0x%x\n" , udc->isp1301_i2c_client->addr);
@@ -3130,8 +3124,10 @@ static int __init lpc32xx_udc_probe(stru* IORESOURCE_IRQ, USB transceiver interrupt number */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) -return -ENXIO ; +if (!res) { + retval = -ENXIO ; + goto resource_fail; + }spin_lock_init (&udc->lock);
@@ -3141,7 +3137,8 @@ static int __init lpc32xx_udc_probe(struif (udc->udp_irq[i] <0 ) {dev_err (udc->dev,"irq resource %d not available!\n" , i); -return udc->udp_irq[i]; + retval = udc->udp_irq[i]; + goto irq_fail; } }
@@ -3149,7 +3146,8 @@ static int __init lpc32xx_udc_probe(stru udc->io_p_size =resource_size (res);if (!request_mem_region (udc->io_p_start, udc->io_p_size, driver_name)) {dev_err (udc->dev,"someone's using UDC memory\n" ); -return -EBUSY ; + retval = -EBUSY ; + goto request_mem_region_fail; } udc->udp_baseaddr =ioremap (udc->io_p_start, udc->io_p_size);
@@ -3346,7 +3344,11 @@ pll_get_fail: io_map_fail:release_mem_region (udc->io_p_start, udc->io_p_size);dev_err (udc->dev,"%s probe failed, %d\n" , driver_name, retval); - +request_mem_region_fail: +irq_fail: +resource_fail: +phy_fail: +kfree (udc);return retval; }
@@ -3384,6 +3386,7 @@ static int __devexit lpc32xx_udc_remove(clk_put (udc->usb_pll_clk);iounmap (udc->udp_baseaddr);release_mem_region (udc->io_p_start, udc->io_p_size); +kfree (udc);return 0 ; }