mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts/rk-usb-loader: Add support for rk3588
@ 2024-06-05 17:25 Alexander Shiyan
  2024-06-10 12:22 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Shiyan @ 2024-06-05 17:25 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

This adds support for rk3588 CPU for rk-usb-loader.
Instead of 0x350a PID, the rk3588 uses 0x350b, so lets use mask
to be compatible with both CPUs.
Tested with 3588OK-C Forlinx board.

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 scripts/rk-usb-loader.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/scripts/rk-usb-loader.c b/scripts/rk-usb-loader.c
index 9c2367ed28..ad70cfe271 100644
--- a/scripts/rk-usb-loader.c
+++ b/scripts/rk-usb-loader.c
@@ -66,7 +66,9 @@ static void log_debug(char *fmt, ...)
 	va_end(va);
 }
 
-static libusb_device_handle *rk_usb_open(libusb_context *ctx, uint16_t vendor, uint16_t product)
+static libusb_device_handle *rk_usb_open(libusb_context *ctx,
+					 uint16_t vendor, uint16_t vmask,
+					 uint16_t product, uint16_t pmask)
 {
 	libusb_device **devlist;
 	libusb_device_handle *handle;
@@ -74,8 +76,8 @@ static libusb_device_handle *rk_usb_open(libusb_context *ctx, uint16_t vendor, u
 	ssize_t count, i;
 	int ret;
 
-	log_info("scanning for USB device matching %04hx:%04hx...\n",
-		 vendor, product);
+	log_info("scanning for USB device matching %04hx/%04hx:%04hx/%04hx...\n",
+		 vendor, vmask, product, pmask);
 
 	while (1) {
 		if ((count = libusb_get_device_list(ctx, &devlist)) < 0) {
@@ -93,11 +95,11 @@ static libusb_device_handle *rk_usb_open(libusb_context *ctx, uint16_t vendor, u
 				return NULL;
 			}
 
-			if (desc.idVendor != vendor)
+			if ((desc.idVendor & vmask) != (vendor & vmask))
 				continue;
 
 			if (product) {
-				if (desc.idProduct != product)
+				if ((desc.idProduct & pmask) != (product & pmask))
 					continue;
 				goto found;
 			}
@@ -113,7 +115,8 @@ static libusb_device_handle *rk_usb_open(libusb_context *ctx, uint16_t vendor, u
 	ret = libusb_open(devlist[i], &handle);
 	if (ret < 0) {
 		log_error("failed to open USB device %04hx:%04hx: %s\n",
-				vendor, product, libusb_error_name(ret));
+				desc.idVendor, desc.idProduct,
+				libusb_error_name(ret));
 		libusb_free_device_list(devlist, 1);
 		return NULL;
 	}
@@ -124,7 +127,8 @@ static libusb_device_handle *rk_usb_open(libusb_context *ctx, uint16_t vendor, u
 		return NULL;
 	}
 
-	log_info("successfully opened %04hx:%04hx\n", vendor, product);
+	log_info("successfully opened %04hx:%04hx\n",
+		 desc.idVendor, desc.idProduct);
 
 	return handle;
 }
@@ -231,7 +235,7 @@ static int upload_image(const char *filename)
 		return ret;
 	}
 
-	dev = rk_usb_open(ctx, 0x2207, 0x350a);
+	dev = rk_usb_open(ctx, 0x2207, 0xffff, 0x350a, 0xfffe);
 	if (!dev) {
 		libusb_exit(ctx);
 		return 1;
-- 
2.38.2




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

end of thread, other threads:[~2024-06-10 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-05 17:25 [PATCH] scripts/rk-usb-loader: Add support for rk3588 Alexander Shiyan
2024-06-10 12:22 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox