Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[pandora-kernel.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 #define AD5780_LINCOMP_0_10             0
42 #define AD5780_LINCOMP_10_20            12
43
44 /* Software Control Register */
45 #define AD5791_SWCTRL_LDAC              (1 << 0)
46 #define AD5791_SWCTRL_CLR               (1 << 1)
47 #define AD5791_SWCTRL_RESET             (1 << 2)
48
49 #define AD5791_DAC_PWRDN_6K             0
50 #define AD5791_DAC_PWRDN_3STATE         1
51
52 /*
53  * TODO: struct ad5791_platform_data needs to go into include/linux/iio
54  */
55
56 /**
57  * struct ad5791_platform_data - platform specific information
58  * @vref_pos_mv:        Vdd Positive Analog Supply Volatge (mV)
59  * @vref_neg_mv:        Vdd Negative Analog Supply Volatge (mV)
60  * @use_rbuf_gain2:     ext. amplifier connected in gain of two configuration
61  */
62
63 struct ad5791_platform_data {
64         u16                             vref_pos_mv;
65         u16                             vref_neg_mv;
66         bool                            use_rbuf_gain2;
67 };
68
69 /**
70  * struct ad5791_chip_info - chip specific information
71  * @bits:               accuracy of the DAC in bits
72  * @left_shift:         number of bits the datum must be shifted
73  * @get_lin_comp:       function pointer to the device specific function
74  */
75
76 struct ad5791_chip_info {
77         u8                      bits;
78         u8                      left_shift;
79         int (*get_lin_comp)     (unsigned int span);
80 };
81
82 /**
83  * struct ad5791_state - driver instance specific data
84  * @us:                 spi_device
85  * @reg_vdd:            positive supply regulator
86  * @reg_vss:            negative supply regulator
87  * @chip_info:          chip model specific constants
88  * @vref_mv:            actual reference voltage used
89  * @pwr_down_mode       current power down mode
90  */
91
92 struct ad5791_state {
93         struct spi_device               *spi;
94         struct regulator                *reg_vdd;
95         struct regulator                *reg_vss;
96         const struct ad5791_chip_info   *chip_info;
97         unsigned short                  vref_mv;
98         unsigned                        ctrl;
99         unsigned                        pwr_down_mode;
100         bool                            pwr_down;
101 };
102
103 /**
104  * ad5791_supported_device_ids:
105  */
106
107 enum ad5791_supported_device_ids {
108         ID_AD5760,
109         ID_AD5780,
110         ID_AD5781,
111         ID_AD5791,
112 };
113
114 #endif /* SPI_AD5791_H_ */