All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L
@ 2022-05-25 13:08 LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate LI Qingwu
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

Modified the units after application of scale from 100*m/s^2 to m/s^2,
since the units in the ABI documents are m/s^2.
Add supports for the BMI085 accelerometer.
Add supports for the BMI090L accelerometer.
Make it possible to config scales.

Change in v4: 
- Rebase to the latest version to fix the conflict issue.
- Modify the bm088 and bmi090 scale list,
  from {0, 897}, {0, 1795}, {0, 3590}, {0, 7179}
    to {0, 897}, {0, 1794}, {0, 3589}, {0, 7178}
  since old one are caculated as 1/sensitivity*9.8, the new one are
  caculated as 9.8/32768*pow(2,reg41+1)*1.5, the values should be same,
  but due to the decimal digits issue, there are 0.000001 differece,
  takethe new scales, since they are more accurate.


LI Qingwu (6):
  iio: accel: bmi088: Modified the scale calculate
  iio: accel: bmi088: Make it possible to config scales
  iio: accel: bmi088: modified the device name
  iio: accel: bmi088: Add support for bmi085 accel
  iio: accel: bmi088: Add support for bmi090l accel
  dt-bindings: iio: accel: Add bmi085 and bmi090l bindings

 .../bindings/iio/accel/bosch,bmi088.yaml      |  2 +
 drivers/iio/accel/bmi088-accel-core.c         | 96 +++++++++++++++----
 drivers/iio/accel/bmi088-accel-spi.c          | 17 +++-
 drivers/iio/accel/bmi088-accel.h              |  9 +-
 4 files changed, 100 insertions(+), 24 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate
  2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
@ 2022-05-25 13:08 ` LI Qingwu
  2022-05-25 17:53   ` kernel test robot
  2022-05-25 13:08 ` [PATCH V4 2/6] iio: accel: bmi088: Make it possible to config scales LI Qingwu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

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(-)

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}},
 	},
 };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 2/6] iio: accel: bmi088: Make it possible to config scales
  2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate LI Qingwu
@ 2022-05-25 13:08 ` LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 3/6] iio: accel: bmi088: modified the device name LI Qingwu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

The sensor can set the scales by writing the range register 0x41,
The current driver has no interface to configure it.
The commit adds the interface for config the scales.

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 | 33 ++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c
index 3f38967c5a0a..16c95d90f829 100644
--- a/drivers/iio/accel/bmi088-accel-core.c
+++ b/drivers/iio/accel/bmi088-accel-core.c
@@ -239,6 +239,21 @@ static int bmi088_accel_set_sample_freq(struct bmi088_accel_data *data, int val)
 				  BMI088_ACCEL_MODE_ODR_MASK, regval);
 }
 
+static int bmi088_accel_set_scale(struct bmi088_accel_data *data, int val, int val2)
+{
+	unsigned int i;
+
+	for (i = 0; i < 4; i++)
+		if (val  == data->chip_info->scale_table[i][0] &&
+		    val2 == data->chip_info->scale_table[i][1])
+			break;
+
+	if (i == 4)
+		return -EINVAL;
+
+	return regmap_write(data->regmap, BMI088_ACCEL_REG_ACC_RANGE, i);
+}
+
 static int bmi088_accel_get_temp(struct bmi088_accel_data *data, int *val)
 {
 	int ret;
@@ -372,7 +387,13 @@ static int bmi088_accel_read_avail(struct iio_dev *indio_dev,
 			     const int **vals, int *type, int *length,
 			     long mask)
 {
+	struct bmi088_accel_data *data = iio_priv(indio_dev);
 	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		*vals = (const int *)data->chip_info->scale_table;
+		*length = 8;
+		*type = IIO_VAL_INT_PLUS_MICRO;
+		return IIO_AVAIL_LIST;
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		*type = IIO_VAL_INT_PLUS_MICRO;
 		*vals = bmi088_sample_freqs;
@@ -392,6 +413,15 @@ static int bmi088_accel_write_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret)
+			return ret;
+
+		ret = bmi088_accel_set_scale(data, val, val2);
+		pm_runtime_mark_last_busy(dev);
+		pm_runtime_put_autosuspend(dev);
+		return ret;
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		ret = pm_runtime_resume_and_get(dev);
 		if (ret)
@@ -413,7 +443,8 @@ static int bmi088_accel_write_raw(struct iio_dev *indio_dev,
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
 	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
 				BIT(IIO_CHAN_INFO_SAMP_FREQ), \
-	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
+	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+				BIT(IIO_CHAN_INFO_SCALE), \
 	.scan_index = AXIS_##_axis, \
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 3/6] iio: accel: bmi088: modified the device name
  2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 2/6] iio: accel: bmi088: Make it possible to config scales LI Qingwu
