staging: IIO: DAC: New driver for AD5791/AD5781 High Resolution Voltage Output DACs
[firefly-linux-kernel-4.4.55.git] / drivers / staging / iio / dac / ad5791.h
1 /*
2  * AD5791 SPI DAC driver
3  *
4  * Copyright 2011 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2.
7  */
8
9 #ifndef SPI_AD5791_H_
10 #define SPI_AD5791_H_
11
12 #define AD5791_RES_MASK(x)              ((1 << (x)) - 1)
13 #define AD5791_DAC_MASK                 AD5791_RES_MASK(20)
14 #define AD5791_DAC_MSB                  (1 << 19)
15
16 #define AD5791_CMD_READ                 (1 << 23)
17 #define AD5791_CMD_WRITE                (0 << 23)
18 #define AD5791_ADDR(addr)               ((addr) << 20)
19
20 /* Registers */
21 #define AD5791_ADDR_NOOP                0
22 #define AD5791_ADDR_DAC0                1
23 #define AD5791_ADDR_CTRL                2
24 #define AD5791_ADDR_CLRCODE             3
25 #define AD5791_ADDR_SW_CTRL             4
26
27 /* Control Register */
28 #define AD5791_CTRL_RBUF                (1 << 1)
29 #define AD5791_CTRL_OPGND               (1 << 2)
30 #define AD5791_CTRL_DACTRI              (1 << 3)
31 #define AD5791_CTRL_BIN2SC              (1 << 4)
32 #define AD5791_CTRL_SDODIS              (1 << 5)
33 #define AD5761_CTRL_LINCOMP(x)          ((x) << 6)
34
35 #define AD5791_LINCOMP_0_10             0
36 #define AD5791_LINCOMP_10_12            1
37 #define AD5791_LINCOMP_12_16            2
38 #define AD5791_LINCOMP_16_19            3
39 #define AD5791_LINCOMP_19_20            12
40
41 /* Software Control Register */
42 #define AD5791_SWCTRL_LDAC              (1 << 0)
43 #define AD5791_SWCTRL_CLR               (1 << 1)
44 #define AD5791_SWCTRL_RESET             (1 << 2)
45
46 #define AD5791_DAC_PWRDN_6K             0
47 #define AD5791_DAC_PWRDN_3STATE         1
48
49 /*
50  * TODO: struct ad5791_platform_data needs to go into include/linux/iio
51  */
52
53 /**
54  * struct ad5791_platform_data - platform specific information
55  * @vref_pos_mv:        Vdd Positive Analog Supply Volatge (mV)
56  * @vref_neg_mv:        Vdd Negative Analog Supply Volatge (mV)
57  * @use_rbuf_gain2:     ext. amplifier connected in gain of two configuration
58  */
59
60 struct ad5791_platform_data {
61         u16                             vref_pos_mv;
62         u16                             vref_neg_mv;
63         bool                            use_rbuf_gain2;
64 };
65
66 /**
67  * struct ad5791_chip_info - chip specific information
68  * @bits:               accuracy of the DAC in bits
69  * @left_shift:         number of bits the datum must be shifted
70  */
71
72 struct ad5791_chip_info {
73         u8                      bits;
74         u8                      left_shift;
75 };
76
77 /**
78  * struct ad5791_state - driver instance specific data
79  * @indio_dev:          the industrial I/O device
80  * @us:                 spi_device
81  * @reg_vdd:            positive supply regulator
82  * @reg_vss:            negative supply regulator
83  * @chip_info:          chip model specific constants
84  * @vref_mv:            actual reference voltage used
85  * @pwr_down_mode       current power down mode
86  */
87
88 struct ad5791_state {
89         struct iio_dev                  *indio_dev;
90         struct spi_device               *spi;
91         struct regulator                *reg_vdd;
92         struct regulator                *reg_vss;
93         const struct ad5791_chip_info   *chip_info;
94         unsigned short                  vref_mv;
95         unsigned                        ctrl;
96         unsigned                        pwr_down_mode;
97         bool                            pwr_down;
98 };
99
100 /**
101  * ad5791_supported_device_ids:
102  */
103
104 enum ad5791_supported_device_ids {
105         ID_AD5791,
106         ID_AD5781,
107 };
108
109 #endif /* SPI_AD5791_H_ */