[PATCH] commands: regulator: add option to list provider devices
Sascha Hauer
sha at pengutronix.de
Mon Dec 4 23:47:43 PST 2023
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 at 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, ®ulator_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 |
More information about the barebox
mailing list