lkml.org 
[lkml]   [2022]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH V3 3/6] iio: accel: bmi088: modified the device name
Date
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 563bcc311844..c30c2d510b92 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 dd1e3f6cf211..24cdeb41d2a6 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 int bmi088_accel_remove(struct spi_device *spi)
@@ -61,8 +61,14 @@ static int bmi088_accel_remove(struct spi_device *spi)
return 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 5c25f16b672c..b6a0281a847f 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);
int bmi088_accel_core_remove(struct device *dev);

#endif /* BMI088_ACCEL_H */
--
2.25.1
\
 
 \ /
  Last update: 2022-05-18 17:09    [W:0.074 / U:0.260 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site