Skip to contentSkip to conversation

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

PATCH Superseded Marek Vasut 4 participants 33 messages Aug 19, 2023 – Sep 1, 2023

Subsystems (8)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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]

---
 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 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]

---
 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
Reviewed-by on v1 2/17
#2 lore raw

Re: [PATCH 02/17] usb: sandbox: Add DM_USB_GADGET support

Quoted 21 lines · Marek Vasut

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]

Quoted 3 lines
---
 drivers/usb/host/usb-sandbox.c | 7 +++++++
 1 file changed, 7 insertions(+)
Reviewed-by on v1 2/17
#3 lore raw

Re: [PATCH 02/17] usb: sandbox: Add DM_USB_GADGET support

In reply to Marek Vasut
Quoted 20 lines · Marek Vasut

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]

Quoted 3 lines
---
 drivers/usb/host/usb-sandbox.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 28 lines
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
#4 lore raw

PATCH 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]

---
 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 69e5efe8748..72452695cdc 100644
@@ -230,6 +230,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 1cd1c2ed7cd..9f8b81f5fe6 100644
@@ -298,6 +298,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 8aa295686dc..cedae60d3cf 100644
@@ -204,6 +204,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 2c6aab6c859..360686b9682 100644
@@ -218,6 +218,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 8d50162b274..bc79adfcd8f 100644
@@ -224,6 +224,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 f3a0fd19a96..2c817b3847d 100644
@@ -237,6 +237,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
Reviewed-by on v1 3/17
#5 lore raw

Re: [PATCH 03/17] configs: sandbox: Enable DM_USB_GADGET

Quoted 19 lines · 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]

Quoted 8 lines
---
 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(+)
Reviewed-by on v1 3/17
#6 lore raw

Re: [PATCH 03/17] configs: sandbox: Enable DM_USB_GADGET

In reply to Marek Vasut
Quoted 18 lines · 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]

Quoted 8 lines
---
 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(+)
Quoted 75 lines
configs/sandbox64_defconfig +1 -0
index 69e5efe8748..72452695cdc 100644
@@ -230,6 +230,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 1cd1c2ed7cd..9f8b81f5fe6 100644
@@ -298,6 +298,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 8aa295686dc..cedae60d3cf 100644
@@ -204,6 +204,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 2c6aab6c859..360686b9682 100644
@@ -218,6 +218,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 8d50162b274..bc79adfcd8f 100644
@@ -224,6 +224,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 f3a0fd19a96..2c817b3847d 100644
@@ -237,6 +237,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
#7 lore raw

PATCH 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]

---
 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
Reviewed-by Tested-by on v1 4/17
#8 lore raw

Re: [PATCH 04/17] cmd: fastboot: Use plain udevice for UDC controller interaction

Quoted 19 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]

Quoted 3 lines
---
 cmd/fastboot.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Tested that I could reflash the bootloader (raw) partition with:

$ fastboot flash bootloader u-boot_kvim3_noab.bin

Works fine!

Based on: 2023.10-rc3

Quoted 40 lines
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
#9 lore raw

PATCH 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]

---
 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
#10 lore raw

PATCH 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]

---
 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
Reviewed-by on v1 6/17
#11 lore raw

Re: [PATCH 06/17] cmd: sdp: Reorder variable declaration

Quoted 19 lines · 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]

Quoted 3 lines
---
 cmd/usb_gadget_sdp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 23 lines
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
#12 lore raw

PATCH 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]

---
 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
#13 lore raw

PATCH 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]

---
 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
Reviewed-by Tested-by on v1 8/17
#14 lore raw

Re: [PATCH 08/17] cmd: ums: Use plain udevice for UDC controller interaction

Quoted 19 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]

Quoted 5 lines
---
 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(-)

Tested on vim3 with:
=> ums 0 mmc 2

Tested that I could read some files from the android data partition.

Quoted 99 lines
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
#15 lore raw

PATCH 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]

---
 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