@ 2022-05-25 13:08 ` LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 4/6] iio: accel: bmi088: Add support for bmi085 accel LI Qingwu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

iio: accel: bmi088: modified the device name

It is possible to have multiple sensors connected on the same platform.
For support of different sensors, making it possible to obtain the
device name by reading the chip id. If the device was found in the
table but the device tree binding is different, the driver will carry
on with a warning. If no matching device was found, the driver load
the binding chip info.

Tested case, test with bmi085 and bmi090 patches applied:
connect 3 bmi090l to the system, and set device tree compatible:
spi2.0: compatible = "bosch,bmi090l-accel";
spi2.2: compatible = "bosch,bmi088-accel";
spi2.4: compatible = "bosch,bmi085-accel";

Get a warning for the mismatched devices:
bmi088_accel_spi spi2.2: unexpected chip id 0x1A
bmi088_accel_spi spi2.4: unexpected chip id 0x1A

Get the real present device name:
/sys/bus/iio/devices/iio:device1/name:bmi090l-accel
/sys/bus/iio/devices/iio:device3/name:bmi090l-accel
/sys/bus/iio/devices/iio:device5/name:bmi090l-accel

Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 drivers/iio/accel/bmi088-accel-core.c | 35 +++++++++++++++------------
 drivers/iio/accel/bmi088-accel-spi.c  | 13 +++++++---
 drivers/iio/accel/bmi088-accel.h      |  7 +++++-
 3 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c
index 16c95d90f829..fe8db9615d69 100644
--- a/drivers/iio/accel/bmi088-accel-core.c
+++ b/drivers/iio/accel/bmi088-accel-core.c
@@ -388,6 +388,7 @@ static int bmi088_accel_read_avail(struct iio_dev *indio_dev,
 			     long mask)
 {
 	struct bmi088_accel_data *data = iio_priv(indio_dev);
+
 	switch (mask) {
 	case IIO_CHAN_INFO_SCALE:
 		*vals = (const int *)data->chip_info->scale_table;
@@ -463,8 +464,8 @@ static const struct iio_chan_spec bmi088_accel_channels[] = {
 };
 
 static const struct bmi088_accel_chip_info bmi088_accel_chip_info_tbl[] = {
-	[0] = {
-		.name = "bmi088a",
+	[BOSCH_BMI088] = {
+		.name = "bmi088-accel",
 		.chip_id = 0x1E,
 		.channels = bmi088_accel_channels,
 		.num_channels = ARRAY_SIZE(bmi088_accel_channels),
@@ -483,12 +484,15 @@ static const unsigned long bmi088_accel_scan_masks[] = {
 	0
 };
 
-static int bmi088_accel_chip_init(struct bmi088_accel_data *data)
+static int bmi088_accel_chip_init(struct bmi088_accel_data *data, enum bmi_device_type type)
 {
 	struct device *dev = regmap_get_device(data->regmap);
 	int ret, i;
 	unsigned int val;
 
+	if (type >= BOSCH_UNKNOWN)
+		return -ENODEV;
+
 	/* Do a dummy read to enable SPI interface, won't harm I2C */
 	regmap_read(data->regmap, BMI088_ACCEL_REG_INT_STATUS, &val);
 
@@ -514,22 +518,23 @@ static int bmi088_accel_chip_init(struct bmi088_accel_data *data)
 	}
 
 	/* Validate chip ID */
-	for (i = 0; i < ARRAY_SIZE(bmi088_accel_chip_info_tbl); i++) {
-		if (bmi088_accel_chip_info_tbl[i].chip_id == val) {
-			data->chip_info = &bmi088_accel_chip_info_tbl[i];
+	for (i = 0; i < ARRAY_SIZE(bmi088_accel_chip_info_tbl); i++)
+		if (bmi088_accel_chip_info_tbl[i].chip_id == val)
 			break;
-		}
-	}
-	if (i == ARRAY_SIZE(bmi088_accel_chip_info_tbl)) {
-		dev_err(dev, "Invalid chip %x\n", val);
-		return -ENODEV;
-	}
+
+	if (i == ARRAY_SIZE(bmi088_accel_chip_info_tbl))
+		data->chip_info = &bmi088_accel_chip_info_tbl[type];
+	else
+		data->chip_info = &bmi088_accel_chip_info_tbl[i];
+
+	if (i != type)
+		dev_warn(dev, "unexpected chip id 0x%X\n", val);
 
 	return 0;
 }
 
 int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap,
-	int irq, const char *name, bool block_supported)
+	int irq, enum bmi_device_type type)
 {
 	struct bmi088_accel_data *data;
 	struct iio_dev *indio_dev;
@@ -544,13 +549,13 @@ int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap,
 
 	data->regmap = regmap;
 
-	ret = bmi088_accel_chip_init(data);
+	ret = bmi088_accel_chip_init(data, type);
 	if (ret)
 		return ret;
 
 	indio_dev->channels = data->chip_info->channels;
 	indio_dev->num_channels = data->chip_info->num_channels;
-	indio_dev->name = name ? name : data->chip_info->name;
+	indio_dev->name = data->chip_info->name;
 	indio_dev->available_scan_masks = bmi088_accel_scan_masks;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &bmi088_accel_info;
diff --git a/drivers/iio/accel/bmi088-accel-spi.c b/drivers/iio/accel/bmi088-accel-spi.c
index 06d99d9949f3..c77aec01bc67 100644
--- a/drivers/iio/accel/bmi088-accel-spi.c
+++ b/drivers/iio/accel/bmi088-accel-spi.c
@@ -52,8 +52,8 @@ static int bmi088_accel_probe(struct spi_device *spi)
 		return PTR_ERR(regmap);
 	}
 
-	return bmi088_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
-				       true);
+	return bmi088_accel_core_probe(&spi->dev, regmap, spi->irq,
+					id->driver_data);
 }
 
 static void bmi088_accel_remove(struct spi_device *spi)
@@ -61,8 +61,14 @@ static void bmi088_accel_remove(struct spi_device *spi)
 	bmi088_accel_core_remove(&spi->dev);
 }
 
+static const struct of_device_id bmi088_of_match[] = {
+	{ .compatible = "bosch,bmi088-accel" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, bmi088_of_match);
+
 static const struct spi_device_id bmi088_accel_id[] = {
-	{"bmi088-accel", },
+	{"bmi088-accel",  BOSCH_BMI088},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, bmi088_accel_id);
@@ -71,6 +77,7 @@ static struct spi_driver bmi088_accel_driver = {
 	.driver = {
 		.name	= "bmi088_accel_spi",
 		.pm	= &bmi088_accel_pm_ops,
+		.of_match_table = bmi088_of_match,
 	},
 	.probe		= bmi088_accel_probe,
 	.remove		= bmi088_accel_remove,
diff --git a/drivers/iio/accel/bmi088-accel.h b/drivers/iio/accel/bmi088-accel.h
index 5d40c7cf1cbc..65338a1bf97d 100644
--- a/drivers/iio/accel/bmi088-accel.h
+++ b/drivers/iio/accel/bmi088-accel.h
@@ -8,11 +8,16 @@
 
 struct device;
 
+enum bmi_device_type {
+	BOSCH_BMI088,
+	BOSCH_UNKNOWN,
+};
+
 extern const struct regmap_config bmi088_regmap_conf;
 extern const struct dev_pm_ops bmi088_accel_pm_ops;
 
 int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported);
+			    enum bmi_device_type type);
 void bmi088_accel_core_remove(struct device *dev);
 
 #endif /* BMI088_ACCEL_H */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 4/6] iio: accel: bmi088: Add support for bmi085 accel
  2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
                   ` (2 preceding siblings ...)
  2022-05-25 13:08 ` [PATCH V4 3/6] iio: accel: bmi088: modified the device name LI Qingwu
@ 2022-05-25 13:08 ` LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 5/6] iio: accel: bmi088: Add support for bmi090l accel LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 6/6] dt-bindings: iio: accel: Add bmi085 and bmi090l bindings LI Qingwu
  5 siblings, 0 replies; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

