]> Git Repo - linux.git/blob - drivers/hwmon/surface_fan.c
Merge tag 'i2c-for-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa...
[linux.git] / drivers / hwmon / surface_fan.c
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.
5  *
6  * Copyright (C) 2023 Ivor Wanders <[email protected]>
7  */
8
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>
14
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 });
20
21 static int surface_fan_hwmon_read(struct device *dev,
22                                   enum hwmon_sensor_types type, u32 attr,
23                                   int channel, long *val)
24 {
25         struct ssam_device *sdev = dev_get_drvdata(dev);
26         int ret;
27         __le16 value;
28
29         ret = __ssam_fan_rpm_get(sdev, &value);
30         if (ret)
31                 return ret;
32
33         *val = le16_to_cpu(value);
34
35         return 0;
36 }
37
38 static const struct hwmon_channel_info *const surface_fan_info[] = {
39         HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
40         NULL
41 };
42
43 static const struct hwmon_ops surface_fan_hwmon_ops = {
44         .visible = 0444,
45         .read = surface_fan_hwmon_read,
46 };
47
48 static const struct hwmon_chip_info surface_fan_chip_info = {
49         .ops = &surface_fan_hwmon_ops,
50         .info = surface_fan_info,
51 };
52
53 static int surface_fan_probe(struct ssam_device *sdev)
54 {
55         struct device *hdev;
56
57         hdev = devm_hwmon_device_register_with_info(&sdev->dev,
58                                                     "surface_fan", sdev,
59                                                     &surface_fan_chip_info,
60                                                     NULL);
61
62         return PTR_ERR_OR_ZERO(hdev);
63 }
64
65 static const struct ssam_device_id ssam_fan_match[] = {
66         { SSAM_SDEV(FAN, SAM, 0x01, 0x01) },
67         {},
68 };
69 MODULE_DEVICE_TABLE(ssam, ssam_fan_match);
70
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,
77         },
78 };
79 module_ssam_device_driver(surface_fan);
80
81 MODULE_AUTHOR("Ivor Wanders <[email protected]>");
82 MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
83 MODULE_LICENSE("GPL");
This page took 0.044956 seconds and 4 git commands to generate.