.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for Texas Instruments / National Semiconductor LM95234 |
---|
3 | 4 | * |
---|
.. | .. |
---|
5 | 6 | * |
---|
6 | 7 | * Derived from lm95241.c |
---|
7 | 8 | * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com> |
---|
8 | | - * |
---|
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; either version 2 of the License, or |
---|
12 | | - * (at your option) any later version. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, |
---|
15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | | - * GNU General Public License for more details. |
---|
18 | 9 | */ |
---|
19 | 10 | |
---|
20 | 11 | #include <linux/module.h> |
---|
.. | .. |
---|
211 | 202 | return ret; |
---|
212 | 203 | } |
---|
213 | 204 | |
---|
214 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
---|
| 205 | +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, |
---|
215 | 206 | char *buf) |
---|
216 | 207 | { |
---|
217 | 208 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
225 | 216 | DIV_ROUND_CLOSEST(data->temp[index] * 125, 32)); |
---|
226 | 217 | } |
---|
227 | 218 | |
---|
228 | | -static ssize_t show_alarm(struct device *dev, |
---|
229 | | - struct device_attribute *attr, char *buf) |
---|
| 219 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
---|
| 220 | + char *buf) |
---|
230 | 221 | { |
---|
231 | 222 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
232 | 223 | u32 mask = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
238 | 229 | return sprintf(buf, "%u", !!(data->status & mask)); |
---|
239 | 230 | } |
---|
240 | 231 | |
---|
241 | | -static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
---|
| 232 | +static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
---|
242 | 233 | char *buf) |
---|
243 | 234 | { |
---|
244 | 235 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
251 | 242 | return sprintf(buf, data->sensor_type & mask ? "1\n" : "2\n"); |
---|
252 | 243 | } |
---|
253 | 244 | |
---|
254 | | -static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
---|
255 | | - const char *buf, size_t count) |
---|
| 245 | +static ssize_t type_store(struct device *dev, struct device_attribute *attr, |
---|
| 246 | + const char *buf, size_t count) |
---|
256 | 247 | { |
---|
257 | 248 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
258 | 249 | unsigned long val; |
---|
.. | .. |
---|
282 | 273 | return count; |
---|
283 | 274 | } |
---|
284 | 275 | |
---|
285 | | -static ssize_t show_tcrit2(struct device *dev, struct device_attribute *attr, |
---|
| 276 | +static ssize_t tcrit2_show(struct device *dev, struct device_attribute *attr, |
---|
286 | 277 | char *buf) |
---|
287 | 278 | { |
---|
288 | 279 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
295 | 286 | return sprintf(buf, "%u", data->tcrit2[index] * 1000); |
---|
296 | 287 | } |
---|
297 | 288 | |
---|
298 | | -static ssize_t set_tcrit2(struct device *dev, struct device_attribute *attr, |
---|
299 | | - const char *buf, size_t count) |
---|
| 289 | +static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr, |
---|
| 290 | + const char *buf, size_t count) |
---|
300 | 291 | { |
---|
301 | 292 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
302 | 293 | int index = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
320 | 311 | return count; |
---|
321 | 312 | } |
---|
322 | 313 | |
---|
323 | | -static ssize_t show_tcrit2_hyst(struct device *dev, |
---|
| 314 | +static ssize_t tcrit2_hyst_show(struct device *dev, |
---|
324 | 315 | struct device_attribute *attr, char *buf) |
---|
325 | 316 | { |
---|
326 | 317 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
335 | 326 | ((int)data->tcrit2[index] - (int)data->thyst) * 1000); |
---|
336 | 327 | } |
---|
337 | 328 | |
---|
338 | | -static ssize_t show_tcrit1(struct device *dev, struct device_attribute *attr, |
---|
| 329 | +static ssize_t tcrit1_show(struct device *dev, struct device_attribute *attr, |
---|
339 | 330 | char *buf) |
---|
340 | 331 | { |
---|
341 | 332 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
344 | 335 | return sprintf(buf, "%u", data->tcrit1[index] * 1000); |
---|
345 | 336 | } |
---|
346 | 337 | |
---|
347 | | -static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr, |
---|
348 | | - const char *buf, size_t count) |
---|
| 338 | +static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr, |
---|
| 339 | + const char *buf, size_t count) |
---|
349 | 340 | { |
---|
350 | 341 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
351 | 342 | int index = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
369 | 360 | return count; |
---|
370 | 361 | } |
---|
371 | 362 | |
---|
372 | | -static ssize_t show_tcrit1_hyst(struct device *dev, |
---|
| 363 | +static ssize_t tcrit1_hyst_show(struct device *dev, |
---|
373 | 364 | struct device_attribute *attr, char *buf) |
---|
374 | 365 | { |
---|
375 | 366 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
384 | 375 | ((int)data->tcrit1[index] - (int)data->thyst) * 1000); |
---|
385 | 376 | } |
---|
386 | 377 | |
---|
387 | | -static ssize_t set_tcrit1_hyst(struct device *dev, |
---|
388 | | - struct device_attribute *attr, |
---|
389 | | - const char *buf, size_t count) |
---|
| 378 | +static ssize_t tcrit1_hyst_store(struct device *dev, |
---|
| 379 | + struct device_attribute *attr, |
---|
| 380 | + const char *buf, size_t count) |
---|
390 | 381 | { |
---|
391 | 382 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
392 | 383 | int index = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
411 | 402 | return count; |
---|
412 | 403 | } |
---|
413 | 404 | |
---|
414 | | -static ssize_t show_offset(struct device *dev, struct device_attribute *attr, |
---|
| 405 | +static ssize_t offset_show(struct device *dev, struct device_attribute *attr, |
---|
415 | 406 | char *buf) |
---|
416 | 407 | { |
---|
417 | 408 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
424 | 415 | return sprintf(buf, "%d", data->toffset[index] * 500); |
---|
425 | 416 | } |
---|
426 | 417 | |
---|
427 | | -static ssize_t set_offset(struct device *dev, struct device_attribute *attr, |
---|
428 | | - const char *buf, size_t count) |
---|
| 418 | +static ssize_t offset_store(struct device *dev, struct device_attribute *attr, |
---|
| 419 | + const char *buf, size_t count) |
---|
429 | 420 | { |
---|
430 | 421 | struct lm95234_data *data = dev_get_drvdata(dev); |
---|
431 | 422 | int index = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
492 | 483 | return count; |
---|
493 | 484 | } |
---|
494 | 485 | |
---|
495 | | -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); |
---|
496 | | -static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); |
---|
497 | | -static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); |
---|
498 | | -static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); |
---|
499 | | -static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4); |
---|
| 486 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
---|
| 487 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
---|
| 488 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
---|
| 489 | +static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3); |
---|
| 490 | +static SENSOR_DEVICE_ATTR_RO(temp5_input, temp, 4); |
---|
500 | 491 | |
---|
501 | | -static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, |
---|
502 | | - BIT(0) | BIT(1)); |
---|
503 | | -static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, |
---|
504 | | - BIT(2) | BIT(3)); |
---|
505 | | -static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL, |
---|
506 | | - BIT(4) | BIT(5)); |
---|
507 | | -static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_alarm, NULL, |
---|
508 | | - BIT(6) | BIT(7)); |
---|
| 492 | +static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, BIT(0) | BIT(1)); |
---|
| 493 | +static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, BIT(2) | BIT(3)); |
---|
| 494 | +static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, BIT(4) | BIT(5)); |
---|
| 495 | +static SENSOR_DEVICE_ATTR_RO(temp5_fault, alarm, BIT(6) | BIT(7)); |
---|
509 | 496 | |
---|
510 | | -static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type, |
---|
511 | | - BIT(1)); |
---|
512 | | -static SENSOR_DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type, set_type, |
---|
513 | | - BIT(2)); |
---|
514 | | -static SENSOR_DEVICE_ATTR(temp4_type, S_IWUSR | S_IRUGO, show_type, set_type, |
---|
515 | | - BIT(3)); |
---|
516 | | -static SENSOR_DEVICE_ATTR(temp5_type, S_IWUSR | S_IRUGO, show_type, set_type, |
---|
517 | | - BIT(4)); |
---|
| 497 | +static SENSOR_DEVICE_ATTR_RW(temp2_type, type, BIT(1)); |
---|
| 498 | +static SENSOR_DEVICE_ATTR_RW(temp3_type, type, BIT(2)); |
---|
| 499 | +static SENSOR_DEVICE_ATTR_RW(temp4_type, type, BIT(3)); |
---|
| 500 | +static SENSOR_DEVICE_ATTR_RW(temp5_type, type, BIT(4)); |
---|
518 | 501 | |
---|
519 | | -static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_tcrit1, |
---|
520 | | - set_tcrit1, 0); |
---|
521 | | -static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_tcrit2, |
---|
522 | | - set_tcrit2, 0); |
---|
523 | | -static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_tcrit2, |
---|
524 | | - set_tcrit2, 1); |
---|
525 | | -static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_tcrit1, |
---|
526 | | - set_tcrit1, 3); |
---|
527 | | -static SENSOR_DEVICE_ATTR(temp5_max, S_IWUSR | S_IRUGO, show_tcrit1, |
---|
528 | | - set_tcrit1, 4); |
---|
| 502 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, tcrit1, 0); |
---|
| 503 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, tcrit2, 0); |
---|
| 504 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, tcrit2, 1); |
---|
| 505 | +static SENSOR_DEVICE_ATTR_RW(temp4_max, tcrit1, 3); |
---|
| 506 | +static SENSOR_DEVICE_ATTR_RW(temp5_max, tcrit1, 4); |
---|
529 | 507 | |
---|
530 | | -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_tcrit1_hyst, |
---|
531 | | - set_tcrit1_hyst, 0); |
---|
532 | | -static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO, show_tcrit2_hyst, NULL, 0); |
---|
533 | | -static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO, show_tcrit2_hyst, NULL, 1); |
---|
534 | | -static SENSOR_DEVICE_ATTR(temp4_max_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 3); |
---|
535 | | -static SENSOR_DEVICE_ATTR(temp5_max_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 4); |
---|
| 508 | +static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, tcrit1_hyst, 0); |
---|
| 509 | +static SENSOR_DEVICE_ATTR_RO(temp2_max_hyst, tcrit2_hyst, 0); |
---|
| 510 | +static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, tcrit2_hyst, 1); |
---|
| 511 | +static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, tcrit1_hyst, 3); |
---|
| 512 | +static SENSOR_DEVICE_ATTR_RO(temp5_max_hyst, tcrit1_hyst, 4); |
---|
536 | 513 | |
---|
537 | | -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, |
---|
538 | | - BIT(0 + 8)); |
---|
539 | | -static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, |
---|
540 | | - BIT(1 + 16)); |
---|
541 | | -static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, |
---|
542 | | - BIT(2 + 16)); |
---|
543 | | -static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, |
---|
544 | | - BIT(3 + 8)); |
---|
545 | | -static SENSOR_DEVICE_ATTR(temp5_max_alarm, S_IRUGO, show_alarm, NULL, |
---|
546 | | - BIT(4 + 8)); |
---|
| 514 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, BIT(0 + 8)); |
---|
| 515 | +static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, BIT(1 + 16)); |
---|
| 516 | +static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, BIT(2 + 16)); |
---|
| 517 | +static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, BIT(3 + 8)); |
---|
| 518 | +static SENSOR_DEVICE_ATTR_RO(temp5_max_alarm, alarm, BIT(4 + 8)); |
---|
547 | 519 | |
---|
548 | | -static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_tcrit1, |
---|
549 | | - set_tcrit1, 1); |
---|
550 | | -static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_tcrit1, |
---|
551 | | - set_tcrit1, 2); |
---|
| 520 | +static SENSOR_DEVICE_ATTR_RW(temp2_crit, tcrit1, 1); |
---|
| 521 | +static SENSOR_DEVICE_ATTR_RW(temp3_crit, tcrit1, 2); |
---|
552 | 522 | |
---|
553 | | -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 1); |
---|
554 | | -static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 2); |
---|
| 523 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, tcrit1_hyst, 1); |
---|
| 524 | +static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, tcrit1_hyst, 2); |
---|
555 | 525 | |
---|
556 | | -static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, |
---|
557 | | - BIT(1 + 8)); |
---|
558 | | -static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, |
---|
559 | | - BIT(2 + 8)); |
---|
| 526 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, BIT(1 + 8)); |
---|
| 527 | +static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, BIT(2 + 8)); |
---|
560 | 528 | |
---|
561 | | -static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_offset, |
---|
562 | | - set_offset, 0); |
---|
563 | | -static SENSOR_DEVICE_ATTR(temp3_offset, S_IWUSR | S_IRUGO, show_offset, |
---|
564 | | - set_offset, 1); |
---|
565 | | -static SENSOR_DEVICE_ATTR(temp4_offset, S_IWUSR | S_IRUGO, show_offset, |
---|
566 | | - set_offset, 2); |
---|
567 | | -static SENSOR_DEVICE_ATTR(temp5_offset, S_IWUSR | S_IRUGO, show_offset, |
---|
568 | | - set_offset, 3); |
---|
| 529 | +static SENSOR_DEVICE_ATTR_RW(temp2_offset, offset, 0); |
---|
| 530 | +static SENSOR_DEVICE_ATTR_RW(temp3_offset, offset, 1); |
---|
| 531 | +static SENSOR_DEVICE_ATTR_RW(temp4_offset, offset, 2); |
---|
| 532 | +static SENSOR_DEVICE_ATTR_RW(temp5_offset, offset, 3); |
---|
569 | 533 | |
---|
570 | 534 | static DEVICE_ATTR_RW(update_interval); |
---|
571 | 535 | |
---|
.. | .. |
---|
713 | 677 | return 0; |
---|
714 | 678 | } |
---|
715 | 679 | |
---|
716 | | -static int lm95234_probe(struct i2c_client *client, |
---|
717 | | - const struct i2c_device_id *id) |
---|
| 680 | +static const struct i2c_device_id lm95234_id[]; |
---|
| 681 | + |
---|
| 682 | +static int lm95234_probe(struct i2c_client *client) |
---|
718 | 683 | { |
---|
719 | 684 | struct device *dev = &client->dev; |
---|
720 | 685 | struct lm95234_data *data; |
---|
.. | .. |
---|
734 | 699 | return err; |
---|
735 | 700 | |
---|
736 | 701 | data->groups[0] = &lm95234_common_group; |
---|
737 | | - if (id->driver_data == lm95234) |
---|
| 702 | + if (i2c_match_id(lm95234_id, client)->driver_data == lm95234) |
---|
738 | 703 | data->groups[1] = &lm95234_group; |
---|
739 | 704 | |
---|
740 | 705 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
---|
.. | .. |
---|
755 | 720 | .driver = { |
---|
756 | 721 | .name = DRVNAME, |
---|
757 | 722 | }, |
---|
758 | | - .probe = lm95234_probe, |
---|
| 723 | + .probe_new = lm95234_probe, |
---|
759 | 724 | .id_table = lm95234_id, |
---|
760 | 725 | .detect = lm95234_detect, |
---|
761 | 726 | .address_list = normal_i2c, |
---|