hwmon: (ina3221) Do not read-back to cache reg_config
Reading back the CONFIG register increases an extra I2C transaction. This's not necessary and could be replaced with a local variable caching the register settings. So this patch replaces two readback regmap_read() calls with a tmp variable. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
committed by
Guenter Roeck
parent
7ebd8b66dd
commit
521c0b6116
@@ -309,21 +309,22 @@ static int ina3221_write_chip(struct device *dev, u32 attr, long val)
|
|||||||
{
|
{
|
||||||
struct ina3221_data *ina = dev_get_drvdata(dev);
|
struct ina3221_data *ina = dev_get_drvdata(dev);
|
||||||
int ret, idx;
|
int ret, idx;
|
||||||
|
u32 tmp;
|
||||||
|
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case hwmon_chip_samples:
|
case hwmon_chip_samples:
|
||||||
idx = find_closest(val, ina3221_avg_samples,
|
idx = find_closest(val, ina3221_avg_samples,
|
||||||
ARRAY_SIZE(ina3221_avg_samples));
|
ARRAY_SIZE(ina3221_avg_samples));
|
||||||
|
|
||||||
ret = regmap_update_bits(ina->regmap, INA3221_CONFIG,
|
tmp = (ina->reg_config & ~INA3221_CONFIG_AVG_MASK) |
|
||||||
INA3221_CONFIG_AVG_MASK,
|
(idx << INA3221_CONFIG_AVG_SHIFT);
|
||||||
idx << INA3221_CONFIG_AVG_SHIFT);
|
ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Update reg_config accordingly */
|
/* Update reg_config accordingly */
|
||||||
return regmap_read(ina->regmap, INA3221_CONFIG,
|
ina->reg_config = tmp;
|
||||||
&ina->reg_config);
|
return 0;
|
||||||
default:
|
default:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
@@ -359,6 +360,7 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable)
|
|||||||
struct ina3221_data *ina = dev_get_drvdata(dev);
|
struct ina3221_data *ina = dev_get_drvdata(dev);
|
||||||
u16 config, mask = INA3221_CONFIG_CHx_EN(channel);
|
u16 config, mask = INA3221_CONFIG_CHx_EN(channel);
|
||||||
u16 config_old = ina->reg_config & mask;
|
u16 config_old = ina->reg_config & mask;
|
||||||
|
u32 tmp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
config = enable ? mask : 0;
|
config = enable ? mask : 0;
|
||||||
@@ -377,14 +379,13 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Enable or disable the channel */
|
/* Enable or disable the channel */
|
||||||
ret = regmap_update_bits(ina->regmap, INA3221_CONFIG, mask, config);
|
tmp = (ina->reg_config & ~mask) | (config & mask);
|
||||||
|
ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* Cache the latest config register value */
|
/* Cache the latest config register value */
|
||||||
ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config);
|
ina->reg_config = tmp;
|
||||||
if (ret)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
/* For disabling routine, decrease refcount or suspend() at last */
|
/* For disabling routine, decrease refcount or suspend() at last */
|
||||||
if (!enable)
|
if (!enable)
|
||||||
|
Reference in New Issue
Block a user