Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: accel: bmi088: add i2c support for bmi088 accel driver

The BMI088, BMI085 and BMI090L accelerometer also support
I2C protocol, so let's add the missing I2C support.

The I2C interface of the {BMI085,BMI088,BMI090L} is compatible with
the I2C Specification UM10204 Rev. 03 (19 June 2007), available at
http://www.nxp.com. The {BMI085,BMI088,BMI090L} supports I2C standard
mode and fast mode, only 7-bit address mode is supported.

Datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi085-ds001.pdf
Datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi088-ds001.pdf
Datasheet: https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/4807/BST-BMI090L-DS000-00.pdf
Signed-off-by: Jun Yan <jerrysteve1101@gmail.com>

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312191325.jfiyeL5F-lkp@intel.com/
Link: https://lore.kernel.org/r/20231219150440.264033-1-jerrysteve1101@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jun Yan and committed by
Jonathan Cameron
b2463c49 3ab574ee

+77 -2
+6 -2
drivers/iio/accel/Kconfig
··· 254 254 255 255 config BMI088_ACCEL 256 256 tristate "Bosch BMI088 Accelerometer Driver" 257 - depends on SPI 258 257 select IIO_BUFFER 259 258 select IIO_TRIGGERED_BUFFER 260 259 select REGMAP 261 - select BMI088_ACCEL_SPI 260 + select BMI088_ACCEL_SPI if SPI 261 + select BMI088_ACCEL_I2C if I2C 262 262 help 263 263 Say yes here to build support for the following Bosch accelerometers: 264 264 BMI088, BMI085, BMI090L. Note that all of these are combo module that ··· 266 266 267 267 This driver only implements the accelerometer part, which has its own 268 268 address and register map. BMG160 provides the gyroscope driver. 269 + 270 + config BMI088_ACCEL_I2C 271 + tristate 272 + select REGMAP_I2C 269 273 270 274 config BMI088_ACCEL_SPI 271 275 tristate
+1
drivers/iio/accel/Makefile
··· 30 30 obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o 31 31 obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o 32 32 obj-$(CONFIG_BMI088_ACCEL) += bmi088-accel-core.o 33 + obj-$(CONFIG_BMI088_ACCEL_I2C) += bmi088-accel-i2c.o 33 34 obj-$(CONFIG_BMI088_ACCEL_SPI) += bmi088-accel-spi.o 34 35 obj-$(CONFIG_DA280) += da280.o 35 36 obj-$(CONFIG_DA311) += da311.o
+70
drivers/iio/accel/bmi088-accel-i2c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * 3-axis accelerometer driver supporting following Bosch-Sensortec chips: 4 + * - BMI088 5 + * - BMI085 6 + * - BMI090L 7 + * 8 + * Copyright 2023 Jun Yan <jerrysteve1101@gmail.com> 9 + */ 10 + 11 + #include <linux/i2c.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/module.h> 14 + #include <linux/regmap.h> 15 + #include <linux/slab.h> 16 + 17 + #include "bmi088-accel.h" 18 + 19 + static int bmi088_accel_probe(struct i2c_client *i2c) 20 + { 21 + struct regmap *regmap; 22 + const struct i2c_device_id *id = i2c_client_get_device_id(i2c); 23 + 24 + regmap = devm_regmap_init_i2c(i2c, &bmi088_regmap_conf); 25 + if (IS_ERR(regmap)) { 26 + dev_err(&i2c->dev, "Failed to initialize i2c regmap\n"); 27 + return PTR_ERR(regmap); 28 + } 29 + 30 + return bmi088_accel_core_probe(&i2c->dev, regmap, i2c->irq, 31 + id->driver_data); 32 + } 33 + 34 + static void bmi088_accel_remove(struct i2c_client *i2c) 35 + { 36 + bmi088_accel_core_remove(&i2c->dev); 37 + } 38 + 39 + static const struct of_device_id bmi088_of_match[] = { 40 + { .compatible = "bosch,bmi085-accel" }, 41 + { .compatible = "bosch,bmi088-accel" }, 42 + { .compatible = "bosch,bmi090l-accel" }, 43 + {} 44 + }; 45 + MODULE_DEVICE_TABLE(of, bmi088_of_match); 46 + 47 + static const struct i2c_device_id bmi088_accel_id[] = { 48 + { "bmi085-accel", BOSCH_BMI085 }, 49 + { "bmi088-accel", BOSCH_BMI088 }, 50 + { "bmi090l-accel", BOSCH_BMI090L }, 51 + {} 52 + }; 53 + MODULE_DEVICE_TABLE(i2c, bmi088_accel_id); 54 + 55 + static struct i2c_driver bmi088_accel_driver = { 56 + .driver = { 57 + .name = "bmi088_accel_i2c", 58 + .pm = pm_ptr(&bmi088_accel_pm_ops), 59 + .of_match_table = bmi088_of_match, 60 + }, 61 + .probe = bmi088_accel_probe, 62 + .remove = bmi088_accel_remove, 63 + .id_table = bmi088_accel_id, 64 + }; 65 + module_i2c_driver(bmi088_accel_driver); 66 + 67 + MODULE_AUTHOR("Jun Yan <jerrysteve1101@gmail.com>"); 68 + MODULE_LICENSE("GPL"); 69 + MODULE_DESCRIPTION("BMI088 accelerometer driver (I2C)"); 70 + MODULE_IMPORT_NS(IIO_BMI088);