summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2021-03-11 13:17:35 -0800
committerCommit Bot <commit-bot@chromium.org>2021-03-25 21:28:55 +0000
commit71f8dd80c9380a839365dc82ac5ed4ce87e116b4 (patch)
treef222a7ddb1e63c06e695bf474f4e93ace94060eb
parent7f7d570862ffe9570266954f5551a6bf8aa1c992 (diff)
downloadchrome-ec-71f8dd80c9380a839365dc82ac5ed4ce87e116b4.tar.gz
PCHG: Don't notify host when there is no soc change
Currently, the host is notified every time a charging info message is received from a charger chip. This slows down the host entring suspend state. This patch makes the pchg state machine skip notifying the host when there is no battery level change. BUG=b:182973695, b:173235954, b:183151376 BRANCH=trogdor TEST=Stylus connect, disconnect, charge events are triggered as expected. TEST=Suspend is entered quickly with a stylus attached. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: If27397a56f8cc636637c0872a00496fee3ca7aa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2770504 (cherry picked from commit 29b492c095675a991147fdde0f586aa9efc94da9) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2787478
-rw-r--r--common/peripheral_charger.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/common/peripheral_charger.c b/common/peripheral_charger.c
index d176b75603..1bf16fd4ae 100644
--- a/common/peripheral_charger.c
+++ b/common/peripheral_charger.c
@@ -240,7 +240,6 @@ static void pchg_state_charging(struct pchg *ctx)
ctx->state = PCHG_STATE_INITIALIZED;
break;
case PCHG_EVENT_CHARGE_UPDATE:
- CPRINTS("Battery %d%%", ctx->battery_percent);
break;
case PCHG_EVENT_DEVICE_LOST:
ctx->battery_percent = 0;
@@ -261,6 +260,7 @@ static void pchg_state_charging(struct pchg *ctx)
static int pchg_run(struct pchg *ctx)
{
enum pchg_state previous_state = ctx->state;
+ uint8_t previous_battery = ctx->battery_percent;
int port = PCHG_CTX_TO_PORT(ctx);
int rv;
@@ -278,10 +278,10 @@ static int pchg_run(struct pchg *ctx)
if (ctx->event == PCHG_EVENT_IRQ) {
rv = ctx->cfg->drv->get_event(ctx);
if (rv) {
- CPRINTS("ERR: get_event (%d)", rv);
+ CPRINTS("ERR: Failed to get event (%d)", rv);
return 0;
}
- CPRINTS("IRQ:EVENT_%s", _text_event(ctx->event));
+ CPRINTS(" EVENT_%s", _text_event(ctx->event));
}
if (ctx->event == PCHG_EVENT_NONE)
@@ -311,19 +311,26 @@ static int pchg_run(struct pchg *ctx)
if (previous_state != ctx->state)
CPRINTS("->STATE_%s", _text_state(ctx->state));
+ if (ctx->battery_percent != previous_battery)
+ CPRINTS("Battery %u%%", ctx->battery_percent);
+
/*
* Notify the host of
- * - [S0] any event
- * - [S3/S0IX] device attach or detach (for wake-up)
- * - [S5/G3] no events.
+ * - [S0] All events except charge update and a new soc.
+ * - [S3/S0IX] Device attach or detach (for wake-up)
+ * - [S5/G3] No events.
*/
- if (chipset_in_state(CHIPSET_STATE_ON))
- return ctx->event != PCHG_EVENT_NONE;
- else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ return 0;
+
+ if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
return (ctx->event == PCHG_EVENT_DEVICE_DETECTED)
|| (ctx->event == PCHG_EVENT_DEVICE_LOST);
- return 0;
+ if (ctx->event == PCHG_EVENT_CHARGE_ERROR)
+ return 1;
+
+ return ctx->battery_percent != previous_battery;
}
void pchg_irq(enum gpio_signal signal)