Skip to contentSkip to conversation

Improvements for the dwc3_generic driver

PATCH New Jean-Jacques Hiblot 3 participants 18 messages May 25, 2018 – May 29, 2018

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

cover Improvements for the dwc3_generic driver

This series aims at bringing improvements to the dwc3_generic driver so that it can be used by most of the platforms using the dwc3 controller.

I tested this on with DRA7 and AM57x platforms for both Peripheral and Host operations. The code to enable DM USB host & dev support for those platforms will be submitted in a separate series.

Enhancements:
- use separate Kconfig option for DM USB Periphal and DM USB Host. This allow platforms to keep their non-DM USB peripheral code and use the DM USB host.
- fixes the bind/probe confusion in dwc3_generic. The probe is done when the USB device is first needed.
- handles PHYs when in the peripheral mode. The code to handle the PHYs is shared with the host side
- handles clock and reset
- bind host controller to the more generic driver 'xhci-dwc3'

Jean-Jacques Hiblot (7):
usb: gadget: Do not call board_usb_xxx() directly in USB gadget
drivers
usb: introduce a separate config option for DM USB device
usb: udc: implement DM versions of
usb_gadget_initialize()/_release()/_handle_interrupt()
dwc3_generic: do not probe the USB device driver when it's bound
dwc3: move phy operation to core.c
dwc3-generic: Handle the PHYs, the clocks and the reset lines
dwc3-generic: Add select_dr_mode operation

 cmd/fastboot.c                    |   4 +-
 cmd/rockusb.c                     |   4 +-
 cmd/thordown.c                    |   4 +-
 cmd/usb_gadget_sdp.c              |   4 +-
 cmd/usb_mass_storage.c            |   4 +-
 common/dfu.c                      |   6 +-
 drivers/usb/Kconfig               |   6 ++
 drivers/usb/dwc3/Kconfig          |   7 +-
 drivers/usb/dwc3/core.c           |  86 +++++++++++++++-
 drivers/usb/dwc3/dwc3-generic.c   | 206 +++++++++++++++++++++++++++++---------
 drivers/usb/dwc3/ep0.c            |   1 -
 drivers/usb/gadget/ether.c        |  38 +------
 drivers/usb/gadget/udc/udc-core.c |  44 +++++++-
 drivers/usb/host/xhci-dwc3.c      |  93 ++---------------
 include/dwc3-uboot.h              |   7 ++
 include/linux/usb/gadget.h        |  18 ++++
 16 files changed, 348 insertions(+), 184 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/7 usb: gadget: Do not call board_usb_xxx() directly in USB gadget drivers

Add 2 functions to wrap the calls to board_usb_init() and board_usb_cleanup().

---

 cmd/fastboot.c             |  4 ++--
 cmd/rockusb.c              |  4 ++--
 cmd/thordown.c             |  4 ++--
 cmd/usb_gadget_sdp.c       |  4 ++--
 cmd/usb_mass_storage.c     |  4 ++--
 common/dfu.c               |  6 +++---
 drivers/usb/gadget/ether.c | 38 +++++---------------------------------
 include/linux/usb/gadget.h | 10 ++++++++++
 8 files changed, 28 insertions(+), 46 deletions(-)
cmd/fastboot.c +2 -2
index a5ec5f4..93f97fd 100644
@@ -24,7 +24,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	usb_controller = argv[1];
 	controller_index = simple_strtoul(usb_controller, NULL, 0);
 
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		pr_err("USB init failed: %d", ret);
 		return CMD_RET_FAILURE;
@@ -55,7 +55,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 exit:
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
 	return ret;
 }
cmd/rockusb.c +2 -2
index 8206643..e0c1480 100644
@@ -33,7 +33,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	dev_index = simple_strtoul(devnum, NULL, 0);
 	rockusb_dev_init(devtype, dev_index);
 
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		printf("USB init failed: %d\n", ret);
 		return CMD_RET_FAILURE;
@@ -62,7 +62,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 exit:
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
 	return ret;
 }
cmd/thordown.c +2 -2
index e297de2..b7866d1 100644
@@ -30,7 +30,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		goto done;
 
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		pr_err("USB init failed: %d", ret);
 		ret = CMD_RET_FAILURE;
@@ -55,7 +55,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 exit:
 	g_dnl_unregister();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_realease(controller_index);
 done:
 	dfu_free_entities();
 
cmd/usb_gadget_sdp.c +2 -2
index ba1f66a..808ed97 100644
@@ -20,7 +20,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	char *usb_controller = argv[1];
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
-	board_usb_init(controller_index, USB_INIT_DEVICE);
+	usb_gadget_initialize(controller_index);
 
 	g_dnl_clear_detach();
 	g_dnl_register("usb_dnl_sdp");
@@ -37,7 +37,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 exit:
 	g_dnl_unregister();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
 	return ret;
 }
cmd/usb_mass_storage.c +2 -2
index 89b9ddf..7c6d0c6 100644
@@ -160,7 +160,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 
 	controller_index = (unsigned int)(simple_strtoul(
 				usb_controller,	NULL, 0));
-	if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
+	if (usb_gadget_initialize(controller_index)) {
 		pr_err("Couldn't init USB controller.");
 		rc = CMD_RET_FAILURE;
 		goto cleanup_ums_init;
@@ -231,7 +231,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 cleanup_register:
 	g_dnl_unregister();
 cleanup_board:
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 cleanup_ums_init:
 	ums_fini();
 
common/dfu.c +3 -3
index 2620d32..44d1484 100644
@@ -23,9 +23,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	bool dfu_reset = false;
 	int ret, i = 0;
 
-	ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(usbctrl_index);
 	if (ret) {
-		pr_err("board usb init failed\n");
+		pr_err("usb_gadget_initialize failed\n");
 		return CMD_RET_FAILURE;
 	}
 	g_dnl_clear_detach();
@@ -84,7 +84,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	}
 exit:
 	g_dnl_unregister();
-	board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE);
+	usb_gadget_release(usbctrl_index);
 
 	if (dfu_reset)
 		do_reset(NULL, 0, 0, NULL);
