public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
To: Benjamin Gaignard <benjamin.gaignard@st.com>,
	agx@sigxcpu.org, yannick.fertre@st.com
Cc: dmitry.torokhov@gmail.com, robh+dt@kernel.org,
	mark.rutland@arm.com, hadess@hadess.net, frowand.list@gmail.com,
	m.felsch@pengutronix.de, arnd@arndb.de,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com, broonie@kernel.org,
	Linux PM <linux-pm@vger.kernel.org>
Subject: Re: [PATCH 1/5] of/device: Add of_ functions for device_link_{add,remove}
Date: Wed, 24 Apr 2019 15:06:52 +0200	[thread overview]
Message-ID: <d038f078-08dc-41ff-edc2-12f37d88a8a3@intel.com> (raw)
In-Reply-To: <20190424101913.1534-2-benjamin.gaignard@st.com>

On 4/24/2019 12:19 PM, Benjamin Gaignard wrote:
> Allows to create and remove links between consumer and suppliers from
> device-tree data. Use 'links-add' property from consumer node to setup
> a link with a list of suppliers.

One immediate question about this one is why stateless links are better 
here?

> Consumers will be suspend before their suppliers and resume after them.
>
> Add devm_of_device_links_add() to automatically remove the links
> when the device is unbound from the bus.

And this might not be necessary even with managed links.

> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@st.com>
> ---
>   drivers/of/device.c       | 103 ++++++++++++++++++++++++++++++++++++++++++++++
>   include/linux/of_device.h |  20 +++++++++
>   2 files changed, 123 insertions(+)
>
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 3717f2a20d0d..011ba9bf7642 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -336,3 +336,106 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
>   	return 0;
>   }
>   EXPORT_SYMBOL_GPL(of_device_uevent_modalias);
> +
> +/**
> + * of_device_links_add - Create links between consumer and suppliers from
> + * device tree data
> + *
> + * @consumer: consumer device
> + *
> + * Returns 0 on success, < 0 on failure.
> + */
> +int of_device_links_add(struct device *consumer)
> +{
> +	struct device_node *np;
> +	struct platform_device *pdev;
> +	int i = 0;
> +
> +	np = of_parse_phandle(consumer->of_node, "links-add", i++);
> +	while (np) {
> +		pdev = of_find_device_by_node(np);
> +		of_node_put(np);
> +		if (!pdev)
> +			return -EINVAL;
> +
> +		device_link_add(consumer, &pdev->dev, DL_FLAG_STATELESS);
> +		platform_device_put(pdev);
> +
> +		np = of_parse_phandle(consumer->of_node, "links-add", i++);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_device_links_add);
> +
> +/**
> + * of_device_links_remove - Remove links between consumer and suppliers from
> + * device tree data
> + *
> + * @consumer: consumer device
> + *
> + * Returns 0 on success, < 0 on failure.
> + */
> +int of_device_links_remove(struct device *consumer)
> +{
> +	struct device_node *np;
> +	struct platform_device *pdev;
> +	int i = 0;
> +
> +	np = of_parse_phandle(consumer->of_node, "links-add", i++);
> +	while (np) {
> +		pdev = of_find_device_by_node(np);
> +		of_node_put(np);
> +		if (!pdev)
> +			return -EINVAL;
> +
> +		device_link_remove(consumer, &pdev->dev);
> +		platform_device_put(pdev);
> +
> +		np = of_parse_phandle(consumer->of_node, "links-add", i++);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_device_links_remove);
> +
> +static void devm_of_device_links_remove(struct device *dev, void *res)
> +{
> +	of_device_links_remove(*(struct device **)res);
> +}
> +
> +/**
> + * devm_of_device_links_add - Create links between consumer and suppliers
> + * from device tree data
> + *
> + * @consumer: consumer device
> + *
> + * Returns 0 on success, < 0 on failure.
> + *
> + * Similar to of_device_links_add(), but will automatically call
> + * of_device_links_remove() when the device is unbound from the bus.
> + */
> +int devm_of_device_links_add(struct device *consumer)
> +{
> +		struct device **ptr;
> +	int ret;
> +
> +	if (!consumer)
> +		return -EINVAL;
> +
> +	ptr = devres_alloc(devm_of_device_links_remove,
> +			   sizeof(*ptr), GFP_KERNEL);
> +	if (!ptr)
> +		return -ENOMEM;
> +
> +	ret = of_device_links_add(consumer);
> +	if (ret < 0) {
> +		devres_free(ptr);
> +	} else {
> +		*ptr = consumer;
> +		devres_add(consumer, ptr);
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(devm_of_device_links_add);
> diff --git a/include/linux/of_device.h b/include/linux/of_device.h
> index 8d31e39dd564..ad01db6828e8 100644
> --- a/include/linux/of_device.h
> +++ b/include/linux/of_device.h
> @@ -41,6 +41,11 @@ extern int of_device_request_module(struct device *dev);
>   extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
>   extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env);
>   
> +
> +extern int of_device_links_add(struct device *consumer);
> +extern int of_device_links_remove(struct device *consumer);
> +extern int devm_of_device_links_add(struct device *consumer);
> +
>   static inline void of_device_node_put(struct device *dev)
>   {
>   	of_node_put(dev->of_node);
> @@ -91,6 +96,21 @@ static inline int of_device_uevent_modalias(struct device *dev,
>   	return -ENODEV;
>   }
>   
> +static int of_device_links_add(struct device *consumer)
> +{
> +	return 0;
> +}
> +
> +static int of_device_links_remove(struct device *consumer)
> +{
> +	return 0;
> +}
> +
> +static int devm_of_device_links_add(struct device *consumer)
> +{
> +	return 0;
> +}
> +
>   static inline void of_device_node_put(struct device *dev) { }
>   
>   static inline const struct of_device_id *__of_match_device(

  reply	other threads:[~2019-04-24 13:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 10:19 [PATCH 0/5] Add of_ functions for device_link_add() Benjamin Gaignard
2019-04-24 10:19 ` [PATCH 1/5] of/device: Add of_ functions for device_link_{add,remove} Benjamin Gaignard
2019-04-24 13:06   ` Rafael J. Wysocki [this message]
2019-04-24 13:39     ` Benjamin GAIGNARD
2019-04-24 10:19 ` [PATCH 2/5] Input: edt-ft5x06: Document links-add property Benjamin Gaignard
2019-04-24 10:19 ` [PATCH 3/5] input: edt-ft5x06 - Call devm_of_device_links_add() to create links Benjamin Gaignard
2019-04-24 22:52   ` Dmitry Torokhov
2019-04-25  7:22     ` Benjamin GAIGNARD
2019-04-24 10:19 ` [PATCH 4/5] Input: goodix: Document links-add property Benjamin Gaignard
2019-04-24 10:19 ` [PATCH 5/5] input: goodix - Call devm_of_device_links_add() to create links Benjamin Gaignard
2019-04-25 18:07 ` [PATCH 0/5] Add of_ functions for device_link_add() Rob Herring
2019-04-25 19:24   ` Dmitry Torokhov
2019-04-25 23:02     ` Rob Herring
2019-04-26  8:36       ` Benjamin GAIGNARD

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=d038f078-08dc-41ff-edc2-12f37d88a8a3@intel.com \
    --to=rafael.j.wysocki@intel.com \
    --cc=agx@sigxcpu.org \
    --cc=arnd@arndb.de \
    --cc=benjamin.gaignard@st.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=hadess@hadess.net \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=m.felsch@pengutronix.de \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=yannick.fertre@st.com \
    /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