1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * AD5592R / AD5593R Digital <-> Analog converters driver
5 * Copyright 2015-2016 Analog Devices Inc.
6 * Author: Paul Cercueil <paul.cercueil@analog.com>
9 #ifndef __DRIVERS_IIO_DAC_AD5592R_BASE_H__
10 #define __DRIVERS_IIO_DAC_AD5592R_BASE_H__
12 #include <linux/types.h>
13 #include <linux/cache.h>
14 #include <linux/mutex.h>
15 #include <linux/gpio/driver.h>
20 enum ad5592r_registers
{
21 AD5592R_REG_NOOP
= 0x0,
22 AD5592R_REG_DAC_READBACK
= 0x1,
23 AD5592R_REG_ADC_SEQ
= 0x2,
24 AD5592R_REG_CTRL
= 0x3,
25 AD5592R_REG_ADC_EN
= 0x4,
26 AD5592R_REG_DAC_EN
= 0x5,
27 AD5592R_REG_PULLDOWN
= 0x6,
28 AD5592R_REG_LDAC
= 0x7,
29 AD5592R_REG_GPIO_OUT_EN
= 0x8,
30 AD5592R_REG_GPIO_SET
= 0x9,
31 AD5592R_REG_GPIO_IN_EN
= 0xA,
33 AD5592R_REG_OPEN_DRAIN
= 0xC,
34 AD5592R_REG_TRISTATE
= 0xD,
35 AD5592R_REG_RESET
= 0xF,
38 #define AD5592R_REG_PD_EN_REF BIT(9)
39 #define AD5592R_REG_CTRL_ADC_RANGE BIT(5)
40 #define AD5592R_REG_CTRL_DAC_RANGE BIT(4)
42 struct ad5592r_rw_ops
{
43 int (*write_dac
)(struct ad5592r_state
*st
, unsigned chan
, u16 value
);
44 int (*read_adc
)(struct ad5592r_state
*st
, unsigned chan
, u16
*value
);
45 int (*reg_write
)(struct ad5592r_state
*st
, u8 reg
, u16 value
);
46 int (*reg_read
)(struct ad5592r_state
*st
, u8 reg
, u16
*value
);
47 int (*gpio_read
)(struct ad5592r_state
*st
, u8
*value
);
50 struct ad5592r_state
{
52 struct regulator
*reg
;
53 struct gpio_chip gpiochip
;
54 struct mutex gpio_lock
; /* Protect cached gpio_out, gpio_val, etc. */
56 unsigned int num_channels
;
57 const struct ad5592r_rw_ops
*ops
;
58 int scale_avail
[2][2];
62 u8 channel_offstate
[8];
68 __be16 spi_msg ____cacheline_aligned
;
72 int ad5592r_probe(struct device
*dev
, const char *name
,
73 const struct ad5592r_rw_ops
*ops
);
74 int ad5592r_remove(struct device
*dev
);
76 #endif /* __DRIVERS_IIO_DAC_AD5592R_BASE_H__ */