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: ad7380: do not use iio_device_claim_direct_scoped anymore

Conditionnal scoped handlers are turning out to be a real pain:
readability issues, compiler and linker handling issues among others so
rollback and remove the scoped version of iio_dvice_claim_direct_mode.

To impove code readability factorize code to set oversampling ratio.

Signed-off-by: Julien Stephan <jstephan@baylibre.com>
Link: https://patch.msgid.link/20250108-ad7380-add-alert-support-v4-1-1751802471ba@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Julien Stephan and committed by
Jonathan Cameron
39bc50e0 2014c95a

+67 -43
+67 -43
drivers/iio/adc/ad7380.c
··· 675 675 static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg, 676 676 u32 writeval, u32 *readval) 677 677 { 678 - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 679 - struct ad7380_state *st = iio_priv(indio_dev); 678 + struct ad7380_state *st = iio_priv(indio_dev); 679 + int ret; 680 680 681 - if (readval) 682 - return regmap_read(st->regmap, reg, readval); 683 - else 684 - return regmap_write(st->regmap, reg, writeval); 685 - } 686 - unreachable(); 681 + ret = iio_device_claim_direct_mode(indio_dev); 682 + if (ret) 683 + return ret; 684 + 685 + if (readval) 686 + ret = regmap_read(st->regmap, reg, readval); 687 + else 688 + ret = regmap_write(st->regmap, reg, writeval); 689 + 690 + iio_device_release_direct_mode(indio_dev); 691 + 692 + return ret; 687 693 } 688 694 689 695 /* ··· 926 920 { 927 921 struct ad7380_state *st = iio_priv(indio_dev); 928 922 const struct iio_scan_type *scan_type; 923 + int ret; 929 924 930 925 scan_type = iio_get_current_scan_type(indio_dev, chan); 931 926 ··· 935 928 936 929 switch (info) { 937 930 case IIO_CHAN_INFO_RAW: 938 - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 939 - return ad7380_read_direct(st, chan->scan_index, 940 - scan_type, val); 941 - } 942 - unreachable(); 931 + ret = iio_device_claim_direct_mode(indio_dev); 932 + if (ret) 933 + return ret; 934 + 935 + ret = ad7380_read_direct(st, chan->scan_index, 936 + scan_type, val); 937 + 938 + iio_device_release_direct_mode(indio_dev); 939 + 940 + return ret; 943 941 case IIO_CHAN_INFO_SCALE: 944 942 /* 945 943 * According to the datasheet, the LSB size is: ··· 1020 1008 return -EINVAL; 1021 1009 } 1022 1010 1011 + static int ad7380_set_oversampling_ratio(struct ad7380_state *st, int val) 1012 + { 1013 + int ret, osr, boost; 1014 + 1015 + osr = ad7380_osr_to_regval(val); 1016 + if (osr < 0) 1017 + return osr; 1018 + 1019 + /* always enable resolution boost when oversampling is enabled */ 1020 + boost = osr > 0 ? 1 : 0; 1021 + 1022 + ret = regmap_update_bits(st->regmap, 1023 + AD7380_REG_ADDR_CONFIG1, 1024 + AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES, 1025 + FIELD_PREP(AD7380_CONFIG1_OSR, osr) | 1026 + FIELD_PREP(AD7380_CONFIG1_RES, boost)); 1027 + 1028 + if (ret) 1029 + return ret; 1030 + 1031 + st->oversampling_ratio = val; 1032 + st->resolution_boost_enabled = boost; 1033 + 1034 + /* 1035 + * Perform a soft reset. This will flush the oversampling 1036 + * block and FIFO but will maintain the content of the 1037 + * configurable registers. 1038 + */ 1039 + ret = regmap_update_bits(st->regmap, 1040 + AD7380_REG_ADDR_CONFIG2, 1041 + AD7380_CONFIG2_RESET, 1042 + FIELD_PREP(AD7380_CONFIG2_RESET, 1043 + AD7380_CONFIG2_RESET_SOFT)); 1044 + return ret; 1045 + } 1023 1046 static int ad7380_write_raw(struct iio_dev *indio_dev, 1024 1047 struct iio_chan_spec const *chan, int val, 1025 1048 int val2, long mask) 1026 1049 { 1027 1050 struct ad7380_state *st = iio_priv(indio_dev); 1028 - int ret, osr, boost; 1051 + int ret; 1029 1052 1030 1053 switch (mask) { 1031 1054 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 1032 - osr = ad7380_osr_to_regval(val); 1033 - if (osr < 0) 1034 - return osr; 1055 + ret = iio_device_claim_direct_mode(indio_dev); 1056 + if (ret) 1057 + return ret; 1035 1058 1036 - /* always enable resolution boost when oversampling is enabled */ 1037 - boost = osr > 0 ? 1 : 0; 1059 + ret = ad7380_set_oversampling_ratio(st, val); 1038 1060 1039 - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 1040 - ret = regmap_update_bits(st->regmap, 1041 - AD7380_REG_ADDR_CONFIG1, 1042 - AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES, 1043 - FIELD_PREP(AD7380_CONFIG1_OSR, osr) | 1044 - FIELD_PREP(AD7380_CONFIG1_RES, boost)); 1061 + iio_device_release_direct_mode(indio_dev); 1045 1062 1046 - if (ret) 1047 - return ret; 1048 - 1049 - st->oversampling_ratio = val; 1050 - st->resolution_boost_enabled = boost; 1051 - 1052 - /* 1053 - * Perform a soft reset. This will flush the oversampling 1054 - * block and FIFO but will maintain the content of the 1055 - * configurable registers. 1056 - */ 1057 - return regmap_update_bits(st->regmap, 1058 - AD7380_REG_ADDR_CONFIG2, 1059 - AD7380_CONFIG2_RESET, 1060 - FIELD_PREP(AD7380_CONFIG2_RESET, 1061 - AD7380_CONFIG2_RESET_SOFT)); 1062 - } 1063 - unreachable(); 1063 + return ret; 1064 1064 default: 1065 1065 return -EINVAL; 1066 1066 }