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
19static 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(ptr: regmap))
25 return dev_err_probe(dev: &client->dev, err: PTR_ERR(ptr: regmap),
26 fmt: "Unable to init register map");
27
28 return bno055_probe(dev: &client->dev, regmap,
29 BNO055_I2C_XFER_BURST_BREAK_THRESHOLD, sw_reset: true);
30}
31
32static const struct i2c_device_id bno055_i2c_id[] = {
33 {"bno055", 0},
34 { }
35};
36MODULE_DEVICE_TABLE(i2c, bno055_i2c_id);
37
38static const struct of_device_id __maybe_unused bno055_i2c_of_match[] = {
39 { .compatible = "bosch,bno055" },
40 { }
41};
42MODULE_DEVICE_TABLE(of, bno055_i2c_of_match);
43
44static struct i2c_driver bno055_driver = {
45 .driver = {
46 .name = "bno055-i2c",
47 .of_match_table = bno055_i2c_of_match,
48 },
49 .probe = bno055_i2c_probe,
50 .id_table = bno055_i2c_id,
51};
52module_i2c_driver(bno055_driver);
53
54MODULE_AUTHOR("Andrea Merello");
55MODULE_DESCRIPTION("Bosch BNO055 I2C interface");
56MODULE_IMPORT_NS(IIO_BNO055);
57MODULE_LICENSE("GPL");
58

source code of linux/drivers/iio/imu/bno055/bno055_i2c.c