Reviewed-by on v1 9/17
#16 lore raw

Re: [PATCH 09/17] dfu: Detach the controller on error

Quoted 20 lines · 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]

Quoted 3 lines
---
 common/dfu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 25 lines
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
#17 lore raw

PATCH 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]

---
 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
Reviewed-by on v1 10/17
#18 lore raw

Re: [PATCH 10/17] dfu: Use plain udevice for UDC controller interaction

Quoted 19 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]

Quoted 3 lines
---
 common/dfu.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
Quoted 64 lines
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
#19 lore raw

PATCH 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]

---
 common/spl/spl_sdp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
common/spl/spl_sdp.c +3 -2
index cc4fb4f7cca..f6b99c1af5a 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_detach;
 	}
 
 	/*
@@ -42,6 +42,7 @@ 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_detach:
 	usb_gadget_release(controller_index);
 	return ret;
 }
Signature · 1 line
2.40.1
Reviewed-by on v1 11/17
#20 lore raw

Re: [PATCH 11/17] spl: sdp: Detach the controller on error

Quoted 5 lines · 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.

Quoted 16 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]
---

Nitpick/question below

Quoted 10 lines
 common/spl/spl_sdp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
common/spl/spl_sdp.c +0 -0
index cc4fb4f7cca..f6b99c1af5a 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) {

common/spl/spl_sdp.c static int spl_sdp_load_image(struct spl_image_info *spl_image, · line 34

Quoted 10 lines
common/spl/spl_sdp.c +2 -2
 		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_detach;

Shouldn't we call g_dnl_unregister(); here since g_dnl_register() was sucessfully called before?

This would match what's done in common/dfu.c

Quoted 13 lines
common/spl/spl_sdp.c +1 -0
 	}
 
 	/*
@@ -42,6 +42,7 @@ 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_detach:
 	usb_gadget_release(controller_index);
 	return ret;
 }
Signature · 1 line
2.40.1
#21 lore raw

Re: [PATCH 11/17] spl: sdp: Detach the controller on error

Quoted 43 lines · Mattijs Korpershoek
Quoted 5 lines · 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.

Quoted 16 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]
---

Nitpick/question below

Quoted 15 lines
  common/spl/spl_sdp.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
common/spl/spl_sdp.c +1 -1
index cc4fb4f7cca..f6b99c1af5a 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;
  	}
 
Quoted 8 lines

common/spl/spl_sdp.c static int spl_sdp_load_image(struct spl_image_info *spl_image, · line 34

Quoted 5 lines
common/spl/spl_sdp.c +1 -1
  	ret = sdp_init(controller_index);
  	if (ret) {
  		pr_err("SDP init failed: %d\n", ret);
-		return -ENODEV;
+		goto err_detach;

Shouldn't we call g_dnl_unregister(); here since g_dnl_register() was sucessfully called before?

It should, fixed in V2, thanks for your help !

#22 lore raw

PATCH 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]

---
 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 f6b99c1af5a..83585cf82d3 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_detach;
@@ -39,11 +42,11 @@ 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_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
Reviewed-by on v1 12/17
#23 lore raw

Re: [PATCH 12/17] sdp: Use plain udevice for UDC controller interaction

Quoted 19 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]

Quoted 6 lines
---
 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(-)
Quoted 158 lines
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 f6b99c1af5a..83585cf82d3 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_detach;
@@ -39,11 +42,11 @@ 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_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
#24 lore raw

PATCH 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]

---
 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
#25 lore raw

PATCH 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]

---
 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
#26 lore raw

PATCH 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]

---
 drivers/usb/gadget/ether.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/usb/gadget/ether.c +15 -7
index 5ff06d3814b..cb1317fd9f3 100644
@@ -137,6 +137,7 @@ struct eth_dev {
 struct ether_priv {
 	struct eth_dev ethdev;
 	struct udevice *netdev;
+	struct udevice *udcdev;
 	struct usb_gadget_driver eth_driver;
 };
 
@@ -1895,7 +1896,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(priv->udcdev);
 #endif
 
 		rndis_uninit(dev->rndis_config);
@@ -2300,7 +2301,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(priv->udcdev);
 	}
 
 	packet_received = 0;
@@ -2370,7 +2371,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(priv->udcdev);
 	}
 	free(rndis_pkt);
 
@@ -2406,7 +2407,7 @@ static void usb_eth_stop(struct udevice *udev)
 
 	/* Clear pending interrupt */
 	if (dev->network_started) {
-		usb_gadget_handle_interrupts(0);
+		dm_usb_gadget_handle_interrupts(priv->udcdev);
 		dev->network_started = 0;
 	}
 }
