@@ -58,7 +58,6 @@ static const u8 num_inputs[] = { 7, 8, 4, 6 };
58
58
59
59
struct adc128_data {
60
60
struct i2c_client * client ;
61
- struct regulator * regulator ;
62
61
int vref ; /* Reference voltage in mV */
63
62
struct mutex update_lock ;
64
63
u8 mode ; /* Operation mode */
@@ -389,7 +388,7 @@ static int adc128_detect(struct i2c_client *client, struct i2c_board_info *info)
389
388
return 0 ;
390
389
}
391
390
392
- static int adc128_init_client (struct adc128_data * data )
391
+ static int adc128_init_client (struct adc128_data * data , bool external_vref )
393
392
{
394
393
struct i2c_client * client = data -> client ;
395
394
int err ;
@@ -408,7 +407,7 @@ static int adc128_init_client(struct adc128_data *data)
408
407
regval |= data -> mode << 1 ;
409
408
410
409
/* If external vref is selected, configure the chip to use it */
411
- if (data -> regulator )
410
+ if (external_vref )
412
411
regval |= 0x01 ;
413
412
414
413
/* Write advanced configuration register */
@@ -430,44 +429,38 @@ static int adc128_init_client(struct adc128_data *data)
430
429
static int adc128_probe (struct i2c_client * client )
431
430
{
432
431
struct device * dev = & client -> dev ;
433
- struct regulator * regulator ;
434
432
struct device * hwmon_dev ;
435
433
struct adc128_data * data ;
434
+ bool external_vref ;
436
435
int err , vref ;
437
436
438
437
data = devm_kzalloc (dev , sizeof (struct adc128_data ), GFP_KERNEL );
439
438
if (!data )
440
439
return - ENOMEM ;
441
440
442
441
/* vref is optional. If specified, is used as chip reference voltage */
443
- regulator = devm_regulator_get_optional (dev , "vref" );
444
- if (!IS_ERR (regulator )) {
445
- data -> regulator = regulator ;
446
- err = regulator_enable (regulator );
447
- if (err < 0 )
448
- return err ;
449
- vref = regulator_get_voltage (regulator );
450
- if (vref < 0 ) {
451
- err = vref ;
452
- goto error ;
453
- }
454
- data -> vref = DIV_ROUND_CLOSEST (vref , 1000 );
455
- } else {
442
+ vref = devm_regulator_get_enable_read_voltage (dev , "vref" );
443
+ if (vref == - ENODEV ) {
444
+ external_vref = false;
456
445
data -> vref = 2560 ; /* 2.56V, in mV */
446
+ } else if (vref < 0 ) {
447
+ return vref ;
448
+ } else {
449
+ external_vref = true;
450
+ data -> vref = DIV_ROUND_CLOSEST (vref , 1000 );
457
451
}
458
452
459
453
/* Operation mode is optional. If unspecified, keep current mode */
460
454
if (of_property_read_u8 (dev -> of_node , "ti,mode" , & data -> mode ) == 0 ) {
461
455
if (data -> mode > 3 ) {
462
456
dev_err (dev , "invalid operation mode %d\n" ,
463
457
data -> mode );
464
- err = - EINVAL ;
465
- goto error ;
458
+ return - EINVAL ;
466
459
}
467
460
} else {
468
461
err = i2c_smbus_read_byte_data (client , ADC128_REG_CONFIG_ADV );
469
462
if (err < 0 )
470
- goto error ;
463
+ return err ;
471
464
data -> mode = (err >> 1 ) & ADC128_REG_MASK ;
472
465
}
473
466
@@ -476,31 +469,16 @@ static int adc128_probe(struct i2c_client *client)
476
469
mutex_init (& data -> update_lock );
477
470
478
471
/* Initialize the chip */
479
- err = adc128_init_client (data );
472
+ err = adc128_init_client (data , external_vref );
480
473
if (err < 0 )
481
- goto error ;
474
+ return err ;
482
475
483
476
hwmon_dev = devm_hwmon_device_register_with_groups (dev , client -> name ,
484
477
data , adc128_groups );
485
- if (IS_ERR (hwmon_dev )) {
486
- err = PTR_ERR (hwmon_dev );
487
- goto error ;
488
- }
478
+ if (IS_ERR (hwmon_dev ))
479
+ return PTR_ERR (hwmon_dev );
489
480
490
481
return 0 ;
491
-
492
- error :
493
- if (data -> regulator )
494
- regulator_disable (data -> regulator );
495
- return err ;
496
- }
497
-
498
- static void adc128_remove (struct i2c_client * client )
499
- {
500
- struct adc128_data * data = i2c_get_clientdata (client );
501
-
502
- if (data -> regulator )
503
- regulator_disable (data -> regulator );
504
482
}
505
483
506
484
static const struct i2c_device_id adc128_id [] = {
@@ -522,7 +500,6 @@ static struct i2c_driver adc128_driver = {
522
500
.of_match_table = of_match_ptr (adc128_of_match ),
523
501
},
524
502
.probe = adc128_probe ,
525
- .remove = adc128_remove ,
526
503
.id_table = adc128_id ,
527
504
.detect = adc128_detect ,
528
505
.address_list = normal_i2c ,
0 commit comments