• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * AD5592R / AD5593R Digital <-> Analog converters driver
4  *
5  * Copyright 2015-2016 Analog Devices Inc.
6  * Author: Paul Cercueil <paul.cercueil@analog.com>
7  */
8 
9 #ifndef __DRIVERS_IIO_DAC_AD5592R_BASE_H__
10 #define __DRIVERS_IIO_DAC_AD5592R_BASE_H__
11 
12 #include <linux/types.h>
13 #include <linux/cache.h>
14 #include <linux/mutex.h>
15 #include <linux/gpio/driver.h>
16 
17 #include <linux/iio/iio.h>
18 
19 struct device;
20 struct ad5592r_state;
21 
22 enum ad5592r_registers {
23 	AD5592R_REG_NOOP		= 0x0,
24 	AD5592R_REG_DAC_READBACK	= 0x1,
25 	AD5592R_REG_ADC_SEQ		= 0x2,
26 	AD5592R_REG_CTRL		= 0x3,
27 	AD5592R_REG_ADC_EN		= 0x4,
28 	AD5592R_REG_DAC_EN		= 0x5,
29 	AD5592R_REG_PULLDOWN		= 0x6,
30 	AD5592R_REG_LDAC		= 0x7,
31 	AD5592R_REG_GPIO_OUT_EN		= 0x8,
32 	AD5592R_REG_GPIO_SET		= 0x9,
33 	AD5592R_REG_GPIO_IN_EN		= 0xA,
34 	AD5592R_REG_PD			= 0xB,
35 	AD5592R_REG_OPEN_DRAIN		= 0xC,
36 	AD5592R_REG_TRISTATE		= 0xD,
37 	AD5592R_REG_RESET		= 0xF,
38 };
39 
40 #define AD5592R_REG_PD_EN_REF		BIT(9)
41 #define AD5592R_REG_CTRL_ADC_RANGE	BIT(5)
42 #define AD5592R_REG_CTRL_DAC_RANGE	BIT(4)
43 
44 struct ad5592r_rw_ops {
45 	int (*write_dac)(struct ad5592r_state *st, unsigned chan, u16 value);
46 	int (*read_adc)(struct ad5592r_state *st, unsigned chan, u16 *value);
47 	int (*reg_write)(struct ad5592r_state *st, u8 reg, u16 value);
48 	int (*reg_read)(struct ad5592r_state *st, u8 reg, u16 *value);
49 	int (*gpio_read)(struct ad5592r_state *st, u8 *value);
50 };
51 
52 struct ad5592r_state {
53 	struct device *dev;
54 	struct regulator *reg;
55 	struct gpio_chip gpiochip;
56 	struct mutex gpio_lock;	/* Protect cached gpio_out, gpio_val, etc. */
57 	struct mutex lock;
58 	unsigned int num_channels;
59 	const struct ad5592r_rw_ops *ops;
60 	int scale_avail[2][2];
61 	u16 cached_dac[8];
62 	u16 cached_gp_ctrl;
63 	u8 channel_modes[8];
64 	u8 channel_offstate[8];
65 	u8 gpio_map;
66 	u8 gpio_out;
67 	u8 gpio_in;
68 	u8 gpio_val;
69 
70 	__be16 spi_msg __aligned(IIO_DMA_MINALIGN);
71 	__be16 spi_msg_nop;
72 };
73 
74 int ad5592r_probe(struct device *dev, const char *name,
75 		const struct ad5592r_rw_ops *ops);
76 void ad5592r_remove(struct device *dev);
77 
78 #endif /* __DRIVERS_IIO_DAC_AD5592R_BASE_H__ */
79