summaryrefslogtreecommitdiffstats
path: root/commands/regulator.c
blob: 3e38b616469f251d91b4e41f2122b87df0b93149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: © 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix

/* regulator command */

#include <common.h>
#include <command.h>
#include <regulator.h>
#include <getopt.h>

static int do_regulator(int argc, char *argv[])
{
	struct regulator *chosen;
	unsigned flags = 0;
	int opt, ret;

	while ((opt = getopt(argc, argv, "e:d:D")) > 0) {
		switch (opt) {
		case 'e':
		case 'd':
			chosen = regulator_get_name(optarg);
			if (IS_ERR_OR_NULL(chosen)) {
				printf("regulator not found\n");
				return COMMAND_ERROR;
			}

			ret = opt == 'e' ? regulator_enable(chosen)
				         : regulator_disable(chosen);
			regulator_put(chosen);
			return ret;
		case 'D':
			flags |= REGULATOR_PRINT_DEVS;
			break;
		default:
			return COMMAND_ERROR_USAGE;
		}
	}

	regulators_print(flags);
	return 0;
}

BAREBOX_CMD_HELP_START(regulator)
	BAREBOX_CMD_HELP_TEXT("List and control regulators.")
	BAREBOX_CMD_HELP_TEXT("Without options, displays regulator info")
	BAREBOX_CMD_HELP_TEXT("Options:")
	BAREBOX_CMD_HELP_OPT("-e REGULATOR\t", "enable REGULATOR")
	BAREBOX_CMD_HELP_OPT("-d REGULATOR\t", "disable REGULATOR")
	BAREBOX_CMD_HELP_OPT("-D\t", "list provider devices of regulators")
BAREBOX_CMD_HELP_END

BAREBOX_CMD_START(regulator)
	.cmd		= do_regulator,
	BAREBOX_CMD_DESC("list and control regulators")
	BAREBOX_CMD_OPTS("[-edD] [REGULATOR]")
	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
	BAREBOX_CMD_HELP(cmd_regulator_help)
BAREBOX_CMD_END