Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2237232lqb; Mon, 27 May 2024 12:24:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXlgGW9Gc3D3OHY2vvhrtaQeFfDaQZ8EaeNaBjQQzhqzfvJVHxEXl+4Qfd66w30PrHay4RRKlwdceNBfn5EkmTX1GIi+pUi3qk7K9Toxw== X-Google-Smtp-Source: AGHT+IHbegjhqavcY4Bn2ZarX0u+/bw9siq6Tt5Dk/qel2qi90+bdQ8mVOEAy187tDmxsFZfKhJ4 X-Received: by 2002:a50:d555:0:b0:578:676e:324 with SMTP id 4fb4d7f45d1cf-578676e0855mr4659510a12.17.1716837875330; Mon, 27 May 2024 12:24:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716837875; cv=pass; d=google.com; s=arc-20160816; b=TTnYTFPbJfExNdf0WJC3FLLnx35kITIAdYPVImpanBMAvFmjQq360l7o504Ic42PzL qwmWGP9xxFikXVoq/saNSCdm1GLJkmH5c43ojyS62WKGXzL5hll8JAGr3nFz0nH3pwmw RRy68DzsJV0gbCqXOq7vyP/vTznlry6Z7r8JUNABNbZAJH4LQ+zyNb+Li8kxMEfci4eM 4jrWGkkj6OrHe1BcrtYdfk5c7mGYzcOy8gxgOKKa+9sPPa9awOSHU6/5joFPFGVJ/Rb3 aAZqIslBjKWcbDvqDvA3HLchFpiphoZxM1VQvLfWaUHeZMNHzu3X1sU+BwjxMidb9l3k XXJg== 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=aq2BzSxTH4qoXGzw6t6ATOXfQpHuuk1uYg9yIQYNXS4=; fh=oaWhg/pgABSyIARcYQPKUkgn0YxIDhr88TG922U/TcU=; b=CqhostPXP5Vpt7rdIhr90FFQNqbxh/VwE72BaRNcx245+6fOcilZNPiCTUgP1rcV90 I5kQeSpfKv6CPGVgOFS/QTMhHPXMoLrAxbgPDlFySi6FVFCqmiOmP1QnprC3vQzryqKh 51Z97LQfuc66CNVI0/3xqJEPliVZE9aVcNQmfJoNulj0K3qvCZlq3w94CFbg7art2S7L /twW17K6wgTO5GDdeF8Xri9rIOy+/Jz4JNr6eDiYvtq/ksEFhIaVMmc/10v2aVU/dZIa 7lRVF7Hn9cEA39KdPfgm8TKfd0+StAnMgfs5zb7Z1h547sThQy/xI+R3FODBKEsRYNFt 4V2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=erhcU8xc; 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-191368-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191368-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 4fb4d7f45d1cf-5785238757esi4266756a12.199.2024.05.27.12.24.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 12:24:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191368-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=erhcU8xc; 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-191368-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191368-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 BC49C1F22F28 for ; Mon, 27 May 2024 19:24:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 515831607A8; Mon, 27 May 2024 19:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="erhcU8xc" 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 632C3168C4; Mon, 27 May 2024 19:24:12 +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=1716837854; cv=none; b=GNqhckEQAOYkemCSPPssoEsvrQCpoTsu35DEB2N9uEtl6RRGLNU/oPPxQ/AB1X3jK5vJOd9bWu9IexexkRdlpvoyexiEiHldwwZPmujgZib1sPwhE/+WG2p7I3AvgTX/S94bX5UnK4+xtnOF9kGWEOTXl6hT2SSmMGbhqfzKYNw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716837854; c=relaxed/simple; bh=1AYlBAqGh7pyXd2PfPvcQ+zPsx8akvGVdpbKbEb3WhU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b9kyW8S0LckUSpxYaEEtntYXQt5Nb8szOFWsnI0pJoD8PTTugHkbOxCMmNkko1osWcmx4dkRr7fi+HUFgAR50DJF4kQlBmyT3JbsSBmykS5J20HPGJHdXG1c0BMgCFt2wBQStYHzqAhR0mr8eXx8LH/MSfXAdpASIO6SRAIGSyk= 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=erhcU8xc; 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=1716837844; bh=1AYlBAqGh7pyXd2PfPvcQ+zPsx8akvGVdpbKbEb3WhU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=erhcU8xcTXBvLNHDveHYYQeXF3gXskdNyLRM8056BO0fY8Pqc64b1OofeHwV2Ua21 J1sDiOvO1TELsFkRLxEUZCt1tvBcrEXFcK9Tc+oy+bTFIBu+s/9Fd6Ipuz5Ml6dJlf FNCCGr8twKdmSWywWiIbakE0EBsXqSICvlMfOgD8= Date: Mon, 27 May 2024 21:24:03 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Stephen Horvath Cc: Jean Delvare , Guenter Roeck , 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: <9cf224dd-51eb-4608-abcf-06f337d08178@t-8ch.de> References: <20240507-cros_ec-hwmon-v2-0-1222c5fca0f7@weissschuh.net> <20240507-cros_ec-hwmon-v2-1-1222c5fca0f7@weissschuh.net> 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: Hi Stephen, 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. 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. And EC_FAN_SPEED_STALLED also sets HWMON_F_FAULT. HWMON_F_ALARM doesn't seem right to me. But if Guenter has a preference, that will do, too. > > > + *speed = data; > > + return 0; > > +} > > + > But feel free to ignore me if I'm completly wrong about this, since I really > don't have much experience with kernel dev. Thanks for your feedback! Would you mind if I Cc you on further revisions? Thomas