Skip to content

Commit

Permalink
hwmon: (adc128d818) Fix advanced configuration register init
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
royvandoormaal authored and groeck committed Aug 4, 2020
1 parent dfddc57 commit e2f75e6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/hwmon/adc128d818.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ static int adc128_init_client(struct adc128_data *data)
{
struct i2c_client *client = data->client;
int err;
u8 regval = 0x0;

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

/* Set operation mode, if non-default */
if (data->mode != 0) {
err = i2c_smbus_write_byte_data(client,
ADC128_REG_CONFIG_ADV,
data->mode << 1);
if (data->mode != 0)
regval |= data->mode << 1;

/* If external vref is selected, configure the chip to use it */
if (data->regulator)
regval |= 0x01;

/* Write advanced configuration register */
if (regval != 0x0) {
err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG_ADV,
regval);
if (err)
return err;
}
Expand All @@ -416,14 +424,6 @@ static int adc128_init_client(struct adc128_data *data)
if (err)
return err;

/* If external vref is selected, configure the chip to use it */
if (data->regulator) {
err = i2c_smbus_write_byte_data(client,
ADC128_REG_CONFIG_ADV, 0x01);
if (err)
return err;
}

return 0;
}

Expand Down

0 comments on commit e2f75e6

Please sign in to comment.