1 /* SPDX-License-Identifier: GPL-2.0 */
3 * This file is part of AD5686 DAC driver
5 * Copyright 2018 Analog Devices Inc.
8 #ifndef __DRIVERS_IIO_DAC_AD5686_H__
9 #define __DRIVERS_IIO_DAC_AD5686_H__
11 #include <linux/types.h>
12 #include <linux/cache.h>
13 #include <linux/mutex.h>
14 #include <linux/kernel.h>
16 #include <linux/iio/iio.h>
18 #define AD5310_CMD(x) ((x) << 12)
20 #define AD5683_DATA(x) ((x) << 4)
22 #define AD5686_ADDR(x) ((x) << 16)
23 #define AD5686_CMD(x) ((x) << 20)
25 #define AD5686_ADDR_DAC(chan) (0x1 << (chan))
26 #define AD5686_ADDR_ALL_DAC 0xF
28 #define AD5686_CMD_NOOP 0x0
29 #define AD5686_CMD_WRITE_INPUT_N 0x1
30 #define AD5686_CMD_UPDATE_DAC_N 0x2
31 #define AD5686_CMD_WRITE_INPUT_N_UPDATE_N 0x3
32 #define AD5686_CMD_POWERDOWN_DAC 0x4
33 #define AD5686_CMD_LDAC_MASK 0x5
34 #define AD5686_CMD_RESET 0x6
35 #define AD5686_CMD_INTERNAL_REFER_SETUP 0x7
36 #define AD5686_CMD_DAISY_CHAIN_ENABLE 0x8
37 #define AD5686_CMD_READBACK_ENABLE 0x9
39 #define AD5686_LDAC_PWRDN_NONE 0x0
40 #define AD5686_LDAC_PWRDN_1K 0x1
41 #define AD5686_LDAC_PWRDN_100K 0x2
42 #define AD5686_LDAC_PWRDN_3STATE 0x3
44 #define AD5686_CMD_CONTROL_REG 0x4
45 #define AD5686_CMD_READBACK_ENABLE_V2 0x5
47 #define AD5310_REF_BIT_MSK BIT(8)
48 #define AD5683_REF_BIT_MSK BIT(12)
49 #define AD5693_REF_BIT_MSK BIT(12)
52 * ad5686_supported_device_ids:
54 enum ad5686_supported_device_ids
{
88 enum ad5686_regmap_type
{
97 typedef int (*ad5686_write_func
)(struct ad5686_state
*st
,
98 u8 cmd
, u8 addr
, u16 val
);
100 typedef int (*ad5686_read_func
)(struct ad5686_state
*st
, u8 addr
);
103 * struct ad5686_chip_info - chip specific information
104 * @int_vref_mv: AD5620/40/60: the internal reference voltage
105 * @num_channels: number of channels
106 * @channel: channel specification
107 * @regmap_type: register map layout variant
110 struct ad5686_chip_info
{
112 unsigned int num_channels
;
113 const struct iio_chan_spec
*channels
;
114 enum ad5686_regmap_type regmap_type
;
118 * struct ad5446_state - driver instance specific data
120 * @chip_info: chip model specific constants, available modes etc
121 * @reg: supply regulator
122 * @vref_mv: actual reference voltage used
123 * @pwr_down_mask: power down mask
124 * @pwr_down_mode: current power down mode
125 * @use_internal_vref: set to true if the internal reference voltage is used
126 * @lock lock to protect the data buffer during regmap ops
127 * @data: spi transfer buffers
130 struct ad5686_state
{
132 const struct ad5686_chip_info
*chip_info
;
133 struct regulator
*reg
;
134 unsigned short vref_mv
;
135 unsigned int pwr_down_mask
;
136 unsigned int pwr_down_mode
;
137 ad5686_write_func write
;
138 ad5686_read_func read
;
139 bool use_internal_vref
;
143 * DMA (thus cache coherency maintenance) may require the
144 * transfer buffers to live in their own cache lines.
151 } data
[3] __aligned(IIO_DMA_MINALIGN
);
155 int ad5686_probe(struct device
*dev
,
156 enum ad5686_supported_device_ids chip_type
,
157 const char *name
, ad5686_write_func write
,
158 ad5686_read_func read
);
160 void ad5686_remove(struct device
*dev
);
163 #endif /* __DRIVERS_IIO_DAC_AD5686_H__ */