[U-Boot] [PATCH 03/17] usb: mv_udc: Move endpoint array into driver data

Marek Vasut marex at denx.de
Wed Jul 10 03:16:29 CEST 2013


The endpoints are operated on a per-controller basis, move the
endpoint array into controller's private data. Also shuffle the
struct mv_ep structure definition just above the definition of
the struct mv_drv so they're well grouped together.

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

diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c
index db30bdd..4c0755d 100644
--- a/drivers/usb/gadget/mv_udc.c
+++ b/drivers/usb/gadget/mv_udc.c
@@ -99,10 +99,8 @@ static struct usb_ep_ops mv_ep_ops = {
 	.free_request   = mv_ep_free_request,
 };
 
-static struct mv_ep ep[2 * NUM_ENDPOINTS];
 static struct mv_drv controller = {
 	.gadget = {
-		.ep0 = &ep[0].ep,
 		.name = "mv_udc",
 	},
 };
@@ -223,7 +221,7 @@ static void handle_ep_complete(struct mv_ep *ep)
 
 static void handle_setup(void)
 {
-	struct usb_request *req = &ep[0].req;
+	struct usb_request *req = &controller.ep[0].req;
 	struct mv_udc *udc = controller.udc;
 	struct ept_queue_head *head;
 	struct usb_ctrlrequest r;
@@ -246,11 +244,11 @@ static void handle_setup(void)
 		if ((r.wValue == 0) && (r.wLength == 0)) {
 			req->length = 0;
 			for (i = 0; i < NUM_ENDPOINTS; i++) {
-				if (!ep[i].desc)
+				if (!controller.ep[i].desc)
 					continue;
-				num = ep[i].desc->bEndpointAddress
-					& USB_ENDPOINT_NUMBER_MASK;
-				in = (ep[i].desc->bEndpointAddress
+				num = controller.ep[i].desc->bEndpointAddress
+						& USB_ENDPOINT_NUMBER_MASK;
+				in = (controller.ep[i].desc->bEndpointAddress
 						& USB_DIR_IN) != 0;
 				if ((num == _num) && (in == _in)) {
 					ep_enable(num, in);
@@ -306,10 +304,11 @@ static void stop_activity(void)
 	for (i = 0; i < NUM_ENDPOINTS; i++) {
 		if (i != 0)
 			writel(0, &udc->epctrl[i]);
-		if (ep[i].desc) {
-			num = ep[i].desc->bEndpointAddress
+		if (controller.ep[i].desc) {
+			num = controller.ep[i].desc->bEndpointAddress
 				& USB_ENDPOINT_NUMBER_MASK;
-			in = (ep[i].desc->bEndpointAddress & USB_DIR_IN) != 0;
+			in = (controller.ep[i].desc->bEndpointAddress
+				& USB_DIR_IN) != 0;
 			head = epts + (num * 2) + (in);
 			head->info = INFO_ACTIVE;
 		}
@@ -340,8 +339,8 @@ void udc_irq(void)
 		if (bit == 2) {
 			controller.gadget.speed = USB_SPEED_HIGH;
 			for (i = 1; i < NUM_ENDPOINTS && n; i++)
-				if (ep[i].desc)
-					ep[i].ep.maxpacket = 512;
+				if (controller.ep[i].desc)
+					controller.ep[i].ep.maxpacket = 512;
 		} else {
 			controller.gadget.speed = USB_SPEED_FULL;
 		}
@@ -360,14 +359,14 @@ void udc_irq(void)
 			writel(n, &udc->epcomp);
 
 		for (i = 0; i < NUM_ENDPOINTS && n; i++) {
-			if (ep[i].desc) {
-				num = ep[i].desc->bEndpointAddress
+			if (controller.ep[i].desc) {
+				num = controller.ep[i].desc->bEndpointAddress
 					& USB_ENDPOINT_NUMBER_MASK;
-				in = (ep[i].desc->bEndpointAddress
+				in = (controller.ep[i].desc->bEndpointAddress
 						& USB_DIR_IN) != 0;
 				bit = (in) ? EPT_TX(num) : EPT_RX(num);
 				if (n & bit)
-					handle_ep_complete(&ep[i]);
+					handle_ep_complete(&controller.ep[i]);
 			}
 		}
 	}
@@ -452,19 +451,20 @@ static int mvudc_probe(void)
 	}
 
 	INIT_LIST_HEAD(&controller.gadget.ep_list);
-	ep[0].ep.maxpacket = 64;
-	ep[0].ep.name = "ep0";
-	ep[0].desc = &ep0_in_desc;
+	controller.gadget.ep0 = &controller.ep[0].ep;
+	controller.ep[0].ep.maxpacket = 64;
+	controller.ep[0].ep.name = "ep0";
+	controller.ep[0].desc = &ep0_in_desc;
 	INIT_LIST_HEAD(&controller.gadget.ep0->ep_list);
 	for (i = 0; i < 2 * NUM_ENDPOINTS; i++) {
 		if (i != 0) {
-			ep[i].ep.maxpacket = 512;
-			ep[i].ep.name = "ep-";
-			list_add_tail(&ep[i].ep.ep_list,
+			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);
-			ep[i].desc = NULL;
+			controller.ep[i].desc = NULL;
 		}
-		ep[i].ep.ops = &mv_ep_ops;
+		controller.ep[i].ep.ops = &mv_ep_ops;
 	}
 	return 0;
 }
diff --git a/include/usb/mv_udc.h b/include/usb/mv_udc.h
index 42dff29..da93ad3 100644
--- a/include/usb/mv_udc.h
+++ b/include/usb/mv_udc.h
@@ -35,13 +35,6 @@
 #define EP_MAX_PACKET_SIZE	0x200
 #define EP0_MAX_PACKET_SIZE	64
 
-struct mv_ep {
-	struct usb_ep ep;
-	struct usb_request req;
-	struct list_head queue;
-	const struct usb_endpoint_descriptor *desc;
-};
-
 struct mv_udc {
 	u32 pad0[80];
 #define MICRO_8FRAME	0x8
@@ -83,10 +76,18 @@ struct mv_udc {
 	u32 epctrl[16];		/* 0x1c0 */
 };
 
+struct mv_ep {
+	struct usb_ep ep;
+	struct usb_request req;
+	struct list_head queue;
+	const struct usb_endpoint_descriptor *desc;
+};
+
 struct mv_drv {
 	struct usb_gadget		gadget;
-	struct usb_gadget_driver		*driver;
+	struct usb_gadget_driver	*driver;
 	struct mv_udc			*udc;
+	struct mv_ep			ep[2 * NUM_ENDPOINTS];
 };
 
 struct ept_queue_head {
-- 
1.7.10.4



More information about the U-Boot mailing list