Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5168607rdb; Sat, 30 Dec 2023 08:35:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFaQlGvUE4fPOlaPVGqDq5mhcMb5yMpaw0vUS/DO4CiwTSal6MWNKy0cW2xNa9XaCECySSV X-Received: by 2002:a05:622a:1b22:b0:423:a9a6:1345 with SMTP id bb34-20020a05622a1b2200b00423a9a61345mr17515263qtb.2.1703954104638; Sat, 30 Dec 2023 08:35:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703954104; cv=none; d=google.com; s=arc-20160816; b=YexYUiL1dhVQQR1UYGvjv0ajT57m4CuOa5PxSSVaAD41ychd+FgktqkniIM0GB15Xg lUoytk3IzVzfDuU8iC9n+I28vGZfcIzi0nXfhsBkTWluQNEgCfJkngikROyBE4yVCr5E aTMYCSzUvPiAUvCzmXvBj9plcZtAXffxYBRO1sEkXZ8QSGiZgOGpI8Y641+vojrQBrP7 lixLBcwKWjQoKAAuK/FHLL9SeGzzUT5ICmkDp/TC4nkOAnBXYpNtUDDbzhFC+Jc5NmCU BgY0fumykncb8tArhgYcBUs5TL8LpLGWqWZYjqsdeN8m7LNCKYxYaPZhWymVWp+ytV12 qRNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=rZB0c1TeByaHjk+7yG8Kc7dtPWL4o/WvzFcOuBAVwGI=; fh=mcBTSntseHKjcAJKWHyiReT+DVa76qiZNhi12q+o38o=; b=KD5LEyA6jrvsiDhsuBzCmuG+bfd8OjiEMFG66Q/XuaYC0+3H/tf4qpGVQabV8P1ugw MIk0ZrxMk5hTcDGrRuw5R8Ij+euy9e9h6RB2nouXHmLw+Ykb304Fh+vEgmx94LBvYGTH /kXP0nfBBie9am2veGtEaJq8pCfX7hk36S4dy8kJfyqW7GvMWZ/4BupkYkeg7ldJogP6 xRArCwUpPT2JqzBbwOzUgguaK8ffbCvliFRq8cnC5zg+8ONiseH7ZjcN7epeb+FPXM9D p6gLBY7T1vo9fDl2htZ4ws/e5Jbqdbt0RGE9z0AncdOSciA5lFlUTr//8beZyp9DO/m1 jN2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XrVT7byR; spf=pass (google.com: domain of linux-kernel+bounces-13510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m4-20020a05622a118400b00428127e6e3asi1155597qtk.258.2023.12.30.08.35.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Dec 2023 08:35:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XrVT7byR; spf=pass (google.com: domain of linux-kernel+bounces-13510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 454B11C214B0 for ; Sat, 30 Dec 2023 16:35:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE7F9C2C6; Sat, 30 Dec 2023 16:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XrVT7byR" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69BA3C2C5; Sat, 30 Dec 2023 16:32:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5537114380bso6120977a12.3; Sat, 30 Dec 2023 08:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703953929; x=1704558729; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=rZB0c1TeByaHjk+7yG8Kc7dtPWL4o/WvzFcOuBAVwGI=; b=XrVT7byRkAeSaKy13LOYHhT56epZIBWi0Dgehc2nT8SYnJk/8PD6hcZQX1VktOcC6N 2EL4MZvq3iWhOQkcNp1waDqySirDXY1G4JSwQscAWWZieMGlqQELZOfb87gzNbdPfkYi xXeDTwNBgTR3yDxTcaBPD1TMIapqxHm9XWifXO+QL1iqR+kXennrlNBvkJZM7xK/Vjcb 54nv+CJN2h5K9P4HhwT8gdxN89+KcEa25TaozBVwEiVEFtuZYlPmwCp29+w8cbB7J1zR Z/ViESnHf25wdIKf+v0RTRioH71MxjAoOhd1aMeGetsquKItmd5kd+jT/v2VRvtb+d5F 6+KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703953929; x=1704558729; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rZB0c1TeByaHjk+7yG8Kc7dtPWL4o/WvzFcOuBAVwGI=; b=ZQkka1fhJgwezxDxBRFKQKZ5FYAMH5ds3NLsXBOYqTArmkjhI5MXuXGexbj2QjeltC znQww8RvLIV8NSgQyT/BOqFf0LnEtndqX2KVXeDkk3RyK0qqPczZFJGutoFLUhshWMyC 5y8+xNKSs3rXIkFtUqu622kfUh7e7yWvMJnSQe6rVNO9UzOdfCdsf+QGHS91nweIqHXU fsu1sKhZ+lo1ToNknjHLKmTlZEEL0mL9H4lYjnfOg472axyKc166kiM54xqoE7WToj6T Azn4DWxmJDGJ7w3pNQHBJ/+W5/3UMemFMAkEMBnLN07UYWaTLf4ovc9/LF7ymUDknqWr NbLg== X-Gm-Message-State: AOJu0YzYERwyJ8/9tuX6tWckLzEBlFOhxFYAhekZnLmDwQ4NWZ0TGr1C hery0YvP0ssVT+WILN/tmxgDkwlWtTY= X-Received: by 2002:a50:c11a:0:b0:555:6bef:7c3d with SMTP id l26-20020a50c11a000000b005556bef7c3dmr2043720edf.21.1703953929367; Sat, 30 Dec 2023 08:32:09 -0800 (PST) Received: from ?IPV6:2a02:8071:b783:140:927c:82ba:d32d:99c1? ([2a02:8071:b783:140:927c:82ba:d32d:99c1]) by smtp.gmail.com with ESMTPSA id g6-20020a056402114600b005561ad0368fsm213251edw.12.2023.12.30.08.32.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Dec 2023 08:32:08 -0800 (PST) Message-ID: Date: Sat, 30 Dec 2023 17:32:04 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] hwmon: add fan speed monitoring driver for Surface devices To: Ivor Wanders , Jean Delvare , Guenter Roeck , Jonathan Corbet , Hans de Goede , Mark Gross Cc: linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org References: <20231228003444.5580-1-ivor@iwanders.net> <20231228003444.5580-2-ivor@iwanders.net> Content-Language: en-US From: Maximilian Luz In-Reply-To: <20231228003444.5580-2-ivor@iwanders.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/28/23 01:34, Ivor Wanders wrote: > Adds a driver that provides read only access to the fan speed for Microsoft > Surface Pro devices. The fan speed is always regulated by the EC and cannot > be influenced directly. > > Signed-off-by: Ivor Wanders > Link: https://github.com/linux-surface/kernel/pull/144 > --- > Changes in v2: > - Removed all sysfs attributes except fan1_input. Simplified code > and updated documentation accordingly. > --- > Documentation/hwmon/index.rst | 1 + > Documentation/hwmon/surface_fan.rst | 25 +++++++ > MAINTAINERS | 8 +++ > drivers/hwmon/Kconfig | 13 ++++ > drivers/hwmon/Makefile | 1 + > drivers/hwmon/surface_fan.c | 105 ++++++++++++++++++++++++++++ > 6 files changed, 153 insertions(+) > create mode 100644 Documentation/hwmon/surface_fan.rst > create mode 100644 drivers/hwmon/surface_fan.c > [...] > diff --git a/drivers/hwmon/surface_fan.c b/drivers/hwmon/surface_fan.c > new file mode 100644 > index 000000000..0160a585c > --- /dev/null > +++ b/drivers/hwmon/surface_fan.c > @@ -0,0 +1,105 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Surface Fan driver for Surface System Aggregator Module. It provides access > + * to the fan's rpm through the hwmon system. > + * > + * Copyright (C) 2023 Ivor Wanders > + */ > + > +#include > +#include > +#include > +#include As far as I can see, linux/platform_device.h is not needed. Regards, Max > +#include > +#include > + > +// SSAM > +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, { > + .target_category = SSAM_SSH_TC_FAN, > + .command_id = 0x01, > +}); > + > +// hwmon > +umode_t surface_fan_hwmon_is_visible(const void *drvdata, > + enum hwmon_sensor_types type, u32 attr, > + int channel) > +{ > + if (type != hwmon_fan) > + return 0; > + > + if (attr != hwmon_fan_input) > + return 0; > + > + return 0444; > +} > + > +static int surface_fan_hwmon_read(struct device *dev, > + enum hwmon_sensor_types type, u32 attr, > + int channel, long *val) > +{ > + struct ssam_device *sdev = dev_get_drvdata(dev); > + __le16 value; > + > + if (type != hwmon_fan) > + return -EOPNOTSUPP; > + > + if (attr != hwmon_fan_input) > + return -EOPNOTSUPP; > + > + if (__ssam_fan_rpm_get(sdev, &value)) > + return -EIO; > + > + *val = le16_to_cpu(value); > + > + return 0; > +} > + > +static const struct hwmon_channel_info *const surface_fan_info[] = { > + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT), > + NULL > +}; > + > +static const struct hwmon_ops surface_fan_hwmon_ops = { > + .is_visible = surface_fan_hwmon_is_visible, > + .read = surface_fan_hwmon_read, > +}; > + > +static const struct hwmon_chip_info surface_fan_chip_info = { > + .ops = &surface_fan_hwmon_ops, > + .info = surface_fan_info, > +}; > + > +static int surface_fan_probe(struct ssam_device *sdev) > +{ > + struct device *hdev; > + > + hdev = devm_hwmon_device_register_with_info(&sdev->dev, "fan", sdev, > + &surface_fan_chip_info, > + NULL); > + if (IS_ERR(hdev)) > + return PTR_ERR(hdev); > + > + ssam_device_set_drvdata(sdev, sdev); > + > + return 0; > +} > + > +static const struct ssam_device_id ssam_fan_match[] = { > + { SSAM_SDEV(FAN, SAM, 0x01, 0x01) }, > + {}, > +}; > +MODULE_DEVICE_TABLE(ssam, ssam_fan_match); > + > +static struct ssam_device_driver surface_fan = { > + .probe = surface_fan_probe, > + .match_table = ssam_fan_match, > + .driver = { > + .name = "surface_fan", > + .probe_type = PROBE_PREFER_ASYNCHRONOUS, > + }, > +}; > +module_ssam_device_driver(surface_fan); > + > +MODULE_AUTHOR("Ivor Wanders "); > +MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module"); > +MODULE_LICENSE("GPL");