diff options
author | Simon Glass <sjg@chromium.org> | 2021-07-05 16:32:49 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-07-21 10:27:34 -0600 |
commit | 201efb2bb0f7c4ae5f08f51b6f6b7cdfdba5b4f4 (patch) | |
tree | 6026b80c95198250f84aa76701c47770f552948b /drivers/misc/cros_ec.c | |
parent | ecc1ed912e4400b19783d4bd384914597c4a3679 (diff) | |
download | u-boot-201efb2bb0f7c4ae5f08f51b6f6b7cdfdba5b4f4.tar.gz |
cros_ec: Allow reading the battery-charge state
Add a function to read this information from the EC. It is useful for
determining whether the battery has enough charge to boot.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/misc/cros_ec.c')
-rw-r--r-- | drivers/misc/cros_ec.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 7904d5cc72..0818ef8ad6 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1661,6 +1661,23 @@ int cros_ec_get_switches(struct udevice *dev) return ret; } +int cros_ec_read_batt_charge(struct udevice *dev, uint *chargep) +{ + struct ec_params_charge_state req; + struct ec_response_charge_state resp; + int ret; + + req.cmd = CHARGE_STATE_CMD_GET_STATE; + ret = ec_command(dev, EC_CMD_CHARGE_STATE, 0, &req, sizeof(req), + &resp, sizeof(resp)); + if (ret) + return log_msg_ret("read", ret); + + *chargep = resp.get_state.batt_state_of_charge; + + return 0; +} + UCLASS_DRIVER(cros_ec) = { .id = UCLASS_CROS_EC, .name = "cros-ec", |