Add supports for BMI085, an Inertial Measurement Unit,
with an accelerometer and gyroscope.
The commit adds the accelerometer driver for the SPI interface.
The gyroscope part is already supported by the BMG160 driver.
Unlike BMI088, the BMI085 accelerometer ranges are +/-2, 4, 6,
and 8g, the scales are calculated as 9.8/32768*pow(2,reg41+1).

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 | 7 +++++++
 drivers/iio/accel/bmi088-accel-spi.c  | 2 ++
 drivers/iio/accel/bmi088-accel.h      | 1 +
 3 files changed, 10 insertions(+)

diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c
index fe8db9615d69..18becc857d49 100644
--- a/drivers/iio/accel/bmi088-accel-core.c
+++ b/drivers/iio/accel/bmi088-accel-core.c
@@ -464,6 +464,13 @@ static const struct iio_chan_spec bmi088_accel_channels[] = {
 };
 
 static const struct bmi088_accel_chip_info bmi088_accel_chip_info_tbl[] = {
+	[BOSCH_BMI085] = {
+		.name = "bmi085-accel",
+		.chip_id = 0x1F,
+		.channels = bmi088_accel_channels,
+		.num_channels = ARRAY_SIZE(bmi088_accel_channels),
+		.scale_table = {{0, 598}, {0, 1196}, {0, 2393}, {0, 4785}},
+	},
 	[BOSCH_BMI088] = {
 		.name = "bmi088-accel",
 		.chip_id = 0x1E,
diff --git a/drivers/iio/accel/bmi088-accel-spi.c b/drivers/iio/accel/bmi088-accel-spi.c
index c77aec01bc67..b14a1e5b986a 100644
--- a/drivers/iio/accel/bmi088-accel-spi.c
+++ b/drivers/iio/accel/bmi088-accel-spi.c
@@ -62,12 +62,14 @@ static void bmi088_accel_remove(struct spi_device *spi)
 }
 
 static const struct of_device_id bmi088_of_match[] = {
+	{ .compatible = "bosch,bmi085-accel" },
 	{ .compatible = "bosch,bmi088-accel" },
 	{}
 };
 MODULE_DEVICE_TABLE(of, bmi088_of_match);
 
 static const struct spi_device_id bmi088_accel_id[] = {
+	{"bmi085-accel",  BOSCH_BMI085},
 	{"bmi088-accel",  BOSCH_BMI088},
 	{}
 };
diff --git a/drivers/iio/accel/bmi088-accel.h b/drivers/iio/accel/bmi088-accel.h
index 65338a1bf97d..044999eb4fd6 100644
--- a/drivers/iio/accel/bmi088-accel.h
+++ b/drivers/iio/accel/bmi088-accel.h
@@ -9,6 +9,7 @@
 struct device;
 
 enum bmi_device_type {
+	BOSCH_BMI085,
 	BOSCH_BMI088,
 	BOSCH_UNKNOWN,
 };
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 5/6] iio: accel: bmi088: Add support for bmi090l accel
  2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
                   ` (3 preceding siblings ...)
  2022-05-25 13:08 ` [PATCH V4 4/6] iio: accel: bmi088: Add support for bmi085 accel LI Qingwu
