diff options
author | Nicolin Chen <nicoleotsuka@gmail.com> | 2019-04-17 19:12:09 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2019-04-18 09:37:25 -0400 |
commit | 521c0b6116ef60e4b96ba42dbf285b2ad69071d4 (patch) | |
tree | 5531a43aec4f8fe58c96764af8761bcdd84096ec | |
parent | 7ebd8b66dd9e5a0b65e5ee5e2b8e7ca382ec97b7 (diff) |
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>
-rw-r--r-- | drivers/hwmon/ina3221.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index 74d39d212931..62040aac653c 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c | |||
@@ -309,21 +309,22 @@ static int ina3221_write_chip(struct device *dev, u32 attr, long val) | |||
309 | { | 309 | { |
310 | struct ina3221_data *ina = dev_get_drvdata(dev); | 310 | struct ina3221_data *ina = dev_get_drvdata(dev); |
311 | int ret, idx; | 311 | int ret, idx; |
312 | u32 tmp; | ||
312 | 313 | ||
313 | switch (attr) { | 314 | switch (attr) { |
314 | case hwmon_chip_samples: | 315 | case hwmon_chip_samples: |
315 | idx = find_closest(val, ina3221_avg_samples, | 316 | idx = find_closest(val, ina3221_avg_samples, |
316 | ARRAY_SIZE(ina3221_avg_samples)); | 317 | ARRAY_SIZE(ina3221_avg_samples)); |
317 | 318 | ||
318 | ret = regmap_update_bits(ina->regmap, INA3221_CONFIG, | 319 | tmp = (ina->reg_config & ~INA3221_CONFIG_AVG_MASK) | |
319 | INA3221_CONFIG_AVG_MASK, | 320 | (idx << INA3221_CONFIG_AVG_SHIFT); |
320 | idx << INA3221_CONFIG_AVG_SHIFT); | 321 | ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp); |
321 | if (ret) | 322 | if (ret) |
322 | return ret; | 323 | return ret; |
323 | 324 | ||
324 | /* Update reg_config accordingly */ | 325 | /* Update reg_config accordingly */ |
325 | return regmap_read(ina->regmap, INA3221_CONFIG, | 326 | ina->reg_config = tmp; |
326 | &ina->reg_config); | 327 | return 0; |
327 | default: | 328 | default: |
328 | return -EOPNOTSUPP; | 329 | return -EOPNOTSUPP; |
329 | } | 330 | } |
@@ -359,6 +360,7 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable) | |||
359 | struct ina3221_data *ina = dev_get_drvdata(dev); | 360 | struct ina3221_data *ina = dev_get_drvdata(dev); |
360 | u16 config, mask = INA3221_CONFIG_CHx_EN(channel); | 361 | u16 config, mask = INA3221_CONFIG_CHx_EN(channel); |
361 | u16 config_old = ina->reg_config & mask; | 362 | u16 config_old = ina->reg_config & mask; |
363 | u32 tmp; | ||
362 | int ret; | 364 | int ret; |
363 | 365 | ||
364 | config = enable ? mask : 0; | 366 | config = enable ? mask : 0; |
@@ -377,14 +379,13 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable) | |||
377 | } | 379 | } |
378 | 380 | ||
379 | /* Enable or disable the channel */ | 381 | /* Enable or disable the channel */ |
380 | ret = regmap_update_bits(ina->regmap, INA3221_CONFIG, mask, config); | 382 | tmp = (ina->reg_config & ~mask) | (config & mask); |
383 | ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp); | ||
381 | if (ret) | 384 | if (ret) |
382 | goto fail; | 385 | goto fail; |
383 | 386 | ||
384 | /* Cache the latest config register value */ | 387 | /* Cache the latest config register value */ |
385 | ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config); | 388 | ina->reg_config = tmp; |
386 | if (ret) | ||
387 | goto fail; | ||
388 | 389 | ||
389 | /* For disabling routine, decrease refcount or suspend() at last */ | 390 | /* For disabling routine, decrease refcount or suspend() at last */ |
390 | if (!enable) | 391 | if (!enable) |