0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __DRIVERS_IIO_DAC_AD5592R_BASE_H__
0010 #define __DRIVERS_IIO_DAC_AD5592R_BASE_H__
0011
0012 #include <linux/types.h>
0013 #include <linux/cache.h>
0014 #include <linux/mutex.h>
0015 #include <linux/gpio/driver.h>
0016
0017 #include <linux/iio/iio.h>
0018
0019 struct device;
0020 struct ad5592r_state;
0021
0022 enum ad5592r_registers {
0023 AD5592R_REG_NOOP = 0x0,
0024 AD5592R_REG_DAC_READBACK = 0x1,
0025 AD5592R_REG_ADC_SEQ = 0x2,
0026 AD5592R_REG_CTRL = 0x3,
0027 AD5592R_REG_ADC_EN = 0x4,
0028 AD5592R_REG_DAC_EN = 0x5,
0029 AD5592R_REG_PULLDOWN = 0x6,
0030 AD5592R_REG_LDAC = 0x7,
0031 AD5592R_REG_GPIO_OUT_EN = 0x8,
0032 AD5592R_REG_GPIO_SET = 0x9,
0033 AD5592R_REG_GPIO_IN_EN = 0xA,
0034 AD5592R_REG_PD = 0xB,
0035 AD5592R_REG_OPEN_DRAIN = 0xC,
0036 AD5592R_REG_TRISTATE = 0xD,
0037 AD5592R_REG_RESET = 0xF,
0038 };
0039
0040 #define AD5592R_REG_PD_EN_REF BIT(9)
0041 #define AD5592R_REG_CTRL_ADC_RANGE BIT(5)
0042 #define AD5592R_REG_CTRL_DAC_RANGE BIT(4)
0043
0044 struct ad5592r_rw_ops {
0045 int (*write_dac)(struct ad5592r_state *st, unsigned chan, u16 value);
0046 int (*read_adc)(struct ad5592r_state *st, unsigned chan, u16 *value);
0047 int (*reg_write)(struct ad5592r_state *st, u8 reg, u16 value);
0048 int (*reg_read)(struct ad5592r_state *st, u8 reg, u16 *value);
0049 int (*gpio_read)(struct ad5592r_state *st, u8 *value);
0050 };
0051
0052 struct ad5592r_state {
0053 struct device *dev;
0054 struct regulator *reg;
0055 struct gpio_chip gpiochip;
0056 struct mutex gpio_lock;
0057 struct mutex lock;
0058 unsigned int num_channels;
0059 const struct ad5592r_rw_ops *ops;
0060 int scale_avail[2][2];
0061 u16 cached_dac[8];
0062 u16 cached_gp_ctrl;
0063 u8 channel_modes[8];
0064 u8 channel_offstate[8];
0065 u8 gpio_map;
0066 u8 gpio_out;
0067 u8 gpio_in;
0068 u8 gpio_val;
0069
0070 __be16 spi_msg __aligned(IIO_DMA_MINALIGN);
0071 __be16 spi_msg_nop;
0072 };
0073
0074 int ad5592r_probe(struct device *dev, const char *name,
0075 const struct ad5592r_rw_ops *ops);
0076 void ad5592r_remove(struct device *dev);
0077
0078 #endif