summaryrefslogtreecommitdiff
path: root/common/cmd_regul.c
blob: 9ac483c5d432e075ef1233d3bde7511dbf599a3d (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (C) 2012 Freescale Semiconductor, Inc.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <linux/types.h>
#include <command.h>
#include <common.h>
#include <asm/regulator.h>

int do_regulops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int rc = 0;
	int uv = 0;

	switch (argc) {
	case 2:
		if (strcmp(argv[1], "list") == 0)
			regul_list(0);
		else
			printf("Unsupported command: %s!\n", argv[1]);

		break;
	case 3:
		if (strcmp(argv[1], "show") == 0) {
			if (strcmp(argv[2], "all") == 0) {
				regul_list(1);
				break;
			} else if (strcmp(argv[2], "core") == 0)
				uv = regul_get_core();
			else if (strcmp(argv[2], "periph") == 0)
				uv = regul_get_periph();
			else
				uv = regul_get(argv[2]);

			if (uv >= 0) {
				printf("Name\t\tVoltage\n");
				printf("%s:\t\t%d\n", argv[2], uv);
			} else
				printf("Can't get regulator's voltage!\n");
		} else
			printf("Unsupported command: %s!\n", argv[1]);
		break;
	case 4:
		if (strcmp(argv[1], "set") == 0) {
			uv = simple_strtoul(argv[3], NULL, 10);
			if (strcmp(argv[2], "core") == 0)
				rc = regul_set_core(uv);
			else if (strcmp(argv[2], "periph") == 0)
				rc = regul_set_periph(uv);
			else
				rc = regul_set(argv[2], uv);

			if (!rc) {
				printf("Set voltage succeed!\n");
				printf("Name\t\tVoltage\n");
				printf("%s:\t\t%d\n", argv[2], uv);
			}
		} else
			printf("Unsupported command: %s!\n", argv[1]);
		break;
	default:
		rc = 1;
		printf("Too many or less parameters!\n");
		break;
	}

	return rc;
}

U_BOOT_CMD(
	regul, 4, 1, do_regulops,
	"Regulator sub system",
	"list - List all regulators' name\n"
	"regul show all "
	"- Display all regulators' voltage\n"
	"regul show core "
	"- Show core voltage in mV\n"
	"regul show periph "
	"- Show peripheral voltage in mV\n"
	"regul show <regulator name> "
	"- Show regulator's voltage in mV\n"
	"regul set core <voltage value> "
	"- Set core voltage in mV\n"
	"regul set periph <voltage value> "
	"- Set periph voltage in mV\n"
	"regul set <regulator name> <voltage value> "
	"- Set regulator's voltage in mV");