diff options
author | Vic Yang <victoryang@chromium.org> | 2013-09-10 15:42:27 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-10 19:40:08 +0000 |
commit | 462133fea54e7a3c27af23373105bf2f673e37e9 (patch) | |
tree | c825e4f1f674fe135610932a62b7fab6b59f4dcd | |
parent | db0b93609bdad2a5700a687b0d1292a727ea1354 (diff) | |
download | chrome-ec-462133fea54e7a3c27af23373105bf2f673e37e9.tar.gz |
Generalize 'charger' command to support BQ24192
This changes 'charger' to report '(unsupported)' when charger module
returns EC_ERROR_UNIMPLEMENTED, and continues even when there is an
error.
BUG=chrome-os-partner:22238
TEST=Run 'charger' command and check values are correct.
BRANCH=None
Change-Id: I5193ec436a10b2c3cbcc4013c846a7bea515864d
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168734
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/charger_common.c | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/common/charger_common.c b/common/charger_common.c index 0c86a73156..4d025f532c 100644 --- a/common/charger_common.c +++ b/common/charger_common.c @@ -44,56 +44,63 @@ int charger_closest_current(int current) return current - (current % info->current_step); } +static void print_item_name(const char *name) +{ + ccprintf(" %-8s", name); +} + +static int check_print_error(int rv) +{ + if (rv == EC_SUCCESS) + return 1; + ccputs(rv == EC_ERROR_UNIMPLEMENTED ? "(unsupported)\n" : "(error)\n"); + return 0; +} + static int print_info(void) { - int rv; int d; - const struct charger_info *info; + const struct charger_info *info = charger_get_info(); /* info */ - info = charger_get_info(); - ccprintf("Name : %s\n", info->name); + print_item_name("Name:"); + ccprintf("%s\n", info->name); /* option */ - rv = charger_get_option(&d); - if (rv) - return rv; - ccprintf("Option: %016b (0x%04x)\n", d, d); + print_item_name("Option:"); + if (check_print_error(charger_get_option(&d))) + ccprintf("%016b (0x%04x)\n", d, d); /* manufacturer id */ - rv = charger_manufacturer_id(&d); - if (rv) - return rv; - ccprintf("Man id: 0x%04x\n", d); + print_item_name("Man id:"); + if (check_print_error(charger_manufacturer_id(&d))) + ccprintf("0x%04x\n", d); /* device id */ - rv = charger_device_id(&d); - if (rv) - return rv; - ccprintf("Dev id: 0x%04x\n", d); + print_item_name("Dev id:"); + if (check_print_error(charger_device_id(&d))) + ccprintf("0x%04x\n", d); /* charge voltage limit */ - rv = charger_get_voltage(&d); - if (rv) - return rv; - ccprintf("V_batt: %5d (%4d - %5d, %3d)\n", d, - info->voltage_min, info->voltage_max, info->voltage_step); + print_item_name("V_batt:"); + if (check_print_error(charger_get_voltage(&d))) + ccprintf("%5d (%4d - %5d, %3d)\n", d, + info->voltage_min, info->voltage_max, + info->voltage_step); /* charge current limit */ - rv = charger_get_current(&d); - if (rv) - return rv; - ccprintf("I_batt: %5d (%4d - %5d, %3d)\n", d, - info->current_min, info->current_max, info->current_step); + print_item_name("I_batt:"); + if (check_print_error(charger_get_current(&d))) + ccprintf("%5d (%4d - %5d, %3d)\n", d, + info->current_min, info->current_max, + info->current_step); /* input current limit */ - rv = charger_get_input_current(&d); - if (rv) - return rv; - - ccprintf("I_in : %5d (%4d - %5d, %3d)\n", d, - info->input_current_min, info->input_current_max, - info->input_current_step); + print_item_name("I_in:"); + if (check_print_error(charger_get_input_current(&d))) + ccprintf("%5d (%4d - %5d, %3d)\n", d, + info->input_current_min, info->input_current_max, + info->input_current_step); return EC_SUCCESS; } |