linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maximilian Luz <luzmaximilian@gmail.com>
To: Ivor Wanders <ivor@iwanders.net>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Jonathan Corbet <corbet@lwn.net>,
	Hans de Goede <hdegoede@redhat.com>,
	Mark Gross <markgross@kernel.org>
Cc: linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH v2 1/2] hwmon: add fan speed monitoring driver for Surface devices
Date: Sat, 30 Dec 2023 17:32:04 +0100	[thread overview]
Message-ID: <f564b1b4-d8d1-4809-9cc0-b01aa53570a0@gmail.com> (raw)
In-Reply-To: <20231228003444.5580-2-ivor@iwanders.net>

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 <ivor@iwanders.net>
> 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 <ivor@iwanders.net>
> + */
> +
> +#include <linux/hwmon.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>

As far as I can see, linux/platform_device.h is not needed.

Regards,
Max

> +#include <linux/surface_aggregator/device.h>
> +#include <linux/types.h>
> +
> +// 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 <ivor@iwanders.net>");
> +MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
> +MODULE_LICENSE("GPL");

  parent reply	other threads:[~2023-12-30 16:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28  0:34 [PATCH v2 0/2] Surface fan monitoring driver Ivor Wanders
2023-12-28  0:34 ` [PATCH v2 1/2] hwmon: add fan speed monitoring driver for Surface devices Ivor Wanders
2023-12-28 15:28   ` Armin Wolf
2023-12-28 23:50     ` Ivor Wanders
2023-12-30 16:32   ` Maximilian Luz [this message]
2023-12-30 22:46     ` Ivor Wanders
2023-12-28  0:34 ` [PATCH v2 2/2] platform/surface: aggregator_registry: add entry for fan speed Ivor Wanders
2023-12-29 22:42   ` Maximilian Luz
2023-12-30 17:19     ` Maximilian Luz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f564b1b4-d8d1-4809-9cc0-b01aa53570a0@gmail.com \
    --to=luzmaximilian@gmail.com \
    --cc=corbet@lwn.net \
    --cc=hdegoede@redhat.com \
    --cc=ivor@iwanders.net \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).