From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, mgr@pengutronix.de
Subject: Re: [PATCH 02/10] commands: regulator: add support for enabling/disabling regulators
Date: Wed, 6 Nov 2019 10:44:59 +0100 [thread overview]
Message-ID: <20191106094459.w32tgsl22ty34vhe@pengutronix.de> (raw)
In-Reply-To: <20191106071155.26389-2-a.fatoum@pengutronix.de>
On Wed, Nov 06, 2019 at 08:11:47AM +0100, Ahmad Fatoum wrote:
> For testing regulator drivers, it can be handy to enable/disable them
> from the shell prompt. Extend the regulator command to support this.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/regulator/core.c | 67 +++++++++++++++++++++++++++++++++++-----
> 1 file changed, 60 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 591e44c15407..4ebad3f906ad 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -388,22 +388,75 @@ static void regulator_print_one(struct regulator_internal *ri)
> #include <common.h>
> #include <command.h>
> #include <regulator.h>
> +#include <getopt.h>
>
> static int do_regulator(int argc, char *argv[])
> {
> - struct regulator_internal *ri;
> + struct regulator_internal *ri, *chosen = NULL;
> + int opt;
>
> - printf("%-20s %6s %10s %10s\n", "name", "enable", "min_uv", "max_uv");
> - list_for_each_entry(ri, ®ulator_list, list)
> - regulator_print_one(ri);
> + if (argc == 1) {
> + printf("%-20s %6s %10s %10s\n", "name", "enable", "min_uv", "max_uv");
> + list_for_each_entry(ri, ®ulator_list, list)
> + regulator_print_one(ri);
>
> - return 0;
> + return 0;
> + }
> +
> + while ((opt = getopt(argc, argv, "r:")) > 0) {
> + switch (opt) {
> + case 'r':
> + if (chosen)
> + return COMMAND_ERROR_USAGE;
> +
> + list_for_each_entry(ri, ®ulator_list, list) {
> + if (!strcmp(ri->name, optarg)) {
> + chosen = ri;
> + break;
> + }
> + }
> +
> + break;
> + default:
> + return COMMAND_ERROR_USAGE;
> + }
> + }
> +
> +
> + if (!chosen) {
> + printf("regulator not found.\n");
> + return COMMAND_ERROR;
> + }
> +
> + if (argc != optind + 1) {
> + printf("Operation must be specified\n");
> + return COMMAND_ERROR_USAGE;
> + }
> +
> + if (!strcmp(argv[optind], "enable"))
> + return regulator_enable_internal(chosen);
> +
> + if (!strcmp(argv[optind], "disable"))
> + return regulator_disable_internal(chosen);
How about doing
-e <regulator>
-d <regulator>
or
-r <regulator> -e
-r <regulator> -d
I don't like these batteries of strcmp(argv[optind], ...) very much,
neither from the programming side nor from the usage of these commands.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-11-06 9:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-06 7:11 [PATCH 01/10] commands: regulator: move implementation to regulator core Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 02/10] commands: regulator: add support for enabling/disabling regulators Ahmad Fatoum
2019-11-06 9:44 ` Sascha Hauer [this message]
2019-11-06 7:11 ` [PATCH 03/10] regulator: copy upstream struct regulator_desc documentation Ahmad Fatoum
2019-11-06 10:24 ` Sascha Hauer
2019-11-06 7:11 ` [PATCH 04/10] regulator: port Linux of_regulator_match Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 05/10] regulator: import linear voltage range helpers Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 06/10] mfd: stpmic1: use dev_get_regmap instead of priv member Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 07/10] regulator: add driver for stpmic1-regulators Ahmad Fatoum
2019-11-06 7:29 ` [PATCH 11/10] fixup! " Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 08/10] ARM: dts: stm32mp157a-dk1: remove unnecessary sram node Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 09/10] ARM: stm32mp: enable STPMIC1 MFD and cell drivers Ahmad Fatoum
2019-11-06 7:11 ` [PATCH 10/10] Revert "ARM: dts: stm32mp157a-dk1: overwrite regulator for sdmmc node" Ahmad Fatoum
2019-11-06 9:39 ` [PATCH 01/10] commands: regulator: move implementation to regulator core Sascha Hauer
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=20191106094459.w32tgsl22ty34vhe@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=mgr@pengutronix.de \
/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