diff mbox series

[2/2] iio: bu27034: Add a read only HWARDWAREGAIN

Message ID 5e88c7b7b0389c6c011f15e05e065791f7561cf5.1718013518.git.mazziesaccount@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series ROHM BU27034NUC to ROHM BU27034ANUC | expand

Commit Message

Matti Vaittinen June 10, 2024, 10:01 a.m. UTC
The ROHM BU27034 light sensor has two data channels for measuring
different frequencies of light. The result from these channels is
combined into Lux value while the raw channel values are reported via
intensity channels.

Both of the intensity channels have adjustable gain setting which
impacts the scale of the raw channels. Eg, doubling the gain will double
the values read from the raw channels, which halves the scale value. The
integration time can also be set for the sensor. This does also have an
impact to the scale of the intensity channels because increasing the
integration time will also increase the values reported via the raw
channels.

Impact of integration time to the scale and the fact that the scale value
does not start from '1', can make it hard for a human reader to compute the
gain values based on the scale.

Add read-only HARDWAREGAIN to help debugging.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
 drivers/iio/light/rohm-bu27034.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

kernel test robot June 10, 2024, 12:55 p.m. UTC | #1
Hi Matti,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0]

url:    https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/bu27034-ROHM-BU27034NUC-to-BU27034ANUC/20240610-180426
base:   1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
patch link:    https://lore.kernel.org/r/5e88c7b7b0389c6c011f15e05e065791f7561cf5.1718013518.git.mazziesaccount%40gmail.com
patch subject: [PATCH 2/2] iio: bu27034: Add a read only HWARDWAREGAIN
config: i386-buildonly-randconfig-002-20240610 (https://download.01.org/0day-ci/archive/20240610/202406102012.s3Qrfbm7-lkp@intel.com/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240610/202406102012.s3Qrfbm7-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/202406102012.s3Qrfbm7-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/device.h:15,
                    from drivers/iio/light/rohm-bu27034.c:10:
   drivers/iio/light/rohm-bu27034.c: In function 'bu27034_write_raw_get_fmt':
>> include/linux/dev_printk.h:138:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
     137 |         ({                                                              \
         |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     138 |                 if (0)                                                  \
         |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     139 |                         _dev_printk(level, dev, fmt, ##__VA_ARGS__);    \
         |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     140 |         })
         |         ~~          
   include/linux/dev_printk.h:171:9: note: in expansion of macro 'dev_no_printk'
     171 |         dev_no_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~
   drivers/iio/light/rohm-bu27034.c:1055:17: note: in expansion of macro 'dev_dbg'
    1055 |                 dev_dbg(data->dev,
         |                 ^~~~~~~
   drivers/iio/light/rohm-bu27034.c:1057:9: note: here
    1057 |         default:
         |         ^~~~~~~


vim +138 include/linux/dev_printk.h

af628aae8640c2 Greg Kroah-Hartman 2019-12-09   99  
ad7d61f159db73 Chris Down         2021-06-15  100  /*
ad7d61f159db73 Chris Down         2021-06-15  101   * Need to take variadic arguments even though we don't use them, as dev_fmt()
ad7d61f159db73 Chris Down         2021-06-15  102   * may only just have been expanded and may result in multiple arguments.
ad7d61f159db73 Chris Down         2021-06-15  103   */
ad7d61f159db73 Chris Down         2021-06-15  104  #define dev_printk_index_emit(level, fmt, ...) \
ad7d61f159db73 Chris Down         2021-06-15  105  	printk_index_subsys_emit("%s %s: ", level, fmt)
ad7d61f159db73 Chris Down         2021-06-15  106  
ad7d61f159db73 Chris Down         2021-06-15  107  #define dev_printk_index_wrap(_p_func, level, dev, fmt, ...)		\
ad7d61f159db73 Chris Down         2021-06-15  108  	({								\
ad7d61f159db73 Chris Down         2021-06-15  109  		dev_printk_index_emit(level, fmt);			\
ad7d61f159db73 Chris Down         2021-06-15  110  		_p_func(dev, fmt, ##__VA_ARGS__);			\
ad7d61f159db73 Chris Down         2021-06-15  111  	})
ad7d61f159db73 Chris Down         2021-06-15  112  
ad7d61f159db73 Chris Down         2021-06-15  113  /*
ad7d61f159db73 Chris Down         2021-06-15  114   * Some callsites directly call dev_printk rather than going through the
ad7d61f159db73 Chris Down         2021-06-15  115   * dev_<level> infrastructure, so we need to emit here as well as inside those
ad7d61f159db73 Chris Down         2021-06-15  116   * level-specific macros. Only one index entry will be produced, either way,
ad7d61f159db73 Chris Down         2021-06-15  117   * since dev_printk's `fmt` isn't known at compile time if going through the
ad7d61f159db73 Chris Down         2021-06-15  118   * dev_<level> macros.
ad7d61f159db73 Chris Down         2021-06-15  119   *
ad7d61f159db73 Chris Down         2021-06-15  120   * dev_fmt() isn't called for dev_printk when used directly, as it's used by
ad7d61f159db73 Chris Down         2021-06-15  121   * the dev_<level> macros internally which already have dev_fmt() processed.
ad7d61f159db73 Chris Down         2021-06-15  122   *
ad7d61f159db73 Chris Down         2021-06-15  123   * We also can't use dev_printk_index_wrap directly, because we have a separate
ad7d61f159db73 Chris Down         2021-06-15  124   * level to process.
ad7d61f159db73 Chris Down         2021-06-15  125   */
ad7d61f159db73 Chris Down         2021-06-15  126  #define dev_printk(level, dev, fmt, ...)				\
ad7d61f159db73 Chris Down         2021-06-15  127  	({								\
ad7d61f159db73 Chris Down         2021-06-15  128  		dev_printk_index_emit(level, fmt);			\
ad7d61f159db73 Chris Down         2021-06-15  129  		_dev_printk(level, dev, fmt, ##__VA_ARGS__);		\
ad7d61f159db73 Chris Down         2021-06-15  130  	})
ad7d61f159db73 Chris Down         2021-06-15  131  
c26ec799042a38 Geert Uytterhoeven 2024-02-28  132  /*
c26ec799042a38 Geert Uytterhoeven 2024-02-28  133   * Dummy dev_printk for disabled debugging statements to use whilst maintaining
c26ec799042a38 Geert Uytterhoeven 2024-02-28  134   * gcc's format checking.
c26ec799042a38 Geert Uytterhoeven 2024-02-28  135   */
c26ec799042a38 Geert Uytterhoeven 2024-02-28  136  #define dev_no_printk(level, dev, fmt, ...)				\
c26ec799042a38 Geert Uytterhoeven 2024-02-28  137  	({								\
c26ec799042a38 Geert Uytterhoeven 2024-02-28 @138  		if (0)							\
c26ec799042a38 Geert Uytterhoeven 2024-02-28  139  			_dev_printk(level, dev, fmt, ##__VA_ARGS__);	\
c26ec799042a38 Geert Uytterhoeven 2024-02-28  140  	})
c26ec799042a38 Geert Uytterhoeven 2024-02-28  141
kernel test robot June 10, 2024, 1:28 p.m. UTC | #2
Hi Matti,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0]

url:    https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/bu27034-ROHM-BU27034NUC-to-BU27034ANUC/20240610-180426
base:   1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
patch link:    https://lore.kernel.org/r/5e88c7b7b0389c6c011f15e05e065791f7561cf5.1718013518.git.mazziesaccount%40gmail.com
patch subject: [PATCH 2/2] iio: bu27034: Add a read only HWARDWAREGAIN
config: i386-buildonly-randconfig-004-20240610 (https://download.01.org/0day-ci/archive/20240610/202406102113.7w2Td20S-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240610/202406102113.7w2Td20S-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/202406102113.7w2Td20S-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/iio/light/rohm-bu27034.c:1057:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    1057 |         default:
         |         ^
   drivers/iio/light/rohm-bu27034.c:1057:2: note: insert '__attribute__((fallthrough));' to silence this warning
    1057 |         default:
         |         ^
         |         __attribute__((fallthrough)); 
   drivers/iio/light/rohm-bu27034.c:1057:2: note: insert 'break;' to avoid fall-through
    1057 |         default:
         |         ^
         |         break; 
   1 warning generated.

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for REGMAP_SPI
   Depends on [n]: SPI [=n]
   Selected by [y]:
   - AD9739A [=y] && IIO [=y] && (SPI [=n] || COMPILE_TEST [=y])


vim +1057 drivers/iio/light/rohm-bu27034.c

e52afbd61039e2 Matti Vaittinen 2023-03-31  1042  
d47b9b84292706 Matti Vaittinen 2023-06-13  1043  static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
d47b9b84292706 Matti Vaittinen 2023-06-13  1044  				     struct iio_chan_spec const *chan,
d47b9b84292706 Matti Vaittinen 2023-06-13  1045  				     long mask)
d47b9b84292706 Matti Vaittinen 2023-06-13  1046  {
6196c88810e86d Matti Vaittinen 2024-06-10  1047  	struct bu27034_data *data = iio_priv(indio_dev);
d47b9b84292706 Matti Vaittinen 2023-06-13  1048  
d47b9b84292706 Matti Vaittinen 2023-06-13  1049  	switch (mask) {
d47b9b84292706 Matti Vaittinen 2023-06-13  1050  	case IIO_CHAN_INFO_SCALE:
d47b9b84292706 Matti Vaittinen 2023-06-13  1051  		return IIO_VAL_INT_PLUS_NANO;
d47b9b84292706 Matti Vaittinen 2023-06-13  1052  	case IIO_CHAN_INFO_INT_TIME:
d47b9b84292706 Matti Vaittinen 2023-06-13  1053  		return IIO_VAL_INT_PLUS_MICRO;
6196c88810e86d Matti Vaittinen 2024-06-10  1054  	case IIO_CHAN_INFO_HARDWAREGAIN:
6196c88810e86d Matti Vaittinen 2024-06-10  1055  		dev_dbg(data->dev,
6196c88810e86d Matti Vaittinen 2024-06-10  1056  			"HARDWAREGAIN is read-only, use scale to set\n");
d47b9b84292706 Matti Vaittinen 2023-06-13 @1057  	default:
d47b9b84292706 Matti Vaittinen 2023-06-13  1058  		return -EINVAL;
d47b9b84292706 Matti Vaittinen 2023-06-13  1059  	}
d47b9b84292706 Matti Vaittinen 2023-06-13  1060  }
d47b9b84292706 Matti Vaittinen 2023-06-13  1061
Jonathan Cameron June 15, 2024, 5:50 p.m. UTC | #3
On Mon, 10 Jun 2024 13:01:40 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> The ROHM BU27034 light sensor has two data channels for measuring
> different frequencies of light. The result from these channels is
> combined into Lux value while the raw channel values are reported via
> intensity channels.
> 
> Both of the intensity channels have adjustable gain setting which
> impacts the scale of the raw channels. Eg, doubling the gain will double
> the values read from the raw channels, which halves the scale value. The
> integration time can also be set for the sensor. This does also have an
> impact to the scale of the intensity channels because increasing the
> integration time will also increase the values reported via the raw
> channels.
> 
> Impact of integration time to the scale and the fact that the scale value
> does not start from '1', can make it hard for a human reader to compute the
> gain values based on the scale.
> 
> Add read-only HARDWAREGAIN to help debugging.
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Other than the thing the bot found with fallthrough on the switch statement
not being marked LGTM.
> ---
>  drivers/iio/light/rohm-bu27034.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
> index 51acad2cafbd..b299ff2aacce 100644
> --- a/drivers/iio/light/rohm-bu27034.c
> +++ b/drivers/iio/light/rohm-bu27034.c
> @@ -149,7 +149,8 @@ static const struct iio_itime_sel_mul bu27034_itimes[] = {
>  	.channel = BU27034_CHAN_##_name,				\
>  	.channel2 = IIO_MOD_LIGHT_CLEAR,				\
>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
> -			      BIT(IIO_CHAN_INFO_SCALE),			\
> +			      BIT(IIO_CHAN_INFO_SCALE) |		\
> +			      BIT(IIO_CHAN_INFO_HARDWAREGAIN),		\
>  	.info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),	\
>  	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),		\
>  	.info_mask_shared_by_all_available =				\
> @@ -992,6 +993,13 @@ static int bu27034_read_raw(struct iio_dev *idev,
>  
>  		return IIO_VAL_INT_PLUS_MICRO;
>  
> +	case IIO_CHAN_INFO_HARDWAREGAIN:
> +		ret = bu27034_get_gain(data, chan->channel, val);
> +		if (ret)
> +			return ret;
> +
> +		return IIO_VAL_INT;
> +
>  	case IIO_CHAN_INFO_SCALE:
>  		return bu27034_get_scale(data, chan->channel, val, val2);
>  
> @@ -1036,12 +1044,16 @@ static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
>  				     struct iio_chan_spec const *chan,
>  				     long mask)
>  {
> +	struct bu27034_data *data = iio_priv(indio_dev);
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_SCALE:
>  		return IIO_VAL_INT_PLUS_NANO;
>  	case IIO_CHAN_INFO_INT_TIME:
>  		return IIO_VAL_INT_PLUS_MICRO;
> +	case IIO_CHAN_INFO_HARDWAREGAIN:
> +		dev_dbg(data->dev,
> +			"HARDWAREGAIN is read-only, use scale to set\n");

return -EINVAL here.  You could use a fall through marking but it gains
little so I wouldn't bother.

>  	default:
>  		return -EINVAL;
>  	}
Matti Vaittinen June 17, 2024, 5:34 a.m. UTC | #4
On 6/15/24 20:50, Jonathan Cameron wrote:
> On Mon, 10 Jun 2024 13:01:40 +0300
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> 
>> The ROHM BU27034 light sensor has two data channels for measuring
>> different frequencies of light. The result from these channels is
>> combined into Lux value while the raw channel values are reported via
>> intensity channels.
>>
>> Both of the intensity channels have adjustable gain setting which
>> impacts the scale of the raw channels. Eg, doubling the gain will double
>> the values read from the raw channels, which halves the scale value. The
>> integration time can also be set for the sensor. This does also have an
>> impact to the scale of the intensity channels because increasing the
>> integration time will also increase the values reported via the raw
>> channels.
>>
>> Impact of integration time to the scale and the fact that the scale value
>> does not start from '1', can make it hard for a human reader to compute the
>> gain values based on the scale.
>>
>> Add read-only HARDWAREGAIN to help debugging.
>>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Other than the thing the bot found with fallthrough on the switch statement
> not being marked LGTM.
>> ---
>>   drivers/iio/light/rohm-bu27034.c | 14 +++++++++++++-
>>   1 file changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
>> index 51acad2cafbd..b299ff2aacce 100644
>> --- a/drivers/iio/light/rohm-bu27034.c
>> +++ b/drivers/iio/light/rohm-bu27034.c
>> @@ -149,7 +149,8 @@ static const struct iio_itime_sel_mul bu27034_itimes[] = {
>>   	.channel = BU27034_CHAN_##_name,				\
>>   	.channel2 = IIO_MOD_LIGHT_CLEAR,				\
>>   	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
>> -			      BIT(IIO_CHAN_INFO_SCALE),			\
>> +			      BIT(IIO_CHAN_INFO_SCALE) |		\
>> +			      BIT(IIO_CHAN_INFO_HARDWAREGAIN),		\
>>   	.info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),	\
>>   	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),		\
>>   	.info_mask_shared_by_all_available =				\
>> @@ -992,6 +993,13 @@ static int bu27034_read_raw(struct iio_dev *idev,
>>   
>>   		return IIO_VAL_INT_PLUS_MICRO;
>>   
>> +	case IIO_CHAN_INFO_HARDWAREGAIN:
>> +		ret = bu27034_get_gain(data, chan->channel, val);
>> +		if (ret)
>> +			return ret;
>> +
>> +		return IIO_VAL_INT;
>> +
>>   	case IIO_CHAN_INFO_SCALE:
>>   		return bu27034_get_scale(data, chan->channel, val, val2);
>>   
>> @@ -1036,12 +1044,16 @@ static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
>>   				     struct iio_chan_spec const *chan,
>>   				     long mask)
>>   {
>> +	struct bu27034_data *data = iio_priv(indio_dev);
>>   
>>   	switch (mask) {
>>   	case IIO_CHAN_INFO_SCALE:
>>   		return IIO_VAL_INT_PLUS_NANO;
>>   	case IIO_CHAN_INFO_INT_TIME:
>>   		return IIO_VAL_INT_PLUS_MICRO;
>> +	case IIO_CHAN_INFO_HARDWAREGAIN:
>> +		dev_dbg(data->dev,
>> +			"HARDWAREGAIN is read-only, use scale to set\n");
> 
> return -EINVAL here.  You could use a fall through marking but it gains
> little so I wouldn't bother.

Right, thanks.

> 
>>   	default:
>>   		return -EINVAL;
>>   	}
>
diff mbox series

Patch

diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
index 51acad2cafbd..b299ff2aacce 100644
--- a/drivers/iio/light/rohm-bu27034.c
+++ b/drivers/iio/light/rohm-bu27034.c
@@ -149,7 +149,8 @@  static const struct iio_itime_sel_mul bu27034_itimes[] = {
 	.channel = BU27034_CHAN_##_name,				\
 	.channel2 = IIO_MOD_LIGHT_CLEAR,				\
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
-			      BIT(IIO_CHAN_INFO_SCALE),			\
+			      BIT(IIO_CHAN_INFO_SCALE) |		\
+			      BIT(IIO_CHAN_INFO_HARDWAREGAIN),		\
 	.info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),	\
 	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),		\
 	.info_mask_shared_by_all_available =				\
@@ -992,6 +993,13 @@  static int bu27034_read_raw(struct iio_dev *idev,
 
 		return IIO_VAL_INT_PLUS_MICRO;
 
+	case IIO_CHAN_INFO_HARDWAREGAIN:
+		ret = bu27034_get_gain(data, chan->channel, val);
+		if (ret)
+			return ret;
+
+		return IIO_VAL_INT;
+
 	case IIO_CHAN_INFO_SCALE:
 		return bu27034_get_scale(data, chan->channel, val, val2);
 
@@ -1036,12 +1044,16 @@  static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
 				     struct iio_chan_spec const *chan,
 				     long mask)
 {
+	struct bu27034_data *data = iio_priv(indio_dev);
 
 	switch (mask) {
 	case IIO_CHAN_INFO_SCALE:
 		return IIO_VAL_INT_PLUS_NANO;
 	case IIO_CHAN_INFO_INT_TIME:
 		return IIO_VAL_INT_PLUS_MICRO;
+	case IIO_CHAN_INFO_HARDWAREGAIN:
+		dev_dbg(data->dev,
+			"HARDWAREGAIN is read-only, use scale to set\n");
 	default:
 		return -EINVAL;
 	}