Skip to contentSkip to conversation

dm: usb: udc: Factor out plain udevice handler functions

PATCH In review Marek Vasut 3 participants 29 messages Sep 1, 2023 – Oct 7, 2023

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/17 dm: usb: udc: Factor out plain udevice handler functions

Pull the functionality of UDC uclass that operates on plain udevice and does not use this dev_array array into separate functions and expose those functions, so that as much code as possible can be switched over to these functions and the dev_array can be dropped.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 drivers/usb/gadget/udc/Makefile     |  2 +-
 drivers/usb/gadget/udc/udc-uclass.c | 57 +++++++++++++++++++++++++----
 include/linux/usb/gadget.h          | 17 +++++++++
 3 files changed, 68 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/Makefile +1 -1
index 95dbf0c82ee..467c566f6d3 100644
@@ -7,4 +7,4 @@ obj-$(CONFIG_USB_DWC3_GADGET)	+= udc-core.o
 endif
 
 obj-$(CONFIG_$(SPL_)DM_USB_GADGET)	+= udc-core.o
-obj-$(CONFIG_$(SPL_)DM) += udc-uclass.o
+obj-y += udc-uclass.o
drivers/usb/gadget/udc/udc-uclass.c +50 -7

86 lines not on this page · raw message

include/linux/usb/gadget.h +17 -0
index 2f694fc25c1..5e9a6513d5b 100644
@@ -1006,6 +1006,23 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
 extern int usb_gadget_handle_interrupts(int index);
 
+/**
+ * udc_device_get_by_index() - Get UDC udevice by index
+ * @index: UDC device index
+ * @udev: UDC udevice matching the index (if found)
+ *
+ * Return: 0 if Ok, -ve on error
+ */
+int udc_device_get_by_index(int index, struct udevice **udev);
+
+/**
+ * udc_device_put() - Put UDC udevice
+ * @udev: UDC udevice
+ *
+ * Return: 0 if Ok, -ve on error
+ */
+int udc_device_put(struct udevice *udev);
+
 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
 int usb_gadget_initialize(int index);
 int usb_gadget_release(int index);
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 2/17 usb: sandbox: Add DM_USB_GADGET support

Remove local usb_gadget_register_driver()/usb_gadget_unregister_driver() implementation which is implemented in udc-core.c instead if DM_USB_GADGET is enabled. Add no-op dm_usb_gadget_handle_interrupts() implementation.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs, Simon

---
 drivers/usb/host/usb-sandbox.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/usb/host/usb-sandbox.c +7 -0
index d1103dcb2e9..582f72d00c1 100644
@@ -124,6 +124,12 @@ static int sandbox_submit_int(struct udevice *bus, struct usb_device *udev,
 	return ret;
 }
 
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+	return 0;
+}
+#else
 int usb_gadget_handle_interrupts(int index)
 {
 	return 0;
@@ -144,6 +150,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 
 	return 0;
 }
+#endif
 
 static int sandbox_alloc_device(struct udevice *dev, struct usb_device *udev)
 {
Signature · 1 line
2.40.1
#2 lore raw

PATCH v2 3/17 configs: sandbox: Enable DM_USB_GADGET

In reply to Marek Vasut

Switch sandbox to DM_USB_GADGET, DM is the future.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs, Simon

---
 configs/sandbox64_defconfig        | 1 +
 configs/sandbox_defconfig          | 1 +
 configs/sandbox_flattree_defconfig | 1 +
 configs/sandbox_noinst_defconfig   | 1 +
 configs/sandbox_spl_defconfig      | 1 +
 configs/sandbox_vpl_defconfig      | 1 +
 6 files changed, 6 insertions(+)
configs/sandbox64_defconfig +1 -0
index 55a01b7eb9d..1104b86ff7c 100644
@@ -236,6 +236,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_VIDEO=y
configs/sandbox_defconfig +1 -0
index 98f0bc13a5f..d667cb9ae47 100644
@@ -299,6 +299,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_USB_GADGET=y
configs/sandbox_flattree_defconfig +1 -0
index db916e6c4e9..29ae4532c50 100644
@@ -203,6 +203,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_VIDEO=y
configs/sandbox_noinst_defconfig +1 -0
index ee04fbbc2e9..d39e54f98d2 100644
@@ -217,6 +217,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_VIDEO=y
configs/sandbox_spl_defconfig +1 -0
index 69b413382a1..4a67af2f088 100644
@@ -223,6 +223,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_VIDEO=y
configs/sandbox_vpl_defconfig +1 -0
index 27354b8b5ed..8d76f19729b 100644
@@ -236,6 +236,7 @@ CONFIG_VPL_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_VIDEO=y
Signature · 1 line
2.40.1
#3 lore raw

PATCH v2 4/17 cmd: fastboot: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB, TB from Mattijs

---
 cmd/fastboot.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
cmd/fastboot.c +4 -3
index 3d5ff951eb6..17fb0a0aa7b 100644
@@ -61,6 +61,7 @@ static int do_fastboot_usb(int argc, char *const argv[],
 {
 	int controller_index;
 	char *usb_controller;
+	struct udevice *udc;
 	char *endp;
 	int ret;
 
@@ -79,7 +80,7 @@ static int do_fastboot_usb(int argc, char *const argv[],
 		return CMD_RET_FAILURE;
 	}
 
-	ret = usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
 	if (ret) {
 		pr_err("USB init failed: %d\n", ret);
 		return CMD_RET_FAILURE;
@@ -103,13 +104,13 @@ static int do_fastboot_usb(int argc, char *const argv[],
 		if (ctrlc())
 			break;
 		schedule();
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udc);
 	}
 
 	ret = CMD_RET_SUCCESS;
 
 exit:
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 	g_dnl_unregister();
 	g_dnl_clear_detach();
 
Signature · 1 line
2.40.1
#4 lore raw

PATCH v2 5/17 cmd: rockusb: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 cmd/rockusb.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
cmd/rockusb.c +4 -3
index f181ec61119..07088564a10 100644
@@ -15,6 +15,7 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	int controller_index, dev_index;
 	char *usb_controller;
+	struct udevice *udc;
 	char *devtype;
 	char *devnum;
 	int ret;
@@ -34,7 +35,7 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
 	dev_index = simple_strtoul(devnum, NULL, 0);
 	rockusb_dev_init(devtype, dev_index);
 
-	ret = usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
 	if (ret) {
 		printf("USB init failed: %d\n", ret);
 		return CMD_RET_FAILURE;
@@ -56,14 +57,14 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
 			break;
 		if (ctrlc())
 			break;
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udc);
 	}
 	ret = CMD_RET_SUCCESS;
 
 exit:
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 
 	return ret;
 }
Signature · 1 line
2.40.1
Reviewed-by on v2 5/17
#5 lore raw

Re: [PATCH v2 05/17] cmd: rockusb: Use plain udevice for UDC controller interaction

Quoted 4 lines · Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

Quoted 61 lines

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 cmd/rockusb.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
cmd/rockusb.c +4 -3
index f181ec61119..07088564a10 100644
@@ -15,6 +15,7 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	int controller_index, dev_index;
 	char *usb_controller;
+	struct udevice *udc;
 	char *devtype;
 	char *devnum;
 	int ret;
@@ -34,7 +35,7 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
 	dev_index = simple_strtoul(devnum, NULL, 0);
 	rockusb_dev_init(devtype, dev_index);
 
-	ret = usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
 	if (ret) {
 		printf("USB init failed: %d\n", ret);
 		return CMD_RET_FAILURE;
@@ -56,14 +57,14 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
 			break;
 		if (ctrlc())
 			break;
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udc);
 	}
 	ret = CMD_RET_SUCCESS;
 
 exit:
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 
 	return ret;
 }
Signature · 1 line
2.40.1
#6 lore raw

PATCH v2 6/17 cmd: sdp: Reorder variable declaration

In reply to Marek Vasut

Move the variable declaration around to improve code readability. No functional change.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 cmd/usb_gadget_sdp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/usb_gadget_sdp.c +2 -2
index 1af82e11366..784d1b49768 100644
@@ -14,13 +14,13 @@
 
 static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
+	int controller_index;
 	int ret;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
-	char *usb_controller = argv[1];
-	int controller_index = simple_strtoul(usb_controller, NULL, 0);
+	controller_index = simple_strtoul(argv[1], NULL, 0);
 	usb_gadget_initialize(controller_index);
 
 	g_dnl_clear_detach();
Signature · 1 line
2.40.1
#7 lore raw

PATCH v2 7/17 cmd: thordown: Reorder variable declaration

In reply to Marek Vasut

Move the variable declaration around to improve code readability. No functional change.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 cmd/thordown.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
cmd/thordown.c +8 -7
index 838764ccef7..0d8dcee5314 100644
@@ -15,22 +15,23 @@
 
 int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
+	char *interface, *devstring;
+	int controller_index;
+	int ret;
+
 	if (argc < 4)
 		return CMD_RET_USAGE;
 
-	char *usb_controller = argv[1];
-	char *interface = argv[2];
-	char *devstring = argv[3];
-
-	int ret;
-
 	puts("TIZEN \"THOR\" Downloader\n");
 
+	interface = argv[2];
+	devstring = argv[3];
+
 	ret = dfu_init_env_entities(interface, devstring);
 	if (ret)
 		goto done;
 
-	int controller_index = simple_strtoul(usb_controller, NULL, 0);
+	controller_index = simple_strtoul(argv[1], NULL, 0);
 	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		pr_err("USB init failed: %d\n", ret);
Signature · 1 line
2.40.1
Reviewed-by on v2 7/17
#8 lore raw

