diff mbox series

[V4,1/6] iio: accel: bmi088: Modified the scale calculate

Message ID 20220525130828.2394919-2-Qing-wu.Li@leica-geosystems.com.cn (mailing list archive)
State Superseded
Headers show
Series iio: accel: bmi088: support BMI085 BMI090L | expand

Commit Message

LI Qingwu May 25, 2022, 1:08 p.m. UTC
The units after application of scale are 100*m/s^2,
The scale calculation is only for the device
with the range of 3, 6, 12, and 24g,
but some other chips have a range of 2, 4, 6, and 8g.

Modified the scales from formula to a list, the scales in the list are
calculated as 9.8/32768*pow(2,reg41+1)*1.5, refer to datasheet 5.3.4.
The new units after the application of scale are m/s^2.

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 drivers/iio/accel/bmi088-accel-core.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

kernel test robot May 25, 2022, 5:53 p.m. UTC | #1
Hi LI,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on v5.18 next-20220525]
[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]

url:    https://github.com/intel-lab-lkp/linux/commits/LI-Qingwu/iio-accel-bmi088-support-BMI085-BMI090L/20220525-211157
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: x86_64-randconfig-a016 (https://download.01.org/0day-ci/archive/20220526/202205260151.TTnXYfeD-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d52a6e75b0c402c7f3b42a2b1b2873f151220947)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/71cdfb0a9a6ddbf8737a46bc6161fb921b1ac2f4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review LI-Qingwu/iio-accel-bmi088-support-BMI085-BMI090L/20220525-211157
        git checkout 71cdfb0a9a6ddbf8737a46bc6161fb921b1ac2f4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/iio/accel/bmi088-accel-core.c:341:10: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                           reg = FIELD_GET(BMIO088_ACCEL_ACC_RANGE_MSK, reg);
                                 ^
   1 error generated.


vim +/FIELD_GET +341 drivers/iio/accel/bmi088-accel-core.c

   278	
   279	static int bmi088_accel_read_raw(struct iio_dev *indio_dev,
   280					 struct iio_chan_spec const *chan,
   281					 int *val, int *val2, long mask)
   282	{
   283		struct bmi088_accel_data *data = iio_priv(indio_dev);
   284		struct device *dev = regmap_get_device(data->regmap);
   285		int ret;
   286		int reg;
   287	
   288		switch (mask) {
   289		case IIO_CHAN_INFO_RAW:
   290			switch (chan->type) {
   291			case IIO_TEMP:
   292				ret = pm_runtime_resume_and_get(dev);
   293				if (ret)
   294					return ret;
   295	
   296				ret = bmi088_accel_get_temp(data, val);
   297				goto out_read_raw_pm_put;
   298			case IIO_ACCEL:
   299				ret = pm_runtime_resume_and_get(dev);
   300				if (ret)
   301					return ret;
   302	
   303				ret = iio_device_claim_direct_mode(indio_dev);
   304				if (ret)
   305					goto out_read_raw_pm_put;
   306	
   307				ret = bmi088_accel_get_axis(data, chan, val);
   308				iio_device_release_direct_mode(indio_dev);
   309				if (!ret)
   310					ret = IIO_VAL_INT;
   311	
   312				goto out_read_raw_pm_put;
   313			default:
   314				return -EINVAL;
   315			}
   316		case IIO_CHAN_INFO_OFFSET:
   317			switch (chan->type) {
   318			case IIO_TEMP:
   319				/* Offset applies before scale */
   320				*val = BMI088_ACCEL_TEMP_OFFSET/BMI088_ACCEL_TEMP_UNIT;
   321				return IIO_VAL_INT;
   322			default:
   323				return -EINVAL;
   324			}
   325		case IIO_CHAN_INFO_SCALE:
   326			switch (chan->type) {
   327			case IIO_TEMP:
   328				/* 0.125 degrees per LSB */
   329				*val = BMI088_ACCEL_TEMP_UNIT;
   330				return IIO_VAL_INT;
   331			case IIO_ACCEL:
   332				ret = pm_runtime_resume_and_get(dev);
   333				if (ret)
   334					return ret;
   335	
   336				ret = regmap_read(data->regmap,
   337						  BMI088_ACCEL_REG_ACC_RANGE, &reg);
   338				if (ret)
   339					goto out_read_raw_pm_put;
   340	
 > 341				reg = FIELD_GET(BMIO088_ACCEL_ACC_RANGE_MSK, reg);
   342				*val  = data->chip_info->scale_table[reg][0];
   343				*val2 = data->chip_info->scale_table[reg][1];
   344				ret = IIO_VAL_INT_PLUS_MICRO;
   345	
   346				goto out_read_raw_pm_put;
   347			default:
   348				return -EINVAL;
   349			}
   350		case IIO_CHAN_INFO_SAMP_FREQ:
   351			ret = pm_runtime_resume_and_get(dev);
   352			if (ret)
   353				return ret;
   354	
   355			ret = bmi088_accel_get_sample_freq(data, val, val2);
   356			goto out_read_raw_pm_put;
   357		default:
   358			break;
   359		}
   360	
   361		return -EINVAL;
   362	
   363	out_read_raw_pm_put:
   364		pm_runtime_mark_last_busy(dev);
   365		pm_runtime_put_autosuspend(dev);
   366	
   367		return ret;
   368	}
   369
diff mbox series

Patch

diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c
index d74465214feb..3f38967c5a0a 100644
--- a/drivers/iio/accel/bmi088-accel-core.c
+++ b/drivers/iio/accel/bmi088-accel-core.c
@@ -73,6 +73,8 @@ 
 #define BMI088_ACCEL_FIFO_MODE_FIFO			0x40
 #define BMI088_ACCEL_FIFO_MODE_STREAM			0x80
 
+#define BMIO088_ACCEL_ACC_RANGE_MSK			GENMASK(1, 0)
+
 enum bmi088_accel_axis {
 	AXIS_X,
 	AXIS_Y,
@@ -119,6 +121,7 @@  struct bmi088_accel_chip_info {
 	u8 chip_id;
 	const struct iio_chan_spec *channels;
 	int num_channels;
+	const int scale_table[4][2];
 };
 
 struct bmi088_accel_data {
@@ -280,6 +283,7 @@  static int bmi088_accel_read_raw(struct iio_dev *indio_dev,
 	struct bmi088_accel_data *data = iio_priv(indio_dev);
 	struct device *dev = regmap_get_device(data->regmap);
 	int ret;
+	int reg;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
@@ -330,13 +334,14 @@  static int bmi088_accel_read_raw(struct iio_dev *indio_dev,
 				return ret;
 
 			ret = regmap_read(data->regmap,
-					  BMI088_ACCEL_REG_ACC_RANGE, val);
+					  BMI088_ACCEL_REG_ACC_RANGE, &reg);
 			if (ret)
 				goto out_read_raw_pm_put;
 
-			*val2 = 15 - (*val & 0x3);
-			*val = 3 * 980;
-			ret = IIO_VAL_FRACTIONAL_LOG2;
+			reg = FIELD_GET(BMIO088_ACCEL_ACC_RANGE_MSK, reg);
+			*val  = data->chip_info->scale_table[reg][0];
+			*val2 = data->chip_info->scale_table[reg][1];
+			ret = IIO_VAL_INT_PLUS_MICRO;
 
 			goto out_read_raw_pm_put;
 		default:
@@ -432,6 +437,7 @@  static const struct bmi088_accel_chip_info bmi088_accel_chip_info_tbl[] = {
 		.chip_id = 0x1E,
 		.channels = bmi088_accel_channels,
 		.num_channels = ARRAY_SIZE(bmi088_accel_channels),
+		.scale_table = {{0, 897}, {0, 1794}, {0, 3589}, {0, 7178}},
 	},
 };