summaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/ad7091r-base.h
blob: b63c658a9d2384dcb64908ed2ebaded6725d0873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * AD7091RX Analog to Digital converter driver
 *
 * Copyright 2014-2019 Analog Devices Inc.
 */

#ifndef __DRIVERS_IIO_ADC_AD7091R_BASE_H__
#define __DRIVERS_IIO_ADC_AD7091R_BASE_H__

#define AD7091R_REG_RESULT  0
#define AD7091R_REG_CHANNEL 1
#define AD7091R_REG_CONF    2
#define AD7091R_REG_ALERT   3
#define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
#define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
#define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)

#define AD7091R_REG_CONF_INT_VREF	BIT(0)

/* AD7091R_REG_CH_LIMIT */
#define AD7091R_HIGH_LIMIT		0xFFF
#define AD7091R_LOW_LIMIT		0x0

#define AD7091R_CHANNEL(idx, bits, ev, num_ev) {			\
	.type = IIO_VOLTAGE,						\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
	.indexed = 1,							\
	.channel = idx,							\
	.event_spec = ev,						\
	.num_event_specs = num_ev,					\
	.scan_type.storagebits = 16,					\
	.scan_type.realbits = bits,					\
}

struct device;

enum ad7091r_mode {
	AD7091R_MODE_SAMPLE,
	AD7091R_MODE_COMMAND,
	AD7091R_MODE_AUTOCYCLE,
};

struct ad7091r_state {
	struct device *dev;
	struct regmap *map;
	struct regulator *vref;
	const struct ad7091r_chip_info *chip_info;
	enum ad7091r_mode mode;
	struct mutex lock; /*lock to prevent concurent reads */
};

struct ad7091r_chip_info {
	unsigned int num_channels;
	const struct iio_chan_spec *channels;
	unsigned int vref_mV;
};

extern const struct iio_event_spec ad7091r_events[3];

extern const struct regmap_config ad7091r_regmap_config;

int ad7091r_probe(struct device *dev, const char *name,
		const struct ad7091r_chip_info *chip_info,
		struct regmap *map, int irq);

bool ad7091r_volatile_reg(struct device *dev, unsigned int reg);
bool ad7091r_writeable_reg(struct device *dev, unsigned int reg);

#endif /* __DRIVERS_IIO_ADC_AD7091R_BASE_H__ */