|
91 | 91 | */ |
92 | 92 | #define INA226_TOTAL_CONV_TIME_DEFAULT 2200 |
93 | 93 |
|
| 94 | +static bool ina2xx_writeable_reg(struct device *dev, unsigned int reg) |
| 95 | +{ |
| 96 | + switch (reg) { |
| 97 | + case INA2XX_CONFIG: |
| 98 | + case INA2XX_CALIBRATION: |
| 99 | + case INA226_MASK_ENABLE: |
| 100 | + case INA226_ALERT_LIMIT: |
| 101 | + return true; |
| 102 | + default: |
| 103 | + return false; |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +static bool ina2xx_volatile_reg(struct device *dev, unsigned int reg) |
| 108 | +{ |
| 109 | + switch (reg) { |
| 110 | + case INA2XX_SHUNT_VOLTAGE: |
| 111 | + case INA2XX_BUS_VOLTAGE: |
| 112 | + case INA2XX_POWER: |
| 113 | + case INA2XX_CURRENT: |
| 114 | + return true; |
| 115 | + default: |
| 116 | + return false; |
| 117 | + } |
| 118 | +} |
| 119 | + |
94 | 120 | static const struct regmap_config ina2xx_regmap_config = { |
95 | 121 | .reg_bits = 8, |
96 | 122 | .val_bits = 16, |
| 123 | + .use_single_write = true, |
| 124 | + .use_single_read = true, |
97 | 125 | .max_register = INA2XX_MAX_REGISTERS, |
| 126 | + .cache_type = REGCACHE_MAPLE, |
| 127 | + .volatile_reg = ina2xx_volatile_reg, |
| 128 | + .writeable_reg = ina2xx_writeable_reg, |
98 | 129 | }; |
99 | 130 |
|
100 | 131 | enum ina2xx_ids { ina219, ina226 }; |
@@ -229,16 +260,16 @@ static int ina2xx_read_reg(struct device *dev, int reg, unsigned int *regval) |
229 | 260 | if (*regval == 0) { |
230 | 261 | unsigned int cal; |
231 | 262 |
|
232 | | - ret = regmap_read(regmap, INA2XX_CALIBRATION, &cal); |
| 263 | + ret = regmap_read_bypassed(regmap, INA2XX_CALIBRATION, &cal); |
233 | 264 | if (ret < 0) |
234 | 265 | return ret; |
235 | 266 |
|
236 | 267 | if (cal == 0) { |
237 | 268 | dev_warn(dev, "chip not calibrated, reinitializing\n"); |
238 | 269 |
|
239 | | - ret = ina2xx_init(data); |
240 | | - if (ret < 0) |
241 | | - return ret; |
| 270 | + regcache_mark_dirty(regmap); |
| 271 | + regcache_sync(regmap); |
| 272 | + |
242 | 273 | /* |
243 | 274 | * Let's make sure the power and current |
244 | 275 | * registers have been updated before trying |
@@ -340,7 +371,7 @@ static int ina226_reg_to_alert(struct ina2xx_data *data, u32 mask, u16 regval) |
340 | 371 | * Turns alert limit values into register values. |
341 | 372 | * Opposite of the formula in ina2xx_get_value(). |
342 | 373 | */ |
343 | | -static s16 ina226_alert_to_reg(struct ina2xx_data *data, u32 mask, int val) |
| 374 | +static u16 ina226_alert_to_reg(struct ina2xx_data *data, u32 mask, int val) |
344 | 375 | { |
345 | 376 | switch (mask) { |
346 | 377 | case INA226_SHUNT_OVER_VOLTAGE_MASK: |
@@ -439,16 +470,17 @@ static ssize_t ina226_alarm_show(struct device *dev, |
439 | 470 | { |
440 | 471 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
441 | 472 | struct ina2xx_data *data = dev_get_drvdata(dev); |
442 | | - int regval; |
| 473 | + unsigned int mask; |
443 | 474 | int alarm = 0; |
444 | 475 | int ret; |
445 | 476 |
|
446 | | - ret = regmap_read(data->regmap, INA226_MASK_ENABLE, ®val); |
| 477 | + ret = regmap_read_bypassed(data->regmap, INA226_MASK_ENABLE, &mask); |
447 | 478 | if (ret) |
448 | 479 | return ret; |
449 | 480 |
|
450 | | - alarm = (regval & attr->index) && |
451 | | - (regval & INA226_ALERT_FUNCTION_FLAG); |
| 481 | + alarm = (mask & attr->index) && |
| 482 | + (mask & INA226_ALERT_FUNCTION_FLAG); |
| 483 | + |
452 | 484 | return sysfs_emit(buf, "%d\n", alarm); |
453 | 485 | } |
454 | 486 |
|
|
0 commit comments