[PATCH 02/10] commands: regulator: add support for enabling/disabling regulators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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, &regulator_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, &regulator_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, &regulator_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);
+
+	printf("Unknown operation '%s'\n", argv[optind]);
+
+	return COMMAND_ERROR_USAGE;
 }
 
+BAREBOX_CMD_HELP_START(regulator)
+BAREBOX_CMD_HELP_TEXT("List and control regulators.")
+BAREBOX_CMD_HELP_TEXT("Without a parameter, displays available regulators.")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-r REGULATOR\t", "regulator name")
+BAREBOX_CMD_HELP_END
+
 BAREBOX_CMD_START(regulator)
 	.cmd		= do_regulator,
-	BAREBOX_CMD_DESC("list regulators")
-	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+	BAREBOX_CMD_DESC("list and control regulators")
+	BAREBOX_CMD_OPTS("[-r REGULATOR] [enable | disable]")
+	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+	BAREBOX_CMD_HELP(cmd_regulator_help)
 BAREBOX_CMD_END
 
 #endif
-- 
2.24.0.rc1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux