From patchwork Mon Mar 31 12:31:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 877294 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp1726692wrs; Mon, 31 Mar 2025 05:33:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWTCUTGQdpufLf73LShYtGGSobCpCXNlW/36ZQE4ImcS+CKCyffxCina7TFBylFdERNeoXaJQ==@linaro.org X-Google-Smtp-Source: AGHT+IEN0+xTNJki1OxiEwG4CphoW3Hoag60W7F8vwA07Xvcw+x0hvQy3FY7Ry+JzlRkIhrZ9gOK X-Received: by 2002:a05:6122:2105:b0:523:6eef:af62 with SMTP id 71dfb90a1353d-52610c95f95mr6326883e0c.4.1743424408949; Mon, 31 Mar 2025 05:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743424408; cv=none; d=google.com; s=arc-20240605; b=M74cYRcNl8R17DGFQbE9w3iokv+f6NqG/xI1IESbTS7bwRSCqcsWflp9adwL3WpBkL +2WePikTwHiUPRKzjVlfvFHcHUaQZ26B5+Wf3AXDHRl8O2jIwGDpToY8uI0Xhaob3Tbd BIvMl54Q7y+Q34n6bxi/KhcXL5ODW+Fw9ehbRGoxF4gqDxTU/ODui9Zh2pdGIBYn0XMR kw0DATTmUxI43sV6TP3wnMLE2Ks+vVYGFRfIuH8YDigDrTBBaknERK64MBJB4reEOzi6 MR+hxfGVFCpKQAKrPc9YylPSpd/gXETvTRWjtO1soIt4Ea6qNNh+a6l9YP9CfUjqDJuC sjYg== 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=Y1BmGfnz9Zf8enWa6MBJvo/gF3i4MJ+4iKJWgpAGdFA=; fh=keFItDNZKY6GK00X2JZFul47PtJZO32zs5RLfwodOTc=; b=UV3eX8+bJHCEA+IYSpiUVtp4i11NJz5THRLeu2BBGDEpdsDeZeje81T6ivyNvJ8Kuc 0msDnsw97X6WVKzMD7EKto33ozziinmg4ZIC3mVgmqk9GNXXD3XDjaFI/v8A76u9FHnj /nSReK0aB7UP9YfY805t7n/nJxzlyBzdCr7tC5GcI4WRGlYrqmSNI454MZCEtTQNtdXF QMMfKg74yIhqaVrkei7tIrlz/0CWNJc5M4OIcs2xQnrgLdK0nq7nEmRfnZY6wXMWhDTU 8sXNsuKCaG+gRSJCv0Dmah8NV9oIyBbjBd4JrOd4Gxsng0Q9/J+5rUN6CeR0PpPW4ZD/ 7nBg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K/wHSKNB"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 71dfb90a1353d-5260eabc5b5si1769693e0c.162.2025.03.31.05.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 05:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K/wHSKNB"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 43EF28206E; Mon, 31 Mar 2025 14:31:54 +0200 (CEST) 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="K/wHSKNB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8420D81FE6; Mon, 31 Mar 2025 14:31:52 +0200 (CEST) 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-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 6F27282012 for ; Mon, 31 Mar 2025 14:31:50 +0200 (CEST) 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-wr1-x432.google.com with SMTP id ffacd0b85a97d-3912fdddf8fso3351035f8f.1 for ; Mon, 31 Mar 2025 05:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1743424310; x=1744029110; 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=Y1BmGfnz9Zf8enWa6MBJvo/gF3i4MJ+4iKJWgpAGdFA=; b=K/wHSKNBCjokhiNlz2uGuNFKgk8Kh17AVAw6cwznm3YQokFK9TjXeQJNuPsELiOMqI NA+Venlpd2TLxhdt5JMsI7FTC3fEu6O3Kq86NQ+XNDvs220qDAmE+08aXKMckX6HmA7c 1SJ0Dx+cUhsv+wrWXXoJ+b5xKrM+bboZPUPUU5kuV6q3R1RGLf7KrNdGVe0qpEhqDWqq Ru7esbgLsuivpmp89GBW5QhIDDr66xgE89wnj9ZcZ1HE30twy4SpxWKafWYQfwTSmbaf T2uPpj1OQZ7JyTv1LZtNHp+OEMDVMFgQ9x/Vcdo9fY2//dzYmnbqP5GFw7FRIwWoQLir W/cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743424310; x=1744029110; 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=Y1BmGfnz9Zf8enWa6MBJvo/gF3i4MJ+4iKJWgpAGdFA=; b=XqA3zzgvAucC1gcbwSxnn+3MYJ6517E3MiXVuB6C6YFLRVQF5jnnVI9GmRTf+i4USm Ahw73DBlpOFsr9UUIF6wNXThh++Kcj/2jIFBFTbHLCec1zhP420nbFxT7pomskqLdHhd FUQjN46yRKGuRMWm0LzNdgO2su8sB1LagB3vOb+4OHPsp7+YKLlzdBCAOjvByI9agUYx FxCBr8O4pzqMicaX5pvFjKPSA0dsTtvM2xydGriLqPbGYJGdAk9LH4O4zMdrmMWrBWpP ZGcK8bPeWXOP1TqRfFIMCCGMyl1VtxHM9v8aYkUHZFH9GjbqLUV5HichB4myu+Ml8Jnh GDxw== X-Gm-Message-State: AOJu0YwcVKVMdoxugRWuO8ujTNZ+VZdpgwkk7xSdOxsDZP/Bt3D5A9lJ zlAex7+tSkuGNoWIN9BBgg89aV4fjiy7sF2/tkyVSfduMmZqScb3pu6EUrgjWtbKFpXLPZR+JuH tyhiLTg== X-Gm-Gg: ASbGncvDR4TJGcZAAgExBq11CFI9wxLz0iFp/gS1p1nxVBMg7/mC0SXLkmiPgvAYFt7 yFloRhh+UWXdXQwV0e+zZVr6qoOR2PA0drzlAftkqTXEl2j+K5UmIbZ+z7MO07E4Q0qzn2YnTOB OBlJ213WTOy8OkfpOe/CWLIYB2ogy4PwWvA2BjeFTGSzgP+/Nd3T/d1EkRcf1i3BSCFNKJSizbs Jy0E+PiH/YOzG4jKx6HScX34QIMWNYQ14nU0I5zQs4DDPZBVhJTjbRCeMORrHafCVbqpAVm3nWY +Qb/FzDPVlszYDtPkeZVTW3FSye6k0N3r4pmAh/vUXsy6gHuo+kU X-Received: by 2002:a05:6000:1a85:b0:39c:1f04:d151 with SMTP id ffacd0b85a97d-39c1f04d17emr1476163f8f.26.1743424309694; Mon, 31 Mar 2025 05:31:49 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:f23c:25c9:dc74:be1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c0b6589e4sm11337029f8f.10.2025.03.31.05.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 05:31:49 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Mattijs Korpershoek , Heinrich Schuchardt , Dragan Simic Subject: [PATCH v5 12/16] dm: usb: move bus initialization into new static function usb_init_bus() Date: Mon, 31 Mar 2025 14:31:06 +0200 Message-ID: <20250331123120.2025062-13-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250331123120.2025062-1-jerome.forissier@linaro.org> References: <20250331123120.2025062-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() and count the number of USB controllers initialized successfully by using the DM device_active() function. Signed-off-by: Jerome Forissier --- drivers/usb/host/usb-uclass.c | 83 +++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..fa1af8f555a 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -287,6 +287,45 @@ static int usb_probe_companion(struct udevice *bus) return 0; } +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"); + return; + } + + if (ret) { /* Other error. */ + printf("probe failed, error %d\n", ret); + return; + } + + usb_probe_companion(bus); +} + int usb_init(void) { int controllers_initialized = 0; @@ -305,47 +344,11 @@ 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); } + usb_started = true; + /* * lowlevel init done, now scan the bus for devices i.e. search HUBs * and configure them, first scan primary controllers. @@ -354,6 +357,8 @@ int usb_init(void) if (!device_active(bus)) continue; + controllers_initialized++; + priv = dev_get_uclass_priv(bus); if (!priv->companion) usb_scan_bus(bus, true);