.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * lm87.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
39 | 40 | * This driver also supports the ADM1024, a sensor chip made by Analog |
---|
40 | 41 | * Devices. That chip is fully compatible with the LM87. Complete |
---|
41 | 42 | * datasheet can be obtained from Analog's website at: |
---|
42 | | - * http://www.analog.com/en/prod/0,2877,ADM1024,00.html |
---|
43 | | - * |
---|
44 | | - * This program is free software; you can redistribute it and/or modify |
---|
45 | | - * it under the terms of the GNU General Public License as published by |
---|
46 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
47 | | - * (at your option) any later version. |
---|
48 | | - * |
---|
49 | | - * This program is distributed in the hope that it will be useful, |
---|
50 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
51 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
52 | | - * GNU General Public License for more details. |
---|
53 | | - * |
---|
54 | | - * You should have received a copy of the GNU General Public License |
---|
55 | | - * along with this program; if not, write to the Free Software |
---|
56 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 43 | + * https://www.analog.com/en/prod/0,2877,ADM1024,00.html |
---|
57 | 44 | */ |
---|
58 | 45 | |
---|
59 | 46 | #include <linux/module.h> |
---|
.. | .. |
---|
276 | 263 | * Sysfs stuff |
---|
277 | 264 | */ |
---|
278 | 265 | |
---|
279 | | -static ssize_t show_in_input(struct device *dev, struct device_attribute *attr, |
---|
280 | | - char *buf) |
---|
| 266 | +static ssize_t in_input_show(struct device *dev, |
---|
| 267 | + struct device_attribute *attr, char *buf) |
---|
281 | 268 | { |
---|
282 | 269 | struct lm87_data *data = lm87_update_device(dev); |
---|
283 | 270 | int nr = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
286 | 273 | data->in_scale[nr])); |
---|
287 | 274 | } |
---|
288 | 275 | |
---|
289 | | -static ssize_t show_in_min(struct device *dev, |
---|
290 | | - struct device_attribute *attr, char *buf) |
---|
| 276 | +static ssize_t in_min_show(struct device *dev, struct device_attribute *attr, |
---|
| 277 | + char *buf) |
---|
291 | 278 | { |
---|
292 | 279 | struct lm87_data *data = lm87_update_device(dev); |
---|
293 | 280 | int nr = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
296 | 283 | data->in_scale[nr])); |
---|
297 | 284 | } |
---|
298 | 285 | |
---|
299 | | -static ssize_t show_in_max(struct device *dev, |
---|
300 | | - struct device_attribute *attr, char *buf) |
---|
| 286 | +static ssize_t in_max_show(struct device *dev, struct device_attribute *attr, |
---|
| 287 | + char *buf) |
---|
301 | 288 | { |
---|
302 | 289 | struct lm87_data *data = lm87_update_device(dev); |
---|
303 | 290 | int nr = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
306 | 293 | data->in_scale[nr])); |
---|
307 | 294 | } |
---|
308 | 295 | |
---|
309 | | -static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
---|
310 | | - const char *buf, size_t count) |
---|
| 296 | +static ssize_t in_min_store(struct device *dev, struct device_attribute *attr, |
---|
| 297 | + const char *buf, size_t count) |
---|
311 | 298 | { |
---|
312 | 299 | struct i2c_client *client = dev_get_drvdata(dev); |
---|
313 | 300 | struct lm87_data *data = i2c_get_clientdata(client); |
---|
.. | .. |
---|
327 | 314 | return count; |
---|
328 | 315 | } |
---|
329 | 316 | |
---|
330 | | -static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
---|
331 | | - const char *buf, size_t count) |
---|
| 317 | +static ssize_t in_max_store(struct device *dev, struct device_attribute *attr, |
---|
| 318 | + const char *buf, size_t count) |
---|
332 | 319 | { |
---|
333 | 320 | struct i2c_client *client = dev_get_drvdata(dev); |
---|
334 | 321 | struct lm87_data *data = i2c_get_clientdata(client); |
---|
.. | .. |
---|
348 | 335 | return count; |
---|
349 | 336 | } |
---|
350 | 337 | |
---|
351 | | -#define set_in(offset) \ |
---|
352 | | -static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
---|
353 | | - show_in_input, NULL, offset); \ |
---|
354 | | -static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
---|
355 | | - show_in_min, set_in_min, offset); \ |
---|
356 | | -static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
---|
357 | | - show_in_max, set_in_max, offset) |
---|
358 | | -set_in(0); |
---|
359 | | -set_in(1); |
---|
360 | | -set_in(2); |
---|
361 | | -set_in(3); |
---|
362 | | -set_in(4); |
---|
363 | | -set_in(5); |
---|
364 | | -set_in(6); |
---|
365 | | -set_in(7); |
---|
| 338 | +static SENSOR_DEVICE_ATTR_RO(in0_input, in_input, 0); |
---|
| 339 | +static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); |
---|
| 340 | +static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); |
---|
| 341 | +static SENSOR_DEVICE_ATTR_RO(in1_input, in_input, 1); |
---|
| 342 | +static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
---|
| 343 | +static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
---|
| 344 | +static SENSOR_DEVICE_ATTR_RO(in2_input, in_input, 2); |
---|
| 345 | +static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
---|
| 346 | +static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
---|
| 347 | +static SENSOR_DEVICE_ATTR_RO(in3_input, in_input, 3); |
---|
| 348 | +static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
---|
| 349 | +static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
---|
| 350 | +static SENSOR_DEVICE_ATTR_RO(in4_input, in_input, 4); |
---|
| 351 | +static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
---|
| 352 | +static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
---|
| 353 | +static SENSOR_DEVICE_ATTR_RO(in5_input, in_input, 5); |
---|
| 354 | +static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5); |
---|
| 355 | +static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5); |
---|
| 356 | +static SENSOR_DEVICE_ATTR_RO(in6_input, in_input, 6); |
---|
| 357 | +static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6); |
---|
| 358 | +static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6); |
---|
| 359 | +static SENSOR_DEVICE_ATTR_RO(in7_input, in_input, 7); |
---|
| 360 | +static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7); |
---|
| 361 | +static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7); |
---|
366 | 362 | |
---|
367 | | -static ssize_t show_temp_input(struct device *dev, |
---|
| 363 | +static ssize_t temp_input_show(struct device *dev, |
---|
368 | 364 | struct device_attribute *attr, char *buf) |
---|
369 | 365 | { |
---|
370 | 366 | struct lm87_data *data = lm87_update_device(dev); |
---|
.. | .. |
---|
373 | 369 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
---|
374 | 370 | } |
---|
375 | 371 | |
---|
376 | | -static ssize_t show_temp_low(struct device *dev, |
---|
| 372 | +static ssize_t temp_low_show(struct device *dev, |
---|
377 | 373 | struct device_attribute *attr, char *buf) |
---|
378 | 374 | { |
---|
379 | 375 | struct lm87_data *data = lm87_update_device(dev); |
---|
.. | .. |
---|
383 | 379 | TEMP_FROM_REG(data->temp_low[nr])); |
---|
384 | 380 | } |
---|
385 | 381 | |
---|
386 | | -static ssize_t show_temp_high(struct device *dev, |
---|
| 382 | +static ssize_t temp_high_show(struct device *dev, |
---|
387 | 383 | struct device_attribute *attr, char *buf) |
---|
388 | 384 | { |
---|
389 | 385 | struct lm87_data *data = lm87_update_device(dev); |
---|
.. | .. |
---|
393 | 389 | TEMP_FROM_REG(data->temp_high[nr])); |
---|
394 | 390 | } |
---|
395 | 391 | |
---|
396 | | -static ssize_t set_temp_low(struct device *dev, struct device_attribute *attr, |
---|
397 | | - const char *buf, size_t count) |
---|
| 392 | +static ssize_t temp_low_store(struct device *dev, |
---|
| 393 | + struct device_attribute *attr, const char *buf, |
---|
| 394 | + size_t count) |
---|
398 | 395 | { |
---|
399 | 396 | struct i2c_client *client = dev_get_drvdata(dev); |
---|
400 | 397 | struct lm87_data *data = i2c_get_clientdata(client); |
---|
.. | .. |
---|
413 | 410 | return count; |
---|
414 | 411 | } |
---|
415 | 412 | |
---|
416 | | -static ssize_t set_temp_high(struct device *dev, struct device_attribute *attr, |
---|
417 | | - const char *buf, size_t count) |
---|
| 413 | +static ssize_t temp_high_store(struct device *dev, |
---|
| 414 | + struct device_attribute *attr, const char *buf, |
---|
| 415 | + size_t count) |
---|
418 | 416 | { |
---|
419 | 417 | struct i2c_client *client = dev_get_drvdata(dev); |
---|
420 | 418 | struct lm87_data *data = i2c_get_clientdata(client); |
---|
.. | .. |
---|
433 | 431 | return count; |
---|
434 | 432 | } |
---|
435 | 433 | |
---|
436 | | -#define set_temp(offset) \ |
---|
437 | | -static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
---|
438 | | - show_temp_input, NULL, offset - 1); \ |
---|
439 | | -static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
---|
440 | | - show_temp_high, set_temp_high, offset - 1); \ |
---|
441 | | -static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
---|
442 | | - show_temp_low, set_temp_low, offset - 1) |
---|
443 | | -set_temp(1); |
---|
444 | | -set_temp(2); |
---|
445 | | -set_temp(3); |
---|
| 434 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0); |
---|
| 435 | +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_low, 0); |
---|
| 436 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_high, 0); |
---|
| 437 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1); |
---|
| 438 | +static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_low, 1); |
---|
| 439 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_high, 1); |
---|
| 440 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp_input, 2); |
---|
| 441 | +static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_low, 2); |
---|
| 442 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_high, 2); |
---|
446 | 443 | |
---|
447 | 444 | static ssize_t temp1_crit_show(struct device *dev, |
---|
448 | 445 | struct device_attribute *attr, char *buf) |
---|
.. | .. |
---|
460 | 457 | |
---|
461 | 458 | static DEVICE_ATTR_RO(temp1_crit); |
---|
462 | 459 | static DEVICE_ATTR_RO(temp2_crit); |
---|
463 | | -static DEVICE_ATTR(temp3_crit, S_IRUGO, temp2_crit_show, NULL); |
---|
| 460 | +static DEVICE_ATTR(temp3_crit, 0444, temp2_crit_show, NULL); |
---|
464 | 461 | |
---|
465 | | -static ssize_t show_fan_input(struct device *dev, |
---|
| 462 | +static ssize_t fan_input_show(struct device *dev, |
---|
466 | 463 | struct device_attribute *attr, char *buf) |
---|
467 | 464 | { |
---|
468 | 465 | struct lm87_data *data = lm87_update_device(dev); |
---|
.. | .. |
---|
472 | 469 | FAN_DIV_FROM_REG(data->fan_div[nr]))); |
---|
473 | 470 | } |
---|
474 | 471 | |
---|
475 | | -static ssize_t show_fan_min(struct device *dev, |
---|
476 | | - struct device_attribute *attr, char *buf) |
---|
| 472 | +static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr, |
---|
| 473 | + char *buf) |
---|
477 | 474 | { |
---|
478 | 475 | struct lm87_data *data = lm87_update_device(dev); |
---|
479 | 476 | int nr = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
482 | 479 | FAN_DIV_FROM_REG(data->fan_div[nr]))); |
---|
483 | 480 | } |
---|
484 | 481 | |
---|
485 | | -static ssize_t show_fan_div(struct device *dev, |
---|
486 | | - struct device_attribute *attr, char *buf) |
---|
| 482 | +static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr, |
---|
| 483 | + char *buf) |
---|
487 | 484 | { |
---|
488 | 485 | struct lm87_data *data = lm87_update_device(dev); |
---|
489 | 486 | int nr = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
492 | 489 | FAN_DIV_FROM_REG(data->fan_div[nr])); |
---|
493 | 490 | } |
---|
494 | 491 | |
---|
495 | | -static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
---|
496 | | - const char *buf, size_t count) |
---|
| 492 | +static ssize_t fan_min_store(struct device *dev, |
---|
| 493 | + struct device_attribute *attr, const char *buf, |
---|
| 494 | + size_t count) |
---|
497 | 495 | { |
---|
498 | 496 | struct i2c_client *client = dev_get_drvdata(dev); |
---|
499 | 497 | struct lm87_data *data = i2c_get_clientdata(client); |
---|
.. | .. |
---|
519 | 517 | * of least surprise; the user doesn't expect the fan minimum to change just |
---|
520 | 518 | * because the divider changed. |
---|
521 | 519 | */ |
---|
522 | | -static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
---|
523 | | - const char *buf, size_t count) |
---|
| 520 | +static ssize_t fan_div_store(struct device *dev, |
---|
| 521 | + struct device_attribute *attr, const char *buf, |
---|
| 522 | + size_t count) |
---|
524 | 523 | { |
---|
525 | 524 | struct i2c_client *client = dev_get_drvdata(dev); |
---|
526 | 525 | struct lm87_data *data = i2c_get_clientdata(client); |
---|
.. | .. |
---|
575 | 574 | return count; |
---|
576 | 575 | } |
---|
577 | 576 | |
---|
578 | | -#define set_fan(offset) \ |
---|
579 | | -static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
---|
580 | | - show_fan_input, NULL, offset - 1); \ |
---|
581 | | -static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
---|
582 | | - show_fan_min, set_fan_min, offset - 1); \ |
---|
583 | | -static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
---|
584 | | - show_fan_div, set_fan_div, offset - 1) |
---|
585 | | -set_fan(1); |
---|
586 | | -set_fan(2); |
---|
| 577 | +static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0); |
---|
| 578 | +static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
---|
| 579 | +static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); |
---|
| 580 | +static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1); |
---|
| 581 | +static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
---|
| 582 | +static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); |
---|
587 | 583 | |
---|
588 | 584 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
---|
589 | 585 | char *buf) |
---|
.. | .. |
---|
653 | 649 | } |
---|
654 | 650 | static DEVICE_ATTR_RW(aout_output); |
---|
655 | 651 | |
---|
656 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
---|
| 652 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
---|
657 | 653 | char *buf) |
---|
658 | 654 | { |
---|
659 | 655 | struct lm87_data *data = lm87_update_device(dev); |
---|
660 | 656 | int bitnr = to_sensor_dev_attr(attr)->index; |
---|
661 | 657 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
---|
662 | 658 | } |
---|
663 | | -static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
---|
664 | | -static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
---|
665 | | -static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
---|
666 | | -static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
---|
667 | | -static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); |
---|
668 | | -static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9); |
---|
669 | | -static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6); |
---|
670 | | -static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7); |
---|
671 | | -static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
---|
672 | | -static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
---|
673 | | -static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 5); |
---|
674 | | -static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); |
---|
675 | | -static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); |
---|
676 | | -static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 14); |
---|
677 | | -static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15); |
---|
| 659 | +static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
---|
| 660 | +static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
---|
| 661 | +static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
---|
| 662 | +static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
---|
| 663 | +static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8); |
---|
| 664 | +static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 9); |
---|
| 665 | +static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 6); |
---|
| 666 | +static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 7); |
---|
| 667 | +static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4); |
---|
| 668 | +static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5); |
---|
| 669 | +static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 5); |
---|
| 670 | +static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6); |
---|
| 671 | +static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7); |
---|
| 672 | +static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 14); |
---|
| 673 | +static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15); |
---|
678 | 674 | |
---|
679 | 675 | /* |
---|
680 | 676 | * Real code |
---|
.. | .. |
---|
916 | 912 | return 0; |
---|
917 | 913 | } |
---|
918 | 914 | |
---|
919 | | -static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id) |
---|
| 915 | +static int lm87_probe(struct i2c_client *client) |
---|
920 | 916 | { |
---|
921 | 917 | struct lm87_data *data; |
---|
922 | 918 | struct device *hwmon_dev; |
---|
.. | .. |
---|
998 | 994 | .name = "lm87", |
---|
999 | 995 | .of_match_table = lm87_of_match, |
---|
1000 | 996 | }, |
---|
1001 | | - .probe = lm87_probe, |
---|
| 997 | + .probe_new = lm87_probe, |
---|
1002 | 998 | .id_table = lm87_id, |
---|
1003 | 999 | .detect = lm87_detect, |
---|
1004 | 1000 | .address_list = normal_i2c, |
---|