@ 2022-05-25 13:08 ` LI Qingwu
  2022-05-25 13:08 ` [PATCH V4 6/6] dt-bindings: iio: accel: Add bmi085 and bmi090l bindings LI Qingwu
  5 siblings, 0 replies; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

Add supports for BMI090L, it's a high-performance Inertial
Measurement Unit, with an accelerometer and gyroscope.
The commit adds the accelerometer driver for the SPI interface.
The gyroscope part is already supported by the BMG160 driver.
Same as BMI088, BMI090L have the range of +/-3, 6, 12, and 24g.

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 | 7 +++++++
 drivers/iio/accel/bmi088-accel-spi.c  | 2 ++
 drivers/iio/accel/bmi088-accel.h      | 1 +
 3 files changed, 10 insertions(+)

diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c
index 18becc857d49..631cd66476ce 100644
--- a/drivers/iio/accel/bmi088-accel-core.c
+++ b/drivers/iio/accel/bmi088-accel-core.c
@@ -478,6 +478,13 @@ static const struct bmi088_accel_chip_info bmi088_accel_chip_info_tbl[] = {
 		.num_channels = ARRAY_SIZE(bmi088_accel_channels),
 		.scale_table = {{0, 897}, {0, 1794}, {0, 3589}, {0, 7178}},
 	},
