[PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set

Pop Ioan Daniel posted 4 patches 7 months, 1 week ago
There is a newer version of this series
[PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
Posted by Pop Ioan Daniel 7 months, 1 week ago
In the function iio_backend_oversampling_ratio_set the chan parameter
was added. The function can be used in contexts where the channel
must be specified. All affected files have been modified.

Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
changes in v2:
 - remove iio_backend_set_dec_rate function and use 
   iio_backend_oversampling_ratio_set function
 drivers/iio/adc/ad4851.c           | 2 +-
 drivers/iio/adc/adi-axi-adc.c      | 3 ++-
 drivers/iio/industrialio-backend.c | 3 ++-
 include/linux/iio/backend.h        | 3 ++-
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/ad4851.c b/drivers/iio/adc/ad4851.c
index 98ebc853db79..a943d5aac9e5 100644
--- a/drivers/iio/adc/ad4851.c
+++ b/drivers/iio/adc/ad4851.c
@@ -321,7 +321,7 @@ static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
 			return ret;
 	}
 
-	ret = iio_backend_oversampling_ratio_set(st->back, osr);
+	ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);
 	if (ret)
 		return ret;
 
diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 4116c44197b8..9e8c30230791 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -381,7 +381,8 @@ static int axi_adc_ad485x_data_size_set(struct iio_backend *back,
 }
 
 static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
-					  unsigned int ratio)
+						 unsigned int chan,
+						 unsigned int ratio)
 {
 	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
 
diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index c1eb9ef9db08..a4e3e54fecb1 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -720,9 +720,10 @@ EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, "IIO_BACKEND");
  * 0 on success, negative error number on failure.
  */
 int iio_backend_oversampling_ratio_set(struct iio_backend *back,
+				       unsigned int chan,
 				       unsigned int ratio)
 {
-	return iio_backend_op_call(back, oversampling_ratio_set, ratio);
+	return iio_backend_op_call(back, oversampling_ratio_set, chan, ratio);
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_ratio_set, "IIO_BACKEND");
 
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index e59d909cb659..dbf4e4a5f4b1 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -144,7 +144,7 @@ struct iio_backend_ops {
 				  enum iio_backend_interface_type *type);
 	int (*data_size_set)(struct iio_backend *back, unsigned int size);
 	int (*oversampling_ratio_set)(struct iio_backend *back,
-				      unsigned int ratio);
+				      unsigned int chan, unsigned int ratio);
 	int (*read_raw)(struct iio_backend *back,
 			struct iio_chan_spec const *chan, int *val, int *val2,
 			long mask);
