Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / staging / iio / adc / max1363.h
blob2cd0112067b21fb3ca1df3c070208fbbf0987ac9
1 #ifndef _MAX1363_H_
2 #define _MAX1363_H_
4 #define MAX1363_SETUP_BYTE(a) ((a) | 0x80)
6 /* There is a fair bit more defined here than currently
7 * used, but the intention is to support everything these
8 * chips do in the long run */
10 /* see data sheets */
11 /* max1363 and max1236, max1237, max1238, max1239 */
12 #define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 0x00
13 #define MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF 0x20
14 #define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT 0x40
15 #define MAX1363_SETUP_AIN3_IS_REF_REF_IS_INT 0x60
16 #define MAX1363_SETUP_POWER_UP_INT_REF 0x10
17 #define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00
19 /* think about includeing max11600 etc - more settings */
20 #define MAX1363_SETUP_EXT_CLOCK 0x08
21 #define MAX1363_SETUP_INT_CLOCK 0x00
22 #define MAX1363_SETUP_UNIPOLAR 0x00
23 #define MAX1363_SETUP_BIPOLAR 0x04
24 #define MAX1363_SETUP_RESET 0x00
25 #define MAX1363_SETUP_NORESET 0x02
26 /* max1363 only - though don't care on others.
27 * For now monitor modes are not implemented as the relevant
28 * line is not connected on my test board.
29 * The definitions are here as I intend to add this soon.
31 #define MAX1363_SETUP_MONITOR_SETUP 0x01
33 /* Specific to the max1363 */
34 #define MAX1363_MON_RESET_CHAN(a) (1 << ((a) + 4))
35 #define MAX1363_MON_INT_ENABLE 0x01
37 /* defined for readability reasons */
38 /* All chips */
39 #define MAX1363_CONFIG_BYTE(a) ((a))
41 #define MAX1363_CONFIG_SE 0x01
42 #define MAX1363_CONFIG_DE 0x00
43 #define MAX1363_CONFIG_SCAN_TO_CS 0x00
44 #define MAX1363_CONFIG_SCAN_SINGLE_8 0x20
45 #define MAX1363_CONFIG_SCAN_MONITOR_MODE 0x40
46 #define MAX1363_CONFIG_SCAN_SINGLE_1 0x60
47 /* max123{6-9} only */
48 #define MAX1236_SCAN_MID_TO_CHANNEL 0x40
50 /* max1363 only - merely part of channel selects or don't care for others*/
51 #define MAX1363_CONFIG_EN_MON_MODE_READ 0x18
53 #define MAX1363_CHANNEL_SEL(a) ((a) << 1)
55 /* max1363 strictly 0x06 - but doesn't matter */
56 #define MAX1363_CHANNEL_SEL_MASK 0x1E
57 #define MAX1363_SCAN_MASK 0x60
58 #define MAX1363_SE_DE_MASK 0x01
60 #define MAX1363_MAX_CHANNELS 25
61 /**
62 * struct max1363_mode - scan mode information
63 * @conf: The corresponding value of the configuration register
64 * @modemask: Bit mask corresponding to channels enabled in this mode
66 struct max1363_mode {
67 int8_t conf;
68 DECLARE_BITMAP(modemask, MAX1363_MAX_CHANNELS);
71 /* This must be maintained along side the max1363_mode_table in max1363_core */
72 enum max1363_modes {
73 /* Single read of a single channel */
74 _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11,
75 /* Differential single read */
76 d0m1, d2m3, d4m5, d6m7, d8m9, d10m11,
77 d1m0, d3m2, d5m4, d7m6, d9m8, d11m10,
78 /* Scan to channel and mid to channel where overlapping */
79 s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6,
80 s6to7, s0to7, s6to8, s0to8, s6to9,
81 s0to9, s6to10, s0to10, s6to11, s0to11,
82 /* Differential scan to channel and mid to channel where overlapping */
83 d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9,
84 d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2,
85 d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8,
86 d7m6to11m10, d1m0to11m10,
89 /**
90 * struct max1363_chip_info - chip specifc information
91 * @name: indentification string for chip
92 * @bits: accuracy of the adc in bits
93 * @int_vref_mv: the internal reference voltage
94 * @info: iio core function callbacks structure
95 * @mode_list: array of available scan modes
96 * @num_modes: the number of scan modes available
97 * @default_mode: the scan mode in which the chip starts up
98 * @channel: channel specification
99 * @num_channels: number of channels
101 struct max1363_chip_info {
102 const struct iio_info *info;
103 struct iio_chan_spec *channels;
104 int num_channels;
105 const enum max1363_modes *mode_list;
106 enum max1363_modes default_mode;
107 u16 int_vref_mv;
108 u8 num_modes;
109 u8 bits;
113 * struct max1363_state - driver instance specific data
114 * @client: i2c_client
115 * @setupbyte: cache of current device setup byte
116 * @configbyte: cache of current device config byte
117 * @chip_info: chip model specific constants, available modes etc
118 * @current_mode: the scan mode of this chip
119 * @requestedmask: a valid requested set of channels
120 * @reg: supply regulator
121 * @monitor_on: whether monitor mode is enabled
122 * @monitor_speed: parameter corresponding to device monitor speed setting
123 * @mask_high: bitmask for enabled high thresholds
124 * @mask_low: bitmask for enabled low thresholds
125 * @thresh_high: high threshold values
126 * @thresh_low: low threshold values
128 struct max1363_state {
129 struct i2c_client *client;
130 u8 setupbyte;
131 u8 configbyte;
132 const struct max1363_chip_info *chip_info;
133 const struct max1363_mode *current_mode;
134 u32 requestedmask;
135 struct regulator *reg;
137 /* Using monitor modes and buffer at the same time is
138 currently not supported */
139 bool monitor_on;
140 unsigned int monitor_speed:3;
141 u8 mask_high;
142 u8 mask_low;
143 /* 4x unipolar first then the fours bipolar ones */
144 s16 thresh_high[8];
145 s16 thresh_low[8];
148 const struct max1363_mode
149 *max1363_match_mode(const unsigned long *mask,
150 const struct max1363_chip_info *ci);
152 int max1363_set_scan_mode(struct max1363_state *st);
154 #ifdef CONFIG_MAX1363_RING_BUFFER
155 int max1363_update_scan_mode(struct iio_dev *indio_dev,
156 const unsigned long *scan_mask);
157 int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev);
158 void max1363_ring_cleanup(struct iio_dev *indio_dev);
160 #else /* CONFIG_MAX1363_RING_BUFFER */
161 int max1363_update_scan_mode(struct iio_dev *indio_dev,
162 const long *scan_mask)
164 return 0;
167 static inline int
168 max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
170 return 0;
173 static inline void max1363_ring_cleanup(struct iio_dev *indio_dev)
176 #endif /* CONFIG_MAX1363_RING_BUFFER */
177 #endif /* _MAX1363_H_ */