From patchwork Tue Mar 18 10:46:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874404 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443236wrq; Tue, 18 Mar 2025 03:49:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWF8Nx2vTAcSu43y4fJaAzs8vpCkTtbLGRrPwHu7CVXGWTF5+U5p+WXEyiu04uIIn9Tt6j1og==@linaro.org X-Google-Smtp-Source: AGHT+IEEfX2Ra3XWHErS8fydxbuV/79TAZeO3KjPDL/gTisLCxzBmyf5geslGH9REmYz6BhYcf3Q X-Received: by 2002:a05:690c:6d13:b0:6fd:97a7:1474 with SMTP id 00721157ae682-6ffd748aa7fmr49453897b3.11.1742294946228; Tue, 18 Mar 2025 03:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294946; cv=none; d=google.com; s=arc-20240605; b=liN2L4JKnaiup4ZYAtJ9WYV7p43sPmRWrLW5sPMUqQ0AY2lAcuoXmkzbtG4X3/IUV2 BnGZ++nUG1jzncAdqAwd6cWo62WcLZSzapnSGYA8s9BWK7Tq22Wca2oJVfXT+9lQttd0 ARQW6iugeHGycat9Hl0QicQQ3hhyLJ8PSAYwDB1sHWyb7cGVvKhcVoTDNKeEdjokQ750 TK3MmS6++lpDVm0IzNS4NUTc65SuOQb4XtieGC0jzHaWo8Ly6wJqPfJ035itz61RWPRP TH3tzaK8KHXwaAFWYGACs/kfDH+9VFgoRETaPpe9lRh4UctjkvtsDhsn6BvNQmjAIOOk dL5w== 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=aOwEPxvaoWHr66xPkiSDm/VL7CWIUInUohTOmW+osfU=; fh=fR0UVWovEQaeizUbW6NYRhJaKj1baCbm+MM7JESBVRo=; b=ONCD2sC5W3E7bojT5HPfeAOhoiTyJk0fwBMPKg7aBnzrmBxleHm2SG/VuVL+ixvxBY UylLBti6I1H0B+iYifSk9TxDJDr08+jBTT149Up5y9VGd2Q3aTypM/8Ifj14XPAc56GD vnXPJK7H0uGwMY0iC+ybdRr5q8vI0Sh5+3gNxz43wRwsa2fYVZ0c6CHHRsmCHHbV8e3S 2yowP/drd0qARNay2qd9jP4GCZTXhp4XQE8FhdCLBsnuJy82HrbB6LiUW81IUEDH9MzE s4RRVUHvPH3j8GN0J2Z74rqQz5BtgUcjO8yahQWqqSwB4Gr9AoRGtoRsracZBcZA7NOE fMUA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vFN+EihI; 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 00721157ae682-6ff32b42002si92131467b3.265.2025.03.18.03.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:49:06 -0700 (PDT) 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=vFN+EihI; 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 D1837819AA; Tue, 18 Mar 2025 11:47:37 +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="vFN+EihI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 198D281D1F; Tue, 18 Mar 2025 11:47:35 +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-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 7321E8122F for ; Tue, 18 Mar 2025 11:47:32 +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-x330.google.com with SMTP id 5b1f17b1804b1-43690d4605dso21748355e9.0 for ; Tue, 18 Mar 2025 03:47:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294852; x=1742899652; 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=aOwEPxvaoWHr66xPkiSDm/VL7CWIUInUohTOmW+osfU=; b=vFN+EihIE1hjAryWK8QhNaBsUwX8vRj1nx568xOYLGRa7h+s3twDimyzMlAoLAmJQr QIa5GguBlN1P8i/sE0i4kUhD0/qHf2hcN2e7Z7wkcGBO0WLPYerJRk4cz1KD322S+WTA rbqdj3igsyyUZWGe9JakDHV6gp+3YyzOzPFTGRBghGCKbEIWJjWNjPLQH3EWmKxPpPPJ mSk9ruHlyb8uvl29TIyYsKFCTtE60uDId/N3AeXDcN/KND4ShpANvU3EV45RGouZQrNe UHhFYXVcgx+sbqSuVKUQQPk2lWj4aSP5AXabKaHxHvVN0K00bz3QTHWYFeI4bseGtWD0 4AGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294852; x=1742899652; 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=aOwEPxvaoWHr66xPkiSDm/VL7CWIUInUohTOmW+osfU=; b=jb39+cJfPehwfw2eQfTjTKGfTR+DPUlj+9ZTMHWFGTWO82Bl2ojJxEipi8Ujhhzlm9 fmSHSqgKEom+mzur0bhrKd5zobaA065MidMLfLeP3zD939xdr6B6WPH0MwQy3iPA6fng KR2FweBpiOPHImQ8p6omUbUZYE+HXBwPLHl7zWVaT10ALhoJvID3HwI3sm+/ansts9ap KESwJxms1XKDsM7SMxm+1DMwiraRf4PmzD1Oz6BO4cS9/LF7xTIHbO8fnYyZ4Z0j9MGN UFDz4tufV1jOGwz8MzGdo0Hy3wYPiRNFzBbEzwfX0fSOuvABhRtWdoRLnTGHg69ggUvU j/ng== X-Gm-Message-State: AOJu0YyJQkZBrIhmzdMrwwhAShkWCjqNu706VCBdDysTq0m8++oCOyXb 20NFJnQJwaSx7e0tmBVAl8ygCN/KwxoU+QjzjJBvFsBnS4/6tjUc5tPNjTmnzJxWFft2uhoe4Rd UdBs= X-Gm-Gg: ASbGncsR5hKjrXVnQq++/6Jk4VPdjLg1fRFUz9VJQDNhWV+D1Aoj6BmwwlKHmixxApf l7vom2IernKLjkg9Bw+GffKmosraXkk4sW+8z30+Ta/lb9g/pNGfORqhHkKuLC2VqUMgqUt9gns iLrXK/rjP9dZRPD21v7UAw8zfHrj2IiZg2C8t9El2rPBi7wceccrNgqJ1eQ8VLRrZNVCWPWmw9E kMyLIq6JDKD84yqp1/GV6cj4mm58f5jI053oDLKsPjEzogHmcVW0Gtg/Cs1ESqEJC93jebhMkOQ 6fVxbucxh7dUBKg+Uo/j/YUdpts55h6kNIvCECEqp99vJ/iJElbIxw== X-Received: by 2002:a05:600c:4295:b0:43c:f513:958a with SMTP id 5b1f17b1804b1-43d3e14fa65mr8428375e9.13.1742294851611; Tue, 18 Mar 2025 03:47:31 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:31 -0700 (PDT) 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 v4 10/14] dm: usb: move bus initialization into new static function usb_init_bus() Date: Tue, 18 Mar 2025 11:46:46 +0100 Message-ID: <20250318104659.1114340-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 threads 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); } /*