@@ -209,6 +209,7 @@ int iio_backend_interface_type_get(struct iio_backend *back,
 				   enum iio_backend_interface_type *type);
 int iio_backend_data_size_set(struct iio_backend *back, unsigned int size);
 int iio_backend_oversampling_ratio_set(struct iio_backend *back,
+				       unsigned int chan,
 				       unsigned int ratio);
 int iio_backend_read_raw(struct iio_backend *back,
 			 struct iio_chan_spec const *chan, int *val, int *val2,
-- 
2.34.1
Re: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
Posted by kernel test robot 7 months, 1 week ago
Hi Pop,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.15-rc5 next-20250509]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pop-Ioan-Daniel/iio-backend-update-iio_backend_oversampling_ratio_set/20250508-203339
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20250508123107.3797042-2-pop.ioan-daniel%40analog.com
patch subject: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
config: i386-randconfig-061-20250509 (https://download.01.org/0day-ci/archive/20250510/202505100131.FZe7C8ot-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250510/202505100131.FZe7C8ot-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505100131.FZe7C8ot-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/iio/adc/ad4851.c:324:60: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected unsigned int chan @@     got struct iio_chan_spec const *chan @@
   drivers/iio/adc/ad4851.c:324:60: sparse:     expected unsigned int chan
   drivers/iio/adc/ad4851.c:324:60: sparse:     got struct iio_chan_spec const *chan

vim +324 drivers/iio/adc/ad4851.c

   295	
   296	static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
   297						 const struct iio_chan_spec *chan,
   298						 unsigned int osr)
   299	{
   300		struct ad4851_state *st = iio_priv(indio_dev);
   301		int val, ret;
   302	
   303		guard(mutex)(&st->lock);
   304	
   305		if (osr == 1) {
   306			ret = regmap_clear_bits(st->regmap, AD4851_REG_OVERSAMPLE,
   307						AD4851_OS_EN_MSK);
   308			if (ret)
   309				return ret;
   310		} else {
   311			val = ad4851_osr_to_regval(osr);
   312			if (val < 0)
   313				return -EINVAL;
   314	
   315			ret = regmap_update_bits(st->regmap, AD4851_REG_OVERSAMPLE,
   316						 AD4851_OS_EN_MSK |
   317						 AD4851_OS_RATIO_MSK,
   318						 FIELD_PREP(AD4851_OS_EN_MSK, 1) |
   319						 FIELD_PREP(AD4851_OS_RATIO_MSK, val));
   320			if (ret)
   321				return ret;
   322		}
   323	
 > 324		ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);
   325		if (ret)
   326			return ret;
   327	
   328		switch (st->info->resolution) {
   329		case 20:
   330			switch (osr) {
   331			case 0:
   332				return -EINVAL;
   333			case 1:
   334				val = 20;
   335				break;
   336			default:
   337				val = 24;
   338				break;
   339			}
   340			break;
   341		case 16:
   342			val = 16;
   343			break;
   344		default:
   345			return -EINVAL;
   346		}
   347	
   348		ret = iio_backend_data_size_set(st->back, val);
   349		if (ret)
   350			return ret;
   351	
   352		if (osr == 1 || st->info->resolution == 16) {
   353			ret = regmap_clear_bits(st->regmap, AD4851_REG_PACKET,
   354						AD4851_PACKET_FORMAT_MASK);
   355			if (ret)
   356				return ret;
   357	
   358			st->resolution_boost_enabled = false;
   359		} else {
   360			ret = regmap_update_bits(st->regmap, AD4851_REG_PACKET,
   361						 AD4851_PACKET_FORMAT_MASK,
   362						 FIELD_PREP(AD4851_PACKET_FORMAT_MASK, 1));
   363			if (ret)
   364				return ret;
   365	
   366			st->resolution_boost_enabled = true;
   367		}
   368	
   369		if (st->osr != osr) {
   370			ret = ad4851_scale_fill(indio_dev);
   371			if (ret)
   372				return ret;
   373	
   374			st->osr = osr;
   375		}
   376	
   377		return 0;
   378	}
   379	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
Posted by kernel test robot 7 months, 1 week ago
Hi Pop,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.15-rc5 next-20250508]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pop-Ioan-Daniel/iio-backend-update-iio_backend_oversampling_ratio_set/20250508-203339
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20250508123107.3797042-2-pop.ioan-daniel%40analog.com
patch subject: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
config: nios2-randconfig-001-20250509 (https://download.01.org/0day-ci/archive/20250509/202505091838.a9sKlbJN-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250509/202505091838.a9sKlbJN-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505091838.a9sKlbJN-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/iio/adc/ad4851.c: In function 'ad4851_set_oversampling_ratio':
>> drivers/iio/adc/ad4851.c:324:60: warning: passing argument 2 of 'iio_backend_oversampling_ratio_set' makes integer from pointer without a cast [-Wint-conversion]
     324 |         ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);
         |                                                            ^~~~
         |                                                            |
         |                                                            const struct iio_chan_spec *
   In file included from drivers/iio/adc/ad4851.c:26:
   include/linux/iio/backend.h:212:53: note: expected 'unsigned int' but argument is of type 'const struct iio_chan_spec *'
     212 |                                        unsigned int chan,
         |                                        ~~~~~~~~~~~~~^~~~


