hwmon: (core) Add current attribute support to new API
[linux-2.6/btrfs-unstable.git] / include / linux / hwmon.h
blob8781c2253b1daad854d21e6b5f26be100d6d01c9
1 /*
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.
14 #ifndef _HWMON_H_
15 #define _HWMON_H_
17 #include <linux/bitops.h>
19 struct device;
20 struct attribute_group;
22 enum hwmon_sensor_types {
23 hwmon_chip,
24 hwmon_temp,
25 hwmon_in,
26 hwmon_curr,
27 hwmon_power,
28 hwmon_energy,
31 enum hwmon_chip_attributes {
32 hwmon_chip_temp_reset_history,
33 hwmon_chip_in_reset_history,
34 hwmon_chip_curr_reset_history,
35 hwmon_chip_register_tz,
36 hwmon_chip_update_interval,
37 hwmon_chip_alarms,
40 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
41 #define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
42 #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
43 #define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
44 #define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
45 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
47 enum hwmon_temp_attributes {
48 hwmon_temp_input = 0,
49 hwmon_temp_type,
50 hwmon_temp_lcrit,
51 hwmon_temp_lcrit_hyst,
52 hwmon_temp_min,
53 hwmon_temp_min_hyst,
54 hwmon_temp_max,
55 hwmon_temp_max_hyst,
56 hwmon_temp_crit,
57 hwmon_temp_crit_hyst,
58 hwmon_temp_emergency,
59 hwmon_temp_emergency_hyst,
60 hwmon_temp_alarm,
61 hwmon_temp_lcrit_alarm,
62 hwmon_temp_min_alarm,
63 hwmon_temp_max_alarm,
64 hwmon_temp_crit_alarm,
65 hwmon_temp_emergency_alarm,
66 hwmon_temp_fault,
67 hwmon_temp_offset,
68 hwmon_temp_label,
69 hwmon_temp_lowest,
70 hwmon_temp_highest,
71 hwmon_temp_reset_history,
74 #define HWMON_T_INPUT BIT(hwmon_temp_input)
75 #define HWMON_T_TYPE BIT(hwmon_temp_type)
76 #define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
77 #define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
78 #define HWMON_T_MIN BIT(hwmon_temp_min)
79 #define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
80 #define HWMON_T_MAX BIT(hwmon_temp_max)
81 #define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
82 #define HWMON_T_CRIT BIT(hwmon_temp_crit)
83 #define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
84 #define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
85 #define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
86 #define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
87 #define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
88 #define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
89 #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
90 #define HWMON_T_FAULT BIT(hwmon_temp_fault)
91 #define HWMON_T_OFFSET BIT(hwmon_temp_offset)
92 #define HWMON_T_LABEL BIT(hwmon_temp_label)
93 #define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
94 #define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
95 #define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
97 enum hwmon_in_attributes {
98 hwmon_in_input,
99 hwmon_in_min,
100 hwmon_in_max,
101 hwmon_in_lcrit,
102 hwmon_in_crit,
103 hwmon_in_average,
104 hwmon_in_lowest,
105 hwmon_in_highest,
106 hwmon_in_reset_history,
107 hwmon_in_label,
108 hwmon_in_alarm,
109 hwmon_in_min_alarm,
110 hwmon_in_max_alarm,
111 hwmon_in_lcrit_alarm,
112 hwmon_in_crit_alarm,
115 #define HWMON_I_INPUT BIT(hwmon_in_input)
116 #define HWMON_I_MIN BIT(hwmon_in_min)
117 #define HWMON_I_MAX BIT(hwmon_in_max)
118 #define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
119 #define HWMON_I_CRIT BIT(hwmon_in_crit)
120 #define HWMON_I_AVERAGE BIT(hwmon_in_average)
121 #define HWMON_I_LOWEST BIT(hwmon_in_lowest)
122 #define HWMON_I_HIGHEST BIT(hwmon_in_highest)
123 #define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
124 #define HWMON_I_LABEL BIT(hwmon_in_label)
125 #define HWMON_I_ALARM BIT(hwmon_in_alarm)
126 #define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
127 #define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
128 #define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
129 #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
131 enum hwmon_curr_attributes {
132 hwmon_curr_input,
133 hwmon_curr_min,
134 hwmon_curr_max,
135 hwmon_curr_lcrit,
136 hwmon_curr_crit,
137 hwmon_curr_average,
138 hwmon_curr_lowest,
139 hwmon_curr_highest,
140 hwmon_curr_reset_history,
141 hwmon_curr_label,
142 hwmon_curr_alarm,
143 hwmon_curr_min_alarm,
144 hwmon_curr_max_alarm,
145 hwmon_curr_lcrit_alarm,
146 hwmon_curr_crit_alarm,
149 #define HWMON_C_INPUT BIT(hwmon_curr_input)
150 #define HWMON_C_MIN BIT(hwmon_curr_min)
151 #define HWMON_C_MAX BIT(hwmon_curr_max)
152 #define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
153 #define HWMON_C_CRIT BIT(hwmon_curr_crit)
154 #define HWMON_C_AVERAGE BIT(hwmon_curr_average)
155 #define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
156 #define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
157 #define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
158 #define HWMON_C_LABEL BIT(hwmon_curr_label)
159 #define HWMON_C_ALARM BIT(hwmon_curr_alarm)
160 #define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
161 #define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
162 #define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
163 #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
166 * struct hwmon_ops - hwmon device operations
167 * @is_visible: Callback to return attribute visibility. Mandatory.
168 * Parameters are:
169 * @const void *drvdata:
170 * Pointer to driver-private data structure passed
171 * as argument to hwmon_device_register_with_info().
172 * @type: Sensor type
173 * @attr: Sensor attribute
174 * @channel:
175 * Channel number
176 * The function returns the file permissions.
177 * If the return value is 0, no attribute will be created.
178 * @read: Read callback. Optional. If not provided, attributes
179 * will not be readable.
180 * Parameters are:
181 * @dev: Pointer to hardware monitoring device
182 * @type: Sensor type
183 * @attr: Sensor attribute
184 * @channel:
185 * Channel number
186 * @val: Pointer to returned value
187 * The function returns 0 on success or a negative error number.
188 * @write: Write callback. Optional. If not provided, attributes
189 * will not be writable.
190 * Parameters are:
191 * @dev: Pointer to hardware monitoring device
192 * @type: Sensor type
193 * @attr: Sensor attribute
194 * @channel:
195 * Channel number
196 * @val: Value to write
197 * The function returns 0 on success or a negative error number.
199 struct hwmon_ops {
200 umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
201 u32 attr, int channel);
202 int (*read)(struct device *dev, enum hwmon_sensor_types type,
203 u32 attr, int channel, long *val);
204 int (*write)(struct device *dev, enum hwmon_sensor_types type,
205 u32 attr, int channel, long val);
209 * Channel information
210 * @type: Channel type.
211 * @config: Pointer to NULL-terminated list of channel parameters.
212 * Use for per-channel attributes.
214 struct hwmon_channel_info {
215 enum hwmon_sensor_types type;
216 const u32 *config;
220 * Chip configuration
221 * @ops: Pointer to hwmon operations.
222 * @info: Null-terminated list of channel information.
224 struct hwmon_chip_info {
225 const struct hwmon_ops *ops;
226 const struct hwmon_channel_info **info;
229 struct device *hwmon_device_register(struct device *dev);
230 struct device *
231 hwmon_device_register_with_groups(struct device *dev, const char *name,
232 void *drvdata,
233 const struct attribute_group **groups);
234 struct device *
235 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
236 void *drvdata,
237 const struct attribute_group **groups);
238 struct device *
239 hwmon_device_register_with_info(struct device *dev,
240 const char *name, void *drvdata,
241 const struct hwmon_chip_info *info,
242 const struct attribute_group **groups);
243 struct device *
244 devm_hwmon_device_register_with_info(struct device *dev,
245 const char *name, void *drvdata,
246 const struct hwmon_chip_info *info,
247 const struct attribute_group **groups);
249 void hwmon_device_unregister(struct device *dev);
250 void devm_hwmon_device_unregister(struct device *dev);
252 #endif