mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] commands: regulator: add option to list provider devices
Date: Tue, 5 Dec 2023 08:47:43 +0100	[thread overview]
Message-ID: <20231205074743.GG1057032@pengutronix.de> (raw)
In-Reply-To: <20231128153020.669750-1-a.fatoum@pengutronix.de>

On Tue, Nov 28, 2023 at 04:30:20PM +0100, Ahmad Fatoum wrote:
> Especially on SCMI boards, it isn't immediately clear if e.g. reg11 is
> supplied by a directly accessed regulator or by the secure world.
> 
> Give the regulator command a -D option to list devices that the
> regulator is associated with as well.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  commands/regulator.c     | 11 ++++++++---
>  drivers/regulator/core.c | 27 ++++++++++++++++++++-------
>  include/regulator.h      |  5 ++++-
>  3 files changed, 32 insertions(+), 11 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/commands/regulator.c b/commands/regulator.c
> index e6b2f4852db4..3e38b616469f 100644
> --- a/commands/regulator.c
> +++ b/commands/regulator.c
> @@ -11,9 +11,10 @@
>  static int do_regulator(int argc, char *argv[])
>  {
>  	struct regulator *chosen;
> +	unsigned flags = 0;
>  	int opt, ret;
>  
> -	while ((opt = getopt(argc, argv, "e:d:")) > 0) {
> +	while ((opt = getopt(argc, argv, "e:d:D")) > 0) {
>  		switch (opt) {
>  		case 'e':
>  		case 'd':
> @@ -27,12 +28,15 @@ static int do_regulator(int argc, char *argv[])
>  				         : regulator_disable(chosen);
>  			regulator_put(chosen);
>  			return ret;
> +		case 'D':
> +			flags |= REGULATOR_PRINT_DEVS;
> +			break;
>  		default:
>  			return COMMAND_ERROR_USAGE;
>  		}
>  	}
>  
> -	regulators_print();
> +	regulators_print(flags);
>  	return 0;
>  }
>  
> @@ -42,12 +46,13 @@ BAREBOX_CMD_HELP_START(regulator)
>  	BAREBOX_CMD_HELP_TEXT("Options:")
>  	BAREBOX_CMD_HELP_OPT("-e REGULATOR\t", "enable REGULATOR")
>  	BAREBOX_CMD_HELP_OPT("-d REGULATOR\t", "disable REGULATOR")
> +	BAREBOX_CMD_HELP_OPT("-D\t", "list provider devices of regulators")
>  BAREBOX_CMD_HELP_END
>  
>  BAREBOX_CMD_START(regulator)
>  	.cmd		= do_regulator,
>  	BAREBOX_CMD_DESC("list and control regulators")
> -	BAREBOX_CMD_OPTS("[-ed] [REGULATOR]")
> +	BAREBOX_CMD_OPTS("[-edD] [REGULATOR]")
>  	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
>  	BAREBOX_CMD_HELP(cmd_regulator_help)
>  BAREBOX_CMD_END
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index b20a48e0f63c..bbba3b0b5712 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -729,20 +729,32 @@ int regulator_get_voltage(struct regulator *regulator)
>  }
>  EXPORT_SYMBOL_GPL(regulator_get_voltage);
>  
> -static void regulator_print_one(struct regulator_dev *rdev, int level)
> +static int regulator_name_indent(unsigned flags)
>  {
> +	return 30 + (flags & REGULATOR_PRINT_DEVS ? 50 : 0);
> +}
> +
> +static void regulator_print_one(struct regulator_dev *rdev, int level, unsigned flags)
> +{
> +	const char *name = rdev->name;
>  	struct regulator *r;
> +	char buf[256];
>  
>  	if (!rdev)
>  		return;
>  
> +	if (flags & REGULATOR_PRINT_DEVS) {
> +		snprintf(buf, sizeof(buf), "%s  %s", dev_name(rdev->dev), rdev->name);
> +		name = buf;
> +	}
> +
>  	printf("%*s%-*s %6d %10d %10d\n", level * 3, "",
> -	       30 - level * 3,
> -	       rdev->name, rdev->enable_count, rdev->min_uv, rdev->max_uv);
> +	       regulator_name_indent(flags) - level * 3,
> +	       name, rdev->enable_count, rdev->min_uv, rdev->max_uv);
>  
>  	list_for_each_entry(r, &rdev->consumer_list, list) {
>  		if (r->rdev_consumer)
> -			regulator_print_one(r->rdev_consumer, level + 1);
> +			regulator_print_one(r->rdev_consumer, level + 1, flags);
>  		else
>  			printf("%*s%s\n", (level + 1) * 3, "", r->dev ? dev_name(r->dev) : "none");
>  	}
> @@ -751,13 +763,14 @@ static void regulator_print_one(struct regulator_dev *rdev, int level)
>  /*
>   * regulators_print - print informations about all regulators
>   */
> -void regulators_print(void)
> +void regulators_print(unsigned flags)
>  {
>  	struct regulator_dev *rdev;
>  
> -	printf("%-30s %6s %10s %10s\n", "name", "enable", "min_uv", "max_uv");
> +	printf("%-*s %6s %10s %10s\n", regulator_name_indent(flags),
> +	       "name", "enable", "min_uv", "max_uv");
>  	list_for_each_entry(rdev, &regulator_list, list) {
>  		if (!rdev->supply)
> -			regulator_print_one(rdev, 0);
> +			regulator_print_one(rdev, 0, flags);
>  	}
>  }
> diff --git a/include/regulator.h b/include/regulator.h
> index 240dbce5e7da..135fe6d91fd3 100644
> --- a/include/regulator.h
> +++ b/include/regulator.h
> @@ -2,6 +2,8 @@
>  #ifndef __REGULATOR_H
>  #define __REGULATOR_H
>  
> +#include <linux/bitops.h>
> +
>  struct device;
>  
>  /* struct regulator is an opaque object for consumers */
> @@ -155,7 +157,8 @@ static inline int of_regulator_register(struct regulator_dev *rd,
>  #endif
>  int dev_regulator_register(struct regulator_dev *rd, const char *name);
>  
> -void regulators_print(void);
> +#define REGULATOR_PRINT_DEVS	BIT(0)
> +void regulators_print(unsigned flags);
>  
>  const char *rdev_get_name(struct regulator_dev *rdev);
>  
> -- 
> 2.39.2
> 
> 
> 

-- 
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 |



      reply	other threads:[~2023-12-05  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 15:30 Ahmad Fatoum
2023-12-05  7:47 ` Sascha Hauer [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=20231205074743.GG1057032@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --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