Re: [PATCH v2 07/17] cmd: thordown: Reorder variable declaration

Quoted 4 lines · Marek Vasut

Move the variable declaration around to improve code readability. No functional change.

Quoted 58 lines

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 cmd/thordown.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
cmd/thordown.c +8 -7
index 838764ccef7..0d8dcee5314 100644
@@ -15,22 +15,23 @@
 
 int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
+	char *interface, *devstring;
+	int controller_index;
+	int ret;
+
 	if (argc < 4)
 		return CMD_RET_USAGE;
 
-	char *usb_controller = argv[1];
-	char *interface = argv[2];
-	char *devstring = argv[3];
-
-	int ret;
-
 	puts("TIZEN \"THOR\" Downloader\n");
 
+	interface = argv[2];
+	devstring = argv[3];
+
 	ret = dfu_init_env_entities(interface, devstring);
 	if (ret)
 		goto done;
 
-	int controller_index = simple_strtoul(usb_controller, NULL, 0);
+	controller_index = simple_strtoul(argv[1], NULL, 0);
 	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		pr_err("USB init failed: %d\n", ret);
Signature · 1 line
2.40.1
#9 lore raw

PATCH v2 8/17 cmd: ums: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB, TB from Mattijs

---
 cmd/usb_mass_storage.c              | 10 ++++++----
 drivers/usb/gadget/f_mass_storage.c |  8 ++++----
 include/usb_mass_storage.h          |  2 +-
 3 files changed, 11 insertions(+), 9 deletions(-)
cmd/usb_mass_storage.c +6 -4
index c3cc1975f9d..9c51ae0967f 100644
@@ -143,6 +143,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
 	const char *devtype;
 	const char *devnum;
 	unsigned int controller_index;
+	struct udevice *udc;
 	int rc;
 	int cable_ready_timeout __maybe_unused;
 
@@ -164,13 +165,14 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
 
 	controller_index = (unsigned int)(simple_strtoul(
 				usb_controller,	NULL, 0));
-	if (usb_gadget_initialize(controller_index)) {
+	rc = udc_device_get_by_index(controller_index, &udc);
+	if (rc) {
 		pr_err("Couldn't init USB controller.\n");
 		rc = CMD_RET_FAILURE;
 		goto cleanup_ums_init;
 	}
 
-	rc = fsg_init(ums, ums_count, controller_index);
+	rc = fsg_init(ums, ums_count, udc);
 	if (rc) {
 		pr_err("fsg_init failed\n");
 		rc = CMD_RET_FAILURE;
@@ -215,7 +217,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
 	}
 
 	while (1) {
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udc);
 
 		rc = fsg_main_thread(NULL);
 		if (rc) {
@@ -247,7 +249,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
 cleanup_register:
 	g_dnl_unregister();
 cleanup_board:
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 cleanup_ums_init:
 	ums_fini();
 
drivers/usb/gadget/f_mass_storage.c +4 -4
index f46829eb7ad..1d17331cb03 100644
@@ -435,7 +435,7 @@ static void set_bulk_out_req_length(struct fsg_common *common,
 static struct ums *ums;
 static int ums_count;
 static struct fsg_common *the_fsg_common;
-static unsigned int controller_index;
+static struct udevice *udcdev;
 
 static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
 {
@@ -680,7 +680,7 @@ static int sleep_thread(struct fsg_common *common)
 			k = 0;
 		}
 
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udcdev);
 	}
 	common->thread_wakeup_needed = 0;
 	return rc;
@@ -2764,11 +2764,11 @@ int fsg_add(struct usb_configuration *c)
 	return fsg_bind_config(c->cdev, c, fsg_common);
 }
 
-int fsg_init(struct ums *ums_devs, int count, unsigned int controller_idx)
+int fsg_init(struct ums *ums_devs, int count, struct udevice *udc)
 {
 	ums = ums_devs;
 	ums_count = count;
-	controller_index = controller_idx;
+	udcdev = udc;
 
 	return 0;
 }
include/usb_mass_storage.h +1 -1
index 08ccc97cf22..83ab93b530d 100644
@@ -25,7 +25,7 @@ struct ums {
 	struct blk_desc block_dev;
 };
 
-int fsg_init(struct ums *ums_devs, int count, unsigned int controller_idx);
+int fsg_init(struct ums *ums_devs, int count, struct udevice *udc);
 void fsg_cleanup(void);
 int fsg_main_thread(void *);
 int fsg_add(struct usb_configuration *c);
Signature · 1 line
2.40.1
#10 lore raw

PATCH v2 9/17 dfu: Detach the controller on error

In reply to Marek Vasut

In case anything errors out during the DFU registration, detach the controller instead of bailing out right away. This way, the controller can be reattached on next attempt.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 common/dfu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/dfu.c +3 -1
index 96190889ab7..32fba84da16 100644
@@ -34,7 +34,8 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	ret = g_dnl_register(usb_dnl_gadget);
 	if (ret) {
 		pr_err("g_dnl_register failed");
-		return CMD_RET_FAILURE;
+		ret = CMD_RET_FAILURE;
+		goto err_detach;
 	}
 
 #ifdef CONFIG_DFU_TIMEOUT
@@ -106,6 +107,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	}
 exit:
 	g_dnl_unregister();
+err_detach:
 	usb_gadget_release(usbctrl_index);
 
 	if (dfu_reset)
Signature · 1 line
2.40.1
#11 lore raw

PATCH v2 10/17 dfu: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 common/dfu.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
common/dfu.c +8 -7
index 32fba84da16..45206b9e225 100644
@@ -23,11 +23,12 @@
 int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 {
 	bool dfu_reset = false;
+	struct udevice *udc;
 	int ret, i = 0;
 
-	ret = usb_gadget_initialize(usbctrl_index);
+	ret = udc_device_get_by_index(usbctrl_index, &udc);
 	if (ret) {
-		pr_err("usb_gadget_initialize failed\n");
+		pr_err("udc_device_get_by_index failed\n");
 		return CMD_RET_FAILURE;
 	}
 	g_dnl_clear_detach();
@@ -55,7 +56,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 			}
 
 			/*
-			 * This extra number of usb_gadget_handle_interrupts()
+			 * This extra number of dm_usb_gadget_handle_interrupts()
 			 * calls is necessary to assure correct transmission
 			 * completion with dfu-util
 			 */
@@ -68,7 +69,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 
 		if (dfu_get_defer_flush()) {
 			/*
-			 * Call to usb_gadget_handle_interrupts() is necessary
+			 * Call to dm_usb_gadget_handle_interrupts() is necessary
 			 * to act on ZLP OUT transaction from HOST PC after
 			 * transmitting the whole file.
 			 *
@@ -77,7 +78,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 			 * 5 seconds). In such situation the dfu-util program
 			 * exits with error message.
 			 */
-			usb_gadget_handle_interrupts(usbctrl_index);
+			dm_usb_gadget_handle_interrupts(udc);
 			ret = dfu_flush(dfu_get_defer_flush(), NULL, 0, 0);
 			dfu_set_defer_flush(NULL);
 			if (ret) {
@@ -103,12 +104,12 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 			goto exit;
 
 		schedule();
-		usb_gadget_handle_interrupts(usbctrl_index);
+		dm_usb_gadget_handle_interrupts(udc);
 	}
 exit:
 	g_dnl_unregister();
 err_detach:
-	usb_gadget_release(usbctrl_index);
+	udc_device_put(udc);
 
 	if (dfu_reset)
 		do_reset(NULL, 0, 0, NULL);
Signature · 1 line
2.40.1
#12 lore raw

PATCH v2 11/17 spl: sdp: Detach the controller on error

In reply to Marek Vasut

In case anything errors out during the SDP transfer, detach the controller instead of bailing out right away. This way, the controller can be reattached on next attempt.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: - Call g_dnl_unregister() in case sdp_init() fails and on regular exit
- Add RB from Mattijs

---
 common/spl/spl_sdp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
common/spl/spl_sdp.c +5 -2
index cc4fb4f7cca..aae886d2e57 100644
@@ -25,13 +25,13 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
 	ret = g_dnl_register("usb_dnl_sdp");
 	if (ret) {
 		pr_err("SDP dnl register failed: %d\n", ret);
-		return ret;
+		goto err_detach;
 	}
 
 	ret = sdp_init(controller_index);
 	if (ret) {
 		pr_err("SDP init failed: %d\n", ret);
-		return -ENODEV;
+		goto err_unregister;
 	}
 
 	/*
@@ -42,6 +42,9 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
 	ret = spl_sdp_handle(controller_index, spl_image, bootdev);
 	debug("SDP ended\n");
 
+err_unregister:
+	g_dnl_unregister();
+err_detach:
 	usb_gadget_release(controller_index);
 	return ret;
 }
Signature · 1 line
2.40.1
#13 lore raw

PATCH v2 12/17 sdp: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 cmd/usb_gadget_sdp.c       | 11 +++++++----
 common/spl/spl_sdp.c       | 13 ++++++++-----
 drivers/usb/gadget/f_sdp.c | 10 +++++-----
 include/sdp.h              |  6 +++---
 4 files changed, 23 insertions(+), 17 deletions(-)
cmd/usb_gadget_sdp.c +7 -4
index 784d1b49768..748aa0a7488 100644
@@ -15,13 +15,16 @@
 static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	int controller_index;
+	struct udevice *udc;
 	int ret;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
 	controller_index = simple_strtoul(argv[1], NULL, 0);
-	usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
+	if (ret)
+		return ret;
 
 	g_dnl_clear_detach();
 	ret = g_dnl_register("usb_dnl_sdp");
@@ -30,20 +33,20 @@ static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		goto exit_register;
 	}
 
-	ret = sdp_init(controller_index);
+	ret = sdp_init(udc);
 	if (ret) {
 		pr_err("SDP init failed: %d\n", ret);
 		goto exit;
 	}
 
 	/* This command typically does not return but jumps to an image */
-	sdp_handle(controller_index);
+	sdp_handle(udc);
 	pr_err("SDP ended\n");
 
 exit:
 	g_dnl_unregister();
 exit_register:
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 
 	return CMD_RET_FAILURE;
 }
