diff options
Diffstat (limited to 'drivers/i2c/chips/it87.c')
-rw-r--r-- | drivers/i2c/chips/it87.c | 396 |
1 files changed, 186 insertions, 210 deletions
diff --git a/drivers/i2c/chips/it87.c b/drivers/i2c/chips/it87.c index 007bdf9e7e2a..db20c9e47393 100644 --- a/drivers/i2c/chips/it87.c +++ b/drivers/i2c/chips/it87.c | |||
@@ -31,7 +31,6 @@ | |||
31 | type at module load time. | 31 | type at module load time. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <linux/config.h> | ||
35 | #include <linux/module.h> | 34 | #include <linux/module.h> |
36 | #include <linux/init.h> | 35 | #include <linux/init.h> |
37 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
@@ -39,6 +38,7 @@ | |||
39 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
40 | #include <linux/i2c-sensor.h> | 39 | #include <linux/i2c-sensor.h> |
41 | #include <linux/i2c-vid.h> | 40 | #include <linux/i2c-vid.h> |
41 | #include <linux/hwmon-sysfs.h> | ||
42 | #include <asm/io.h> | 42 | #include <asm/io.h> |
43 | 43 | ||
44 | 44 | ||
@@ -173,8 +173,6 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
173 | ((val)+500)/1000),-128,127)) | 173 | ((val)+500)/1000),-128,127)) |
174 | #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000) | 174 | #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000) |
175 | 175 | ||
176 | #define ALARMS_FROM_REG(val) (val) | ||
177 | |||
178 | #define PWM_TO_REG(val) ((val) >> 1) | 176 | #define PWM_TO_REG(val) ((val) >> 1) |
179 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) | 177 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) |
180 | 178 | ||
@@ -241,27 +239,42 @@ static struct i2c_driver it87_driver = { | |||
241 | .detach_client = it87_detach_client, | 239 | .detach_client = it87_detach_client, |
242 | }; | 240 | }; |
243 | 241 | ||
244 | static ssize_t show_in(struct device *dev, char *buf, int nr) | 242 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
243 | char *buf) | ||
245 | { | 244 | { |
245 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
246 | int nr = sensor_attr->index; | ||
247 | |||
246 | struct it87_data *data = it87_update_device(dev); | 248 | struct it87_data *data = it87_update_device(dev); |
247 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 249 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
248 | } | 250 | } |
249 | 251 | ||
250 | static ssize_t show_in_min(struct device *dev, char *buf, int nr) | 252 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
253 | char *buf) | ||
251 | { | 254 | { |
255 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
256 | int nr = sensor_attr->index; | ||
257 | |||
252 | struct it87_data *data = it87_update_device(dev); | 258 | struct it87_data *data = it87_update_device(dev); |
253 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 259 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
254 | } | 260 | } |
255 | 261 | ||
256 | static ssize_t show_in_max(struct device *dev, char *buf, int nr) | 262 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
263 | char *buf) | ||
257 | { | 264 | { |
265 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
266 | int nr = sensor_attr->index; | ||
267 | |||
258 | struct it87_data *data = it87_update_device(dev); | 268 | struct it87_data *data = it87_update_device(dev); |
259 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 269 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
260 | } | 270 | } |
261 | 271 | ||
262 | static ssize_t set_in_min(struct device *dev, const char *buf, | 272 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
263 | size_t count, int nr) | 273 | const char *buf, size_t count) |
264 | { | 274 | { |
275 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
276 | int nr = sensor_attr->index; | ||
277 | |||
265 | struct i2c_client *client = to_i2c_client(dev); | 278 | struct i2c_client *client = to_i2c_client(dev); |
266 | struct it87_data *data = i2c_get_clientdata(client); | 279 | struct it87_data *data = i2c_get_clientdata(client); |
267 | unsigned long val = simple_strtoul(buf, NULL, 10); | 280 | unsigned long val = simple_strtoul(buf, NULL, 10); |
@@ -273,9 +286,12 @@ static ssize_t set_in_min(struct device *dev, const char *buf, | |||
273 | up(&data->update_lock); | 286 | up(&data->update_lock); |
274 | return count; | 287 | return count; |
275 | } | 288 | } |
276 | static ssize_t set_in_max(struct device *dev, const char *buf, | 289 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
277 | size_t count, int nr) | 290 | const char *buf, size_t count) |
278 | { | 291 | { |
292 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
293 | int nr = sensor_attr->index; | ||
294 | |||
279 | struct i2c_client *client = to_i2c_client(dev); | 295 | struct i2c_client *client = to_i2c_client(dev); |
280 | struct it87_data *data = i2c_get_clientdata(client); | 296 | struct it87_data *data = i2c_get_clientdata(client); |
281 | unsigned long val = simple_strtoul(buf, NULL, 10); | 297 | unsigned long val = simple_strtoul(buf, NULL, 10); |
@@ -289,38 +305,14 @@ static ssize_t set_in_max(struct device *dev, const char *buf, | |||
289 | } | 305 | } |
290 | 306 | ||
291 | #define show_in_offset(offset) \ | 307 | #define show_in_offset(offset) \ |
292 | static ssize_t \ | 308 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
293 | show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 309 | show_in, NULL, offset); |
294 | { \ | ||
295 | return show_in(dev, buf, offset); \ | ||
296 | } \ | ||
297 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); | ||
298 | 310 | ||
299 | #define limit_in_offset(offset) \ | 311 | #define limit_in_offset(offset) \ |
300 | static ssize_t \ | 312 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
301 | show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | 313 | show_in_min, set_in_min, offset); \ |
302 | { \ | 314 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
303 | return show_in_min(dev, buf, offset); \ | 315 | show_in_max, set_in_max, offset); |
304 | } \ | ||
305 | static ssize_t \ | ||
306 | show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
307 | { \ | ||
308 | return show_in_max(dev, buf, offset); \ | ||
309 | } \ | ||
310 | static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
311 | const char *buf, size_t count) \ | ||
312 | { \ | ||
313 | return set_in_min(dev, buf, count, offset); \ | ||
314 | } \ | ||
315 | static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
316 | const char *buf, size_t count) \ | ||
317 | { \ | ||
318 | return set_in_max(dev, buf, count, offset); \ | ||
319 | } \ | ||
320 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
321 | show_in##offset##_min, set_in##offset##_min); \ | ||
322 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
323 | show_in##offset##_max, set_in##offset##_max); | ||
324 | 316 | ||
325 | show_in_offset(0); | 317 | show_in_offset(0); |
326 | limit_in_offset(0); | 318 | limit_in_offset(0); |
@@ -341,24 +333,39 @@ limit_in_offset(7); | |||
341 | show_in_offset(8); | 333 | show_in_offset(8); |
342 | 334 | ||
343 | /* 3 temperatures */ | 335 | /* 3 temperatures */ |
344 | static ssize_t show_temp(struct device *dev, char *buf, int nr) | 336 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
337 | char *buf) | ||
345 | { | 338 | { |
339 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
340 | int nr = sensor_attr->index; | ||
341 | |||
346 | struct it87_data *data = it87_update_device(dev); | 342 | struct it87_data *data = it87_update_device(dev); |
347 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); | 343 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
348 | } | 344 | } |
349 | static ssize_t show_temp_max(struct device *dev, char *buf, int nr) | 345 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
346 | char *buf) | ||
350 | { | 347 | { |
348 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
349 | int nr = sensor_attr->index; | ||
350 | |||
351 | struct it87_data *data = it87_update_device(dev); | 351 | struct it87_data *data = it87_update_device(dev); |
352 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); | 352 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); |
353 | } | 353 | } |
354 | static ssize_t show_temp_min(struct device *dev, char *buf, int nr) | 354 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
355 | char *buf) | ||
355 | { | 356 | { |
357 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
358 | int nr = sensor_attr->index; | ||
359 | |||
356 | struct it87_data *data = it87_update_device(dev); | 360 | struct it87_data *data = it87_update_device(dev); |
357 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); | 361 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); |
358 | } | 362 | } |
359 | static ssize_t set_temp_max(struct device *dev, const char *buf, | 363 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
360 | size_t count, int nr) | 364 | const char *buf, size_t count) |
361 | { | 365 | { |
366 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
367 | int nr = sensor_attr->index; | ||
368 | |||
362 | struct i2c_client *client = to_i2c_client(dev); | 369 | struct i2c_client *client = to_i2c_client(dev); |
363 | struct it87_data *data = i2c_get_clientdata(client); | 370 | struct it87_data *data = i2c_get_clientdata(client); |
364 | int val = simple_strtol(buf, NULL, 10); | 371 | int val = simple_strtol(buf, NULL, 10); |
@@ -369,9 +376,12 @@ static ssize_t set_temp_max(struct device *dev, const char *buf, | |||
369 | up(&data->update_lock); | 376 | up(&data->update_lock); |
370 | return count; | 377 | return count; |
371 | } | 378 | } |
372 | static ssize_t set_temp_min(struct device *dev, const char *buf, | 379 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
373 | size_t count, int nr) | 380 | const char *buf, size_t count) |
374 | { | 381 | { |
382 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
383 | int nr = sensor_attr->index; | ||
384 | |||
375 | struct i2c_client *client = to_i2c_client(dev); | 385 | struct i2c_client *client = to_i2c_client(dev); |
376 | struct it87_data *data = i2c_get_clientdata(client); | 386 | struct it87_data *data = i2c_get_clientdata(client); |
377 | int val = simple_strtol(buf, NULL, 10); | 387 | int val = simple_strtol(buf, NULL, 10); |
@@ -383,42 +393,23 @@ static ssize_t set_temp_min(struct device *dev, const char *buf, | |||
383 | return count; | 393 | return count; |
384 | } | 394 | } |
385 | #define show_temp_offset(offset) \ | 395 | #define show_temp_offset(offset) \ |
386 | static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 396 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
387 | { \ | 397 | show_temp, NULL, offset - 1); \ |
388 | return show_temp(dev, buf, offset - 1); \ | 398 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
389 | } \ | 399 | show_temp_max, set_temp_max, offset - 1); \ |
390 | static ssize_t \ | 400 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
391 | show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | 401 | show_temp_min, set_temp_min, offset - 1); |
392 | { \ | ||
393 | return show_temp_max(dev, buf, offset - 1); \ | ||
394 | } \ | ||
395 | static ssize_t \ | ||
396 | show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
397 | { \ | ||
398 | return show_temp_min(dev, buf, offset - 1); \ | ||
399 | } \ | ||
400 | static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
401 | const char *buf, size_t count) \ | ||
402 | { \ | ||
403 | return set_temp_max(dev, buf, count, offset - 1); \ | ||
404 | } \ | ||
405 | static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
406 | const char *buf, size_t count) \ | ||
407 | { \ | ||
408 | return set_temp_min(dev, buf, count, offset - 1); \ | ||
409 | } \ | ||
410 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \ | ||
411 | static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | ||
412 | show_temp_##offset##_max, set_temp_##offset##_max); \ | ||
413 | static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ | ||
414 | show_temp_##offset##_min, set_temp_##offset##_min); | ||
415 | 402 | ||
416 | show_temp_offset(1); | 403 | show_temp_offset(1); |
417 | show_temp_offset(2); | 404 | show_temp_offset(2); |
418 | show_temp_offset(3); | 405 | show_temp_offset(3); |
419 | 406 | ||
420 | static ssize_t show_sensor(struct device *dev, char *buf, int nr) | 407 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
408 | char *buf) | ||
421 | { | 409 | { |
410 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
411 | int nr = sensor_attr->index; | ||
412 | |||
422 | struct it87_data *data = it87_update_device(dev); | 413 | struct it87_data *data = it87_update_device(dev); |
423 | u8 reg = data->sensor; /* In case the value is updated while we use it */ | 414 | u8 reg = data->sensor; /* In case the value is updated while we use it */ |
424 | 415 | ||
@@ -428,9 +419,12 @@ static ssize_t show_sensor(struct device *dev, char *buf, int nr) | |||
428 | return sprintf(buf, "2\n"); /* thermistor */ | 419 | return sprintf(buf, "2\n"); /* thermistor */ |
429 | return sprintf(buf, "0\n"); /* disabled */ | 420 | return sprintf(buf, "0\n"); /* disabled */ |
430 | } | 421 | } |
431 | static ssize_t set_sensor(struct device *dev, const char *buf, | 422 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, |
432 | size_t count, int nr) | 423 | const char *buf, size_t count) |
433 | { | 424 | { |
425 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
426 | int nr = sensor_attr->index; | ||
427 | |||
434 | struct i2c_client *client = to_i2c_client(dev); | 428 | struct i2c_client *client = to_i2c_client(dev); |
435 | struct it87_data *data = i2c_get_clientdata(client); | 429 | struct it87_data *data = i2c_get_clientdata(client); |
436 | int val = simple_strtol(buf, NULL, 10); | 430 | int val = simple_strtol(buf, NULL, 10); |
@@ -453,53 +447,67 @@ static ssize_t set_sensor(struct device *dev, const char *buf, | |||
453 | return count; | 447 | return count; |
454 | } | 448 | } |
455 | #define show_sensor_offset(offset) \ | 449 | #define show_sensor_offset(offset) \ |
456 | static ssize_t show_sensor_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 450 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
457 | { \ | 451 | show_sensor, set_sensor, offset - 1); |
458 | return show_sensor(dev, buf, offset - 1); \ | ||
459 | } \ | ||
460 | static ssize_t set_sensor_##offset (struct device *dev, struct device_attribute *attr, \ | ||
461 | const char *buf, size_t count) \ | ||
462 | { \ | ||
463 | return set_sensor(dev, buf, count, offset - 1); \ | ||
464 | } \ | ||
465 | static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ | ||
466 | show_sensor_##offset, set_sensor_##offset); | ||
467 | 452 | ||
468 | show_sensor_offset(1); | 453 | show_sensor_offset(1); |
469 | show_sensor_offset(2); | 454 | show_sensor_offset(2); |
470 | show_sensor_offset(3); | 455 | show_sensor_offset(3); |
471 | 456 | ||
472 | /* 3 Fans */ | 457 | /* 3 Fans */ |
473 | static ssize_t show_fan(struct device *dev, char *buf, int nr) | 458 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
459 | char *buf) | ||
474 | { | 460 | { |
461 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
462 | int nr = sensor_attr->index; | ||
463 | |||
475 | struct it87_data *data = it87_update_device(dev); | 464 | struct it87_data *data = it87_update_device(dev); |
476 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], | 465 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], |
477 | DIV_FROM_REG(data->fan_div[nr]))); | 466 | DIV_FROM_REG(data->fan_div[nr]))); |
478 | } | 467 | } |
479 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) | 468 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
469 | char *buf) | ||
480 | { | 470 | { |
471 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
472 | int nr = sensor_attr->index; | ||
473 | |||
481 | struct it87_data *data = it87_update_device(dev); | 474 | struct it87_data *data = it87_update_device(dev); |
482 | return sprintf(buf,"%d\n", | 475 | return sprintf(buf,"%d\n", |
483 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); | 476 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); |
484 | } | 477 | } |
485 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | 478 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
479 | char *buf) | ||
486 | { | 480 | { |
481 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
482 | int nr = sensor_attr->index; | ||
483 | |||
487 | struct it87_data *data = it87_update_device(dev); | 484 | struct it87_data *data = it87_update_device(dev); |
488 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | 485 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
489 | } | 486 | } |
490 | static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr) | 487 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, |
488 | char *buf) | ||
491 | { | 489 | { |
490 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
491 | int nr = sensor_attr->index; | ||
492 | |||
492 | struct it87_data *data = it87_update_device(dev); | 493 | struct it87_data *data = it87_update_device(dev); |
493 | return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); | 494 | return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); |
494 | } | 495 | } |
495 | static ssize_t show_pwm(struct device *dev, char *buf, int nr) | 496 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
497 | char *buf) | ||
496 | { | 498 | { |
499 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
500 | int nr = sensor_attr->index; | ||
501 | |||
497 | struct it87_data *data = it87_update_device(dev); | 502 | struct it87_data *data = it87_update_device(dev); |
498 | return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); | 503 | return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); |
499 | } | 504 | } |
500 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 505 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
501 | size_t count, int nr) | 506 | const char *buf, size_t count) |
502 | { | 507 | { |
508 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
509 | int nr = sensor_attr->index; | ||
510 | |||
503 | struct i2c_client *client = to_i2c_client(dev); | 511 | struct i2c_client *client = to_i2c_client(dev); |
504 | struct it87_data *data = i2c_get_clientdata(client); | 512 | struct it87_data *data = i2c_get_clientdata(client); |
505 | int val = simple_strtol(buf, NULL, 10); | 513 | int val = simple_strtol(buf, NULL, 10); |
@@ -510,9 +518,12 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, | |||
510 | up(&data->update_lock); | 518 | up(&data->update_lock); |
511 | return count; | 519 | return count; |
512 | } | 520 | } |
513 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 521 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
514 | size_t count, int nr) | 522 | const char *buf, size_t count) |
515 | { | 523 | { |
524 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
525 | int nr = sensor_attr->index; | ||
526 | |||
516 | struct i2c_client *client = to_i2c_client(dev); | 527 | struct i2c_client *client = to_i2c_client(dev); |
517 | struct it87_data *data = i2c_get_clientdata(client); | 528 | struct it87_data *data = i2c_get_clientdata(client); |
518 | int val = simple_strtol(buf, NULL, 10); | 529 | int val = simple_strtol(buf, NULL, 10); |
@@ -550,9 +561,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
550 | up(&data->update_lock); | 561 | up(&data->update_lock); |
551 | return count; | 562 | return count; |
552 | } | 563 | } |
553 | static ssize_t set_pwm_enable(struct device *dev, const char *buf, | 564 | static ssize_t set_pwm_enable(struct device *dev, |
554 | size_t count, int nr) | 565 | struct device_attribute *attr, const char *buf, size_t count) |
555 | { | 566 | { |
567 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
568 | int nr = sensor_attr->index; | ||
569 | |||
556 | struct i2c_client *client = to_i2c_client(dev); | 570 | struct i2c_client *client = to_i2c_client(dev); |
557 | struct it87_data *data = i2c_get_clientdata(client); | 571 | struct it87_data *data = i2c_get_clientdata(client); |
558 | int val = simple_strtol(buf, NULL, 10); | 572 | int val = simple_strtol(buf, NULL, 10); |
@@ -581,9 +595,12 @@ static ssize_t set_pwm_enable(struct device *dev, const char *buf, | |||
581 | up(&data->update_lock); | 595 | up(&data->update_lock); |
582 | return count; | 596 | return count; |
583 | } | 597 | } |
584 | static ssize_t set_pwm(struct device *dev, const char *buf, | 598 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
585 | size_t count, int nr) | 599 | const char *buf, size_t count) |
586 | { | 600 | { |
601 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
602 | int nr = sensor_attr->index; | ||
603 | |||
587 | struct i2c_client *client = to_i2c_client(dev); | 604 | struct i2c_client *client = to_i2c_client(dev); |
588 | struct it87_data *data = i2c_get_clientdata(client); | 605 | struct it87_data *data = i2c_get_clientdata(client); |
589 | int val = simple_strtol(buf, NULL, 10); | 606 | int val = simple_strtol(buf, NULL, 10); |
@@ -599,64 +616,23 @@ static ssize_t set_pwm(struct device *dev, const char *buf, | |||
599 | return count; | 616 | return count; |
600 | } | 617 | } |
601 | 618 | ||
602 | #define show_fan_offset(offset) \ | 619 | #define show_fan_offset(offset) \ |
603 | static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 620 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
604 | { \ | 621 | show_fan, NULL, offset - 1); \ |
605 | return show_fan(dev, buf, offset - 1); \ | 622 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
606 | } \ | 623 | show_fan_min, set_fan_min, offset - 1); \ |
607 | static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | 624 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
608 | { \ | 625 | show_fan_div, set_fan_div, offset - 1); |
609 | return show_fan_min(dev, buf, offset - 1); \ | ||
610 | } \ | ||
611 | static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
612 | { \ | ||
613 | return show_fan_div(dev, buf, offset - 1); \ | ||
614 | } \ | ||
615 | static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
616 | const char *buf, size_t count) \ | ||
617 | { \ | ||
618 | return set_fan_min(dev, buf, count, offset - 1); \ | ||
619 | } \ | ||
620 | static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr, \ | ||
621 | const char *buf, size_t count) \ | ||
622 | { \ | ||
623 | return set_fan_div(dev, buf, count, offset - 1); \ | ||
624 | } \ | ||
625 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \ | ||
626 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
627 | show_fan_##offset##_min, set_fan_##offset##_min); \ | ||
628 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | ||
629 | show_fan_##offset##_div, set_fan_##offset##_div); | ||
630 | 626 | ||
631 | show_fan_offset(1); | 627 | show_fan_offset(1); |
632 | show_fan_offset(2); | 628 | show_fan_offset(2); |
633 | show_fan_offset(3); | 629 | show_fan_offset(3); |
634 | 630 | ||
635 | #define show_pwm_offset(offset) \ | 631 | #define show_pwm_offset(offset) \ |
636 | static ssize_t show_pwm##offset##_enable (struct device *dev, struct device_attribute *attr, \ | 632 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
637 | char *buf) \ | 633 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
638 | { \ | 634 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
639 | return show_pwm_enable(dev, buf, offset - 1); \ | 635 | show_pwm, set_pwm, offset - 1); |
640 | } \ | ||
641 | static ssize_t show_pwm##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
642 | { \ | ||
643 | return show_pwm(dev, buf, offset - 1); \ | ||
644 | } \ | ||
645 | static ssize_t set_pwm##offset##_enable (struct device *dev, struct device_attribute *attr, \ | ||
646 | const char *buf, size_t count) \ | ||
647 | { \ | ||
648 | return set_pwm_enable(dev, buf, count, offset - 1); \ | ||
649 | } \ | ||
650 | static ssize_t set_pwm##offset (struct device *dev, struct device_attribute *attr, \ | ||
651 | const char *buf, size_t count) \ | ||
652 | { \ | ||
653 | return set_pwm(dev, buf, count, offset - 1); \ | ||
654 | } \ | ||
655 | static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ | ||
656 | show_pwm##offset##_enable, \ | ||
657 | set_pwm##offset##_enable); \ | ||
658 | static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | ||
659 | show_pwm##offset , set_pwm##offset ); | ||
660 | 636 | ||
661 | show_pwm_offset(1); | 637 | show_pwm_offset(1); |
662 | show_pwm_offset(2); | 638 | show_pwm_offset(2); |
@@ -666,7 +642,7 @@ show_pwm_offset(3); | |||
666 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 642 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
667 | { | 643 | { |
668 | struct it87_data *data = it87_update_device(dev); | 644 | struct it87_data *data = it87_update_device(dev); |
669 | return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms)); | 645 | return sprintf(buf, "%u\n", data->alarms); |
670 | } | 646 | } |
671 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 647 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
672 | 648 | ||
@@ -864,60 +840,60 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
864 | it87_init_client(new_client, data); | 840 | it87_init_client(new_client, data); |
865 | 841 | ||
866 | /* Register sysfs hooks */ | 842 | /* Register sysfs hooks */ |
867 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 843 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); |
868 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 844 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); |
869 | device_create_file(&new_client->dev, &dev_attr_in2_input); | 845 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); |
870 | device_create_file(&new_client->dev, &dev_attr_in3_input); | 846 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr); |
871 | device_create_file(&new_client->dev, &dev_attr_in4_input); | 847 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr); |
872 | device_create_file(&new_client->dev, &dev_attr_in5_input); | 848 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr); |
873 | device_create_file(&new_client->dev, &dev_attr_in6_input); | 849 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr); |
874 | device_create_file(&new_client->dev, &dev_attr_in7_input); | 850 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr); |
875 | device_create_file(&new_client->dev, &dev_attr_in8_input); | 851 | device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr); |
876 | device_create_file(&new_client->dev, &dev_attr_in0_min); | 852 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); |
877 | device_create_file(&new_client->dev, &dev_attr_in1_min); | 853 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr); |
878 | device_create_file(&new_client->dev, &dev_attr_in2_min); | 854 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr); |
879 | device_create_file(&new_client->dev, &dev_attr_in3_min); | 855 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr); |
880 | device_create_file(&new_client->dev, &dev_attr_in4_min); | 856 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr); |
881 | device_create_file(&new_client->dev, &dev_attr_in5_min); | 857 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr); |
882 | device_create_file(&new_client->dev, &dev_attr_in6_min); | 858 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr); |
883 | device_create_file(&new_client->dev, &dev_attr_in7_min); | 859 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr); |
884 | device_create_file(&new_client->dev, &dev_attr_in0_max); | 860 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); |
885 | device_create_file(&new_client->dev, &dev_attr_in1_max); | 861 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr); |
886 | device_create_file(&new_client->dev, &dev_attr_in2_max); | 862 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr); |
887 | device_create_file(&new_client->dev, &dev_attr_in3_max); | 863 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr); |
888 | device_create_file(&new_client->dev, &dev_attr_in4_max); | 864 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr); |
889 | device_create_file(&new_client->dev, &dev_attr_in5_max); | 865 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr); |
890 | device_create_file(&new_client->dev, &dev_attr_in6_max); | 866 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr); |
891 | device_create_file(&new_client->dev, &dev_attr_in7_max); | 867 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr); |
892 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 868 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); |
893 | device_create_file(&new_client->dev, &dev_attr_temp2_input); | 869 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr); |
894 | device_create_file(&new_client->dev, &dev_attr_temp3_input); | 870 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr); |
895 | device_create_file(&new_client->dev, &dev_attr_temp1_max); | 871 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr); |
896 | device_create_file(&new_client->dev, &dev_attr_temp2_max); | 872 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr); |
897 | device_create_file(&new_client->dev, &dev_attr_temp3_max); | 873 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr); |
898 | device_create_file(&new_client->dev, &dev_attr_temp1_min); | 874 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr); |
899 | device_create_file(&new_client->dev, &dev_attr_temp2_min); | 875 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr); |
900 | device_create_file(&new_client->dev, &dev_attr_temp3_min); | 876 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr); |
901 | device_create_file(&new_client->dev, &dev_attr_temp1_type); | 877 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr); |
902 | device_create_file(&new_client->dev, &dev_attr_temp2_type); | 878 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr); |
903 | device_create_file(&new_client->dev, &dev_attr_temp3_type); | 879 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr); |
904 | device_create_file(&new_client->dev, &dev_attr_fan1_input); | 880 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr); |
905 | device_create_file(&new_client->dev, &dev_attr_fan2_input); | 881 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr); |
906 | device_create_file(&new_client->dev, &dev_attr_fan3_input); | 882 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr); |
907 | device_create_file(&new_client->dev, &dev_attr_fan1_min); | 883 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr); |
908 | device_create_file(&new_client->dev, &dev_attr_fan2_min); | 884 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr); |
909 | device_create_file(&new_client->dev, &dev_attr_fan3_min); | 885 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr); |
910 | device_create_file(&new_client->dev, &dev_attr_fan1_div); | 886 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr); |
911 | device_create_file(&new_client->dev, &dev_attr_fan2_div); | 887 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr); |
912 | device_create_file(&new_client->dev, &dev_attr_fan3_div); | 888 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr); |
913 | device_create_file(&new_client->dev, &dev_attr_alarms); | 889 | device_create_file(&new_client->dev, &dev_attr_alarms); |
914 | if (enable_pwm_interface) { | 890 | if (enable_pwm_interface) { |
915 | device_create_file(&new_client->dev, &dev_attr_pwm1_enable); | 891 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); |
916 | device_create_file(&new_client->dev, &dev_attr_pwm2_enable); | 892 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); |
917 | device_create_file(&new_client->dev, &dev_attr_pwm3_enable); | 893 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); |
918 | device_create_file(&new_client->dev, &dev_attr_pwm1); | 894 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); |
919 | device_create_file(&new_client->dev, &dev_attr_pwm2); | 895 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); |
920 | device_create_file(&new_client->dev, &dev_attr_pwm3); | 896 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); |
921 | } | 897 | } |
922 | 898 | ||
923 | if (data->type == it8712) { | 899 | if (data->type == it8712) { |
@@ -954,7 +930,7 @@ static int it87_detach_client(struct i2c_client *client) | |||
954 | return 0; | 930 | return 0; |
955 | } | 931 | } |
956 | 932 | ||
957 | /* The SMBus locks itself, but ISA access must be locked explicitely! | 933 | /* The SMBus locks itself, but ISA access must be locked explicitly! |
958 | We don't want to lock the whole ISA bus, so we lock each client | 934 | We don't want to lock the whole ISA bus, so we lock each client |
959 | separately. | 935 | separately. |
960 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 936 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
@@ -974,7 +950,7 @@ static int it87_read_value(struct i2c_client *client, u8 reg) | |||
974 | return i2c_smbus_read_byte_data(client, reg); | 950 | return i2c_smbus_read_byte_data(client, reg); |
975 | } | 951 | } |
976 | 952 | ||
977 | /* The SMBus locks itself, but ISA access muse be locked explicitely! | 953 | /* The SMBus locks itself, but ISA access muse be locked explicitly! |
978 | We don't want to lock the whole ISA bus, so we lock each client | 954 | We don't want to lock the whole ISA bus, so we lock each client |
979 | separately. | 955 | separately. |
980 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 956 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |