Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: update ad7779 to use IIO backend

Add a new functionality to ad7779 driver that streams data through data
output interface using IIO backend interface.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
Link: https://patch.msgid.link/20250825221355.6214-5-Ioana.Risteiu@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Ioana Risteiu and committed by
Jonathan Cameron
16647eff 2ca33c50

+108 -1
+1
drivers/iio/adc/Kconfig
··· 389 389 depends on SPI 390 390 select CRC8 391 391 select IIO_BUFFER 392 + select IIO_BACKEND 392 393 help 393 394 Say yes here to build support for Analog Devices AD777X family 394 395 (AD7770, AD7771, AD7779) analog to digital converter (ADC).
+107 -1
drivers/iio/adc/ad7779.c
··· 25 25 #include <linux/units.h> 26 26 27 27 #include <linux/iio/iio.h> 28 + #include <linux/iio/backend.h> 28 29 #include <linux/iio/buffer.h> 29 30 #include <linux/iio/sysfs.h> 30 31 #include <linux/iio/trigger.h> ··· 146 145 struct completion completion; 147 146 unsigned int sampling_freq; 148 147 enum ad7779_filter filter_enabled; 148 + struct iio_backend *back; 149 149 /* 150 150 * DMA (thus cache coherency maintenance) requires the 151 151 * transfer buffers to live in their own cache lines. ··· 632 630 return ret; 633 631 } 634 632 633 + static int ad7779_update_scan_mode(struct iio_dev *indio_dev, 634 + const unsigned long *scan_mask) 635 + { 636 + struct ad7779_state *st = iio_priv(indio_dev); 637 + unsigned int c; 638 + int ret; 639 + 640 + for (c = 0; c < AD7779_NUM_CHANNELS; c++) { 641 + if (test_bit(c, scan_mask)) 642 + ret = iio_backend_chan_enable(st->back, c); 643 + else 644 + ret = iio_backend_chan_disable(st->back, c); 645 + if (ret) 646 + return ret; 647 + } 648 + 649 + return 0; 650 + } 651 + 635 652 static const struct iio_info ad7779_info = { 636 653 .read_raw = ad7779_read_raw, 637 654 .write_raw = ad7779_write_raw, 638 655 .debugfs_reg_access = &ad7779_reg_access, 656 + }; 657 + 658 + static const struct iio_info ad7779_info_data = { 659 + .read_raw = ad7779_read_raw, 660 + .write_raw = ad7779_write_raw, 661 + .debugfs_reg_access = &ad7779_reg_access, 662 + .update_scan_mode = &ad7779_update_scan_mode, 639 663 }; 640 664 641 665 static const struct iio_enum ad7779_filter_enum = { ··· 780 752 return 0; 781 753 } 782 754 755 + static int ad7779_set_data_lines(struct iio_dev *indio_dev, u32 num_lanes) 756 + { 757 + struct ad7779_state *st = iio_priv(indio_dev); 758 + int ret; 759 + 760 + if (num_lanes != 1 && num_lanes != 2 && num_lanes != 4) 761 + return -EINVAL; 762 + 763 + ret = ad7779_set_sampling_frequency(st, num_lanes * AD7779_DEFAULT_SAMPLING_1LINE); 764 + if (ret) 765 + return ret; 766 + 767 + ret = iio_backend_num_lanes_set(st->back, num_lanes); 768 + if (ret) 769 + return ret; 770 + 771 + return ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 772 + AD7779_DOUT_FORMAT_MSK, 773 + FIELD_PREP(AD7779_DOUT_FORMAT_MSK, 2 - ilog2(num_lanes))); 774 + } 775 + 776 + static int ad7779_setup_channels(struct iio_dev *indio_dev, const struct ad7779_state *st) 777 + { 778 + struct iio_chan_spec *channels; 779 + struct device *dev = &st->spi->dev; 780 + 781 + channels = devm_kmemdup_array(dev, st->chip_info->channels, 782 + ARRAY_SIZE(ad7779_channels), 783 + sizeof(*channels), GFP_KERNEL); 784 + if (!channels) 785 + return -ENOMEM; 786 + 787 + for (unsigned int i = 0; i < ARRAY_SIZE(ad7779_channels); i++) 788 + channels[i].scan_type.endianness = IIO_CPU; 789 + 790 + indio_dev->channels = channels; 791 + indio_dev->num_channels = ARRAY_SIZE(ad7779_channels); 792 + 793 + return 0; 794 + } 795 + 783 796 static int ad7779_setup_without_backend(struct ad7779_state *st, struct iio_dev *indio_dev) 784 797 { 785 798 int ret; ··· 864 795 return ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 865 796 AD7779_DCLK_CLK_DIV_MSK, 866 797 FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7)); 798 + } 799 + 800 + static int ad7779_setup_backend(struct ad7779_state *st, struct iio_dev *indio_dev) 801 + { 802 + struct device *dev = &st->spi->dev; 803 + int ret; 804 + u32 num_lanes; 805 + 806 + indio_dev->info = &ad7779_info_data; 807 + 808 + ret = ad7779_setup_channels(indio_dev, st); 809 + if (ret) 810 + return ret; 811 + 812 + st->back = devm_iio_backend_get(dev, NULL); 813 + if (IS_ERR(st->back)) 814 + return dev_err_probe(dev, PTR_ERR(st->back), 815 + "failed to get iio backend"); 816 + 817 + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 818 + if (ret) 819 + return ret; 820 + 821 + ret = devm_iio_backend_enable(dev, st->back); 822 + if (ret) 823 + return ret; 824 + 825 + num_lanes = 4; 826 + ret = device_property_read_u32(dev, "adi,num-lanes", &num_lanes); 827 + if (ret && ret != -EINVAL) 828 + return ret; 829 + 830 + return ad7779_set_data_lines(indio_dev, num_lanes); 867 831 } 868 832 869 833 static int ad7779_probe(struct spi_device *spi) ··· 950 848 indio_dev->name = st->chip_info->name; 951 849 indio_dev->modes = INDIO_DIRECT_MODE; 952 850 953 - ret = ad7779_setup_without_backend(st, indio_dev); 851 + if (device_property_present(dev, "io-backends")) 852 + ret = ad7779_setup_backend(st, indio_dev); 853 + else 854 + ret = ad7779_setup_without_backend(st, indio_dev); 954 855 if (ret) 955 856 return ret; 956 857 ··· 1047 942 MODULE_AUTHOR("Ramona Alexandra Nechita <ramona.nechita@analog.com>"); 1048 943 MODULE_DESCRIPTION("Analog Devices AD7779 ADC"); 1049 944 MODULE_LICENSE("GPL"); 945 + MODULE_IMPORT_NS("IIO_BACKEND");