common/spl/spl_sdp.c +8 -5
index aae886d2e57..5a5ccd0676c 100644
@@ -14,10 +14,13 @@
 static int spl_sdp_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	int ret;
 	const int controller_index = CONFIG_SPL_SDP_USB_DEV;
+	struct udevice *udc;
+	int ret;
 
-	usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
+	if (ret)
+		return ret;
 
 	board_usb_init(controller_index, USB_INIT_DEVICE);
 
@@ -28,7 +31,7 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
 		goto err_detach;
 	}
 
-	ret = sdp_init(controller_index);
+	ret = sdp_init(udc);
 	if (ret) {
 		pr_err("SDP init failed: %d\n", ret);
 		goto err_unregister;
@@ -39,13 +42,13 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
 	 * or it loads a FIT image and returns it to be handled by the SPL
 	 * code.
 	 */
-	ret = spl_sdp_handle(controller_index, spl_image, bootdev);
+	ret = spl_sdp_handle(udc, spl_image, bootdev);
 	debug("SDP ended\n");
 
 err_unregister:
 	g_dnl_unregister();
 err_detach:
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 	return ret;
 }
 SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);
drivers/usb/gadget/f_sdp.c +5 -5
index 4da5a160a09..37f6281abfb 100644
@@ -702,7 +702,7 @@ static int sdp_bind_config(struct usb_configuration *c)
 	return status;
 }
 
-int sdp_init(int controller_index)
+int sdp_init(struct udevice *udc)
 {
 	printf("SDP: initialize...\n");
 	while (!sdp_func->configuration_done) {
@@ -712,7 +712,7 @@ int sdp_init(int controller_index)
 		}
 
 		schedule();
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udc);
 	}
 
 	return 0;
@@ -911,9 +911,9 @@ static void sdp_handle_out_ep(void)
 }
 
 #ifndef CONFIG_SPL_BUILD
-int sdp_handle(int controller_index)
+int sdp_handle(struct udevice *udc)
 #else
-int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image,
+int spl_sdp_handle(struct udevice *udc, struct spl_image_info *spl_image,
 		   struct spl_boot_device *bootdev)
 #endif
 {
@@ -929,7 +929,7 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image,
 			return 0;
 
 		schedule();
-		usb_gadget_handle_interrupts(controller_index);
+		dm_usb_gadget_handle_interrupts(udc);
 
 #ifdef CONFIG_SPL_BUILD
 		flag = sdp_handle_in_ep(spl_image, bootdev);
include/sdp.h +3 -3
index 6d89baa04ec..5492f9c47d2 100644
@@ -9,15 +9,15 @@
 #ifndef __SDP_H_
 #define __SDP_H_
 
-int sdp_init(int controller_index);
+int sdp_init(struct udevice *udc);
 
 #ifdef CONFIG_SPL_BUILD
 #include <spl.h>
 
-int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image,
+int spl_sdp_handle(struct udevice *udc, struct spl_image_info *spl_image,
 		   struct spl_boot_device *bootdev);
 #else
-int sdp_handle(int controller_index);
+int sdp_handle(struct udevice *udc);
 #endif
 
 #endif /* __SDP_H_ */
Signature · 1 line
2.40.1
#14 lore raw

PATCH v2 13/17 thordown: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 cmd/thordown.c              |  9 +++--
 drivers/usb/gadget/f_thor.c | 74 +++++++++++++++++++------------------
 include/thor.h              |  4 +-
 3 files changed, 45 insertions(+), 42 deletions(-)
cmd/thordown.c +5 -4
index 0d8dcee5314..fcfd38f523c 100644
@@ -17,6 +17,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	char *interface, *devstring;
 	int controller_index;
+	struct udevice *udc;
 	int ret;
 
 	if (argc < 4)
@@ -32,7 +33,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		goto done;
 
 	controller_index = simple_strtoul(argv[1], NULL, 0);
-	ret = usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
 	if (ret) {
 		pr_err("USB init failed: %d\n", ret);
 		ret = CMD_RET_FAILURE;
@@ -46,7 +47,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		goto exit;
 	}
 
-	ret = thor_init();
+	ret = thor_init(udc);
 	if (ret) {
 		pr_err("THOR DOWNLOAD failed: %d\n", ret);
 		ret = CMD_RET_FAILURE;
@@ -54,7 +55,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	}
 
 	do {
-		ret = thor_handle();
+		ret = thor_handle(udc);
 		if (ret == THOR_DFU_REINIT_NEEDED) {
 			dfu_free_entities();
 			ret = dfu_init_env_entities(interface, devstring);
@@ -67,7 +68,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	} while (ret == 0);
 exit:
 	g_dnl_unregister();
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 done:
 	dfu_free_entities();
 
drivers/usb/gadget/f_thor.c +38 -36

249 lines not on this page · raw message

include/thor.h +2 -2
index ee67ab0a270..3cb56b654ae 100644
@@ -14,7 +14,7 @@
 
 #define THOR_DFU_REINIT_NEEDED	0xFFFFFFFE
 
-int thor_handle(void);
-int thor_init(void);
+int thor_handle(struct udevice *udc);
+int thor_init(struct udevice *udc);
 int thor_add(struct usb_configuration *c);
 #endif /* __THOR_H_ */
Signature · 1 line
2.40.1
Reviewed-by on v2 13/17
#15 lore raw

Re: [PATCH v2 13/17] thordown: Use plain udevice for UDC controller interaction

Quoted 4 lines · Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

Quoted 15 lines

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]

Quoted 347 lines

---
V2: No change

---
 cmd/thordown.c              |  9 +++--
 drivers/usb/gadget/f_thor.c | 74 +++++++++++++++++++------------------
 include/thor.h              |  4 +-
 3 files changed, 45 insertions(+), 42 deletions(-)
cmd/thordown.c +5 -4
index 0d8dcee5314..fcfd38f523c 100644
@@ -17,6 +17,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	char *interface, *devstring;
 	int controller_index;
+	struct udevice *udc;
 	int ret;
 
 	if (argc < 4)
@@ -32,7 +33,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		goto done;
 
 	controller_index = simple_strtoul(argv[1], NULL, 0);
-	ret = usb_gadget_initialize(controller_index);
+	ret = udc_device_get_by_index(controller_index, &udc);
 	if (ret) {
 		pr_err("USB init failed: %d\n", ret);
 		ret = CMD_RET_FAILURE;
@@ -46,7 +47,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		goto exit;
 	}
 
-	ret = thor_init();
+	ret = thor_init(udc);
 	if (ret) {
 		pr_err("THOR DOWNLOAD failed: %d\n", ret);
 		ret = CMD_RET_FAILURE;
@@ -54,7 +55,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	}
 
 	do {
-		ret = thor_handle();
+		ret = thor_handle(udc);
 		if (ret == THOR_DFU_REINIT_NEEDED) {
 			dfu_free_entities();
 			ret = dfu_init_env_entities(interface, devstring);
@@ -67,7 +68,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	} while (ret == 0);
 exit:
 	g_dnl_unregister();
-	usb_gadget_release(controller_index);
+	udc_device_put(udc);
 done:
 	dfu_free_entities();
 
drivers/usb/gadget/f_thor.c +38 -36
index 47ef55b2fd3..3caa4c36387 100644
@@ -15,9 +15,10 @@
  */
 
 #include <command.h>
-#include <errno.h>
 #include <common.h>
 #include <console.h>
+#include <dm.h>
+#include <errno.h>
 #include <init.h>
 #include <log.h>
 #include <malloc.h>
@@ -34,9 +35,9 @@
 
 #include "f_thor.h"
 
-static void thor_tx_data(unsigned char *data, int len);
+static void thor_tx_data(struct udevice *udc, unsigned char *data, int len);
 static void thor_set_dma(void *addr, int len);
-static int thor_rx_data(void);
+static int thor_rx_data(struct udevice *udc);
 
 static struct f_thor *thor_func;
 static inline struct f_thor *func_to_thor(struct usb_function *f)
@@ -56,15 +57,15 @@ DEFINE_CACHE_ALIGN_BUFFER(char, f_name, F_NAME_BUF_SIZE + 1);
 static unsigned long long int thor_file_size;
 static int alt_setting_num;
 
-static void send_rsp(const struct rsp_box *rsp)
+static void send_rsp(struct udevice *udc, const struct rsp_box *rsp)
 {
 	memcpy(thor_tx_data_buf, rsp, sizeof(struct rsp_box));
-	thor_tx_data(thor_tx_data_buf, sizeof(struct rsp_box));
+	thor_tx_data(udc, thor_tx_data_buf, sizeof(struct rsp_box));
 
 	debug("-RSP: %d, %d\n", rsp->rsp, rsp->rsp_data);
 }
 
-static void send_data_rsp(s32 ack, s32 count)
+static void send_data_rsp(struct udevice *udc, s32 ack, s32 count)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct data_rsp_box, rsp,
 				 sizeof(struct data_rsp_box));
@@ -73,12 +74,12 @@ static void send_data_rsp(s32 ack, s32 count)
 	rsp->count = count;
 
 	memcpy(thor_tx_data_buf, rsp, sizeof(struct data_rsp_box));
-	thor_tx_data(thor_tx_data_buf, sizeof(struct data_rsp_box));
+	thor_tx_data(udc, thor_tx_data_buf, sizeof(struct data_rsp_box));
 
 	debug("-DATA RSP: %d, %d\n", ack, count);
 }
 
