bno055_i2c.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <[email protected]>
  8. */
  9. #include <linux/i2c.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <linux/module.h>
  12. #include <linux/regmap.h>
  13. #include "bno055.h"
  14. #define BNO055_I2C_XFER_BURST_BREAK_THRESHOLD 3
  15. static int bno055_i2c_probe(struct i2c_client *client)
  16. {
  17. struct regmap *regmap;
  18. regmap = devm_regmap_init_i2c(client, &bno055_regmap_config);
  19. if (IS_ERR(regmap))
  20. return dev_err_probe(&client->dev, PTR_ERR(regmap),
  21. "Unable to init register map");
  22. return bno055_probe(&client->dev, regmap,
  23. BNO055_I2C_XFER_BURST_BREAK_THRESHOLD, true);
  24. }
  25. static const struct i2c_device_id bno055_i2c_id[] = {
  26. {"bno055", 0},
  27. { }
  28. };
  29. MODULE_DEVICE_TABLE(i2c, bno055_i2c_id);
  30. static const struct of_device_id __maybe_unused bno055_i2c_of_match[] = {
  31. { .compatible = "bosch,bno055" },
  32. { }
  33. };
  34. MODULE_DEVICE_TABLE(of, bno055_i2c_of_match);
  35. static struct i2c_driver bno055_driver = {
  36. .driver = {
  37. .name = "bno055-i2c",
  38. .of_match_table = bno055_i2c_of_match,
  39. },
  40. .probe_new = bno055_i2c_probe,
  41. .id_table = bno055_i2c_id,
  42. };
  43. module_i2c_driver(bno055_driver);
  44. MODULE_AUTHOR("Andrea Merello");
  45. MODULE_DESCRIPTION("Bosch BNO055 I2C interface");
  46. MODULE_IMPORT_NS(IIO_BNO055);
  47. MODULE_LICENSE("GPL");