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

iio: imu: add BNO055 I2C driver

Add an I2C driver for communicating to a BNO055 IMU via I2C bus and enable
the BNO055 core driver to work in this scenario.

Signed-off-by: Andrea Merello <andrea.merello@iit.it>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220907132205.28021-14-andrea.merello@iit.it
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andrea Merello and committed by
Jonathan Cameron
50fe984f 2eef5a9c

+70
+11
drivers/iio/imu/bno055/Kconfig
··· 12 12 13 13 This driver can also be built as a module. If so, the module will be 14 14 called bno055_sl. 15 + 16 + config BOSCH_BNO055_I2C 17 + tristate "Bosch BNO055 attached via I2C bus" 18 + depends on I2C 19 + select REGMAP_I2C 20 + select BOSCH_BNO055 21 + help 22 + Enable this to support Bosch BNO055 IMUs attached via I2C bus. 23 + 24 + This driver can also be built as a module. If so, the module will be 25 + called bno055_i2c.
+2
drivers/iio/imu/bno055/Makefile
··· 6 6 # define_trace.h needs to know how to find our header 7 7 CFLAGS_bno055_ser_trace.o := -I$(src) 8 8 bno055_ser-$(CONFIG_TRACING) += bno055_ser_trace.o 9 + 10 + obj-$(CONFIG_BOSCH_BNO055_I2C) += bno055_i2c.o
+57
drivers/iio/imu/bno055/bno055_i2c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Support for I2C-interfaced Bosch BNO055 IMU. 4 + * 5 + * Copyright (C) 2021-2022 Istituto Italiano di Tecnologia 6 + * Electronic Design Laboratory 7 + * Written by Andrea Merello <andrea.merello@iit.it> 8 + */ 9 + 10 + #include <linux/i2c.h> 11 + #include <linux/mod_devicetable.h> 12 + #include <linux/module.h> 13 + #include <linux/regmap.h> 14 + 15 + #include "bno055.h" 16 + 17 + #define BNO055_I2C_XFER_BURST_BREAK_THRESHOLD 3 18 + 19 + static int bno055_i2c_probe(struct i2c_client *client) 20 + { 21 + struct regmap *regmap; 22 + 23 + regmap = devm_regmap_init_i2c(client, &bno055_regmap_config); 24 + if (IS_ERR(regmap)) 25 + return dev_err_probe(&client->dev, PTR_ERR(regmap), 26 + "Unable to init register map"); 27 + 28 + return bno055_probe(&client->dev, regmap, 29 + BNO055_I2C_XFER_BURST_BREAK_THRESHOLD, true); 30 + } 31 + 32 + static const struct i2c_device_id bno055_i2c_id[] = { 33 + {"bno055", 0}, 34 + { } 35 + }; 36 + MODULE_DEVICE_TABLE(i2c, bno055_i2c_id); 37 + 38 + static const struct of_device_id __maybe_unused bno055_i2c_of_match[] = { 39 + { .compatible = "bosch,bno055" }, 40 + { } 41 + }; 42 + MODULE_DEVICE_TABLE(of, bno055_i2c_of_match); 43 + 44 + static struct i2c_driver bno055_driver = { 45 + .driver = { 46 + .name = "bno055-i2c", 47 + .of_match_table = bno055_i2c_of_match, 48 + }, 49 + .probe_new = bno055_i2c_probe, 50 + .id_table = bno055_i2c_id, 51 + }; 52 + module_i2c_driver(bno055_driver); 53 + 54 + MODULE_AUTHOR("Andrea Merello"); 55 + MODULE_DESCRIPTION("Bosch BNO055 I2C interface"); 56 + MODULE_IMPORT_NS(IIO_BNO055); 57 + MODULE_LICENSE("GPL");