adxl313.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * ADXL313 3-Axis Digital Accelerometer
  4. *
  5. * Copyright (c) 2021 Lucas Stankus <[email protected]>
  6. */
  7. #ifndef _ADXL313_H_
  8. #define _ADXL313_H_
  9. #include <linux/iio/iio.h>
  10. /* ADXL313 register definitions */
  11. #define ADXL313_REG_DEVID0 0x00
  12. #define ADXL313_REG_DEVID1 0x01
  13. #define ADXL313_REG_PARTID 0x02
  14. #define ADXL313_REG_XID 0x04
  15. #define ADXL313_REG_SOFT_RESET 0x18
  16. #define ADXL313_REG_OFS_AXIS(index) (0x1E + (index))
  17. #define ADXL313_REG_THRESH_ACT 0x24
  18. #define ADXL313_REG_ACT_INACT_CTL 0x27
  19. #define ADXL313_REG_BW_RATE 0x2C
  20. #define ADXL313_REG_POWER_CTL 0x2D
  21. #define ADXL313_REG_INT_MAP 0x2F
  22. #define ADXL313_REG_DATA_FORMAT 0x31
  23. #define ADXL313_REG_DATA_AXIS(index) (0x32 + ((index) * 2))
  24. #define ADXL313_REG_FIFO_CTL 0x38
  25. #define ADXL313_REG_FIFO_STATUS 0x39
  26. #define ADXL313_DEVID0 0xAD
  27. #define ADXL313_DEVID0_ADXL312_314 0xE5
  28. #define ADXL313_DEVID1 0x1D
  29. #define ADXL313_PARTID 0xCB
  30. #define ADXL313_SOFT_RESET 0x52
  31. #define ADXL313_RATE_MSK GENMASK(3, 0)
  32. #define ADXL313_RATE_BASE 6
  33. #define ADXL313_POWER_CTL_MSK GENMASK(3, 2)
  34. #define ADXL313_MEASUREMENT_MODE BIT(3)
  35. #define ADXL313_RANGE_MSK GENMASK(1, 0)
  36. #define ADXL313_RANGE_MAX 3
  37. #define ADXL313_FULL_RES BIT(3)
  38. #define ADXL313_SPI_3WIRE BIT(6)
  39. #define ADXL313_I2C_DISABLE BIT(6)
  40. extern const struct regmap_access_table adxl312_readable_regs_table;
  41. extern const struct regmap_access_table adxl313_readable_regs_table;
  42. extern const struct regmap_access_table adxl314_readable_regs_table;
  43. extern const struct regmap_access_table adxl312_writable_regs_table;
  44. extern const struct regmap_access_table adxl313_writable_regs_table;
  45. extern const struct regmap_access_table adxl314_writable_regs_table;
  46. enum adxl313_device_type {
  47. ADXL312,
  48. ADXL313,
  49. ADXL314,
  50. };
  51. struct adxl313_data {
  52. struct regmap *regmap;
  53. const struct adxl313_chip_info *chip_info;
  54. struct mutex lock; /* lock to protect transf_buf */
  55. __le16 transf_buf __aligned(IIO_DMA_MINALIGN);
  56. };
  57. struct adxl313_chip_info {
  58. const char *name;
  59. enum adxl313_device_type type;
  60. int scale_factor;
  61. bool variable_range;
  62. bool soft_reset;
  63. int (*check_id)(struct device *dev, struct adxl313_data *data);
  64. };
  65. extern const struct adxl313_chip_info adxl31x_chip_info[];
  66. int adxl313_core_probe(struct device *dev,
  67. struct regmap *regmap,
  68. const struct adxl313_chip_info *chip_info,
  69. int (*setup)(struct device *, struct regmap *));
  70. #endif /* _ADXL313_H_ */