From e2b01a3c48326884b71928afe12e3dd7ac242517 Mon Sep 17 00:00:00 2001 From: Bartosz Bilas Date: Fri, 27 Oct 2023 19:49:51 +0200 Subject: [PATCH] drivers: regulator: shell: make use of the regulator current limits support Add a new `clist` regulator shell subcommand that prints the list of supported current limits for specified regulator device. Signed-off-by: Bartosz Bilas --- drivers/regulator/regulator_shell.c | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/regulator/regulator_shell.c b/drivers/regulator/regulator_shell.c index 4caaa9f8815..74aa1f22ca6 100644 --- a/drivers/regulator/regulator_shell.c +++ b/drivers/regulator/regulator_shell.c @@ -221,6 +221,38 @@ static int cmd_vget(const struct shell *sh, size_t argc, char **argv) return 0; } +static int cmd_clist(const struct shell *sh, size_t argc, char **argv) +{ + const struct device *dev; + unsigned int current_cnt; + int32_t last_current_ua; + + ARG_UNUSED(argc); + + dev = device_get_binding(argv[1]); + if (dev == NULL) { + shell_error(sh, "Regulator device %s not available", argv[1]); + return -ENODEV; + } + + current_cnt = regulator_count_current_limits(dev); + + for (unsigned int i = 0U; i < current_cnt; i++) { + int32_t current_ua; + + (void)regulator_list_current_limit(dev, i, ¤t_ua); + + /* do not print repeated current limits */ + if ((i == 0U) || (last_current_ua != current_ua)) { + microtoshell(sh, 'A', current_ua); + } + + last_current_ua = current_ua; + } + + return 0; +} + static int cmd_iset(const struct shell *sh, size_t argc, char **argv) { const struct device *dev; @@ -449,6 +481,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE( "Get voltage\n" "Usage: vget ", cmd_vget, 2, 0), + SHELL_CMD_ARG(clist, &dsub_device_name, + "List all supported current limits\n" + "Usage: clist ", + cmd_clist, 2, 0), SHELL_CMD_ARG(iset, &dsub_device_name, "Set current limit\n" "Input requires units, e.g. 200ma, 20.5ma, 10ua, 1a...\n"