[U-Boot] [PATCH v6 21/26] pmic: Extend PMIC framework to support battery related commands
Lukasz Majewski
l.majewski at samsung.com
Fri Nov 9 08:42:26 CET 2012
Two extra commands:
"pmic name bat state" and "pmic name bat charge" has been added to
pmic framework. Those provides state display and charge capabilities
to named batteries.
The pmic_core.c file has been refactored to more consistent name scheme.
Signed-off-by: Lukasz Majewski <l.majewski at samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
Cc: Stefano Babic <sbabic at denx.de>
---
Changes for v2:
- New patch to v2.
Changes for v3:
- change code according to struct pmic redesign
Changes for v4:
- None
Changes for v5:
- None
Changes for v6:
- None
---
drivers/power/pmic_core.c | 51 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/drivers/power/pmic_core.c b/drivers/power/pmic_core.c
index 2908f66..01a240f 100644
--- a/drivers/power/pmic_core.c
+++ b/drivers/power/pmic_core.c
@@ -124,35 +124,46 @@ struct pmic *pmic_get(const char *s)
return NULL;
}
+const char *power_get_interface(int interface)
+{
+ const char *power_interface[] = {"I2C", "SPI", "|+|-|"};
+ return power_interface[interface];
+}
+
static void pmic_list_names(void)
{
struct pmic *p;
puts("PMIC devices:\n");
list_for_each_entry(p, &pmic_list, list) {
- printf("name: %s\n", p->name);
+ printf("name: %s bus: %s_%d\n", p->name,
+ power_get_interface(p->interface), p->bus);
}
}
int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
u32 ret, reg, val;
+ char *cmd, *name;
struct pmic *p;
- char *cmd;
/* at least two arguments please */
if (argc < 2)
return CMD_RET_USAGE;
- cmd = argv[1];
-
- if (strcmp(cmd, "list") == 0) {
+ if (strcmp(argv[1], "list") == 0) {
pmic_list_names();
return CMD_RET_SUCCESS;
}
+ name = argv[1];
+ cmd = argv[2];
+
+ debug("%s: name: %s cmd: %s\n", __func__, name, cmd);
+ p = pmic_get(name);
+
if (strcmp(cmd, "dump") == 0) {
- if (pmic_dump(pmic_get(argv[2])))
+ if (pmic_dump(p))
return CMD_RET_FAILURE;
return CMD_RET_SUCCESS;
}
@@ -162,7 +173,6 @@ int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return CMD_RET_USAGE;
reg = simple_strtoul(argv[3], NULL, 16);
- p = pmic_get(argv[2]);
ret = pmic_reg_read(p, reg, &val);
if (ret)
@@ -179,12 +189,31 @@ int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
reg = simple_strtoul(argv[3], NULL, 16);
val = simple_strtoul(argv[4], NULL, 16);
- p = pmic_get(argv[2]);
pmic_reg_write(p, reg, val);
return CMD_RET_SUCCESS;
}
+ if (strcmp(cmd, "bat") == 0) {
+ if (argc < 4)
+ return CMD_RET_USAGE;
+
+ if (strcmp(argv[3], "state") == 0)
+ p->fg->fg_battery_check(p->pbat->fg, p);
+
+ if (strcmp(argv[3], "charge") == 0) {
+ if (p->pbat) {
+ printf("PRINT BAT charge %s\n", p->name);
+ if (p->low_power_mode)
+ p->low_power_mode();
+ if (p->pbat->battery_charge)
+ p->pbat->battery_charge(p);
+ }
+ }
+
+ return CMD_RET_SUCCESS;
+ }
+
/* No subcommand found */
return CMD_RET_SUCCESS;
}
@@ -193,7 +222,9 @@ U_BOOT_CMD(
pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
"PMIC",
"list - list available PMICs\n"
- "pmic dump name - dump named PMIC registers\n"
+ "pmic name dump - dump named PMIC registers\n"
"pmic name read <reg> - read register\n"
- "pmic name write <reg> <value> - write register"
+ "pmic name write <reg> <value> - write register\n"
+ "pmic name bat state - write register\n"
+ "pmic name bat charge - write register\n"
);
--
1.7.2.3
More information about the U-Boot
mailing list