Skip to content

Commit

Permalink
drivers: regulator: shell: add is_enabled cmd
Browse files Browse the repository at this point in the history
Reports whether regulator is enabled or disabled

Signed-off-by: Mike J. Chen <[email protected]>
  • Loading branch information
mjchen0 authored and aescolar committed May 1, 2024
1 parent 5176324 commit 40a8022
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions drivers/regulator/regulator_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ static int cmd_disable(const struct shell *sh, size_t argc, char **argv)
return 0;
}

static int cmd_is_enabled(const struct shell *sh, size_t argc, char **argv)
{
const struct device *dev;

ARG_UNUSED(argc);

dev = device_get_binding(argv[1]);
if (dev == NULL) {
shell_error(sh, "Regulator device %s not available", argv[1]);
return -ENODEV;
}

if (regulator_is_enabled(dev)) {
shell_print(sh, "Regulator is enabled");
} else {
shell_print(sh, "Regulator is disabled");
}

return 0;
}

static int cmd_vlist(const struct shell *sh, size_t argc, char **argv)
{
const struct device *dev;
Expand Down Expand Up @@ -524,6 +545,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
"Disable regulator\n"
"Usage: disable <device>",
cmd_disable, 2, 0),
SHELL_CMD_ARG(is_enabled, &dsub_device_name,
"Report whether regulator is enabled or disabled\n"
"Usage: is_enabled <device>",
cmd_is_enabled, 2, 0),
SHELL_CMD_ARG(vlist, &dsub_device_name,
"List all supported voltages\n"
"Usage: vlist <device>",
Expand Down

0 comments on commit 40a8022

Please sign in to comment.