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  * @get_lin_comp:	function pointer to the device specific function
72  */
73 
74 struct ad5791_chip_info {
75 	int (*get_lin_comp)	(unsigned int span);
76 };
77 
78 /**
79  * struct ad5791_state - driver instance specific data
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  * @vref_neg_mv:	voltage of the negative supply
86  * @pwr_down_mode	current power down mode
87  */
88 
89 struct ad5791_state {
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 int			vref_neg_mv;
96 	unsigned			ctrl;
97 	unsigned			pwr_down_mode;
98 	bool				pwr_down;
99 };
100 
101 /**
102  * ad5791_supported_device_ids:
103  */
104 
105 enum ad5791_supported_device_ids {
106 	ID_AD5760,
107 	ID_AD5780,
108 	ID_AD5781,
109 	ID_AD5791,
110 };
111 
112 #endif /* SPI_AD5791_H_ */
113