mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lukasz Luba <lukasz.luba@arm.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Samuel Holland" <samuel@sholland.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Saravana Kannan" <saravanak@google.com>,
	"Jonathan Hunter" <jonathanh@nvidia.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Daniel Lezcano" <daniel.lezcano@kernel.org>,
	"Hans de Goede" <hansg@kernel.org>,
	"Maximilian Luz" <luzmaximilian@gmail.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Bjorn Andersson" <andersson@kernel.org>,
	"Daniel Lezcano" <daniel.lezcano@linaro.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	linux-pm@vger.kernel.org,
	"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Chen-Yu Tsai" <wens@kernel.org>,
	"Yangtao Li" <tiny.windzz@gmail.com>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>,
	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,
	"Konrad Dybcio" <konradybcio@kernel.org>
Subject: Re: [PATCH v2 01/11] of: Add wrappers to match root node with OF device ID tables
Date: Thu, 13 Nov 2025 09:55:09 +0000	[thread overview]
Message-ID: <d0238361-8953-4f08-8c04-bacaf0465366@arm.com> (raw)
In-Reply-To: <20251112-b4-of-match-matchine-data-v2-1-d46b72003fd6@linaro.org>

Hi Krzysztof,

On 11/12/25 10:28, Krzysztof Kozlowski wrote:
> 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 <angelogioacchino.delregno@collabora.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> 
> 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;
> 

Makes sense based on the clean-up in dtpm.c (since I've been there
I looked here as well).

LGTM

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

Regards,
Lukasz

  reply	other threads:[~2025-11-13  9:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12 10:28 [PATCH v2 00/11] " Krzysztof Kozlowski
2025-11-12 10:28 ` [PATCH v2 01/11] " Krzysztof Kozlowski
2025-11-13  9:55   ` Lukasz Luba [this message]
2025-12-02 14:07   ` Geert Uytterhoeven
2025-11-12 10:28 ` [PATCH v2 02/11] cpufreq: dt-platdev: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
2025-11-12 11:44   ` AngeloGioacchino Del Regno
2025-12-02 13:56   ` Geert Uytterhoeven
2025-11-12 10:28 ` [PATCH v2 03/11] cpufreq: mediatek: " Krzysztof Kozlowski
2025-11-12 11:44   ` AngeloGioacchino Del Regno
2025-11-12 10:28 ` [PATCH v2 04/11] cpufreq: sun50i: Simplify with of_machine_device_match() Krzysztof Kozlowski
2025-11-12 10:28 ` [PATCH v2 05/11] cpuidle: big_little: " Krzysztof Kozlowski
2025-11-12 11:44   ` AngeloGioacchino Del Regno
2025-11-12 10:28 ` [PATCH v2 06/11] firmware: qcom: scm: " Krzysztof Kozlowski
2025-11-12 11:44   ` AngeloGioacchino Del Regno
2025-11-12 10:28 ` [PATCH v2 07/11] irqchip/atmel-aic: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
2025-11-12 13:06   ` Alexandre Belloni
2025-11-12 10:28 ` [PATCH v2 08/11] platform: surface: " Krzysztof Kozlowski
2025-11-12 10:28 ` [PATCH v2 09/11] powercap: dtpm: " Krzysztof Kozlowski
2025-11-13  9:50   ` Lukasz Luba
2025-11-12 10:28 ` [PATCH v2 10/11] soc: qcom: ubwc: " Krzysztof Kozlowski
2025-11-12 10:28 ` [PATCH v2 11/11] soc: tegra: Simplify with of_machine_device_match() Krzysztof Kozlowski
2025-11-12 11:44   ` AngeloGioacchino Del Regno
2025-11-14 13:17   ` Thierry Reding
2025-11-12 11:52 ` [PATCH v2 00/11] of: Add wrappers to match root node with OF device ID tables AngeloGioacchino Del Regno
2025-11-14 13:24   ` Thierry Reding
2025-11-27  1:55 ` Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d0238361-8953-4f08-8c04-bacaf0465366@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andersson@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=daniel.lezcano@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=konradybcio@kernel.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=luzmaximilian@gmail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=samuel@sholland.org \
    --cc=saravanak@google.com \
    --cc=tglx@linutronix.de \
    --cc=thierry.reding@gmail.com \
    --cc=tiny.windzz@gmail.com \
    --cc=viresh.kumar@linaro.org \
    --cc=wens@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®