linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
To: Yicheng Li <yichengli@chromium.org>, linux-kernel@vger.kernel.org
Cc: bleung@chromium.org, gwendal@chromium.org
Subject: Re: [PATCH v2] mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW
Date: Mon, 25 Nov 2019 18:09:07 +0100	[thread overview]
Message-ID: <0f223903-ec93-a5ec-e858-fa0e2e282cf3@collabora.com> (raw)
In-Reply-To: <20191122212905.35679-1-yichengli@chromium.org>

Hi,

On 22/11/19 22:29, Yicheng Li wrote:
> 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 <yichengli@chromium.org>
> ---
>  drivers/platform/chrome/cros_ec.c           | 23 +++++++++++++++++++++
>  include/linux/platform_data/cros_ec_proto.h |  5 +++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
> index 9b2d07422e17..a72514ac3ce7 100644
> --- a/drivers/platform/chrome/cros_ec.c
> +++ b/drivers/platform/chrome/cros_ec.c
> @@ -104,6 +104,22 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)
>  	return ret;
>  }
>  
> +static int cros_ec_ready_event(struct notifier_block *nb,
> +	unsigned long queued_during_suspend, void *_notify)
> +{
> +	struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device,
> +						     notifier_ready);
> +	u32 host_event = cros_ec_get_host_event(ec_dev);
> +
> +	if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INTERFACE_READY)) {
> +		mutex_lock(&ec_dev->lock);
> +		cros_ec_query_all(ec_dev);
> +		mutex_unlock(&ec_dev->lock);
> +		return NOTIFY_OK;

I think you're missing a closing bracket here. Please make sure to do a build
test before sending the patches to the mailing list.

> +
> +	return NOTIFY_DONE;
> +}
> +
>  /**
>   * cros_ec_register() - Register a new ChromeOS EC, using the provided info.
>   * @ec_dev: Device to register.
> @@ -201,6 +217,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
>  		dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec",
>  			err);
>  
> +	/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */
> +	ec_dev->notifier_ready.notifier_call = cros_ec_ready_event;
> +	err = blocking_notifier_chain_register(&ec_dev->event_notifier,
> +					       &ec_dev->notifier_ready);
> +	if (err)
> +		return err;
> +
>  	dev_info(dev, "Chrome EC device registered\n");
>  
>  	return 0;
> diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
> index 0d4e4aaed37a..4b016d5dbf50 100644
> --- a/include/linux/platform_data/cros_ec_proto.h
> +++ b/include/linux/platform_data/cros_ec_proto.h
> @@ -161,6 +161,11 @@ struct cros_ec_device {
>  	int event_size;
>  	u32 host_event_wake_mask;
>  	u32 last_resume_result;
> +	/*
> +	 * The notifier block to let the kernel re-query EC communication
> +	 * protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY.
> +	 */

The comment should go in the documentation of the struct, above `struct
cros_ec_device` in correct kernel-doc format, not here.

Thanks,
 Enric

> +	struct notifier_block notifier_ready;
>  
>  	/* The platform devices used by the mfd driver */
>  	struct platform_device *ec;
> 

  reply	other threads:[~2019-11-25 17:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 21:29 [PATCH v2] mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW Yicheng Li
2019-11-25 17:09 ` Enric Balletbo i Serra [this message]
2019-11-25 22:08   ` [PATCH v3] " Yicheng Li
2019-11-25 22:15   ` [PATCH v4] " Yicheng Li
2019-11-26  9:56     ` Enric Balletbo i Serra
2019-12-03 19:20       ` Gwendal Grignou
2019-12-16 10:40     ` Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0f223903-ec93-a5ec-e858-fa0e2e282cf3@collabora.com \
    --to=enric.balletbo@collabora.com \
    --cc=bleung@chromium.org \
    --cc=gwendal@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yichengli@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).