drivers/usb/gadget/ether.c +5 -33
index 8ab9b9f..1c438c3 100644
@@ -105,9 +105,6 @@ struct eth_dev {
 	struct usb_gadget	*gadget;
 	struct usb_request	*req;		/* for control responses */
 	struct usb_request	*stat_req;	/* for cdc & rndis status */
-#ifdef CONFIG_DM_USB
-	struct udevice		*usb_udev;
-#endif
 
 	u8			config;
 	struct usb_ep		*in_ep, *out_ep, *status_ep;
@@ -2341,40 +2338,17 @@ fail:
 }
 
 /*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_DM_USB
-int dm_usb_init(struct eth_dev *e_dev)
-{
-	struct udevice *dev = NULL;
-	int ret;
-
-	ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
-	if (!dev || ret) {
-		pr_err("No USB device found\n");
-		return -ENODEV;
-	}
-
-	e_dev->usb_udev = dev;
-
-	return ret;
-}
-#endif
-
 static int _usb_eth_init(struct ether_priv *priv)
 {
 	struct eth_dev *dev = &priv->ethdev;
 	struct usb_gadget *gadget;
 	unsigned long ts;
+	int ret;
 	unsigned long timeout = USB_CONNECT_TIMEOUT;
 
-#ifdef CONFIG_DM_USB
-	if (dm_usb_init(dev)) {
-		pr_err("USB ether not found\n");
-		return -ENODEV;
-	}
-#else
-	board_usb_init(0, USB_INIT_DEVICE);
-#endif
+	ret = usb_gadget_initialize(0);
+	if (ret)
+		return ret;
 
 	/* Configure default mac-addresses for the USB ethernet device */
 #ifdef CONFIG_USBNET_DEV_ADDR
@@ -2546,9 +2520,7 @@ void _usb_eth_halt(struct ether_priv *priv)
 	}
 
 	usb_gadget_unregister_driver(&priv->eth_driver);
-#ifndef CONFIG_DM_USB
-	board_usb_cleanup(0, USB_INIT_DEVICE);
-#endif
+	usb_gadget_release(0);
 }
 
 #ifndef CONFIG_DM_ETH
include/linux/usb/gadget.h +10 -0
index b824f13..40ca2d3 100644
@@ -19,6 +19,7 @@
 #define __LINUX_USB_GADGET_H
 
 #include <errno.h>
+#include <usb.h>
 #include <linux/compat.h>
 #include <linux/list.h>
 
@@ -926,4 +927,13 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
 extern int usb_gadget_handle_interrupts(int index);
 
+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	/* __LINUX_USB_GADGET_H */
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/7 usb: gadget: Do not call board_usb_xxx() directly in USB gadget drivers

Quoted 2 lines · Jean-Jacques Hiblot

Add 2 functions to wrap the calls to board_usb_init() and board_usb_cleanup().

Here should be written why you need this change.

M

Quoted 246 lines

---

 cmd/fastboot.c             |  4 ++--
 cmd/rockusb.c              |  4 ++--
 cmd/thordown.c             |  4 ++--
 cmd/usb_gadget_sdp.c       |  4 ++--
 cmd/usb_mass_storage.c     |  4 ++--
 common/dfu.c               |  6 +++---
 drivers/usb/gadget/ether.c | 38 +++++---------------------------------
 include/linux/usb/gadget.h | 10 ++++++++++
 8 files changed, 28 insertions(+), 46 deletions(-)
cmd/fastboot.c +2 -2
index a5ec5f4..93f97fd 100644
@@ -24,7 +24,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	usb_controller = argv[1];
 	controller_index = simple_strtoul(usb_controller, NULL, 0);
 
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		pr_err("USB init failed: %d", ret);
 		return CMD_RET_FAILURE;
@@ -55,7 +55,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 exit:
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
 	return ret;
 }
cmd/rockusb.c +2 -2
index 8206643..e0c1480 100644
@@ -33,7 +33,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	dev_index = simple_strtoul(devnum, NULL, 0);
 	rockusb_dev_init(devtype, dev_index);
 
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		printf("USB init failed: %d\n", ret);
 		return CMD_RET_FAILURE;
@@ -62,7 +62,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 exit:
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
 	return ret;
 }
cmd/thordown.c +2 -2
index e297de2..b7866d1 100644
@@ -30,7 +30,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		goto done;
 
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
 	if (ret) {
 		pr_err("USB init failed: %d", ret);
 		ret = CMD_RET_FAILURE;
@@ -55,7 +55,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 exit:
 	g_dnl_unregister();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_realease(controller_index);
 done:
 	dfu_free_entities();
 
cmd/usb_gadget_sdp.c +2 -2
index ba1f66a..808ed97 100644
@@ -20,7 +20,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	char *usb_controller = argv[1];
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
-	board_usb_init(controller_index, USB_INIT_DEVICE);
+	usb_gadget_initialize(controller_index);
 
 	g_dnl_clear_detach();
 	g_dnl_register("usb_dnl_sdp");
@@ -37,7 +37,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 exit:
 	g_dnl_unregister();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
 	return ret;
 }
cmd/usb_mass_storage.c +2 -2
index 89b9ddf..7c6d0c6 100644
@@ -160,7 +160,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 
 	controller_index = (unsigned int)(simple_strtoul(
 				usb_controller,	NULL, 0));
-	if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
+	if (usb_gadget_initialize(controller_index)) {
 		pr_err("Couldn't init USB controller.");
 		rc = CMD_RET_FAILURE;
 		goto cleanup_ums_init;
@@ -231,7 +231,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 cleanup_register:
 	g_dnl_unregister();
 cleanup_board:
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 cleanup_ums_init:
 	ums_fini();
 
common/dfu.c +3 -3
index 2620d32..44d1484 100644
@@ -23,9 +23,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	bool dfu_reset = false;
 	int ret, i = 0;
 
-	ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(usbctrl_index);
 	if (ret) {
-		pr_err("board usb init failed\n");
+		pr_err("usb_gadget_initialize failed\n");
 		return CMD_RET_FAILURE;
 	}
 	g_dnl_clear_detach();
@@ -84,7 +84,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	}
 exit:
 	g_dnl_unregister();
-	board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE);
+	usb_gadget_release(usbctrl_index);
 
 	if (dfu_reset)
 		do_reset(NULL, 0, 0, NULL);
drivers/usb/gadget/ether.c +5 -33
index 8ab9b9f..1c438c3 100644
@@ -105,9 +105,6 @@ struct eth_dev {
 	struct usb_gadget	*gadget;
 	struct usb_request	*req;		/* for control responses */
 	struct usb_request	*stat_req;	/* for cdc & rndis status */
-#ifdef CONFIG_DM_USB
-	struct udevice		*usb_udev;
-#endif
 
 	u8			config;
 	struct usb_ep		*in_ep, *out_ep, *status_ep;
@@ -2341,40 +2338,17 @@ fail:
 }
 
 /*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_DM_USB
-int dm_usb_init(struct eth_dev *e_dev)
-{
-	struct udevice *dev = NULL;
-	int ret;
-
-	ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
-	if (!dev || ret) {
-		pr_err("No USB device found\n");
-		return -ENODEV;
-	}
-
-	e_dev->usb_udev = dev;
-
-	return ret;
-}
-#endif
-
 static int _usb_eth_init(struct ether_priv *priv)
 {
 	struct eth_dev *dev = &priv->ethdev;
 	struct usb_gadget *gadget;
 	unsigned long ts;
+	int ret;
 	unsigned long timeout = USB_CONNECT_TIMEOUT;
 
-#ifdef CONFIG_DM_USB
-	if (dm_usb_init(dev)) {
-		pr_err("USB ether not found\n");
-		return -ENODEV;
-	}
-#else
-	board_usb_init(0, USB_INIT_DEVICE);
-#endif
+	ret = usb_gadget_initialize(0);
+	if (ret)
+		return ret;
 
 	/* Configure default mac-addresses for the USB ethernet device */
 #ifdef CONFIG_USBNET_DEV_ADDR
