@@ -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
@@ -441,6 +456,9 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev)
441
456
ret = ad7768_spi_reg_read (st , AD7768_REG_ADC_DATA , & readval , 3 );
442
457
if (ret < 0 )
443
458
return ret ;
459
+
460
+ if (st -> filter_mode == SINC5_DEC_X8 )
461
+ readval = readval >> 8 ;
444
462
/*
445
463
* Any SPI configuration of the AD7768-1 can only be
446
464
* performed in continuous conversion mode.
@@ -839,8 +857,13 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
839
857
int * val , int * val2 , long info )
840
858
{
841
859
struct ad7768_state * st = iio_priv (indio_dev );
860
+ const struct iio_scan_type * scan_type ;
842
861
int scale_uv , ret ;
843
862
863
+ scan_type = iio_get_current_scan_type (indio_dev , chan );
864
+ if (IS_ERR (scan_type ))
865
+ return PTR_ERR (scan_type );
866
+
844
867
switch (info ) {
845
868
case IIO_CHAN_INFO_RAW :
846
869
ret = iio_device_claim_direct_mode (indio_dev );
@@ -849,7 +872,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
849
872
850
873
ret = ad7768_scan_direct (indio_dev );
851
874
if (ret >= 0 )
852
- * val = sign_extend32 (ret , chan -> scan_type . realbits - 1 );
875
+ * val = sign_extend32 (ret , scan_type -> realbits - 1 );
853
876
854
877
iio_device_release_direct_mode (indio_dev );
855
878
if (ret < 0 )
@@ -863,7 +886,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
863
886
return scale_uv ;
864
887
865
888
* val = (scale_uv * 2 ) / 1000 ;
866
- * val2 = chan -> scan_type . realbits ;
889
+ * val2 = scan_type -> realbits ;
867
890
868
891
return IIO_VAL_FRACTIONAL_LOG2 ;
869
892
@@ -907,11 +930,21 @@ static const struct attribute_group ad7768_group = {
907
930
.attrs = ad7768_attributes ,
908
931
};
909
932
933
+ static int ad7768_get_current_scan_type (const struct iio_dev * indio_dev ,
934
+ const struct iio_chan_spec * chan )
935
+ {
936
+ struct ad7768_state * st = iio_priv (indio_dev );
937
+
938
+ return st -> filter_mode == SINC5_DEC_X8 ? AD7768_SCAN_TYPE_HIGH_SPEED
939
+ : AD7768_SCAN_TYPE_NORMAL ;
940
+ }
941
+
910
942
static const struct iio_info ad7768_info = {
911
943
.attrs = & ad7768_group ,
912
944
.read_raw = & ad7768_read_raw ,
913
945
.write_raw = & ad7768_write_raw ,
914
946
.read_label = ad7768_read_label ,
947
+ .get_current_scan_type = & ad7768_get_current_scan_type ,
915
948
.debugfs_reg_access = & ad7768_reg_access ,
916
949
};
917
950
@@ -1029,15 +1062,20 @@ static irqreturn_t ad7768_interrupt(int irq, void *dev_id)
1029
1062
static int ad7768_buffer_postenable (struct iio_dev * indio_dev )
1030
1063
{
1031
1064
struct ad7768_state * st = iio_priv (indio_dev );
1065
+ const struct iio_scan_type * scan_type ;
1032
1066
struct spi_transfer xfer = {
1033
1067
.len = 1 ,
1034
- .bits_per_word = 32
1035
1068
};
1036
1069
unsigned int rx_data [2 ];
1037
- unsigned int tx_data [2 ];
1038
1070
struct spi_message msg ;
1039
1071
int ret ;
1040
1072
1073
+ scan_type = iio_get_current_scan_type (indio_dev , & indio_dev -> channels [0 ]);
1074
+ if (IS_ERR (scan_type ))
1075
+ return PTR_ERR (scan_type );
1076
+
1077
+ xfer .bits_per_word = scan_type -> realbits ;
1078
+
1041
1079
/*
1042
1080
* Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
1043
1081
* continuous read mode. Subsequent data reads do not require an
@@ -1050,8 +1088,6 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
1050
1088
if (st -> spi_is_dma_mapped ) {
1051
1089
spi_bus_lock (st -> spi -> master );
1052
1090
1053
- tx_data [0 ] = AD7768_RD_FLAG_MSK (AD7768_REG_ADC_DATA ) << 24 ;
1054
- xfer .tx_buf = tx_data ;
1055
1091
xfer .rx_buf = rx_data ;
1056
1092
spi_message_init_with_transfers (& msg , & xfer , 1 );
1057
1093
ret = spi_engine_offload_load_msg (st -> spi , & msg );
0 commit comments