adxl345_i2c.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * ADXL345 3-Axis Digital Accelerometer I2C driver
  3. *
  4. * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
  5. *
  6. * This file is subject to the terms and conditions of version 2 of
  7. * the GNU General Public License. See the file COPYING in the main
  8. * directory of this archive for more details.
  9. *
  10. * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or
  11. * 0x53 (ALT ADDRESS pin grounded)
  12. */
  13. #include <linux/i2c.h>
  14. #include <linux/module.h>
  15. #include <linux/regmap.h>
  16. #include "adxl345.h"
  17. static const struct regmap_config adxl345_i2c_regmap_config = {
  18. .reg_bits = 8,
  19. .val_bits = 8,
  20. };
  21. static int adxl345_i2c_probe(struct i2c_client *client,
  22. const struct i2c_device_id *id)
  23. {
  24. struct regmap *regmap;
  25. regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
  26. if (IS_ERR(regmap)) {
  27. dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
  28. PTR_ERR(regmap));
  29. return PTR_ERR(regmap);
  30. }
  31. return adxl345_core_probe(&client->dev, regmap, id->driver_data,
  32. id ? id->name : NULL);
  33. }
  34. static int adxl345_i2c_remove(struct i2c_client *client)
  35. {
  36. return adxl345_core_remove(&client->dev);
  37. }
  38. static const struct i2c_device_id adxl345_i2c_id[] = {
  39. { "adxl345", ADXL345 },
  40. { "adxl375", ADXL375 },
  41. { }
  42. };
  43. MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
  44. static const struct of_device_id adxl345_of_match[] = {
  45. { .compatible = "adi,adxl345" },
  46. { .compatible = "adi,adxl375" },
  47. { },
  48. };
  49. MODULE_DEVICE_TABLE(of, adxl345_of_match);
  50. static struct i2c_driver adxl345_i2c_driver = {
  51. .driver = {
  52. .name = "adxl345_i2c",
  53. .of_match_table = adxl345_of_match,
  54. },
  55. .probe = adxl345_i2c_probe,
  56. .remove = adxl345_i2c_remove,
  57. .id_table = adxl345_i2c_id,
  58. };
  59. module_i2c_driver(adxl345_i2c_driver);
  60. MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
  61. MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
  62. MODULE_LICENSE("GPL v2");