@@ -2546,9 +2520,7 @@ void _usb_eth_halt(struct ether_priv *priv)
 	}
 
 	usb_gadget_unregister_driver(&priv->eth_driver);
-#ifndef CONFIG_DM_USB
-	board_usb_cleanup(0, USB_INIT_DEVICE);
-#endif
+	usb_gadget_release(0);
 }
 
 #ifndef CONFIG_DM_ETH
include/linux/usb/gadget.h +10 -0
index b824f13..40ca2d3 100644
@@ -19,6 +19,7 @@
 #define __LINUX_USB_GADGET_H
 
 #include <errno.h>
+#include <usb.h>
 #include <linux/compat.h>
 #include <linux/list.h>
 
@@ -926,4 +927,13 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
 extern int usb_gadget_handle_interrupts(int index);
 
+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	/* __LINUX_USB_GADGET_H */
#3 lore raw

PATCH 1/7 usb: gadget: Do not call board_usb_xxx() directly in USB gadget drivers

Quoted 6 lines · Michal Simek
Quoted 2 lines · Jean-Jacques Hiblot

Add 2 functions to wrap the calls to board_usb_init() and board_usb_cleanup().

Here should be written why you need this change.

M

I'll update the commit log.
It's a preparatory work for DM support for UDC drivers.

Quoted 247 lines
Quoted 246 lines

---

  cmd/fastboot.c             |  4 ++--
  cmd/rockusb.c              |  4 ++--
  cmd/thordown.c             |  4 ++--
  cmd/usb_gadget_sdp.c       |  4 ++--
  cmd/usb_mass_storage.c     |  4 ++--
  common/dfu.c               |  6 +++---
  drivers/usb/gadget/ether.c | 38 +++++---------------------------------
  include/linux/usb/gadget.h | 10 ++++++++++
  8 files changed, 28 insertions(+), 46 deletions(-)
cmd/fastboot.c +2 -2
index a5ec5f4..93f97fd 100644
@@ -24,7 +24,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  	usb_controller = argv[1];
  	controller_index = simple_strtoul(usb_controller, NULL, 0);
 
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
  	if (ret) {
  		pr_err("USB init failed: %d", ret);
  		return CMD_RET_FAILURE;
@@ -55,7 +55,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  exit:
  	g_dnl_unregister();
  	g_dnl_clear_detach();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
  	return ret;
  }
cmd/rockusb.c +2 -2
index 8206643..e0c1480 100644
@@ -33,7 +33,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  	dev_index = simple_strtoul(devnum, NULL, 0);
  	rockusb_dev_init(devtype, dev_index);
 
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
  	if (ret) {
  		printf("USB init failed: %d\n", ret);
  		return CMD_RET_FAILURE;
@@ -62,7 +62,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  exit:
  	g_dnl_unregister();
  	g_dnl_clear_detach();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
  	return ret;
  }
cmd/thordown.c +2 -2
index e297de2..b7866d1 100644
@@ -30,7 +30,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  		goto done;
 
  	int controller_index = simple_strtoul(usb_controller, NULL, 0);
-	ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(controller_index);
  	if (ret) {
  		pr_err("USB init failed: %d", ret);
  		ret = CMD_RET_FAILURE;
@@ -55,7 +55,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
  exit:
  	g_dnl_unregister();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_realease(controller_index);
  done:
  	dfu_free_entities();
 
cmd/usb_gadget_sdp.c +2 -2
index ba1f66a..808ed97 100644
@@ -20,7 +20,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
  	char *usb_controller = argv[1];
  	int controller_index = simple_strtoul(usb_controller, NULL, 0);
-	board_usb_init(controller_index, USB_INIT_DEVICE);
+	usb_gadget_initialize(controller_index);
 
  	g_dnl_clear_detach();
  	g_dnl_register("usb_dnl_sdp");
@@ -37,7 +37,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
  exit:
  	g_dnl_unregister();
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
 
  	return ret;
  }
cmd/usb_mass_storage.c +2 -2
index 89b9ddf..7c6d0c6 100644
@@ -160,7 +160,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 
  	controller_index = (unsigned int)(simple_strtoul(
  				usb_controller,	NULL, 0));
-	if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
+	if (usb_gadget_initialize(controller_index)) {
  		pr_err("Couldn't init USB controller.");
  		rc = CMD_RET_FAILURE;
  		goto cleanup_ums_init;
@@ -231,7 +231,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
  cleanup_register:
  	g_dnl_unregister();
  cleanup_board:
-	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+	usb_gadget_release(controller_index);
  cleanup_ums_init:
  	ums_fini();
 
common/dfu.c +3 -3
index 2620d32..44d1484 100644
@@ -23,9 +23,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
  	bool dfu_reset = false;
  	int ret, i = 0;
 
-	ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE);
+	ret = usb_gadget_initialize(usbctrl_index);
  	if (ret) {
-		pr_err("board usb init failed\n");
+		pr_err("usb_gadget_initialize failed\n");
  		return CMD_RET_FAILURE;
  	}
  	g_dnl_clear_detach();
@@ -84,7 +84,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
  	}
  exit:
  	g_dnl_unregister();
-	board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE);
+	usb_gadget_release(usbctrl_index);
 
  	if (dfu_reset)
  		do_reset(NULL, 0, 0, NULL);
drivers/usb/gadget/ether.c +5 -33
index 8ab9b9f..1c438c3 100644
@@ -105,9 +105,6 @@ struct eth_dev {
  	struct usb_gadget	*gadget;
  	struct usb_request	*req;		/* for control responses */
  	struct usb_request	*stat_req;	/* for cdc & rndis status */
-#ifdef CONFIG_DM_USB
-	struct udevice		*usb_udev;
-#endif
 
  	u8			config;
  	struct usb_ep		*in_ep, *out_ep, *status_ep;
@@ -2341,40 +2338,17 @@ fail:
  }
 
  /*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_DM_USB
-int dm_usb_init(struct eth_dev *e_dev)
-{
-	struct udevice *dev = NULL;
-	int ret;
-
-	ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
-	if (!dev || ret) {
-		pr_err("No USB device found\n");
-		return -ENODEV;
-	}
-
-	e_dev->usb_udev = dev;
-
-	return ret;
-}
-#endif
-
  static int _usb_eth_init(struct ether_priv *priv)
  {
  	struct eth_dev *dev = &priv->ethdev;
  	struct usb_gadget *gadget;
  	unsigned long ts;
+	int ret;
  	unsigned long timeout = USB_CONNECT_TIMEOUT;
 
-#ifdef CONFIG_DM_USB
-	if (dm_usb_init(dev)) {
-		pr_err("USB ether not found\n");
-		return -ENODEV;
-	}
-#else
-	board_usb_init(0, USB_INIT_DEVICE);
-#endif
+	ret = usb_gadget_initialize(0);
+	if (ret)
+		return ret;
 
  	/* Configure default mac-addresses for the USB ethernet device */
  #ifdef CONFIG_USBNET_DEV_ADDR
