adxl345_i2c.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <eraretuya@gmail.com>
  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, NULL);
  25. }
  26. static const struct adxl345_chip_info adxl345_i2c_info = {
  27. .name = "adxl345",
  28. .uscale = ADXL345_USCALE,
  29. };
  30. static const struct adxl345_chip_info adxl375_i2c_info = {
  31. .name = "adxl375",
  32. .uscale = ADXL375_USCALE,
  33. };
  34. static const struct i2c_device_id adxl345_i2c_id[] = {
  35. { "adxl345", (kernel_ulong_t)&adxl345_i2c_info },
  36. { "adxl375", (kernel_ulong_t)&adxl375_i2c_info },
  37. { }
  38. };
  39. MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
  40. static const struct of_device_id adxl345_of_match[] = {
  41. { .compatible = "adi,adxl345", .data = &adxl345_i2c_info },
  42. { .compatible = "adi,adxl375", .data = &adxl375_i2c_info },
  43. { }
  44. };
  45. MODULE_DEVICE_TABLE(of, adxl345_of_match);
  46. static const struct acpi_device_id adxl345_acpi_match[] = {
  47. { "ADS0345", (kernel_ulong_t)&adxl345_i2c_info },
  48. { }
  49. };
  50. MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
  51. static struct i2c_driver adxl345_i2c_driver = {
  52. .driver = {
  53. .name = "adxl345_i2c",
  54. .of_match_table = adxl345_of_match,
  55. .acpi_match_table = adxl345_acpi_match,
  56. },
  57. .probe = adxl345_i2c_probe,
  58. .id_table = adxl345_i2c_id,
  59. };
  60. module_i2c_driver(adxl345_i2c_driver);
  61. MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
  62. MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
  63. MODULE_LICENSE("GPL v2");
  64. MODULE_IMPORT_NS(IIO_ADXL345);