Skip to content

Commit e2f75e6

Browse files
royvandoormaal-ptgroeck
authored andcommitted
hwmon: (adc128d818) Fix advanced configuration register init
If the operation mode is non-zero and an external reference voltage is set, first the operation mode is written to the advanced configuration register, followed by the externel reference enable bit, resetting the configuration mode to 0. To fix this, first compose the value of the advanced configuration register based on the configuration mode and the external reference voltage. The advanced configuration register is then written to the device, if it is different from the default register value (0x0). Signed-off-by: Roy van Doormaal <[email protected]> Link: https://lore.kernel.org/r/20200728151846.231785-1-roy.van.doormaal@prodrive-technologies.com Signed-off-by: Guenter Roeck <[email protected]>
1 parent dfddc57 commit e2f75e6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

drivers/hwmon/adc128d818.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static int adc128_init_client(struct adc128_data *data)
393393
{
394394
struct i2c_client *client = data->client;
395395
int err;
396+
u8 regval = 0x0;
396397

397398
/*
398399
* Reset chip to defaults.
@@ -403,10 +404,17 @@ static int adc128_init_client(struct adc128_data *data)
403404
return err;
404405

405406
/* Set operation mode, if non-default */
406-
if (data->mode != 0) {
407-
err = i2c_smbus_write_byte_data(client,
408-
ADC128_REG_CONFIG_ADV,
409-
data->mode << 1);
407+
if (data->mode != 0)
408+
regval |= data->mode << 1;
409+
410+
/* If external vref is selected, configure the chip to use it */
411+
if (data->regulator)
412+
regval |= 0x01;
413+
414+
/* Write advanced configuration register */
415+
if (regval != 0x0) {
416+
err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG_ADV,
417+
regval);
410418
if (err)
411419
return err;
412420
}
@@ -416,14 +424,6 @@ static int adc128_init_client(struct adc128_data *data)
416424
if (err)
417425
return err;
418426

419-
/* If external vref is selected, configure the chip to use it */
420-
if (data->regulator) {
421-
err = i2c_smbus_write_byte_data(client,
422-
ADC128_REG_CONFIG_ADV, 0x01);
423-
if (err)
424-
return err;
425-
}
426-
427427
return 0;
428428
}
429429

0 commit comments

Comments
 (0)