Skip to content

Commit

Permalink
drivers: regulator: shell: make use of the new regulator current limi…
Browse files Browse the repository at this point in the history
…ts 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 <b.bilas@grinn-global.com>
  • Loading branch information
bbilas committed Oct 27, 2023
1 parent 403cd45 commit 29a862b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions drivers/regulator/regulator_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &current_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;
Expand Down Expand Up @@ -449,6 +481,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
"Get voltage\n"
"Usage: vget <device>",
cmd_vget, 2, 0),
SHELL_CMD_ARG(clist, &dsub_device_name,
"List all supported current limits\n"
"Usage: clist <device>",
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"
Expand Down

0 comments on commit 29a862b

Please sign in to comment.