hwmon: (max6650) Simplify alarm handling

Instead of re-reading the alarm register after reporting an alarm,
mark cached values as invalid. While this results in always reading all
data on subsequent reads, it is quite unlikely that such reads will
actually happen before the cache times out. The upside is avoiding
unnecessary unconditional i2c read operations.

Cc: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Guenter Roeck 2019-06-07 10:23:21 -07:00
parent f5b20b11bb
commit 0d5cc9383e
1 changed files with 3 additions and 6 deletions

View File

@ -512,15 +512,12 @@ static ssize_t alarm_show(struct device *dev,
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct max6650_data *data = max6650_update_device(dev); struct max6650_data *data = max6650_update_device(dev);
struct i2c_client *client = data->client; bool alarm = data->alarm & attr->index;
int alarm = 0;
if (data->alarm & attr->index) { if (alarm) {
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
alarm = 1;
data->alarm &= ~attr->index; data->alarm &= ~attr->index;
data->alarm |= i2c_smbus_read_byte_data(client, data->valid = false;
MAX6650_REG_ALARM);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
} }