From patchwork Tue Mar 4 15:24:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870111 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313561wrg; Tue, 4 Mar 2025 07:33:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXQPZM4d5RKDwMSNGajBJHKxgyAnNIp8GvHN0PLvHzvcJUA5dvNcHeJGqA/gun17Jdpj5TMOA==@linaro.org X-Google-Smtp-Source: AGHT+IHUhPUtUcuuXw/oya97Q+Yl+tCyzb9k3v/sDoIwzXicZkzpBcG21juFu0J7OwHJnp3T6m2j X-Received: by 2002:a05:6a21:6b0f:b0:1ee:c631:6057 with SMTP id adf61e73a8af0-1f2f4e0ffc7mr33487051637.34.1741102391509; Tue, 04 Mar 2025 07:33:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102391; cv=none; d=google.com; s=arc-20240605; b=HLO9Um+p+B5sPpS1RD0vPU/F7ccpnXcxC1mygSO2Y1stAQaEwJXAnbdf9oU/zD2geT fjS2NWNLKGDT84dG4edDqK9k4UU33XLpFqvvqGS1HvEqyh/mu9qIpr7+OZdNyaJO7r6I O3bZ6gOF2tLpKyIDsnYR+W3+izU4U9oVrWQJHV9ttyrXtlFoWw6l3am8IyHl/T8nvcaH 4htTXPCI0khqjBrWZ7uFBUNLsFVzN2ShG6YkjiS17jhGTnouXFmBEcZcqD1dMLOaWGJ+ SNn+N1TkQl5Lhmqsn3isEpMUYG51QXzDSvpoCUPJCoVImIAKTPuromY1pYcSb/mhMqqU b7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ce5dvI/5nuqLZMR/lkwnf7B1aBvTQhktpRS0pk/2NjQ=; fh=fR0UVWovEQaeizUbW6NYRhJaKj1baCbm+MM7JESBVRo=; b=U+xuHtky2l3nBpVFKEbQ1Do94vljqgzLsKBPV+PtpJSPBUqasJdGOzuHPconM+1eP/ Evrr2eylLUpIBLD0hoEl+rkW5gMWQNWg4IYby/6vdFL5vYuj3b7bT259kOEDowU/+VBv LJgAMa5GAnDq5w7wLD5nVW39GpcudUc+vMJhTXLRwLXefr2YW6PGPriz0kUmo9/L4s7C h/aON1R6UpOiJaDCBvh/mif4458SLgA3/837arzWc4E1WBWDM9ycxOuuyx/xnnaIBGio 7zuDFPEEFI4YkbDH5QVFj8wKpAxvSXKqTyofnmTCbmRYH0pEEhM8+x70bbeXL2CwDPhA FpJA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kUGBlFOf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 41be03b00d2f7-aee7df3fabcsi18963693a12.715.2025.03.04.07.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:33:11 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kUGBlFOf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8E35280BAA; Tue, 4 Mar 2025 16:32:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="kUGBlFOf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 377A88141A; Tue, 4 Mar 2025 16:32:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 BA58581273 for ; Tue, 4 Mar 2025 16:32:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43bc4b1603fso14456755e9.0 for ; Tue, 04 Mar 2025 07:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102299; x=1741707099; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ce5dvI/5nuqLZMR/lkwnf7B1aBvTQhktpRS0pk/2NjQ=; b=kUGBlFOf8w6GCGVWixFZRq65AETKlQdmmoXsl4jFNq8TeFL8ToWBLhkM014ke2Mr6C bpcGIyzcIswn0A3KC1+pL3aRVUHq6ySNKv17eXxIJF3IQVT82KyR3kqlZUAA2FKf+S+A FjCQWi2vLI2LRL5lTG8pOVPeYmLcfjRj2fcOuQGQ/hr7KEfmUZ7MvKwdU+qlqXIBczF3 SkyOxpC2YiOvnNYihBZdxBJJtO0HxfpcUINRjBWPzxSCRdHNsIepZG6udk7FrMQoKo1j wGSxepj/R13pP6iYHkZGsgwhd+L8oAFLf7R0SRub+UoooOL/QcIKhbk9D3cqLThtCt5F KbmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102299; x=1741707099; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ce5dvI/5nuqLZMR/lkwnf7B1aBvTQhktpRS0pk/2NjQ=; b=H6PKYTKj588LgtBnYWBKBb6hH8Qo7LgTQrSK9Q+cTKe/vvuPZuiNhXHqAX3WGuEORd 0cy6M71kohc05QEPtD1+ZZk8vNbE9m6OjBJ5rTaJ8I7zxorCl0Ofs26nQ7E+lVKsj5kF pYBna9XSu4sBSIQBJWAGCwoxbceMHEhWl/efjR4mfBnxuyyyLriMfPj0/CxiwBbdW/HC WcoEQiaFg+qSCxEeiG+mZeRU8CbQMSBfLKBukZoGb5N+9c5RtaTJXOraYtHgdYPS28ld 2QTF1wu9zApZ0n4LY36lCFfev6kzezoiyP+q6sqkjYyJrbTQ0aGwouhJhUwBKMj+IcW8 3tfA== X-Gm-Message-State: AOJu0YxIorEbovM3Gggr1JHILPr+wwBOoxslceIUCSqXeOR5YnoK2p6o UW5EIr2EuuzYUn/D4K6hf8VkNnPD8wlhayjxg7znBzuqq0mKm3rea54BDKtiE/g8ojhTchtLjko i X-Gm-Gg: ASbGnctmaEg9DdN+SSujIS+dE5rqK9/k2reH6KM+UZaBvk8UD2zUKQxoMDn+7kZXdb5 THP7+r27mtU3RwPdHve+8yiz8nbsggvgIk+NABAXIBBLQrJbq0XwGow131Cry7ycel3fEJIPcpX edKX4d9QdNUzAn2XaH2gCZGJqGwb3kBLMCqiNeFdqhkknToJhrDAJ8B1RbQ6DzGdBE+sPueB6fy icOSBNJqy8W4g3Iu9R/nL0XhqnX1Dadn/5qEtQYGeB5vBUhMRavOhuxkjV888KkY4O8cV8CDWiM hCyzoXMgyrpEHqFJ0VVMX7uaqe+ZDTiuz5FVx20iRevsKN+GWDyVmg== X-Received: by 2002:a5d:59a3:0:b0:391:cd7:82f9 with SMTP id ffacd0b85a97d-3910cd7835cmr6134495f8f.27.1741102298755; Tue, 04 Mar 2025 07:31:38 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:38 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Mattijs Korpershoek , Caleb Connolly , Dragan Simic , Heinrich Schuchardt Subject: [PATCH v3 10/14] dm: usb: move bus initialization into new static function usb_init_bus() Date: Tue, 4 Mar 2025 16:24:58 +0100 Message-ID: <20250304152510.2832340-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 To prepare for the introduction of coroutines in the USB initialization sequence, move code out of usb_init() into a new helper function: usb_init_bus(). No functional change. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- drivers/usb/host/usb-uclass.c | 88 +++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..cc803241461 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -287,9 +287,55 @@ static int usb_probe_companion(struct udevice *bus) return 0; } +static int controllers_initialized; + +static void usb_init_bus(struct udevice *bus) +{ + int ret; + + /* init low_level USB */ + printf("Bus %s: ", bus->name); + + /* + * For Sandbox, we need scan the device tree each time when we + * start the USB stack, in order to re-create the emulated USB + * devices and bind drivers for them before we actually do the + * driver probe. + * + * For USB onboard HUB, we need to do some non-trivial init + * like enabling a power regulator, before enumeration. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || + IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { + ret = dm_scan_fdt_dev(bus); + if (ret) { + printf("USB device scan from fdt failed (%d)", ret); + return; + } + } + + ret = device_probe(bus); + if (ret == -ENODEV) { /* No such device. */ + puts("Port not available.\n"); + controllers_initialized++; + return; + } + + if (ret) { /* Other error. */ + printf("probe failed, error %d\n", ret); + return; + } + + ret = usb_probe_companion(bus); + if (ret) + return; + + controllers_initialized++; + usb_started = true; +} + int usb_init(void) { - int controllers_initialized = 0; struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -305,45 +351,7 @@ int usb_init(void) uc_priv = uclass_get_priv(uc); uclass_foreach_dev(bus, uc) { - /* init low_level USB */ - printf("Bus %s: ", bus->name); - - /* - * For Sandbox, we need scan the device tree each time when we - * start the USB stack, in order to re-create the emulated USB - * devices and bind drivers for them before we actually do the - * driver probe. - * - * For USB onboard HUB, we need to do some non-trivial init - * like enabling a power regulator, before enumeration. - */ - if (IS_ENABLED(CONFIG_SANDBOX) || - IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { - ret = dm_scan_fdt_dev(bus); - if (ret) { - printf("USB device scan from fdt failed (%d)", ret); - continue; - } - } - - ret = device_probe(bus); - if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); - controllers_initialized++; - continue; - } - - if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); - continue; - } - - ret = usb_probe_companion(bus); - if (ret) - continue; - - controllers_initialized++; - usb_started = true; + usb_init_bus(bus); } /*