-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhwmon_fan.c
152 lines (128 loc) · 3.03 KB
/
hwmon_fan.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
#include "pr.h"
#include <linux/device.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/init.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include "ec.h"
#include "fan.h"
#include "features.h"
#include "hwmon_fan.h"
#include "pdev.h"
/* ========================================================================== */
static struct device *qc71_hwmon_fan_dev;
/* ========================================================================== */
static umode_t qc71_hwmon_fan_is_visible(const void *data, enum hwmon_sensor_types type,
u32 attr, int channel)
{
switch (type) {
case hwmon_fan:
switch (attr) {
case hwmon_fan_input:
case hwmon_fan_fault:
return 0444;
}
break;
case hwmon_temp:
switch (attr) {
case hwmon_temp_input:
case hwmon_temp_label:
return 0444;
}
default:
break;
}
return 0;
}
static int qc71_hwmon_fan_read(struct device *device, enum hwmon_sensor_types type,
u32 attr, int channel, long *value)
{
int err;
switch (type) {
case hwmon_fan:
switch (attr) {
case hwmon_fan_input:
err = qc71_fan_get_rpm(channel);
if (err < 0)
return err;
*value = err;
break;
default:
return -EOPNOTSUPP;
}
break;
case hwmon_temp:
switch (attr) {
case hwmon_temp_input:
err = qc71_fan_get_temp(channel);
if (err < 0)
return err;
*value = err * 1000;
break;
default:
return -EOPNOTSUPP;
}
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static int qc71_hwmon_fan_read_string(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str)
{
static const char * const temp_labels[] = {
"fan1_temp",
"fan2_temp",
};
switch (type) {
case hwmon_temp:
switch (attr) {
case hwmon_temp_label:
*str = temp_labels[channel];
break;
default:
return -EOPNOTSUPP;
}
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
/* ========================================================================== */
static const struct hwmon_channel_info *qc71_hwmon_fan_ch_info[] = {
HWMON_CHANNEL_INFO(fan,
HWMON_F_INPUT,
HWMON_F_INPUT),
HWMON_CHANNEL_INFO(temp,
HWMON_T_INPUT | HWMON_T_LABEL,
HWMON_T_INPUT | HWMON_T_LABEL),
NULL
};
static const struct hwmon_ops qc71_hwmon_fan_ops = {
.is_visible = qc71_hwmon_fan_is_visible,
.read = qc71_hwmon_fan_read,
.read_string = qc71_hwmon_fan_read_string,
};
static const struct hwmon_chip_info qc71_hwmon_fan_chip_info = {
.ops = &qc71_hwmon_fan_ops,
.info = qc71_hwmon_fan_ch_info,
};
/* ========================================================================== */
int __init qc71_hwmon_fan_setup(void)
{
qc71_hwmon_fan_dev = hwmon_device_register_with_info(
&qc71_platform_dev->dev, KBUILD_MODNAME ".hwmon.fan", NULL,
&qc71_hwmon_fan_chip_info, NULL);
if (IS_ERR(qc71_hwmon_fan_dev))
return PTR_ERR(qc71_hwmon_fan_dev);
return 0;
}
void qc71_hwmon_fan_cleanup(void)
{
if (!IS_ERR_OR_NULL(qc71_hwmon_fan_dev))
hwmon_device_unregister(qc71_hwmon_fan_dev);
}