summaryrefslogtreecommitdiff
path: root/driver/nfc
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2021-02-11 15:52:53 -0800
committerCommit Bot <commit-bot@chromium.org>2021-02-12 16:51:08 +0000
commitde9fd43a3ffffa4e4c9e7c12bc0be40860b7b293 (patch)
tree115e22ec66a2beaa5cc3875419b2012747177e38 /driver/nfc
parent914a3266dc25ff00e2ca171827f1e94cb5e8c5e9 (diff)
downloadchrome-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 'driver/nfc')
-rw-r--r--driver/nfc/ctn730.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/driver/nfc/ctn730.c b/driver/nfc/ctn730.c
index c8be10d297..8e5dd2ea20 100644
--- a/driver/nfc/ctn730.c
+++ b/driver/nfc/ctn730.c
@@ -90,6 +90,8 @@ static const int _detection_interval_ms = 100;
#define WLC_HOST_CTRL_DUMP_STATUS_CMD_SIZE 1
/* WLC_CHG_CTRL_CHARGING_INFO constants */
+#define WLC_CHG_CTRL_CHARGING_INFO_CMD_SIZE 0
+#define WLC_CHG_CTRL_CHARGING_INFO_RSP_SIZE 2
#define WLC_CHG_CTRL_CHARGING_INFO_EVT_SIZE 5
/* Status Codes */
@@ -313,12 +315,13 @@ static int _process_payload_response(struct pchg *ctx, struct ctn730_msg *res)
if (IS_ENABLED(CTN730_DEBUG))
CPRINTS("Payload: %ph", HEX_BUF(buf, len));
+ ctx->event = PCHG_EVENT_NONE;
+
switch (res->instruction) {
case WLC_HOST_CTRL_RESET:
if (len != WLC_HOST_CTRL_RESET_RSP_SIZE
|| buf[0] != WLC_HOST_STATUS_OK)
return EC_ERROR_UNKNOWN;
- ctx->event = PCHG_EVENT_NONE;
break;
case WLC_CHG_CTRL_ENABLE:
if (len != WLC_CHG_CTRL_ENABLE_RSP_SIZE
@@ -330,11 +333,15 @@ static int _process_payload_response(struct pchg *ctx, struct ctn730_msg *res)
if (len != WLC_CHG_CTRL_DISABLE_RSP_SIZE
|| buf[0] != WLC_HOST_STATUS_OK)
return EC_ERROR_UNKNOWN;
- ctx->event = PCHG_EVENT_NONE;
+ break;
+ case WLC_CHG_CTRL_CHARGING_INFO:
+ if (len != WLC_CHG_CTRL_CHARGING_INFO_RSP_SIZE
+ || buf[0] != WLC_HOST_STATUS_OK)
+ return EC_ERROR_UNKNOWN;
+ ctx->battery_percent = buf[1];
break;
default:
CPRINTS("Received unknown response (%d)", res->instruction);
- ctx->event = PCHG_EVENT_NONE;
break;
}
@@ -453,6 +460,22 @@ static int ctn730_get_event(struct pchg *ctx)
return EC_ERROR_UNKNOWN;
}
+static int ctn730_get_soc(struct pchg *ctx)
+{
+ struct ctn730_msg cmd;
+ int rv;
+
+ cmd.message_type = CTN730_MESSAGE_TYPE_COMMAND;
+ cmd.instruction = WLC_CHG_CTRL_CHARGING_INFO;
+ cmd.length = WLC_CHG_CTRL_CHARGING_INFO_CMD_SIZE;
+
+ rv = _send_command(ctx, &cmd);
+ if (rv)
+ return rv;
+
+ return EC_SUCCESS;
+}
+
/**
* Send command in blocking loop
*
@@ -519,6 +542,7 @@ const struct pchg_drv ctn730_drv = {
.init = ctn730_init,
.enable = ctn730_enable,
.get_event = ctn730_get_event,
+ .get_soc = ctn730_get_soc,
};
static int cc_ctn730(int argc, char **argv)