Skip to content

Commit

Permalink
hwmon: (tmp421) really disable channels
Browse files Browse the repository at this point in the history
Recent patch added possibility to disable selected channels. That would
only make sure that the ENODATA is returned for those channels but would
not configure the actual hardware.

With this patch, the config register is written to make sure the
channels are disabled also at hardware level.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
  • Loading branch information
Krzysztof Adamski authored and intel-lab-lkp committed Sep 7, 2021
1 parent 890bb82 commit 56fe3c4
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions drivers/hwmon/tmp421.c
Expand Up @@ -33,6 +33,8 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
/* The TMP421 registers */
#define TMP421_STATUS_REG 0x08
#define TMP421_CONFIG_REG_1 0x09
#define TMP421_CONFIG_REG_2 0x0A
#define TMP421_CONFIG_REG_REN(x) (BIT(3 + (x)))
#define TMP421_CONVERSION_RATE_REG 0x0B
#define TMP421_N_FACTOR_REG_1 0x21
#define TMP421_MANUFACTURER_ID_REG 0xFE
Expand Down Expand Up @@ -351,6 +353,25 @@ void tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data)
}
}

void tmp421_disable_channels(struct i2c_client *client, uint8_t mask)
{
int err;
int cfg = i2c_smbus_read_byte_data(client, TMP421_CONFIG_REG_2);

if (cfg < 0) {
dev_err(&client->dev,
"error reading register, can't disable channels\n");
return;
}

cfg &= ~mask;

err = i2c_smbus_write_byte_data(client, TMP421_CONFIG_REG_2, cfg);
if (err < 0)
dev_err(&client->dev,
"error writing register, can't disable channels\n");
}

static const struct hwmon_ops tmp421_ops = {
.is_visible = tmp421_is_visible,
.read = tmp421_read,
Expand All @@ -363,6 +384,7 @@ static int tmp421_probe(struct i2c_client *client)
struct device *hwmon_dev;
struct tmp421_data *data;
int i, err;
u8 disable = 0;

data = devm_kzalloc(dev, sizeof(struct tmp421_data), GFP_KERNEL);
if (!data)
Expand All @@ -380,11 +402,18 @@ static int tmp421_probe(struct i2c_client *client)
if (err)
return err;

for (i = 0; i < data->channels; i++)
data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;

tmp421_probe_from_dt(client, data);

for (i = 0; i < data->channels; i++) {
data->temp_config[i] |= HWMON_T_INPUT | HWMON_T_FAULT;
if (data->channel[i].disabled)
disable |= TMP421_CONFIG_REG_REN(i);

}

if (disable)
tmp421_disable_channels(client, disable);

data->chip.ops = &tmp421_ops;
data->chip.info = data->info;

Expand Down

0 comments on commit 56fe3c4

Please sign in to comment.