[PATCH 05/10] USB endpoint autoconfiguration: use helper functions to determine endpoint type and direction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use helper functions to determine the type and direction of an endpoint instead
of fiddling with bEndpointAddress and bmAttributes

Signed-off-by: Matthias Kaehlcke <matthias@xxxxxxxxxxxx>
---
 drivers/usb/gadget/epautoconf.c |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index cd0914e..f56b4b0 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -66,7 +66,6 @@ ep_matches (
 	struct usb_endpoint_descriptor	*desc
 )
 {
-	u8		type;
 	const char	*tmp;
 	u16		max;
 
@@ -75,8 +74,7 @@ ep_matches (
 		return 0;
 
 	/* only support ep0 for portable CONTROL traffic */
-	type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
-	if (USB_ENDPOINT_XFER_CONTROL == type)
+	if (usb_endpoint_xfer_control(desc))
 		return 0;
 
 	/* some other naming convention */
@@ -89,7 +87,7 @@ ep_matches (
 	if ('-' != ep->name[2]) {
 		tmp = strrchr (ep->name, '-');
 		if (tmp) {
-			switch (type) {
+			switch (usb_endpoint_type(desc)) {
 			case USB_ENDPOINT_XFER_INT:
 				/* bulk endpoints handle interrupt transfers,
 				 * except the toggle-quirky iso-synch kind
@@ -118,7 +116,7 @@ ep_matches (
 		/* direction-restriction:  "..in-..", "out-.." */
 		tmp--;
 		if (!isdigit (*tmp)) {
-			if (desc->bEndpointAddress & USB_DIR_IN) {
+			if (usb_endpoint_dir_in(desc)) {
 				if ('n' != *tmp)
 					return 0;
 			} else {
@@ -133,7 +131,7 @@ ep_matches (
 	 * the usb spec fixes high speed bulk maxpacket at 512 bytes.
 	 */
 	max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
-	switch (type) {
+	switch (usb_endpoint_type(desc)) {
 	case USB_ENDPOINT_XFER_INT:
 		/* INT:  limit 64 bytes full speed, 1024 high speed */
 		if (!gadget->is_dualspeed && max > 64)
@@ -164,7 +162,7 @@ ep_matches (
 		u8	num = simple_strtoul (&ep->name [2], NULL, 10);
 		desc->bEndpointAddress |= num;
 #ifdef	MANY_ENDPOINTS
-	} else if (desc->bEndpointAddress & USB_DIR_IN) {
+	} else if (usb_endpoint_dir_in(desc)) {
 		if (++in_epnum > 15)
 			return 0;
 		desc->bEndpointAddress = USB_DIR_IN | in_epnum;
@@ -176,7 +174,7 @@ ep_matches (
 	}
 
 	/* report (variable) full speed bulk maxpacket */
-	if (USB_ENDPOINT_XFER_BULK == type) {
+	if (usb_endpoint_xfer_bulk(desc)) {
 		int size = ep->maxpacket;
 
 		/* min() doesn't work on bitfields with gcc-3.5 */
@@ -235,14 +233,11 @@ struct usb_ep * __init usb_ep_autoconfig (
 )
 {
 	struct usb_ep	*ep;
-	u8		type;
-
-	type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
 
 	/* First, apply chip-specific "best usage" knowledge.
 	 * This might make a good usb_gadget_ops hook ...
 	 */
-	if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) {
+	if (gadget_is_net2280(gadget) && usb_endpoint_xfer_int(desc)) {
 		/* ep-e, ep-f are PIO with only 64 byte fifos */
 		ep = find_ep (gadget, "ep-e");
 		if (ep && ep_matches (gadget, ep, desc))
@@ -252,26 +247,25 @@ struct usb_ep * __init usb_ep_autoconfig (
 			return ep;
 
 	} else if (gadget_is_goku (gadget)) {
-		if (USB_ENDPOINT_XFER_INT == type) {
+		if (usb_endpoint_xfer_int(desc)) {
 			/* single buffering is enough */
 			ep = find_ep (gadget, "ep3-bulk");
 			if (ep && ep_matches (gadget, ep, desc))
 				return ep;
-		} else if (USB_ENDPOINT_XFER_BULK == type
-				&& (USB_DIR_IN & desc->bEndpointAddress)) {
+		} else if (usb_endpoint_is_bulk_in(desc)) {
 			/* DMA may be available */
 			ep = find_ep (gadget, "ep2-bulk");
 			if (ep && ep_matches (gadget, ep, desc))
 				return ep;
 		}
 
-	} else if (gadget_is_sh (gadget) && USB_ENDPOINT_XFER_INT == type) {
+	} else if (gadget_is_sh(gadget) && usb_endpoint_xfer_int(desc)) {
 		/* single buffering is enough; maybe 8 byte fifo is too */
 		ep = find_ep (gadget, "ep3in-bulk");
 		if (ep && ep_matches (gadget, ep, desc))
 			return ep;
 
-	} else if (gadget_is_mq11xx (gadget) && USB_ENDPOINT_XFER_INT == type) {
+	} else if (gadget_is_mq11xx(gadget) && usb_endpoint_xfer_int(desc)) {
 		ep = find_ep (gadget, "ep1-bulk");
 		if (ep && ep_matches (gadget, ep, desc))
 			return ep;
-- 
1.6.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux