Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / hwmon / surface_fan.c
blobaafb4ac92e6c6f7de2c8c4e49355d80a86cd0e25
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Surface Fan driver for Surface System Aggregator Module. It provides access
4 * to the fan's rpm through the hwmon system.
6 * Copyright (C) 2023 Ivor Wanders <ivor@iwanders.net>
7 */
9 #include <linux/hwmon.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/surface_aggregator/device.h>
13 #include <linux/types.h>
15 // SSAM
16 SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, {
17 .target_category = SSAM_SSH_TC_FAN,
18 .command_id = 0x01,
19 });
21 static int surface_fan_hwmon_read(struct device *dev,
22 enum hwmon_sensor_types type, u32 attr,
23 int channel, long *val)
25 struct ssam_device *sdev = dev_get_drvdata(dev);
26 int ret;
27 __le16 value;
29 ret = __ssam_fan_rpm_get(sdev, &value);
30 if (ret)
31 return ret;
33 *val = le16_to_cpu(value);
35 return 0;
38 static const struct hwmon_channel_info *const surface_fan_info[] = {
39 HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
40 NULL
43 static const struct hwmon_ops surface_fan_hwmon_ops = {
44 .visible = 0444,
45 .read = surface_fan_hwmon_read,
48 static const struct hwmon_chip_info surface_fan_chip_info = {
49 .ops = &surface_fan_hwmon_ops,
50 .info = surface_fan_info,
53 static int surface_fan_probe(struct ssam_device *sdev)
55 struct device *hdev;
57 hdev = devm_hwmon_device_register_with_info(&sdev->dev,
58 "surface_fan", sdev,
59 &surface_fan_chip_info,
60 NULL);
62 return PTR_ERR_OR_ZERO(hdev);
65 static const struct ssam_device_id ssam_fan_match[] = {
66 { SSAM_SDEV(FAN, SAM, 0x01, 0x01) },
67 {},
69 MODULE_DEVICE_TABLE(ssam, ssam_fan_match);
71 static struct ssam_device_driver surface_fan = {
72 .probe = surface_fan_probe,
73 .match_table = ssam_fan_match,
74 .driver = {
75 .name = "surface_fan",
76 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
79 module_ssam_device_driver(surface_fan);
81 MODULE_AUTHOR("Ivor Wanders <ivor@iwanders.net>");
82 MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
83 MODULE_LICENSE("GPL");