]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/hwmon.h
hwmon: (core) Add voltage attribute support to new API
[mirror_ubuntu-bionic-kernel.git] / include / linux / hwmon.h
1 /*
2 hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
3
4 This file declares helper functions for the sysfs class "hwmon",
5 for use by sensors drivers.
6
7 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
12 */
13
14 #ifndef _HWMON_H_
15 #define _HWMON_H_
16
17 #include <linux/bitops.h>
18
19 struct device;
20 struct attribute_group;
21
22 enum hwmon_sensor_types {
23 hwmon_chip,
24 hwmon_temp,
25 hwmon_in,
26 hwmon_curr,
27 hwmon_power,
28 hwmon_energy,
29 };
30
31 enum hwmon_chip_attributes {
32 hwmon_chip_temp_reset_history,
33 hwmon_chip_in_reset_history,
34 hwmon_chip_register_tz,
35 hwmon_chip_update_interval,
36 hwmon_chip_alarms,
37 };
38
39 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
40 #define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
41 #define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
42 #define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
43 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
44
45 enum hwmon_temp_attributes {
46 hwmon_temp_input = 0,
47 hwmon_temp_type,
48 hwmon_temp_lcrit,
49 hwmon_temp_lcrit_hyst,
50 hwmon_temp_min,
51 hwmon_temp_min_hyst,
52 hwmon_temp_max,
53 hwmon_temp_max_hyst,
54 hwmon_temp_crit,
55 hwmon_temp_crit_hyst,
56 hwmon_temp_emergency,
57 hwmon_temp_emergency_hyst,
58 hwmon_temp_alarm,
59 hwmon_temp_lcrit_alarm,
60 hwmon_temp_min_alarm,
61 hwmon_temp_max_alarm,
62 hwmon_temp_crit_alarm,
63 hwmon_temp_emergency_alarm,
64 hwmon_temp_fault,
65 hwmon_temp_offset,
66 hwmon_temp_label,
67 hwmon_temp_lowest,
68 hwmon_temp_highest,
69 hwmon_temp_reset_history,
70 };
71
72 #define HWMON_T_INPUT BIT(hwmon_temp_input)
73 #define HWMON_T_TYPE BIT(hwmon_temp_type)
74 #define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
75 #define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
76 #define HWMON_T_MIN BIT(hwmon_temp_min)
77 #define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
78 #define HWMON_T_MAX BIT(hwmon_temp_max)
79 #define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
80 #define HWMON_T_CRIT BIT(hwmon_temp_crit)
81 #define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
82 #define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
83 #define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
84 #define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
85 #define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
86 #define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
87 #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
88 #define HWMON_T_FAULT BIT(hwmon_temp_fault)
89 #define HWMON_T_OFFSET BIT(hwmon_temp_offset)
90 #define HWMON_T_LABEL BIT(hwmon_temp_label)
91 #define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
92 #define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
93 #define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
94
95 enum hwmon_in_attributes {
96 hwmon_in_input,
97 hwmon_in_min,
98 hwmon_in_max,
99 hwmon_in_lcrit,
100 hwmon_in_crit,
101 hwmon_in_average,
102 hwmon_in_lowest,
103 hwmon_in_highest,
104 hwmon_in_reset_history,
105 hwmon_in_label,
106 hwmon_in_alarm,
107 hwmon_in_min_alarm,
108 hwmon_in_max_alarm,
109 hwmon_in_lcrit_alarm,
110 hwmon_in_crit_alarm,
111 };
112
113 #define HWMON_I_INPUT BIT(hwmon_in_input)
114 #define HWMON_I_MIN BIT(hwmon_in_min)
115 #define HWMON_I_MAX BIT(hwmon_in_max)
116 #define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
117 #define HWMON_I_CRIT BIT(hwmon_in_crit)
118 #define HWMON_I_AVERAGE BIT(hwmon_in_average)
119 #define HWMON_I_LOWEST BIT(hwmon_in_lowest)
120 #define HWMON_I_HIGHEST BIT(hwmon_in_highest)
121 #define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
122 #define HWMON_I_LABEL BIT(hwmon_in_label)
123 #define HWMON_I_ALARM BIT(hwmon_in_alarm)
124 #define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
125 #define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
126 #define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
127 #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
128
129 /**
130 * struct hwmon_ops - hwmon device operations
131 * @is_visible: Callback to return attribute visibility. Mandatory.
132 * Parameters are:
133 * @const void *drvdata:
134 * Pointer to driver-private data structure passed
135 * as argument to hwmon_device_register_with_info().
136 * @type: Sensor type
137 * @attr: Sensor attribute
138 * @channel:
139 * Channel number
140 * The function returns the file permissions.
141 * If the return value is 0, no attribute will be created.
142 * @read: Read callback. Optional. If not provided, attributes
143 * will not be readable.
144 * Parameters are:
145 * @dev: Pointer to hardware monitoring device
146 * @type: Sensor type
147 * @attr: Sensor attribute
148 * @channel:
149 * Channel number
150 * @val: Pointer to returned value
151 * The function returns 0 on success or a negative error number.
152 * @write: Write callback. Optional. If not provided, attributes
153 * will not be writable.
154 * Parameters are:
155 * @dev: Pointer to hardware monitoring device
156 * @type: Sensor type
157 * @attr: Sensor attribute
158 * @channel:
159 * Channel number
160 * @val: Value to write
161 * The function returns 0 on success or a negative error number.
162 */
163 struct hwmon_ops {
164 umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
165 u32 attr, int channel);
166 int (*read)(struct device *dev, enum hwmon_sensor_types type,
167 u32 attr, int channel, long *val);
168 int (*write)(struct device *dev, enum hwmon_sensor_types type,
169 u32 attr, int channel, long val);
170 };
171
172 /**
173 * Channel information
174 * @type: Channel type.
175 * @config: Pointer to NULL-terminated list of channel parameters.
176 * Use for per-channel attributes.
177 */
178 struct hwmon_channel_info {
179 enum hwmon_sensor_types type;
180 const u32 *config;
181 };
182
183 /**
184 * Chip configuration
185 * @ops: Pointer to hwmon operations.
186 * @info: Null-terminated list of channel information.
187 */
188 struct hwmon_chip_info {
189 const struct hwmon_ops *ops;
190 const struct hwmon_channel_info **info;
191 };
192
193 struct device *hwmon_device_register(struct device *dev);
194 struct device *
195 hwmon_device_register_with_groups(struct device *dev, const char *name,
196 void *drvdata,
197 const struct attribute_group **groups);
198 struct device *
199 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
200 void *drvdata,
201 const struct attribute_group **groups);
202 struct device *
203 hwmon_device_register_with_info(struct device *dev,
204 const char *name, void *drvdata,
205 const struct hwmon_chip_info *info,
206 const struct attribute_group **groups);
207 struct device *
208 devm_hwmon_device_register_with_info(struct device *dev,
209 const char *name, void *drvdata,
210 const struct hwmon_chip_info *info,
211 const struct attribute_group **groups);
212
213 void hwmon_device_unregister(struct device *dev);
214 void devm_hwmon_device_unregister(struct device *dev);
215
216 #endif