@@ -157,6 +157,19 @@ enum ad7768_dec_rate {
157
157
AD7768_DEC_RATE_16 = 10
158
158
};
159
159
160
+ enum ad7768_scan_type {
161
+ AD7768_SCAN_TYPE_DMA_NORMAL ,
162
+ AD7768_SCAN_TYPE_DMA_HIGH_SPEED ,
163
+ AD7768_SCAN_TYPE_NORMAL ,
164
+ AD7768_SCAN_TYPE_HIGH_SPEED ,
165
+ };
166
+
167
+ struct ad7768_clk_configuration {
168
+ enum ad7768_mclk_div mclk_div ;
169
+ enum ad7768_dec_rate dec_rate ;
170
+ unsigned int clk_div ;
171
+ };
172
+
160
173
static const char * const ad7768_vcm_modes [] = {
161
174
"(AVDD1-AVSS)/2" ,
162
175
"2V5" ,
@@ -180,6 +193,33 @@ static const int sinc3_dec_rate_max_values[4] = {
180
193
20480 , 40960 , 81920 , 163840 ,
181
194
};
182
195
196
+ static const struct iio_scan_type ad7768_scan_type [] = {
197
+ [AD7768_SCAN_TYPE_NORMAL ] = {
198
+ .sign = 's' ,
199
+ .realbits = 24 ,
200
+ .storagebits = 32 ,
201
+ .endianness = IIO_BE ,
202
+ },
203
+ [AD7768_SCAN_TYPE_HIGH_SPEED ] = {
204
+ .sign = 's' ,
205
+ .realbits = 16 ,
206
+ .storagebits = 32 ,
207
+ .endianness = IIO_BE ,
208
+ },
209
+ [AD7768_SCAN_TYPE_DMA_NORMAL ] = {
210
+ .sign = 's' ,
211
+ .realbits = 24 ,
212
+ .storagebits = 32 ,
213
+ .endianness = IIO_CPU ,
214
+ },
215
+ [AD7768_SCAN_TYPE_DMA_HIGH_SPEED ] = {
216
+ .sign = 's' ,
217
+ .realbits = 16 ,
218
+ .storagebits = 32 ,
219
+ .endianness = IIO_CPU ,
220
+ },
221
+ };
222
+
183
223
static const char * const ad7768_filter_enum [] = {
184
224
[SINC5 ] = "sinc5" ,
185
225
[SINC3 ] = "sinc3" ,
@@ -242,12 +282,9 @@ static const struct iio_chan_spec ad7768_channels[] = {
242
282
.indexed = 1 ,
243
283
.channel = 0 ,
244
284
.scan_index = 0 ,
245
- .scan_type = {
246
- .sign = 's' ,
247
- .realbits = 24 ,
248
- .storagebits = 32 ,
249
- .shift = 8 ,
250
- },
285
+ .has_ext_scan_type = 1 ,
286
+ .ext_scan_type = ad7768_scan_type ,
287
+ .num_ext_scan_type = ARRAY_SIZE (ad7768_scan_type ),
251
288
},
252
289
};
253
290
@@ -421,6 +458,9 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev)
421
458
ret = ad7768_spi_reg_read (st , AD7768_REG_ADC_DATA , & readval , 3 );
422
459
if (ret < 0 )
423
460
return ret ;
461
+
462
+ if (st -> filter_mode == SINC5_DEC_X8 )
463
+ readval = readval >> 8 ;
424
464
/*
425
465
* Any SPI configuration of the AD7768-1 can only be
426
466
* performed in continuous conversion mode.
@@ -898,8 +938,13 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
898
938
int * val , int * val2 , long info )
899
939
{
900
940
struct ad7768_state * st = iio_priv (indio_dev );
941
+ const struct iio_scan_type * scan_type ;
901
942
int scale_uv , ret ;
902
943
944
+ scan_type = iio_get_current_scan_type (indio_dev , chan );
945
+ if (IS_ERR (scan_type ))
946
+ return PTR_ERR (scan_type );
947
+
903
948
switch (info ) {
904
949
case IIO_CHAN_INFO_RAW :
905
950
ret = iio_device_claim_direct_mode (indio_dev );
@@ -908,7 +953,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
908
953
909
954
ret = ad7768_scan_direct (indio_dev );
910
955
if (ret >= 0 )
911
- * val = sign_extend32 (ret , chan -> scan_type . realbits - 1 );
956
+ * val = sign_extend32 (ret , scan_type -> realbits - 1 );
912
957
913
958
iio_device_release_direct_mode (indio_dev );
914
959
if (ret < 0 )
@@ -922,7 +967,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
922
967
return scale_uv ;
923
968
924
969
* val = (scale_uv * 2 ) / 1000 ;
925
- * val2 = chan -> scan_type . realbits ;
970
+ * val2 = scan_type -> realbits ;
926
971
927
972
return IIO_VAL_FRACTIONAL_LOG2 ;
928
973
@@ -967,11 +1012,25 @@ static const struct attribute_group ad7768_group = {
967
1012
.attrs = ad7768_attributes ,
968
1013
};
969
1014
1015
+ static int ad7768_get_current_scan_type (const struct iio_dev * indio_dev ,
1016
+ const struct iio_chan_spec * chan )
1017
+ {
1018
+ struct ad7768_state * st = iio_priv (indio_dev );
1019
+
1020
+ if (st -> spi_is_dma_mapped )
1021
+ return st -> filter_mode == SINC5_DEC_X8 ? AD7768_SCAN_TYPE_DMA_HIGH_SPEED :
1022
+ AD7768_SCAN_TYPE_DMA_NORMAL ;
1023
+ else
1024
+ return st -> filter_mode == SINC5_DEC_X8 ? AD7768_SCAN_TYPE_HIGH_SPEED :
1025
+ AD7768_SCAN_TYPE_NORMAL ;
1026
+ }
1027
+
970
1028
static const struct iio_info ad7768_info = {
971
1029
.attrs = & ad7768_group ,
972
1030
.read_raw = & ad7768_read_raw ,
973
1031
.write_raw = & ad7768_write_raw ,
974
1032
.read_label = ad7768_read_label ,
1033
+ .get_current_scan_type = & ad7768_get_current_scan_type ,
975
1034
.debugfs_reg_access = & ad7768_reg_access ,
976
1035
};
977
1036
@@ -1077,15 +1136,21 @@ static irqreturn_t ad7768_interrupt(int irq, void *dev_id)
1077
1136
static int ad7768_buffer_postenable (struct iio_dev * indio_dev )
1078
1137
{
1079
1138
struct ad7768_state * st = iio_priv (indio_dev );
1139
+ const struct iio_scan_type * scan_type ;
1080
1140
struct spi_transfer xfer = {
1081
1141
.len = 1 ,
1082
- .bits_per_word = 32
1083
1142
};
1084
1143
unsigned int rx_data [2 ];
1085
1144
unsigned int tx_data [2 ];
1086
1145
struct spi_message msg ;
1087
1146
int ret ;
1088
1147
1148
+ scan_type = iio_get_current_scan_type (indio_dev , & indio_dev -> channels [0 ]);
1149
+ if (IS_ERR (scan_type ))
1150
+ return PTR_ERR (scan_type );
1151
+
1152
+ xfer .bits_per_word = scan_type -> realbits ;
1153
+
1089
1154
/*
1090
1155
* Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
1091
1156
* continuous read mode. Subsequent data reads do not require an
0 commit comments