vim +/iio_backend_oversampling_ratio_set +324 drivers/iio/adc/ad4851.c

   295	
   296	static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
   297						 const struct iio_chan_spec *chan,
   298						 unsigned int osr)
   299	{
   300		struct ad4851_state *st = iio_priv(indio_dev);
   301		int val, ret;
   302	
   303		guard(mutex)(&st->lock);
   304	
   305		if (osr == 1) {
   306			ret = regmap_clear_bits(st->regmap, AD4851_REG_OVERSAMPLE,
   307						AD4851_OS_EN_MSK);
   308			if (ret)
   309				return ret;
   310		} else {
   311			val = ad4851_osr_to_regval(osr);
   312			if (val < 0)
   313				return -EINVAL;
   314	
   315			ret = regmap_update_bits(st->regmap, AD4851_REG_OVERSAMPLE,
   316						 AD4851_OS_EN_MSK |
   317						 AD4851_OS_RATIO_MSK,
   318						 FIELD_PREP(AD4851_OS_EN_MSK, 1) |
   319						 FIELD_PREP(AD4851_OS_RATIO_MSK, val));
   320			if (ret)
   321				return ret;
   322		}
   323	
 > 324		ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);
   325		if (ret)
   326			return ret;
   327	
   328		switch (st->info->resolution) {
   329		case 20:
   330			switch (osr) {
   331			case 0:
   332				return -EINVAL;
   333			case 1:
   334				val = 20;
   335				break;
   336			default:
   337				val = 24;
   338				break;
   339			}
   340			break;
   341		case 16:
   342			val = 16;
   343			break;
   344		default:
   345			return -EINVAL;
   346		}
   347	
   348		ret = iio_backend_data_size_set(st->back, val);
   349		if (ret)
   350			return ret;
   351	
   352		if (osr == 1 || st->info->resolution == 16) {
   353			ret = regmap_clear_bits(st->regmap, AD4851_REG_PACKET,
   354						AD4851_PACKET_FORMAT_MASK);
   355			if (ret)
   356				return ret;
   357	
   358			st->resolution_boost_enabled = false;
   359		} else {
   360			ret = regmap_update_bits(st->regmap, AD4851_REG_PACKET,
   361						 AD4851_PACKET_FORMAT_MASK,
   362						 FIELD_PREP(AD4851_PACKET_FORMAT_MASK, 1));
   363			if (ret)
   364				return ret;
   365	
   366			st->resolution_boost_enabled = true;
   367		}
   368	
   369		if (st->osr != osr) {
   370			ret = ad4851_scale_fill(indio_dev);
   371			if (ret)
   372				return ret;
   373	
   374			st->osr = osr;
   375		}
   376	
   377		return 0;
   378	}
   379	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
Posted by kernel test robot 7 months, 1 week ago
Hi Pop,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v6.15-rc5 next-20250508]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pop-Ioan-Daniel/iio-backend-update-iio_backend_oversampling_ratio_set/20250508-203339
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20250508123107.3797042-2-pop.ioan-daniel%40analog.com
patch subject: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
config: arm-randconfig-004-20250509 (https://download.01.org/0day-ci/archive/20250509/202505091706.owR2rZED-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250509/202505091706.owR2rZED-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505091706.owR2rZED-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/iio/adc/ad4851.c:324:53: error: incompatible pointer to integer conversion passing 'const struct iio_chan_spec *' to parameter of type 'unsigned int' [-Wint-conversion]
     324 |         ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);
         |                                                            ^~~~
   include/linux/iio/backend.h:212:25: note: passing argument to parameter 'chan' here
     212 |                                        unsigned int chan,
         |                                                     ^
   1 error generated.


