adxl345_i2c.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADXL345 3-Axis Digital Accelerometer I2C driver
  4. *
  5. * Copyright (c) 2017 Eva Rachel Retuya <[email protected]>
  6. *
  7. * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or
  8. * 0x53 (ALT ADDRESS pin grounded)
  9. */
  10. #include <linux/i2c.h>
  11. #include <linux/module.h>
  12. #include <linux/regmap.h>
  13. #include "adxl345.h"
  14. static const struct regmap_config adxl345_i2c_regmap_config = {
  15. .reg_bits = 8,
  16. .val_bits = 8,
  17. };
  18. static int adxl345_i2c_probe(struct i2c_client *client)
  19. {
  20. struct regmap *regmap;
  21. regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
  22. if (IS_ERR(regmap))
  23. return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
  24. return adxl345_core_probe(&client->dev, regmap);
  25. }
  26. static const struct i2c_device_id adxl345_i2c_id[] = {
  27. { "adxl345", ADXL345 },
  28. { "adxl375", ADXL375 },
  29. { }
  30. };
  31. MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
  32. static const struct of_device_id adxl345_of_match[] = {
  33. { .compatible = "adi,adxl345", .data = (const void *)ADXL345 },
  34. { .compatible = "adi,adxl375", .data = (const void *)ADXL375 },
  35. { }
  36. };
  37. MODULE_DEVICE_TABLE(of, adxl345_of_match);
  38. static const struct acpi_device_id adxl345_acpi_match[] = {
  39. { "ADS0345", ADXL345 },
  40. { }
  41. };
  42. MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
  43. static struct i2c_driver adxl345_i2c_driver = {
  44. .driver = {
  45. .name = "adxl345_i2c",
  46. .of_match_table = adxl345_of_match,
  47. .acpi_match_table = adxl345_acpi_match,
  48. },
  49. .probe_new = adxl345_i2c_probe,
  50. .id_table = adxl345_i2c_id,
  51. };
  52. module_i2c_driver(adxl345_i2c_driver);
  53. MODULE_AUTHOR("Eva Rachel Retuya <[email protected]>");
  54. MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
  55. MODULE_LICENSE("GPL v2");
  56. MODULE_IMPORT_NS(IIO_ADXL345);