-static int process_rqt_info(const struct rqt_box *rqt)
+static int process_rqt_info(struct udevice *udc, const struct rqt_box *rqt)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
 	memset(rsp, 0, sizeof(struct rsp_box));
@@ -111,11 +112,11 @@ static int process_rqt_info(const struct rqt_box *rqt)
 		return -EINVAL;
 	}
 
-	send_rsp(rsp);
+	send_rsp(udc, rsp);
 	return true;
 }
 
-static int process_rqt_cmd(const struct rqt_box *rqt)
+static int process_rqt_cmd(struct udevice *udc, const struct rqt_box *rqt)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
 	memset(rsp, 0, sizeof(struct rsp_box));
@@ -126,7 +127,7 @@ static int process_rqt_cmd(const struct rqt_box *rqt)
 	switch (rqt->rqt_data) {
 	case RQT_CMD_REBOOT:
 		debug("TARGET RESET\n");
-		send_rsp(rsp);
+		send_rsp(udc, rsp);
 		g_dnl_unregister();
 		dfu_free_entities();
 #ifdef CONFIG_THOR_RESET_OFF
@@ -136,7 +137,7 @@ static int process_rqt_cmd(const struct rqt_box *rqt)
 		break;
 	case RQT_CMD_POWEROFF:
 	case RQT_CMD_EFSCLEAR:
-		send_rsp(rsp);
+		send_rsp(udc, rsp);
 	default:
 		printf("Command not supported -> cmd: %d\n", rqt->rqt_data);
 		return -EINVAL;
@@ -145,7 +146,8 @@ static int process_rqt_cmd(const struct rqt_box *rqt)
 	return true;
 }
 
-static long long int download_head(unsigned long long total,
+static long long int download_head(struct udevice *udc,
+				   unsigned long long total,
 				   unsigned int packet_size,
 				   long long int *left,
 				   int *cnt)
@@ -166,7 +168,7 @@ static long long int download_head(unsigned long long total,
 	while (total - rcv_cnt >= packet_size) {
 		thor_set_dma(buf, packet_size);
 		buf += packet_size;
-		ret_rcv = thor_rx_data();
+		ret_rcv = thor_rx_data(udc);
 		if (ret_rcv < 0)
 			return ret_rcv;
 		rcv_cnt += ret_rcv;
@@ -184,7 +186,7 @@ static long long int download_head(unsigned long long total,
 			}
 			buf = transfer_buffer;
 		}
-		send_data_rsp(0, ++usb_pkt_cnt);
+		send_data_rsp(udc, 0, ++usb_pkt_cnt);
 	}
 
 	/* Calculate the amount of data to arrive from PC (in bytes) */
@@ -200,11 +202,11 @@ static long long int download_head(unsigned long long total,
 
 	if (left_to_rcv) {
 		thor_set_dma(buf, packet_size);
-		ret_rcv = thor_rx_data();
+		ret_rcv = thor_rx_data(udc);
 		if (ret_rcv < 0)
 			return ret_rcv;
 		rcv_cnt += ret_rcv;
-		send_data_rsp(0, ++usb_pkt_cnt);
+		send_data_rsp(udc, 0, ++usb_pkt_cnt);
 	}
 
 	debug("%s: %llu total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
@@ -254,7 +256,7 @@ static int download_tail(long long int left, int cnt)
 	return ret;
 }
 
-static long long int process_rqt_download(const struct rqt_box *rqt)
+static long long int process_rqt_download(struct udevice *udc, const struct rqt_box *rqt)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
 	static long long int left, ret_head;
@@ -301,8 +303,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
 		}
 		break;
 	case RQT_DL_FILE_START:
-		send_rsp(rsp);
-		ret_head = download_head(thor_file_size, THOR_PACKET_SIZE,
+		send_rsp(udc, rsp);
+		ret_head = download_head(udc, thor_file_size, THOR_PACKET_SIZE,
 					 &left, &cnt);
 		if (ret_head < 0) {
 			left = 0;
@@ -324,11 +326,11 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
 		ret = -ENOTSUPP;
 	}
 
-	send_rsp(rsp);
+	send_rsp(udc, rsp);
 	return ret;
 }
 
-static int process_data(void)
+static int process_data(struct udevice *udc)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct rqt_box, rqt, sizeof(struct rqt_box));
 	int ret = -EINVAL;
@@ -339,13 +341,13 @@ static int process_data(void)
 
 	switch (rqt->rqt) {
 	case RQT_INFO:
-		ret = process_rqt_info(rqt);
+		ret = process_rqt_info(udc, rqt);
 		break;
 	case RQT_CMD:
-		ret = process_rqt_cmd(rqt);
+		ret = process_rqt_cmd(udc, rqt);
 		break;
 	case RQT_DL:
-		ret = (int) process_rqt_download(rqt);
+		ret = (int) process_rqt_download(udc, rqt);
 		break;
 	case RQT_UL:
 		puts("RQT: UPLOAD not supported!\n");
@@ -536,7 +538,7 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
 	return req;
 }
 
-static int thor_rx_data(void)
+static int thor_rx_data(struct udevice *udc)
 {
 	struct thor_dev *dev = thor_func->dev;
 	int data_to_rx, tmp, status;
@@ -557,7 +559,7 @@ static int thor_rx_data(void)
 		}
 
 		while (!dev->rxdata) {
-			usb_gadget_handle_interrupts(0);
+			dm_usb_gadget_handle_interrupts(udc);
 			if (ctrlc())
 				return -1;
 		}
@@ -568,7 +570,7 @@ static int thor_rx_data(void)
 	return tmp;
 }
 
-static void thor_tx_data(unsigned char *data, int len)
+static void thor_tx_data(struct udevice *udc, unsigned char *data, int len)
 {
 	struct thor_dev *dev = thor_func->dev;
 	unsigned char *ptr = dev->in_req->buf;
@@ -591,7 +593,7 @@ static void thor_tx_data(unsigned char *data, int len)
 
 	/* Wait until tx interrupt received */
 	while (!dev->txdata)
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udc);
 
 	dev->txdata = 0;
 }
@@ -685,18 +687,18 @@ static void thor_set_dma(void *addr, int len)
 	dev->out_req->length = len;
 }
 
-int thor_init(void)
+int thor_init(struct udevice *udc)
 {
 	struct thor_dev *dev = thor_func->dev;
 
 	/* Wait for a device enumeration and configuration settings */
 	debug("THOR enumeration/configuration setting....\n");
 	while (!dev->configuration_done)
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udc);
 
 	thor_set_dma(thor_rx_data_buf, strlen("THOR"));
 	/* detect the download request from Host PC */
-	if (thor_rx_data() < 0) {
+	if (thor_rx_data(udc) < 0) {
 		printf("%s: Data not received!\n", __func__);
 		return -1;
 	}
@@ -706,7 +708,7 @@ int thor_init(void)
 		udelay(30 * 1000); /* 30 ms */
 
 		strcpy((char *)thor_tx_data_buf, "ROHT");
-		thor_tx_data(thor_tx_data_buf, strlen("ROHT"));
+		thor_tx_data(udc, thor_tx_data_buf, strlen("ROHT"));
 	} else {
 		puts("Wrong reply information\n");
 		return -1;
@@ -715,17 +717,17 @@ int thor_init(void)
 	return 0;
 }
 
