]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_pmic.c
2 * Copyright (C) 2014-2015 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <dm/uclass-internal.h>
11 #include <power/pmic.h>
14 #define LIMIT_PARENT 20
16 static struct udevice
*currdev
;
18 static int failure(int ret
)
20 printf("Error: %d (%s)\n", ret
, errno_str(ret
));
22 return CMD_RET_FAILURE
;
25 static int do_dev(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
33 ret
= pmic_get(name
, &currdev
);
35 printf("Can't get PMIC: %s!\n", name
);
40 printf("PMIC device is not set!\n\n");
44 printf("dev: %d @ %s\n", currdev
->seq
, currdev
->name
);
47 return CMD_RET_SUCCESS
;
50 static int do_list(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
55 printf("| %-*.*s| %-*.*s| %s @ %s\n",
56 LIMIT_DEV
, LIMIT_DEV
, "Name",
57 LIMIT_PARENT
, LIMIT_PARENT
, "Parent name",
58 "Parent uclass", "seq");
60 for (ret
= uclass_first_device(UCLASS_PMIC
, &dev
); dev
;
61 ret
= uclass_next_device(&dev
)) {
65 printf("| %-*.*s| %-*.*s| %s @ %d\n",
66 LIMIT_DEV
, LIMIT_DEV
, dev
->name
,
67 LIMIT_PARENT
, LIMIT_PARENT
, dev
->parent
->name
,
68 dev_get_uclass_name(dev
->parent
), dev
->parent
->seq
);
72 return CMD_RET_FAILURE
;
74 return CMD_RET_SUCCESS
;
77 static int do_dump(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
85 printf("First, set the PMIC device!\n");
91 printf("Dump pmic: %s registers\n", dev
->name
);
93 for (reg
= 0; reg
< pmic_reg_count(dev
); reg
++) {
94 ret
= pmic_read(dev
, reg
, &value
, 1);
96 printf("Can't read register: %d\n", reg
);
101 printf("\n0x%02x: ", reg
);
103 printf("%2.2x ", value
);
107 return CMD_RET_SUCCESS
;
110 static int do_read(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
118 printf("First, set the PMIC device!\n");
119 return CMD_RET_USAGE
;
125 return CMD_RET_USAGE
;
127 reg
= simple_strtoul(argv
[1], NULL
, 0);
128 regs
= pmic_reg_count(dev
);
130 printf("PMIC max reg: %d\n", regs
);
131 return failure(-EFAULT
);
134 ret
= pmic_read(dev
, reg
, &value
, 1);
136 printf("Can't read PMIC register: %d!\n", reg
);
140 printf("0x%02x: 0x%2.2x\n", reg
, value
);
142 return CMD_RET_SUCCESS
;
145 static int do_write(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
153 printf("First, set the PMIC device!\n");
154 return CMD_RET_USAGE
;
160 return CMD_RET_USAGE
;
162 reg
= simple_strtoul(argv
[1], NULL
, 0);
163 regs
= pmic_reg_count(dev
);
165 printf("PMIC max reg: %d\n", regs
);
166 return failure(-EFAULT
);
169 value
= simple_strtoul(argv
[2], NULL
, 0);
171 ret
= pmic_write(dev
, reg
, &value
, 1);
173 printf("Can't write PMIC register: %d!\n", reg
);
177 return CMD_RET_SUCCESS
;
180 static cmd_tbl_t subcmd
[] = {
181 U_BOOT_CMD_MKENT(dev
, 2, 1, do_dev
, "", ""),
182 U_BOOT_CMD_MKENT(list
, 1, 1, do_list
, "", ""),
183 U_BOOT_CMD_MKENT(dump
, 1, 1, do_dump
, "", ""),
184 U_BOOT_CMD_MKENT(read
, 2, 1, do_read
, "", ""),
185 U_BOOT_CMD_MKENT(write
, 3, 1, do_write
, "", ""),
188 static int do_pmic(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
196 cmd
= find_cmd_tbl(argv
[0], subcmd
, ARRAY_SIZE(subcmd
));
197 if (cmd
== NULL
|| argc
> cmd
->maxargs
)
198 return CMD_RET_USAGE
;
200 return cmd
->cmd(cmdtp
, flag
, argc
, argv
);
203 U_BOOT_CMD(pmic
, CONFIG_SYS_MAXARGS
, 1, do_pmic
,
205 "list - list pmic devices\n"
206 "pmic dev [name] - show or [set] operating PMIC device\n"
207 "pmic dump - dump registers\n"
208 "pmic read address - read byte of register at address\n"
209 "pmic write address - write byte to register at address\n"