.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* tmp401.c |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright (C) 2007,2008 Hans de Goede <hdegoede@redhat.com> |
---|
.. | .. |
---|
7 | 8 | * |
---|
8 | 9 | * Cleanup and support for TMP431 and TMP432 by Guenter Roeck |
---|
9 | 10 | * Copyright (c) 2013 Guenter Roeck <linux@roeck-us.net> |
---|
10 | | - * |
---|
11 | | - * This program is free software; you can redistribute it and/or modify |
---|
12 | | - * it under the terms of the GNU General Public License as published by |
---|
13 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
14 | | - * (at your option) any later version. |
---|
15 | | - * |
---|
16 | | - * This program is distributed in the hope that it will be useful, |
---|
17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | | - * GNU General Public License for more details. |
---|
20 | | - * |
---|
21 | | - * You should have received a copy of the GNU General Public License |
---|
22 | | - * along with this program; if not, write to the Free Software |
---|
23 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
24 | 11 | */ |
---|
25 | 12 | |
---|
26 | 13 | /* |
---|
.. | .. |
---|
288 | 275 | return ret; |
---|
289 | 276 | } |
---|
290 | 277 | |
---|
291 | | -static ssize_t show_temp(struct device *dev, |
---|
292 | | - struct device_attribute *devattr, char *buf) |
---|
| 278 | +static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, |
---|
| 279 | + char *buf) |
---|
293 | 280 | { |
---|
294 | 281 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
---|
295 | 282 | int index = to_sensor_dev_attr_2(devattr)->index; |
---|
.. | .. |
---|
302 | 289 | tmp401_register_to_temp(data->temp[nr][index], data->config)); |
---|
303 | 290 | } |
---|
304 | 291 | |
---|
305 | | -static ssize_t show_temp_crit_hyst(struct device *dev, |
---|
306 | | - struct device_attribute *devattr, char *buf) |
---|
| 292 | +static ssize_t temp_crit_hyst_show(struct device *dev, |
---|
| 293 | + struct device_attribute *devattr, |
---|
| 294 | + char *buf) |
---|
307 | 295 | { |
---|
308 | 296 | int temp, index = to_sensor_dev_attr(devattr)->index; |
---|
309 | 297 | struct tmp401_data *data = tmp401_update_device(dev); |
---|
.. | .. |
---|
319 | 307 | return sprintf(buf, "%d\n", temp); |
---|
320 | 308 | } |
---|
321 | 309 | |
---|
322 | | -static ssize_t show_status(struct device *dev, |
---|
323 | | - struct device_attribute *devattr, char *buf) |
---|
| 310 | +static ssize_t status_show(struct device *dev, |
---|
| 311 | + struct device_attribute *devattr, char *buf) |
---|
324 | 312 | { |
---|
325 | 313 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
---|
326 | 314 | int mask = to_sensor_dev_attr_2(devattr)->index; |
---|
.. | .. |
---|
332 | 320 | return sprintf(buf, "%d\n", !!(data->status[nr] & mask)); |
---|
333 | 321 | } |
---|
334 | 322 | |
---|
335 | | -static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, |
---|
336 | | - const char *buf, size_t count) |
---|
| 323 | +static ssize_t temp_store(struct device *dev, |
---|
| 324 | + struct device_attribute *devattr, const char *buf, |
---|
| 325 | + size_t count) |
---|
337 | 326 | { |
---|
338 | 327 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
---|
339 | 328 | int index = to_sensor_dev_attr_2(devattr)->index; |
---|
.. | .. |
---|
365 | 354 | return count; |
---|
366 | 355 | } |
---|
367 | 356 | |
---|
368 | | -static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute |
---|
369 | | - *devattr, const char *buf, size_t count) |
---|
| 357 | +static ssize_t temp_crit_hyst_store(struct device *dev, |
---|
| 358 | + struct device_attribute *devattr, |
---|
| 359 | + const char *buf, size_t count) |
---|
370 | 360 | { |
---|
371 | 361 | int temp, index = to_sensor_dev_attr(devattr)->index; |
---|
372 | 362 | struct tmp401_data *data = tmp401_update_device(dev); |
---|
.. | .. |
---|
404 | 394 | * This is done by writing any value to any of the minimum/maximum registers |
---|
405 | 395 | * (0x30-0x37). |
---|
406 | 396 | */ |
---|
407 | | -static ssize_t reset_temp_history(struct device *dev, |
---|
408 | | - struct device_attribute *devattr, const char *buf, size_t count) |
---|
| 397 | +static ssize_t reset_temp_history_store(struct device *dev, |
---|
| 398 | + struct device_attribute *devattr, |
---|
| 399 | + const char *buf, size_t count) |
---|
409 | 400 | { |
---|
410 | 401 | struct tmp401_data *data = dev_get_drvdata(dev); |
---|
411 | 402 | struct i2c_client *client = data->client; |
---|
.. | .. |
---|
467 | 458 | return count; |
---|
468 | 459 | } |
---|
469 | 460 | |
---|
470 | | -static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
---|
471 | | -static SENSOR_DEVICE_ATTR_2(temp1_min, S_IWUSR | S_IRUGO, show_temp, |
---|
472 | | - store_temp, 1, 0); |
---|
473 | | -static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp, |
---|
474 | | - store_temp, 2, 0); |
---|
475 | | -static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IWUSR | S_IRUGO, show_temp, |
---|
476 | | - store_temp, 3, 0); |
---|
477 | | -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, |
---|
478 | | - show_temp_crit_hyst, store_temp_crit_hyst, 0); |
---|
479 | | -static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, show_status, NULL, |
---|
480 | | - 1, TMP432_STATUS_LOCAL); |
---|
481 | | -static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, show_status, NULL, |
---|
482 | | - 2, TMP432_STATUS_LOCAL); |
---|
483 | | -static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, show_status, NULL, |
---|
484 | | - 3, TMP432_STATUS_LOCAL); |
---|
485 | | -static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1); |
---|
486 | | -static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp, |
---|
487 | | - store_temp, 1, 1); |
---|
488 | | -static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp, |
---|
489 | | - store_temp, 2, 1); |
---|
490 | | -static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IWUSR | S_IRUGO, show_temp, |
---|
491 | | - store_temp, 3, 1); |
---|
492 | | -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, |
---|
493 | | - NULL, 1); |
---|
494 | | -static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_status, NULL, |
---|
495 | | - 0, TMP432_STATUS_REMOTE1); |
---|
496 | | -static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, show_status, NULL, |
---|
497 | | - 1, TMP432_STATUS_REMOTE1); |
---|
498 | | -static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, show_status, NULL, |
---|
499 | | - 2, TMP432_STATUS_REMOTE1); |
---|
500 | | -static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, show_status, NULL, |
---|
501 | | - 3, TMP432_STATUS_REMOTE1); |
---|
| 461 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_input, temp, 0, 0); |
---|
| 462 | +static SENSOR_DEVICE_ATTR_2_RW(temp1_min, temp, 1, 0); |
---|
| 463 | +static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 2, 0); |
---|
| 464 | +static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 3, 0); |
---|
| 465 | +static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, temp_crit_hyst, 0); |
---|
| 466 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm, status, 1, |
---|
| 467 | + TMP432_STATUS_LOCAL); |
---|
| 468 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, status, 2, |
---|
| 469 | + TMP432_STATUS_LOCAL); |
---|
| 470 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, status, 3, |
---|
| 471 | + TMP432_STATUS_LOCAL); |
---|
| 472 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_input, temp, 0, 1); |
---|
| 473 | +static SENSOR_DEVICE_ATTR_2_RW(temp2_min, temp, 1, 1); |
---|
| 474 | +static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 2, 1); |
---|
| 475 | +static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 3, 1); |
---|
| 476 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, temp_crit_hyst, 1); |
---|
| 477 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, status, 0, TMP432_STATUS_REMOTE1); |
---|
| 478 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm, status, 1, |
---|
| 479 | + TMP432_STATUS_REMOTE1); |
---|
| 480 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, status, 2, |
---|
| 481 | + TMP432_STATUS_REMOTE1); |
---|
| 482 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, status, 3, |
---|
| 483 | + TMP432_STATUS_REMOTE1); |
---|
502 | 484 | |
---|
503 | 485 | static DEVICE_ATTR_RW(update_interval); |
---|
504 | 486 | |
---|
.. | .. |
---|
538 | 520 | * minimum and maximum register reset for both the local |
---|
539 | 521 | * and remote channels. |
---|
540 | 522 | */ |
---|
541 | | -static SENSOR_DEVICE_ATTR_2(temp1_lowest, S_IRUGO, show_temp, NULL, 4, 0); |
---|
542 | | -static SENSOR_DEVICE_ATTR_2(temp1_highest, S_IRUGO, show_temp, NULL, 5, 0); |
---|
543 | | -static SENSOR_DEVICE_ATTR_2(temp2_lowest, S_IRUGO, show_temp, NULL, 4, 1); |
---|
544 | | -static SENSOR_DEVICE_ATTR_2(temp2_highest, S_IRUGO, show_temp, NULL, 5, 1); |
---|
545 | | -static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, |
---|
546 | | - 0); |
---|
| 523 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_lowest, temp, 4, 0); |
---|
| 524 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_highest, temp, 5, 0); |
---|
| 525 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_lowest, temp, 4, 1); |
---|
| 526 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_highest, temp, 5, 1); |
---|
| 527 | +static SENSOR_DEVICE_ATTR_WO(temp_reset_history, reset_temp_history, 0); |
---|
547 | 528 | |
---|
548 | 529 | static struct attribute *tmp411_attributes[] = { |
---|
549 | 530 | &sensor_dev_attr_temp1_highest.dev_attr.attr, |
---|
.. | .. |
---|
558 | 539 | .attrs = tmp411_attributes, |
---|
559 | 540 | }; |
---|
560 | 541 | |
---|
561 | | -static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2); |
---|
562 | | -static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp, |
---|
563 | | - store_temp, 1, 2); |
---|
564 | | -static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp, |
---|
565 | | - store_temp, 2, 2); |
---|
566 | | -static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IWUSR | S_IRUGO, show_temp, |
---|
567 | | - store_temp, 3, 2); |
---|
568 | | -static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, |
---|
569 | | - NULL, 2); |
---|
570 | | -static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_status, NULL, |
---|
571 | | - 0, TMP432_STATUS_REMOTE2); |
---|
572 | | -static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, show_status, NULL, |
---|
573 | | - 1, TMP432_STATUS_REMOTE2); |
---|
574 | | -static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, show_status, NULL, |
---|
575 | | - 2, TMP432_STATUS_REMOTE2); |
---|
576 | | -static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, show_status, NULL, |
---|
577 | | - 3, TMP432_STATUS_REMOTE2); |
---|
| 542 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_input, temp, 0, 2); |
---|
| 543 | +static SENSOR_DEVICE_ATTR_2_RW(temp3_min, temp, 1, 2); |
---|
| 544 | +static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 2, 2); |
---|
| 545 | +static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 3, 2); |
---|
| 546 | +static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, temp_crit_hyst, 2); |
---|
| 547 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, status, 0, TMP432_STATUS_REMOTE2); |
---|
| 548 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm, status, 1, |
---|
| 549 | + TMP432_STATUS_REMOTE2); |
---|
| 550 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, status, 2, |
---|
| 551 | + TMP432_STATUS_REMOTE2); |
---|
| 552 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, status, 3, |
---|
| 553 | + TMP432_STATUS_REMOTE2); |
---|
578 | 554 | |
---|
579 | 555 | static struct attribute *tmp432_attributes[] = { |
---|
580 | 556 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
---|
.. | .. |
---|
598 | 574 | * Additional features of the TMP461 chip. |
---|
599 | 575 | * The TMP461 temperature offset for the remote channel. |
---|
600 | 576 | */ |
---|
601 | | -static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp, |
---|
602 | | - store_temp, 6, 1); |
---|
| 577 | +static SENSOR_DEVICE_ATTR_2_RW(temp2_offset, temp, 6, 1); |
---|
603 | 578 | |
---|
604 | 579 | static struct attribute *tmp461_attributes[] = { |
---|
605 | 580 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
---|
.. | .. |
---|
708 | 683 | return 0; |
---|
709 | 684 | } |
---|
710 | 685 | |
---|
711 | | -static int tmp401_probe(struct i2c_client *client, |
---|
712 | | - const struct i2c_device_id *id) |
---|
| 686 | +static int tmp401_probe(struct i2c_client *client) |
---|
713 | 687 | { |
---|
714 | 688 | static const char * const names[] = { |
---|
715 | 689 | "TMP401", "TMP411", "TMP431", "TMP432", "TMP435", "TMP461" |
---|
.. | .. |
---|
725 | 699 | |
---|
726 | 700 | data->client = client; |
---|
727 | 701 | mutex_init(&data->update_lock); |
---|
728 | | - data->kind = id->driver_data; |
---|
| 702 | + data->kind = i2c_match_id(tmp401_id, client)->driver_data; |
---|
729 | 703 | |
---|
730 | 704 | /* Initialize the TMP401 chip */ |
---|
731 | 705 | status = tmp401_init_client(data, client); |
---|
.. | .. |
---|
756 | 730 | return 0; |
---|
757 | 731 | } |
---|
758 | 732 | |
---|
| 733 | +static const struct of_device_id __maybe_unused tmp4xx_of_match[] = { |
---|
| 734 | + { .compatible = "ti,tmp401", }, |
---|
| 735 | + { .compatible = "ti,tmp411", }, |
---|
| 736 | + { .compatible = "ti,tmp431", }, |
---|
| 737 | + { .compatible = "ti,tmp432", }, |
---|
| 738 | + { .compatible = "ti,tmp435", }, |
---|
| 739 | + { }, |
---|
| 740 | +}; |
---|
| 741 | +MODULE_DEVICE_TABLE(of, tmp4xx_of_match); |
---|
| 742 | + |
---|
759 | 743 | static struct i2c_driver tmp401_driver = { |
---|
760 | 744 | .class = I2C_CLASS_HWMON, |
---|
761 | 745 | .driver = { |
---|
762 | 746 | .name = "tmp401", |
---|
| 747 | + .of_match_table = of_match_ptr(tmp4xx_of_match), |
---|
763 | 748 | }, |
---|
764 | | - .probe = tmp401_probe, |
---|
| 749 | + .probe_new = tmp401_probe, |
---|
765 | 750 | .id_table = tmp401_id, |
---|
766 | 751 | .detect = tmp401_detect, |
---|
767 | 752 | .address_list = normal_i2c, |
---|