75
75
#define T_CONVERT_NS 190 /* conversion time */
76
76
#define T_CONVERT_0_NS 10 /* 1st conversion start time (oversampling) */
77
77
#define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */
78
+ #define T_POWERUP_US 5000 /* Power up */
78
79
79
80
struct ad7380_timing_specs {
80
81
const unsigned int t_csh_ns ; /* CS minimum high time */
@@ -86,6 +87,9 @@ struct ad7380_chip_info {
86
87
unsigned int num_channels ;
87
88
unsigned int num_simult_channels ;
88
89
bool has_mux ;
90
+ const char * const * supplies ;
91
+ unsigned int num_supplies ;
92
+ bool external_ref_only ;
89
93
const char * const * vcm_supplies ;
90
94
unsigned int num_vcm_supplies ;
91
95
const unsigned long * available_scan_masks ;
@@ -243,6 +247,10 @@ DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u);
243
247
DEFINE_AD7380_8_CHANNEL (ad7387_4_channels , 14 , 0 , u );
244
248
DEFINE_AD7380_8_CHANNEL (ad7388_4_channels , 12 , 0 , u );
245
249
250
+ static const char * const ad7380_supplies [] = {
251
+ "vcc" , "vlogic" ,
252
+ };
253
+
246
254
static const char * const ad7380_2_channel_vcm_supplies [] = {
247
255
"aina" , "ainb" ,
248
256
};
@@ -338,6 +346,8 @@ static const struct ad7380_chip_info ad7380_chip_info = {
338
346
.channels = ad7380_channels ,
339
347
.num_channels = ARRAY_SIZE (ad7380_channels ),
340
348
.num_simult_channels = 2 ,
349
+ .supplies = ad7380_supplies ,
350
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
341
351
.available_scan_masks = ad7380_2_channel_scan_masks ,
342
352
.timing_specs = & ad7380_timing ,
343
353
};
@@ -347,6 +357,8 @@ static const struct ad7380_chip_info ad7381_chip_info = {
347
357
.channels = ad7381_channels ,
348
358
.num_channels = ARRAY_SIZE (ad7381_channels ),
349
359
.num_simult_channels = 2 ,
360
+ .supplies = ad7380_supplies ,
361
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
350
362
.available_scan_masks = ad7380_2_channel_scan_masks ,
351
363
.timing_specs = & ad7380_timing ,
352
364
};
@@ -356,6 +368,8 @@ static const struct ad7380_chip_info ad7383_chip_info = {
356
368
.channels = ad7383_channels ,
357
369
.num_channels = ARRAY_SIZE (ad7383_channels ),
358
370
.num_simult_channels = 2 ,
371
+ .supplies = ad7380_supplies ,
372
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
359
373
.vcm_supplies = ad7380_2_channel_vcm_supplies ,
360
374
.num_vcm_supplies = ARRAY_SIZE (ad7380_2_channel_vcm_supplies ),
361
375
.available_scan_masks = ad7380_2_channel_scan_masks ,
@@ -367,6 +381,8 @@ static const struct ad7380_chip_info ad7384_chip_info = {
367
381
.channels = ad7384_channels ,
368
382
.num_channels = ARRAY_SIZE (ad7384_channels ),
369
383
.num_simult_channels = 2 ,
384
+ .supplies = ad7380_supplies ,
385
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
370
386
.vcm_supplies = ad7380_2_channel_vcm_supplies ,
371
387
.num_vcm_supplies = ARRAY_SIZE (ad7380_2_channel_vcm_supplies ),
372
388
.available_scan_masks = ad7380_2_channel_scan_masks ,
@@ -378,6 +394,8 @@ static const struct ad7380_chip_info ad7386_chip_info = {
378
394
.channels = ad7386_channels ,
379
395
.num_channels = ARRAY_SIZE (ad7386_channels ),
380
396
.num_simult_channels = 2 ,
397
+ .supplies = ad7380_supplies ,
398
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
381
399
.has_mux = true,
382
400
.available_scan_masks = ad7380_2x2_channel_scan_masks ,
383
401
.timing_specs = & ad7380_timing ,
@@ -388,6 +406,8 @@ static const struct ad7380_chip_info ad7387_chip_info = {
388
406
.channels = ad7387_channels ,
389
407
.num_channels = ARRAY_SIZE (ad7387_channels ),
390
408
.num_simult_channels = 2 ,
409
+ .supplies = ad7380_supplies ,
410
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
391
411
.has_mux = true,
392
412
.available_scan_masks = ad7380_2x2_channel_scan_masks ,
393
413
.timing_specs = & ad7380_timing ,
@@ -398,6 +418,8 @@ static const struct ad7380_chip_info ad7388_chip_info = {
398
418
.channels = ad7388_channels ,
399
419
.num_channels = ARRAY_SIZE (ad7388_channels ),
400
420
.num_simult_channels = 2 ,
421
+ .supplies = ad7380_supplies ,
422
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
401
423
.has_mux = true,
402
424
.available_scan_masks = ad7380_2x2_channel_scan_masks ,
403
425
.timing_specs = & ad7380_timing ,
@@ -408,6 +430,9 @@ static const struct ad7380_chip_info ad7380_4_chip_info = {
408
430
.channels = ad7380_4_channels ,
409
431
.num_channels = ARRAY_SIZE (ad7380_4_channels ),
410
432
.num_simult_channels = 4 ,
433
+ .supplies = ad7380_supplies ,
434
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
435
+ .external_ref_only = true,
411
436
.available_scan_masks = ad7380_4_channel_scan_masks ,
412
437
.timing_specs = & ad7380_4_timing ,
413
438
};
@@ -417,6 +442,8 @@ static const struct ad7380_chip_info ad7381_4_chip_info = {
417
442
.channels = ad7381_4_channels ,
418
443
.num_channels = ARRAY_SIZE (ad7381_4_channels ),
419
444
.num_simult_channels = 4 ,
445
+ .supplies = ad7380_supplies ,
446
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
420
447
.available_scan_masks = ad7380_4_channel_scan_masks ,
421
448
.timing_specs = & ad7380_4_timing ,
422
449
};
@@ -426,6 +453,8 @@ static const struct ad7380_chip_info ad7383_4_chip_info = {
426
453
.channels = ad7383_4_channels ,
427
454
.num_channels = ARRAY_SIZE (ad7383_4_channels ),
428
455
.num_simult_channels = 4 ,
456
+ .supplies = ad7380_supplies ,
457
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
429
458
.vcm_supplies = ad7380_4_channel_vcm_supplies ,
430
459
.num_vcm_supplies = ARRAY_SIZE (ad7380_4_channel_vcm_supplies ),
431
460
.available_scan_masks = ad7380_4_channel_scan_masks ,
@@ -437,6 +466,8 @@ static const struct ad7380_chip_info ad7384_4_chip_info = {
437
466
.channels = ad7384_4_channels ,
438
467
.num_channels = ARRAY_SIZE (ad7384_4_channels ),
439
468
.num_simult_channels = 4 ,
469
+ .supplies = ad7380_supplies ,
470
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
440
471
.vcm_supplies = ad7380_4_channel_vcm_supplies ,
441
472
.num_vcm_supplies = ARRAY_SIZE (ad7380_4_channel_vcm_supplies ),
442
473
.available_scan_masks = ad7380_4_channel_scan_masks ,
@@ -448,6 +479,8 @@ static const struct ad7380_chip_info ad7386_4_chip_info = {
448
479
.channels = ad7386_4_channels ,
449
480
.num_channels = ARRAY_SIZE (ad7386_4_channels ),
450
481
.num_simult_channels = 4 ,
482
+ .supplies = ad7380_supplies ,
483
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
451
484
.has_mux = true,
452
485
.available_scan_masks = ad7380_2x4_channel_scan_masks ,
453
486
.timing_specs = & ad7380_4_timing ,
@@ -458,6 +491,8 @@ static const struct ad7380_chip_info ad7387_4_chip_info = {
458
491
.channels = ad7387_4_channels ,
459
492
.num_channels = ARRAY_SIZE (ad7387_4_channels ),
460
493
.num_simult_channels = 4 ,
494
+ .supplies = ad7380_supplies ,
495
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
461
496
.has_mux = true,
462
497
.available_scan_masks = ad7380_2x4_channel_scan_masks ,
463
498
.timing_specs = & ad7380_4_timing ,
@@ -468,6 +503,8 @@ static const struct ad7380_chip_info ad7388_4_chip_info = {
468
503
.channels = ad7388_4_channels ,
469
504
.num_channels = ARRAY_SIZE (ad7388_4_channels ),
470
505
.num_simult_channels = 4 ,
506
+ .supplies = ad7380_supplies ,
507
+ .num_supplies = ARRAY_SIZE (ad7380_supplies ),
471
508
.has_mux = true,
472
509
.available_scan_masks = ad7380_2x4_channel_scan_masks ,
473
510
.timing_specs = & ad7380_4_timing ,
@@ -956,7 +993,7 @@ static const struct iio_info ad7380_info = {
956
993
.debugfs_reg_access = & ad7380_debugfs_reg_access ,
957
994
};
958
995
959
- static int ad7380_init (struct ad7380_state * st , struct regulator * vref )
996
+ static int ad7380_init (struct ad7380_state * st , bool external_ref_en )
960
997
{
961
998
int ret ;
962
999
@@ -968,13 +1005,13 @@ static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
968
1005
if (ret < 0 )
969
1006
return ret ;
970
1007
971
- /* select internal or external reference voltage */
972
- ret = regmap_update_bits ( st -> regmap , AD7380_REG_ADDR_CONFIG1 ,
973
- AD7380_CONFIG1_REFSEL ,
974
- FIELD_PREP ( AD7380_CONFIG1_REFSEL ,
975
- vref ? 1 : 0 ));
976
- if ( ret < 0 )
977
- return ret ;
1008
+ if ( external_ref_en ) {
1009
+ /* select external reference voltage */
1010
+ ret = regmap_set_bits ( st -> regmap , AD7380_REG_ADDR_CONFIG1 ,
1011
+ AD7380_CONFIG1_REFSEL );
1012
+ if ( ret < 0 )
1013
+ return ret ;
1014
+ }
978
1015
979
1016
/* This is the default value after reset. */
980
1017
st -> oversampling_ratio = 1 ;
@@ -987,16 +1024,11 @@ static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
987
1024
FIELD_PREP (AD7380_CONFIG2_SDO , 1 ));
988
1025
}
989
1026
990
- static void ad7380_regulator_disable (void * p )
991
- {
992
- regulator_disable (p );
993
- }
994
-
995
1027
static int ad7380_probe (struct spi_device * spi )
996
1028
{
997
1029
struct iio_dev * indio_dev ;
998
1030
struct ad7380_state * st ;
999
- struct regulator * vref ;
1031
+ bool external_ref_en ;
1000
1032
int ret , i ;
1001
1033
1002
1034
indio_dev = devm_iio_device_alloc (& spi -> dev , sizeof (* st ));
@@ -1009,36 +1041,38 @@ static int ad7380_probe(struct spi_device *spi)
1009
1041
if (!st -> chip_info )
1010
1042
return dev_err_probe (& spi -> dev , - EINVAL , "missing match data\n" );
1011
1043
1012
- vref = devm_regulator_get_optional (& spi -> dev , "refio" );
1013
- if (IS_ERR (vref )) {
1014
- if (PTR_ERR (vref ) != - ENODEV )
1015
- return dev_err_probe (& spi -> dev , PTR_ERR (vref ),
1016
- "Failed to get refio regulator\n" );
1017
-
1018
- vref = NULL ;
1019
- }
1044
+ ret = devm_regulator_bulk_get_enable (& spi -> dev , st -> chip_info -> num_supplies ,
1045
+ st -> chip_info -> supplies );
1020
1046
1021
- /*
1022
- * If there is no REFIO supply, then it means that we are using
1023
- * the internal 2.5V reference, otherwise REFIO is reference voltage.
1024
- */
1025
- if (vref ) {
1026
- ret = regulator_enable (vref );
1027
- if (ret )
1028
- return ret ;
1029
-
1030
- ret = devm_add_action_or_reset (& spi -> dev ,
1031
- ad7380_regulator_disable , vref );
1032
- if (ret )
1033
- return ret ;
1047
+ if (ret )
1048
+ return dev_err_probe (& spi -> dev , ret ,
1049
+ "Failed to enable power supplies\n" );
1050
+ fsleep (T_POWERUP_US );
1034
1051
1035
- ret = regulator_get_voltage (vref );
1052
+ if (st -> chip_info -> external_ref_only ) {
1053
+ ret = devm_regulator_get_enable_read_voltage (& spi -> dev ,
1054
+ "refin" );
1036
1055
if (ret < 0 )
1037
- return ret ;
1056
+ return dev_err_probe (& spi -> dev , ret ,
1057
+ "Failed to get refin regulator\n" );
1038
1058
1039
1059
st -> vref_mv = ret / 1000 ;
1060
+
1061
+ /* these chips don't have a register bit for this */
1062
+ external_ref_en = false;
1040
1063
} else {
1041
- st -> vref_mv = AD7380_INTERNAL_REF_MV ;
1064
+ /*
1065
+ * If there is no REFIO supply, then it means that we are using
1066
+ * the internal reference, otherwise REFIO is reference voltage.
1067
+ */
1068
+ ret = devm_regulator_get_enable_read_voltage (& spi -> dev ,
1069
+ "refio" );
1070
+ if (ret < 0 && ret != - ENODEV )
1071
+ return dev_err_probe (& spi -> dev , ret ,
1072
+ "Failed to get refio regulator\n" );
1073
+
1074
+ external_ref_en = ret != - ENODEV ;
1075
+ st -> vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV ;
1042
1076
}
1043
1077
1044
1078
if (st -> chip_info -> num_vcm_supplies > ARRAY_SIZE (st -> vcm_mv ))
@@ -1050,27 +1084,13 @@ static int ad7380_probe(struct spi_device *spi)
1050
1084
* input pin.
1051
1085
*/
1052
1086
for (i = 0 ; i < st -> chip_info -> num_vcm_supplies ; i ++ ) {
1053
- struct regulator * vcm ;
1054
-
1055
- vcm = devm_regulator_get (& spi -> dev ,
1056
- st -> chip_info -> vcm_supplies [i ]);
1057
- if (IS_ERR (vcm ))
1058
- return dev_err_probe (& spi -> dev , PTR_ERR (vcm ),
1059
- "Failed to get %s regulator\n" ,
1060
- st -> chip_info -> vcm_supplies [i ]);
1087
+ const char * vcm = st -> chip_info -> vcm_supplies [i ];
1061
1088
1062
- ret = regulator_enable (vcm );
1063
- if (ret )
1064
- return ret ;
1065
-
1066
- ret = devm_add_action_or_reset (& spi -> dev ,
1067
- ad7380_regulator_disable , vcm );
1068
- if (ret )
1069
- return ret ;
1070
-
1071
- ret = regulator_get_voltage (vcm );
1089
+ ret = devm_regulator_get_enable_read_voltage (& spi -> dev , vcm );
1072
1090
if (ret < 0 )
1073
- return ret ;
1091
+ return dev_err_probe (& spi -> dev , ret ,
1092
+ "Failed to get %s regulator\n" ,
1093
+ vcm );
1074
1094
1075
1095
st -> vcm_mv [i ] = ret / 1000 ;
1076
1096
}
@@ -1135,7 +1155,7 @@ static int ad7380_probe(struct spi_device *spi)
1135
1155
if (ret )
1136
1156
return ret ;
1137
1157
1138
- ret = ad7380_init (st , vref );
1158
+ ret = ad7380_init (st , external_ref_en );
1139
1159
if (ret )
1140
1160
return ret ;
1141
1161
0 commit comments