-int thor_handle(void)
+int thor_handle(struct udevice *udc)
 {
 	int ret;
 
 	/* receive the data from Host PC */
 	while (1) {
 		thor_set_dma(thor_rx_data_buf, sizeof(struct rqt_box));
-		ret = thor_rx_data();
+		ret = thor_rx_data(udc);
 
 		if (ret > 0) {
-			ret = process_data();
+			ret = process_data(udc);
 #ifdef CONFIG_THOR_RESET_OFF
 			if (ret == RESET_DONE)
 				break;
include/thor.h +2 -2
index ee67ab0a270..3cb56b654ae 100644
@@ -14,7 +14,7 @@
 
 #define THOR_DFU_REINIT_NEEDED	0xFFFFFFFE
 
-int thor_handle(void);
-int thor_init(void);
+int thor_handle(struct udevice *udc);
+int thor_init(struct udevice *udc);
 int thor_add(struct usb_configuration *c);
 #endif /* __THOR_H_ */
Signature · 1 line
2.40.1
#16 lore raw

PATCH v2 14/17 usb: gadget: acm: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 drivers/usb/gadget/f_acm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/gadget/f_acm.c +8 -5
index b2ddd1ada8b..de42e0189e8 100644
@@ -51,7 +51,7 @@ struct f_acm {
 #define ACM_CTRL_RTS	BIT(1)	/* unused with full duplex */
 #define ACM_CTRL_DTR	BIT(0)	/* host is ready for data r/w */
 
-	int controller_index;
+	struct udevice *udc;
 };
 
 static struct f_acm *default_acm_function;
@@ -489,7 +489,7 @@ static void __acm_tx(struct f_acm *f_acm)
 	int len, ret;
 
 	do {
-		usb_gadget_handle_interrupts(f_acm->controller_index);
+		dm_usb_gadget_handle_interrupts(f_acm->udc);
 
 		if (!(f_acm->handshake_bits & ACM_CTRL_DTR))
 			break;
@@ -520,7 +520,7 @@ static bool acm_connected(struct stdio_dev *dev)
 	struct f_acm *f_acm = stdio_to_acm(dev);
 
 	/* give a chance to process udc irq */
-	usb_gadget_handle_interrupts(f_acm->controller_index);
+	dm_usb_gadget_handle_interrupts(f_acm->udc);
 
 	return f_acm->connected;
 }
@@ -543,7 +543,10 @@ static int acm_add(struct usb_configuration *c)
 	f_acm->usb_function.descriptors = acm_fs_function;
 	f_acm->usb_function.hs_descriptors = acm_hs_function;
 	f_acm->usb_function.setup = acm_setup;
-	f_acm->controller_index = 0;
+
+	status = udc_device_get_by_index(0, &f_acm->udc);
+	if (status)
+		return status;
 
 	status = usb_add_function(c, &f_acm->usb_function);
 	if (status) {
@@ -567,7 +570,7 @@ static int acm_stdio_tstc(struct stdio_dev *dev)
 {
 	struct f_acm *f_acm = stdio_to_acm(dev);
 
-	usb_gadget_handle_interrupts(f_acm->controller_index);
+	dm_usb_gadget_handle_interrupts(f_acm->udc);
 
 	return (f_acm->rx_buf.size > 0);
 }
Signature · 1 line
2.40.1
Reviewed-by on v2 14/17
#17 lore raw

Re: [PATCH v2 14/17] usb: gadget: acm: Use plain udevice for UDC controller interaction

Quoted 4 lines · Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

Quoted 75 lines

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: No change

---
 drivers/usb/gadget/f_acm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/gadget/f_acm.c +8 -5
index b2ddd1ada8b..de42e0189e8 100644
@@ -51,7 +51,7 @@ struct f_acm {
 #define ACM_CTRL_RTS	BIT(1)	/* unused with full duplex */
 #define ACM_CTRL_DTR	BIT(0)	/* host is ready for data r/w */
 
-	int controller_index;
+	struct udevice *udc;
 };
 
 static struct f_acm *default_acm_function;
@@ -489,7 +489,7 @@ static void __acm_tx(struct f_acm *f_acm)
 	int len, ret;
 
 	do {
-		usb_gadget_handle_interrupts(f_acm->controller_index);
+		dm_usb_gadget_handle_interrupts(f_acm->udc);
 
 		if (!(f_acm->handshake_bits & ACM_CTRL_DTR))
 			break;
@@ -520,7 +520,7 @@ static bool acm_connected(struct stdio_dev *dev)
 	struct f_acm *f_acm = stdio_to_acm(dev);
 
 	/* give a chance to process udc irq */
-	usb_gadget_handle_interrupts(f_acm->controller_index);
+	dm_usb_gadget_handle_interrupts(f_acm->udc);
 
 	return f_acm->connected;
 }
@@ -543,7 +543,10 @@ static int acm_add(struct usb_configuration *c)
 	f_acm->usb_function.descriptors = acm_fs_function;
 	f_acm->usb_function.hs_descriptors = acm_hs_function;
 	f_acm->usb_function.setup = acm_setup;
-	f_acm->controller_index = 0;
+
+	status = udc_device_get_by_index(0, &f_acm->udc);
+	if (status)
+		return status;
 
 	status = usb_add_function(c, &f_acm->usb_function);
 	if (status) {
@@ -567,7 +570,7 @@ static int acm_stdio_tstc(struct stdio_dev *dev)
 {
 	struct f_acm *f_acm = stdio_to_acm(dev);
 
-	usb_gadget_handle_interrupts(f_acm->controller_index);
+	dm_usb_gadget_handle_interrupts(f_acm->udc);
 
 	return (f_acm->rx_buf.size > 0);
 }
Signature · 1 line
2.40.1
#18 lore raw

PATCH v2 15/17 usb: gadget: ether: Use plain udevice for UDC controller interaction

In reply to Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Use udev->parent for UDC access

---
 drivers/usb/gadget/ether.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/ether.c +11 -9
index 5ff06d3814b..11b1a6221b3 100644
@@ -1880,8 +1880,10 @@ static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
 	}
 }
 
-static int eth_stop(struct eth_dev *dev)
+static int eth_stop(struct udevice *udev)
 {
+	struct ether_priv *priv = dev_get_priv(udev);
+	struct eth_dev *dev = &priv->ethdev;
 #ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
 	unsigned long ts;
 	unsigned long timeout = CONFIG_SYS_HZ; /* 1 sec to stop RNDIS */
@@ -1895,7 +1897,7 @@ static int eth_stop(struct eth_dev *dev)
 		/* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
 		ts = get_timer(0);
 		while (get_timer(ts) < timeout)
-			usb_gadget_handle_interrupts(0);
+			dm_usb_gadget_handle_interrupts(udev->parent);
 #endif
 
 		rndis_uninit(dev->rndis_config);
@@ -2300,7 +2302,7 @@ static int usb_eth_start(struct udevice *udev)
 			pr_err("The remote end did not respond in time.");
 			goto fail;
 		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
 	}
 
 	packet_received = 0;
@@ -2370,7 +2372,7 @@ static int usb_eth_send(struct udevice *udev, void *packet, int length)
 			printf("timeout sending packets to usb ethernet\n");
 			return -1;
 		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
 	}
 	free(rndis_pkt);
 
@@ -2400,13 +2402,13 @@ static void usb_eth_stop(struct udevice *udev)
 	 * 2) 'pullup' callback in your UDC driver can be improved to perform
 	 * this deinitialization.
 	 */
-	eth_stop(dev);
+	eth_stop(udev);
 
 	usb_gadget_disconnect(dev->gadget);
 
 	/* Clear pending interrupt */
 	if (dev->network_started) {
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
 		dev->network_started = 0;
 	}
 }
@@ -2416,7 +2418,7 @@ static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
 	struct ether_priv *priv = dev_get_priv(dev);
 	struct eth_dev *ethdev = &priv->ethdev;
 
-	usb_gadget_handle_interrupts(0);
+	dm_usb_gadget_handle_interrupts(dev->parent);
 
 	if (packet_received) {
 		if (ethdev->rx_req) {
@@ -2467,7 +2469,7 @@ int usb_ether_init(void)
 		return ret;
 	}
 
-	return usb_gadget_initialize(0);
+	return 0;
 }
 
 static int usb_eth_probe(struct udevice *dev)
@@ -2528,7 +2530,7 @@ static int usb_eth_remove(struct udevice *dev)
 
 static int usb_eth_unbind(struct udevice *dev)
 {
-	usb_gadget_release(0);
+	udc_device_put(dev->parent);
 
 	return 0;
 }
Signature · 1 line
2.40.1
#19 lore raw

Re: [PATCH v2 15/17] usb: gadget: ether: Use plain udevice for UDC controller interaction

Quoted 94 lines · Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Use udev->parent for UDC access

---
 drivers/usb/gadget/ether.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/ether.c +9 -7
index 5ff06d3814b..11b1a6221b3 100644
@@ -1880,8 +1880,10 @@ static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
 	}
 }
 
-static int eth_stop(struct eth_dev *dev)
+static int eth_stop(struct udevice *udev)
 {
+	struct ether_priv *priv = dev_get_priv(udev);
+	struct eth_dev *dev = &priv->ethdev;
 #ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
 	unsigned long ts;
 	unsigned long timeout = CONFIG_SYS_HZ; /* 1 sec to stop RNDIS */
@@ -1895,7 +1897,7 @@ static int eth_stop(struct eth_dev *dev)
 		/* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
 		ts = get_timer(0);
 		while (get_timer(ts) < timeout)
-			usb_gadget_handle_interrupts(0);
+			dm_usb_gadget_handle_interrupts(udev->parent);
 #endif
 
 		rndis_uninit(dev->rndis_config);
@@ -2300,7 +2302,7 @@ static int usb_eth_start(struct udevice *udev)
 			pr_err("The remote end did not respond in time.");
 			goto fail;
 		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
 	}
 
 	packet_received = 0;
@@ -2370,7 +2372,7 @@ static int usb_eth_send(struct udevice *udev, void *packet, int length)
 			printf("timeout sending packets to usb ethernet\n");
 			return -1;
 		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
 	}
 	free(rndis_pkt);
 
@@ -2400,13 +2402,13 @@ static void usb_eth_stop(struct udevice *udev)
 	 * 2) 'pullup' callback in your UDC driver can be improved to perform
 	 * this deinitialization.
 	 */
-	eth_stop(dev);
+	eth_stop(udev);
 
 	usb_gadget_disconnect(dev->gadget);
 
 	/* Clear pending interrupt */
 	if (dev->network_started) {
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
 		dev->network_started = 0;
 	}
 }
@@ -2416,7 +2418,7 @@ static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
 	struct ether_priv *priv = dev_get_priv(dev);
 	struct eth_dev *ethdev = &priv->ethdev;
 
-	usb_gadget_handle_interrupts(0);
+	dm_usb_gadget_handle_interrupts(dev->parent);
 
 	if (packet_received) {
 		if (ethdev->rx_req) {

drivers/usb/gadget/ether.c int usb_ether_init(void) · line 2472

Quoted 5 lines
drivers/usb/gadget/ether.c +1 -1
@@ -2467,7 +2469,7 @@ int usb_ether_init(void)
 		return ret;
 	}
 
-	return usb_gadget_initialize(0);
+	return 0;

No udc_device_get() here?

This looks a little suspicious, because in the unbind() we call udc_device_put().

Quoted 14 lines
drivers/usb/gadget/ether.c +1 -1
 }
 
 static int usb_eth_probe(struct udevice *dev)
@@ -2528,7 +2530,7 @@ static int usb_eth_remove(struct udevice *dev)
 
 static int usb_eth_unbind(struct udevice *dev)
 {
-	usb_gadget_release(0);
+	udc_device_put(dev->parent);
 
 	return 0;
 }
Signature · 1 line
2.40.1
#20 lore raw

Re: [PATCH v2 15/17] usb: gadget: ether: Use plain udevice for UDC controller interaction

Quoted 99 lines · Mattijs Korpershoek
Quoted 97 lines · Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Use udev->parent for UDC access

---
  drivers/usb/gadget/ether.c | 20 +++++++++++---------
  1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/ether.c +9 -7
index 5ff06d3814b..11b1a6221b3 100644
@@ -1880,8 +1880,10 @@ static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
  	}
  }
 
