From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CA08CCFA1A for ; Wed, 12 Nov 2025 10:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Xtn1agn38vYYRSDmrX8xmfCfXiGeMgWG3lL/9kBn0bY=; b=ugGPCk/4lOFyJbwPm5RlFRAEc9 ni8BzmSPVC2HHcdN2tEtbs5L8r+8CsMYSASNWMeMWVLlhNvugR3L+um2CIqrpGL/+YAH3oVYOSMJr a2vgQpzBRrHsdp/1a+1M02FmusBbBNWqOTHr06uudFXEWAWfzEpgdvD1urytbWj38l9Vn2ylBC/PW WEn4g6IcIEP/2ew7GDO0uY017dcWZEKPO8A/0XYUte6relybP2gHvdJlE989ATgmGvTwgaLenKSsk jyEdxRaNN3BbIAlcd3OXQaTOYsOtFHeWzubtNr9yrxEbIr+o99ElXsqs9w6dNFb3HKvumaMnBdBLk bURAlu0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vJ86C-00000008Ywc-0rgG; Wed, 12 Nov 2025 10:29:12 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vJ868-00000008Ytl-1XXL for linux-mediatek@lists.infradead.org; Wed, 12 Nov 2025 10:29:09 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-429c844066fso79562f8f.3 for ; Wed, 12 Nov 2025 02:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1762943347; x=1763548147; darn=lists.infradead.org; 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=Xtn1agn38vYYRSDmrX8xmfCfXiGeMgWG3lL/9kBn0bY=; b=bSfYg+Q9N7Yk3yQ7HEL8ITBAdEssrBPqTumvbvBQ+5dLx9v/6V0ffvVtCpW/emO172 7KPcYwqQf9QOJ/ProiueJHnARX+DGH1cxRz7neI45WTNbMfEsc+jzLEDlqWFMjQfUnVI F01WGuQjbWwlSuwnEXtyxTLMyRpwdPV453a8yLhUlzG9QsmLUnXKZ+8Z4e2YKuMf+8yw ujU/Hje09QnGFdInDV45kzlWEjJx0edvOuG9pSjtEZXoA1SLWSy5di/JL2QABwGZQ3RU Hasvm+3rmxSchAVjDWD8assZpaEFt//K/o2F/yWpcwHPswtolAOwKla46kyEuUwgD22V W5xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762943347; x=1763548147; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Xtn1agn38vYYRSDmrX8xmfCfXiGeMgWG3lL/9kBn0bY=; b=dQ2n/qG10oddbZ08CR3VAiBlhC6aqGJFJtyvp/7pMjgk+B4v6HDV3BzvWq+1szI2fW tf9YvA1lu603VZDDBYMkD7r+KCLzlGWLH76TM5eMZBryXb6E4YsJsgsInlJCaSq0DwIF wBMtJjwWbSgrnwBkZ7u6Dv+hBPh3qhFsV4SFLp8HnCSznIWtiDW7viKo3VRcFHcyY/1A L/MHs6++rO7o6QruZ/1iS9pjEdY4eKEDcty6iBZ2NpIABWrGFi3/i6KIe80JBJXw0Fsh KnpCLBDBWm+sIvQSNDx4PkC+x3QTyXuDRD4C/MKnpQu2RcfTdmjoYA2Y+SaIbIvL0jC2 8Ynw== X-Forwarded-Encrypted: i=1; AJvYcCXqYND8gljAUr8RK+c9u7DdZqmk0mJOPtOg++VnYYE5ttm/dsTDqWz+b9wQMA6k/IunoEqhk8zrNMkX4NkxDw==@lists.infradead.org X-Gm-Message-State: AOJu0Yyv6dyaU4OyzWI1Ke3ypiMr7zYqz1q0ox75etbFP+B0QgOo/Toz P7uR/SGfUxc+EFReBKF040E56t1T0/TNocXdKcIxE+9Dt07/KiBtIuZgpWigDHBR8UQ= X-Gm-Gg: ASbGncu0wM9zNadYGlhc6yNeYd7fQ7N35V8SydTDVe2FLwACk3ktPpg3tpCTEuX7PE1 6blywwLebu8CHqPJlfMTkgRwhXM7mY7ZmiyUTKjfIuF9LcAmsp3Q0tuYg3QJR8l1ARZ8+EFuox9 6hlAVV1ZUsazTqUtvx7YLk8wWQmhaVIzDtAIpO7o97LhKkemoSeRZixSDrVpDIp6r89hvJzg0i1 8qtWIb2Qy5q9MNKn+WOCL0st9eLw73ef8Ycd1p9yH8g7qFaBrpFlxSdI1+hHVD2O2+HhlxQSV+X 11Ct42ZvIJHT0U2QrxYn4KOT6sp7VJSCgiFrcls0G7REmhBpDrVfpY+FuFPhmkqruz16zl5g76M E0eMMibXGM/xX6iXoVOsHD0aLoHa8abjf6cUKfmDXaEBqA3MPNVXStwl6G+8BFodeq3wm55VIPe EM+3jBPOzdafjjxyBa X-Google-Smtp-Source: AGHT+IEqw4rhZRyDy+yPmdGyXuh1FmIzLY034EYTwmwGfWZRi5DR0a/TjWaTQc0ZSjDYk6R/6C4iqQ== X-Received: by 2002:a05:6000:2087:b0:42b:2da3:ac30 with SMTP id ffacd0b85a97d-42b4bb875c4mr1198295f8f.2.1762943346620; Wed, 12 Nov 2025 02:29:06 -0800 (PST) Received: from [127.0.1.1] ([178.197.219.123]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b32ecf522sm22020001f8f.45.2025.11.12.02.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 02:29:06 -0800 (PST) From: Krzysztof Kozlowski Date: Wed, 12 Nov 2025 11:28:46 +0100 Subject: [PATCH v2 01/11] of: Add wrappers to match root node with OF device ID tables MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251112-b4-of-match-matchine-data-v2-1-d46b72003fd6@linaro.org> References: <20251112-b4-of-match-matchine-data-v2-0-d46b72003fd6@linaro.org> In-Reply-To: <20251112-b4-of-match-matchine-data-v2-0-d46b72003fd6@linaro.org> To: Rob Herring , Saravana Kannan , "Rafael J. Wysocki" , Viresh Kumar , Matthias Brugger , AngeloGioacchino Del Regno , Yangtao Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Lorenzo Pieralisi , Daniel Lezcano , Bjorn Andersson , Konrad Dybcio , Thomas Gleixner , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Maximilian Luz , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Daniel Lezcano , Thierry Reding , Jonathan Hunter Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-tegra@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3774; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=97pN+hZe6aOdQXzqXH/jzMv6/WG6YtpXykn+P6/wWxo=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBpFGFkNYeOuoYzpykLoG20VsmMhHx83ITlx4eh3 nQhR2/+8c+JAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCaRRhZAAKCRDBN2bmhouD 1+WoD/0TKoeUAmx+UOxM0JybjWAMODukmdMBn6gauxFIVRlljF/oKwZMabgzYrNN21aWkVxl2Gx YzAxkQ/qwOh0Kdg86awylIZT+BceJmpZHLGj/zlXD7z1Kp2Ib/Kvukk1qf78AAs+4CkVn6XLbMm SfzvNCXZAFS/Wmwt570i9P1qKzGcXPrFmD4MBRBDKcQbzpnZXtKtATET5wD1DdrmwA6VvwTWg8L p0SrRLcNqaiA690mMfLZ7XlwD14yyWMuYn3NzN0WwFvYKWh2yqTxVxjNKzEoCRxn+6Lh6E//R1R UotKfqNNiO5iZadxiAimw/mkju2Kc5uaLsCPVtoLaIALM1ORhiyi23/oZKufSjy2XuBogIcXmzT fUnq0U1+Oeh5KRBAcI4FJ5EDuOL2QM3vVPw5CHBaTVxUvCg72PkhHxk2T41dJ0MliQNhFjNBVIM i0zNFwh00b3UiSNkrkGSas79QDK4rhMiYBsgfZUGYjST+qh/p6kM7ccxpbMz3tirdbvMsZxEufo M7xuNl4R9dMgRs7AKLfaIIsojl8PL6NpZNLEoFVh6RzLDTt1v687levEf1VfBoqiRy85HTPXUJr NsuSFe0RR2EjGM7CjvRbVfguXXSnUnV9PtpU259qszWKt0OBGoXxH4O/Co15e4lndqJuZVDKFX0 WigE1E0XpsiiR1A== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251112_022908_450445_7F769A54 X-CRM114-Status: GOOD ( 15.77 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Several drivers duplicate same code for getting reference to the root node, matching it against 'struct of_device_id' table and getting out the match data from the table entry. There is a of_machine_compatible_match() wrapper but it takes array of strings, which is not suitable for many drivers since they want the driver data associated with each compatible. Add two wrappers, similar to existing of_device_get_match_data(): 1. of_machine_device_match() doing only matching against 'struct of_device_id' and returning bool. 2. of_machine_get_match_data() doing the matching and returning associated driver data for found compatible. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Krzysztof Kozlowski --- All further patches depend on this. --- drivers/of/base.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 7043acd971a0..0b65039ece53 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -434,6 +434,53 @@ bool of_machine_compatible_match(const char *const *compats) } EXPORT_SYMBOL(of_machine_compatible_match); +/** + * of_machine_device_match - Test root of device tree against a of_device_id array + * @matches: NULL terminated array of of_device_id match structures to search in + * + * Returns true if the root node has any of the given compatible values in its + * compatible property. + */ +bool of_machine_device_match(const struct of_device_id *matches) +{ + struct device_node *root; + const struct of_device_id *match = NULL; + + root = of_find_node_by_path("/"); + if (root) { + match = of_match_node(matches, root); + of_node_put(root); + } + + return match != NULL; +} +EXPORT_SYMBOL(of_machine_device_match); + +/** + * of_machine_get_match_data - Tell if root of device tree has a matching of_match structure + * @matches: NULL terminated array of of_device_id match structures to search in + * + * Returns data associated with matched entry or NULL + */ +const void *of_machine_get_match_data(const struct of_device_id *matches) +{ + const struct of_device_id *match; + struct device_node *root; + + root = of_find_node_by_path("/"); + if (!root) + return NULL; + + match = of_match_node(matches, root); + of_node_put(root); + + if (!match) + return NULL; + + return match->data; +} +EXPORT_SYMBOL(of_machine_get_match_data); + static bool __of_device_is_status(const struct device_node *device, const char * const*strings) { diff --git a/include/linux/of.h b/include/linux/of.h index 121a288ca92d..01bb3affcd49 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -407,6 +407,8 @@ extern int of_alias_get_id(const struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); bool of_machine_compatible_match(const char *const *compats); +bool of_machine_device_match(const struct of_device_id *matches); +const void *of_machine_get_match_data(const struct of_device_id *matches); /** * of_machine_is_compatible - Test root of device tree for a given compatible value @@ -855,6 +857,17 @@ static inline bool of_machine_compatible_match(const char *const *compats) return false; } +static inline bool of_machine_device_match(const struct of_device_id *matches) +{ + return false; +} + +static inline const void * +of_machine_get_match_data(const struct of_device_id *matches) +{ + return NULL; +} + static inline bool of_console_check(const struct device_node *dn, const char *name, int index) { return false; -- 2.48.1