diff options
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm80.c | 247 |
1 files changed, 112 insertions, 135 deletions
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 32dfdf38b161..612807c786e2 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/hwmon.h> | 29 | #include <linux/hwmon.h> |
30 | #include <linux/hwmon-sysfs.h> | ||
30 | #include <linux/err.h> | 31 | #include <linux/err.h> |
31 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
32 | 33 | ||
@@ -158,105 +159,74 @@ static struct i2c_driver lm80_driver = { | |||
158 | #define show_in(suffix, value) \ | 159 | #define show_in(suffix, value) \ |
159 | static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ | 160 | static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ |
160 | { \ | 161 | { \ |
162 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
161 | struct lm80_data *data = lm80_update_device(dev); \ | 163 | struct lm80_data *data = lm80_update_device(dev); \ |
162 | return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \ | 164 | return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \ |
163 | } | 165 | } |
164 | show_in(min0, in_min[0]); | 166 | show_in(min, in_min) |
165 | show_in(min1, in_min[1]); | 167 | show_in(max, in_max) |
166 | show_in(min2, in_min[2]); | 168 | show_in(input, in) |
167 | show_in(min3, in_min[3]); | ||
168 | show_in(min4, in_min[4]); | ||
169 | show_in(min5, in_min[5]); | ||
170 | show_in(min6, in_min[6]); | ||
171 | show_in(max0, in_max[0]); | ||
172 | show_in(max1, in_max[1]); | ||
173 | show_in(max2, in_max[2]); | ||
174 | show_in(max3, in_max[3]); | ||
175 | show_in(max4, in_max[4]); | ||
176 | show_in(max5, in_max[5]); | ||
177 | show_in(max6, in_max[6]); | ||
178 | show_in(input0, in[0]); | ||
179 | show_in(input1, in[1]); | ||
180 | show_in(input2, in[2]); | ||
181 | show_in(input3, in[3]); | ||
182 | show_in(input4, in[4]); | ||
183 | show_in(input5, in[5]); | ||
184 | show_in(input6, in[6]); | ||
185 | 169 | ||
186 | #define set_in(suffix, value, reg) \ | 170 | #define set_in(suffix, value, reg) \ |
187 | static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ | 171 | static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ |
188 | size_t count) \ | 172 | size_t count) \ |
189 | { \ | 173 | { \ |
174 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
190 | struct i2c_client *client = to_i2c_client(dev); \ | 175 | struct i2c_client *client = to_i2c_client(dev); \ |
191 | struct lm80_data *data = i2c_get_clientdata(client); \ | 176 | struct lm80_data *data = i2c_get_clientdata(client); \ |
192 | long val = simple_strtol(buf, NULL, 10); \ | 177 | long val = simple_strtol(buf, NULL, 10); \ |
193 | \ | 178 | \ |
194 | mutex_lock(&data->update_lock);\ | 179 | mutex_lock(&data->update_lock);\ |
195 | data->value = IN_TO_REG(val); \ | 180 | data->value[nr] = IN_TO_REG(val); \ |
196 | lm80_write_value(client, reg, data->value); \ | 181 | lm80_write_value(client, reg(nr), data->value[nr]); \ |
197 | mutex_unlock(&data->update_lock);\ | 182 | mutex_unlock(&data->update_lock);\ |
198 | return count; \ | 183 | return count; \ |
199 | } | 184 | } |
200 | set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); | 185 | set_in(min, in_min, LM80_REG_IN_MIN) |
201 | set_in(min1, in_min[1], LM80_REG_IN_MIN(1)); | 186 | set_in(max, in_max, LM80_REG_IN_MAX) |
202 | set_in(min2, in_min[2], LM80_REG_IN_MIN(2)); | 187 | |
203 | set_in(min3, in_min[3], LM80_REG_IN_MIN(3)); | 188 | #define show_fan(suffix, value) \ |
204 | set_in(min4, in_min[4], LM80_REG_IN_MIN(4)); | ||
205 | set_in(min5, in_min[5], LM80_REG_IN_MIN(5)); | ||
206 | set_in(min6, in_min[6], LM80_REG_IN_MIN(6)); | ||
207 | set_in(max0, in_max[0], LM80_REG_IN_MAX(0)); | ||
208 | set_in(max1, in_max[1], LM80_REG_IN_MAX(1)); | ||
209 | set_in(max2, in_max[2], LM80_REG_IN_MAX(2)); | ||
210 | set_in(max3, in_max[3], LM80_REG_IN_MAX(3)); | ||
211 | set_in(max4, in_max[4], LM80_REG_IN_MAX(4)); | ||
212 | set_in(max5, in_max[5], LM80_REG_IN_MAX(5)); | ||
213 | set_in(max6, in_max[6], LM80_REG_IN_MAX(6)); | ||
214 | |||
215 | #define show_fan(suffix, value, div) \ | ||
216 | static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ | 189 | static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ |
217 | { \ | 190 | { \ |
191 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
218 | struct lm80_data *data = lm80_update_device(dev); \ | 192 | struct lm80_data *data = lm80_update_device(dev); \ |
219 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \ | 193 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \ |
220 | DIV_FROM_REG(data->div))); \ | 194 | DIV_FROM_REG(data->fan_div[nr]))); \ |
221 | } | 195 | } |
222 | show_fan(min1, fan_min[0], fan_div[0]); | 196 | show_fan(min, fan_min) |
223 | show_fan(min2, fan_min[1], fan_div[1]); | 197 | show_fan(input, fan) |
224 | show_fan(input1, fan[0], fan_div[0]); | ||
225 | show_fan(input2, fan[1], fan_div[1]); | ||
226 | 198 | ||
227 | #define show_fan_div(suffix, value) \ | 199 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
228 | static ssize_t show_fan_div##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ | 200 | char *buf) |
229 | { \ | 201 | { |
230 | struct lm80_data *data = lm80_update_device(dev); \ | 202 | int nr = to_sensor_dev_attr(attr)->index; |
231 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \ | 203 | struct lm80_data *data = lm80_update_device(dev); |
204 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | ||
232 | } | 205 | } |
233 | show_fan_div(1, fan_div[0]); | ||
234 | show_fan_div(2, fan_div[1]); | ||
235 | 206 | ||
236 | #define set_fan(suffix, value, reg, div) \ | 207 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
237 | static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ | 208 | const char *buf, size_t count) |
238 | size_t count) \ | 209 | { |
239 | { \ | 210 | int nr = to_sensor_dev_attr(attr)->index; |
240 | struct i2c_client *client = to_i2c_client(dev); \ | 211 | struct i2c_client *client = to_i2c_client(dev); |
241 | struct lm80_data *data = i2c_get_clientdata(client); \ | 212 | struct lm80_data *data = i2c_get_clientdata(client); |
242 | long val = simple_strtoul(buf, NULL, 10); \ | 213 | long val = simple_strtoul(buf, NULL, 10); |
243 | \ | 214 | |
244 | mutex_lock(&data->update_lock);\ | 215 | mutex_lock(&data->update_lock); |
245 | data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ | 216 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
246 | lm80_write_value(client, reg, data->value); \ | 217 | lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); |
247 | mutex_unlock(&data->update_lock);\ | 218 | mutex_unlock(&data->update_lock); |
248 | return count; \ | 219 | return count; |
249 | } | 220 | } |
250 | set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]); | ||
251 | set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]); | ||
252 | 221 | ||
253 | /* Note: we save and restore the fan minimum here, because its value is | 222 | /* Note: we save and restore the fan minimum here, because its value is |
254 | determined in part by the fan divisor. This follows the principle of | 223 | determined in part by the fan divisor. This follows the principle of |
255 | least surprise; the user doesn't expect the fan minimum to change just | 224 | least surprise; the user doesn't expect the fan minimum to change just |
256 | because the divisor changed. */ | 225 | because the divisor changed. */ |
257 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 226 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
258 | size_t count, int nr) | 227 | const char *buf, size_t count) |
259 | { | 228 | { |
229 | int nr = to_sensor_dev_attr(attr)->index; | ||
260 | struct i2c_client *client = to_i2c_client(dev); | 230 | struct i2c_client *client = to_i2c_client(dev); |
261 | struct lm80_data *data = i2c_get_clientdata(client); | 231 | struct lm80_data *data = i2c_get_clientdata(client); |
262 | unsigned long min, val = simple_strtoul(buf, NULL, 10); | 232 | unsigned long min, val = simple_strtoul(buf, NULL, 10); |
@@ -291,15 +261,6 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
291 | return count; | 261 | return count; |
292 | } | 262 | } |
293 | 263 | ||
294 | #define set_fan_div(number) \ | ||
295 | static ssize_t set_fan_div##number(struct device *dev, struct device_attribute *attr, const char *buf, \ | ||
296 | size_t count) \ | ||
297 | { \ | ||
298 | return set_fan_div(dev, buf, count, number - 1); \ | ||
299 | } | ||
300 | set_fan_div(1); | ||
301 | set_fan_div(2); | ||
302 | |||
303 | static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf) | 264 | static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf) |
304 | { | 265 | { |
305 | struct lm80_data *data = lm80_update_device(dev); | 266 | struct lm80_data *data = lm80_update_device(dev); |
@@ -343,35 +304,51 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | |||
343 | return sprintf(buf, "%u\n", data->alarms); | 304 | return sprintf(buf, "%u\n", data->alarms); |
344 | } | 305 | } |
345 | 306 | ||
346 | static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0); | 307 | static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, |
347 | static DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min1, set_in_min1); | 308 | show_in_min, set_in_min, 0); |
348 | static DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min2, set_in_min2); | 309 | static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, |
349 | static DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min3, set_in_min3); | 310 | show_in_min, set_in_min, 1); |
350 | static DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min4, set_in_min4); | 311 | static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, |
351 | static DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min5, set_in_min5); | 312 | show_in_min, set_in_min, 2); |
352 | static DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min6, set_in_min6); | 313 | static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, |
353 | static DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max0, set_in_max0); | 314 | show_in_min, set_in_min, 3); |
354 | static DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max1, set_in_max1); | 315 | static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, |
355 | static DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max2, set_in_max2); | 316 | show_in_min, set_in_min, 4); |
356 | static DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max3, set_in_max3); | 317 | static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, |
357 | static DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max4, set_in_max4); | 318 | show_in_min, set_in_min, 5); |
358 | static DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max5, set_in_max5); | 319 | static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, |
359 | static DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max6, set_in_max6); | 320 | show_in_min, set_in_min, 6); |
360 | static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); | 321 | static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, |
361 | static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); | 322 | show_in_max, set_in_max, 0); |
362 | static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); | 323 | static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, |
363 | static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL); | 324 | show_in_max, set_in_max, 1); |
364 | static DEVICE_ATTR(in4_input, S_IRUGO, show_in_input4, NULL); | 325 | static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, |
365 | static DEVICE_ATTR(in5_input, S_IRUGO, show_in_input5, NULL); | 326 | show_in_max, set_in_max, 2); |
366 | static DEVICE_ATTR(in6_input, S_IRUGO, show_in_input6, NULL); | 327 | static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, |
367 | static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min1, | 328 | show_in_max, set_in_max, 3); |
368 | set_fan_min1); | 329 | static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, |
369 | static DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min2, | 330 | show_in_max, set_in_max, 4); |
370 | set_fan_min2); | 331 | static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, |
371 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL); | 332 | show_in_max, set_in_max, 5); |
372 | static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL); | 333 | static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, |
373 | static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div1, set_fan_div1); | 334 | show_in_max, set_in_max, 6); |
374 | static DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div2, set_fan_div2); | 335 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0); |
336 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1); | ||
337 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2); | ||
338 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3); | ||
339 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4); | ||
340 | static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5); | ||
341 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6); | ||
342 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, | ||
343 | show_fan_min, set_fan_min, 0); | ||
344 | static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, | ||
345 | show_fan_min, set_fan_min, 1); | ||
346 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); | ||
347 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); | ||
348 | static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, | ||
349 | show_fan_div, set_fan_div, 0); | ||
350 | static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, | ||
351 | show_fan_div, set_fan_div, 1); | ||
375 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); | 352 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); |
376 | static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max, | 353 | static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max, |
377 | set_temp_hot_max); | 354 | set_temp_hot_max); |
@@ -395,33 +372,33 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter) | |||
395 | } | 372 | } |
396 | 373 | ||
397 | static struct attribute *lm80_attributes[] = { | 374 | static struct attribute *lm80_attributes[] = { |
398 | &dev_attr_in0_min.attr, | 375 | &sensor_dev_attr_in0_min.dev_attr.attr, |
399 | &dev_attr_in1_min.attr, | 376 | &sensor_dev_attr_in1_min.dev_attr.attr, |
400 | &dev_attr_in2_min.attr, | 377 | &sensor_dev_attr_in2_min.dev_attr.attr, |
401 | &dev_attr_in3_min.attr, | 378 | &sensor_dev_attr_in3_min.dev_attr.attr, |
402 | &dev_attr_in4_min.attr, | 379 | &sensor_dev_attr_in4_min.dev_attr.attr, |
403 | &dev_attr_in5_min.attr, | 380 | &sensor_dev_attr_in5_min.dev_attr.attr, |
404 | &dev_attr_in6_min.attr, | 381 | &sensor_dev_attr_in6_min.dev_attr.attr, |
405 | &dev_attr_in0_max.attr, | 382 | &sensor_dev_attr_in0_max.dev_attr.attr, |
406 | &dev_attr_in1_max.attr, | 383 | &sensor_dev_attr_in1_max.dev_attr.attr, |
407 | &dev_attr_in2_max.attr, | 384 | &sensor_dev_attr_in2_max.dev_attr.attr, |
408 | &dev_attr_in3_max.attr, | 385 | &sensor_dev_attr_in3_max.dev_attr.attr, |
409 | &dev_attr_in4_max.attr, | 386 | &sensor_dev_attr_in4_max.dev_attr.attr, |
410 | &dev_attr_in5_max.attr, | 387 | &sensor_dev_attr_in5_max.dev_attr.attr, |
411 | &dev_attr_in6_max.attr, | 388 | &sensor_dev_attr_in6_max.dev_attr.attr, |
412 | &dev_attr_in0_input.attr, | 389 | &sensor_dev_attr_in0_input.dev_attr.attr, |
413 | &dev_attr_in1_input.attr, | 390 | &sensor_dev_attr_in1_input.dev_attr.attr, |
414 | &dev_attr_in2_input.attr, | 391 | &sensor_dev_attr_in2_input.dev_attr.attr, |
415 | &dev_attr_in3_input.attr, | 392 | &sensor_dev_attr_in3_input.dev_attr.attr, |
416 | &dev_attr_in4_input.attr, | 393 | &sensor_dev_attr_in4_input.dev_attr.attr, |
417 | &dev_attr_in5_input.attr, | 394 | &sensor_dev_attr_in5_input.dev_attr.attr, |
418 | &dev_attr_in6_input.attr, | 395 | &sensor_dev_attr_in6_input.dev_attr.attr, |
419 | &dev_attr_fan1_min.attr, | 396 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
420 | &dev_attr_fan2_min.attr, | 397 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
421 | &dev_attr_fan1_input.attr, | 398 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
422 | &dev_attr_fan2_input.attr, | 399 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
423 | &dev_attr_fan1_div.attr, | 400 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
424 | &dev_attr_fan2_div.attr, | 401 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
425 | &dev_attr_temp1_input.attr, | 402 | &dev_attr_temp1_input.attr, |
426 | &dev_attr_temp1_max.attr, | 403 | &dev_attr_temp1_max.attr, |
427 | &dev_attr_temp1_max_hyst.attr, | 404 | &dev_attr_temp1_max_hyst.attr, |