-static int eth_stop(struct eth_dev *dev)
+static int eth_stop(struct udevice *udev)
  {
+	struct ether_priv *priv = dev_get_priv(udev);
+	struct eth_dev *dev = &priv->ethdev;
  #ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
  	unsigned long ts;
  	unsigned long timeout = CONFIG_SYS_HZ; /* 1 sec to stop RNDIS */
@@ -1895,7 +1897,7 @@ static int eth_stop(struct eth_dev *dev)
  		/* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
  		ts = get_timer(0);
  		while (get_timer(ts) < timeout)
-			usb_gadget_handle_interrupts(0);
+			dm_usb_gadget_handle_interrupts(udev->parent);
  #endif
 
  		rndis_uninit(dev->rndis_config);
@@ -2300,7 +2302,7 @@ static int usb_eth_start(struct udevice *udev)
  			pr_err("The remote end did not respond in time.");
  			goto fail;
  		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
  	}
 
  	packet_received = 0;
@@ -2370,7 +2372,7 @@ static int usb_eth_send(struct udevice *udev, void *packet, int length)
  			printf("timeout sending packets to usb ethernet\n");
  			return -1;
  		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
  	}
  	free(rndis_pkt);
 
@@ -2400,13 +2402,13 @@ static void usb_eth_stop(struct udevice *udev)
  	 * 2) 'pullup' callback in your UDC driver can be improved to perform
  	 * this deinitialization.
  	 */
-	eth_stop(dev);
+	eth_stop(udev);
 
  	usb_gadget_disconnect(dev->gadget);
 
  	/* Clear pending interrupt */
  	if (dev->network_started) {
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
  		dev->network_started = 0;
  	}
  }
@@ -2416,7 +2418,7 @@ static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
  	struct ether_priv *priv = dev_get_priv(dev);
  	struct eth_dev *ethdev = &priv->ethdev;
 
-	usb_gadget_handle_interrupts(0);
+	dm_usb_gadget_handle_interrupts(dev->parent);
 
  	if (packet_received) {
  		if (ethdev->rx_req) {
@@ -2467,7 +2469,7 @@ int usb_ether_init(void)
  		return ret;
  	}
 
Quoted 7 lines

drivers/usb/gadget/ether.c int usb_ether_init(void) · line 2472

Quoted 2 lines
drivers/usb/gadget/ether.c +1 -1
-	return usb_gadget_initialize(0);
+	return 0;

No udc_device_get() here?

This looks a little suspicious, because in the unbind() we call udc_device_put().

Look at how udc_device_get_by_index() is implemented and what it does, compared to what usb_ether_init() does (hint: they are basically doing the same thing). This udc_device_put() here is only a workaround for platforms which are not using the bind command to bind USB ethernet yet.

#21 lore raw

Re: [PATCH v2 15/17] usb: gadget: ether: Use plain udevice for UDC controller interaction

Quoted 105 lines · Marek Vasut
Quoted 104 lines · Mattijs Korpershoek
Quoted 94 lines · Marek Vasut

Convert to plain udevice interaction with UDC controller device, avoid the use of UDC uclass dev_array .

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Use udev->parent for UDC access

---
  drivers/usb/gadget/ether.c | 20 +++++++++++---------
  1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/ether.c +9 -7
index 5ff06d3814b..11b1a6221b3 100644
@@ -1880,8 +1880,10 @@ static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
  	}
  }
 
-static int eth_stop(struct eth_dev *dev)
+static int eth_stop(struct udevice *udev)
  {
+	struct ether_priv *priv = dev_get_priv(udev);
+	struct eth_dev *dev = &priv->ethdev;
  #ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
  	unsigned long ts;
  	unsigned long timeout = CONFIG_SYS_HZ; /* 1 sec to stop RNDIS */
@@ -1895,7 +1897,7 @@ static int eth_stop(struct eth_dev *dev)
  		/* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
  		ts = get_timer(0);
  		while (get_timer(ts) < timeout)
-			usb_gadget_handle_interrupts(0);
+			dm_usb_gadget_handle_interrupts(udev->parent);
  #endif
 
  		rndis_uninit(dev->rndis_config);
@@ -2300,7 +2302,7 @@ static int usb_eth_start(struct udevice *udev)
  			pr_err("The remote end did not respond in time.");
  			goto fail;
  		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
  	}
 
  	packet_received = 0;
@@ -2370,7 +2372,7 @@ static int usb_eth_send(struct udevice *udev, void *packet, int length)
  			printf("timeout sending packets to usb ethernet\n");
  			return -1;
  		}
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
  	}
  	free(rndis_pkt);
 
@@ -2400,13 +2402,13 @@ static void usb_eth_stop(struct udevice *udev)
  	 * 2) 'pullup' callback in your UDC driver can be improved to perform
  	 * this deinitialization.
  	 */
-	eth_stop(dev);
+	eth_stop(udev);
 
  	usb_gadget_disconnect(dev->gadget);
 
  	/* Clear pending interrupt */
  	if (dev->network_started) {
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(udev->parent);
  		dev->network_started = 0;
  	}
  }
@@ -2416,7 +2418,7 @@ static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
  	struct ether_priv *priv = dev_get_priv(dev);
  	struct eth_dev *ethdev = &priv->ethdev;
 
-	usb_gadget_handle_interrupts(0);
+	dm_usb_gadget_handle_interrupts(dev->parent);
 
  	if (packet_received) {
  		if (ethdev->rx_req) {

drivers/usb/gadget/ether.c int usb_ether_init(void) · line 2472

Quoted 5 lines
drivers/usb/gadget/ether.c +1 -1
@@ -2467,7 +2469,7 @@ int usb_ether_init(void)
  		return ret;
  	}
 
-	return usb_gadget_initialize(0);
+	return 0;

No udc_device_get() here?

Quoted 7 lines
Quoted 2 lines

This looks a little suspicious, because in the unbind() we call udc_device_put().

Look at how udc_device_get_by_index() is implemented and what it does, compared to what usb_ether_init() does (hint: they are basically doing the same thing). This udc_device_put() here is only a workaround for platforms which are not using the bind command to bind USB ethernet yet.

Oh right. Thank you for explaining.

#22 lore raw

PATCH v2 16/17 dm: usb: udc: Drop legacy udevice handler functions

In reply to Marek Vasut

Remove legacy functions limited by the dev_array array, those are no longer used anywhere, all the code uses plain udevice based access now.

The usb_gadget_handle_interrupts() is doing udevice look up until all call sites use dm_usb_gadget_handle_interrupts().

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 drivers/usb/gadget/udc/udc-uclass.c | 44 ++++-------------------------
 include/linux/usb/gadget.h          | 17 -----------
 2 files changed, 6 insertions(+), 55 deletions(-)
drivers/usb/gadget/udc/udc-uclass.c +6 -38
index b4271b4be9f..7f54a3b00cb 100644
@@ -12,9 +12,6 @@
 #include <linux/usb/gadget.h>
 
 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
-#define MAX_UDC_DEVICES 4
-static struct udevice *dev_array[MAX_UDC_DEVICES];
-
 int udc_device_get_by_index(int index, struct udevice **udev)
 {
 	struct udevice *dev = NULL;
@@ -45,45 +42,16 @@ int udc_device_put(struct udevice *udev)
 #endif
 }
 
-int usb_gadget_initialize(int index)
-{
-	int ret;
-	struct udevice *dev = NULL;
-
-	if (index < 0 || index >= ARRAY_SIZE(dev_array))
-		return -EINVAL;
-	if (dev_array[index])
-		return 0;
-	ret = udc_device_get_by_index(index, &dev);
-	if (!dev || ret) {
-		pr_err("No USB device found\n");
-		return -ENODEV;
-	}
-	dev_array[index] = dev;
-	return 0;
-}
-
-int usb_gadget_release(int index)
+int usb_gadget_handle_interrupts(int index)
 {
-#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
+	struct udevice *udc;
 	int ret;
-	if (index < 0 || index >= ARRAY_SIZE(dev_array))
-		return -EINVAL;
 
-	ret = device_remove(dev_array[index]);
-	if (!ret)
-		dev_array[index] = NULL;
-	return ret;
-#else
-	return -ENOSYS;
-#endif
-}
+	ret = udc_device_get_by_index(index, &udc);
+	if (ret)
+		return ret;
 
-int usb_gadget_handle_interrupts(int index)
-{
-	if (index < 0 || index >= ARRAY_SIZE(dev_array))
-		return -EINVAL;
-	return dm_usb_gadget_handle_interrupts(dev_array[index]);
+	return dm_usb_gadget_handle_interrupts(udc);
 }
 #else
 /* Backwards hardware compatibility -- switch to DM_USB_GADGET */
include/linux/usb/gadget.h +0 -17
index 5e9a6513d5b..54875d2716e 100644
@@ -1023,21 +1023,4 @@ int udc_device_get_by_index(int index, struct udevice **udev);
  */
 int udc_device_put(struct udevice *udev);
 
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)
-int usb_gadget_initialize(int index);
-int usb_gadget_release(int index);
-int dm_usb_gadget_handle_interrupts(struct udevice *dev);
-#else
-#include <usb.h>
-static inline int usb_gadget_initialize(int index)
-{
-	return board_usb_init(index, USB_INIT_DEVICE);
-}
-
-static inline int usb_gadget_release(int index)
-{
-	return board_usb_cleanup(index, USB_INIT_DEVICE);
-}
-#endif
-
 #endif	/* __LINUX_USB_GADGET_H */
