Patchwork [U-Boot,04/17] usb: mv_udc: Clean up the EP initialization

login
register
mail settings
Submitter Marek Vasut
Date July 10, 2013, 1:16 a.m.
Message ID <1373419003-10919-5-git-send-email-marex@denx.de>
Download mbox | patch
Permalink /patch/257942/
State Awaiting Upstream
Delegated to: Marek Vasut
Headers show

Comments

Marek Vasut - July 10, 2013, 1:16 a.m.
Move the constant values that are programmed into mv_ep.ep into
separate static const structure so they can be memcpy()'d when
the initialization happens.

Moveover, we only every init NUM_ENDPOINTS, not 2 * NUM_ENDPOINTS,
so fix this bug as well.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Lei Wen <leiwen@marvell.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
---
 drivers/usb/gadget/mv_udc.c |   38 ++++++++++++++++++++++++++------------
 include/usb/mv_udc.h        |    2 +-
 2 files changed, 27 insertions(+), 13 deletions(-)

Patch

diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c
index 4c0755d..1164d74 100644
--- a/drivers/usb/gadget/mv_udc.c
+++ b/drivers/usb/gadget/mv_udc.c
@@ -99,6 +99,20 @@  static struct usb_ep_ops mv_ep_ops = {
 	.free_request   = mv_ep_free_request,
 };
 
+/* Init values for USB endpoints. */
+static const struct usb_ep mv_ep_init[2] = {
+	[0] = {	/* EP 0 */
+		.maxpacket	= 64,
+		.name		= "ep0",
+		.ops		= &mv_ep_ops,
+	},
+	[1] = {	/* EP 1..n */
+		.maxpacket	= 512,
+		.name		= "ep-",
+		.ops		= &mv_ep_ops,
+	},
+};
+
 static struct mv_drv controller = {
 	.gadget = {
 		.name = "mv_udc",
@@ -451,21 +465,21 @@  static int mvudc_probe(void)
 	}
 
 	INIT_LIST_HEAD(&controller.gadget.ep_list);
-	controller.gadget.ep0 = &controller.ep[0].ep;
-	controller.ep[0].ep.maxpacket = 64;
-	controller.ep[0].ep.name = "ep0";
+
+	/* Init EP 0 */
+	memcpy(&controller.ep[0].ep, &mv_ep_init[0], sizeof(*mv_ep_init));
 	controller.ep[0].desc = &ep0_in_desc;
+	controller.gadget.ep0 = &controller.ep[0].ep;
 	INIT_LIST_HEAD(&controller.gadget.ep0->ep_list);
-	for (i = 0; i < 2 * NUM_ENDPOINTS; i++) {
-		if (i != 0) {
-			controller.ep[i].ep.maxpacket = 512;
-			controller.ep[i].ep.name = "ep-";
-			list_add_tail(&controller.ep[i].ep.ep_list,
-				      &controller.gadget.ep_list);
-			controller.ep[i].desc = NULL;
-		}
-		controller.ep[i].ep.ops = &mv_ep_ops;
+
+	/* Init EP 1..n */
+	for (i = 1; i < NUM_ENDPOINTS; i++) {
+		memcpy(&controller.ep[i].ep, &mv_ep_init[1],
+		       sizeof(*mv_ep_init));
+		list_add_tail(&controller.ep[i].ep.ep_list,
+			      &controller.gadget.ep_list);
 	}
+
 	return 0;
 }
 
diff --git a/include/usb/mv_udc.h b/include/usb/mv_udc.h
index da93ad3..88100ce 100644
--- a/include/usb/mv_udc.h
+++ b/include/usb/mv_udc.h
@@ -87,7 +87,7 @@  struct mv_drv {
 	struct usb_gadget		gadget;
 	struct usb_gadget_driver	*driver;
 	struct mv_udc			*udc;
-	struct mv_ep			ep[2 * NUM_ENDPOINTS];
+	struct mv_ep			ep[NUM_ENDPOINTS];
 };
 
 struct ept_queue_head {