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 333F4EB64DD for ; Thu, 13 Jul 2023 10:25:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 704AF86B8F; Thu, 13 Jul 2023 12:25:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kwiboo.se header.i=@kwiboo.se header.b="Zpu0HWgc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E5978691D; Thu, 13 Jul 2023 12:25:20 +0200 (CEST) Received: from s.wrqvtbkv.outbound-mail.sendgrid.net (s.wrqvtbkv.outbound-mail.sendgrid.net [149.72.123.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31CA286B8F for ; Thu, 13 Jul 2023 12:25:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bounces+31435339-7456-u-boot=lists.denx.de@em2124.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=mime-version:subject:references:from:in-reply-to:to:cc:content-type: content-transfer-encoding:cc:content-type:from:subject:to; s=s1; bh=IER8pUuwxUVcEEGWThQ1XS1P4N3Vy+YpQ8qplR5BdPc=; b=Zpu0HWgctEC4uOrTx4+Ic1BaJMiJLSQYxOSrxeYVIe5G2QuAlZFC2cXS7hBNPrxVaMt8 7WA7seKWXy84ivBl4pyneaPmtnRfci/REhqnaExUdOqvErjJUEWiqH4xUXU6Ckk+OpZLyT ITi+zINnKH48Z0doe/On+fNO+2Cz3q2Iy8zW3AVMWItiWP1NPFQtGwrQU+rNoUtxAeC/+2 aofiuyKEoDDc5iGEQwEBcZb2xJN1Cpxd7Cr3m/Syvtke6zQWm5vUUjGQdpdI6PumxLM1kM xYjo4fpptkcW9kdlHy5zw2QcGPPhXTUVipiG0oDmgA+pQF5wOHSSvS/EWlaI8+Gg== Received: by filterdrecv-77869f68cc-5c259 with SMTP id filterdrecv-77869f68cc-5c259-1-64AFD10C-D 2023-07-13 10:25:16.536412635 +0000 UTC m=+5482139.815756782 Received: from [192.168.1.50] (unknown) by geopod-ismtpd-11 (SG) with ESMTP id SJ9ISOgNQQCKYGiLQrUcoQ Thu, 13 Jul 2023 10:25:16.201 +0000 (UTC) Message-ID: <20bc80a2-9038-e19d-853c-2b89013c2121@kwiboo.se> Date: Thu, 13 Jul 2023 10:25:16 +0000 (UTC) MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 3/5] usb: dwc3-generic: Relax unsupported dr_mode check Content-Language: en-US References: <20230530102617.3413183-1-jonas@kwiboo.se> <20230530102617.3413183-4-jonas@kwiboo.se> <10ff39ad-bbe4-6a88-37e9-07b5c9ef650d@kwiboo.se> <9695332a-515d-1525-c855-7b28637f7307@denx.de> From: Jonas Karlman In-Reply-To: <9695332a-515d-1525-c855-7b28637f7307@denx.de> X-SG-EID: =?us-ascii?Q?TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxA?= =?us-ascii?Q?fZekEeQsTe+RrMu3cja6a0hwppjrlOswi2PUOz2?= =?us-ascii?Q?CZxH39kuRs6HsRRM=2FVmDqZnUrUKDJpxoa9aSjd+?= =?us-ascii?Q?dHbrzBC+BqBv3b+tAE69DLblURU5dTYrKdef5iK?= =?us-ascii?Q?KxkEEF=2F4L=2F+obRyhJVGvsoIbpENSLj=2FflGnK7dZ?= =?us-ascii?Q?klUexa21ABP=2FB=2FW2buXS1NgToAXupU+YV1Ve1E?= To: Marek Vasut , Kever Yang , Simon Glass , Philipp Tomsich Cc: Akash Gajjar , Jagan Teki , FUKAUMI Naoki , u-boot@lists.denx.de X-Entity-ID: P7KYpSJvGCELWjBME/J5tg== Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 On 2023-07-13 12:08, Marek Vasut wrote: > On 7/13/23 11:56, Jonas Karlman wrote: >> Hi Marek, >> >> Sorry for late reply. >> On 2023-06-05 12:14, Marek Vasut wrote: >>> On 5/30/23 12:26, 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 >>>> >>>> Signed-off-by: Jonas Karlman >>>> --- >>>> drivers/usb/dwc3/dwc3-generic.c | 4 ++-- >>>> 1 file changed, 2 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c >>>> index c28ad47bddd8..f7859a530280 100644 >>>> --- a/drivers/usb/dwc3/dwc3-generic.c >>>> +++ b/drivers/usb/dwc3/dwc3-generic.c >>>> @@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) >>>> dr_mode = usb_get_dr_mode(node); >>>> >>>> switch (dr_mode) { >>>> +#if CONFIG_IS_ENABLED(DM_USB_GADGET) >>>> case USB_DR_MODE_PERIPHERAL: >>>> case USB_DR_MODE_OTG: >>>> -#if CONFIG_IS_ENABLED(DM_USB_GADGET) >>> >>> Why not just do >>> >>> #else >>> return -ENODEV >>> #endif >>> >>> here ? >> >> The code was changed to closer match how host mode is already handled, >> and the default switch case already return -ENODEV. > > Let's try the above and see if that makes the code more readable. > > Also, you might want to try > > if (!CONFIG_IS_ENABLED(DM_USB_GADGET)) > return -ENODEV; > > To improve build coverage. In my opinion this (after this patch as-is) is more readable and has the benefit of the debug message when DM_USB_GADGET is disabled. switch (dr_mode) { #if CONFIG_IS_ENABLED(DM_USB_GADGET) case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: debug("%s: dr_mode: OTG or Peripheral\n", __func__); driver = "dwc3-generic-peripheral"; break; #endif #if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD) case 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__); return -ENODEV; }; Compared to the following: switch (dr_mode) { case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: if (!CONFIG_IS_ENABLED(DM_USB_GADGET)) return -ENODEV; debug("%s: dr_mode: OTG or Peripheral\n", __func__); driver = "dwc3-generic-peripheral"; break; #if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD) case 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__); return -ENODEV; }; Any suggestion on how this could otherwise be refactored? The original intent with the patch is to fix a non-booting config to a booting config with minimal code changes :-) Regards, Jonas