diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2021-02-11 15:52:53 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-12 16:51:08 +0000 |
commit | de9fd43a3ffffa4e4c9e7c12bc0be40860b7b293 (patch) | |
tree | 115e22ec66a2beaa5cc3875419b2012747177e38 /common/peripheral_charger.c | |
parent | 914a3266dc25ff00e2ca171827f1e94cb5e8c5e9 (diff) | |
download | chrome-ec-de9fd43a3ffffa4e4c9e7c12bc0be40860b7b293.tar.gz |
PCHG: Get SOC proactively when device is detected
This patch makes PCHG send CHG_CTRL_CHARGING_INFO_CMD when a stylus
is detected. This will allow the EC to report 'full' to the host
even if charging doesn't start (because the stylus is already
charged).
BUG=b:179390065,b:173235954
BRANCH=trogdor
TEST=CoachZ. Re-attach charged stylus and verify PCHG_STATE_FULL
is reported.
Change-Id: Id8578e2d3d21294fb08a21933f12ecee7f2bd062
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2691729
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/peripheral_charger.c')
-rw-r--r-- | common/peripheral_charger.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/common/peripheral_charger.c b/common/peripheral_charger.c index 85910d4c76..cb9a6e1f3e 100644 --- a/common/peripheral_charger.c +++ b/common/peripheral_charger.c @@ -83,6 +83,9 @@ static enum pchg_state pchg_initialize(struct pchg *ctx, enum pchg_state state) CPRINTS("ERR: Failed to initialize"); } + ctx->battery_percent = 0; + ctx->error = 0; + return state; } @@ -159,6 +162,11 @@ static enum pchg_state pchg_state_enabled(struct pchg *ctx) state = PCHG_STATE_INITIALIZED; break; case PCHG_EVENT_DEVICE_DETECTED: + /* + * Proactively query SOC in case charging info won't be sent + * because device is already charged. + */ + ctx->cfg->drv->get_soc(ctx); state = PCHG_STATE_DETECTED; break; case PCHG_EVENT_CHARGE_STARTED: @@ -195,6 +203,7 @@ static enum pchg_state pchg_state_detected(struct pchg *ctx) state = PCHG_STATE_CHARGING; break; case PCHG_EVENT_DEVICE_LOST: + ctx->battery_percent = 0; state = PCHG_STATE_ENABLED; break; case PCHG_EVENT_CHARGE_ERROR: @@ -231,6 +240,7 @@ static enum pchg_state pchg_state_charging(struct pchg *ctx) CPRINTS("Battery %d%%", ctx->battery_percent); break; case PCHG_EVENT_DEVICE_LOST: + ctx->battery_percent = 0; state = PCHG_STATE_ENABLED; break; case PCHG_EVENT_CHARGE_ERROR: @@ -444,8 +454,9 @@ static int cc_pchg(int argc, char **argv) ctx = &pchgs[port]; if (argc == 2) { - ccprintf("P%d STATE_%s EVENT_%s\n", port, - _text_state(ctx->state), _text_event(ctx->event)); + ccprintf("P%d STATE_%s EVENT_%s SOC=%d%%\n", port, + _text_state(ctx->state), _text_event(ctx->event), + ctx->battery_percent); return EC_SUCCESS; } |