Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2225578pxa; Mon, 17 Aug 2020 04:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1JveyK23Kn1wJ96hnP22D6MkZoPA8CniWWJGLR1K2/K9sbsWz1Qlvl62qCFjFfqmj/o5S X-Received: by 2002:a17:907:20e6:: with SMTP id rh6mr14381146ejb.301.1597664161846; Mon, 17 Aug 2020 04:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597664161; cv=none; d=google.com; s=arc-20160816; b=n/FsEPUcxi4CXqkcP440AksbUSxhdVo6jQasP9p8AUumhur9J8MZhAWfEJrQxK2Yv8 1RkuCgL/Pzw8/yeQEUT/ZcQ3P5ZbknPsDwd2DDmTXCIKpfu5HjFsG5lQel8bYTqm3pR3 lp2XMOcvRGs3wh3gbaUJBTnHTChD0pFztlscrQNv8xVW6CnAw9NWlAbpDxi0tKI2x0DQ XNrgaiT9ohNVtz59hQriCNRESxjETlT37s2ktuSZ/cskVYRNtMWCXtHFv8JwStpEKEt+ jn8qM6/6bLUyqTrImt6Yh7THKZx7fOAkhb44GV7AbkfLeUQMfxVZavtp0/08y2GCG2H9 YlAQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ZGO/KKNPUOF56NnWtMFVQdxBbLfbiGd4Iyi8BrWJhLE=; b=sko4652J1mUfOZi6muN+xNgeJ31YOCsHpjyUnqHRhdlYbCZKvNBBTiD89+dOHfS5Q9 4jdU//5BLMPsdajubikRqfZTh8ZkIO2cGkncNVUKpxq7af5pJA1CMbCFE8X9mAsovDBy 8l8qeoJPQhDiCZ8evN0lNx3RKD95sBLHTBZkMyLeevBhRRojtaqfqeoROp7yQ0fdpuSx HX8yAYajUuG8geQbvxGCz0htyShqjPMKHUIePoi4XYM33hJksoRkvGRLEJBd4K2myVSy c8wHHOw4eqlyV8Q5c3muq6qRTZfKB7VtbRrvCqS/uqhGIKCG9gSOZlx3aEEDFxcmiKiV l7pQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si10652509edz.218.2020.08.17.04.35.39; Mon, 17 Aug 2020 04:36:01 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728423AbgHQLbK (ORCPT + 99 others); Mon, 17 Aug 2020 07:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728380AbgHQLay (ORCPT ); Mon, 17 Aug 2020 07:30:54 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66897C061389 for ; Mon, 17 Aug 2020 04:30:54 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id A3D2E28DA67 Subject: Re: [PATCH v2 1/2] platform/chrome: cros_ec_proto: ignore unnecessary wakeups on old ECs To: Brian Norris , Benson Leung , Guenter Roeck Cc: linux-kernel@vger.kernel.org References: <20200724190841.3112365-1-briannorris@chromium.org> From: Enric Balletbo i Serra Message-ID: <8a3b8af8-12d3-0566-49f2-cd763d7a2002@collabora.com> Date: Mon, 17 Aug 2020 13:30:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200724190841.3112365-1-briannorris@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Brian, On 24/7/20 21:08, Brian Norris wrote: > ECs that don't implement EC_CMD_HOST_EVENT_GET_WAKE_MASK should still > have some reasonable default mask -- otherwise, they'll treat a variety > of EC signals as spurious wakeups. Battery and AC events can be > especially common, for devices that have been sitting at full charge > plugged into AC for a long time, as they may cycle their charging off > and on, or their battery may start reporting failures as it ages. > > Treating these as wakeups does not serve a useful purpose, and is > instead often counterproductive. And indeed, later ECs (that implement > the mask) don't include these events in their wake-mask. > > Note that this patch doesn't do anything without the subsequent patch > ("platform/chrome: cros_ec_proto: check for missing > EC_CMD_HOST_EVENT_GET_WAKE_MASK"), because > cros_ec_get_host_event_wake_mask() currently does not return an error if > EC_CMD_HOST_EVENT_GET_WAKE_MASK is not implemented. > > Some additional notes: > While the EC typically knows not to wake the CPU for these unimportant > events once the CPU reaches a sleep state, it doesn't really have a way > to know that the CPU is "almost" asleep, unless it has support for > EC_CMD_HOST_SLEEP_EVENT. Alas, these older ECs do not support that > command either, so this solution is not 100% complete. > > Signed-off-by: Brian Norris Sorry for late notice. The patch has been applied for 5.9. > --- > v2: > * more notes in commit message > --- > drivers/platform/chrome/cros_ec_proto.c | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > index 3e745e0fe092..e93024b55ce8 100644 > --- a/drivers/platform/chrome/cros_ec_proto.c > +++ b/drivers/platform/chrome/cros_ec_proto.c > @@ -469,14 +469,26 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev) > &ver_mask); > ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1))); > > - /* > - * Get host event wake mask, assume all events are wake events > - * if unavailable. > - */ > + /* Get host event wake mask. */ > 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; > + if (ret < 0) { > + /* > + * If the EC doesn't support EC_CMD_HOST_EVENT_GET_WAKE_MASK, > + * use a reasonable default. Note that we ignore various > + * battery, AC status, and power-state events, because (a) > + * those can be quite common (e.g., when sitting at full > + * charge, on AC) and (b) these are not actionable wake events; > + * if anything, we'd like to continue suspending (to save > + * power), not wake up. > + */ > + ec_dev->host_event_wake_mask = U32_MAX & > + ~(BIT(EC_HOST_EVENT_AC_DISCONNECTED) | > + BIT(EC_HOST_EVENT_BATTERY_LOW) | > + BIT(EC_HOST_EVENT_BATTERY_CRITICAL) | > + BIT(EC_HOST_EVENT_PD_MCU) | > + BIT(EC_HOST_EVENT_BATTERY_STATUS)); > + } > > ret = 0; > >