bma400_i2c.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * I2C IIO driver for Bosch BMA400 triaxial acceleration sensor.
  4. *
  5. * Copyright 2019 Dan Robertson <[email protected]>
  6. *
  7. * I2C address is either 0x14 or 0x15 depending on SDO
  8. */
  9. #include <linux/i2c.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <linux/module.h>
  12. #include <linux/regmap.h>
  13. #include "bma400.h"
  14. static int bma400_i2c_probe(struct i2c_client *client,
  15. const struct i2c_device_id *id)
  16. {
  17. struct regmap *regmap;
  18. regmap = devm_regmap_init_i2c(client, &bma400_regmap_config);
  19. if (IS_ERR(regmap)) {
  20. dev_err(&client->dev, "failed to create regmap\n");
  21. return PTR_ERR(regmap);
  22. }
  23. return bma400_probe(&client->dev, regmap, client->irq, id->name);
  24. }
  25. static const struct i2c_device_id bma400_i2c_ids[] = {
  26. { "bma400", 0 },
  27. { }
  28. };
  29. MODULE_DEVICE_TABLE(i2c, bma400_i2c_ids);
  30. static const struct of_device_id bma400_of_i2c_match[] = {
  31. { .compatible = "bosch,bma400" },
  32. { }
  33. };
  34. MODULE_DEVICE_TABLE(of, bma400_of_i2c_match);
  35. static struct i2c_driver bma400_i2c_driver = {
  36. .driver = {
  37. .name = "bma400",
  38. .of_match_table = bma400_of_i2c_match,
  39. },
  40. .probe = bma400_i2c_probe,
  41. .id_table = bma400_i2c_ids,
  42. };
  43. module_i2c_driver(bma400_i2c_driver);
  44. MODULE_AUTHOR("Dan Robertson <[email protected]>");
  45. MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor (I2C)");
  46. MODULE_LICENSE("GPL");
  47. MODULE_IMPORT_NS(IIO_BMA400);