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.
6 * Copyright (C) 2023 Ivor Wanders <ivor@iwanders.net>
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
,
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
);
29 ret
= __ssam_fan_rpm_get(sdev
, &value
);
33 *val
= le16_to_cpu(value
);
38 static const struct hwmon_channel_info
*const surface_fan_info
[] = {
39 HWMON_CHANNEL_INFO(fan
, HWMON_F_INPUT
),
43 static const struct hwmon_ops surface_fan_hwmon_ops
= {
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
)
57 hdev
= devm_hwmon_device_register_with_info(&sdev
->dev
,
59 &surface_fan_chip_info
,
62 return PTR_ERR_OR_ZERO(hdev
);
65 static const struct ssam_device_id ssam_fan_match
[] = {
66 { SSAM_SDEV(FAN
, SAM
, 0x01, 0x01) },
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
,
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");