1 /* SPDX-License-Identifier: GPL-2.0 */
3 * AD7091RX Analog to Digital converter driver
5 * Copyright 2014-2019 Analog Devices Inc.
8 #ifndef __DRIVERS_IIO_ADC_AD7091R_BASE_H__
9 #define __DRIVERS_IIO_ADC_AD7091R_BASE_H__
11 #include <linux/regmap.h>
13 #define AD7091R_REG_RESULT 0
14 #define AD7091R_REG_CHANNEL 1
15 #define AD7091R_REG_CONF 2
16 #define AD7091R_REG_ALERT 3
17 #define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
18 #define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
19 #define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
21 /* AD7091R_REG_RESULT */
22 #define AD7091R5_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3)
23 #define AD7091R8_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x7)
24 #define AD7091R_REG_RESULT_CONV_RESULT(x) ((x) & 0xfff)
26 /* AD7091R_REG_CONF */
27 #define AD7091R_REG_CONF_INT_VREF BIT(0)
28 #define AD7091R_REG_CONF_ALERT_EN BIT(4)
29 #define AD7091R_REG_CONF_AUTO BIT(8)
30 #define AD7091R_REG_CONF_CMD BIT(10)
32 #define AD7091R_REG_CONF_MODE_MASK \
33 (AD7091R_REG_CONF_AUTO | AD7091R_REG_CONF_CMD)
35 /* AD7091R_REG_CH_LIMIT */
36 #define AD7091R_HIGH_LIMIT 0xFFF
37 #define AD7091R_LOW_LIMIT 0x0
39 #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
40 .type = IIO_VOLTAGE, \
41 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
42 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
46 .num_event_specs = num_ev, \
47 .scan_type.storagebits = 16, \
48 .scan_type.realbits = bits, \
57 AD7091R_MODE_AUTOCYCLE
,
60 struct ad7091r_state
{
63 struct gpio_desc
*convst_gpio
;
64 struct gpio_desc
*reset_gpio
;
65 struct regulator
*vref
;
66 const struct ad7091r_chip_info
*chip_info
;
67 enum ad7091r_mode mode
;
68 struct mutex lock
; /*lock to prevent concurrent reads */
69 __be16 tx_buf
__aligned(IIO_DMA_MINALIGN
);
73 struct ad7091r_chip_info
{
75 unsigned int num_channels
;
76 const struct iio_chan_spec
*channels
;
78 unsigned int (*reg_result_chan_id
)(unsigned int val
);
79 int (*set_mode
)(struct ad7091r_state
*st
, enum ad7091r_mode mode
);
82 struct ad7091r_init_info
{
83 const struct ad7091r_chip_info
*info_irq
;
84 const struct ad7091r_chip_info
*info_no_irq
;
85 const struct regmap_config
*regmap_config
;
86 void (*init_adc_regmap
)(struct ad7091r_state
*st
,
87 const struct regmap_config
*regmap_conf
);
88 int (*setup
)(struct ad7091r_state
*st
);
91 extern const struct iio_event_spec ad7091r_events
[3];
93 int ad7091r_probe(struct device
*dev
, const struct ad7091r_init_info
*init_info
,
96 bool ad7091r_volatile_reg(struct device
*dev
, unsigned int reg
);
97 bool ad7091r_writeable_reg(struct device
*dev
, unsigned int reg
);
99 #endif /* __DRIVERS_IIO_ADC_AD7091R_BASE_H__ */