Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1724975ybz; Sat, 18 Apr 2020 07:13:38 -0700 (PDT) X-Google-Smtp-Source: APiQypLh7WvYX4yO5I2IAJx7bjwxZ0qq+9/cA1m89Q6kocs4HW4QeWjXYYuQx6Ij1UDGHTldYi+z X-Received: by 2002:a17:906:f1c3:: with SMTP id gx3mr8035575ejb.25.1587219217941; Sat, 18 Apr 2020 07:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587219217; cv=none; d=google.com; s=arc-20160816; b=FL30oYXkaGZNX2rjBHiwLVzr70csAPR/e+WUQeeEqaeQgkdmXYTQJqVzjB3KmV7t/0 nfYXrxI3sPLR+c0koOerD1NbrBPzOXho+s3s2vR6R7bvifgZ9zfKokFsTkV0t84evOOu bZ8I6OZjkUazqIwuwpHuR1Mw6grScX9vxlwoTIy8OHWwvYWFUI3GxJeebV5+S+4G7DnP U77ayCpgLcjRlWbEBLMcwyh0+2NFtMuNyFrfInaugePNtUXBR/zBdDpsdJOmnVlP5dsn rh9XrlYAZf/EnZxUazPbV9jiZbpit28LezCobdECTfizupi3zRTas2my5Z/kJdOL5Joj cI5A== 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=JlP5uQt0TslnBNTlcwsMITl+a2vvSBXJufW0r3Cg42o=; b=Yo7KGUviKQiNGo8zdhuW2emmw2rUeVKi3Kg6KRzTwnMVQkMKSQADDWBKsa6NuUkUKr Cor+32A5IEk13F2UtIcjC/m4Hbpa1g8mQv+x/8xmB5qIuKjizHxlHauPUIt6EH/TjZWG 9oLPfEQb0itFcZtPwfaUY/1O3lcG16BQVKJybEe7SpTS+SdLOWX2ePpWaKssfwKTFpSF jzCaux7fRTrofnYZ7BtjFY+ZiQsNcuIbnQEdEhgQK5TuTVN3qi9g+VAv9RadHcoYUFXV qJ5E1+22FzYPgUtLOKTXGtmdsRvCSJ/ZGIEWJh5yCaoE0oKDqK9gVCT+BSGwQaDC8FeX 4cIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VMw/W9ef"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw16si2802395edb.150.2020.04.18.07.13.15; Sat, 18 Apr 2020 07:13:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VMw/W9ef"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbgDROK0 (ORCPT + 99 others); Sat, 18 Apr 2020 10:10:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:38184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbgDROKN (ORCPT ); Sat, 18 Apr 2020 10:10:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A653621D7E; Sat, 18 Apr 2020 14:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587219013; bh=MuIOjmunTWEFlt5HQIFx2mjqJzIGMAOGls5X8CybAR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VMw/W9efSZyCb6c1SfwUrOiOpw7B5kHEu/Lzbq0mT7SepFMxVSSeOfgEXNwYJEG/8 88VLOXPdLNcbYIp9yzIq+Zgn/KBY5yRxhsZZQYBu5h+i0lgkQ53+2diOBZyCQjwfMo yeU/IgiQIZVcnX+vpjJYA3H9SZv9HtRZaRF/cYVU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yicheng Li , Marek Szyprowski , Gwendal Grignou , Enric Balletbo i Serra , Sasha Levin Subject: [PATCH AUTOSEL 5.5 50/75] platform/chrome: cros_ec: Query EC protocol version if EC transitions between RO/RW Date: Sat, 18 Apr 2020 10:08:45 -0400 Message-Id: <20200418140910.8280-50-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200418140910.8280-1-sashal@kernel.org> References: <20200418140910.8280-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yicheng Li [ Upstream commit 42cd0ab476e2daffc23982c37822a78f9a53cdd5 ] 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 Tested-by: Marek Szyprowski Reviewed-by: Gwendal Grignou Signed-off-by: Enric Balletbo i Serra Signed-off-by: Sasha Levin --- drivers/platform/chrome/cros_ec.c | 30 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 4 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index 6d6ce86a1408a..e5e1bbb270914 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -137,6 +137,24 @@ 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. @@ -236,6 +254,18 @@ int cros_ec_register(struct cros_ec_device *ec_dev) dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec", err); + if (ec_dev->mkbp_event_supported) { + /* + * 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 30098a5515231..e6af1b4a7cbcf 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -126,6 +126,9 @@ struct cros_ec_command { * @host_event_wake_mask: Mask of host events that cause wake from suspend. * @last_event_time: exact time from the hard irq when we got notified of * a new event. + * @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 @@ -167,6 +170,7 @@ struct cros_ec_device { u32 host_event_wake_mask; u32 last_resume_result; ktime_t last_event_time; + struct notifier_block notifier_ready; /* The platform devices used by the mfd driver */ struct platform_device *ec; -- 2.20.1