Signature · 1 line
2.40.1
#23 lore raw

PATCH v2 17/17 board: usb: Replace legacy usb_gadget_handle_interrupts()

In reply to Marek Vasut

The usb_gadget_handle_interrupts() is no longer used anywhere, replace the remaining uses with dm_usb_gadget_handle_interrupts() which takes udevice as a parameter.

Some of the UDC drivers currently ignore the index parameter altogether, those also ignore the udevice and have to be reworked. Other like the dwc3_uboot_handle_interrupt() had to be switched from index to udevice look up to avoid breakage.

---
NOTE: Next step, get rid of dwc3_uboot_init()/dwc3_uboot_exit()
---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB, TB from Mattijs

---
 arch/arm/mach-rockchip/board.c      |  4 ++--
 board/purism/librem5/spl.c          |  4 ++--
 board/samsung/common/exynos5-dt.c   |  4 ++--
 board/st/stih410-b2260/board.c      |  4 ++--
 board/ti/am43xx/board.c             |  6 +++---
 drivers/usb/dwc3/core.c             |  6 +++---
 drivers/usb/dwc3/dwc3-omap.c        |  8 ++++----
 drivers/usb/gadget/at91_udc.c       |  2 +-
 drivers/usb/gadget/atmel_usba_udc.c |  3 +--
 drivers/usb/gadget/ci_udc.c         |  4 ++--
 drivers/usb/gadget/dwc2_udc_otg.c   | 12 ++----------
 drivers/usb/gadget/udc/udc-uclass.c | 12 ------------
 drivers/usb/host/usb-sandbox.c      |  5 -----
 drivers/usb/musb-new/musb_uboot.c   |  2 +-
 include/dwc3-omap-uboot.h           |  2 +-
 include/dwc3-uboot.h                |  2 +-
 include/linux/usb/gadget.h          |  2 +-
 17 files changed, 28 insertions(+), 54 deletions(-)
arch/arm/mach-rockchip/board.c +2 -2
index 8d7b39ba157..57f08e0be0e 100644
@@ -299,9 +299,9 @@ static struct dwc3_device dwc3_device_data = {
 	.hsphy_mode = USBPHY_INTERFACE_MODE_UTMIW,
 };
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
-	dwc3_uboot_handle_interrupt(0);
+	dwc3_uboot_handle_interrupt(dev);
 	return 0;
 }
 
board/purism/librem5/spl.c +2 -2
index 90f1fcf415f..581f0929662 100644
@@ -418,9 +418,9 @@ out:
 	return rv;
 }
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
-	dwc3_uboot_handle_interrupt(0);
+	dwc3_uboot_handle_interrupt(dev);
 	return 0;
 }
 
board/samsung/common/exynos5-dt.c +2 -2
index cde77d79a0f..726b7f0667a 100644
@@ -126,9 +126,9 @@ static struct dwc3_device dwc3_device_data = {
 	.index = 0,
 };
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
-	dwc3_uboot_handle_interrupt(0);
+	dwc3_uboot_handle_interrupt(dev);
 	return 0;
 }
 
board/st/stih410-b2260/board.c +2 -2
index cd3a7dc51a2..e21cbc270e9 100644
@@ -50,9 +50,9 @@ static struct dwc3_device dwc3_device_data = {
 	.index = 0,
 };
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
-	dwc3_uboot_handle_interrupt(index);
+	dwc3_uboot_handle_interrupt(dev);
 	return 0;
 }
 
board/ti/am43xx/board.c +3 -3
index 87e552a4701..58bfe7cd455 100644
@@ -760,13 +760,13 @@ static struct ti_usb_phy_device usb_phy2_device = {
 	.index = 1,
 };
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
 	u32 status;
 
-	status = dwc3_omap_uboot_interrupt_status(index);
+	status = dwc3_omap_uboot_interrupt_status(dev);
 	if (status)
-		dwc3_uboot_handle_interrupt(index);
+		dwc3_uboot_handle_interrupt(dev);
 
 	return 0;
 }
drivers/usb/dwc3/core.c +3 -3
index 49f6a1900b0..7ca9d09824e 100644
@@ -986,18 +986,18 @@ void dwc3_uboot_exit(int index)
 
 /**
  * dwc3_uboot_handle_interrupt - handle dwc3 core interrupt
- * @index: index of this controller
+ * @dev: device of this controller
  *
  * Invokes dwc3 gadget interrupts.
  *
  * Generally called from board file.
  */
-void dwc3_uboot_handle_interrupt(int index)
+void dwc3_uboot_handle_interrupt(struct udevice *dev)
 {
 	struct dwc3 *dwc = NULL;
 
 	list_for_each_entry(dwc, &dwc3_list, list) {
-		if (dwc->index != index)
+		if (dwc->dev != dev)
 			continue;
 
 		dwc3_gadget_uboot_handle_interrupt(dwc);
drivers/usb/dwc3/dwc3-omap.c +4 -4
index 9596bf144c3..ff4ebfb4447 100644
@@ -119,7 +119,7 @@
 #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID	(1 << 1)
 
 struct dwc3_omap {
-	struct device		*dev;
+	struct udevice		*dev;
 
 	void __iomem		*base;
 
@@ -429,19 +429,19 @@ void dwc3_omap_uboot_exit(int index)
 
 /**
  * dwc3_omap_uboot_interrupt_status - check the status of interrupt
- * @index: index of this controller
+ * @dev: device of this controller
  *
  * Checks the status of interrupts and returns true if an interrupt
  * is detected or false otherwise.
  *
  * Generally called from board file.
  */
-int dwc3_omap_uboot_interrupt_status(int index)
+int dwc3_omap_uboot_interrupt_status(struct udevice *dev)
 {
 	struct dwc3_omap *omap = NULL;
 
 	list_for_each_entry(omap, &dwc3_omap_list, list)
-		if (omap->index == index)
+		if (omap->dev == dev)
 			return dwc3_omap_interrupt(-1, omap);
 
 	return 0;
drivers/usb/gadget/at91_udc.c +1 -1
index baa4c431fed..61d2aa5b929 100644
@@ -1429,7 +1429,7 @@ static const struct at91_udc_caps at91sam9261_udc_caps = {
 };
 #endif
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
 	struct at91_udc *udc = controller;
 
drivers/usb/gadget/atmel_usba_udc.c +1 -2
index f4dcd205a4f..90b248a0777 100644
@@ -1198,14 +1198,13 @@ static struct usba_udc controller = {
 	},
 };
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
 	struct usba_udc *udc = &controller;
 
 	return usba_udc_irq(udc);
 }
 
-
 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
 	struct usba_udc *udc = &controller;
drivers/usb/gadget/ci_udc.c +2 -2
index 5bb26d7ab4a..44d2da0b4fb 100644
@@ -869,10 +869,10 @@ void udc_irq(void)
 	}
 }
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
-	u32 value;
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+	u32 value;
 
 	value = readl(&udc->usbsts);
 	if (value)
drivers/usb/gadget/dwc2_udc_otg.c +2 -10
index 0a3bc0886e6..ff5173eda68 100644
@@ -941,15 +941,12 @@ int dwc2_udc_handle_interrupt(void)
 	return 0;
 }
 
-#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
-
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
 	return dwc2_udc_handle_interrupt();
 }
 
-#else /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
-
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
 struct dwc2_priv_data {
 	struct clk_bulk		clks;
 	struct reset_ctl_bulk	resets;
@@ -957,11 +954,6 @@ struct dwc2_priv_data {
 	struct udevice *usb33d_supply;
 };
 
-int dm_usb_gadget_handle_interrupts(struct udevice *dev)
-{
-	return dwc2_udc_handle_interrupt();
-}
-
 static int dwc2_phy_setup(struct udevice *dev, struct phy_bulk *phys)
 {
 	int ret;
drivers/usb/gadget/udc/udc-uclass.c +0 -12
index 7f54a3b00cb..9dfae08313b 100644
@@ -41,18 +41,6 @@ int udc_device_put(struct udevice *udev)
 	return -ENOSYS;
 #endif
 }
-
-int usb_gadget_handle_interrupts(int index)
-{
-	struct udevice *udc;
-	int ret;
-
-	ret = udc_device_get_by_index(index, &udc);
-	if (ret)
-		return ret;
-
-	return dm_usb_gadget_handle_interrupts(udc);
-}
 #else
 /* Backwards hardware compatibility -- switch to DM_USB_GADGET */
 static int legacy_index;
drivers/usb/host/usb-sandbox.c +0 -5
index 582f72d00c1..3d4f8d653b5 100644
@@ -130,11 +130,6 @@ int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 	return 0;
 }
 #else
-int usb_gadget_handle_interrupts(int index)
-{
-	return 0;
-}
-
 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
 	struct sandbox_udc *dev = this_controller;