@@ -2546,9 +2520,7 @@ void _usb_eth_halt(struct ether_priv *priv)
  	}
 
  	usb_gadget_unregister_driver(&priv->eth_driver);
-#ifndef CONFIG_DM_USB
-	board_usb_cleanup(0, USB_INIT_DEVICE);
-#endif
+	usb_gadget_release(0);
  }
 
  #ifndef CONFIG_DM_ETH
include/linux/usb/gadget.h +10 -0
index b824f13..40ca2d3 100644
@@ -19,6 +19,7 @@
  #define __LINUX_USB_GADGET_H
 
  #include <errno.h>
+#include <usb.h>
  #include <linux/compat.h>
  #include <linux/list.h>
 
@@ -926,4 +927,13 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
  extern int usb_gadget_handle_interrupts(int index);
 
+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	/* __LINUX_USB_GADGET_H */
#4 lore raw

PATCH 2/7 usb: introduce a separate config option for DM USB device

In reply to Jean-Jacques Hiblot

Using CONFIG_DM_USB for this purpose prevents using DM_USB for host and not for device.

---

 drivers/usb/Kconfig             | 6 ++++++
 drivers/usb/dwc3/core.c         | 2 +-
 drivers/usb/dwc3/dwc3-generic.c | 4 +++-
 3 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/Kconfig +6 -0
index 4fbe172..3587ba4 100644
@@ -47,6 +47,12 @@ config DM_USB
 	  declared with the U_BOOT_USB_DEVICE() macro and will be
 	  automatically probed when found on the bus.
 
+config DM_USB_DEV
+	bool "Enable driver model for USB (Peripheral mode)"
+	depends on DM_USB
+	help
+	  Enable driver model for USB (Peripheral mode).
+
 source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
drivers/usb/dwc3/core.c +1 -1
index 1ab5cee..d5ee6d9 100644
@@ -789,7 +789,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
 
