@@ -143,6 +143,11 @@ enum ad7768_dec_rate {
143
143
AD7768_DEC_RATE_1024 = 5
144
144
};
145
145
146
+ enum ad7768_scan_type {
147
+ AD7768_SCAN_TYPE_NORMAL ,
148
+ AD7768_SCAN_TYPE_HIGH_SPEED ,
149
+ };
150
+
146
151
struct ad7768_clk_configuration {
147
152
enum ad7768_mclk_div mclk_div ;
148
153
enum ad7768_dec_rate dec_rate ;
@@ -199,6 +204,19 @@ static const int sinc3_dec_rate_max_values[4] = {
199
204
20480 , 40960 , 81920 , 163840 ,
200
205
};
201
206
207
+ static const struct iio_scan_type ad7768_scan_type [] = {
208
+ [AD7768_SCAN_TYPE_NORMAL ] = {
209
+ .sign = 's' ,
210
+ .realbits = 24 ,
211
+ .storagebits = 32 ,
212
+ },
213
+ [AD7768_SCAN_TYPE_HIGH_SPEED ] = {
214
+ .sign = 's' ,
215
+ .realbits = 16 ,
216
+ .storagebits = 32 ,
217
+ },
218
+ };
219
+
202
220
static const char * const ad7768_filter_enum [] = {
203
221
[SINC5 ] = "sinc5" ,
204
222
[SINC5_DEC_X8 ] = "sinc5-dec8" ,
@@ -270,12 +288,9 @@ static const struct iio_chan_spec ad7768_channels[] = {
270
288
.indexed = 1 ,
271
289
.channel = 0 ,
272
290
.scan_index = 0 ,
273
- .scan_type = {
274
- .sign = 's' ,
275
- .realbits = 24 ,
276
- .storagebits = 32 ,
277
- .shift = 8 ,
278
- },
291
+ .has_ext_scan_type = 1 ,
292
+ .ext_scan_type = ad7768_scan_type ,
293
+ .num_ext_scan_type = ARRAY_SIZE (ad7768_scan_type ),
279
294
},
280
295
};
281
296
@@ -424,6 +439,9 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev)
424
439
ret = ad7768_spi_reg_read (st , AD7768_REG_ADC_DATA , & readval , 3 );
425
440
if (ret < 0 )
426
441
return ret ;
442
+
443
+ if (st -> filter_mode == SINC5_DEC_X8 )
444
+ readval = readval >> 8 ;
427
445
/*
428
446
* Any SPI configuration of the AD7768-1 can only be
429
447
* performed in continuous conversion mode.
@@ -825,6 +843,11 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
825
843
{
826
844
struct ad7768_state * st = iio_priv (indio_dev );
827
845
int scale_uv , ret ;
846
+ const struct iio_scan_type * scan_type ;
847
+
848
+ scan_type = iio_get_current_scan_type (indio_dev , chan );
849
+ if (IS_ERR (scan_type ))
850
+ return PTR_ERR (scan_type );
828
851
829
852
switch (info ) {
830
853
case IIO_CHAN_INFO_RAW :
@@ -834,7 +857,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
834
857
835
858
ret = ad7768_scan_direct (indio_dev );
836
859
if (ret >= 0 )
837
- * val = sign_extend32 (ret , chan -> scan_type . realbits - 1 );
860
+ * val = sign_extend32 (ret , scan_type -> realbits - 1 );
838
861
839
862
iio_device_release_direct_mode (indio_dev );
840
863
if (ret < 0 )
@@ -848,7 +871,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
848
871
return scale_uv ;
849
872
850
873
* val = (scale_uv * 2 ) / 1000 ;
851
- * val2 = chan -> scan_type . realbits ;
874
+ * val2 = scan_type -> realbits ;
852
875
853
876
return IIO_VAL_FRACTIONAL_LOG2 ;
854
877
@@ -892,11 +915,21 @@ static const struct attribute_group ad7768_group = {
892
915
.attrs = ad7768_attributes ,
893
916
};
894
917
918
+ static int ad7768_get_current_scan_type (const struct iio_dev * indio_dev ,
919
+ const struct iio_chan_spec * chan )
920
+ {
921
+ struct ad7768_state * st = iio_priv (indio_dev );
922
+
923
+ return st -> filter_mode == SINC5_DEC_X8 ? AD7768_SCAN_TYPE_HIGH_SPEED
924
+ : AD7768_SCAN_TYPE_NORMAL ;
925
+ }
926
+
895
927
static const struct iio_info ad7768_info = {
896
928
.attrs = & ad7768_group ,
897
929
.read_raw = & ad7768_read_raw ,
898
930
.write_raw = & ad7768_write_raw ,
899
931
.read_label = ad7768_read_label ,
932
+ .get_current_scan_type = & ad7768_get_current_scan_type ,
900
933
.debugfs_reg_access = & ad7768_reg_access ,
901
934
};
902
935
@@ -1009,13 +1042,18 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
1009
1042
struct ad7768_state * st = iio_priv (indio_dev );
1010
1043
struct spi_transfer xfer = {
1011
1044
.len = 1 ,
1012
- .bits_per_word = 32
1013
1045
};
1014
1046
unsigned int rx_data [2 ];
1015
- unsigned int tx_data [2 ];
1016
1047
struct spi_message msg ;
1048
+ const struct iio_scan_type * scan_type ;
1017
1049
int ret ;
1018
1050
1051
+ scan_type = iio_get_current_scan_type (indio_dev , & indio_dev -> channels [0 ]);
1052
+ if (IS_ERR (scan_type ))
1053
+ return PTR_ERR (scan_type );
1054
+
1055
+ xfer .bits_per_word = scan_type -> realbits ;
1056
+
1019
1057
/*
1020
1058
* Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
1021
1059
* continuous read mode. Subsequent data reads do not require an
@@ -1028,8 +1066,6 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
1028
1066
if (st -> spi_is_dma_mapped ) {
1029
1067
spi_bus_lock (st -> spi -> master );
1030
1068
1031
- tx_data [0 ] = AD7768_RD_FLAG_MSK (AD7768_REG_ADC_DATA ) << 24 ;
1032
- xfer .tx_buf = tx_data ;
1033
1069
xfer .rx_buf = rx_data ;
1034
1070
spi_message_init_with_transfers (& msg , & xfer , 1 );
1035
1071
ret = spi_engine_offload_load_msg (st -> spi , & msg );
0 commit comments