2 hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
4 This file declares helper functions for the sysfs class "hwmon",
5 for use by sensors drivers.
7 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
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.
17 #include <linux/bitops.h>
20 struct attribute_group;
22 enum hwmon_sensor_types {
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,
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)
45 enum hwmon_temp_attributes {
49 hwmon_temp_lcrit_hyst,
57 hwmon_temp_emergency_hyst,
59 hwmon_temp_lcrit_alarm,
62 hwmon_temp_crit_alarm,
63 hwmon_temp_emergency_alarm,
69 hwmon_temp_reset_history,
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)
95 enum hwmon_in_attributes {
104 hwmon_in_reset_history,
109 hwmon_in_lcrit_alarm,
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)
130 * struct hwmon_ops - hwmon device operations
131 * @is_visible: Callback to return attribute visibility. Mandatory.
133 * @const void *drvdata:
134 * Pointer to driver-private data structure passed
135 * as argument to hwmon_device_register_with_info().
137 * @attr: Sensor attribute
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.
145 * @dev: Pointer to hardware monitoring device
147 * @attr: Sensor attribute
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.
155 * @dev: Pointer to hardware monitoring device
157 * @attr: Sensor attribute
160 * @val: Value to write
161 * The function returns 0 on success or a negative error number.
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);
173 * Channel information
174 * @type: Channel type.
175 * @config: Pointer to NULL-terminated list of channel parameters.
176 * Use for per-channel attributes.
178 struct hwmon_channel_info {
179 enum hwmon_sensor_types type;
185 * @ops: Pointer to hwmon operations.
186 * @info: Null-terminated list of channel information.
188 struct hwmon_chip_info {
189 const struct hwmon_ops *ops;
190 const struct hwmon_channel_info **info;
193 struct device *hwmon_device_register(struct device *dev);
195 hwmon_device_register_with_groups(struct device *dev, const char *name,
197 const struct attribute_group **groups);
199 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
201 const struct attribute_group **groups);
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);
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);
213 void hwmon_device_unregister(struct device *dev);
214 void devm_hwmon_device_unregister(struct device *dev);