mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@barebox.org>, barebox@lists.infradead.org
Subject: Re: [PATCH 1/5] regulator: implement dev_of_regulator_get
Date: Mon, 27 Oct 2025 13:27:39 +0100	[thread overview]
Message-ID: <458109fe-0d93-4b34-a985-231250b920b7@pengutronix.de> (raw)
In-Reply-To: <20251027065315.2419160-1-a.fatoum@barebox.org>

Hi,

On 10/27/25 7:53 AM, Ahmad Fatoum wrote:
> Regulators for a device need not be listed in the main node associated
> with a device. Export dev_of_regulator_get for these use cases to
> simplify porting Linux drivers.

This caused CI failures for some 32-bit targets, presumably ones without OF.

I'll respin.

Cheers,
Ahmad

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
> ---
>  drivers/regulator/core.c | 20 ++++++++++++--------
>  include/regulator.h      | 27 ++++++++++++++++++++++-----
>  2 files changed, 34 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index f18622cba80c..cd0795589403 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -329,7 +329,8 @@ int of_regulator_register(struct regulator_dev *rdev, struct device_node *node)
>  }
>  
>  static struct regulator_dev *of_regulator_get(struct device *dev,
> -						   const char *supply)
> +					      struct device_node *np,
> +					      const char *supply)
>  {
>  	char *propname;
>  	struct regulator_dev *rdev;
> @@ -339,7 +340,7 @@ static struct regulator_dev *of_regulator_get(struct device *dev,
>  	/*
>  	 * If the device does have a device node return the dummy regulator.
>  	 */
> -	if (!dev->of_node)
> +	if (!np)
>  		return NULL;
>  
>  	propname = basprintf("%s-supply", supply);
> @@ -348,7 +349,7 @@ static struct regulator_dev *of_regulator_get(struct device *dev,
>  	 * If the device node does not contain a supply property, this device doesn't
>  	 * need a regulator. Return the dummy regulator in this case.
>  	 */
> -	if (!of_get_property(dev->of_node, propname, NULL)) {
> +	if (!of_get_property(np, propname, NULL)) {
>  		dev_dbg(dev, "No %s-supply node found, using dummy regulator\n",
>  				supply);
>  		rdev = NULL;
> @@ -359,7 +360,7 @@ static struct regulator_dev *of_regulator_get(struct device *dev,
>  	 * The device node specifies a supply, so it's mandatory. Return an error when
>  	 * something goes wrong below.
>  	 */
> -	node = of_parse_phandle(dev->of_node, propname, 0);
> +	node = of_parse_phandle(np, propname, 0);
>  	if (!node) {
>  		dev_dbg(dev, "No %s node found\n", propname);
>  		rdev = ERR_PTR(-EINVAL);
> @@ -408,7 +409,8 @@ static struct regulator_dev *of_regulator_get(struct device *dev,
>  }
>  #else
>  static struct regulator_dev *of_regulator_get(struct device *dev,
> -						   const char *supply)
> +					      struct device_node *np,
> +					      const char *supply)
>  {
>  	return NULL;
>  }
> @@ -505,14 +507,16 @@ static struct regulator_dev *dev_regulator_get(struct device *dev,
>   *
>   * Return: a regulator object or an error pointer
>   */
> -struct regulator *regulator_get(struct device *dev, const char *supply)
> +struct regulator *dev_of_regulator_get(struct device *dev,
> +				       struct device_node *np,
> +				       const char *supply)
>  {
>  	struct regulator_dev *rdev = NULL;
>  	struct regulator *r;
>  	int ret;
>  
> -	if (dev->of_node && supply) {
> -		rdev = of_regulator_get(dev, supply);
> +	if (np && supply) {
> +		rdev = of_regulator_get(dev, np, supply);
>  		if (IS_ERR(rdev))
>  			return ERR_CAST(rdev);
>  	}
> diff --git a/include/regulator.h b/include/regulator.h
> index cb542b05c696..401cb8ba464e 100644
> --- a/include/regulator.h
> +++ b/include/regulator.h
> @@ -4,8 +4,7 @@
>  
>  #include <linux/bitops.h>
>  #include <linux/err.h>
> -
> -struct device;
> +#include <device.h>
>  
>  /* struct regulator is an opaque object for consumers */
>  struct regulator;
> @@ -212,7 +211,9 @@ const char *rdev_get_name(struct regulator_dev *rdev);
>  
>  #ifdef CONFIG_REGULATOR
>  
> -struct regulator *regulator_get(struct device *, const char *);
> +struct regulator *dev_of_regulator_get(struct device *dev,
> +				       struct device_node *np,
> +				       const char *supply);
>  void regulator_put(struct regulator *r);
>  struct regulator *regulator_get_name(const char *name);
>  int regulator_enable(struct regulator *);
> @@ -265,8 +266,9 @@ int regulator_list_voltage_table(struct regulator_dev *rdev,
>  				  unsigned int selector);
>  #else
>  
> -static inline struct regulator *regulator_get(struct device *dev,
> -					      const char *id)
> +struct regulator *dev_of_regulator_get(struct device *dev,
> +				       struct device_node *np,
> +				       const char *supply)
>  {
>  	return NULL;
>  }
> @@ -327,6 +329,21 @@ static inline int regulator_get_voltage(struct regulator *regulator)
>  
>  #endif
>  
> +/*
> + * regulator_get - get the supply for a device.
> + * @dev:	the device a supply is requested for
> + * @supply:     the supply name
> + *
> + * This returns a supply for a device. Check the result with IS_ERR().
> + * NULL is a valid regulator, the dummy regulator.
> + *
> + * Return: a regulator object or an error pointer
> + */
> +static inline struct regulator *regulator_get(struct device *dev, const char *id)
> +{
> +	return dev_of_regulator_get(dev, dev_of_node(dev), id);
> +}
> +
>  static inline struct regulator *regulator_get_optional(struct device *dev,
>  						       const char *id)
>  {

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




      parent reply	other threads:[~2025-10-27 12:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27  6:53 Ahmad Fatoum
2025-10-27  6:53 ` [PATCH 2/5] pmdomain: look up pmdomain even if not have_genpd_providers Ahmad Fatoum
2025-10-27  7:19   ` Ahmad Fatoum
2025-10-27  6:53 ` [PATCH 3/5] pmdomain: warn if deep probe enabled and driver missing Ahmad Fatoum
2025-10-27  6:53 ` [PATCH 4/5] pmdomain: allow callback for when devices are attached Ahmad Fatoum
2025-10-27  6:53 ` [PATCH 5/5] pmdomain: add Rockchip power domain support Ahmad Fatoum
2025-10-27 12:27 ` Ahmad Fatoum [this message]

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=458109fe-0d93-4b34-a985-231250b920b7@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.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