Skip to content

Commit e2b01a3

Browse files
bbilasfabiobaltieri
authored andcommitted
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 <[email protected]>
1 parent ea0a554 commit e2b01a3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/regulator/regulator_shell.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,38 @@ static int cmd_vget(const struct shell *sh, size_t argc, char **argv)
221221
return 0;
222222
}
223223

224+
static int cmd_clist(const struct shell *sh, size_t argc, char **argv)
225+
{
226+
const struct device *dev;
227+
unsigned int current_cnt;
228+
int32_t last_current_ua;
229+
230+
ARG_UNUSED(argc);
231+
232+
dev = device_get_binding(argv[1]);
233+
if (dev == NULL) {
234+
shell_error(sh, "Regulator device %s not available", argv[1]);
235+
return -ENODEV;
236+
}
237+
238+
current_cnt = regulator_count_current_limits(dev);
239+
240+
for (unsigned int i = 0U; i < current_cnt; i++) {
241+
int32_t current_ua;
242+
243+
(void)regulator_list_current_limit(dev, i, &current_ua);
244+
245+
/* do not print repeated current limits */
246+
if ((i == 0U) || (last_current_ua != current_ua)) {
247+
microtoshell(sh, 'A', current_ua);
248+
}
249+
250+
last_current_ua = current_ua;
251+
}
252+
253+
return 0;
254+
}
255+
224256
static int cmd_iset(const struct shell *sh, size_t argc, char **argv)
225257
{
226258
const struct device *dev;
@@ -449,6 +481,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
449481
"Get voltage\n"
450482
"Usage: vget <device>",
451483
cmd_vget, 2, 0),
484+
SHELL_CMD_ARG(clist, &dsub_device_name,
485+
"List all supported current limits\n"
486+
"Usage: clist <device>",
487+
cmd_clist, 2, 0),
452488
SHELL_CMD_ARG(iset, &dsub_device_name,
453489
"Set current limit\n"
454490
"Input requires units, e.g. 200ma, 20.5ma, 10ua, 1a...\n"

0 commit comments

Comments
 (0)