@@ -2416,7 +2417,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(priv->udcdev);
 
 	if (packet_received) {
 		if (ethdev->rx_req) {
@@ -2452,6 +2453,7 @@ static const struct eth_ops usb_eth_ops = {
 
 int usb_ether_init(void)
 {
+	struct ether_priv *priv;
 	struct udevice *usb_dev;
 	int ret;
 
@@ -2467,7 +2469,8 @@ int usb_ether_init(void)
 		return ret;
 	}
 
-	return usb_gadget_initialize(0);
+	priv = dev_get_priv(usb_dev);
+	return udc_device_get_by_index(0, &priv->udcdev);
 }
 
 static int usb_eth_probe(struct udevice *dev)
@@ -2478,6 +2481,9 @@ static int usb_eth_probe(struct udevice *dev)
 	priv->netdev = dev;
 	l_priv = priv;
 
+	if (!priv->udcdev)
+		priv->udcdev = dev->parent;
+
 	get_ether_addr(CONFIG_USBNET_DEV_ADDR, pdata->enetaddr);
 	eth_env_set_enetaddr("usbnet_devaddr", pdata->enetaddr);
 
@@ -2528,7 +2534,9 @@ static int usb_eth_remove(struct udevice *dev)
 
 static int usb_eth_unbind(struct udevice *dev)
 {
-	usb_gadget_release(0);
+	struct ether_priv *priv = dev_get_priv(dev);
+
+	udc_device_put(priv->udcdev);
 
 	return 0;
 }
Signature · 1 line
2.40.1
#27 lore raw

PATCH 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]

---
 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
Reviewed-by on v1 16/17
#28 lore raw

Re: [PATCH 16/17] dm: usb: udc: Drop legacy udevice handler functions

Quoted 23 lines · 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]

Quoted 4 lines
---
 drivers/usb/gadget/udc/udc-uclass.c | 44 ++++-------------------------
 include/linux/usb/gadget.h          | 17 -----------
 2 files changed, 6 insertions(+), 55 deletions(-)
Quoted 95 lines
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
#29 lore raw

PATCH 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]

---
 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
Reviewed-by Tested-by on v1 17/17
#30 lore raw

Re: [PATCH 17/17] board: usb: Replace legacy usb_gadget_handle_interrupts()

Quoted 38 lines · 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]

---
 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 ++--
Quoted 8 lines
 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(-)

Tested that I could reflash the vim3 bootloader (on mmc2boot0)

Quoted 323 lines
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
#31 lore raw
In reply to Marek Vasut

Hi Marek,

[email protected] wrote on Sat, 19 Aug 2023 16:23:51 +0200:

Quoted 6 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.

Quoted 16 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]
---

Would you mind adding a cover letter to your series? It would be easier for us to (a) know what is the final purpose of the series and (b) have a location where to send global feedback.

Indeed, I did not yet investigate, in particular because every time fastboot is broken I cannot easily test new images without going through a whole recovery step with another image, but it seems like the network over USB is no longer working (not 100% sure about that one, sometimes the network is capricious) and anyway just calling unbind crashes:

