mfd: cros_ec: non-wake host events support
v2 cover mfd: cros_ec: non-wake host events support
Hi,
This patchset adds support for non-wake host events. These are events sent by the EC that should not wakeup the device.
This patchset also adds 2 fixes in cros_ec regarding a possible deadlock and an error code returned when it should not.
This patchset depends on [1] to compile
v2:
- Check for wake_event state in cros_ec_get_next_event()
- Remove cros_ec_get_host_event() implementation already introduced by [1]
[1] https://lkml.org/lkml/2017/1/19/278
Gwendal Grignou (1):
cros_ec: Fix deadlock when EC is not responsive at probe
Shawn Nematbakhsh (1):
cros_ec: Don't signal wake event for non-wake host events
Thierry Escande (1):
cros_ec: Don't return error when checking command version
drivers/mfd/cros_ec.c | 13 +++-- drivers/platform/chrome/cros_ec_proto.c | 96 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 16 +++++- 3 files changed, 115 insertions(+), 10 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/3 cros_ec: Don't return error when checking command version
With this patch, cros_ec_query_all() does not return an error if it fails to check for MKBP events support. Instead, the EC device structure indicates that it does not support MKBP events (mkbp_event_supported field) and cros_ec_query_all() returns 0.
--- drivers/platform/chrome/cros_ec_proto.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/platform/chrome/cros_ec_proto.c +2 -0
@@ -371,6 +371,8 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)else ec_dev->mkbp_event_supported =1 ; + ret =0 ; + exit:kfree (proto_msg);return ret;
Signature · 1 line
2.7.4
Benson Leung
AppliedRe: [PATCH v2 1/3] cros_ec: Don't return error when checking command version
Hi Thierry,
Quoted 6 lines · Thierry Escande
With this patch,
cros_ec_query_all()does not return an error if it fails to check for MKBP events support. Instead, the EC device structure indicates that it does not support MKBP events (mkbp_event_supportedfield) andcros_ec_query_all()returns 0.Signed-off-by Thierry Escande <[email protected]>
Applied. Thanks!
Signature · 7 lines
Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. [email protected] Chromium OS Project [email protected]
PATCH v2 2/3 cros_ec: Fix deadlock when EC is not responsive at probe
In reply to Thierry EscandeFrom: Gwendal Grignou <[email protected]>
When the EC is not responsive at probe, we try to get basic information (protocol to use) later on through cros_xfer_cmd() call. This patch makes sure there is no deadlock when re-probing the EC by replacing call to cros_xfer_cmd() with send_command() in the function cros_ec_get_host_command_version_mask(). Also, this patch adds the function header indicating it must be called protected.
--- drivers/platform/chrome/cros_ec_proto.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_proto.c +17 -1
@@ -235,6 +235,22 @@ static int cros_ec_host_command_proto_query_v2(struct cros_ec_device *ec_dev)return ret; } +/* +* cros_ec_get_host_command_version_mask +* +* Get the version mask of a given command. +* +* @ec_dev: EC device to call +* @msg: message structure to use +* @cmd: command to get the version of. +* @mask: result when function returns 0. +* +* @return 0 on success, error code otherwise +* +* LOCKING: +* the caller has ec_dev->lock mutex or the caller knows there is +* no other command in progress. +*/ static int cros_ec_get_host_command_version_mask (struct cros_ec_device *ec_dev,u16 cmd,u32 *mask) {
@@ -256,7 +272,7 @@ static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev, pver = (struct ec_params_get_cmd_versions *)msg->data; pver->cmd = cmd; - ret =cros_ec_cmd_xfer (ec_dev, msg); + ret =send_command (ec_dev, msg);if (ret >0 ) { rver = (struct ec_response_get_cmd_versions *)msg->data; *mask = rver->version_mask;
Signature · 1 line
2.7.4
Benson Leung
AppliedRe: [PATCH v2 2/3] cros_ec: Fix deadlock when EC is not responsive at probe
Hi Thierry,
Quoted 11 lines · Thierry Escande
From: Gwendal Grignou <[email protected]>
When the EC is not responsive at probe, we try to get basic information (protocol to use) later on through
cros_xfer_cmd()call. This patch makes sure there is no deadlock when re-probing the EC by replacing call tocros_xfer_cmd()withsend_command()in the functioncros_ec_get_host_command_version_mask(). Also, this patch adds the function header indicating it must be called protected.Signed-off-by Gwendal Grignou <[email protected]>Signed-off-by Thierry Escande <[email protected]>
Applied. Thanks again!
Signature · 7 lines
Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. [email protected] Chromium OS Project [email protected]
PATCH v2 3/3 cros_ec: Don't signal wake event for non-wake host events
In reply to Thierry EscandeFrom: Shawn Nematbakhsh <[email protected]>
The subset of wake-enabled host events is defined by the EC, but the EC may still send non-wake host events if we're in the process of suspending. Get the mask of wake-enabled host events from the EC and filter out non-wake events to prevent spurious aborted suspend attempts.
--- drivers/mfd/cros_ec.c | 13 ++++-- drivers/platform/chrome/cros_ec_proto.c | 76 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 5 ++- 3 files changed, 85 insertions(+), 9 deletions(-)
drivers/mfd/cros_ec.c +10 -3
@@ -54,12 +54,19 @@ static const struct mfd_cell ec_pd_cell = {static irqreturn_t ec_irq_thread (int irq,void *data) {struct cros_ec_device *ec_dev = data; +bool wake_event = true;int ret; -if (device_may_wakeup (ec_dev->dev)) + ret =cros_ec_get_next_event (ec_dev, &wake_event); + +/* +* Signal only if wake host events or any interrupt if +* cros_ec_get_next_event() returned an error (default value for +* wake_event is true) +*/ +if (wake_event &&device_may_wakeup (ec_dev->dev))pm_wakeup_event (ec_dev->dev,0 ); - ret =cros_ec_get_next_event (ec_dev);if (ret >0 )blocking_notifier_call_chain (&ec_dev->event_notifier,0 , ec_dev);
@@ -212,7 +219,7 @@ EXPORT_SYMBOL(cros_ec_suspend);static void cros_ec_drain_events (struct cros_ec_device *ec_dev) { -while (cros_ec_get_next_event (ec_dev) >0 ) +while (cros_ec_get_next_event (ec_dev,NULL ) >0 )blocking_notifier_call_chain (&ec_dev->event_notifier,1 , ec_dev); }
drivers/platform/chrome/cros_ec_proto.c +71 -5
95 lines not on this page · raw message
include/linux/mfd/cros_ec.h +4 -1
@@ -148,6 +148,7 @@ struct cros_ec_device {struct ec_response_get_next_event event_data;int event_size; +u32 host_event_wake_mask; };/**
@@ -294,10 +295,12 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);* cros_ec_get_next_event - Fetch next event from the ChromeOS EC * * @ec_dev: Device to fetch event from +* @wake_event: Pointer to a bool set to true upon return if the event might be +* treated as a wake event. Ignored if null. * * Returns: 0 on success, Linux error number on failure */ -int cros_ec_get_next_event (struct cros_ec_device *ec_dev); +int cros_ec_get_next_event (struct cros_ec_device *ec_dev,bool *wake_event);/** * cros_ec_get_host_event - Return a mask of event set by the EC.
Signature · 1 line
2.7.4
Re: [PATCH v2 3/3] cros_ec: Don't signal wake event for non-wake host events
Quoted 8 lines · Thierry Escande
From: Shawn Nematbakhsh <[email protected]>
The subset of wake-enabled host events is defined by the EC, but the EC may still send non-wake host events if we're in the process of suspending. Get the mask of wake-enabled host events from the EC and filter out non-wake events to prevent spurious aborted suspend attempts.
Quoted 7 lines
Signed-off-by Shawn Nematbakhsh <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- drivers/mfd/cros_ec.c | 13 ++++-- drivers/platform/chrome/cros_ec_proto.c | 76 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 5 ++- 3 files changed, 85 insertions(+), 9 deletions(-)
Looks okay from an MFD perspective:
For my own reference:
Quoted 163 lines
drivers/mfd/cros_ec.c +10
-3@@ -54,12 +54,19 @@ static const struct mfd_cell ec_pd_cell = {static irqreturn_t ec_irq_thread (int irq,void *data) {struct cros_ec_device *ec_dev = data; +bool wake_event = true;int ret; -if (device_may_wakeup (ec_dev->dev)) + ret =cros_ec_get_next_event (ec_dev, &wake_event); + +/* +* Signal only if wake host events or any interrupt if +* cros_ec_get_next_event() returned an error (default value for +* wake_event is true) +*/ +if (wake_event &&device_may_wakeup (ec_dev->dev))pm_wakeup_event (ec_dev->dev,0 ); - ret =cros_ec_get_next_event (ec_dev);if (ret >0 )blocking_notifier_call_chain (&ec_dev->event_notifier,0 , ec_dev);@@ -212,7 +219,7 @@ EXPORT_SYMBOL(cros_ec_suspend);static void cros_ec_drain_events (struct cros_ec_device *ec_dev) { -while (cros_ec_get_next_event (ec_dev) >0 ) +while (cros_ec_get_next_event (ec_dev,NULL ) >0 )blocking_notifier_call_chain (&ec_dev->event_notifier,1 , ec_dev); }drivers/platform/chrome/cros_ec_proto.c +71
-5@@ -150,6 +150,40 @@ int cros_ec_check_result(struct cros_ec_device *ec_dev, }EXPORT_SYMBOL (cros_ec_check_result); +/* +* cros_ec_get_host_event_wake_mask +* +* Get the mask of host events that cause wake from suspend. +* +* @ec_dev: EC device to call +* @msg: message structure to use +* @mask: result when function returns >=0. +* +* LOCKING: +* the caller has ec_dev->lock mutex, or the caller knows there is +* no other command in progress. +*/ +static int cros_ec_get_host_event_wake_mask (struct cros_ec_device *ec_dev, +struct cros_ec_command *msg, +uint32_t *mask) +{ +struct ec_response_host_event_mask *r; +int ret; + + msg->command =EC_CMD_HOST_EVENT_GET_WAKE_MASK ; + msg->version =0 ; + msg->outsize =0 ; + msg->insize =sizeof (*r); + + ret =send_command (ec_dev, msg); +if (ret >0 ) { + r = (struct ec_response_host_event_mask *)msg->data; + *mask = r->mask; + } + +return ret; +} +static int cros_ec_host_command_proto_query (struct cros_ec_device *ec_dev,int devidx,struct cros_ec_command *msg)@@ -387,6 +421,15 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)else ec_dev->mkbp_event_supported =1 ; +/* +* Get host event wake mask, assume all events are wake events +* if unavailable. +*/ + ret =cros_ec_get_host_event_wake_mask (ec_dev, proto_msg, + &ec_dev->host_event_wake_mask); +if (ret <0 ) + ec_dev->host_event_wake_mask =U32_MAX ; + ret =0 ; exit:@@ -504,12 +547,35 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev)return ec_dev->event_size; } -int cros_ec_get_next_event (struct cros_ec_device *ec_dev) +int cros_ec_get_next_event (struct cros_ec_device *ec_dev,bool *wake_event) { -if (ec_dev->mkbp_event_supported) -return get_next_event (ec_dev); -else -return get_keyboard_state_event (ec_dev); +u32 host_event; +int ret; + +if (!ec_dev->mkbp_event_supported) { + ret =get_keyboard_state_event (ec_dev); +if (ret <0 ) +return ret; + +if (wake_event) + *wake_event = true; + +return ret; + } + + ret =get_next_event (ec_dev); +if (ret <0 ) +return ret; + +if (wake_event) { + host_event =cros_ec_get_host_event (ec_dev); + +/* Consider non-host_event as wake event */ + *wake_event = !host_event || + !!(host_event & ec_dev->host_event_wake_mask); + } + +return ret; }EXPORT_SYMBOL (cros_ec_get_next_event);include/linux/mfd/cros_ec.h +4
-1@@ -148,6 +148,7 @@ struct cros_ec_device {struct ec_response_get_next_event event_data;int event_size; +u32 host_event_wake_mask; };/** @@ -294,10 +295,12 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);* cros_ec_get_next_event - Fetch next event from the ChromeOS EC * * @ec_dev: Device to fetch event from +* @wake_event: Pointer to a bool set to true upon return if the event might be +* treated as a wake event. Ignored if null. * * Returns: 0 on success, Linux error number on failure */ -int cros_ec_get_next_event (struct cros_ec_device *ec_dev); +int cros_ec_get_next_event (struct cros_ec_device *ec_dev,bool *wake_event);/** * cros_ec_get_host_event - Return a mask of event set by the EC.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Benson Leung
AppliedRe: [PATCH v2 3/3] cros_ec: Don't signal wake event for non-wake host events
In reply to Thierry EscandeHi Thierry,
Quoted 8 lines · Thierry Escande
From: Shawn Nematbakhsh <[email protected]>
The subset of wake-enabled host events is defined by the EC, but the EC may still send non-wake host events if we're in the process of suspending. Get the mask of wake-enabled host events from the EC and filter out non-wake events to prevent spurious aborted suspend attempts.
Quoted 8 lines
Signed-off-by Shawn Nematbakhsh <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- drivers/mfd/cros_ec.c | 13 ++++-- drivers/platform/chrome/cros_ec_proto.c | 76 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 5 ++- 3 files changed, 85 insertions(+), 9 deletions(-)
Another use of cros_ec_get_next_event was introduced in cros_ec_lpc.c since this patch was posted, so I went ahead and modified that too.
Applied. Thanks.
Signature · 7 lines
Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. [email protected] Chromium OS Project [email protected]
Re: [PATCH v2 3/3] cros_ec: Don't signal wake event for non-wake host events
Quoted 20 lines · Benson Leung
Hi Thierry,
Quoted 8 lines · Thierry Escande
From: Shawn Nematbakhsh <[email protected]>
The subset of wake-enabled host events is defined by the EC, but the EC may still send non-wake host events if we're in the process of suspending. Get the mask of wake-enabled host events from the EC and filter out non-wake events to prevent spurious aborted suspend attempts.
Quoted 8 lines
Signed-off-by Shawn Nematbakhsh <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- drivers/mfd/cros_ec.c | 13 ++++-- drivers/platform/chrome/cros_ec_proto.c | 76 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 5 ++- 3 files changed, 85 insertions(+), 9 deletions(-)
Quoted 4 lines
Another use of
cros_ec_get_next_eventwas introduced incros_ec_lpc.csince this patch was posted, so I went ahead and modified that too.Applied. Thanks.
No need to change anything this time, but please note the "for my own reference" in my Ack in future. It typically means that I plan on pushing it through the MFD tree or that it requires further discussion (in the case that another Maintainer would prefer it go through their tree).
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v2 3/3] cros_ec: Don't signal wake event for non-wake host events
Hi Lee,
Quoted 25 lines · Lee Jones
Quoted 23 lines · Benson Leung
Hi Thierry,
Quoted 8 lines · Thierry Escande
From: Shawn Nematbakhsh <[email protected]>
The subset of wake-enabled host events is defined by the EC, but the EC may still send non-wake host events if we're in the process of suspending. Get the mask of wake-enabled host events from the EC and filter out non-wake events to prevent spurious aborted suspend attempts.
Quoted 8 lines
Signed-off-by Shawn Nematbakhsh <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- drivers/mfd/cros_ec.c | 13 ++++-- drivers/platform/chrome/cros_ec_proto.c | 76 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 5 ++- 3 files changed, 85 insertions(+), 9 deletions(-)Another use of
cros_ec_get_next_eventwas introduced incros_ec_lpc.csince this patch was posted, so I went ahead and modified that too.
Quoted 8 lines
Quoted 1 line
Applied. Thanks.
No need to change anything this time, but please note the "for my own reference" in my Ack in future. It typically means that I plan on pushing it through the MFD tree or that it requires further discussion (in the case that another Maintainer would prefer it go through their tree).
Sorry about that. Thanks for the advice! I'm still getting my sea legs for maintainership.
Benson
Signature · 7 lines
Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. [email protected] Chromium OS Project [email protected]
Re: [PATCH v2 3/3] cros_ec: Don't signal wake event for non-wake host events
Quoted 28 lines · Benson Leung
Quoted 27 lines · Lee Jones
Quoted 24 lines · Benson Leung
Hi Thierry,
Quoted 8 lines · Thierry Escande
From: Shawn Nematbakhsh <[email protected]>
The subset of wake-enabled host events is defined by the EC, but the EC may still send non-wake host events if we're in the process of suspending. Get the mask of wake-enabled host events from the EC and filter out non-wake events to prevent spurious aborted suspend attempts.
Quoted 8 lines
Signed-off-by Shawn Nematbakhsh <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- drivers/mfd/cros_ec.c | 13 ++++-- drivers/platform/chrome/cros_ec_proto.c | 76 ++++++++++++++++++++++++++++++--- include/linux/mfd/cros_ec.h | 5 ++- 3 files changed, 85 insertions(+), 9 deletions(-)Another use of
cros_ec_get_next_eventwas introduced incros_ec_lpc.csince this patch was posted, so I went ahead and modified that too.Applied. Thanks.
Quoted 8 lines
Quoted 5 lines
No need to change anything this time, but please note the "for my own reference" in my Ack in future. It typically means that I plan on pushing it through the MFD tree or that it requires further discussion (in the case that another Maintainer would prefer it go through their tree).
Sorry about that. Thanks for the advice! I'm still getting my sea legs for maintainership.
It's not your fault. The tag I use is non-standard, so I expect some trivial issues like this to occur from time to time. But it solves more problems than it creates, so it's still work me using it.
Thanks for your understanding.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog