ad7091r-base.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * AD7091RX Analog to Digital converter driver
  4. *
  5. * Copyright 2014-2019 Analog Devices Inc.
  6. */
  7. #ifndef __DRIVERS_IIO_ADC_AD7091R_BASE_H__
  8. #define __DRIVERS_IIO_ADC_AD7091R_BASE_H__
  9. #include <linux/regmap.h>
  10. #define AD7091R_REG_RESULT 0
  11. #define AD7091R_REG_CHANNEL 1
  12. #define AD7091R_REG_CONF 2
  13. #define AD7091R_REG_ALERT 3
  14. #define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
  15. #define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
  16. #define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
  17. /* AD7091R_REG_RESULT */
  18. #define AD7091R5_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3)
  19. #define AD7091R8_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x7)
  20. #define AD7091R_REG_RESULT_CONV_RESULT(x) ((x) & 0xfff)
  21. /* AD7091R_REG_CONF */
  22. #define AD7091R_REG_CONF_INT_VREF BIT(0)
  23. #define AD7091R_REG_CONF_ALERT_EN BIT(4)
  24. #define AD7091R_REG_CONF_AUTO BIT(8)
  25. #define AD7091R_REG_CONF_CMD BIT(10)
  26. #define AD7091R_REG_CONF_MODE_MASK \
  27. (AD7091R_REG_CONF_AUTO | AD7091R_REG_CONF_CMD)
  28. /* AD7091R_REG_CH_LIMIT */
  29. #define AD7091R_HIGH_LIMIT 0xFFF
  30. #define AD7091R_LOW_LIMIT 0x0
  31. #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
  32. .type = IIO_VOLTAGE, \
  33. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  34. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  35. .indexed = 1, \
  36. .channel = idx, \
  37. .event_spec = ev, \
  38. .num_event_specs = num_ev, \
  39. .scan_type.storagebits = 16, \
  40. .scan_type.realbits = bits, \
  41. }
  42. struct device;
  43. struct gpio_desc;
  44. enum ad7091r_mode {
  45. AD7091R_MODE_SAMPLE,
  46. AD7091R_MODE_COMMAND,
  47. AD7091R_MODE_AUTOCYCLE,
  48. };
  49. struct ad7091r_state {
  50. struct device *dev;
  51. struct regmap *map;
  52. struct gpio_desc *convst_gpio;
  53. struct gpio_desc *reset_gpio;
  54. struct regulator *vref;
  55. const struct ad7091r_chip_info *chip_info;
  56. enum ad7091r_mode mode;
  57. struct mutex lock; /*lock to prevent concurent reads */
  58. __be16 tx_buf __aligned(IIO_DMA_MINALIGN);
  59. __be16 rx_buf;
  60. };
  61. struct ad7091r_chip_info {
  62. const char *name;
  63. unsigned int num_channels;
  64. const struct iio_chan_spec *channels;
  65. unsigned int vref_mV;
  66. unsigned int (*reg_result_chan_id)(unsigned int val);
  67. int (*set_mode)(struct ad7091r_state *st, enum ad7091r_mode mode);
  68. };
  69. struct ad7091r_init_info {
  70. const struct ad7091r_chip_info *info_irq;
  71. const struct ad7091r_chip_info *info_no_irq;
  72. const struct regmap_config *regmap_config;
  73. void (*init_adc_regmap)(struct ad7091r_state *st,
  74. const struct regmap_config *regmap_conf);
  75. int (*setup)(struct ad7091r_state *st);
  76. };
  77. extern const struct iio_event_spec ad7091r_events[3];
  78. int ad7091r_probe(struct device *dev, const struct ad7091r_init_info *init_info,
  79. int irq);
  80. bool ad7091r_volatile_reg(struct device *dev, unsigned int reg);
  81. bool ad7091r_writeable_reg(struct device *dev, unsigned int reg);
  82. #endif /* __DRIVERS_IIO_ADC_AD7091R_BASE_H__ */