summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2021-04-30 09:07:10 -0700
committerCommit Bot <commit-bot@chromium.org>2021-06-11 21:20:29 +0000
commit4a46ad60f03301f0184df4a0f977b02cfeb3a1f7 (patch)
tree8a69e9960bc058a88a0dfb8725d76108a62c645b
parentfae894230df4f0e34dc4f13c587ee4d721dfa812 (diff)
downloadchrome-ec-4a46ad60f03301f0184df4a0f977b02cfeb3a1f7.tar.gz
PCHG: Handle WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DOCKED
We'll extend the period for a stylus to be statically charged so that EEPROM corruption can be avoided by not entering negotiated mode with a depleted battery. During this static charge period, the user currently doesn't see any charging indication. To prevent users from removing a stylus, we'll add a new state 'device docked' to ctn730. The EC firmware is updated to handle this new state as follows: - PCHG_STATE_DETECTED will be reused to indicate a device is in proximity but not ready for communication. - PCHG_STATE_CONNECTED will be added to indicate a device is ready for digital communication. This is formerly called DETECTED. - CTN730 driver produces PCHG_EVENT_DETECTED on 'docked' event and PCHG_EVENT_CONNECTED on 'detected' event. - When DEVICE_UNDOCKED is received in PCHG_STATE_DETECTED, transition to PCHG_STATE_ENABLED. BUG=b:189323070, b:173235954 BRANCH=trogdor TEST=Verify unpowered listener board can be detected. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I7fa83f6dd31cf74eab7c158e557ddc09f8976798 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2920628 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--common/peripheral_charger.c52
-rw-r--r--driver/nfc/ctn730.c10
-rw-r--r--include/ec_commands.h9
-rw-r--r--include/peripheral_charger.h29
4 files changed, 79 insertions, 21 deletions
diff --git a/common/peripheral_charger.c b/common/peripheral_charger.c
index 0b467afc6e..0a597ad6bd 100644
--- a/common/peripheral_charger.c
+++ b/common/peripheral_charger.c
@@ -65,6 +65,7 @@ static const char *_text_event(enum pchg_event event)
[PCHG_EVENT_ENABLED] = "ENABLED",
[PCHG_EVENT_DISABLED] = "DISABLED",
[PCHG_EVENT_DEVICE_DETECTED] = "DEVICE_DETECTED",
+ [PCHG_EVENT_DEVICE_CONNECTED] = "DEVICE_CONNECTED",
[PCHG_EVENT_DEVICE_LOST] = "DEVICE_LOST",
[PCHG_EVENT_CHARGE_STARTED] = "CHARGE_STARTED",
[PCHG_EVENT_CHARGE_UPDATE] = "CHARGE_UPDATE",
@@ -194,15 +195,15 @@ static void pchg_state_enabled(struct pchg *ctx)
ctx->state = PCHG_STATE_INITIALIZED;
break;
case PCHG_EVENT_DEVICE_DETECTED:
+ ctx->state = PCHG_STATE_DETECTED;
+ break;
+ case PCHG_EVENT_DEVICE_CONNECTED:
/*
* Proactively query SOC in case charging info won't be sent
* because device is already charged.
*/
ctx->cfg->drv->get_soc(ctx);
- ctx->state = PCHG_STATE_DETECTED;
- break;
- case PCHG_EVENT_CHARGE_STARTED:
- ctx->state = PCHG_STATE_CHARGING;
+ ctx->state = PCHG_STATE_CONNECTED;
break;
default:
break;
@@ -228,6 +229,42 @@ static void pchg_state_detected(struct pchg *ctx)
case PCHG_EVENT_DISABLED:
ctx->state = PCHG_STATE_INITIALIZED;
break;
+ case PCHG_EVENT_DEVICE_CONNECTED:
+ /*
+ * Proactively query SOC in case charging info won't be sent
+ * because device is already charged.
+ */
+ ctx->cfg->drv->get_soc(ctx);
+ ctx->state = PCHG_STATE_CONNECTED;
+ break;
+ case PCHG_EVENT_DEVICE_LOST:
+ ctx->battery_percent = 0;
+ ctx->state = PCHG_STATE_ENABLED;
+ break;
+ default:
+ break;
+ }
+}
+
+static void pchg_state_connected(struct pchg *ctx)
+{
+ int rv;
+
+ switch (ctx->event) {
+ case PCHG_EVENT_RESET:
+ ctx->state = pchg_reset(ctx);
+ break;
+ case PCHG_EVENT_DISABLE:
+ ctx->error |= PCHG_ERROR_HOST;
+ rv = ctx->cfg->drv->enable(ctx, false);
+ if (rv == EC_SUCCESS)
+ ctx->state = PCHG_STATE_INITIALIZED;
+ else if (rv != EC_SUCCESS_IN_PROGRESS)
+ CPRINTS("ERR: Failed to disable");
+ break;
+ case PCHG_EVENT_DISABLED:
+ ctx->state = PCHG_STATE_INITIALIZED;
+ break;
case PCHG_EVENT_CHARGE_STARTED:
ctx->state = PCHG_STATE_CHARGING;
break;
@@ -273,7 +310,7 @@ static void pchg_state_charging(struct pchg *ctx)
break;
case PCHG_EVENT_CHARGE_ENDED:
case PCHG_EVENT_CHARGE_STOPPED:
- ctx->state = PCHG_STATE_DETECTED;
+ ctx->state = PCHG_STATE_CONNECTED;
break;
default:
break;
@@ -395,6 +432,9 @@ static int pchg_run(struct pchg *ctx)
case PCHG_STATE_DETECTED:
pchg_state_detected(ctx);
break;
+ case PCHG_STATE_CONNECTED:
+ pchg_state_connected(ctx);
+ break;
case PCHG_STATE_CHARGING:
pchg_state_charging(ctx);
break;
@@ -546,7 +586,7 @@ static enum ec_status hc_pchg(struct host_cmd_handler_args *args)
ctx = &pchgs[port];
- if (ctx->state == PCHG_STATE_DETECTED
+ if (ctx->state == PCHG_STATE_CONNECTED
&& ctx->battery_percent >= ctx->cfg->full_percent)
r->state = PCHG_STATE_FULL;
else
diff --git a/driver/nfc/ctn730.c b/driver/nfc/ctn730.c
index b3da1bbb79..1fe5a48b1b 100644
--- a/driver/nfc/ctn730.c
+++ b/driver/nfc/ctn730.c
@@ -98,6 +98,8 @@ static const int _detection_interval_ms = 500;
#define WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DEACTIVATED 0x01
#define WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DEVICE_LOST 0x02
#define WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DEVICE_BAD_VERSION 0x03
+#define WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DOCKED 0x04
+#define WLC_CHG_CTRL_DEVICE_STATE_DEVICE_UNDOCKED 0x05
#define WLC_CHG_CTRL_DEVICE_STATE_EVT_SIZE_DETECTED 8
#define WLC_CHG_CTRL_DEVICE_STATE_EVT_SIZE 1
@@ -502,12 +504,18 @@ static int _process_payload_event(struct pchg *ctx, struct ctn730_msg *res)
break;
case WLC_CHG_CTRL_DEVICE_STATE:
switch (buf[0]) {
+ case WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DOCKED:
+ if (len != WLC_CHG_CTRL_DEVICE_STATE_EVT_SIZE)
+ return EC_ERROR_INVAL;
+ ctx->event = PCHG_EVENT_DEVICE_DETECTED;
+ break;
case WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DETECTED:
if (len != WLC_CHG_CTRL_DEVICE_STATE_EVT_SIZE_DETECTED)
return EC_ERROR_INVAL;
- ctx->event = PCHG_EVENT_DEVICE_DETECTED;
+ ctx->event = PCHG_EVENT_DEVICE_CONNECTED;
break;
case WLC_CHG_CTRL_DEVICE_STATE_DEVICE_DEVICE_LOST:
+ case WLC_CHG_CTRL_DEVICE_STATE_DEVICE_UNDOCKED:
if (len != WLC_CHG_CTRL_DEVICE_STATE_EVT_SIZE)
return EC_ERROR_INVAL;
ctx->event = PCHG_EVENT_DEVICE_LOST;
diff --git a/include/ec_commands.h b/include/ec_commands.h
index c0bea49322..09592c8b96 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -6820,16 +6820,18 @@ enum pchg_state {
PCHG_STATE_INITIALIZED,
/* Charger is enabled and ready to detect a device. */
PCHG_STATE_ENABLED,
- /* Device is detected in proximity. */
+ /* Device is in proximity. */
PCHG_STATE_DETECTED,
/* Device is being charged. */
PCHG_STATE_CHARGING,
/* Device is fully charged. It implies DETECTED (& not charging). */
PCHG_STATE_FULL,
- /* In download (or firmware update) mode. Update session is closed. */
+ /* In download (a.k.a. firmware update) mode */
PCHG_STATE_DOWNLOAD,
- /* In download mode. Session is opened. Ready for receiving data. */
+ /* In download mode. Ready for receiving data. */
PCHG_STATE_DOWNLOADING,
+ /* Device is ready for data communication. */
+ PCHG_STATE_CONNECTED,
/* Put no more entry below */
PCHG_STATE_COUNT,
};
@@ -6843,6 +6845,7 @@ enum pchg_state {
[PCHG_STATE_FULL] = "FULL", \
[PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
[PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
+ [PCHG_STATE_CONNECTED] = "CONNECTED", \
}
/**
diff --git a/include/peripheral_charger.h b/include/peripheral_charger.h
index 93d6427814..702d3c9835 100644
--- a/include/peripheral_charger.h
+++ b/include/peripheral_charger.h
@@ -37,26 +37,32 @@
* |
* | INITIALIZED
* v
- * +-------+-------+
+ * +---------------+
* | INITIALIZED |<--------------+
- * +------+-+------+ |
+ * +------+--------+ |
* | ^ |
* ENABLED | | DISABLED |
* v | |
- * +------+--------+ |
- * +------------->+ ENABLED | |
- * | +-------+-------+ |
- * | | |
- * | | DEVICE_DETECTED |
- * | v |
+ * +--------+------+ |
+ * +------------->| ENABLED | |
+ * | +-----+-+-------+ |
+ * | | | |
+ * | DEVICE_CONNECTED | | DEVICE_DOCKED |
+ * | | v |
+ * | DEVICE_LOST +---------------+ |
+ * +--------------+ DOCKED +---------------+
* | +-------+-------+ |
- * +--------------+ DETECTED +---------------+
- * | DEVICE_LOST +------+-+------+ ERROR |
+ * | | | |
+ * | | | DEVICE_CONNECTED |
+ * | v v |
+ * | +---------------+ |
+ * +--------------+ CONNECTED +---------------+
+ * | DEVICE_LOST +------+--------+ ERROR |
* | | ^ |
* | CHARGE_STARTED | | CHARGE_ENDED |
* | | | CHARGE_STOPPED |
* | v | |
- * | +------+-+------+ |
+ * | +--------+------+ |
* +--------------+ CHARGING +---------------+
* DEVICE_LOST +---------------+ ERROR
*
@@ -94,6 +100,7 @@ enum pchg_event {
PCHG_EVENT_ENABLED,
PCHG_EVENT_DISABLED,
PCHG_EVENT_DEVICE_DETECTED,
+ PCHG_EVENT_DEVICE_CONNECTED,
PCHG_EVENT_DEVICE_LOST,
PCHG_EVENT_CHARGE_STARTED,
PCHG_EVENT_CHARGE_UPDATE,