Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3420124ybc; Mon, 25 Nov 2019 14:19:55 -0800 (PST) X-Google-Smtp-Source: APXvYqy5YfPUqk7VxNwX0AwKo5u8inelhYYt6vSa9K7/1G4XM+NWdC5nUhhrsXWKvzNWqr99jG+C X-Received: by 2002:aa7:c68d:: with SMTP id n13mr16279768edq.193.1574720395385; Mon, 25 Nov 2019 14:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574720395; cv=none; d=google.com; s=arc-20160816; b=GvVPL9qDez6rt+V5awm9uPzsM/gFjbYMOXW6QCX07sRtBYIH9La8rPk7M/8CqSYIQI hMRd0UYp3FqVZ96PEX0crvYKFepvGAVNyrErVvdGT/8WewucOB3ADb576sHWlwa55H+M hvK4N4GHWSclI42tEN2jl+6TivsKlCEoFcR91xRYaHyV12QajBWIfLAVEWWJ1FfAxsO7 iLiw8mbefS/Lf4fYWzXXW0i+pPmR/b5tY7dGhUT3v6ddcM0vZm4VCWGMiQhpcvycdout Uzt0UjwO5GLNOZfD/3OHd1FxxvE8rHS7DUKqLVHgMM8Cohphno4DfVD1Gh7EdP5dASgc QO8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i2FzA9U/0kMzyDVMENZ9fqG7bwxFaEkKYL5q8/6pH/U=; b=LNAXVYMuaeTlCIs7AemtMu9xwPjPut00o38fr2jd9nRcTPMda3e8b761EmIWrvgsv5 DOabmUUu4FLuW2d38rXjzvp1AC1zyDrGQz5Yq3PvnKCJF1tcZZUvB40gXvyKC0Ap2OJh BEB5ItdvyBoECTQWR8qg3Z4eJAPWjrTvfToNOZgFofiaC6EFqU3v/UTGpiLQEglG6Dyv YPgm3UTbOWwSxvy/BEnM1m+zUsYWr+uxNu6dKBAzJicBODfQn89tCnsBc176aIpVfl+B vcO9i8LS1iRP7VK4Vafn8QAC9zb2LaVN8o+Trt5dIhyH82YXAmeWudNEjssKeBSkXQ7O V68g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AviB7ZG1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m14si5953349edp.78.2019.11.25.14.19.28; Mon, 25 Nov 2019 14:19:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AviB7ZG1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726029AbfKYWQJ (ORCPT + 99 others); Mon, 25 Nov 2019 17:16:09 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:43838 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725930AbfKYWQJ (ORCPT ); Mon, 25 Nov 2019 17:16:09 -0500 Received: by mail-pj1-f68.google.com with SMTP id a10so7249351pju.10 for ; Mon, 25 Nov 2019 14:16:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i2FzA9U/0kMzyDVMENZ9fqG7bwxFaEkKYL5q8/6pH/U=; b=AviB7ZG1CwpXNrCFxl4vaIWZoScolzPXgFrIjsZVyAIldCRN8E4G0LcOUXT70DPT6f On7X8Vv5S2F6TYajp5stdorneg5Q4UX+Q+smXUePUBtiJoH3adF0cj2/5no2A+jlVCGs KLPPYbuQLqk6muF8+z1UsVXni7+pjeEMPSWo8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i2FzA9U/0kMzyDVMENZ9fqG7bwxFaEkKYL5q8/6pH/U=; b=TptYmWGM2nLb+cMA51i7bzmHMg7c1bYCl/Ko26VS/C1ipKz/Zci6dvZbZJeTaGJus6 faINaJXagkLbQ5ZT18mf4Arkfzi+B7RgyO2SmpObUlpaqJJwQb7AmoYyWjJqlX3FzJXg n11uZj8oO1pClmQjwBrbq4MwSrJNzehk2JYTS+oL+Yig/LcyQX4ywgz2rPRGp7NptQJP qtzjnf+MzcF2XacRjBouI0QpC48bXKRixrNeSh4i3VRxrVfWkt6OWNlbL3w59hrY4MNq zssdgNnZZrGofzwDesBrZWKPqrjPmKlTqf4jkH7+FSrghIUffForJ2J2Fa3M2SG4CRCt ZubQ== X-Gm-Message-State: APjAAAVNDQWx5MS2DGMqzwmTD4/L026UrGElh5QvJg9+ikLfGcNzzaGX HfgJw6W/QnSmo4wjST1mDzq8k1/C3/KJ+w== X-Received: by 2002:a17:902:24e:: with SMTP id 72mr26023327plc.287.1574720167949; Mon, 25 Nov 2019 14:16:07 -0800 (PST) Received: from yichengli2.mtv.corp.google.com ([2620:15c:202:201:900:2031:8afd:85a7]) by smtp.gmail.com with ESMTPSA id o124sm9814844pfb.56.2019.11.25.14.16.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Nov 2019 14:16:07 -0800 (PST) From: Yicheng Li To: linux-kernel@vger.kernel.org Cc: bleung@chromium.org, yichengli@chromium.org, gwendal@chromium.org, enric.balletbo@collabora.com Subject: [PATCH v4] mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW Date: Mon, 25 Nov 2019 14:15:17 -0800 Message-Id: <20191125221517.91611-1-yichengli@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <0f223903-ec93-a5ec-e858-fa0e2e282cf3@collabora.com> References: <0f223903-ec93-a5ec-e858-fa0e2e282cf3@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index 9b2d07422e17..38ec1fb409a5 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -104,6 +104,23 @@ 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; + } + + return NOTIFY_DONE; +} + /** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register. @@ -201,6 +218,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..a1c545c464e7 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -121,6 +121,8 @@ struct cros_ec_command { * @event_data: Raw payload transferred with the MKBP event. * @event_size: Size in bytes of the event data. * @host_event_wake_mask: Mask of host events that cause wake from suspend. + * @notifier_ready: The notifier_block to let the kernel re-query EC + * communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. * @ec: The platform_device used by the mfd driver to interface with the * main EC. * @pd: The platform_device used by the mfd driver to interface with the @@ -161,6 +163,7 @@ struct cros_ec_device { int event_size; u32 host_event_wake_mask; u32 last_resume_result; + struct notifier_block notifier_ready; /* The platform devices used by the mfd driver */ struct platform_device *ec; -- 2.21.0