Skip to content

Commit

Permalink
platform/chrome: Add support for v1 of host sleep event
Browse files Browse the repository at this point in the history
Add support in code for the new forms of the host sleep event.
Detects the presence of this version of the command at runtime,
and use whichever form the EC supports. At this time, always
request the default timeout, and only report the failing response
via a WARN_ONCE(). Future versions could accept the sleep parameter
from outside the driver, and return the response information to
usermode or elsewhere.

Signed-off-by: Evan Green <[email protected]>
Reviewed-by: Rajat Jain <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
Acked-by: Enric Balletbo i Serra <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
  • Loading branch information
Evan Green authored and Lee Jones committed May 14, 2019
1 parent afe2bb5 commit 7235560
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
39 changes: 34 additions & 5 deletions drivers/mfd/cros_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,49 @@ static irqreturn_t ec_irq_thread(int irq, void *data)

static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)
{
int ret;
struct {
struct cros_ec_command msg;
struct ec_params_host_sleep_event req;
union {
struct ec_params_host_sleep_event req0;
struct ec_params_host_sleep_event_v1 req1;
struct ec_response_host_sleep_event_v1 resp1;
} u;
} __packed buf;

memset(&buf, 0, sizeof(buf));

buf.req.sleep_event = sleep_event;
if (ec_dev->host_sleep_v1) {
buf.u.req1.sleep_event = sleep_event;
buf.u.req1.suspend_params.sleep_timeout_ms =
EC_HOST_SLEEP_TIMEOUT_DEFAULT;

buf.msg.outsize = sizeof(buf.u.req1);
if ((sleep_event == HOST_SLEEP_EVENT_S3_RESUME) ||
(sleep_event == HOST_SLEEP_EVENT_S0IX_RESUME))
buf.msg.insize = sizeof(buf.u.resp1);

buf.msg.version = 1;

} else {
buf.u.req0.sleep_event = sleep_event;
buf.msg.outsize = sizeof(buf.u.req0);
}

buf.msg.command = EC_CMD_HOST_SLEEP_EVENT;
buf.msg.version = 0;
buf.msg.outsize = sizeof(buf.req);

return cros_ec_cmd_xfer(ec_dev, &buf.msg);
ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);

/* For now, report failure to transition to S0ix with a warning. */
if (ret >= 0 && ec_dev->host_sleep_v1 &&
(sleep_event == HOST_SLEEP_EVENT_S0IX_RESUME))
WARN_ONCE(buf.u.resp1.resume_response.sleep_transitions &
EC_HOST_RESUME_SLEEP_TIMEOUT,
"EC detected sleep transition timeout. Total slp_s0 transitions: %d",
buf.u.resp1.resume_response.sleep_transitions &
EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK);

return ret;
}

int cros_ec_register(struct cros_ec_device *ec_dev)
Expand Down
6 changes: 6 additions & 0 deletions drivers/platform/chrome/cros_ec_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
else
ec_dev->mkbp_event_supported = 1;

/* Probe if host sleep v1 is supported for S0ix failure detection. */
ret = cros_ec_get_host_command_version_mask(ec_dev,
EC_CMD_HOST_SLEEP_EVENT,
&ver_mask);
ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1)));

/*
* Get host event wake mask, assume all events are wake events
* if unavailable.
Expand Down
2 changes: 2 additions & 0 deletions include/linux/mfd/cros_ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct cros_ec_command {
* @pkt_xfer: Send packet to EC and get response.
* @lock: One transaction at a time.
* @mkbp_event_supported: True if this EC supports the MKBP event protocol.
* @host_sleep_v1: True if this EC supports the sleep v1 command.
* @event_notifier: Interrupt event notifier for transport devices.
* @event_data: Raw payload transferred with the MKBP event.
* @event_size: Size in bytes of the event data.
Expand Down Expand Up @@ -154,6 +155,7 @@ struct cros_ec_device {
struct cros_ec_command *msg);
struct mutex lock;
bool mkbp_event_supported;
bool host_sleep_v1;
struct blocking_notifier_head event_notifier;

struct ec_response_get_next_event_v1 event_data;
Expand Down

0 comments on commit 7235560

Please sign in to comment.