adxl355_i2c.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADXL355 3-Axis Digital Accelerometer I2C driver
  4. *
  5. * Copyright (c) 2021 Puranjay Mohan <puranjay12@gmail.com>
  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. const struct adxl355_chip_info *chip_data;
  23. chip_data = i2c_get_match_data(client);
  24. if (!chip_data)
  25. return -ENODEV;
  26. regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
  27. if (IS_ERR(regmap)) {
  28. dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
  29. PTR_ERR(regmap));
  30. return PTR_ERR(regmap);
  31. }
  32. return adxl355_core_probe(&client->dev, regmap, chip_data);
  33. }
  34. static const struct i2c_device_id adxl355_i2c_id[] = {
  35. { "adxl355", (kernel_ulong_t)&adxl35x_chip_info[ADXL355] },
  36. { "adxl359", (kernel_ulong_t)&adxl35x_chip_info[ADXL359] },
  37. { }
  38. };
  39. MODULE_DEVICE_TABLE(i2c, adxl355_i2c_id);
  40. static const struct of_device_id adxl355_of_match[] = {
  41. { .compatible = "adi,adxl355", .data = &adxl35x_chip_info[ADXL355] },
  42. { .compatible = "adi,adxl359", .data = &adxl35x_chip_info[ADXL359] },
  43. { }
  44. };
  45. MODULE_DEVICE_TABLE(of, adxl355_of_match);
  46. static struct i2c_driver adxl355_i2c_driver = {
  47. .driver = {
  48. .name = "adxl355_i2c",
  49. .of_match_table = adxl355_of_match,
  50. },
  51. .probe = adxl355_i2c_probe,
  52. .id_table = adxl355_i2c_id,
  53. };
  54. module_i2c_driver(adxl355_i2c_driver);
  55. MODULE_AUTHOR("Puranjay Mohan <puranjay12@gmail.com>");
  56. MODULE_DESCRIPTION("ADXL355 3-Axis Digital Accelerometer I2C driver");
  57. MODULE_LICENSE("GPL v2");
  58. MODULE_IMPORT_NS(IIO_ADXL355);