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;
};
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),
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);
}
/* 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;
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;
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)
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);
.driver = {
.name = "bmi088_accel_spi",
.pm = &bmi088_accel_pm_ops,
+ .of_match_table = bmi088_of_match,
},
.probe = bmi088_accel_probe,
.remove = bmi088_accel_remove,
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 */