=> dm tree
[...]

 misc          0  [ + ]   ti-musb-wrapper       |   |-- usb@47400000
 usb           0  [ + ]   ti-musb-peripheral    |   |   |-- usb@47401000
 ethernet      1  [ + ]   usb_ether             |   |   |   `-- usb_ether
 bootdev       3  [   ]   eth_bootdev           |   |   |       `-- usb_ether.bootdev
 usb           0  [   ]   ti-musb-host          |   |   `-- usb@47401800
=> unbind ethernet 1
data abort
pc : [<9ff9a0e6>]          lr : [<9ff9a0e7>]

reloc pc : [<808350e6>] lr : [<808350e7>]
sp : 9df2f998 ip : 0000001c fp : 00000003
r10: 9df4d800 r9 : 9df44ea0 r8 : 9ffe4a0c
r7 : 9ff82ad9 r6 : 9df4d800 r5 : 84000000 r4 : 9df4cf48
r3 : 9ff9a0e1 r2 : 00000000 r1 : 00000000 r0 : 00000000
Flags: NzCv IRQs off FIQs on Mode SVC_32 (T)

Code: 9ffd b508 f7ec fe63 (f8d0) 00b0 

Resetting CPU ...

Thanks,
Miquèl

Reviewed-by on v1 1/17
#32 lore raw
In reply to Marek Vasut
Quoted 6 lines · Marek Vasut

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.

Quoted 16 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 139 lines
 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
index de8861829c7..b4271b4be9f 100644
@@ -14,6 +14,37 @@
 #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;
+	int ret;
+
+	ret = uclass_get_device_by_seq(UCLASS_USB_GADGET_GENERIC, index, &dev);
+	if (!ret && dev) {
+		*udev = dev;
+		return 0;
+	}
+
+	ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, index, &dev);
+	if (!ret && dev) {
+		*udev = dev;
+		return 0;
+	}
+
+	pr_err("No USB device found\n");
+	return -ENODEV;
+}
+
+int udc_device_put(struct udevice *udev)
+{
+#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
+	return device_remove(udev, DM_REMOVE_NORMAL);
+#else
+	return -ENOSYS;
+#endif
+}
+
 int usb_gadget_initialize(int index)
 {
 	int ret;
@@ -23,13 +54,10 @@ int usb_gadget_initialize(int index)
 		return -EINVAL;
 	if (dev_array[index])
 		return 0;
-	ret = uclass_get_device_by_seq(UCLASS_USB_GADGET_GENERIC, index, &dev);
+	ret = udc_device_get_by_index(index, &dev);
 	if (!dev || ret) {
-		ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, index, &dev);
-		if (!dev || ret) {
-			pr_err("No USB device found\n");
-			return -ENODEV;
-		}
+		pr_err("No USB device found\n");
+		return -ENODEV;
 	}
 	dev_array[index] = dev;
 	return 0;
@@ -42,7 +70,7 @@ int usb_gadget_release(int index)
 	if (index < 0 || index >= ARRAY_SIZE(dev_array))
 		return -EINVAL;
 
-	ret = device_remove(dev_array[index], DM_REMOVE_NORMAL);
+	ret = device_remove(dev_array[index]);
 	if (!ret)
 		dev_array[index] = NULL;
 	return ret;
@@ -57,10 +85,25 @@ int usb_gadget_handle_interrupts(int index)
 		return -EINVAL;
 	return dm_usb_gadget_handle_interrupts(dev_array[index]);
 }
+#else
+/* Backwards hardware compatibility -- switch to DM_USB_GADGET */
+static int legacy_index;
+int udc_device_get_by_index(int index, struct udevice **udev)
+{
+	legacy_index = index;
+	return board_usb_init(index, USB_INIT_DEVICE);
+}
+
+int udc_device_put(struct udevice *udev)
+{
+	return board_usb_cleanup(legacy_index, USB_INIT_DEVICE);
+}
 #endif
 
+#if CONFIG_IS_ENABLED(DM)
 UCLASS_DRIVER(usb_gadget_generic) = {
 	.id		= UCLASS_USB_GADGET_GENERIC,
 	.name		= "usb",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 };
+#endif
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