adxl355_i2c.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADXL355 3-Axis Digital Accelerometer I2C driver
  4. *
  5. * Copyright (c) 2021 Puranjay Mohan <[email protected]>
  6. */
  7. #include <linux/i2c.h>
  8. #include <linux/module.h>
  9. #include <linux/mod_devicetable.h>
  10. #include <linux/regmap.h>
  11. #include "adxl355.h"
  12. static const struct regmap_config adxl355_i2c_regmap_config = {
  13. .reg_bits = 8,
  14. .val_bits = 8,
  15. .max_register = 0x2F,
  16. .rd_table = &adxl355_readable_regs_tbl,
  17. .wr_table = &adxl355_writeable_regs_tbl,
  18. };
  19. static int adxl355_i2c_probe(struct i2c_client *client)
  20. {
  21. struct regmap *regmap;
  22. regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
  23. if (IS_ERR(regmap)) {
  24. dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
  25. PTR_ERR(regmap));
  26. return PTR_ERR(regmap);
  27. }
  28. return adxl355_core_probe(&client->dev, regmap, client->name);
  29. }
  30. static const struct i2c_device_id adxl355_i2c_id[] = {
  31. { "adxl355", 0 },
  32. { }
  33. };
  34. MODULE_DEVICE_TABLE(i2c, adxl355_i2c_id);
  35. static const struct of_device_id adxl355_of_match[] = {
  36. { .compatible = "adi,adxl355" },
  37. { }
  38. };
  39. MODULE_DEVICE_TABLE(of, adxl355_of_match);
  40. static struct i2c_driver adxl355_i2c_driver = {
  41. .driver = {
  42. .name = "adxl355_i2c",
  43. .of_match_table = adxl355_of_match,
  44. },
  45. .probe_new = adxl355_i2c_probe,
  46. .id_table = adxl355_i2c_id,
  47. };
  48. module_i2c_driver(adxl355_i2c_driver);
  49. MODULE_AUTHOR("Puranjay Mohan <[email protected]>");
  50. MODULE_DESCRIPTION("ADXL355 3-Axis Digital Accelerometer I2C driver");
  51. MODULE_LICENSE("GPL v2");
  52. MODULE_IMPORT_NS(IIO_ADXL355);