Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp78397lqb; Tue, 28 May 2024 09:16:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXCqstI+oVH+TvPakEDFZvhbCmpPfsWh33hzpN41qK5GJtm/JFqytdQn0vxQjE1MUqzQAkmSJsnBSvJlMhqQYQFoC1iFm0HiB6X9i/XQ== X-Google-Smtp-Source: AGHT+IFyoEDOcDqBoGHR9lQ9bIokAxwgQLPztfG75buVRVvEWavEGVX4SsLBQnHFgqzuTDJqncBf X-Received: by 2002:a17:906:2484:b0:a59:af4c:c7de with SMTP id a640c23a62f3a-a6264f15de7mr865297566b.58.1716912970942; Tue, 28 May 2024 09:16:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716912970; cv=pass; d=google.com; s=arc-20160816; b=cSDhmDqBpJdvwTx/ZngNPzJRLY6YLUWxrMnHFkbFp1BesmcL5H0eUPCTS//RmPbSdv Gx8KUfH7m1lGA+6wCxO9p/xcd043owddYBi4LZvXzya36+GlW/SmUPz1dh6KWrXiH5wh 5XK92g6gg59OR0tzPhDII06plB1eFHeLtXHhDWV4491MQUVQn0J8udlhFUvB7yH74iUv 2F2dAugx/8qI4og+ENxA19l/bQhsCslxdF0911egmUSTzbgv1QJGinvksz+MZM83tkGn dmAhwczFYUsJ5Y+y6vBynDOTOWcDQaPNRZwgQlL9Si1jZz+43HvbGQqSVXtDLjQ4zRlC Mb1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rRyJxm/xPFcNdkeyeRdazMYEQb0+LH8/ntntDM7HPlg=; fh=MSn75nQVBvEBgHchCN8QPsguKL78wWrWekNGNSR+d0Q=; b=NjyNwneJumY7/AurooEv450/uOxc9S5QiA0ltFNSGjBzOhN46SH5JghT54JBz5xPm8 FBbsbS/pmhNNIZoMFnwIvKmr93XjQTlumvXhJ+6ad6GH/Ln8sgAST5GygP0gWrNVaStY XsWgX+xJCdZdedmJxO6h13+Mf/WmEfuDC/GG9n4DMwo0FHdlWlra9ItSw0rL0KzR6IhT aAqImXLNh0O5TFdN/CcYRsMurlxPYa+GUEndukhwoQHoruW7rZqEzUSnCExyBWxII6RW 00LNH94erGD/XIkEB35iA67bQsmpzSix7UbDfuMKajhL3U12NVg5okgPKXLggH05KUy1 zZig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=D4wORzPO; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-192733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192733-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a634ce528e4si73440166b.283.2024.05.28.09.16.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 09:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=D4wORzPO; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-192733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192733-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 83BD11F2519C for ; Tue, 28 May 2024 16:16:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A9B517279E; Tue, 28 May 2024 16:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="D4wORzPO" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AAF816D9D2; Tue, 28 May 2024 16:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716912964; cv=none; b=NbbRW/M/jOaD/e04SHT6uIsOkgdqgKihfb2pyfWhW7wo8qYWCQhL3WemdGJZpqXLFSfHecxOA5KQ428P/K+FdVco0IKeZjTKZl7yuL6q0cuRTIK02POcOMYYZRfaVHsZZyVyq1ynT6nrq5t8z4D3/8E1JBVMfB6K9fQDA4w6jBg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716912964; c=relaxed/simple; bh=l6x4ez58HU9UJM5Ps7D89/4CNRdh7IYjsMDwe693JlQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t2e8La/7t8uxHYT6Uh0RupVDHOqNgE6i4wl4mobqmFJ/kiGA3mL09d20xdW+kDuJEKsg8lXO3+u0YX1H5Tc1WYmpHbqy5nMpf6LOCvChbwXch0JEcPdlEQ2kXPXyCqOMjfxWLGL0vre97WSdZak8y2bXCKUZfQJjzm4Lwj9QJec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=D4wORzPO; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1716912956; bh=l6x4ez58HU9UJM5Ps7D89/4CNRdh7IYjsMDwe693JlQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=D4wORzPO/dcNOsesBD/hol+eQeSr63q3p1WKENypCodZkC7huLrBXL1LwoSLZFbP8 X13x5+BT2jwmBPLL8hPhRZhJKBf047O02c5z46EaZ8tmZDjHkQj+wVLFS2Fm6QW+m3 w1k2KYckDr2N4+gVVZbDhHrTAdCA1o89KA4vF/2k= Date: Tue, 28 May 2024 18:15:56 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Guenter Roeck Cc: Stephen Horvath , Jean Delvare , Benson Leung , Lee Jones , Guenter Roeck , linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, chrome-platform@lists.linux.dev, Dustin Howett , Mario Limonciello , Moritz Fischer Subject: Re: [PATCH v2 1/2] hwmon: add ChromeOS EC driver Message-ID: References: <20240507-cros_ec-hwmon-v2-0-1222c5fca0f7@weissschuh.net> <20240507-cros_ec-hwmon-v2-1-1222c5fca0f7@weissschuh.net> <9cf224dd-51eb-4608-abcf-06f337d08178@t-8ch.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On 2024-05-28 08:50:49+0000, Guenter Roeck wrote: > On 5/27/24 17:15, Stephen Horvath wrote: > > On 28/5/24 05:24, Thomas Weißschuh wrote: > > > On 2024-05-25 09:13:09+0000, Stephen Horvath wrote: > > > > I was the one to implement fan monitoring/control into Dustin's driver, and > > > > just had a quick comment for your driver: > > > > > > > > On 8/5/24 02:29, Thomas Weißschuh wrote: > > > > > The ChromeOS Embedded Controller exposes fan speed and temperature > > > > > readings. > > > > > Expose this data through the hwmon subsystem. > > > > > > > > > > The driver is designed to be probed via the cros_ec mfd device. > > > > > > > > > > Signed-off-by: Thomas Weißschuh > > > > > --- > > > > >    Documentation/hwmon/cros_ec_hwmon.rst |  26 ++++ > > > > >    Documentation/hwmon/index.rst         |   1 + > > > > >    MAINTAINERS                           |   8 + > > > > >    drivers/hwmon/Kconfig                 |  11 ++ > > > > >    drivers/hwmon/Makefile                |   1 + > > > > >    drivers/hwmon/cros_ec_hwmon.c         | 269 ++++++++++++++++++++++++++++++++++ > > > > >    6 files changed, 316 insertions(+) > > > > > > > > > > > > > > > > > > > diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c > > > > > new file mode 100644 > > > > > index 000000000000..d59d39df2ac4 > > > > > --- /dev/null > > > > > +++ b/drivers/hwmon/cros_ec_hwmon.c > > > > > @@ -0,0 +1,269 @@ > > > > > +// SPDX-License-Identifier: GPL-2.0-or-later > > > > > +/* > > > > > + *  ChromesOS EC driver for hwmon > > > > > + * > > > > > + *  Copyright (C) 2024 Thomas Weißschuh > > > > > + */ > > > > > + > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > + > > > > > +#define DRV_NAME    "cros-ec-hwmon" > > > > > + > > > > > +struct cros_ec_hwmon_priv { > > > > > +    struct cros_ec_device *cros_ec; > > > > > +    u8 thermal_version; > > > > > +    const char *temp_sensor_names[EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES]; > > > > > +}; > > > > > + > > > > > +static int cros_ec_hwmon_read_fan_speed(struct cros_ec_device *cros_ec, u8 index, u16 *speed) > > > > > +{ > > > > > +    u16 data; > > > > > +    int ret; > > > > > + > > > > > +    ret = cros_ec->cmd_readmem(cros_ec, EC_MEMMAP_FAN + index * 2, 2, &data); > > > > > +    if (ret < 0) > > > > > +        return ret; > > > > > + > > > > > +    data = le16_to_cpu(data); > > > > > + > > > > > +    if (data == EC_FAN_SPEED_NOT_PRESENT) > > > > > +        return -ENODEV; > > > > > + > > > > > > > > Don't forget it can also return `EC_FAN_SPEED_STALLED`. > > > > > > Thanks for the hint. I'll need to think about how to handle this better. > > > > > > > Like Guenter, I also don't like returning `-ENODEV`, but I don't have a > > > > problem with checking for `EC_FAN_SPEED_NOT_PRESENT` in case it was removed > > > > since init or something. > > > > > That won't happen. Chromebooks are not servers, where one might be able to > replace a fan tray while the system is running. In one of my testruns this actually happened. When running on battery, one specific of the CPU sensors sporadically returned EC_FAN_SPEED_NOT_PRESENT. > > > Ok. > > > > > > > My approach was to return the speed as `0`, since the fan probably isn't > > > > spinning, but set HWMON_F_FAULT for `EC_FAN_SPEED_NOT_PRESENT` and > > > > HWMON_F_ALARM for `EC_FAN_SPEED_STALLED`. > > > > No idea if this is correct though. > > > > > > I'm not a fan of returning a speed of 0 in case of errors. > > > Rather -EIO which can't be mistaken. > > > Maybe -EIO for both EC_FAN_SPEED_NOT_PRESENT (which should never happen) > > > and also for EC_FAN_SPEED_STALLED. > > > > Yeah, that's pretty reasonable. > > > > -EIO is an i/o error. I have trouble reconciling that with > EC_FAN_SPEED_NOT_PRESENT or EC_FAN_SPEED_STALLED. > > Looking into the EC source code [1], I see: > > EC_FAN_SPEED_NOT_PRESENT means that the fan is not present. > That should return -ENODEV in the above code, but only for > the purpose of making the attribute invisible. > > EC_FAN_SPEED_STALLED means exactly that, i.e., that the fan > is present but not turning. The EC code does not expect that > to happen and generates a thermal event in case it does. > Given that, it does make sense to set the fault flag. > The actual fan speed value should then be reported as 0 or > possibly -ENODATA. It should _not_ generate any other error > because that would trip up the "sensors" command for no > good reason. Ack. Currently I have the following logic (for both fans and temp): if NOT_PRESENT during probing: make the attribute invisible. if any error during runtime (including NOT_PRESENT): return -ENODATA and a FAULT This should also handle the sporadic NOT_PRESENT failures. What do you think? Is there any other feedback to this revision or should I send the next? Thanks, Thomas