This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asus-ec-sensors.c
152 lines (129 loc) · 3.1 KB
/
asus-ec-sensors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Asus EC sensor driver
*
* Copyright (C) 2020 Anthony DeRossi <[email protected]>
*/
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
MODULE_AUTHOR("Anthony DeRossi <[email protected]>");
MODULE_DESCRIPTION("Asus EC sensor driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.1");
#define T_SENSOR_OFFSET 61
static const struct dmi_system_id asus_ec_sensors_dmi_match[] = {
{
/* Asus Prime X570-Pro */
.matches = {
DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "PRIME X570-PRO"),
},
},
{}
};
MODULE_DEVICE_TABLE(dmi, asus_ec_sensors_dmi_match);
static umode_t asus_hwmon_is_visible(const void *data,
enum hwmon_sensor_types type, u32 attr,
int channel)
{
switch (type) {
case hwmon_temp:
switch (attr) {
case hwmon_temp_input:
case hwmon_temp_label:
return 0444;
default:
break;
}
default:
break;
}
return 0;
}
static int asus_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
int err;
u8 byte_read;
switch (type) {
case hwmon_temp:
switch (attr) {
case hwmon_temp_input:
err = ec_read(T_SENSOR_OFFSET, &byte_read);
if (err)
return err;
*val = byte_read * 1000;
return 0;
default:
break;
}
default:
break;
}
return -EOPNOTSUPP;
}
static int asus_hwmon_read_label(struct device *dev,
enum hwmon_sensor_types type, u32 attr,
int channel, const char **str)
{
switch (type) {
case hwmon_temp:
*str = "T_Sensor";
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static const struct hwmon_ops asus_hwmon_ops = {
.is_visible = asus_hwmon_is_visible,
.read = asus_hwmon_read,
.read_string = asus_hwmon_read_label,
};
static const struct hwmon_channel_info *asus_hwmon_info[] = {
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_LABEL),
NULL
};
static const struct hwmon_chip_info asus_hwmon_chip_info = {
.ops = &asus_hwmon_ops,
.info = asus_hwmon_info,
};
static struct platform_driver asus_platform_driver = {
.driver = {
.name = "asus-ec-sensors",
},
};
static int __init asus_platform_probe(struct platform_device *pdev)
{
struct device *hwmon_dev =
devm_hwmon_device_register_with_info(&pdev->dev, "asusec",
NULL,
&asus_hwmon_chip_info,
NULL);
return PTR_ERR_OR_ZERO(hwmon_dev);
}
static struct platform_device *asus_platform_device;
static int __init asus_ec_sensors_init(void)
{
acpi_handle ec_handle;
if (!dmi_first_match(asus_ec_sensors_dmi_match))
return -ENODEV;
ec_handle = ec_get_handle();
if (!ec_handle)
return -ENODEV;
asus_platform_device = platform_create_bundle(&asus_platform_driver,
asus_platform_probe,
NULL, 0, NULL, 0);
return PTR_ERR_OR_ZERO(asus_platform_device);
}
static void __exit asus_ec_sensors_exit(void)
{
platform_device_unregister(asus_platform_device);
platform_driver_unregister(&asus_platform_driver);
}
module_init(asus_ec_sensors_init);
module_exit(asus_ec_sensors_exit);