Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD9CEC001B0 for ; Wed, 26 Jul 2023 16:38:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 44BF9847BC; Wed, 26 Jul 2023 18:38:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 5B2988474B; Wed, 26 Jul 2023 18:38:00 +0200 (CEST) Received: from mail-m11886.qiye.163.com (mail-m11886.qiye.163.com [115.236.118.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 81918847BC for ; Wed, 26 Jul 2023 18:37:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kever.yang@rock-chips.com Received: from [172.16.12.93] (unknown [58.22.7.114]) by mail-m11886.qiye.163.com (Hmail) with ESMTPA id 9DB398028B; Wed, 26 Jul 2023 17:28:51 +0800 (CST) Message-ID: <16fdfafb-4f51-49ef-28bf-a99cf033c4bd@rock-chips.com> Date: Wed, 26 Jul 2023 17:28:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v3 3/5] usb: dwc3-generic: Relax unsupported dr_mode check Content-Language: en-US To: Jonas Karlman , Simon Glass , Philipp Tomsich , Marek Vasut Cc: Akash Gajjar , Jagan Teki , FUKAUMI Naoki , u-boot@lists.denx.de References: <20230716223507.2886459-1-jonas@kwiboo.se> <20230716223507.2886459-4-jonas@kwiboo.se> From: Kever Yang In-Reply-To: <20230716223507.2886459-4-jonas@kwiboo.se> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQx0fHVZIH09MH0gZSkhJSUtVEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSk5MSUpJVUpLS1VKQl kG X-HM-Tid: 0a8991879f592ebakusn9db398028b X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Ngw6ETo6PT0CIUwvQwsWGR81 IUlPFCJVSlVKTUJLSE1ITEhJSE9DVTMWGhIXVRAeDR4JVQIaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFPQ05CNwY+ X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Hi Marek,    Could you help to look at this patch, is there any further comment for the change? Thanks, - Kever On 2023/7/17 06:35, Jonas Karlman wrote: > When dr_mode is peripheral or otg and U-Boot has not been built with > DM_USB_GADGET support, booting such device may end up with: > > dwc3_glue_bind_common: subnode name: usb@fcc00000 > Error binding driver 'dwc3-generic-wrapper': -6 > Some drivers failed to bind > initcall sequence 00000000effbca08 failed at call 0000000000a217c8 (err=-6) > ### ERROR ### Please RESET the board ### > > Instead fail gracfully with ENODEV to allow board continue booting. > > dwc3_glue_bind_common: subnode name: usb@fcc00000 > dwc3_glue_bind_common: unsupported dr_mode 3 > > Also use CONFIG_IS_ENABLED(USB_HOST) and change switch to if statements > to improve readability of the code. > > Signed-off-by: Jonas Karlman > --- > v3: > - Update debug message to include dr_mode (Marek Vasut) > v2: > - Change to use CONFIG_IS_ENABLED for USB_HOST > - Refactor switch to if statements (Marek Vasut) > > drivers/usb/dwc3/dwc3-generic.c | 27 ++++++++------------------- > 1 file changed, 8 insertions(+), 19 deletions(-) > > diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c > index 4d5d500aefab..2331ac453132 100644 > --- a/drivers/usb/dwc3/dwc3-generic.c > +++ b/drivers/usb/dwc3/dwc3-generic.c > @@ -226,8 +226,7 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = { > }; > #endif > > -#if defined(CONFIG_SPL_USB_HOST) || \ > - !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_HOST) > +#if CONFIG_IS_ENABLED(USB_HOST) > static int dwc3_generic_host_probe(struct udevice *dev) > { > struct xhci_hcor *hcor; > @@ -409,7 +408,7 @@ struct dwc3_glue_ops ti_ops = { > static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) > { > const char *name = ofnode_get_name(node); > - const char *driver = NULL; > + const char *driver; > enum usb_dr_mode dr_mode; > struct udevice *dev; > int ret; > @@ -421,27 +420,17 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) > if (!dr_mode) > dr_mode = usb_get_dr_mode(node); > > - switch (dr_mode) { > - case USB_DR_MODE_PERIPHERAL: > - case USB_DR_MODE_OTG: > -#if CONFIG_IS_ENABLED(DM_USB_GADGET) > + if (CONFIG_IS_ENABLED(DM_USB_GADGET) && > + (dr_mode == USB_DR_MODE_PERIPHERAL || dr_mode == USB_DR_MODE_OTG)) { > debug("%s: dr_mode: OTG or Peripheral\n", __func__); > driver = "dwc3-generic-peripheral"; > -#endif > - break; > -#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD) > - case USB_DR_MODE_HOST: > + } else if (CONFIG_IS_ENABLED(USB_HOST) && dr_mode == USB_DR_MODE_HOST) { > debug("%s: dr_mode: HOST\n", __func__); > driver = "dwc3-generic-host"; > - break; > -#endif > - default: > - debug("%s: unsupported dr_mode\n", __func__); > + } else { > + debug("%s: unsupported dr_mode %d\n", __func__, dr_mode); > return -ENODEV; > - }; > - > - if (!driver) > - return -ENXIO; > + } > > ret = device_bind_driver_to_node(parent, driver, name, > node, &dev);