From 201efb2bb0f7c4ae5f08f51b6f6b7cdfdba5b4f4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 5 Jul 2021 16:32:49 -0600 Subject: 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 --- drivers/misc/cros_ec.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'drivers/misc') diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 7904d5cc72d..0818ef8ad6e 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", -- cgit v1.3.1 From 1e465eb6698e294e8fa9ed41165483b88062396a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 5 Jul 2021 16:32:50 -0600 Subject: cros_ec: Drop cros_ec_entering_mode() This function is not needed anymore. Drop it. Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 11 ----------- drivers/misc/cros_ec_sandbox.c | 3 --- include/cros_ec.h | 9 --------- 3 files changed, 23 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 0818ef8ad6e..2a15094d20a 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -754,17 +754,6 @@ int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask, return 0; } -int cros_ec_entering_mode(struct udevice *dev, int mode) -{ - int rc; - - rc = ec_command(dev, EC_CMD_ENTERING_MODE, 0, &mode, sizeof(mode), - NULL, 0); - if (rc) - return -1; - return 0; -} - static int cros_ec_check_version(struct udevice *dev) { struct cros_ec_dev *cdev = dev_get_uclass_priv(dev); diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index beea47caa33..ab91f3fa67a 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -496,9 +496,6 @@ static int process_cmd(struct ec_state *ec, case EC_CMD_MKBP_STATE: len = cros_ec_keyscan(ec, resp_data); break; - case EC_CMD_ENTERING_MODE: - len = 0; - break; case EC_CMD_GET_NEXT_EVENT: { struct ec_response_get_next_event *resp = resp_data; diff --git a/include/cros_ec.h b/include/cros_ec.h index 9dab6cdf9ba..ef89deff762 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -198,15 +198,6 @@ int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask, uint32_t set_flags, struct ec_response_flash_protect *resp); -/** - * Notify EC of current boot mode - * - * @param dev CROS-EC device - * @param vboot_mode Verified boot mode - * @return 0 if ok, <0 on error - */ -int cros_ec_entering_mode(struct udevice *dev, int mode); - /** * Run internal tests on the cros_ec interface. * -- cgit v1.3.1 From 656d7447705550af0b464e7f6bc10fc1547e69ee Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 5 Jul 2021 16:32:51 -0600 Subject: cros_ec: Support the full-size vboot context The v2 format is 64-bytes in size. Support this and drop v1 since it is not used anymore. Signed-off-by: Simon Glass --- drivers/misc/cros_ec_sandbox.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index ab91f3fa67a..12cc11efbd0 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -343,15 +343,13 @@ static int process_cmd(struct ec_state *ec, switch (req->op) { case EC_VBNV_CONTEXT_OP_READ: - /* TODO(sjg@chromium.org): Support full-size context */ memcpy(resp->block, ec->vbnv_context, - EC_VBNV_BLOCK_SIZE); - len = 16; + EC_VBNV_BLOCK_SIZE_V2); + len = EC_VBNV_BLOCK_SIZE_V2; break; case EC_VBNV_CONTEXT_OP_WRITE: - /* TODO(sjg@chromium.org): Support full-size context */ memcpy(ec->vbnv_context, req->block, - EC_VBNV_BLOCK_SIZE); + EC_VBNV_BLOCK_SIZE_V2); len = 0; break; default: -- cgit v1.3.1 From 56dae9ef3c56a7de6ed4af5efb82e661329d4738 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 5 Jul 2021 16:32:52 -0600 Subject: cros_ec: Use standard calls for recovery-request checking Rather than calling directly into the sandbox SDL code, we can use the normal U-Boot console handling for this feature. Update the code, to make it more generic. Signed-off-by: Simon Glass --- drivers/misc/cros_ec_sandbox.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 12cc11efbd0..2173517cff3 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -624,15 +624,19 @@ void cros_ec_check_keyboard(struct udevice *dev) struct ec_state *ec = dev_get_priv(dev); ulong start; - printf("Press keys for EC to detect on reset (ESC=recovery)..."); + printf("\nPress keys for EC to detect on reset (ESC=recovery)..."); start = get_timer(0); - while (get_timer(start) < 1000) - ; - putc('\n'); - if (!sandbox_sdl_key_pressed(KEY_ESC)) { - ec->recovery_req = true; - printf(" - EC requests recovery\n"); + while (get_timer(start) < 2000) { + if (tstc()) { + int ch = getchar(); + + if (ch == 0x1b) { + ec->recovery_req = true; + printf("EC requests recovery"); + } + } } + putc('\n'); } /* Return the byte of EC switch states */ -- cgit v1.3.1