vim +324 drivers/iio/adc/ad4851.c

   295	
   296	static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
   297						 const struct iio_chan_spec *chan,
   298						 unsigned int osr)
   299	{
   300		struct ad4851_state *st = iio_priv(indio_dev);
   301		int val, ret;
   302	
   303		guard(mutex)(&st->lock);
   304	
   305		if (osr == 1) {
   306			ret = regmap_clear_bits(st->regmap, AD4851_REG_OVERSAMPLE,
   307						AD4851_OS_EN_MSK);
   308			if (ret)
   309				return ret;
   310		} else {
   311			val = ad4851_osr_to_regval(osr);
   312			if (val < 0)
   313				return -EINVAL;
   314	
   315			ret = regmap_update_bits(st->regmap, AD4851_REG_OVERSAMPLE,
   316						 AD4851_OS_EN_MSK |
   317						 AD4851_OS_RATIO_MSK,
   318						 FIELD_PREP(AD4851_OS_EN_MSK, 1) |
   319						 FIELD_PREP(AD4851_OS_RATIO_MSK, val));
   320			if (ret)
   321				return ret;
   322		}
   323	
 > 324		ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);
   325		if (ret)
   326			return ret;
   327	
   328		switch (st->info->resolution) {
   329		case 20:
   330			switch (osr) {
   331			case 0:
   332				return -EINVAL;
   333			case 1:
   334				val = 20;
   335				break;
   336			default:
   337				val = 24;
   338				break;
   339			}
   340			break;
   341		case 16:
   342			val = 16;
   343			break;
   344		default:
   345			return -EINVAL;
   346		}
   347	
   348		ret = iio_backend_data_size_set(st->back, val);
   349		if (ret)
   350			return ret;
   351	
   352		if (osr == 1 || st->info->resolution == 16) {
   353			ret = regmap_clear_bits(st->regmap, AD4851_REG_PACKET,
   354						AD4851_PACKET_FORMAT_MASK);
   355			if (ret)
   356				return ret;
   357	
   358			st->resolution_boost_enabled = false;
   359		} else {
   360			ret = regmap_update_bits(st->regmap, AD4851_REG_PACKET,
   361						 AD4851_PACKET_FORMAT_MASK,
   362						 FIELD_PREP(AD4851_PACKET_FORMAT_MASK, 1));
   363			if (ret)
   364				return ret;
   365	
   366			st->resolution_boost_enabled = true;
   367		}
   368	
   369		if (st->osr != osr) {
   370			ret = ad4851_scale_fill(indio_dev);
   371			if (ret)
   372				return ret;
   373	
   374			st->osr = osr;
   375		}
   376	
   377		return 0;
   378	}
   379	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 1/4] iio: backend: update iio_backend_oversampling_ratio_set
Posted by David Lechner 7 months, 1 week ago
On 5/8/25 7:30 AM, Pop Ioan Daniel wrote:
> In the function iio_backend_oversampling_ratio_set the chan parameter
> was added. The function can be used in contexts where the channel
> must be specified. All affected files have been modified.
> 
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
> changes in v2:
>  - remove iio_backend_set_dec_rate function and use 
>    iio_backend_oversampling_ratio_set function
>  drivers/iio/adc/ad4851.c           | 2 +-
>  drivers/iio/adc/adi-axi-adc.c      | 3 ++-
>  drivers/iio/industrialio-backend.c | 3 ++-
>  include/linux/iio/backend.h        | 3 ++-
>  4 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad4851.c b/drivers/iio/adc/ad4851.c
> index 98ebc853db79..a943d5aac9e5 100644
> --- a/drivers/iio/adc/ad4851.c
> +++ b/drivers/iio/adc/ad4851.c
> @@ -321,7 +321,7 @@ static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
>  			return ret;
>  	}
>  
> -	ret = iio_backend_oversampling_ratio_set(st->back, osr);
> +	ret = iio_backend_oversampling_ratio_set(st->back, chan, osr);

Isn't this a compile error? chan here is const struct iio_chan_spec *, not
unsigned int.

>  	if (ret)
>  		return ret;
>