.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * ADT7316 digital temperature sensor driver supporting ADT7316/7/8 ADT7516/7/9 |
---|
3 | 4 | * |
---|
4 | | - * |
---|
5 | 5 | * Copyright 2010 Analog Devices Inc. |
---|
6 | | - * |
---|
7 | | - * Licensed under the GPL-2 or later. |
---|
8 | 6 | */ |
---|
9 | 7 | |
---|
10 | 8 | #include <linux/interrupt.h> |
---|
11 | | -#include <linux/gpio.h> |
---|
| 9 | +#include <linux/gpio/consumer.h> |
---|
| 10 | +#include <linux/irq.h> |
---|
12 | 11 | #include <linux/workqueue.h> |
---|
13 | 12 | #include <linux/device.h> |
---|
14 | 13 | #include <linux/kernel.h> |
---|
.. | .. |
---|
61 | 60 | #define ADT7316_CONFIG1 0x18 |
---|
62 | 61 | #define ADT7316_CONFIG2 0x19 |
---|
63 | 62 | #define ADT7316_CONFIG3 0x1A |
---|
64 | | -#define ADT7316_LDAC_CONFIG 0x1B |
---|
65 | | -#define ADT7316_DAC_CONFIG 0x1C |
---|
| 63 | +#define ADT7316_DAC_CONFIG 0x1B |
---|
| 64 | +#define ADT7316_LDAC_CONFIG 0x1C |
---|
66 | 65 | #define ADT7316_INT_MASK1 0x1D |
---|
67 | 66 | #define ADT7316_INT_MASK2 0x1E |
---|
68 | 67 | #define ADT7316_IN_TEMP_OFFSET 0x1F |
---|
.. | .. |
---|
119 | 118 | */ |
---|
120 | 119 | #define ADT7316_ADCLK_22_5 0x1 |
---|
121 | 120 | #define ADT7316_DA_HIGH_RESOLUTION 0x2 |
---|
122 | | -#define ADT7316_DA_EN_VIA_DAC_LDCA 0x4 |
---|
| 121 | +#define ADT7316_DA_EN_VIA_DAC_LDAC 0x8 |
---|
123 | 122 | #define ADT7516_AIN_IN_VREF 0x10 |
---|
124 | 123 | #define ADT7316_EN_IN_TEMP_PROP_DACA 0x20 |
---|
125 | 124 | #define ADT7316_EN_EX_TEMP_PROP_DACB 0x40 |
---|
.. | .. |
---|
129 | 128 | */ |
---|
130 | 129 | #define ADT7316_DA_2VREF_CH_MASK 0xF |
---|
131 | 130 | #define ADT7316_DA_EN_MODE_MASK 0x30 |
---|
| 131 | +#define ADT7316_DA_EN_MODE_SHIFT 4 |
---|
132 | 132 | #define ADT7316_DA_EN_MODE_SINGLE 0x00 |
---|
133 | 133 | #define ADT7316_DA_EN_MODE_AB_CD 0x10 |
---|
134 | 134 | #define ADT7316_DA_EN_MODE_ABCD 0x20 |
---|
.. | .. |
---|
179 | 179 | |
---|
180 | 180 | struct adt7316_chip_info { |
---|
181 | 181 | struct adt7316_bus bus; |
---|
182 | | - u16 ldac_pin; |
---|
| 182 | + struct gpio_desc *ldac_pin; |
---|
183 | 183 | u16 int_mask; /* 0x2f */ |
---|
184 | 184 | u8 config1; |
---|
185 | 185 | u8 config2; |
---|
.. | .. |
---|
219 | 219 | }; |
---|
220 | 220 | |
---|
221 | 221 | static ssize_t adt7316_show_enabled(struct device *dev, |
---|
222 | | - struct device_attribute *attr, |
---|
223 | | - char *buf) |
---|
| 222 | + struct device_attribute *attr, |
---|
| 223 | + char *buf) |
---|
224 | 224 | { |
---|
225 | 225 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
226 | 226 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
229 | 229 | } |
---|
230 | 230 | |
---|
231 | 231 | static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip, |
---|
232 | | - int enable) |
---|
| 232 | + int enable) |
---|
233 | 233 | { |
---|
234 | 234 | u8 config1; |
---|
235 | 235 | int ret; |
---|
.. | .. |
---|
249 | 249 | } |
---|
250 | 250 | |
---|
251 | 251 | static ssize_t adt7316_store_enabled(struct device *dev, |
---|
252 | | - struct device_attribute *attr, |
---|
253 | | - const char *buf, |
---|
254 | | - size_t len) |
---|
| 252 | + struct device_attribute *attr, |
---|
| 253 | + const char *buf, |
---|
| 254 | + size_t len) |
---|
255 | 255 | { |
---|
256 | 256 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
257 | 257 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
274 | 274 | 0); |
---|
275 | 275 | |
---|
276 | 276 | static ssize_t adt7316_show_select_ex_temp(struct device *dev, |
---|
277 | | - struct device_attribute *attr, |
---|
278 | | - char *buf) |
---|
| 277 | + struct device_attribute *attr, |
---|
| 278 | + char *buf) |
---|
279 | 279 | { |
---|
280 | 280 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
281 | 281 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
287 | 287 | } |
---|
288 | 288 | |
---|
289 | 289 | static ssize_t adt7316_store_select_ex_temp(struct device *dev, |
---|
290 | | - struct device_attribute *attr, |
---|
291 | | - const char *buf, |
---|
292 | | - size_t len) |
---|
| 290 | + struct device_attribute *attr, |
---|
| 291 | + const char *buf, |
---|
| 292 | + size_t len) |
---|
293 | 293 | { |
---|
294 | 294 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
295 | 295 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
318 | 318 | 0); |
---|
319 | 319 | |
---|
320 | 320 | static ssize_t adt7316_show_mode(struct device *dev, |
---|
321 | | - struct device_attribute *attr, |
---|
322 | | - char *buf) |
---|
| 321 | + struct device_attribute *attr, |
---|
| 322 | + char *buf) |
---|
323 | 323 | { |
---|
324 | 324 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
325 | 325 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
331 | 331 | } |
---|
332 | 332 | |
---|
333 | 333 | static ssize_t adt7316_store_mode(struct device *dev, |
---|
334 | | - struct device_attribute *attr, |
---|
335 | | - const char *buf, |
---|
336 | | - size_t len) |
---|
| 334 | + struct device_attribute *attr, |
---|
| 335 | + const char *buf, |
---|
| 336 | + size_t len) |
---|
337 | 337 | { |
---|
338 | 338 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
339 | 339 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
359 | 359 | 0); |
---|
360 | 360 | |
---|
361 | 361 | static ssize_t adt7316_show_all_modes(struct device *dev, |
---|
362 | | - struct device_attribute *attr, |
---|
363 | | - char *buf) |
---|
| 362 | + struct device_attribute *attr, |
---|
| 363 | + char *buf) |
---|
364 | 364 | { |
---|
365 | 365 | return sprintf(buf, "single_channel\nround_robin\n"); |
---|
366 | 366 | } |
---|
.. | .. |
---|
368 | 368 | static IIO_DEVICE_ATTR(all_modes, 0444, adt7316_show_all_modes, NULL, 0); |
---|
369 | 369 | |
---|
370 | 370 | static ssize_t adt7316_show_ad_channel(struct device *dev, |
---|
371 | | - struct device_attribute *attr, |
---|
372 | | - char *buf) |
---|
| 371 | + struct device_attribute *attr, |
---|
| 372 | + char *buf) |
---|
373 | 373 | { |
---|
374 | 374 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
375 | 375 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
384 | 384 | return sprintf(buf, "1 - Internal Temperature\n"); |
---|
385 | 385 | case ADT7316_AD_SINGLE_CH_EX: |
---|
386 | 386 | if (((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) && |
---|
387 | | - (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) |
---|
| 387 | + (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) |
---|
388 | 388 | return sprintf(buf, "2 - AIN1\n"); |
---|
389 | 389 | |
---|
390 | 390 | return sprintf(buf, "2 - External Temperature\n"); |
---|
.. | .. |
---|
406 | 406 | } |
---|
407 | 407 | |
---|
408 | 408 | static ssize_t adt7316_store_ad_channel(struct device *dev, |
---|
409 | | - struct device_attribute *attr, |
---|
410 | | - const char *buf, |
---|
411 | | - size_t len) |
---|
| 409 | + struct device_attribute *attr, |
---|
| 410 | + const char *buf, |
---|
| 411 | + size_t len) |
---|
412 | 412 | { |
---|
413 | 413 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
414 | 414 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
452 | 452 | 0); |
---|
453 | 453 | |
---|
454 | 454 | static ssize_t adt7316_show_all_ad_channels(struct device *dev, |
---|
455 | | - struct device_attribute *attr, |
---|
456 | | - char *buf) |
---|
| 455 | + struct device_attribute *attr, |
---|
| 456 | + char *buf) |
---|
457 | 457 | { |
---|
458 | 458 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
459 | 459 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
473 | 473 | adt7316_show_all_ad_channels, NULL, 0); |
---|
474 | 474 | |
---|
475 | 475 | static ssize_t adt7316_show_disable_averaging(struct device *dev, |
---|
476 | | - struct device_attribute *attr, |
---|
477 | | - char *buf) |
---|
| 476 | + struct device_attribute *attr, |
---|
| 477 | + char *buf) |
---|
478 | 478 | { |
---|
479 | 479 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
480 | 480 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
484 | 484 | } |
---|
485 | 485 | |
---|
486 | 486 | static ssize_t adt7316_store_disable_averaging(struct device *dev, |
---|
487 | | - struct device_attribute *attr, |
---|
488 | | - const char *buf, |
---|
489 | | - size_t len) |
---|
| 487 | + struct device_attribute *attr, |
---|
| 488 | + const char *buf, |
---|
| 489 | + size_t len) |
---|
490 | 490 | { |
---|
491 | 491 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
492 | 492 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
512 | 512 | 0); |
---|
513 | 513 | |
---|
514 | 514 | static ssize_t adt7316_show_enable_smbus_timeout(struct device *dev, |
---|
515 | | - struct device_attribute *attr, |
---|
516 | | - char *buf) |
---|
| 515 | + struct device_attribute *attr, |
---|
| 516 | + char *buf) |
---|
517 | 517 | { |
---|
518 | 518 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
519 | 519 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
523 | 523 | } |
---|
524 | 524 | |
---|
525 | 525 | static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev, |
---|
526 | | - struct device_attribute *attr, |
---|
527 | | - const char *buf, |
---|
528 | | - size_t len) |
---|
| 526 | + struct device_attribute *attr, |
---|
| 527 | + const char *buf, |
---|
| 528 | + size_t len) |
---|
529 | 529 | { |
---|
530 | 530 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
531 | 531 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
551 | 551 | 0); |
---|
552 | 552 | |
---|
553 | 553 | static ssize_t adt7316_show_powerdown(struct device *dev, |
---|
554 | | - struct device_attribute *attr, |
---|
555 | | - char *buf) |
---|
| 554 | + struct device_attribute *attr, |
---|
| 555 | + char *buf) |
---|
556 | 556 | { |
---|
557 | 557 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
558 | 558 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
561 | 561 | } |
---|
562 | 562 | |
---|
563 | 563 | static ssize_t adt7316_store_powerdown(struct device *dev, |
---|
564 | | - struct device_attribute *attr, |
---|
565 | | - const char *buf, |
---|
566 | | - size_t len) |
---|
| 564 | + struct device_attribute *attr, |
---|
| 565 | + const char *buf, |
---|
| 566 | + size_t len) |
---|
567 | 567 | { |
---|
568 | 568 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
569 | 569 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
589 | 589 | 0); |
---|
590 | 590 | |
---|
591 | 591 | static ssize_t adt7316_show_fast_ad_clock(struct device *dev, |
---|
592 | | - struct device_attribute *attr, |
---|
593 | | - char *buf) |
---|
| 592 | + struct device_attribute *attr, |
---|
| 593 | + char *buf) |
---|
594 | 594 | { |
---|
595 | 595 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
596 | 596 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
599 | 599 | } |
---|
600 | 600 | |
---|
601 | 601 | static ssize_t adt7316_store_fast_ad_clock(struct device *dev, |
---|
602 | | - struct device_attribute *attr, |
---|
603 | | - const char *buf, |
---|
604 | | - size_t len) |
---|
| 602 | + struct device_attribute *attr, |
---|
| 603 | + const char *buf, |
---|
| 604 | + size_t len) |
---|
605 | 605 | { |
---|
606 | 606 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
607 | 607 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
627 | 627 | 0); |
---|
628 | 628 | |
---|
629 | 629 | static ssize_t adt7316_show_da_high_resolution(struct device *dev, |
---|
630 | | - struct device_attribute *attr, |
---|
631 | | - char *buf) |
---|
| 630 | + struct device_attribute *attr, |
---|
| 631 | + char *buf) |
---|
632 | 632 | { |
---|
633 | 633 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
634 | 634 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
635 | 635 | |
---|
636 | 636 | if (chip->config3 & ADT7316_DA_HIGH_RESOLUTION) { |
---|
637 | | - if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516) |
---|
638 | | - return sprintf(buf, "1 (12 bits)\n"); |
---|
639 | | - if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) |
---|
| 637 | + if (chip->id != ID_ADT7318 && chip->id != ID_ADT7519) |
---|
640 | 638 | return sprintf(buf, "1 (10 bits)\n"); |
---|
641 | 639 | } |
---|
642 | 640 | |
---|
.. | .. |
---|
644 | 642 | } |
---|
645 | 643 | |
---|
646 | 644 | static ssize_t adt7316_store_da_high_resolution(struct device *dev, |
---|
647 | | - struct device_attribute *attr, |
---|
648 | | - const char *buf, |
---|
649 | | - size_t len) |
---|
| 645 | + struct device_attribute *attr, |
---|
| 646 | + const char *buf, |
---|
| 647 | + size_t len) |
---|
650 | 648 | { |
---|
651 | 649 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
652 | 650 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
653 | 651 | u8 config3; |
---|
654 | 652 | int ret; |
---|
655 | 653 | |
---|
656 | | - chip->dac_bits = 8; |
---|
| 654 | + if (chip->id == ID_ADT7318 || chip->id == ID_ADT7519) |
---|
| 655 | + return -EPERM; |
---|
657 | 656 | |
---|
658 | | - if (buf[0] == '1') { |
---|
659 | | - config3 = chip->config3 | ADT7316_DA_HIGH_RESOLUTION; |
---|
660 | | - if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516) |
---|
661 | | - chip->dac_bits = 12; |
---|
662 | | - else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) |
---|
663 | | - chip->dac_bits = 10; |
---|
664 | | - } else { |
---|
665 | | - config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); |
---|
666 | | - } |
---|
| 657 | + config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); |
---|
| 658 | + if (buf[0] == '1') |
---|
| 659 | + config3 |= ADT7316_DA_HIGH_RESOLUTION; |
---|
667 | 660 | |
---|
668 | 661 | ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3); |
---|
669 | 662 | if (ret) |
---|
.. | .. |
---|
680 | 673 | 0); |
---|
681 | 674 | |
---|
682 | 675 | static ssize_t adt7316_show_AIN_internal_Vref(struct device *dev, |
---|
683 | | - struct device_attribute *attr, |
---|
684 | | - char *buf) |
---|
| 676 | + struct device_attribute *attr, |
---|
| 677 | + char *buf) |
---|
685 | 678 | { |
---|
686 | 679 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
687 | 680 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
694 | 687 | } |
---|
695 | 688 | |
---|
696 | 689 | static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev, |
---|
697 | | - struct device_attribute *attr, |
---|
698 | | - const char *buf, |
---|
699 | | - size_t len) |
---|
| 690 | + struct device_attribute *attr, |
---|
| 691 | + const char *buf, |
---|
| 692 | + size_t len) |
---|
700 | 693 | { |
---|
701 | 694 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
702 | 695 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
726 | 719 | 0); |
---|
727 | 720 | |
---|
728 | 721 | static ssize_t adt7316_show_enable_prop_DACA(struct device *dev, |
---|
729 | | - struct device_attribute *attr, |
---|
730 | | - char *buf) |
---|
| 722 | + struct device_attribute *attr, |
---|
| 723 | + char *buf) |
---|
731 | 724 | { |
---|
732 | 725 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
733 | 726 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
737 | 730 | } |
---|
738 | 731 | |
---|
739 | 732 | static ssize_t adt7316_store_enable_prop_DACA(struct device *dev, |
---|
740 | | - struct device_attribute *attr, |
---|
741 | | - const char *buf, |
---|
742 | | - size_t len) |
---|
| 733 | + struct device_attribute *attr, |
---|
| 734 | + const char *buf, |
---|
| 735 | + size_t len) |
---|
743 | 736 | { |
---|
744 | 737 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
745 | 738 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
760 | 753 | } |
---|
761 | 754 | |
---|
762 | 755 | static IIO_DEVICE_ATTR(enable_proportion_DACA, 0644, |
---|
763 | | - adt7316_show_enable_prop_DACA, |
---|
764 | | - adt7316_store_enable_prop_DACA, |
---|
765 | | - 0); |
---|
| 756 | + adt7316_show_enable_prop_DACA, |
---|
| 757 | + adt7316_store_enable_prop_DACA, |
---|
| 758 | + 0); |
---|
766 | 759 | |
---|
767 | 760 | static ssize_t adt7316_show_enable_prop_DACB(struct device *dev, |
---|
768 | | - struct device_attribute *attr, |
---|
769 | | - char *buf) |
---|
| 761 | + struct device_attribute *attr, |
---|
| 762 | + char *buf) |
---|
770 | 763 | { |
---|
771 | 764 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
772 | 765 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
776 | 769 | } |
---|
777 | 770 | |
---|
778 | 771 | static ssize_t adt7316_store_enable_prop_DACB(struct device *dev, |
---|
779 | | - struct device_attribute *attr, |
---|
780 | | - const char *buf, |
---|
781 | | - size_t len) |
---|
| 772 | + struct device_attribute *attr, |
---|
| 773 | + const char *buf, |
---|
| 774 | + size_t len) |
---|
782 | 775 | { |
---|
783 | 776 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
784 | 777 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
799 | 792 | } |
---|
800 | 793 | |
---|
801 | 794 | static IIO_DEVICE_ATTR(enable_proportion_DACB, 0644, |
---|
802 | | - adt7316_show_enable_prop_DACB, |
---|
803 | | - adt7316_store_enable_prop_DACB, |
---|
804 | | - 0); |
---|
| 795 | + adt7316_show_enable_prop_DACB, |
---|
| 796 | + adt7316_store_enable_prop_DACB, |
---|
| 797 | + 0); |
---|
805 | 798 | |
---|
806 | 799 | static ssize_t adt7316_show_DAC_2Vref_ch_mask(struct device *dev, |
---|
807 | | - struct device_attribute *attr, |
---|
808 | | - char *buf) |
---|
| 800 | + struct device_attribute *attr, |
---|
| 801 | + char *buf) |
---|
809 | 802 | { |
---|
810 | 803 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
811 | 804 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
815 | 808 | } |
---|
816 | 809 | |
---|
817 | 810 | static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev, |
---|
818 | | - struct device_attribute *attr, |
---|
819 | | - const char *buf, |
---|
820 | | - size_t len) |
---|
| 811 | + struct device_attribute *attr, |
---|
| 812 | + const char *buf, |
---|
| 813 | + size_t len) |
---|
821 | 814 | { |
---|
822 | 815 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
823 | 816 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
842 | 835 | } |
---|
843 | 836 | |
---|
844 | 837 | static IIO_DEVICE_ATTR(DAC_2Vref_channels_mask, 0644, |
---|
845 | | - adt7316_show_DAC_2Vref_ch_mask, |
---|
846 | | - adt7316_store_DAC_2Vref_ch_mask, |
---|
847 | | - 0); |
---|
| 838 | + adt7316_show_DAC_2Vref_ch_mask, |
---|
| 839 | + adt7316_store_DAC_2Vref_ch_mask, |
---|
| 840 | + 0); |
---|
848 | 841 | |
---|
849 | 842 | static ssize_t adt7316_show_DAC_update_mode(struct device *dev, |
---|
850 | | - struct device_attribute *attr, |
---|
851 | | - char *buf) |
---|
| 843 | + struct device_attribute *attr, |
---|
| 844 | + char *buf) |
---|
852 | 845 | { |
---|
853 | 846 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
854 | 847 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
855 | 848 | |
---|
856 | | - if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA)) |
---|
| 849 | + if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDAC)) |
---|
857 | 850 | return sprintf(buf, "manual\n"); |
---|
858 | 851 | |
---|
859 | 852 | switch (chip->dac_config & ADT7316_DA_EN_MODE_MASK) { |
---|
.. | .. |
---|
872 | 865 | } |
---|
873 | 866 | |
---|
874 | 867 | static ssize_t adt7316_store_DAC_update_mode(struct device *dev, |
---|
875 | | - struct device_attribute *attr, |
---|
876 | | - const char *buf, |
---|
877 | | - size_t len) |
---|
| 868 | + struct device_attribute *attr, |
---|
| 869 | + const char *buf, |
---|
| 870 | + size_t len) |
---|
878 | 871 | { |
---|
879 | 872 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
880 | 873 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
882 | 875 | u8 data; |
---|
883 | 876 | int ret; |
---|
884 | 877 | |
---|
885 | | - if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA)) |
---|
| 878 | + if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDAC)) |
---|
886 | 879 | return -EPERM; |
---|
887 | 880 | |
---|
888 | 881 | ret = kstrtou8(buf, 10, &data); |
---|
889 | | - if (ret || data > ADT7316_DA_EN_MODE_MASK) |
---|
| 882 | + if (ret || data > (ADT7316_DA_EN_MODE_MASK >> ADT7316_DA_EN_MODE_SHIFT)) |
---|
890 | 883 | return -EINVAL; |
---|
891 | 884 | |
---|
892 | 885 | dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK); |
---|
893 | | - dac_config |= data; |
---|
| 886 | + dac_config |= data << ADT7316_DA_EN_MODE_SHIFT; |
---|
894 | 887 | |
---|
895 | 888 | ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config); |
---|
896 | 889 | if (ret) |
---|
.. | .. |
---|
902 | 895 | } |
---|
903 | 896 | |
---|
904 | 897 | static IIO_DEVICE_ATTR(DAC_update_mode, 0644, |
---|
905 | | - adt7316_show_DAC_update_mode, |
---|
906 | | - adt7316_store_DAC_update_mode, |
---|
907 | | - 0); |
---|
| 898 | + adt7316_show_DAC_update_mode, |
---|
| 899 | + adt7316_store_DAC_update_mode, |
---|
| 900 | + 0); |
---|
908 | 901 | |
---|
909 | 902 | static ssize_t adt7316_show_all_DAC_update_modes(struct device *dev, |
---|
910 | | - struct device_attribute *attr, |
---|
911 | | - char *buf) |
---|
| 903 | + struct device_attribute *attr, |
---|
| 904 | + char *buf) |
---|
912 | 905 | { |
---|
913 | 906 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
914 | 907 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
915 | 908 | |
---|
916 | | - if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA) |
---|
| 909 | + if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDAC) |
---|
917 | 910 | return sprintf(buf, "0 - auto at any MSB DAC writing\n" |
---|
918 | 911 | "1 - auto at MSB DAC AB and CD writing\n" |
---|
919 | 912 | "2 - auto at MSB DAC ABCD writing\n" |
---|
.. | .. |
---|
922 | 915 | } |
---|
923 | 916 | |
---|
924 | 917 | static IIO_DEVICE_ATTR(all_DAC_update_modes, 0444, |
---|
925 | | - adt7316_show_all_DAC_update_modes, NULL, 0); |
---|
| 918 | + adt7316_show_all_DAC_update_modes, NULL, 0); |
---|
926 | 919 | |
---|
927 | 920 | static ssize_t adt7316_store_update_DAC(struct device *dev, |
---|
928 | | - struct device_attribute *attr, |
---|
929 | | - const char *buf, |
---|
930 | | - size_t len) |
---|
| 921 | + struct device_attribute *attr, |
---|
| 922 | + const char *buf, |
---|
| 923 | + size_t len) |
---|
931 | 924 | { |
---|
932 | 925 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
933 | 926 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
935 | 928 | u8 data; |
---|
936 | 929 | int ret; |
---|
937 | 930 | |
---|
938 | | - if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA) { |
---|
| 931 | + if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDAC) { |
---|
939 | 932 | if ((chip->dac_config & ADT7316_DA_EN_MODE_MASK) != |
---|
940 | 933 | ADT7316_DA_EN_MODE_LDAC) |
---|
941 | 934 | return -EPERM; |
---|
.. | .. |
---|
952 | 945 | if (ret) |
---|
953 | 946 | return -EIO; |
---|
954 | 947 | } else { |
---|
955 | | - gpio_set_value(chip->ldac_pin, 0); |
---|
956 | | - gpio_set_value(chip->ldac_pin, 1); |
---|
| 948 | + gpiod_set_value(chip->ldac_pin, 0); |
---|
| 949 | + gpiod_set_value(chip->ldac_pin, 1); |
---|
957 | 950 | } |
---|
958 | 951 | |
---|
959 | 952 | return len; |
---|
960 | 953 | } |
---|
961 | 954 | |
---|
962 | 955 | static IIO_DEVICE_ATTR(update_DAC, 0644, |
---|
963 | | - NULL, |
---|
964 | | - adt7316_store_update_DAC, |
---|
965 | | - 0); |
---|
| 956 | + NULL, |
---|
| 957 | + adt7316_store_update_DAC, |
---|
| 958 | + 0); |
---|
966 | 959 | |
---|
967 | 960 | static ssize_t adt7316_show_DA_AB_Vref_bypass(struct device *dev, |
---|
968 | | - struct device_attribute *attr, |
---|
969 | | - char *buf) |
---|
| 961 | + struct device_attribute *attr, |
---|
| 962 | + char *buf) |
---|
970 | 963 | { |
---|
971 | 964 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
972 | 965 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
973 | | - |
---|
974 | | - if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
975 | | - return -EPERM; |
---|
976 | 966 | |
---|
977 | 967 | return sprintf(buf, "%d\n", |
---|
978 | 968 | !!(chip->dac_config & ADT7316_VREF_BYPASS_DAC_AB)); |
---|
979 | 969 | } |
---|
980 | 970 | |
---|
981 | 971 | static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev, |
---|
982 | | - struct device_attribute *attr, |
---|
983 | | - const char *buf, |
---|
984 | | - size_t len) |
---|
| 972 | + struct device_attribute *attr, |
---|
| 973 | + const char *buf, |
---|
| 974 | + size_t len) |
---|
985 | 975 | { |
---|
986 | 976 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
987 | 977 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
988 | 978 | u8 dac_config; |
---|
989 | 979 | int ret; |
---|
990 | | - |
---|
991 | | - if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
992 | | - return -EPERM; |
---|
993 | 980 | |
---|
994 | 981 | dac_config = chip->dac_config & (~ADT7316_VREF_BYPASS_DAC_AB); |
---|
995 | 982 | if (buf[0] == '1') |
---|
.. | .. |
---|
1005 | 992 | } |
---|
1006 | 993 | |
---|
1007 | 994 | static IIO_DEVICE_ATTR(DA_AB_Vref_bypass, 0644, |
---|
1008 | | - adt7316_show_DA_AB_Vref_bypass, |
---|
1009 | | - adt7316_store_DA_AB_Vref_bypass, |
---|
1010 | | - 0); |
---|
| 995 | + adt7316_show_DA_AB_Vref_bypass, |
---|
| 996 | + adt7316_store_DA_AB_Vref_bypass, |
---|
| 997 | + 0); |
---|
1011 | 998 | |
---|
1012 | 999 | static ssize_t adt7316_show_DA_CD_Vref_bypass(struct device *dev, |
---|
1013 | | - struct device_attribute *attr, |
---|
1014 | | - char *buf) |
---|
| 1000 | + struct device_attribute *attr, |
---|
| 1001 | + char *buf) |
---|
1015 | 1002 | { |
---|
1016 | 1003 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1017 | 1004 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
1018 | | - |
---|
1019 | | - if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
1020 | | - return -EPERM; |
---|
1021 | 1005 | |
---|
1022 | 1006 | return sprintf(buf, "%d\n", |
---|
1023 | 1007 | !!(chip->dac_config & ADT7316_VREF_BYPASS_DAC_CD)); |
---|
1024 | 1008 | } |
---|
1025 | 1009 | |
---|
1026 | 1010 | static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev, |
---|
1027 | | - struct device_attribute *attr, |
---|
1028 | | - const char *buf, |
---|
1029 | | - size_t len) |
---|
| 1011 | + struct device_attribute *attr, |
---|
| 1012 | + const char *buf, |
---|
| 1013 | + size_t len) |
---|
1030 | 1014 | { |
---|
1031 | 1015 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1032 | 1016 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
1033 | 1017 | u8 dac_config; |
---|
1034 | 1018 | int ret; |
---|
1035 | | - |
---|
1036 | | - if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
1037 | | - return -EPERM; |
---|
1038 | 1019 | |
---|
1039 | 1020 | dac_config = chip->dac_config & (~ADT7316_VREF_BYPASS_DAC_CD); |
---|
1040 | 1021 | if (buf[0] == '1') |
---|
.. | .. |
---|
1050 | 1031 | } |
---|
1051 | 1032 | |
---|
1052 | 1033 | static IIO_DEVICE_ATTR(DA_CD_Vref_bypass, 0644, |
---|
1053 | | - adt7316_show_DA_CD_Vref_bypass, |
---|
1054 | | - adt7316_store_DA_CD_Vref_bypass, |
---|
1055 | | - 0); |
---|
| 1034 | + adt7316_show_DA_CD_Vref_bypass, |
---|
| 1035 | + adt7316_store_DA_CD_Vref_bypass, |
---|
| 1036 | + 0); |
---|
1056 | 1037 | |
---|
1057 | 1038 | static ssize_t adt7316_show_DAC_internal_Vref(struct device *dev, |
---|
1058 | | - struct device_attribute *attr, |
---|
1059 | | - char *buf) |
---|
| 1039 | + struct device_attribute *attr, |
---|
| 1040 | + char *buf) |
---|
1060 | 1041 | { |
---|
1061 | 1042 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1062 | 1043 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
1063 | 1044 | |
---|
1064 | 1045 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
1065 | 1046 | return sprintf(buf, "0x%x\n", |
---|
1066 | | - (chip->dac_config & ADT7516_DAC_IN_VREF_MASK) >> |
---|
| 1047 | + (chip->ldac_config & ADT7516_DAC_IN_VREF_MASK) >> |
---|
1067 | 1048 | ADT7516_DAC_IN_VREF_OFFSET); |
---|
1068 | 1049 | return sprintf(buf, "%d\n", |
---|
1069 | | - !!(chip->dac_config & ADT7316_DAC_IN_VREF)); |
---|
| 1050 | + !!(chip->ldac_config & ADT7316_DAC_IN_VREF)); |
---|
1070 | 1051 | } |
---|
1071 | 1052 | |
---|
1072 | 1053 | static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev, |
---|
1073 | | - struct device_attribute *attr, |
---|
1074 | | - const char *buf, |
---|
1075 | | - size_t len) |
---|
| 1054 | + struct device_attribute *attr, |
---|
| 1055 | + const char *buf, |
---|
| 1056 | + size_t len) |
---|
1076 | 1057 | { |
---|
1077 | 1058 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1078 | 1059 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1111 | 1092 | } |
---|
1112 | 1093 | |
---|
1113 | 1094 | static IIO_DEVICE_ATTR(DAC_internal_Vref, 0644, |
---|
1114 | | - adt7316_show_DAC_internal_Vref, |
---|
1115 | | - adt7316_store_DAC_internal_Vref, |
---|
1116 | | - 0); |
---|
| 1095 | + adt7316_show_DAC_internal_Vref, |
---|
| 1096 | + adt7316_store_DAC_internal_Vref, |
---|
| 1097 | + 0); |
---|
1117 | 1098 | |
---|
1118 | 1099 | static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip, |
---|
1119 | | - int channel, char *buf) |
---|
| 1100 | + int channel, char *buf) |
---|
1120 | 1101 | { |
---|
1121 | 1102 | u16 data; |
---|
1122 | 1103 | u8 msb, lsb; |
---|
.. | .. |
---|
1124 | 1105 | int ret; |
---|
1125 | 1106 | |
---|
1126 | 1107 | if ((chip->config2 & ADT7316_AD_SINGLE_CH_MODE) && |
---|
1127 | | - channel != (chip->config2 & ADT7516_AD_SINGLE_CH_MASK)) |
---|
| 1108 | + channel != (chip->config2 & ADT7516_AD_SINGLE_CH_MASK)) |
---|
1128 | 1109 | return -EPERM; |
---|
1129 | 1110 | |
---|
1130 | 1111 | switch (channel) { |
---|
.. | .. |
---|
1191 | 1172 | } |
---|
1192 | 1173 | |
---|
1193 | 1174 | static ssize_t adt7316_show_VDD(struct device *dev, |
---|
1194 | | - struct device_attribute *attr, |
---|
1195 | | - char *buf) |
---|
| 1175 | + struct device_attribute *attr, |
---|
| 1176 | + char *buf) |
---|
1196 | 1177 | { |
---|
1197 | 1178 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1198 | 1179 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1202 | 1183 | static IIO_DEVICE_ATTR(VDD, 0444, adt7316_show_VDD, NULL, 0); |
---|
1203 | 1184 | |
---|
1204 | 1185 | static ssize_t adt7316_show_in_temp(struct device *dev, |
---|
1205 | | - struct device_attribute *attr, |
---|
1206 | | - char *buf) |
---|
| 1186 | + struct device_attribute *attr, |
---|
| 1187 | + char *buf) |
---|
1207 | 1188 | { |
---|
1208 | 1189 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1209 | 1190 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1214 | 1195 | static IIO_DEVICE_ATTR(in_temp, 0444, adt7316_show_in_temp, NULL, 0); |
---|
1215 | 1196 | |
---|
1216 | 1197 | static ssize_t adt7316_show_ex_temp_AIN1(struct device *dev, |
---|
1217 | | - struct device_attribute *attr, |
---|
1218 | | - char *buf) |
---|
| 1198 | + struct device_attribute *attr, |
---|
| 1199 | + char *buf) |
---|
1219 | 1200 | { |
---|
1220 | 1201 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1221 | 1202 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1224 | 1205 | } |
---|
1225 | 1206 | |
---|
1226 | 1207 | static IIO_DEVICE_ATTR(ex_temp_AIN1, 0444, adt7316_show_ex_temp_AIN1, |
---|
1227 | | - NULL, 0); |
---|
| 1208 | + NULL, 0); |
---|
1228 | 1209 | static IIO_DEVICE_ATTR(ex_temp, 0444, adt7316_show_ex_temp_AIN1, NULL, 0); |
---|
1229 | 1210 | |
---|
1230 | 1211 | static ssize_t adt7316_show_AIN2(struct device *dev, |
---|
1231 | | - struct device_attribute *attr, |
---|
1232 | | - char *buf) |
---|
| 1212 | + struct device_attribute *attr, |
---|
| 1213 | + char *buf) |
---|
1233 | 1214 | { |
---|
1234 | 1215 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1235 | 1216 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1239 | 1220 | static IIO_DEVICE_ATTR(AIN2, 0444, adt7316_show_AIN2, NULL, 0); |
---|
1240 | 1221 | |
---|
1241 | 1222 | static ssize_t adt7316_show_AIN3(struct device *dev, |
---|
1242 | | - struct device_attribute *attr, |
---|
1243 | | - char *buf) |
---|
| 1223 | + struct device_attribute *attr, |
---|
| 1224 | + char *buf) |
---|
1244 | 1225 | { |
---|
1245 | 1226 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1246 | 1227 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1250 | 1231 | static IIO_DEVICE_ATTR(AIN3, 0444, adt7316_show_AIN3, NULL, 0); |
---|
1251 | 1232 | |
---|
1252 | 1233 | static ssize_t adt7316_show_AIN4(struct device *dev, |
---|
1253 | | - struct device_attribute *attr, |
---|
1254 | | - char *buf) |
---|
| 1234 | + struct device_attribute *attr, |
---|
| 1235 | + char *buf) |
---|
1255 | 1236 | { |
---|
1256 | 1237 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1257 | 1238 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1261 | 1242 | static IIO_DEVICE_ATTR(AIN4, 0444, adt7316_show_AIN4, NULL, 0); |
---|
1262 | 1243 | |
---|
1263 | 1244 | static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip, |
---|
1264 | | - int offset_addr, char *buf) |
---|
| 1245 | + int offset_addr, char *buf) |
---|
1265 | 1246 | { |
---|
1266 | 1247 | int data; |
---|
1267 | 1248 | u8 val; |
---|
.. | .. |
---|
1279 | 1260 | } |
---|
1280 | 1261 | |
---|
1281 | 1262 | static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip, |
---|
1282 | | - int offset_addr, const char *buf, size_t len) |
---|
| 1263 | + int offset_addr, |
---|
| 1264 | + const char *buf, |
---|
| 1265 | + size_t len) |
---|
1283 | 1266 | { |
---|
1284 | 1267 | int data; |
---|
1285 | 1268 | u8 val; |
---|
.. | .. |
---|
1302 | 1285 | } |
---|
1303 | 1286 | |
---|
1304 | 1287 | static ssize_t adt7316_show_in_temp_offset(struct device *dev, |
---|
1305 | | - struct device_attribute *attr, |
---|
1306 | | - char *buf) |
---|
| 1288 | + struct device_attribute *attr, |
---|
| 1289 | + char *buf) |
---|
1307 | 1290 | { |
---|
1308 | 1291 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1309 | 1292 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1312 | 1295 | } |
---|
1313 | 1296 | |
---|
1314 | 1297 | static ssize_t adt7316_store_in_temp_offset(struct device *dev, |
---|
1315 | | - struct device_attribute *attr, |
---|
1316 | | - const char *buf, |
---|
1317 | | - size_t len) |
---|
| 1298 | + struct device_attribute *attr, |
---|
| 1299 | + const char *buf, |
---|
| 1300 | + size_t len) |
---|
1318 | 1301 | { |
---|
1319 | 1302 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1320 | 1303 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1324 | 1307 | } |
---|
1325 | 1308 | |
---|
1326 | 1309 | static IIO_DEVICE_ATTR(in_temp_offset, 0644, |
---|
1327 | | - adt7316_show_in_temp_offset, |
---|
1328 | | - adt7316_store_in_temp_offset, 0); |
---|
| 1310 | + adt7316_show_in_temp_offset, |
---|
| 1311 | + adt7316_store_in_temp_offset, 0); |
---|
1329 | 1312 | |
---|
1330 | 1313 | static ssize_t adt7316_show_ex_temp_offset(struct device *dev, |
---|
1331 | | - struct device_attribute *attr, |
---|
1332 | | - char *buf) |
---|
| 1314 | + struct device_attribute *attr, |
---|
| 1315 | + char *buf) |
---|
1333 | 1316 | { |
---|
1334 | 1317 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1335 | 1318 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1338 | 1321 | } |
---|
1339 | 1322 | |
---|
1340 | 1323 | static ssize_t adt7316_store_ex_temp_offset(struct device *dev, |
---|
1341 | | - struct device_attribute *attr, |
---|
1342 | | - const char *buf, |
---|
1343 | | - size_t len) |
---|
| 1324 | + struct device_attribute *attr, |
---|
| 1325 | + const char *buf, |
---|
| 1326 | + size_t len) |
---|
1344 | 1327 | { |
---|
1345 | 1328 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1346 | 1329 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1350 | 1333 | } |
---|
1351 | 1334 | |
---|
1352 | 1335 | static IIO_DEVICE_ATTR(ex_temp_offset, 0644, |
---|
1353 | | - adt7316_show_ex_temp_offset, |
---|
1354 | | - adt7316_store_ex_temp_offset, 0); |
---|
| 1336 | + adt7316_show_ex_temp_offset, |
---|
| 1337 | + adt7316_store_ex_temp_offset, 0); |
---|
1355 | 1338 | |
---|
1356 | 1339 | static ssize_t adt7316_show_in_analog_temp_offset(struct device *dev, |
---|
1357 | | - struct device_attribute *attr, |
---|
1358 | | - char *buf) |
---|
| 1340 | + struct device_attribute *attr, |
---|
| 1341 | + char *buf) |
---|
1359 | 1342 | { |
---|
1360 | 1343 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1361 | 1344 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1365 | 1348 | } |
---|
1366 | 1349 | |
---|
1367 | 1350 | static ssize_t adt7316_store_in_analog_temp_offset(struct device *dev, |
---|
1368 | | - struct device_attribute *attr, |
---|
1369 | | - const char *buf, |
---|
1370 | | - size_t len) |
---|
| 1351 | + struct device_attribute *attr, |
---|
| 1352 | + const char *buf, |
---|
| 1353 | + size_t len) |
---|
1371 | 1354 | { |
---|
1372 | 1355 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1373 | 1356 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1377 | 1360 | } |
---|
1378 | 1361 | |
---|
1379 | 1362 | static IIO_DEVICE_ATTR(in_analog_temp_offset, 0644, |
---|
1380 | | - adt7316_show_in_analog_temp_offset, |
---|
1381 | | - adt7316_store_in_analog_temp_offset, 0); |
---|
| 1363 | + adt7316_show_in_analog_temp_offset, |
---|
| 1364 | + adt7316_store_in_analog_temp_offset, 0); |
---|
1382 | 1365 | |
---|
1383 | 1366 | static ssize_t adt7316_show_ex_analog_temp_offset(struct device *dev, |
---|
1384 | | - struct device_attribute *attr, |
---|
1385 | | - char *buf) |
---|
| 1367 | + struct device_attribute *attr, |
---|
| 1368 | + char *buf) |
---|
1386 | 1369 | { |
---|
1387 | 1370 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1388 | 1371 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1392 | 1375 | } |
---|
1393 | 1376 | |
---|
1394 | 1377 | static ssize_t adt7316_store_ex_analog_temp_offset(struct device *dev, |
---|
1395 | | - struct device_attribute *attr, |
---|
1396 | | - const char *buf, |
---|
1397 | | - size_t len) |
---|
| 1378 | + struct device_attribute *attr, |
---|
| 1379 | + const char *buf, |
---|
| 1380 | + size_t len) |
---|
1398 | 1381 | { |
---|
1399 | 1382 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1400 | 1383 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1404 | 1387 | } |
---|
1405 | 1388 | |
---|
1406 | 1389 | static IIO_DEVICE_ATTR(ex_analog_temp_offset, 0644, |
---|
1407 | | - adt7316_show_ex_analog_temp_offset, |
---|
1408 | | - adt7316_store_ex_analog_temp_offset, 0); |
---|
| 1390 | + adt7316_show_ex_analog_temp_offset, |
---|
| 1391 | + adt7316_store_ex_analog_temp_offset, 0); |
---|
1409 | 1392 | |
---|
1410 | 1393 | static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, |
---|
1411 | | - int channel, char *buf) |
---|
| 1394 | + int channel, char *buf) |
---|
1412 | 1395 | { |
---|
1413 | 1396 | u16 data = 0; |
---|
1414 | 1397 | u8 msb, lsb, offset; |
---|
1415 | 1398 | int ret; |
---|
1416 | 1399 | |
---|
1417 | 1400 | if (channel >= ADT7316_DA_MSB_DATA_REGS || |
---|
1418 | | - (channel == 0 && |
---|
1419 | | - (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || |
---|
1420 | | - (channel == 1 && |
---|
1421 | | - (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) |
---|
| 1401 | + (channel == 0 && |
---|
| 1402 | + (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || |
---|
| 1403 | + (channel == 1 && |
---|
| 1404 | + (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) |
---|
1422 | 1405 | return -EPERM; |
---|
1423 | 1406 | |
---|
1424 | 1407 | offset = chip->dac_bits - 8; |
---|
.. | .. |
---|
1445 | 1428 | } |
---|
1446 | 1429 | |
---|
1447 | 1430 | static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, |
---|
1448 | | - int channel, const char *buf, size_t len) |
---|
| 1431 | + int channel, const char *buf, size_t len) |
---|
1449 | 1432 | { |
---|
1450 | 1433 | u8 msb, lsb, lsb_reg, offset; |
---|
1451 | 1434 | u16 data; |
---|
1452 | 1435 | int ret; |
---|
1453 | 1436 | |
---|
1454 | 1437 | if (channel >= ADT7316_DA_MSB_DATA_REGS || |
---|
1455 | | - (channel == 0 && |
---|
1456 | | - (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || |
---|
1457 | | - (channel == 1 && |
---|
1458 | | - (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) |
---|
| 1438 | + (channel == 0 && |
---|
| 1439 | + (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || |
---|
| 1440 | + (channel == 1 && |
---|
| 1441 | + (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) |
---|
1459 | 1442 | return -EPERM; |
---|
1460 | 1443 | |
---|
1461 | 1444 | offset = chip->dac_bits - 8; |
---|
.. | .. |
---|
1486 | 1469 | } |
---|
1487 | 1470 | |
---|
1488 | 1471 | static ssize_t adt7316_show_DAC_A(struct device *dev, |
---|
1489 | | - struct device_attribute *attr, |
---|
1490 | | - char *buf) |
---|
| 1472 | + struct device_attribute *attr, |
---|
| 1473 | + char *buf) |
---|
1491 | 1474 | { |
---|
1492 | 1475 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1493 | 1476 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1496 | 1479 | } |
---|
1497 | 1480 | |
---|
1498 | 1481 | static ssize_t adt7316_store_DAC_A(struct device *dev, |
---|
1499 | | - struct device_attribute *attr, |
---|
1500 | | - const char *buf, |
---|
1501 | | - size_t len) |
---|
| 1482 | + struct device_attribute *attr, |
---|
| 1483 | + const char *buf, |
---|
| 1484 | + size_t len) |
---|
1502 | 1485 | { |
---|
1503 | 1486 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1504 | 1487 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1507 | 1490 | } |
---|
1508 | 1491 | |
---|
1509 | 1492 | static IIO_DEVICE_ATTR(DAC_A, 0644, adt7316_show_DAC_A, |
---|
1510 | | - adt7316_store_DAC_A, 0); |
---|
| 1493 | + adt7316_store_DAC_A, 0); |
---|
1511 | 1494 | |
---|
1512 | 1495 | static ssize_t adt7316_show_DAC_B(struct device *dev, |
---|
1513 | | - struct device_attribute *attr, |
---|
1514 | | - char *buf) |
---|
| 1496 | + struct device_attribute *attr, |
---|
| 1497 | + char *buf) |
---|
1515 | 1498 | { |
---|
1516 | 1499 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1517 | 1500 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1520 | 1503 | } |
---|
1521 | 1504 | |
---|
1522 | 1505 | static ssize_t adt7316_store_DAC_B(struct device *dev, |
---|
1523 | | - struct device_attribute *attr, |
---|
1524 | | - const char *buf, |
---|
1525 | | - size_t len) |
---|
| 1506 | + struct device_attribute *attr, |
---|
| 1507 | + const char *buf, |
---|
| 1508 | + size_t len) |
---|
1526 | 1509 | { |
---|
1527 | 1510 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1528 | 1511 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1531 | 1514 | } |
---|
1532 | 1515 | |
---|
1533 | 1516 | static IIO_DEVICE_ATTR(DAC_B, 0644, adt7316_show_DAC_B, |
---|
1534 | | - adt7316_store_DAC_B, 0); |
---|
| 1517 | + adt7316_store_DAC_B, 0); |
---|
1535 | 1518 | |
---|
1536 | 1519 | static ssize_t adt7316_show_DAC_C(struct device *dev, |
---|
1537 | | - struct device_attribute *attr, |
---|
1538 | | - char *buf) |
---|
| 1520 | + struct device_attribute *attr, |
---|
| 1521 | + char *buf) |
---|
1539 | 1522 | { |
---|
1540 | 1523 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1541 | 1524 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1544 | 1527 | } |
---|
1545 | 1528 | |
---|
1546 | 1529 | static ssize_t adt7316_store_DAC_C(struct device *dev, |
---|
1547 | | - struct device_attribute *attr, |
---|
1548 | | - const char *buf, |
---|
1549 | | - size_t len) |
---|
| 1530 | + struct device_attribute *attr, |
---|
| 1531 | + const char *buf, |
---|
| 1532 | + size_t len) |
---|
1550 | 1533 | { |
---|
1551 | 1534 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1552 | 1535 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1555 | 1538 | } |
---|
1556 | 1539 | |
---|
1557 | 1540 | static IIO_DEVICE_ATTR(DAC_C, 0644, adt7316_show_DAC_C, |
---|
1558 | | - adt7316_store_DAC_C, 0); |
---|
| 1541 | + adt7316_store_DAC_C, 0); |
---|
1559 | 1542 | |
---|
1560 | 1543 | static ssize_t adt7316_show_DAC_D(struct device *dev, |
---|
1561 | | - struct device_attribute *attr, |
---|
1562 | | - char *buf) |
---|
| 1544 | + struct device_attribute *attr, |
---|
| 1545 | + char *buf) |
---|
1563 | 1546 | { |
---|
1564 | 1547 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1565 | 1548 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1568 | 1551 | } |
---|
1569 | 1552 | |
---|
1570 | 1553 | static ssize_t adt7316_store_DAC_D(struct device *dev, |
---|
1571 | | - struct device_attribute *attr, |
---|
1572 | | - const char *buf, |
---|
1573 | | - size_t len) |
---|
| 1554 | + struct device_attribute *attr, |
---|
| 1555 | + const char *buf, |
---|
| 1556 | + size_t len) |
---|
1574 | 1557 | { |
---|
1575 | 1558 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1576 | 1559 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1579 | 1562 | } |
---|
1580 | 1563 | |
---|
1581 | 1564 | static IIO_DEVICE_ATTR(DAC_D, 0644, adt7316_show_DAC_D, |
---|
1582 | | - adt7316_store_DAC_D, 0); |
---|
| 1565 | + adt7316_store_DAC_D, 0); |
---|
1583 | 1566 | |
---|
1584 | 1567 | static ssize_t adt7316_show_device_id(struct device *dev, |
---|
1585 | | - struct device_attribute *attr, |
---|
1586 | | - char *buf) |
---|
| 1568 | + struct device_attribute *attr, |
---|
| 1569 | + char *buf) |
---|
1587 | 1570 | { |
---|
1588 | 1571 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1589 | 1572 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1600 | 1583 | static IIO_DEVICE_ATTR(device_id, 0444, adt7316_show_device_id, NULL, 0); |
---|
1601 | 1584 | |
---|
1602 | 1585 | static ssize_t adt7316_show_manufactorer_id(struct device *dev, |
---|
1603 | | - struct device_attribute *attr, |
---|
1604 | | - char *buf) |
---|
| 1586 | + struct device_attribute *attr, |
---|
| 1587 | + char *buf) |
---|
1605 | 1588 | { |
---|
1606 | 1589 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1607 | 1590 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1616 | 1599 | } |
---|
1617 | 1600 | |
---|
1618 | 1601 | static IIO_DEVICE_ATTR(manufactorer_id, 0444, |
---|
1619 | | - adt7316_show_manufactorer_id, NULL, 0); |
---|
| 1602 | + adt7316_show_manufactorer_id, NULL, 0); |
---|
1620 | 1603 | |
---|
1621 | 1604 | static ssize_t adt7316_show_device_rev(struct device *dev, |
---|
1622 | | - struct device_attribute *attr, |
---|
1623 | | - char *buf) |
---|
| 1605 | + struct device_attribute *attr, |
---|
| 1606 | + char *buf) |
---|
1624 | 1607 | { |
---|
1625 | 1608 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1626 | 1609 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1637 | 1620 | static IIO_DEVICE_ATTR(device_rev, 0444, adt7316_show_device_rev, NULL, 0); |
---|
1638 | 1621 | |
---|
1639 | 1622 | static ssize_t adt7316_show_bus_type(struct device *dev, |
---|
1640 | | - struct device_attribute *attr, |
---|
1641 | | - char *buf) |
---|
| 1623 | + struct device_attribute *attr, |
---|
| 1624 | + char *buf) |
---|
1642 | 1625 | { |
---|
1643 | 1626 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1644 | 1627 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1718 | 1701 | &iio_dev_attr_DAC_update_mode.dev_attr.attr, |
---|
1719 | 1702 | &iio_dev_attr_all_DAC_update_modes.dev_attr.attr, |
---|
1720 | 1703 | &iio_dev_attr_update_DAC.dev_attr.attr, |
---|
1721 | | - &iio_dev_attr_DA_AB_Vref_bypass.dev_attr.attr, |
---|
1722 | | - &iio_dev_attr_DA_CD_Vref_bypass.dev_attr.attr, |
---|
1723 | 1704 | &iio_dev_attr_DAC_internal_Vref.dev_attr.attr, |
---|
1724 | 1705 | &iio_dev_attr_VDD.dev_attr.attr, |
---|
1725 | 1706 | &iio_dev_attr_in_temp.dev_attr.attr, |
---|
.. | .. |
---|
1817 | 1798 | return IRQ_HANDLED; |
---|
1818 | 1799 | } |
---|
1819 | 1800 | |
---|
| 1801 | +static int adt7316_setup_irq(struct iio_dev *indio_dev) |
---|
| 1802 | +{ |
---|
| 1803 | + struct adt7316_chip_info *chip = iio_priv(indio_dev); |
---|
| 1804 | + int irq_type, ret; |
---|
| 1805 | + |
---|
| 1806 | + irq_type = irqd_get_trigger_type(irq_get_irq_data(chip->bus.irq)); |
---|
| 1807 | + |
---|
| 1808 | + switch (irq_type) { |
---|
| 1809 | + case IRQF_TRIGGER_HIGH: |
---|
| 1810 | + case IRQF_TRIGGER_RISING: |
---|
| 1811 | + break; |
---|
| 1812 | + case IRQF_TRIGGER_LOW: |
---|
| 1813 | + case IRQF_TRIGGER_FALLING: |
---|
| 1814 | + break; |
---|
| 1815 | + default: |
---|
| 1816 | + dev_info(&indio_dev->dev, "mode %d unsupported, using IRQF_TRIGGER_LOW\n", |
---|
| 1817 | + irq_type); |
---|
| 1818 | + irq_type = IRQF_TRIGGER_LOW; |
---|
| 1819 | + break; |
---|
| 1820 | + } |
---|
| 1821 | + |
---|
| 1822 | + ret = devm_request_threaded_irq(&indio_dev->dev, chip->bus.irq, |
---|
| 1823 | + NULL, adt7316_event_handler, |
---|
| 1824 | + irq_type | IRQF_ONESHOT, |
---|
| 1825 | + indio_dev->name, indio_dev); |
---|
| 1826 | + if (ret) { |
---|
| 1827 | + dev_err(&indio_dev->dev, "failed to request irq %d\n", |
---|
| 1828 | + chip->bus.irq); |
---|
| 1829 | + return ret; |
---|
| 1830 | + } |
---|
| 1831 | + |
---|
| 1832 | + if (irq_type & IRQF_TRIGGER_HIGH) |
---|
| 1833 | + chip->config1 |= ADT7316_INT_POLARITY; |
---|
| 1834 | + |
---|
| 1835 | + return 0; |
---|
| 1836 | +} |
---|
| 1837 | + |
---|
1820 | 1838 | /* |
---|
1821 | 1839 | * Show mask of enabled interrupts in Hex. |
---|
1822 | 1840 | */ |
---|
1823 | 1841 | static ssize_t adt7316_show_int_mask(struct device *dev, |
---|
1824 | | - struct device_attribute *attr, |
---|
1825 | | - char *buf) |
---|
| 1842 | + struct device_attribute *attr, |
---|
| 1843 | + char *buf) |
---|
1826 | 1844 | { |
---|
1827 | 1845 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1828 | 1846 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1834 | 1852 | * Set 1 to the mask in Hex to enabled interrupts. |
---|
1835 | 1853 | */ |
---|
1836 | 1854 | static ssize_t adt7316_set_int_mask(struct device *dev, |
---|
1837 | | - struct device_attribute *attr, |
---|
1838 | | - const char *buf, |
---|
1839 | | - size_t len) |
---|
| 1855 | + struct device_attribute *attr, |
---|
| 1856 | + const char *buf, |
---|
| 1857 | + size_t len) |
---|
1840 | 1858 | { |
---|
1841 | 1859 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1842 | 1860 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1875 | 1893 | } |
---|
1876 | 1894 | |
---|
1877 | 1895 | static inline ssize_t adt7316_show_ad_bound(struct device *dev, |
---|
1878 | | - struct device_attribute *attr, |
---|
1879 | | - char *buf) |
---|
| 1896 | + struct device_attribute *attr, |
---|
| 1897 | + char *buf) |
---|
1880 | 1898 | { |
---|
1881 | 1899 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
---|
1882 | 1900 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
.. | .. |
---|
1886 | 1904 | int ret; |
---|
1887 | 1905 | |
---|
1888 | 1906 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX && |
---|
1889 | | - this_attr->address > ADT7316_EX_TEMP_LOW) |
---|
| 1907 | + this_attr->address > ADT7316_EX_TEMP_LOW) |
---|
1890 | 1908 | return -EPERM; |
---|
1891 | 1909 | |
---|
1892 | 1910 | ret = chip->bus.read(chip->bus.client, this_attr->address, &val); |
---|
.. | .. |
---|
1896 | 1914 | data = (int)val; |
---|
1897 | 1915 | |
---|
1898 | 1916 | if (!((chip->id & ID_FAMILY_MASK) == ID_ADT75XX && |
---|
1899 | | - (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)) { |
---|
| 1917 | + (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)) { |
---|
1900 | 1918 | if (data & 0x80) |
---|
1901 | 1919 | data -= 256; |
---|
1902 | 1920 | } |
---|
.. | .. |
---|
1905 | 1923 | } |
---|
1906 | 1924 | |
---|
1907 | 1925 | static inline ssize_t adt7316_set_ad_bound(struct device *dev, |
---|
1908 | | - struct device_attribute *attr, |
---|
1909 | | - const char *buf, |
---|
1910 | | - size_t len) |
---|
| 1926 | + struct device_attribute *attr, |
---|
| 1927 | + const char *buf, |
---|
| 1928 | + size_t len) |
---|
1911 | 1929 | { |
---|
1912 | 1930 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
---|
1913 | 1931 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
.. | .. |
---|
1917 | 1935 | int ret; |
---|
1918 | 1936 | |
---|
1919 | 1937 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX && |
---|
1920 | | - this_attr->address > ADT7316_EX_TEMP_LOW) |
---|
| 1938 | + this_attr->address > ADT7316_EX_TEMP_LOW) |
---|
1921 | 1939 | return -EPERM; |
---|
1922 | 1940 | |
---|
1923 | 1941 | ret = kstrtoint(buf, 10, &data); |
---|
.. | .. |
---|
1925 | 1943 | return -EINVAL; |
---|
1926 | 1944 | |
---|
1927 | 1945 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX && |
---|
1928 | | - (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) { |
---|
| 1946 | + (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) { |
---|
1929 | 1947 | if (data > 255 || data < 0) |
---|
1930 | 1948 | return -EINVAL; |
---|
1931 | 1949 | } else { |
---|
.. | .. |
---|
1946 | 1964 | } |
---|
1947 | 1965 | |
---|
1948 | 1966 | static ssize_t adt7316_show_int_enabled(struct device *dev, |
---|
1949 | | - struct device_attribute *attr, |
---|
1950 | | - char *buf) |
---|
| 1967 | + struct device_attribute *attr, |
---|
| 1968 | + char *buf) |
---|
1951 | 1969 | { |
---|
1952 | 1970 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1953 | 1971 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
1956 | 1974 | } |
---|
1957 | 1975 | |
---|
1958 | 1976 | static ssize_t adt7316_set_int_enabled(struct device *dev, |
---|
1959 | | - struct device_attribute *attr, |
---|
1960 | | - const char *buf, |
---|
1961 | | - size_t len) |
---|
| 1977 | + struct device_attribute *attr, |
---|
| 1978 | + const char *buf, |
---|
| 1979 | + size_t len) |
---|
1962 | 1980 | { |
---|
1963 | 1981 | struct iio_dev *dev_info = dev_to_iio_dev(dev); |
---|
1964 | 1982 | struct adt7316_chip_info *chip = iio_priv(dev_info); |
---|
.. | .. |
---|
2107 | 2125 | * device probe and remove |
---|
2108 | 2126 | */ |
---|
2109 | 2127 | int adt7316_probe(struct device *dev, struct adt7316_bus *bus, |
---|
2110 | | - const char *name) |
---|
| 2128 | + const char *name) |
---|
2111 | 2129 | { |
---|
2112 | 2130 | struct adt7316_chip_info *chip; |
---|
2113 | 2131 | struct iio_dev *indio_dev; |
---|
2114 | | - unsigned short *adt7316_platform_data = dev->platform_data; |
---|
2115 | | - int ret = 0; |
---|
| 2132 | + int ret; |
---|
2116 | 2133 | |
---|
2117 | 2134 | indio_dev = devm_iio_device_alloc(dev, sizeof(*chip)); |
---|
2118 | 2135 | if (!indio_dev) |
---|
.. | .. |
---|
2130 | 2147 | else |
---|
2131 | 2148 | return -ENODEV; |
---|
2132 | 2149 | |
---|
2133 | | - chip->ldac_pin = adt7316_platform_data[1]; |
---|
2134 | | - if (chip->ldac_pin) { |
---|
2135 | | - chip->config3 |= ADT7316_DA_EN_VIA_DAC_LDCA; |
---|
| 2150 | + if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516) |
---|
| 2151 | + chip->dac_bits = 12; |
---|
| 2152 | + else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) |
---|
| 2153 | + chip->dac_bits = 10; |
---|
| 2154 | + else |
---|
| 2155 | + chip->dac_bits = 8; |
---|
| 2156 | + |
---|
| 2157 | + chip->ldac_pin = devm_gpiod_get_optional(dev, "adi,ldac", |
---|
| 2158 | + GPIOD_OUT_LOW); |
---|
| 2159 | + if (IS_ERR(chip->ldac_pin)) { |
---|
| 2160 | + ret = PTR_ERR(chip->ldac_pin); |
---|
| 2161 | + dev_err(dev, "Failed to request ldac GPIO: %d\n", ret); |
---|
| 2162 | + return ret; |
---|
| 2163 | + } |
---|
| 2164 | + |
---|
| 2165 | + if (!chip->ldac_pin) { |
---|
| 2166 | + chip->config3 |= ADT7316_DA_EN_VIA_DAC_LDAC; |
---|
2136 | 2167 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
2137 | 2168 | chip->config1 |= ADT7516_SEL_AIN3; |
---|
2138 | 2169 | } |
---|
.. | .. |
---|
2140 | 2171 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
2141 | 2172 | chip->int_mask |= ADT7516_AIN_INT_MASK; |
---|
2142 | 2173 | |
---|
2143 | | - indio_dev->dev.parent = dev; |
---|
2144 | 2174 | if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) |
---|
2145 | 2175 | indio_dev->info = &adt7516_info; |
---|
2146 | 2176 | else |
---|
.. | .. |
---|
2149 | 2179 | indio_dev->modes = INDIO_DIRECT_MODE; |
---|
2150 | 2180 | |
---|
2151 | 2181 | if (chip->bus.irq > 0) { |
---|
2152 | | - if (adt7316_platform_data[0]) |
---|
2153 | | - chip->bus.irq_flags = adt7316_platform_data[0]; |
---|
2154 | | - |
---|
2155 | | - ret = devm_request_threaded_irq(dev, chip->bus.irq, |
---|
2156 | | - NULL, |
---|
2157 | | - adt7316_event_handler, |
---|
2158 | | - chip->bus.irq_flags | |
---|
2159 | | - IRQF_ONESHOT, |
---|
2160 | | - indio_dev->name, |
---|
2161 | | - indio_dev); |
---|
| 2182 | + ret = adt7316_setup_irq(indio_dev); |
---|
2162 | 2183 | if (ret) |
---|
2163 | 2184 | return ret; |
---|
2164 | | - |
---|
2165 | | - if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH) |
---|
2166 | | - chip->config1 |= ADT7316_INT_POLARITY; |
---|
2167 | 2185 | } |
---|
2168 | 2186 | |
---|
2169 | 2187 | ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1); |
---|
.. | .. |
---|
2179 | 2197 | return ret; |
---|
2180 | 2198 | |
---|
2181 | 2199 | dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n", |
---|
2182 | | - indio_dev->name); |
---|
| 2200 | + indio_dev->name); |
---|
2183 | 2201 | |
---|
2184 | 2202 | return 0; |
---|
2185 | 2203 | } |
---|