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 B9A79EB64DD for ; Thu, 13 Jul 2023 11:36:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8E90A86C17; Thu, 13 Jul 2023 13:35:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1689248158; bh=YP07ozgRUJcriPcgWE7wwhqoOOtVGWag11UsrqDPF14=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=agDL3O8+D6slMKsfy4PAPrqbe5np3KE/XbhR96xy5gsb/1zyXcovG1cnAgrMVR/u8 cK8Ludjz7qjZNOYPiES6G2phV2tMtdXf5FqQ38OJXf3t0AyQpGHSSv1vgM/D+WkAyJ mUvsDVkrn84gQ4uweKI3oT725oJiHJoDhRPRGJ82m/rw6AoyCSREKfRc1NP3mP/mG8 GhAh0I9jsRDIUz/Wlfr88657IQCIqz7JdXxHlOhjFcLhaccf23Wdl1FQqzTW/fVnSa itn6xHHKkFWi9S2uElCPax6nBdpsYKenM/yZ4fKn7dP/gH+DmnuerIpa1rBVDVA7EW 28ceqvjK0ZAow== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 065D086BFB; Thu, 13 Jul 2023 13:35:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1689248156; bh=YP07ozgRUJcriPcgWE7wwhqoOOtVGWag11UsrqDPF14=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XP1Ih/tusgVOA0okZEehmdY1wxoY2KKRzO/tSOBK6lr1W4XSzYDBGTigCsir0iucz F1DdWO+8a6Y02m5ga6x02CJKyz/mo5aHHc7Klyfp0jyuYp1lsUAJ+Zxw3P7egNtPUA SZwm9Df+bMZkW9J6vNUDWhnuVis0PP6mM+AveYg/0ZJEfLHgXJBK7KABBQFbatiGwW ReEEJ3o2AO+oLeE/4XEBjxVv4LnKoftfIkAglR184q87C/iTyDOfDBWBnLpUxwSF1P e0jwOpnRHwVQBQP+8Hzz6iGboFx+FFwYDzmn92DBkYdlZokaZBa38U1h/6wTohn3hh Syzx+xhlqCkCA== Message-ID: <77eab394-49a4-45fc-cbb2-7fd4ab155d21@denx.de> Date: Thu, 13 Jul 2023 13:35:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 3/5] usb: dwc3-generic: Relax unsupported dr_mode check To: Jonas Karlman , Kever Yang , Simon Glass , Philipp Tomsich Cc: Akash Gajjar , Jagan Teki , FUKAUMI Naoki , u-boot@lists.denx.de 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> <20bc80a2-9038-e19d-853c-2b89013c2121@kwiboo.se> Content-Language: en-US From: Marek Vasut In-Reply-To: <20bc80a2-9038-e19d-853c-2b89013c2121@kwiboo.se> Content-Type: text/plain; charset=UTF-8; format=flowed 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 7/13/23 12:25, Jonas Karlman wrote: > 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; Maybe drop the switch-case and try: 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"; > break; > #if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD) else if ((CONFIG_IS_ENABLED(USB_HOST) || !IS_ENABLED(SPL_BUILD)) && dr_mode == host) { > case USB_DR_MODE_HOST: > debug("%s: dr_mode: HOST\n", __func__); > driver = "dwc3-generic-host"; > break; > #endif } else { > 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 :-) It's awful either way, but at least with the CONFIG_IS_ENABLED() stuff, we avoid bitrot of ifdef'd out code, since all the code is compiled in any case.