drivers/usb/musb-new/musb_uboot.c +1 -1
index 67dc11669d2..0dcc428efeb 100644
@@ -376,7 +376,7 @@ struct dm_usb_ops musb_usb_ops = {
 #if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET)
 static struct musb *gadget;
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
 	schedule();
 	if (!gadget || !gadget->isr)
include/dwc3-omap-uboot.h +1 -1
index 7c982e3798b..9e0e717dc98 100644
@@ -27,5 +27,5 @@ struct dwc3_omap_device {
 
 int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
 void dwc3_omap_uboot_exit(int index);
-int dwc3_omap_uboot_interrupt_status(int index);
+int dwc3_omap_uboot_interrupt_status(struct udevice *dev);
 #endif /* __DWC3_OMAP_UBOOT_H_ */
include/dwc3-uboot.h +1 -1
index e08530ec4e5..bb0436c0973 100644
@@ -44,7 +44,7 @@ struct dwc3_device {
 
 int dwc3_uboot_init(struct dwc3_device *dev);
 void dwc3_uboot_exit(int index);
-void dwc3_uboot_handle_interrupt(int index);
+void dwc3_uboot_handle_interrupt(struct udevice *dev);
 
 struct phy;
 #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)
include/linux/usb/gadget.h +1 -1
index 54875d2716e..40228e320b3 100644
@@ -1004,7 +1004,7 @@ extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
 
 extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
-extern int usb_gadget_handle_interrupts(int index);
+extern int dm_usb_gadget_handle_interrupts(struct udevice *);
 
 /**
  * udc_device_get_by_index() - Get UDC udevice by index
Signature · 1 line
2.40.1
#24 lore raw
In reply to Marek Vasut

Hi Marek,

I'm answering here as there is no cover letter. Just to let you know I'm still concerned by the series and want to test it but did not had the time to do so recently. Hopefully next week.

Sorry for the delay.
Miquèl

[email protected] wrote on Fri, 1 Sep 2023 11:49:47 +0200:

Quoted 29 lines

Pull the functionality of UDC uclass that operates on plain udevice and does not use this dev_array array into separate functions and expose those functions, so that as much code as possible can be switched over to these functions and the dev_array can be dropped.

---
Cc: Angus Ainslie <[email protected]>
Cc: Dmitrii Merkurev <[email protected]>
Cc: Eddie Cai <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Miquel Raynal <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Nishanth Menon <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Philipp Tomsich <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: [email protected]
---
V2: Add RB from Mattijs

---
 drivers/usb/gadget/udc/Makefile     |  2 +-
 drivers/usb/gadget/udc/udc-uclass.c | 57 +++++++++++++++++++++++++----
 include/linux/usb/gadget.h          | 17 +++++++++
 3 files changed, 68 insertions(+), 8 deletions(-)
Tested-by
#25 lore raw

Hi Marek,

[email protected] wrote on Fri, 22 Sep 2023 12:00:12 +0200:

Quoted 5 lines

Hi Marek,

I'm answering here as there is no cover letter. Just to let you know I'm still concerned by the series and want to test it but did not had the time to do so recently. Hopefully next week.

The series looks good to me and works as well on a Beagle Bone Black with no visible functional changes regarding the use of the UDC. The whole series is:

By the way, following your initial series there have been three followup patches trying to improve a little bit the doc, one got merged and two others were delegated to you:
https://patchwork.ozlabs.org/project/uboot/list/?series=367635

They are almost 2 months old now, would you mind acking or merging them so both your initial USB gadget rework and the additional (related) doc can be in the same release please?

Thanks,
Miquèl

#26 lore raw
Quoted 1 line · Miquel Raynal

Hi Marek,

Hi,

Quoted 14 lines

[email protected] wrote on Fri, 22 Sep 2023 12:00:12 +0200:

Quoted 5 lines

Hi Marek,

I'm answering here as there is no cover letter. Just to let you know I'm still concerned by the series and want to test it but did not had the time to do so recently. Hopefully next week.

The series looks good to me and works as well on a Beagle Bone Black with no visible functional changes regarding the use of the UDC. The whole series is:

Quoted 8 lines

By the way, following your initial series there have been three followup patches trying to improve a little bit the doc, one got merged and two others were delegated to you:
https://patchwork.ozlabs.org/project/uboot/list/?series=367635

They are almost 2 months old now, would you mind acking or merging them so both your initial USB gadget rework and the additional (related) doc can be in the same release please?

Can you resend those and CC this mail address ?

That said, 1/2 should be in some sort of README instead, and the 'dm tree' command depends on CMD_DM=y .

The usb_gadget_probe_driver() is code synchronized from kernel, you likely want to add any such clarification to usb_gadget_register_driver() . That said, the usb_gadget_register_driver() should be reworked into some new functions, which takes UDC controller *udevice pointer to avoid this binding heuristics.

#27 lore raw

Hi Marek,

[email protected] wrote on Sat, 30 Sep 2023 23:11:17 +0200:

Quoted 24 lines · Miquel Raynal
Quoted 1 line

Hi Marek,

Hi,

Quoted 19 lines

[email protected] wrote on Fri, 22 Sep 2023 12:00:12 +0200:

Quoted 5 lines

Hi Marek,

I'm answering here as there is no cover letter. Just to let you know I'm still concerned by the series and want to test it but did not had the time to do so recently. Hopefully next week.

The series looks good to me and works as well on a Beagle Bone Black with no visible functional changes regarding the use of the UDC. The whole series is:

By the way, following your initial series there have been three followup patches trying to improve a little bit the doc, one got merged and two others were delegated to you:
https://patchwork.ozlabs.org/project/uboot/list/?series=367635

Quoted 5 lines
Quoted 3 lines

They are almost 2 months old now, would you mind acking or merging them so both your initial USB gadget rework and the additional (related) doc can be in the same release please?

Can you resend those and CC this mail address ?

Of course!

Quoted 1 line

That said, 1/2 should be in some sort of README instead, and the 'dm tree' command depends on CMD_DM=y .

Well, the README is more something which targets the developer IMO, whereas here I want to target the users. Many people only see U-Boot through Yocto now (that's a different topic) and the purpose of this additional text is to help them in finding their way into U-Boot device model *alone*. It's really short, but I bet it can really help, given how I felt when I actually understood why you advised to type a couple of semi-random bind/unbind commands which eventually worked. Anybody not involved in any DM conversion is likely just not aware of all of that. Having people finding their own way through the DM means less complaints/needs for help on the mailing list.

Quoted 1 line

The usb_gadget_probe_driver() is code synchronized from kernel, you likely want to add any such clarification to usb_gadget_register_driver() .

Actually the kernel functions do have some kind of alternate error message as well now :-) Clearly different given that this code has been adapted to U-Boot's DM, but the idea is close. However usb_gadget_register_driver() is kind of blind regarding the number of UDCs in the system and if they are already bound or not, so I don't really see the point in moving the error message there along with all the logic duplication involved.

Quoted 3 lines

That said, the usb_gadget_register_driver() should be reworked into some new functions, which takes UDC controller *udevice pointer to avoid this binding heuristics.

Yes, I don't know many boards with two UDCs but it's a clear limitation.

Thanks,
Miquèl

#28 lore raw
Quoted 38 lines · Miquel Raynal

Hi Marek,

[email protected] wrote on Sat, 30 Sep 2023 23:11:17 +0200:

Quoted 24 lines · Miquel Raynal
Quoted 1 line

Hi Marek,

Hi,

Quoted 19 lines

[email protected] wrote on Fri, 22 Sep 2023 12:00:12 +0200:

Quoted 5 lines

Hi Marek,

I'm answering here as there is no cover letter. Just to let you know I'm still concerned by the series and want to test it but did not had the time to do so recently. Hopefully next week.

The series looks good to me and works as well on a Beagle Bone Black with no visible functional changes regarding the use of the UDC. The whole series is:

By the way, following your initial series there have been three followup patches trying to improve a little bit the doc, one got merged and two others were delegated to you:
https://patchwork.ozlabs.org/project/uboot/list/?series=367635

Quoted 5 lines
Quoted 3 lines

They are almost 2 months old now, would you mind acking or merging them so both your initial USB gadget rework and the additional (related) doc can be in the same release please?

Can you resend those and CC this mail address ?

Of course!

Quoted 1 line

That said, 1/2 should be in some sort of README instead, and the 'dm tree' command depends on CMD_DM=y .

Quoted 10 lines

Well, the README is more something which targets the developer IMO, whereas here I want to target the users. Many people only see U-Boot through Yocto now (that's a different topic) and the purpose of this additional text is to help them in finding their way into U-Boot device model *alone*. It's really short, but I bet it can really help, given how I felt when I actually understood why you advised to type a couple of semi-random bind/unbind commands which eventually worked. Anybody not involved in any DM conversion is likely just not aware of all of that. Having people finding their own way through the DM means less complaints/needs for help on the mailing list.

Thinking about it back and forth, I think you've got a point, yes.

Quoted 10 lines
Quoted 1 line

The usb_gadget_probe_driver() is code synchronized from kernel, you likely want to add any such clarification to usb_gadget_register_driver() .

Actually the kernel functions do have some kind of alternate error message as well now :-) Clearly different given that this code has been adapted to U-Boot's DM, but the idea is close. However usb_gadget_register_driver() is kind of blind regarding the number of UDCs in the system and if they are already bound or not, so I don't really see the point in moving the error message there along with all the logic duplication involved.

Quoted 5 lines
Quoted 3 lines

That said, the usb_gadget_register_driver() should be reworked into some new functions, which takes UDC controller *udevice pointer to avoid this binding heuristics.

Yes, I don't know many boards with two UDCs but it's a clear limitation.

i.MX8M Plus is one such example, Quad I think is another, and pretty much anything with more than one DWC3 controller is. The CI HDRC is also often present in OTG capable configuration, so a lot of i.MXes are multi UDC systems.