@@ -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
@@ -422,6 +459,9 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev)
422
459
ret = ad7768_spi_reg_read (st , AD7768_REG_ADC_DATA , & readval , 3 );
423
460
if (ret < 0 )
424
461
return ret ;
462
+
463
+ if (st -> filter_mode == SINC5_DEC_X8 )
464
+ readval = readval >> 8 ;
425
465
/*
426
466
* Any SPI configuration of the AD7768-1 can only be
427
467
* performed in continuous conversion mode.
@@ -916,8 +956,13 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
916
956
int * val , int * val2 , long info )
917
957
{
918
958
struct ad7768_state * st = iio_priv (indio_dev );
959
+ const struct iio_scan_type * scan_type ;
919
960
int scale_uv , ret ;
920
961
962
+ scan_type = iio_get_current_scan_type (indio_dev , chan );
963
+ if (IS_ERR (scan_type ))
964
+ return PTR_ERR (scan_type );
965
+
921
966
switch (info ) {
922
967
case IIO_CHAN_INFO_RAW :
923
968
ret = iio_device_claim_direct_mode (indio_dev );
@@ -926,7 +971,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
926
971
927
972
ret = ad7768_scan_direct (indio_dev );
928
973
if (ret >= 0 )
929
- * val = sign_extend32 (ret , chan -> scan_type . realbits - 1 );
974
+ * val = sign_extend32 (ret , scan_type -> realbits - 1 );
930
975
931
976
iio_device_release_direct_mode (indio_dev );
932
977
if (ret < 0 )
@@ -940,7 +985,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
940
985
return scale_uv ;
941
986
942
987
* val = (scale_uv * 2 ) / 1000 ;
943
- * val2 = chan -> scan_type . realbits ;
988
+ * val2 = scan_type -> realbits ;
944
989
945
990
return IIO_VAL_FRACTIONAL_LOG2 ;
946
991
@@ -985,11 +1030,25 @@ static const struct attribute_group ad7768_group = {
985
1030
.attrs = ad7768_attributes ,
986
1031
};
987
1032
1033
+ static int ad7768_get_current_scan_type (const struct iio_dev * indio_dev ,
1034
+ const struct iio_chan_spec * chan )
1035
+ {
1036
+ struct ad7768_state * st = iio_priv (indio_dev );
1037
+
1038
+ if (st -> spi_is_dma_mapped )
1039
+ return st -> filter_mode == SINC5_DEC_X8 ? AD7768_SCAN_TYPE_DMA_HIGH_SPEED :
1040
+ AD7768_SCAN_TYPE_DMA_NORMAL ;
1041
+ else
1042
+ return st -> filter_mode == SINC5_DEC_X8 ? AD7768_SCAN_TYPE_HIGH_SPEED :
1043
+ AD7768_SCAN_TYPE_NORMAL ;
1044
+ }
1045
+
988
1046
static const struct iio_info ad7768_info = {
989
1047
.attrs = & ad7768_group ,
990
1048
.read_raw = & ad7768_read_raw ,
991
1049
.write_raw = & ad7768_write_raw ,
992
1050
.read_label = ad7768_read_label ,
1051
+ .get_current_scan_type = & ad7768_get_current_scan_type ,
993
1052
.debugfs_reg_access = & ad7768_reg_access ,
994
1053
};
995
1054
@@ -1095,15 +1154,21 @@ static irqreturn_t ad7768_interrupt(int irq, void *dev_id)
1095
1154
static int ad7768_buffer_postenable (struct iio_dev * indio_dev )
1096
1155
{
1097
1156
struct ad7768_state * st = iio_priv (indio_dev );
1157
+ const struct iio_scan_type * scan_type ;
1098
1158
struct spi_transfer xfer = {
1099
1159
.len = 1 ,
1100
- .bits_per_word = 32
1101
1160
};
1102
1161
unsigned int rx_data [2 ];
1103
1162
unsigned int tx_data [2 ];
1104
1163
struct spi_message msg ;
1105
1164
int ret ;
1106
1165
1166
+ scan_type = iio_get_current_scan_type (indio_dev , & indio_dev -> channels [0 ]);
1167
+ if (IS_ERR (scan_type ))
1168
+ return PTR_ERR (scan_type );
1169
+
1170
+ xfer .bits_per_word = scan_type -> realbits ;
1171
+
1107
1172
/*
1108
1173
* Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
1109
1174
* continuous read mode. Subsequent data reads do not require an
0 commit comments