adxl372_i2c.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * ADXL372 3-Axis Digital Accelerometer I2C driver
  4. *
  5. * Copyright 2018 Analog Devices Inc.
  6. */
  7. #include <linux/i2c.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/module.h>
  10. #include <linux/regmap.h>
  11. #include "adxl372.h"
  12. static const struct regmap_config adxl372_regmap_config = {
  13. .reg_bits = 8,
  14. .val_bits = 8,
  15. .readable_noinc_reg = adxl372_readable_noinc_reg,
  16. };
  17. static int adxl372_i2c_probe(struct i2c_client *client,
  18. const struct i2c_device_id *id)
  19. {
  20. struct regmap *regmap;
  21. unsigned int regval;
  22. int ret;
  23. regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config);
  24. if (IS_ERR(regmap))
  25. return PTR_ERR(regmap);
  26. ret = regmap_read(regmap, ADXL372_REVID, &regval);
  27. if (ret < 0)
  28. return ret;
  29. /* Starting with the 3rd revision an I2C chip bug was fixed */
  30. if (regval < 3)
  31. dev_warn(&client->dev,
  32. "I2C might not work properly with other devices on the bus");
  33. return adxl372_probe(&client->dev, regmap, client->irq, id->name);
  34. }
  35. static const struct i2c_device_id adxl372_i2c_id[] = {
  36. { "adxl372", 0 },
  37. {}
  38. };
  39. MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id);
  40. static const struct of_device_id adxl372_of_match[] = {
  41. { .compatible = "adi,adxl372" },
  42. { }
  43. };
  44. MODULE_DEVICE_TABLE(of, adxl372_of_match);
  45. static struct i2c_driver adxl372_i2c_driver = {
  46. .driver = {
  47. .name = "adxl372_i2c",
  48. .of_match_table = adxl372_of_match,
  49. },
  50. .probe = adxl372_i2c_probe,
  51. .id_table = adxl372_i2c_id,
  52. };
  53. module_i2c_driver(adxl372_i2c_driver);
  54. MODULE_AUTHOR("Stefan Popa <[email protected]>");
  55. MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver");
  56. MODULE_LICENSE("GPL");
  57. MODULE_IMPORT_NS(IIO_ADXL372);