Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp333473lqb; Tue, 28 May 2024 18:01:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXr9y4Ws1bxcVcHUbcBVUW/uO7MEsirM8yEt1R5NM6j7Z5I/V3sOdUHkhKpFoMgDyAPxOpH0fXCU1QQapUM5zOUQADvpAndbccZfn8s8g== X-Google-Smtp-Source: AGHT+IHYpj6joAuyMHDWoBrHobjUMiaE8nLy9SCBHaZdG0CqWe3+8nTH3W1ydDhZIjpADXPbVgEo X-Received: by 2002:a05:6e02:1a46:b0:36b:85e:7d69 with SMTP id e9e14a558f8ab-3737b292328mr210338545ab.10.1716944506972; Tue, 28 May 2024 18:01:46 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822a98e44esi9123893a12.752.2024.05.28.18.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193279-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@OUTLOOK.COM.AU header.s=selector1 header.b=s40PDuUC; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-193279-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193279-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=outlook.com.au 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 23BCCB258B7 for ; Wed, 29 May 2024 00:58:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C522B15A856; Wed, 29 May 2024 00:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=OUTLOOK.COM.AU header.i=@OUTLOOK.COM.AU header.b="s40PDuUC" Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2143.outbound.protection.outlook.com [40.92.62.143]) (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 F148D2F2A; Wed, 29 May 2024 00:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.62.143 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716944319; cv=fail; b=fFHBS+X/rpb62tgmnxXmR/CMDEqukPbvWfdOIG5hcJC4Pxn2GQWwk4b24iCQWdfcUjkYuYEFQ13SIyE7nnA6rJchPYCWCms+ZsdVlkSsgFsLZVxNpFUpnoESd8WC8C9UwlihxRxRzKv6Vd5h4mcrWRj9x8l3WwdhM1606o1EldE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716944319; c=relaxed/simple; bh=fn85pvff5ZRZa/WSv5iuBlHu28RBeLbz48LajbqNv8Y=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=TEM1RdEe7dIkRfKGqYCaTh8rPNH/oQ/QyPh2DV//6tkHkod8aa8jU7YPCAmHLHanHl1Ywyvj6McOInNFd3m1E6fEU1IJ0VnSh2y4FBhMBoz+13zHt2PYwKo6IHRm0nl2cyOgsmW/uxykTFHNSKw9XO8Wp8al1lVrm+LhbmvcoIs= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com.au; spf=pass smtp.mailfrom=outlook.com.au; dkim=pass (2048-bit key) header.d=OUTLOOK.COM.AU header.i=@OUTLOOK.COM.AU header.b=s40PDuUC; arc=fail smtp.client-ip=40.92.62.143 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com.au ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gGdts9H0vsL51Urs3cIUqOEFQGY+9pMIx8uafY7X2EbWPGSMpWdKl33SoJXMxJbndQr2cI8q462/VzNlmGiNbhPohsMi9+PouaJO5UtXEVML4iK1OUM7jz11XXGFuZfRCfMWOzuIVG9xhIVU60nacg8a84oWFGhICT5lIdMb4sd3c5rf6Wyn1HXro5TMhcGA+5CY4KAycU9fJZyrhkurA6TYV0VAF24LqLm2Fyl5ln6kawDe8z2cZybi+Z1pghnQxXlI71i33S6VDcNCjIKSM1u0FaA1I/w7reEwTg4uZTDMbvREwRcPcEMer7Xh4dRR8kssUYJVdKBFB5SGmDdsSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XWeEVSlW96/E+/iPdYxgjndPup7n1XSwkI7ZE0+n8Tk=; b=PO8D9twgIKOAzmc6Z57IydPMyAuMwNhLxrCI0bkzwsZA1+eLHS46xgTZR2UwSteBbh3UatXXMIQZ+jmDGxLQbDwXQ+KEN0mIJjNKUQCA1mwqEjZ7wtvOqIaJCFCRyguWEDQWsbYD9HuuSgyuREajkXHA/g5AYeTernAMGqTBXlnZLE1SJ1sR05xH9/pZmcZ8t5mzZFJdXIR/LoQYEbo6C7ApIPoH5RwYFlJak33jPj01ykfwT+FNeeaVHB/DuQnUH98aQG6LV0kTWVR3SuudsZ4wMW71RRYpa7rEq+bDt906qs/Xjx5WKl/5EmTr46IVnvjhGjPtE43BGFQGOOVzbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=OUTLOOK.COM.AU; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XWeEVSlW96/E+/iPdYxgjndPup7n1XSwkI7ZE0+n8Tk=; b=s40PDuUCkr9QwADGxx5xFWyIj3ml6w16tELCRYa5V86wR5ArAu1FQTN69xiI9ZR5Wj3/5JhRvHEg2L1Ey7zbKU/v6mLZp0NQ1o4ZIpdrGqQyd264y0WNed2+Eh7e9fkHkR+Oc8f2LrIopQxueIJqvtw5svXwKpky2AWZUqjQ1WzDNTrwcA9b+LCt3bps7FCczDTWkk+TzG0WYv96B+SoJrLbtEQKd+svFjvA0biwVmFz9DhrJMYk7KkaSV/wXH0HvFj5N1ZyWWceeNEaE77JU4LBvEWb/IyneJXt5dOi6+3rOwd926CnLcCxQwZHh4RYXHgHuuLpkH3u8DrZHEQVXg== Received: from SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:159::9) by SY4P282MB3890.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:192::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.17; Wed, 29 May 2024 00:58:31 +0000 Received: from SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM ([fe80::37cc:3733:d1e9:d8e4]) by SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM ([fe80::37cc:3733:d1e9:d8e4%3]) with mapi id 15.20.7633.017; Wed, 29 May 2024 00:58:31 +0000 Message-ID: Date: Wed, 29 May 2024 10:58:23 +1000 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] hwmon: add ChromeOS EC driver To: Guenter Roeck , =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: 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 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> <6824f030-92da-4439-af3b-8c2498f4382e@roeck-us.net> Content-Language: en-US, en-AU, en-GB From: Stephen Horvath In-Reply-To: <6824f030-92da-4439-af3b-8c2498f4382e@roeck-us.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TMN: [fIrBzQF835DN1v6Pu6DSA/RGOIKzgMKkq+tUgkAEwKz0VnfGWoK8lnUs+MAjpmLg5YjTKNNAax8=] X-ClientProxiedBy: SYBPR01CA0126.ausprd01.prod.outlook.com (2603:10c6:10:5::18) To SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:159::9) X-Microsoft-Original-Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB3063:EE_|SY4P282MB3890:EE_ X-MS-Office365-Filtering-Correlation-Id: d1813196-6899-4780-5fb1-08dc7f7a751e X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|3412199016|440099019|1602099003; X-Microsoft-Antispam-Message-Info: D+b/wSiIAd0U7ur5Ga6D1Eg3RID/PMCkGmHhZ4kU7tVIxV2lSPSsMVbtsRCv2bVDvAWorpveOkHJJBQvKhMcKE9W7SPrdHKZFDu57kn2tmGNOk6yKYaV6b17c2VN2lScxzcwiDCGPleNaPQxZoJVRV8ouJKf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k4amVKSlBKNG9UREJuRFJFSnBaS0tp?= =?utf-8?B?RERIZDljbkJjKyt3a1FqQld4Vzkyc2ROWnpxczBIV3daVy9qT0h1dG5kQkR1?= =?utf-8?B?ckZnMGNzazVjRmNxdjZuTElVanJtQmNkYXNsZEZ4ZWlxbXk0d0ZiYUE2YlM1?= =?utf-8?B?Mjl2TndKZ0tJcEYyYlZrbzhZVXdYUWlTem1PSHBlTE0xb1hEUC94UGh6SFE1?= =?utf-8?B?TW5WYklKR0xUQXhFY0c5ZlZXUm1UTDE2eEtZMEhSVDdqU2wvUWcyQ0NCNGxi?= =?utf-8?B?VW5pTUw3eEVlMzA3TXFHMmc1aEVkQ2FsN1hHSCszMHFIRDRITFEwWnUxei8v?= =?utf-8?B?UncvYVFndy9EaFE2cGJkZnFyTkd1c2wzSW5sWHJFTDZKaWhxdHVab2FaWU1S?= =?utf-8?B?Ulp1MlQ1N01Udk5scnVqeGlWWkFXZngzb2I3TUhCUUhNRHJ5VDNxcXhlSUNn?= =?utf-8?Q?I44a3ZbhFF0ggY70lqrbA0Gv0umanNPTLmF4908?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-746f3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: d1813196-6899-4780-5fb1-08dc7f7a751e X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2024 00:58:30.9798 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY4P282MB3890 Hi Guenter, On 29/5/24 09:29, Guenter Roeck wrote: > On 5/28/24 09:15, Thomas Weißschuh wrote: >> 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. >> > > What Chromebook was that ? I can't see the code path in the EC source > that would get me there. > I believe Thomas and I both have the Framework 13 AMD, the source code is here: https://github.com/FrameworkComputer/EmbeddedController/tree/lotus-zephyr The organisation confuses me a little, but Dustin has previous said on the framework forums (https://community.frame.work/t/what-ec-is-used/38574/2): "This one is based on the Zephyr port of the ChromeOS EC, and tracks mainline more closely. It is in the branch lotus-zephyr. All of the model-specific code lives in zephyr/program/lotus. The 13"-specific code lives in a few subdirectories off the main tree named azalea." Also I just unplugged my fan and you are definitely correct, the EC only generates EC_FAN_SPEED_NOT_PRESENT for fans it does not have the capability to support. Even after a reboot it just returns 0 RPM for an unplugged fan. I thought about simulating a stall too, but I was mildly scared I was going to break one of the tiny blades. >>>>> 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? >> > > No, except I'd really like to know which Chromebook randomly generates > a EC_FAN_SPEED_NOT_PRESENT response because that really looks like a bug. > Also, can you reproduce the problem with the ectool command ? I have a feeling it was related to the concurrency problems between ACPI and the CrOS code that are being fixed in another patch by Ben Walsh, I was also seeing some weird behaviour sometimes but I *believe* it was fixed by that. Thanks, Steve