All of lore.kernel.org
 help / color / mirror / Atom feed
* [tegrarcm PATCH 1/3] Move all USB device matching logic into usb_match()
@ 2015-10-08 18:38 Stephen Warren
       [not found] ` <1444329510-23848-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Warren @ 2015-10-08 18:38 UTC (permalink / raw)
  To: Allen Martin; +Cc: Stephen Warren, linux-tegra-u79uwXL29TY76Z2rM5mHXA

From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

This consolidates the matching logic into one place, which will make
future enhancements to the logic simpler.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 src/usb.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/usb.c b/src/usb.c
index b0a7a8822aa2..71234d77d7b1 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -45,16 +45,32 @@
 static int usb_match(libusb_device *dev, uint16_t venid, uint16_t *devid)
 {
 	struct libusb_device_descriptor desc;
+
 	if (libusb_get_device_descriptor(dev, &desc)) {
 		dprintf("libusb_get_device_descriptor\n");
 		return 0;
 	}
-	if (desc.idVendor == venid) {
-		*devid = desc.idProduct;
-		return 1;
+	if (desc.idVendor != venid) {
+		dprintf("non-NVIDIA USB device: 0x%x:0x%x\n",
+			desc.idVendor, desc.idProduct);
+		return 0;
+	}
+	switch (desc.idProduct & 0xff) {
+	case USB_DEVID_NVIDIA_TEGRA20:
+	case USB_DEVID_NVIDIA_TEGRA30:
+	case USB_DEVID_NVIDIA_TEGRA114:
+	case USB_DEVID_NVIDIA_TEGRA124:
+		break;
+	default:
+		dprintf("non-Tegra NVIDIA USB device: 0x%x:0x%x\n",
+			desc.idVendor, desc.idProduct);
+		return 0;
 	}
 
-	return 0;
+	dprintf("device matches\n");
+	*devid = desc.idProduct;
+
+	return 1;
 }
 
 static void usb_check_interface(const struct libusb_interface_descriptor *iface_desc,
@@ -155,17 +171,10 @@ usb_device_t *usb_open(uint16_t venid, uint16_t *devid)
 
 	for (i = 0; i < cnt; i++) {
 		libusb_device *device = list[i];
+
 		if (usb_match(device, venid, devid)) {
-			if ((*devid & 0xff) == USB_DEVID_NVIDIA_TEGRA20 ||
-			    (*devid & 0xff) == USB_DEVID_NVIDIA_TEGRA30 ||
-			    (*devid & 0xff) == USB_DEVID_NVIDIA_TEGRA114 ||
-			    (*devid & 0xff) == USB_DEVID_NVIDIA_TEGRA124) {
-				found = device;
-				break;
-			} else {
-				dprintf("non-tegra NVIDIA USB device: 0x%x\n",
-					*devid);
-			}
+			found = device;
+			break;
 		}
 	}
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-16 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-08 18:38 [tegrarcm PATCH 1/3] Move all USB device matching logic into usb_match() Stephen Warren
     [not found] ` <1444329510-23848-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-10-08 18:38   ` [tegrarcm PATCH 2/3] Match USB port ID on re-enumeration Stephen Warren
2015-10-08 18:38   ` [tegrarcm PATCH 3/3] Implement --usb-port-path cmdline option Stephen Warren
2015-10-16 16:57   ` [tegrarcm PATCH 1/3] Move all USB device matching logic into usb_match() Stephen Warren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.