+	[BOSCH_BMI090L] = {
+		.name = "bmi090l-accel",
+		.chip_id = 0x1A,
+		.channels = bmi088_accel_channels,
+		.num_channels = ARRAY_SIZE(bmi088_accel_channels),
+		.scale_table = {{0, 897}, {0, 1794}, {0, 3589}, {0, 7178}},
+	},
 };
 
 static const struct iio_info bmi088_accel_info = {
diff --git a/drivers/iio/accel/bmi088-accel-spi.c b/drivers/iio/accel/bmi088-accel-spi.c
index b14a1e5b986a..8aa25138f098 100644
--- a/drivers/iio/accel/bmi088-accel-spi.c
+++ b/drivers/iio/accel/bmi088-accel-spi.c
@@ -64,6 +64,7 @@ static void bmi088_accel_remove(struct spi_device *spi)
 static const struct of_device_id bmi088_of_match[] = {
 	{ .compatible = "bosch,bmi085-accel" },
 	{ .compatible = "bosch,bmi088-accel" },
+	{ .compatible = "bosch,bmi090l-accel" },
 	{}
 };
 MODULE_DEVICE_TABLE(of, bmi088_of_match);
@@ -71,6 +72,7 @@ MODULE_DEVICE_TABLE(of, bmi088_of_match);
 static const struct spi_device_id bmi088_accel_id[] = {
 	{"bmi085-accel",  BOSCH_BMI085},
 	{"bmi088-accel",  BOSCH_BMI088},
+	{"bmi090l-accel", BOSCH_BMI090L},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, bmi088_accel_id);
diff --git a/drivers/iio/accel/bmi088-accel.h b/drivers/iio/accel/bmi088-accel.h
index 044999eb4fd6..80cd396a3141 100644
--- a/drivers/iio/accel/bmi088-accel.h
+++ b/drivers/iio/accel/bmi088-accel.h
@@ -11,6 +11,7 @@ struct device;
 enum bmi_device_type {
 	BOSCH_BMI085,
 	BOSCH_BMI088,
+	BOSCH_BMI090L,
 	BOSCH_UNKNOWN,
 };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 6/6] dt-bindings: iio: accel: Add bmi085 and bmi090l bindings
  2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
                   ` (4 preceding siblings ...)
  2022-05-25 13:08 ` [PATCH V4 5/6] iio: accel: bmi088: Add support for bmi090l accel LI Qingwu
@ 2022-05-25 13:08 ` LI Qingwu
  5 siblings, 0 replies; 8+ messages in thread
From: LI Qingwu @ 2022-05-25 13:08 UTC (permalink / raw)
  To: jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, Qing-wu.Li, robh+dt, mike.looijmans, devicetree
  Cc: thomas.haemmerle

Adds the device-tree bindings for the Bosch
BMI085 and BMI090L IMU, the accelerometer part.

Datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi085-ds001.pdf
Datasheet: https://media.digikey.com/pdf/Data%20Sheets/Bosch/BST-BMI090L-DS000-00.pdf
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml
index 911a1ae9c83f..272eb48eef5a 100644
--- a/Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml
+++ b/Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml
@@ -17,7 +17,9 @@ description: |
 properties:
   compatible:
     enum:
+      - bosch,bmi085-accel
       - bosch,bmi088-accel
+      - bosch,bmi090l-accel
 
   reg:
     maxItems: 1
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate
  2022-05-25 13:08 ` [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate LI Qingwu
@ 2022-05-25 17:53   ` kernel test robot
  0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2022-05-25 17:53 UTC (permalink / raw)
  To: LI Qingwu, jic23, lars, mchehab+huawei, ardeleanalex, linux-iio,
	linux-kernel, robh+dt, mike.looijmans, devicetree
  Cc: llvm, kbuild-all, thomas.haemmerle

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	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-25 17:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 13:08 [PATCH V4 0/6] iio: accel: bmi088: support BMI085 BMI090L LI Qingwu
2022-05-25 13:08 ` [PATCH V4 1/6] iio: accel: bmi088: Modified the scale calculate LI Qingwu
2022-05-25 17:53   ` kernel test robot
2022-05-25 13:08 ` [PATCH V4 2/6] iio: accel: bmi088: Make it possible to config scales LI Qingwu
2022-05-25 13:08 ` [PATCH V4 3/6] iio: accel: bmi088: modified the device name LI Qingwu
2022-05-25 13:08 ` [PATCH V4 4/6] iio: accel: bmi088: Add support for bmi085 accel LI Qingwu
2022-05-25 13:08 ` [PATCH V4 5/6] iio: accel: bmi088: Add support for bmi090l accel LI Qingwu
2022-05-25 13:08 ` [PATCH V4 6/6] dt-bindings: iio: accel: Add bmi085 and bmi090l bindings LI Qingwu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.