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@xxxxxxxxxxxxxx> > --- > 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@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox