Commit cedb9bd8 authored by Danila Tikhonov's avatar Danila Tikhonov Committed by Jonathan Cameron

iio: imu: bmi160: add support for bmi120

Add support for bmi120 low power variant of bmi160.
Relax failure to match ID to a warning rather than probe fail.
This allows for fallback compatibles, whilst retaining a useful
debugging message if they turn out not to be so compatible due to
badly behaved firmware.
Signed-off-by: default avatarDanila Tikhonov <danila@jiaxyga.com>
Co-developed-by: default avatarBarnabás Czémán <trabarni@gmail.com>
Signed-off-by: default avatarBarnabás Czémán <trabarni@gmail.com>
Link: https://lore.kernel.org/r/20240505-bmi120-v3-1-15cee3d0b2ef@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent eef36819
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "bmi160.h" #include "bmi160.h"
#define BMI160_REG_CHIP_ID 0x00 #define BMI160_REG_CHIP_ID 0x00
#define BMI120_CHIP_ID_VAL 0xD3
#define BMI160_CHIP_ID_VAL 0xD1 #define BMI160_CHIP_ID_VAL 0xD1
#define BMI160_REG_PMU_STATUS 0x03 #define BMI160_REG_PMU_STATUS 0x03
...@@ -112,6 +113,11 @@ ...@@ -112,6 +113,11 @@
.ext_info = bmi160_ext_info, \ .ext_info = bmi160_ext_info, \
} }
static const u8 bmi_chip_ids[] = {
BMI120_CHIP_ID_VAL,
BMI160_CHIP_ID_VAL,
};
/* scan indexes follow DATA register order */ /* scan indexes follow DATA register order */
enum bmi160_scan_axis { enum bmi160_scan_axis {
BMI160_SCAN_EXT_MAGN_X = 0, BMI160_SCAN_EXT_MAGN_X = 0,
...@@ -704,6 +710,16 @@ static int bmi160_setup_irq(struct iio_dev *indio_dev, int irq, ...@@ -704,6 +710,16 @@ static int bmi160_setup_irq(struct iio_dev *indio_dev, int irq,
return bmi160_probe_trigger(indio_dev, irq, irq_type); return bmi160_probe_trigger(indio_dev, irq, irq_type);
} }
static int bmi160_check_chip_id(const u8 chip_id)
{
for (int i = 0; i < ARRAY_SIZE(bmi_chip_ids); i++) {
if (chip_id == bmi_chip_ids[i])
return 0;
}
return -ENODEV;
}
static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
{ {
int ret; int ret;
...@@ -737,12 +753,10 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) ...@@ -737,12 +753,10 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
dev_err(dev, "Error reading chip id\n"); dev_err(dev, "Error reading chip id\n");
goto disable_regulator; goto disable_regulator;
} }
if (val != BMI160_CHIP_ID_VAL) {
dev_err(dev, "Wrong chip id, got %x expected %x\n", ret = bmi160_check_chip_id(val);
val, BMI160_CHIP_ID_VAL); if (ret)
ret = -ENODEV; dev_warn(dev, "Chip id not found: %x\n", val);
goto disable_regulator;
}
ret = bmi160_set_mode(data, BMI160_ACCEL, true); ret = bmi160_set_mode(data, BMI160_ACCEL, true);
if (ret) if (ret)
......
...@@ -37,6 +37,7 @@ static int bmi160_i2c_probe(struct i2c_client *client) ...@@ -37,6 +37,7 @@ static int bmi160_i2c_probe(struct i2c_client *client)
} }
static const struct i2c_device_id bmi160_i2c_id[] = { static const struct i2c_device_id bmi160_i2c_id[] = {
{"bmi120", 0},
{"bmi160", 0}, {"bmi160", 0},
{} {}
}; };
...@@ -52,12 +53,14 @@ static const struct acpi_device_id bmi160_acpi_match[] = { ...@@ -52,12 +53,14 @@ static const struct acpi_device_id bmi160_acpi_match[] = {
* the affected devices are from 2021/2022. * the affected devices are from 2021/2022.
*/ */
{"10EC5280", 0}, {"10EC5280", 0},
{"BMI0120", 0},
{"BMI0160", 0}, {"BMI0160", 0},
{ }, { },
}; };
MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
static const struct of_device_id bmi160_of_match[] = { static const struct of_device_id bmi160_of_match[] = {
{ .compatible = "bosch,bmi120" },
{ .compatible = "bosch,bmi160" }, { .compatible = "bosch,bmi160" },
{ }, { },
}; };
......
...@@ -34,18 +34,21 @@ static int bmi160_spi_probe(struct spi_device *spi) ...@@ -34,18 +34,21 @@ static int bmi160_spi_probe(struct spi_device *spi)
} }
static const struct spi_device_id bmi160_spi_id[] = { static const struct spi_device_id bmi160_spi_id[] = {
{"bmi120", 0},
{"bmi160", 0}, {"bmi160", 0},
{} {}
}; };
MODULE_DEVICE_TABLE(spi, bmi160_spi_id); MODULE_DEVICE_TABLE(spi, bmi160_spi_id);
static const struct acpi_device_id bmi160_acpi_match[] = { static const struct acpi_device_id bmi160_acpi_match[] = {
{"BMI0120", 0},
{"BMI0160", 0}, {"BMI0160", 0},
{ }, { },
}; };
MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
static const struct of_device_id bmi160_of_match[] = { static const struct of_device_id bmi160_of_match[] = {
{ .compatible = "bosch,bmi120" },
{ .compatible = "bosch,bmi160" }, { .compatible = "bosch,bmi160" },
{ }, { },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment