1 // SPDX-License-Identifier: GPL-2.0+
3 * Surface Fan driver for Surface System Aggregator Module. It provides access
4 * to the fan's rpm through the hwmon system.
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>
16 SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, {
17 .target_category = SSAM_SSH_TC_FAN,
22 static umode_t surface_fan_hwmon_is_visible(const void *drvdata,
23 enum hwmon_sensor_types type, u32 attr,
29 static int surface_fan_hwmon_read(struct device *dev,
30 enum hwmon_sensor_types type, u32 attr,
31 int channel, long *val)
33 struct ssam_device *sdev = dev_get_drvdata(dev);
37 ret = __ssam_fan_rpm_get(sdev, &value);
41 *val = le16_to_cpu(value);
46 static const struct hwmon_channel_info *const surface_fan_info[] = {
47 HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
51 static const struct hwmon_ops surface_fan_hwmon_ops = {
52 .is_visible = surface_fan_hwmon_is_visible,
53 .read = surface_fan_hwmon_read,
56 static const struct hwmon_chip_info surface_fan_chip_info = {
57 .ops = &surface_fan_hwmon_ops,
58 .info = surface_fan_info,
61 static int surface_fan_probe(struct ssam_device *sdev)
65 hdev = devm_hwmon_device_register_with_info(&sdev->dev,
67 &surface_fan_chip_info,
70 return PTR_ERR_OR_ZERO(hdev);
73 static const struct ssam_device_id ssam_fan_match[] = {
74 { SSAM_SDEV(FAN, SAM, 0x01, 0x01) },
77 MODULE_DEVICE_TABLE(ssam, ssam_fan_match);
79 static struct ssam_device_driver surface_fan = {
80 .probe = surface_fan_probe,
81 .match_table = ssam_fan_match,
83 .name = "surface_fan",
84 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
87 module_ssam_device_driver(surface_fan);
90 MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
91 MODULE_LICENSE("GPL");