2 * AD5592R / AD5593R Digital <-> Analog converters driver
4 * Copyright 2015-2016 Analog Devices Inc.
5 * Author: Paul Cercueil <paul.cercueil@analog.com>
7 * Licensed under the GPL-2.
10 #ifndef __DRIVERS_IIO_DAC_AD5592R_BASE_H__
11 #define __DRIVERS_IIO_DAC_AD5592R_BASE_H__
13 #include <linux/types.h>
14 #include <linux/cache.h>
15 #include <linux/mutex.h>
16 #include <linux/gpio/driver.h>
21 enum ad5592r_registers {
22 AD5592R_REG_NOOP = 0x0,
23 AD5592R_REG_DAC_READBACK = 0x1,
24 AD5592R_REG_ADC_SEQ = 0x2,
25 AD5592R_REG_CTRL = 0x3,
26 AD5592R_REG_ADC_EN = 0x4,
27 AD5592R_REG_DAC_EN = 0x5,
28 AD5592R_REG_PULLDOWN = 0x6,
29 AD5592R_REG_LDAC = 0x7,
30 AD5592R_REG_GPIO_OUT_EN = 0x8,
31 AD5592R_REG_GPIO_SET = 0x9,
32 AD5592R_REG_GPIO_IN_EN = 0xA,
34 AD5592R_REG_OPEN_DRAIN = 0xC,
35 AD5592R_REG_TRISTATE = 0xD,
36 AD5592R_REG_RESET = 0xF,
39 #define AD5592R_REG_PD_EN_REF BIT(9)
40 #define AD5592R_REG_CTRL_ADC_RANGE BIT(5)
41 #define AD5592R_REG_CTRL_DAC_RANGE BIT(4)
43 struct ad5592r_rw_ops {
44 int (*write_dac)(struct ad5592r_state *st, unsigned chan, u16 value);
45 int (*read_adc)(struct ad5592r_state *st, unsigned chan, u16 *value);
46 int (*reg_write)(struct ad5592r_state *st, u8 reg, u16 value);
47 int (*reg_read)(struct ad5592r_state *st, u8 reg, u16 *value);
48 int (*gpio_read)(struct ad5592r_state *st, u8 *value);
51 struct ad5592r_state {
53 struct regulator *reg;
54 struct gpio_chip gpiochip;
55 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__ */