-#ifdef CONFIG_DM_USB
+#ifdef CONFIG_DM_USB_DEV
 
 int dwc3_init(struct dwc3 *dwc)
 {
drivers/usb/dwc3/dwc3-generic.c +3 -1
index ca63eac..2c1e696 100644
@@ -21,7 +21,7 @@
 #include "gadget.h"
 #include "linux-compat.h"
 
-DECLARE_GLOBAL_DATA_PTR;
+#ifdef CONFIG_DM_USB_DEV
 
 int usb_gadget_handle_interrupts(int index)
 {
@@ -98,6 +98,8 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = {
 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
 };
 
+#endif
+
 static int dwc3_generic_bind(struct udevice *parent)
 {
 	const void *fdt = gd->fdt_blob;
Signature · 1 line
2.7.4
#5 lore raw

PATCH 2/7 usb: introduce a separate config option for DM USB device

Quoted 46 lines · Jean-Jacques Hiblot

Using CONFIG_DM_USB for this purpose prevents using DM_USB for host and not for device.

---

 drivers/usb/Kconfig             | 6 ++++++
 drivers/usb/dwc3/core.c         | 2 +-
 drivers/usb/dwc3/dwc3-generic.c | 4 +++-
 3 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/Kconfig +6 -0
index 4fbe172..3587ba4 100644
@@ -47,6 +47,12 @@ config DM_USB
 	  declared with the U_BOOT_USB_DEVICE() macro and will be
 	  automatically probed when found on the bus.
 
+config DM_USB_DEV
+	bool "Enable driver model for USB (Peripheral mode)"
+	depends on DM_USB
+	help
+	  Enable driver model for USB (Peripheral mode).
+
 source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
drivers/usb/dwc3/core.c +1 -1
index 1ab5cee..d5ee6d9 100644
@@ -789,7 +789,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
 
-#ifdef CONFIG_DM_USB
+#ifdef CONFIG_DM_USB_DEV
 
 int dwc3_init(struct dwc3 *dwc)
 {
drivers/usb/dwc3/dwc3-generic.c +0 -0
index ca63eac..2c1e696 100644

drivers/usb/dwc3/dwc3-generic.c line 24

Quoted 4 lines
drivers/usb/dwc3/dwc3-generic.c +0 -1
@@ -21,7 +21,7 @@
 #include "gadget.h"
 #include "linux-compat.h"
 
-DECLARE_GLOBAL_DATA_PTR;

Removing this looks weird. I would expect that there will be new error/warning when you compile it because gd is used in bind function.

M

Quoted 14 lines
drivers/usb/dwc3/dwc3-generic.c +3 -0
+#ifdef CONFIG_DM_USB_DEV
 
 int usb_gadget_handle_interrupts(int index)
 {
@@ -98,6 +98,8 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = {
 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
 };
 
+#endif
+
 static int dwc3_generic_bind(struct udevice *parent)
 {
 	const void *fdt = gd->fdt_blob;
#6 lore raw

PATCH 2/7 usb: introduce a separate config option for DM USB device

Quoted 50 lines · Michal Simek
Quoted 49 lines · Jean-Jacques Hiblot

Using CONFIG_DM_USB for this purpose prevents using DM_USB for host and not for device.

---

  drivers/usb/Kconfig             | 6 ++++++
  drivers/usb/dwc3/core.c         | 2 +-
  drivers/usb/dwc3/dwc3-generic.c | 4 +++-
  3 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/Kconfig +6 -0
index 4fbe172..3587ba4 100644
@@ -47,6 +47,12 @@ config DM_USB
  	  declared with the U_BOOT_USB_DEVICE() macro and will be
  	  automatically probed when found on the bus.
 
+config DM_USB_DEV
+	bool "Enable driver model for USB (Peripheral mode)"
+	depends on DM_USB
+	help
+	  Enable driver model for USB (Peripheral mode).
+
  source "drivers/usb/host/Kconfig"
 
  source "drivers/usb/dwc3/Kconfig"
drivers/usb/dwc3/core.c +1 -1
index 1ab5cee..d5ee6d9 100644
@@ -789,7 +789,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");
  MODULE_LICENSE("GPL v2");
  MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
 
-#ifdef CONFIG_DM_USB
+#ifdef CONFIG_DM_USB_DEV
 
  int dwc3_init(struct dwc3 *dwc)
  {
drivers/usb/dwc3/dwc3-generic.c +0 -0
index ca63eac..2c1e696 100644
@@ -21,7 +21,7 @@
  #include "gadget.h"
  #include "linux-compat.h"
 
Quoted 3 lines

drivers/usb/dwc3/dwc3-generic.c line 24

Quoted 1 line
drivers/usb/dwc3/dwc3-generic.c +0 -1
-DECLARE_GLOBAL_DATA_PTR;

Removing this looks weird. I would expect that there will be new error/warning when you compile it because gd is used in bind function.

It must be declared somewhere else in the included headers, there is no complain from the compiler.

Quoted 18 lines

M

Quoted 14 lines
drivers/usb/dwc3/dwc3-generic.c +3 -0
+#ifdef CONFIG_DM_USB_DEV
 
  int usb_gadget_handle_interrupts(int index)
  {
@@ -98,6 +98,8 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = {
  	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
  };
 
+#endif
+
  static int dwc3_generic_bind(struct udevice *parent)
  {
  	const void *fdt = gd->fdt_blob;
#7 lore raw

PATCH 3/7 usb: udc: implement DM versions of usb_gadget_initialize()/_release()/_handle_interrupt()

In reply to Jean-Jacques Hiblot

When DM_USB_DEV the platform code for the USB device must be replaced by calls to a USB device driver.

usb_gadget_initialize() probes the USB device driver. usb_gadget_release() removes the USB device driver.

---

 drivers/usb/dwc3/dwc3-generic.c   | 14 ++-----------
 drivers/usb/gadget/udc/udc-core.c | 44 ++++++++++++++++++++++++++++++++++++++-
 include/linux/usb/gadget.h        |  8 +++++++
 3 files changed, 53 insertions(+), 13 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +2 -12
index 2c1e696..43e97be 100644
@@ -23,19 +23,9 @@
 
 #ifdef CONFIG_DM_USB_DEV
 
-int usb_gadget_handle_interrupts(int index)
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
-	struct dwc3 *priv;
-	struct udevice *dev;
-	int ret;
-
-	ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
-	if (!dev || ret) {
-		pr_err("No USB device found\n");
-		return -ENODEV;
-	}
-
-	priv = dev_get_priv(dev);
+	struct dwc3 *priv = dev_get_priv(dev);
 
 	dwc3_gadget_uboot_handle_interrupt(priv);
 
drivers/usb/gadget/udc/udc-core.c +43 -1

53 lines not on this page · raw message

include/linux/usb/gadget.h +8 -0
index 40ca2d3..a094e31 100644
@@ -927,6 +927,12 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
 extern int usb_gadget_handle_interrupts(int index);
 
+#ifdef CONFIG_DM_USB_DEV
+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);
@@ -936,4 +942,6 @@ 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.7.4
#8 lore raw

PATCH 3/7 usb: udc: implement DM versions of usb_gadget_initialize()/_release()/_handle_interrupt()

Quoted 7 lines · On Fri, 25 May 2018 11:32:38 +0200 Jean-Jacques Hiblot <[email protected]> wrote:

When DM_USB_DEV the platform code for the USB device must be replaced by calls to a USB device driver.

usb_gadget_initialize() probes the USB device driver. usb_gadget_release() removes the USB device driver.

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180528/05643238/attachment.sig>

#9 lore raw

PATCH 4/7 dwc3_generic: do not probe the USB device driver when it's bound

In reply to Jean-Jacques Hiblot

The driver will be probed when usb_gadget_initialize() is called.

---

 drivers/usb/dwc3/dwc3-generic.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -7
index 43e97be..3ec0c0e 100644
@@ -71,21 +71,14 @@ static int dwc3_generic_peripheral_ofdata_to_platdata(struct udevice *dev)
 	return 0;
 }
 
-static int dwc3_generic_peripheral_bind(struct udevice *dev)
-{
-	return device_probe(dev);
-}
-
 U_BOOT_DRIVER(dwc3_generic_peripheral) = {
 	.name	= "dwc3-generic-peripheral",
 	.id	= UCLASS_USB_DEV_GENERIC,
 	.ofdata_to_platdata = dwc3_generic_peripheral_ofdata_to_platdata,
 	.probe = dwc3_generic_peripheral_probe,
 	.remove = dwc3_generic_peripheral_remove,
-	.bind = dwc3_generic_peripheral_bind,
 	.platdata_auto_alloc_size = sizeof(struct usb_platdata),
 	.priv_auto_alloc_size = sizeof(struct dwc3),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
 };
 
 #endif
Signature · 1 line
2.7.4
#10 lore raw

PATCH 5/7 dwc3: move phy operation to core.c

In reply to Jean-Jacques Hiblot

Those operations can be used for peripheral operation as well as host operation.

---

 drivers/usb/dwc3/core.c      | 88 ++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/dwc3/ep0.c       |  1 -
 drivers/usb/host/xhci-dwc3.c | 93 +++-----------------------------------------
 include/dwc3-uboot.h         |  7 ++++
 4 files changed, 99 insertions(+), 90 deletions(-)
drivers/usb/dwc3/core.c +86 -2
index d5ee6d9..538c603 100644
@@ -19,7 +19,7 @@
 #include <asm/dma-mapping.h>
 #include <linux/ioport.h>
 #include <dm.h>
-
+#include <generic-phy.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 
@@ -789,8 +789,92 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
 
-#ifdef CONFIG_DM_USB_DEV
+#ifdef CONFIG_DM_USB
+int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys)
+{
+	int i, ret, count;
+	struct phy *usb_phys;
+
+	/* Return if no phy declared */
+	if (!dev_read_prop(dev, "phys", NULL))
+		return 0;
+
+	count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
+	if (count <= 0)
+		return count;
+
+	usb_phys = devm_kcalloc(dev, count, sizeof(struct phy),
+				GFP_KERNEL);
+	if (!usb_phys)
+		return -ENOMEM;
+
+	for (i = 0; i < count; i++) {
+		ret = generic_phy_get_by_index(dev, i, &usb_phys[i]);
+		if (ret && ret != -ENOENT) {
+			pr_err("Failed to get USB PHY%d for %s\n",
+			       i, dev->name);
+			return ret;
+		}
+	}
+
+	for (i = 0; i < count; i++) {
+		ret = generic_phy_init(&usb_phys[i]);
+		if (ret) {
+			pr_err("Can't init USB PHY%d for %s\n",
+			       i, dev->name);
+			goto phys_init_err;
+		}
+	}
+
+	for (i = 0; i < count; i++) {
+		ret = generic_phy_power_on(&usb_phys[i]);
+		if (ret) {
+			pr_err("Can't power USB PHY%d for %s\n",
+			       i, dev->name);
+			goto phys_poweron_err;
+		}
+	}
+
+	*num_phys =  count;
+	return 0;
 
+phys_poweron_err:
+	for (i = count - 1; i >= 0; i--)
+		generic_phy_power_off(&usb_phys[i]);
+
+	for (i = 0; i < count; i++)
+		generic_phy_exit(&usb_phys[i]);
+
+	return ret;
+
+phys_init_err:
+	for (; i >= 0; i--)
+		generic_phy_exit(&usb_phys[i]);
+
+	return ret;
+}
+
+int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys)
+{
+	int i, ret;
+
+	for (i = 0; i < num_phys; i++) {
+		if (!generic_phy_valid(&usb_phys[i]))
+			continue;
+
+		ret = generic_phy_power_off(&usb_phys[i]);
+		ret |= generic_phy_exit(&usb_phys[i]);
+		if (ret) {
+			pr_err("Can't shutdown USB PHY%d for %s\n",
+			       i, dev->name);
+		}
+	}
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_DM_USB_DEV
 int dwc3_init(struct dwc3 *dwc)
 {
 	int ret;
drivers/usb/dwc3/ep0.c +0 -1
index 4f68887..433e5f6 100644
@@ -19,7 +19,6 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/composite.h>
-
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
drivers/usb/host/xhci-dwc3.c +6 -87

123 lines not on this page · raw message

include/dwc3-uboot.h +7 -0
index 228ab3b..a2da081 100644
@@ -38,4 +38,11 @@ struct dwc3_device {
 int dwc3_uboot_init(struct dwc3_device *dev);
 void dwc3_uboot_exit(int index);
 void dwc3_uboot_handle_interrupt(int index);
+
+#ifdef CONFIG_DM_USB
+struct phy;
+int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys);
+int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys);
+#endif
+
 #endif /* __DWC3_UBOOT_H_ */
Signature · 1 line
2.7.4
#11 lore raw

PATCH 6/7 dwc3-generic: Handle the PHYs, the clocks and the reset lines

In reply to Jean-Jacques Hiblot

This make the driver more generic. At this point this driver can replace the dwc3-of-simple implementation.
Make the description in the Kconfig more generic too.

---

 drivers/usb/dwc3/Kconfig        |   7 +-
 drivers/usb/dwc3/dwc3-generic.c | 159 +++++++++++++++++++++++++++++++++-------
 2 files changed, 136 insertions(+), 30 deletions(-)
drivers/usb/dwc3/Kconfig +4 -3
index 943b763..bbd8105 100644
@@ -38,10 +38,11 @@ config USB_DWC3_OMAP
 	  Say 'Y' here if you have one such device
 
 config USB_DWC3_GENERIC
-	bool "Xilinx ZynqMP and similar Platforms"
-	depends on DM_USB && USB_DWC3
+	bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)"
+	depends on DM_USB && USB_DWC3 && MISC
 	help
-	  Some platforms can reuse this DWC3 generic implementation.
+	  Select this for Xilinx ZynqMP and similar Platforms.
+	  This wrapper supports Host and Peripheral operation modes.
 
 config USB_DWC3_UNIPHIER
 	bool "DesignWare USB3 Host Support on UniPhier Platforms"
drivers/usb/dwc3/dwc3-generic.c +132 -27

246 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

PATCH 7/7 dwc3-generic: Add select_dr_mode operation

In reply to Jean-Jacques Hiblot

The select_dr_mode operation is executed when the glue driver is probed. The role of this optional function is to configure the operating mode of the controller at the glue level.

---

 drivers/usb/dwc3/dwc3-generic.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/usb/dwc3/dwc3-generic.c +26 -0
index 977f310..9227501 100644
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <asm-generic/io.h>
 #include <dm.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
@@ -110,6 +111,12 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = {
 struct dwc3_glue_data {
 	struct clk_bulk		clks;
 	struct reset_ctl_bulk	resets;
+	fdt_addr_t regs;
+};
+
+struct dwc3_glue_ops {
+	void (*select_dr_mode)(struct udevice *dev, int index,
+			       enum usb_dr_mode mode);
 };
 
 static int dwc3_glue_bind(struct udevice *parent)
@@ -205,9 +212,14 @@ static int dwc3_glue_clk_init(struct udevice *dev,
 
 static int dwc3_glue_probe(struct udevice *dev)
 {
+	struct dwc3_glue_ops *ops = (struct dwc3_glue_ops *)dev_get_driver_data(dev);
 	struct dwc3_glue_data *glue = dev_get_platdata(dev);
+	struct udevice *child = NULL;
+	int index = 0;
 	int ret;
 
+	glue->regs = dev_read_addr(dev);
+
 	ret = dwc3_glue_clk_init(dev, glue);
 	if (ret)
 		return ret;
@@ -216,6 +228,20 @@ static int dwc3_glue_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	ret = device_find_first_child(dev, &child);
+	if (ret)
+		return ret;
+
+	while (child) {
+		enum usb_dr_mode dr_mode;
+
+		dr_mode = usb_get_dr_mode(dev_of_offset(child));
+		device_find_next_child(&child);
+		if (ops && ops->select_dr_mode)
+			ops->select_dr_mode(dev, index, dr_mode);
+		index++;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.7.4
#13 lore raw

cover Improvements for the dwc3_generic driver

In reply to Jean-Jacques Hiblot

Hi Jean,

Quoted 7 lines · Jean-Jacques Hiblot

This series aims at bringing improvements to the dwc3_generic driver so that it can be used by most of the platforms using the dwc3 controller.

I tested this on with DRA7 and AM57x platforms for both Peripheral and Host operations. The code to enable DM USB host & dev support for those platforms will be submitted in a separate series.

Quoted 10 lines

Enhancements:
- use separate Kconfig option for DM USB Periphal and DM USB Host. This allow platforms to keep their non-DM USB peripheral code and use the DM USB host.
- fixes the bind/probe confusion in dwc3_generic. The probe is done when the USB device is first needed.
- handles PHYs when in the peripheral mode. The code to handle the PHYs is shared with the host side
- handles clock and reset
- bind host controller to the more generic driver 'xhci-dwc3'

I see two series which were sent recently without any description of dependencies.
Will be good to push these patches somewhere to git and send a link that I can easily test.

Thanks,
Michal

Quoted 32 lines

Jean-Jacques Hiblot (7):
usb: gadget: Do not call board_usb_xxx() directly in USB gadget
drivers
usb: introduce a separate config option for DM USB device
usb: udc: implement DM versions of
usb_gadget_initialize()/_release()/_handle_interrupt()
dwc3_generic: do not probe the USB device driver when it's bound
dwc3: move phy operation to core.c
dwc3-generic: Handle the PHYs, the clocks and the reset lines
dwc3-generic: Add select_dr_mode operation

 cmd/fastboot.c                    |   4 +-
 cmd/rockusb.c                     |   4 +-
 cmd/thordown.c                    |   4 +-
 cmd/usb_gadget_sdp.c              |   4 +-
 cmd/usb_mass_storage.c            |   4 +-
 common/dfu.c                      |   6 +-
 drivers/usb/Kconfig               |   6 ++
 drivers/usb/dwc3/Kconfig          |   7 +-
 drivers/usb/dwc3/core.c           |  86 +++++++++++++++-
 drivers/usb/dwc3/dwc3-generic.c   | 206 +++++++++++++++++++++++++++++---------
 drivers/usb/dwc3/ep0.c            |   1 -
 drivers/usb/gadget/ether.c        |  38 +------
 drivers/usb/gadget/udc/udc-core.c |  44 +++++++-
 drivers/usb/host/xhci-dwc3.c      |  93 ++---------------
 include/dwc3-uboot.h              |   7 ++
 include/linux/usb/gadget.h        |  18 ++++
 16 files changed, 348 insertions(+), 184 deletions(-)
#14 lore raw

cover Improvements for the dwc3_generic driver

Hi Michal

Quoted 20 lines · Michal Simek

Hi Jean,

Quoted 7 lines · Jean-Jacques Hiblot

This series aims at bringing improvements to the dwc3_generic driver so that it can be used by most of the platforms using the dwc3 controller.

I tested this on with DRA7 and AM57x platforms for both Peripheral and Host operations. The code to enable DM USB host & dev support for those platforms will be submitted in a separate series.

Quoted 10 lines

Enhancements:
- use separate Kconfig option for DM USB Periphal and DM USB Host. This allow platforms to keep their non-DM USB peripheral code and use the DM USB host.
- fixes the bind/probe confusion in dwc3_generic. The probe is done when the USB device is first needed.
- handles PHYs when in the peripheral mode. The code to handle the PHYs is shared with the host side
- handles clock and reset
- bind host controller to the more generic driver 'xhci-dwc3'

Quoted 2 lines

I see two series which were sent recently without any description of dependencies.

Right I forgot. This series applies on to of the master branch of the USB tree

Quoted 2 lines

Will be good to push these patches somewhere to git and send a link that I can easily test.

I pushed all on github : https://github.com/jjhiblot/u-boot

JJ

Quoted 36 lines

Thanks,
Michal

Quoted 31 lines

Jean-Jacques Hiblot (7):
usb: gadget: Do not call board_usb_xxx() directly in USB gadget
drivers
usb: introduce a separate config option for DM USB device
usb: udc: implement DM versions of
usb_gadget_initialize()/_release()/_handle_interrupt()
dwc3_generic: do not probe the USB device driver when it's bound
dwc3: move phy operation to core.c
dwc3-generic: Handle the PHYs, the clocks and the reset lines
dwc3-generic: Add select_dr_mode operation

  cmd/fastboot.c                    |   4 +-
  cmd/rockusb.c                     |   4 +-
  cmd/thordown.c                    |   4 +-
  cmd/usb_gadget_sdp.c              |   4 +-
  cmd/usb_mass_storage.c            |   4 +-
  common/dfu.c                      |   6 +-
  drivers/usb/Kconfig               |   6 ++
  drivers/usb/dwc3/Kconfig          |   7 +-
  drivers/usb/dwc3/core.c           |  86 +++++++++++++++-
  drivers/usb/dwc3/dwc3-generic.c   | 206 +++++++++++++++++++++++++++++---------
  drivers/usb/dwc3/ep0.c            |   1 -
  drivers/usb/gadget/ether.c        |  38 +------
  drivers/usb/gadget/udc/udc-core.c |  44 +++++++-
  drivers/usb/host/xhci-dwc3.c      |  93 ++---------------
  include/dwc3-uboot.h              |   7 ++
  include/linux/usb/gadget.h        |  18 ++++
  16 files changed, 348 insertions(+), 184 deletions(-)
#15 lore raw

cover Improvements for the dwc3_generic driver

Hi,

Quoted 26 lines · Jean-Jacques Hiblot

Hi Michal

Quoted 22 lines · Michal Simek

Hi Jean,

Quoted 19 lines · Jean-Jacques Hiblot

This series aims at bringing improvements to the dwc3_generic driver so that it can be used by most of the platforms using the dwc3 controller.

I tested this on with DRA7 and AM57x platforms for both Peripheral and Host
operations. The code to enable DM USB host & dev support for those platforms will be submitted in a separate series.

Enhancements:
- use separate Kconfig option for DM USB Periphal and DM USB Host. This allow platforms to keep their non-DM USB peripheral code and use the DM USB host.
- fixes the bind/probe confusion in dwc3_generic. The probe is done when the USB device is first needed.
- handles PHYs when in the peripheral mode. The code to handle the PHYs is
shared with the host side
- handles clock and reset
- bind host controller to the more generic driver 'xhci-dwc3'

Quoted 7 lines
Quoted 2 lines

I see two series which were sent recently without any description of dependencies.

Right I forgot. This series applies on to of the master branch of the USB tree

Quoted 2 lines

Will be good to push these patches somewhere to git and send a link that I can easily test.

I pushed all on github : https://github.com/jjhiblot/u-boot

I didn't build all patches to identify which one is introducing the issue. But look below at issues and please fix them. Then I will test.

Thanks,
Michal

[u-boot](dwc3)$ nice -n 19 ./tools/buildman/buildman -b dwc3 zynqmp -o ../tmp/ -C -I -c 1 -sSed
boards.cfg is up to date. Nothing to do.
Summary of 1 commit for 20 boards (8 threads, 1 job per thread) 01: board: ti: am57xx: remove USB platform code
aarch64: + xilinx_zynqmp_zc1751_xm016_dc2
xilinx_zynqmp_zcu102_revA xilinx_zynqmp_zcu100_revC xilinx_zynqmp_zcu104_revA xilinx_zynqmp_zc1751_xm017_dc3 xilinx_zynqmp_zcu102_revB xilinx_zynqmp_zcu106_revA xilinx_zynqmp_zc1751_xm015_dc1 xilinx_zynqmp_zcu111_revA xilinx_zynqmp_zcu102_rev1_0 xilinx_zynqmp_zcu104_revC +common/built-in.o: In function `run_usb_dnl_gadget':
+build/../common/dfu.c:73: undefined reference to `usb_gadget_handle_interrupts'
+build/../common/dfu.c:83: undefined reference to `usb_gadget_handle_interrupts'
+make[1]: *** [u-boot] Error 139
+make: *** [sub-make] Error 2
+ usb_gadget_realease(controller_index);
+ ^~~~~~~~~~~~~~~~~~~
+cmd/built-in.o: In function `do_fastboot':
+build/../cmd/fastboot.c:50: undefined reference to `usb_gadget_handle_interrupts'
+cmd/built-in.o: In function `do_thor_down':
+build/../cmd/thordown.c:58: undefined reference to usb_gadget_realease' +drivers/usb/gadget/built-in.o: In function thor_rx_data':
+build/../drivers/usb/gadget/f_thor.c:555: undefined reference to usb_gadget_handle_interrupts' +drivers/usb/gadget/built-in.o: In function thor_tx_data':
+build/../drivers/usb/gadget/f_thor.c:589: undefined reference to usb_gadget_handle_interrupts' +drivers/usb/gadget/built-in.o: In function thor_init':
+build/../drivers/usb/gadget/f_thor.c:706: undefined reference to `usb_gadget_handle_interrupts'
w+../cmd/thordown.c: In function ?do_thor_down?:
w+../cmd/thordown.c:58:2: warning: implicit declaration of function ?usb_gadget_realease? [-Wimplicit-function-declaration]

#16 lore raw

cover Improvements for the dwc3_generic driver

Quoted 31 lines · Michal Simek

Hi,

Quoted 28 lines · Jean-Jacques Hiblot

Hi Michal

Quoted 24 lines · Michal Simek

Hi Jean,

Quoted 8 lines · Jean-Jacques Hiblot

This series aims at bringing improvements to the dwc3_generic driver so that it can be used by most of the platforms using the dwc3 controller.

I tested this on with DRA7 and AM57x platforms for both Peripheral and Host
operations. The code to enable DM USB host & dev support for those platforms will be submitted in a separate series.

Quoted 11 lines

Enhancements:
- use separate Kconfig option for DM USB Periphal and DM USB Host. This allow platforms to keep their non-DM USB peripheral code and use the DM USB host.
- fixes the bind/probe confusion in dwc3_generic. The probe is done when the USB device is first needed.
- handles PHYs when in the peripheral mode. The code to handle the PHYs is
shared with the host side
- handles clock and reset
- bind host controller to the more generic driver 'xhci-dwc3'

I see two series which were sent recently without any description of dependencies.

Quoted 7 lines
Quoted 5 lines

Right I forgot. This series applies on to of the master branch of the USB tree

Quoted 2 lines

Will be good to push these patches somewhere to git and send a link that I can easily test.

I pushed all on github : https://github.com/jjhiblot/u-boot

I didn't build all patches to identify which one is introducing the issue. But look below at issues and please fix them. Then I will test.

The CONFIG_DM_USB_DEV is missing from configuration. This will be fixed in v2

Quoted 43 lines

Thanks,
Michal

[u-boot](dwc3)$ nice -n 19 ./tools/buildman/buildman -b dwc3 zynqmp -o ../tmp/ -C -I -c 1 -sSed
boards.cfg is up to date. Nothing to do.
Summary of 1 commit for 20 boards (8 threads, 1 job per thread) 01: board: ti: am57xx: remove USB platform code

    aarch64:  +   xilinx_zynqmp_zc1751_xm016_dc2

xilinx_zynqmp_zcu102_revA xilinx_zynqmp_zcu100_revC xilinx_zynqmp_zcu104_revA xilinx_zynqmp_zc1751_xm017_dc3 xilinx_zynqmp_zcu102_revB xilinx_zynqmp_zcu106_revA xilinx_zynqmp_zc1751_xm015_dc1 xilinx_zynqmp_zcu111_revA xilinx_zynqmp_zcu102_rev1_0 xilinx_zynqmp_zcu104_revC

(quoted diff) +2 -0
+common/built-in.o: In function `run_usb_dnl_gadget':
+build/../common/dfu.c:73: undefined reference to

`usb_gadget_handle_interrupts'
+build/../common/dfu.c:83: undefined reference to
`usb_gadget_handle_interrupts'

(quoted diff) +6 -0
+make[1]: *** [u-boot] Error 139
+make: *** [sub-make] Error 2
+  usb_gadget_realease(controller_index);
+  ^~~~~~~~~~~~~~~~~~~
+cmd/built-in.o: In function `do_fastboot':
+build/../cmd/fastboot.c:50: undefined reference to

`usb_gadget_handle_interrupts'

(quoted diff) +4 -0
+cmd/built-in.o: In function `do_thor_down':
+build/../cmd/thordown.c:58: undefined reference to `usb_gadget_realease'
+drivers/usb/gadget/built-in.o: In function `thor_rx_data':
+build/../drivers/usb/gadget/f_thor.c:555: undefined reference to

`usb_gadget_handle_interrupts'

(quoted diff) +2 -0
+drivers/usb/gadget/built-in.o: In function `thor_tx_data':
+build/../drivers/usb/gadget/f_thor.c:589: undefined reference to

`usb_gadget_handle_interrupts'

(quoted diff) +2 -0
+drivers/usb/gadget/built-in.o: In function `thor_init':
+build/../drivers/usb/gadget/f_thor.c:706: undefined reference to

`usb_gadget_handle_interrupts'
w+../cmd/thordown.c: In function ?do_thor_down?:
w+../cmd/thordown.c:58:2: warning: implicit declaration of function ?usb_gadget_realease? [-Wimplicit-function-declaration]

#17 lore raw

cover Improvements for the dwc3_generic driver

Quoted 41 lines · Jean-Jacques Hiblot
Quoted 38 lines · Michal Simek

Hi,

Quoted 35 lines · Jean-Jacques Hiblot

Hi Michal

Quoted 27 lines · Michal Simek

Hi Jean,

Quoted 10 lines · Jean-Jacques Hiblot

This series aims at bringing improvements to the dwc3_generic driver so
that it can be used by most of the platforms using the dwc3 controller.

I tested this on with DRA7 and AM57x platforms for both Peripheral and Host
operations. The code to enable DM USB host & dev support for those platforms will be submitted in a separate series.

Quoted 14 lines

Enhancements:
- use separate Kconfig option for DM USB Periphal and DM USB Host. This
allow platforms to keep their non-DM USB peripheral code and use the DM
USB host.
- fixes the bind/probe confusion in dwc3_generic. The probe is done when
the USB device is first needed.
- handles PHYs when in the peripheral mode. The code to handle the PHYs is
shared with the host side
- handles clock and reset
- bind host controller to the more generic driver 'xhci-dwc3'

Quoted 2 lines

I see two series which were sent recently without any description of dependencies.

Right I forgot. This series applies on to of the master branch of the USB tree

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Will be good to push these patches somewhere to git and send a link that
I can easily test.

I pushed all on github : https://github.com/jjhiblot/u-boot

I didn't build all patches to identify which one is introducing the issue. But look below at issues and please fix them. Then I will test.

The CONFIG_DM_USB_DEV is missing from configuration. This will be fixed in v2

ok. Please send it with another link to git repo.

Thanks,
Michal