3535
3636#define AD4000_SCALE_OPTIONS 2
3737
38- #define AD4000_TQUIET1_NS 190
39- #define AD4000_TQUIET2_NS 60
40- #define AD4000_TCONV_NS 320
41-
4238#define __AD4000_DIFF_CHANNEL (_sign , _real_bits , _storage_bits , _reg_access ) \
4339{ \
4440 .type = IIO_VOLTAGE, \
@@ -122,108 +118,145 @@ static const int ad4000_gains[] = {
122118 454 , 909 , 1000 , 1900 ,
123119};
124120
121+ struct ad4000_time_spec {
122+ int t_conv_ns ;
123+ int t_quiet2_ns ;
124+ };
125+
126+ /*
127+ * Same timing specifications for all of AD4000, AD4001, ..., AD4008, AD4010,
128+ * ADAQ4001, and ADAQ4003.
129+ */
130+ static const struct ad4000_time_spec ad4000_t_spec = {
131+ .t_conv_ns = 320 ,
132+ .t_quiet2_ns = 60 ,
133+ };
134+
135+ /* AD4020, AD4021, AD4022 */
136+ static const struct ad4000_time_spec ad4020_t_spec = {
137+ .t_conv_ns = 350 ,
138+ .t_quiet2_ns = 60 ,
139+ };
140+
125141struct ad4000_chip_info {
126142 const char * dev_name ;
127143 struct iio_chan_spec chan_spec [2 ];
128144 struct iio_chan_spec reg_access_chan_spec [2 ];
145+ const struct ad4000_time_spec * time_spec ;
129146 bool has_hardware_gain ;
130147};
131148
132149static const struct ad4000_chip_info ad4000_chip_info = {
133150 .dev_name = "ad4000" ,
134151 .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 16 , 0 ),
135152 .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 16 , 1 ),
153+ .time_spec = & ad4000_t_spec ,
136154};
137155
138156static const struct ad4000_chip_info ad4001_chip_info = {
139157 .dev_name = "ad4001" ,
140158 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 16 , 0 ),
141159 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 16 , 1 ),
160+ .time_spec = & ad4000_t_spec ,
142161};
143162
144163static const struct ad4000_chip_info ad4002_chip_info = {
145164 .dev_name = "ad4002" ,
146165 .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 18 , 0 ),
147166 .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 18 , 1 ),
167+ .time_spec = & ad4000_t_spec ,
148168};
149169
150170static const struct ad4000_chip_info ad4003_chip_info = {
151171 .dev_name = "ad4003" ,
152172 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 0 ),
153173 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 1 ),
174+ .time_spec = & ad4000_t_spec ,
154175};
155176
156177static const struct ad4000_chip_info ad4004_chip_info = {
157178 .dev_name = "ad4004" ,
158179 .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 16 , 0 ),
159180 .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 16 , 1 ),
181+ .time_spec = & ad4000_t_spec ,
160182};
161183
162184static const struct ad4000_chip_info ad4005_chip_info = {
163185 .dev_name = "ad4005" ,
164186 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 16 , 0 ),
165187 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 16 , 1 ),
188+ .time_spec = & ad4000_t_spec ,
166189};
167190
168191static const struct ad4000_chip_info ad4006_chip_info = {
169192 .dev_name = "ad4006" ,
170193 .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 18 , 0 ),
171194 .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 18 , 1 ),
195+ .time_spec = & ad4000_t_spec ,
172196};
173197
174198static const struct ad4000_chip_info ad4007_chip_info = {
175199 .dev_name = "ad4007" ,
176200 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 0 ),
177201 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 1 ),
202+ .time_spec = & ad4000_t_spec ,
178203};
179204
180205static const struct ad4000_chip_info ad4008_chip_info = {
181206 .dev_name = "ad4008" ,
182207 .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 16 , 0 ),
183208 .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 16 , 1 ),
209+ .time_spec = & ad4000_t_spec ,
184210};
185211
186212static const struct ad4000_chip_info ad4010_chip_info = {
187213 .dev_name = "ad4010" ,
188214 .chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 18 , 0 ),
189215 .reg_access_chan_spec = AD4000_PSEUDO_DIFF_CHANNELS ('u' , 18 , 1 ),
216+ .time_spec = & ad4000_t_spec ,
190217};
191218
192219static const struct ad4000_chip_info ad4011_chip_info = {
193220 .dev_name = "ad4011" ,
194221 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 0 ),
195222 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 1 ),
223+ .time_spec = & ad4000_t_spec ,
196224};
197225
198226static const struct ad4000_chip_info ad4020_chip_info = {
199227 .dev_name = "ad4020" ,
200228 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 20 , 0 ),
201229 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 20 , 1 ),
230+ .time_spec = & ad4020_t_spec ,
202231};
203232
204233static const struct ad4000_chip_info ad4021_chip_info = {
205234 .dev_name = "ad4021" ,
206235 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 20 , 0 ),
207236 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 20 , 1 ),
237+ .time_spec = & ad4020_t_spec ,
208238};
209239
210240static const struct ad4000_chip_info ad4022_chip_info = {
211241 .dev_name = "ad4022" ,
212242 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 20 , 0 ),
213243 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 20 , 1 ),
244+ .time_spec = & ad4020_t_spec ,
214245};
215246
216247static const struct ad4000_chip_info adaq4001_chip_info = {
217248 .dev_name = "adaq4001" ,
218249 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 16 , 0 ),
219250 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 16 , 1 ),
251+ .time_spec = & ad4000_t_spec ,
220252 .has_hardware_gain = true,
221253};
222254
223255static const struct ad4000_chip_info adaq4003_chip_info = {
224256 .dev_name = "adaq4003" ,
225257 .chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 0 ),
226258 .reg_access_chan_spec = AD4000_DIFF_CHANNELS ('s' , 18 , 1 ),
259+ .time_spec = & ad4000_t_spec ,
227260 .has_hardware_gain = true,
228261};
229262
@@ -238,6 +271,7 @@ struct ad4000_state {
238271 bool span_comp ;
239272 u16 gain_milli ;
240273 int scale_tbl [AD4000_SCALE_OPTIONS ][2 ];
274+ const struct ad4000_time_spec * time_spec ;
241275
242276 /*
243277 * DMA (thus cache coherency maintenance) requires the transfer buffers
@@ -502,16 +536,15 @@ static const struct iio_info ad4000_info = {
502536static int ad4000_prepare_3wire_mode_message (struct ad4000_state * st ,
503537 const struct iio_chan_spec * chan )
504538{
505- unsigned int cnv_pulse_time = AD4000_TCONV_NS ;
506539 struct spi_transfer * xfers = st -> xfers ;
507540
508541 xfers [0 ].cs_change = 1 ;
509- xfers [0 ].cs_change_delay .value = cnv_pulse_time ;
542+ xfers [0 ].cs_change_delay .value = st -> time_spec -> t_conv_ns ;
510543 xfers [0 ].cs_change_delay .unit = SPI_DELAY_UNIT_NSECS ;
511544
512545 xfers [1 ].rx_buf = & st -> scan .data ;
513546 xfers [1 ].len = BITS_TO_BYTES (chan -> scan_type .storagebits );
514- xfers [1 ].delay .value = AD4000_TQUIET2_NS ;
547+ xfers [1 ].delay .value = st -> time_spec -> t_quiet2_ns ;
515548 xfers [1 ].delay .unit = SPI_DELAY_UNIT_NSECS ;
516549
517550 spi_message_init_with_transfers (& st -> msg , st -> xfers , 2 );
@@ -529,15 +562,14 @@ static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st,
529562static int ad4000_prepare_4wire_mode_message (struct ad4000_state * st ,
530563 const struct iio_chan_spec * chan )
531564{
532- unsigned int cnv_to_sdi_time = AD4000_TCONV_NS ;
533565 struct spi_transfer * xfers = st -> xfers ;
534566
535567 /*
536568 * Dummy transfer to cause enough delay between CNV going high and SDI
537569 * going low.
538570 */
539571 xfers [0 ].cs_off = 1 ;
540- xfers [0 ].delay .value = cnv_to_sdi_time ;
572+ xfers [0 ].delay .value = st -> time_spec -> t_conv_ns ;
541573 xfers [0 ].delay .unit = SPI_DELAY_UNIT_NSECS ;
542574
543575 xfers [1 ].rx_buf = & st -> scan .data ;
@@ -576,6 +608,7 @@ static int ad4000_probe(struct spi_device *spi)
576608
577609 st = iio_priv (indio_dev );
578610 st -> spi = spi ;
611+ st -> time_spec = chip -> time_spec ;
579612
580613 ret = devm_regulator_bulk_get_enable (dev , ARRAY_SIZE (ad4000_power_supplies ),
581614 ad4000_power_supplies );
0 commit comments