From patchwork Wed Apr 10 17:06:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 787527 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp795735wrs; Wed, 10 Apr 2024 10:07:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX7f0whXI6Cdcdo+fHx7YA6gB7IE8+DmfG3MD94TafVH7lc2/an+kRxCv3l1iPmsDi5PKW+EgZaF2IGU0VDMA9Y X-Google-Smtp-Source: AGHT+IEQXSJA2t1PWSzqIbVclgiQFNrJQmpQZA7h6szfH/i0v8WDTxiXmDklLKEp5+RDPGIJdezf X-Received: by 2002:ac2:5337:0:b0:516:10be:d7a9 with SMTP id f23-20020ac25337000000b0051610bed7a9mr2110888lfh.30.1712768856355; Wed, 10 Apr 2024 10:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712768856; cv=none; d=google.com; s=arc-20160816; b=mg4g8LFFmUZ/fTcwpuRf2SZi8eCSDugxGT/1Gmasl+agSwDba022iQ5cYsakMV+l7I gL26Gm2pzH30+C5v+MFoosEN5q6shfK3dfwi5QMOLSz2qUnAWOVulL2TlxwjzMHuAhZQ CKyWBI8Nj2u6fDcT6dgZn6wLf9XAKje337MnV1DJQ45U6DGF08gd8pdu9sxLKx2DN8tg bV8Ovhv8hTkYpyoc+nL1T9W49IZ2ffC4/Lc69xXfoOQhjCs798Ji9ne+E0tRYlGwVTV2 DWnKkuSslznzCb/zWuTT6hNm1J9eZizXwE90+QoRYev+LAzH32gcThHu+4QuRfD3jGHe Setw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=02zx0nKuszz8w4M8rcBUaVZHu951fIoW3vmJjCnRxRI=; fh=yNn6vIpzE3AMrmGj3U3IjlIaHjPBKfZoQEwu55TxRbg=; b=vUzn1f+nvUOiXXre8fYEL/UKO+tQD4WA5pttiE6gGajcfsQ6892FJRsFssarkVjYcR y/W9Te6p/QOWWeL+o4QGUcmBc7U4zTp8UwpoQPOLEAGrIhvlmjO2qdas/8aQ1oUh3pWq +VN5Z3RY4I2Go3queU8QuMHGef8UH9DZs3cLwGdPNPR5u6Z7jestHz9OEKJSzTnLZ5sk t7o++ta2O6PlZ++1/HyYCXP/n8F0TyjVZR+arwSaIxc7CRODUGjaOvRUGAfN0ulc3/ZT oFn+hHlVLl4Wla/DbAgtuUQMIfCSsG31wezM6y5A1h4ENpFCHj6k8cFcGQN/rX11/pr9 N1Vw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YxlkRUn4; 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 Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ka19-20020a170907991300b00a51feef6438si1654293ejc.517.2024.04.10.10.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 10:07:36 -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=YxlkRUn4; 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 Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 75C62881A6; Wed, 10 Apr 2024 19:07:15 +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="YxlkRUn4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C52E587A00; Wed, 10 Apr 2024 19:07:14 +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,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 CC9258815A for ; Wed, 10 Apr 2024 19:07:10 +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=caleb.connolly@linaro.org Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a51d3193e54so422955966b.2 for ; Wed, 10 Apr 2024 10:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712768830; x=1713373630; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=02zx0nKuszz8w4M8rcBUaVZHu951fIoW3vmJjCnRxRI=; b=YxlkRUn4WkjqMw8z/0H7J9Yzm+Rd9VY4MspkYuV44UiQ1m1Bq+IlvYShY3ZtAFtopQ 6Xyd5qtEwPzXX7MB+SDzZLPUpJY9z/W/Q6PkRaVJ+RmupTAoCS8oZEDsB1dr1WFdNCw1 My1Hcdmv+IfOesmMWAqiil4eXfLeJE1L/txFrFbAN6Ad8syo+x+K3iNNhoaRbDERbvcV lb8EuEKwEzAjxmt5D5Anjdbi47aC9EJhf0t+sF/3MOUuC7Gn/oQuXYRlHL8PdMcczsTv 5XtFuSwlHokzj3B3RIO8J33KsGeTvOYOz5LWiIUkHYYgFsu/2lp9lKbRLGybKm53PAit VygA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712768830; x=1713373630; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=02zx0nKuszz8w4M8rcBUaVZHu951fIoW3vmJjCnRxRI=; b=T/QpXvv3YMM1VgPzb/YB7e1VAFwGflT7S8E58IfHMZIZI497CQnMM0NOMwaUWdz/wn eHWvcNgZ6lHfR6ZfwxDymqi+/F6PcuvaDtFnVh+tZ94/w6qp5B+hJ3IFz1Ga6J9mKYHT 95RN7V+r/tXqEjDLV98IZ7UXZxZFjF3oKeAQVrxO4XJPag9APHR377lwicTDo9mSwjN/ BsIxrMXYiDhNIvhn3AMO7B6I0E2QRiKbWTNtV7kZQARvKAq7h0tLQB0vZH5fuKJEvSiW sDAUJVwYSgn26QbDWBu3/696691XgAFfo/3xWos/9VH0QBZD7RhoQg+LTgAx7N0t5lJD VELw== X-Forwarded-Encrypted: i=1; AJvYcCVZGBtlc5jfhePi1wma/PsUYZ0Mr1kz7rPYOJcJzaLcs8ZVPYxecQCei1lMqpfRplOvvz7pjaR3Nzbgag6b0eWU5FNCkA== X-Gm-Message-State: AOJu0Yz2LyrWIhuMq5ooulCfz6OR9+H6AfioxQl/vxIIhU5Nq93kDyb9 fETkMD+iFi4uJFFCn13YD9fDlOFSW+5T7ZhEgzn+7wPGG49sa4oaImAOmJm6R/A= X-Received: by 2002:a17:906:168e:b0:a47:3312:b32a with SMTP id s14-20020a170906168e00b00a473312b32amr1919786ejd.58.1712768830205; Wed, 10 Apr 2024 10:07:10 -0700 (PDT) Received: from [192.168.0.113] ([2a02:8109:aa0d:be00::4716]) by smtp.gmail.com with ESMTPSA id fw14-20020a170906c94e00b00a51def4861bsm3331881ejb.91.2024.04.10.10.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 10:07:09 -0700 (PDT) From: Caleb Connolly Date: Wed, 10 Apr 2024 19:06:57 +0200 Subject: [PATCH 1/2] dm: core: add support for fallback drivers MIME-Version: 1.0 Message-Id: <20240410-b4-stub-drivers-v1-1-6935bd2c07d1@linaro.org> References: <20240410-b4-stub-drivers-v1-0-6935bd2c07d1@linaro.org> In-Reply-To: <20240410-b4-stub-drivers-v1-0-6935bd2c07d1@linaro.org> To: Simon Glass , Tom Rini , Lukasz Majewski , Sean Anderson Cc: Heinrich Schuchardt , Ilias Apalodimas , Neil Armstrong , Sumit Garg , u-boot-qcom@groups.io, u-boot@lists.denx.de, Caleb Connolly X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3910; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=uW3PK2f+vNh4A0TYpzbXWCElmio+ONn45bjBs9aUpF0=; b=owEBbQKS/ZANAwAIAQWDMSsZX2S2AcsmYgBmFsc7YF0BDVZO+uz5tupQgE07BKp8Ga8CO2qp9 hox89OoEr+JAjMEAAEIAB0WIQS2UaFGPGq+0GkMVc0FgzErGV9ktgUCZhbHOwAKCRAFgzErGV9k tkOOD/0SKIDh/houY3Vc1EjRfU89aK1EFjC00epK1FvezX141IgzZ09dqoVNGNGd/snA1StVIgQ XJJANgWevmKq8no0jP9Hl8ERYQRSabpmIfjiwYCKBoPhWrhwf4paUyCG3lI6JtDkb5OrTpCEH+k m3bKNijBP6LgGbyYPWRWMN9aNLFtDGYqmHglPZHWJmXXnjDsmg486vJcIpitGNpqULk9ZExEUmr ZiPkvsJOx/1l3Lq6fx6hB2MHA3EzHPLHz6Vo5DGauYoELr/FICtmSelMbdm76mvvWWN3kwlIDQS A877anXpMNxYLpWWsOszX/FxthHjLZEKFC6eQBcva/AI9X3sFLzg88cDY1dsGk3LIuX6AGYilKJ bCfGqObCderWBuCjIV+mygAyrULbS4GLwD79mBST2PPb+qK9i6FGx/9s0iHIn+icfuD5b4n02eu yoZ+WV1P6CqjHENkc3gGc/qDo+bmAbyIOZStS1LWrX5zP7035k+qhIaiBoDu0Az1k2S4w/N2xNw Wgkr1WT6Wsoee/SOgt/Rf/7qQNnBSZlujUwJcThoJHMCVbAQMjNTj7X9pBJHKuwQJ3rWTkT4li/ TKb20UnbFHKueU+hHNwVEeZoDSmmGVLJGaknY0qMdBufm7abR7x05hrln9NTT/6oRPAqqBpef9P eEOVafkRsRNQOfg== X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 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 Introduce support for a uclass to provide a fallback/stub driver which can be used when no device is found for a given node. This might be useful for handling non-essential clock controllers like the RPMh on Qualcomm platforms, or during early bringup to get UART output before a real clock driver has been created. Signed-off-by: Caleb Connolly --- drivers/core/Kconfig | 10 ++++++++++ drivers/core/uclass.c | 24 +++++++++++++++++++++++- include/dm/uclass.h | 3 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig index 1081d61fcf01..09075b9b7a15 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -466,5 +466,15 @@ config BOUNCE_BUFFER A second possible use of bounce buffers is their ability to provide aligned buffers for DMA operations. +menuconfig FALLBACK_DRIVERS + bool "Enable per-uclass fallback drivers" + depends on DM + help + If a driver requests a resource (like a clock) from a node which + isn't bound to a driver, the driver model will look for a fallback + driver to "stub" the resource. These stubs usually do nothing and + are therefore only suitable in instances where the resource is not + required. + endmenu diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index e46d5717aa62..91d3a48d77b8 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -378,8 +378,26 @@ int uclass_find_device_by_of_offset(enum uclass_id id, int node, return -ENODEV; } +static int uclass_bind_fallback(struct uclass *uc, ofnode node, struct udevice **devp) +{ + struct driver *drv; + + log(LOGC_DM, LOGL_ERR, " - binding fallback '%s' driver '%s'\n", + uc->uc_drv->name, uc->uc_drv->fallback_drv_name); + + drv = lists_driver_lookup_name(uc->uc_drv->fallback_drv_name); + if (!drv) { + log(LOGC_DM, LOGL_DEBUG, " - Can't find stub driver '%s' for uclass '%s'\n", + uc->uc_drv->fallback_drv_name, uc->uc_drv->name); + return -ENOENT; + } + + return device_bind_with_driver_data(gd->dm_root, drv, + ofnode_get_name(node), 0, node, devp); +} + int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, struct udevice **devp) { struct uclass *uc; @@ -401,9 +419,13 @@ int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, *devp = dev; goto done; } } - ret = -ENODEV; + + if (CONFIG_IS_ENABLED(FALLBACK_DRIVERS) && uc->uc_drv->fallback_drv_name) + ret = uclass_bind_fallback(uc, node, devp); + else + ret = -ENODEV; done: log(LOGC_DM, LOGL_DEBUG, " - result for %s: %s (ret=%d)\n", ofnode_get_name(node), *devp ? (*devp)->name : "(none)", ret); diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 456eef7f2f31..b99e36485bc5 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -67,8 +67,10 @@ struct udevice; * @child_pre_probe: Called before a child in this uclass is probed * @child_post_probe: Called after a child in this uclass is probed * @init: Called to set up the uclass * @destroy: Called to destroy the uclass + * @stub_drv_name: Name of a stub driver to use for devices that are not + * supported by any other driver. * @priv_auto: If non-zero this is the size of the private data * to be allocated in the uclass's ->priv pointer. If zero, then the uclass * driver is responsible for allocating any data required. * @per_device_auto: Each device can hold private data owned @@ -98,8 +100,9 @@ struct uclass_driver { int (*child_pre_probe)(struct udevice *dev); int (*child_post_probe)(struct udevice *dev); int (*init)(struct uclass *class); int (*destroy)(struct uclass *class); + const char *fallback_drv_name; int priv_auto; int per_device_auto; int per_device_plat_auto; int per_child_auto;