From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 3/3] cmd: usb gadget: Add a command to bind a USB gadget driver to a UDC port
Date: Thu, 7 Jun 2018 11:39:54 +0200 [thread overview]
Message-ID: <20180607113954.0710e473@jawa> (raw)
In-Reply-To: <1528108297-18442-4-git-send-email-jjhiblot@ti.com>
Hi Jean-Jacques,
> Most of the time the UDC is bound to a driver when a dedicated
> command is executed, like 'dfu'. But the ethernet gadget driver must
> be bound by calling usb_ether_init() in the code otherwise the USB
> ethernet adapter is not visible to the ethernet core.
>
> In DM context, the platform code should not be used to bind UDC to a
> particular driver, so adding a new command to bind a USB device port
> to a driver.
>
> usage example:
> usbdev bind 0 usb_ether
> usbdev unbind 0
I would prefer a comment from Simon (so adding him to CC) - as it looks
to me that we shall try to use DM to avoid adding separate commands for
binding.
>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
>
> ---
>
> cmd/usb.c | 71
> +++++++++++++++++++++++++++++++++++++++++++-
> drivers/core/device-remove.c | 11 +------
> include/dm/device-internal.h | 15 ++++++++++ 3 files changed, 86
> insertions(+), 11 deletions(-)
>
> diff --git a/cmd/usb.c b/cmd/usb.c
> index 0ccb1b5..03245cb 100644
> --- a/cmd/usb.c
> +++ b/cmd/usb.c
> @@ -14,6 +14,8 @@
> #include <command.h>
> #include <console.h>
> #include <dm.h>
> +#include <dm/lists.h>
> +#include <dm/device-internal.h>
> #include <dm/uclass-internal.h>
> #include <memalign.h>
> #include <asm/byteorder.h>
> @@ -753,7 +755,6 @@ U_BOOT_CMD(
> #endif /* CONFIG_USB_STORAGE */
> );
>
> -
> #ifdef CONFIG_USB_STORAGE
> U_BOOT_CMD(
> usbboot, 3, 1, do_usbboot,
> @@ -761,3 +762,71 @@ U_BOOT_CMD(
> "loadAddr dev:part"
> );
> #endif /* CONFIG_USB_STORAGE */
> +
> +#ifdef CONFIG_DM_USB_DEV
> +int do_usbdev(cmd_tbl_t *cmdtp, int flag, int argc, char * const
> argv[]) +{
> + struct udevice *dev;
> + struct udevice *usb_dev;
> + int port;
> + int ret;
> + bool bind;
> + static const char * const supported_drivers[] = {
> +#ifdef CONFIG_USB_ETHER
> + "usb_ether",
> +#endif
> + };
> +
> + if (argc < 2)
> + return CMD_RET_USAGE;
> +
> + if ((strncmp(argv[1], "bind", 4) == 0) && (argc == 4)) {
> + port = simple_strtoul(argv[2], NULL, 10);
> + printf("Binding USB port %d to %s\n", port, argv[3]);
> + bind = true;
> + } else if ((strncmp(argv[1], "unbind", 6) == 0) && (argc ==
> 3)) {
> + port = simple_strtoul(argv[2], NULL, 10);
> + printf("Unbinding USB port %d\n", port);
> + bind = false;
> + } else if ((strncmp(argv[1], "list", 4) == 0) && (argc ==
> 2)) {
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(supported_drivers); i++)
> + printf("%s\n", supported_drivers[i]);
> +
> + return CMD_RET_SUCCESS;
> + } else {
> + return CMD_RET_USAGE;
> + }
> +
> + ret = uclass_find_device(UCLASS_USB_DEV_GENERIC, port,
> &usb_dev);
> + if (!usb_dev || ret) {
> + printf("Cannot find UDC %d\n", port);
> + return CMD_RET_FAILURE;
> + }
> +
> + if (bind) {
> + ret = device_bind_driver(usb_dev, argv[3], "gadget",
> &dev);
> + if (!dev || ret) {
> + printf("Unable to bind. err:%d\n", ret);
> + return CMD_RET_FAILURE;
> + }
> + } else {
> + ret = device_chld_unbind(usb_dev);
> + if (ret) {
> + printf("Unable to bind. err:%d\n", ret);
> + return CMD_RET_FAILURE;
> + }
> + }
> +
> + return CMD_RET_SUCCESS;
> +}
> +
> +U_BOOT_CMD(
> + usbdev, 4, 0, do_usbdev,
> + "USB gadget driver",
> + "bind dev# driver- bind the USB device port to a driver\n"
> + "unbind dev# - unbind the USB device port to a driver\n"
> + "list - display the list of available gadget drivers"
> +);
> +#endif /* CONFIG_DM_USB_DEV */
> diff --git a/drivers/core/device-remove.c
> b/drivers/core/device-remove.c index 1cf2278..b0b5ea3 100644
> --- a/drivers/core/device-remove.c
> +++ b/drivers/core/device-remove.c
> @@ -17,16 +17,7 @@
> #include <dm/uclass-internal.h>
> #include <dm/util.h>
>
> -/**
> - * device_chld_unbind() - Unbind all device's children from the
> device
> - *
> - * On error, the function continues to unbind all children, and
> reports the
> - * first error.
> - *
> - * @dev: The device that is to be stripped of its children
> - * @return 0 on success, -ve on error
> - */
> -static int device_chld_unbind(struct udevice *dev)
> +int device_chld_unbind(struct udevice *dev)
> {
> struct udevice *pos, *n;
> int ret, saved_ret = 0;
> diff --git a/include/dm/device-internal.h
> b/include/dm/device-internal.h index 5a4d50c..b4f44c8 100644
> --- a/include/dm/device-internal.h
> +++ b/include/dm/device-internal.h
> @@ -120,6 +120,21 @@ int device_unbind(struct udevice *dev);
> static inline int device_unbind(struct udevice *dev) { return 0; }
> #endif
>
> +/**
> + * device_chld_unbind() - Unbind all device's children from the
> device
> + *
> + * On error, the function continues to unbind all children, and
> reports the
> + * first error.
> + *
> + * @dev: The device that is to be stripped of its children
> + * @return 0 on success, -ve on error
> + */
> +#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
> +int device_chld_unbind(struct udevice *dev);
> +#else
> +static inline int device_chld_unbind(struct udevice *dev) { return
> 0; } +#endif
> +
> #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
> void device_free(struct udevice *dev);
> #else
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/20180607/ca93dfc6/attachment.sig>
next prev parent reply other threads:[~2018-06-07 9:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 10:31 [U-Boot] [PATCH v1 0/3] Fixes/Addition to use the USB Ethernet gadget with the DWC3 gadget controller Jean-Jacques Hiblot
2018-06-04 10:31 ` [U-Boot] [PATCH v1 1/3] usb: gadget: Add bcdDevice for the DWC3 USB Gadget Controller Jean-Jacques Hiblot
2018-06-04 10:31 ` [U-Boot] [PATCH v1 2/3] net: eth-uclass: Fix for DM USB ethernet support Jean-Jacques Hiblot
2018-06-12 18:32 ` Joe Hershberger
2018-06-04 10:31 ` [U-Boot] [PATCH v1 3/3] cmd: usb gadget: Add a command to bind a USB gadget driver to a UDC port Jean-Jacques Hiblot
2018-06-07 9:39 ` Lukasz Majewski [this message]
2018-06-08 21:59 ` Simon Glass
2018-06-12 9:31 ` Jean-Jacques Hiblot
2018-06-13 1:29 ` Simon Glass
2018-06-14 15:02 ` Jean-Jacques Hiblot
2018-06-14 15:11 ` Simon Glass
2018-06-14 16:01 ` Stephen Warren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180607113954.0710e473@jawa \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox