Skip to content

Commit 42cd0ab

Browse files
Yicheng LiEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec: Query EC protocol version if EC transitions between RO/RW
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller / cros_fp, but not true for main ec / cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version of EC_CMD_GET_NEXT_EVENT to RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop. Once an EC_HOST_EVENT_INTERFACE_READY is received, we know that there might have been a transition between RO and RW, so re-query the protocol. Signed-off-by: Yicheng Li <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Reviewed-by: Gwendal Grignou <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent 8673e94 commit 42cd0ab

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

drivers/platform/chrome/cros_ec.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)
138138
return ret;
139139
}
140140

141+
static int cros_ec_ready_event(struct notifier_block *nb,
142+
unsigned long queued_during_suspend,
143+
void *_notify)
144+
{
145+
struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device,
146+
notifier_ready);
147+
u32 host_event = cros_ec_get_host_event(ec_dev);
148+
149+
if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INTERFACE_READY)) {
150+
mutex_lock(&ec_dev->lock);
151+
cros_ec_query_all(ec_dev);
152+
mutex_unlock(&ec_dev->lock);
153+
return NOTIFY_OK;
154+
}
155+
156+
return NOTIFY_DONE;
157+
}
158+
141159
/**
142160
* cros_ec_register() - Register a new ChromeOS EC, using the provided info.
143161
* @ec_dev: Device to register.
@@ -237,6 +255,18 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
237255
dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec",
238256
err);
239257

258+
if (ec_dev->mkbp_event_supported) {
259+
/*
260+
* Register the notifier for EC_HOST_EVENT_INTERFACE_READY
261+
* event.
262+
*/
263+
ec_dev->notifier_ready.notifier_call = cros_ec_ready_event;
264+
err = blocking_notifier_chain_register(&ec_dev->event_notifier,
265+
&ec_dev->notifier_ready);
266+
if (err)
267+
return err;
268+
}
269+
240270
dev_info(dev, "Chrome EC device registered\n");
241271

242272
return 0;

include/linux/platform_data/cros_ec_proto.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ struct cros_ec_command {
125125
* @host_event_wake_mask: Mask of host events that cause wake from suspend.
126126
* @last_event_time: exact time from the hard irq when we got notified of
127127
* a new event.
128+
* @notifier_ready: The notifier_block to let the kernel re-query EC
129+
* communication protocol when the EC sends
130+
* EC_HOST_EVENT_INTERFACE_READY.
128131
* @ec: The platform_device used by the mfd driver to interface with the
129132
* main EC.
130133
* @pd: The platform_device used by the mfd driver to interface with the
@@ -166,6 +169,7 @@ struct cros_ec_device {
166169
u32 host_event_wake_mask;
167170
u32 last_resume_result;
168171
ktime_t last_event_time;
172+
struct notifier_block notifier_ready;
169173

170174
/* The platform devices used by the mfd driver */
171175
struct platform_device *ec;

0 commit comments

Comments
 (0)