Commit 10bfef47 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (lm90) Read limit registers only once

Read limit registers only once at startup or after errors to improve
driver performance.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 37ad04d7
......@@ -508,79 +508,48 @@ static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data,
data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64);
}
static struct lm90_data *lm90_update_device(struct device *dev)
static int lm90_update_limits(struct device *dev)
{
struct lm90_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
unsigned long next_update;
int val = 0;
mutex_lock(&data->update_lock);
next_update = data->last_updated +
msecs_to_jiffies(data->update_interval);
if (time_after(jiffies, next_update) || !data->valid) {
dev_dbg(&client->dev, "Updating lm90 data.\n");
val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW);
if (val < 0)
goto error;
data->temp8[LOCAL_LOW] = val;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH);
if (val < 0)
goto error;
data->temp8[LOCAL_HIGH] = val;
int val;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT);
if (val < 0)
goto error;
return val;
data->temp8[LOCAL_CRIT] = val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
if (val < 0)
goto error;
return val;
data->temp8[REMOTE_CRIT] = val;
val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST);
if (val < 0)
goto error;
return val;
data->temp_hyst = val;
if (data->reg_local_ext) {
val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
data->reg_local_ext);
if (val < 0)
goto error;
data->temp11[LOCAL_TEMP] = val;
} else {
val = lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP);
if (val < 0)
goto error;
data->temp11[LOCAL_TEMP] = val << 8;
}
val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
LM90_REG_R_REMOTE_TEMPL);
if (val < 0)
goto error;
data->temp11[REMOTE_TEMP] = val;
lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
if (val < 0)
goto error;
return val;
data->temp11[REMOTE_LOW] = val << 8;
if (data->flags & LM90_HAVE_REM_LIMIT_EXT) {
val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL);
if (val < 0)
goto error;
return val;
data->temp11[REMOTE_LOW] |= val;
}
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
if (val < 0)
goto error;
return val;
data->temp11[REMOTE_HIGH] = val << 8;
if (data->flags & LM90_HAVE_REM_LIMIT_EXT) {
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL);
if (val < 0)
goto error;
return val;
data->temp11[REMOTE_HIGH] |= val;
}
......@@ -588,54 +557,118 @@ static struct lm90_data *lm90_update_device(struct device *dev)
val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH,
LM90_REG_R_REMOTE_OFFSL);
if (val < 0)
goto error;
return val;
data->temp11[REMOTE_OFFSET] = val;
}
if (data->flags & LM90_HAVE_EMERGENCY) {
val = lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG);
if (val < 0)
goto error;
return val;
data->temp8[LOCAL_EMERG] = val;
val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
if (val < 0)
goto error;
return val;
data->temp8[REMOTE_EMERG] = val;
}
val = lm90_read_reg(client, LM90_REG_R_STATUS);
if (val < 0)
goto error;
data->alarms = val; /* lower 8 bit of alarms */
if (data->kind == max6696) {
val = lm90_select_remote_channel(client, data, 1);
if (val < 0)
goto error;
return val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
if (val < 0)
goto error;
return val;
data->temp8[REMOTE2_CRIT] = val;
val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
if (val < 0)
goto error;
return val;
data->temp8[REMOTE2_EMERG] = val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
if (val < 0)
return val;
data->temp11[REMOTE2_LOW] = val << 8;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
if (val < 0)
return val;
data->temp11[REMOTE2_HIGH] = val << 8;
lm90_select_remote_channel(client, data, 0);
}
return 0;
}
static struct lm90_data *lm90_update_device(struct device *dev)
{
struct lm90_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
unsigned long next_update;
int val = 0;
mutex_lock(&data->update_lock);
if (!data->valid) {
val = lm90_update_limits(dev);
if (val < 0)
goto error;
}
next_update = data->last_updated +
msecs_to_jiffies(data->update_interval);
if (time_after(jiffies, next_update) || !data->valid) {
dev_dbg(&client->dev, "Updating lm90 data.\n");
data->valid = 0;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW);
if (val < 0)
goto error;
data->temp8[LOCAL_LOW] = val;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH);
if (val < 0)
goto error;
data->temp8[LOCAL_HIGH] = val;
if (data->reg_local_ext) {
val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
data->reg_local_ext);
if (val < 0)
goto error;
data->temp11[LOCAL_TEMP] = val;
} else {
val = lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP);
if (val < 0)
goto error;
data->temp11[LOCAL_TEMP] = val << 8;
}
val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
LM90_REG_R_REMOTE_TEMPL);
if (val < 0)
goto error;
data->temp11[REMOTE2_TEMP] = val;
data->temp11[REMOTE_TEMP] = val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
val = lm90_read_reg(client, LM90_REG_R_STATUS);
if (val < 0)
goto error;
data->temp11[REMOTE2_LOW] = val << 8;
data->alarms = val; /* lower 8 bit of alarms */
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
if (data->kind == max6696) {
val = lm90_select_remote_channel(client, data, 1);
if (val < 0)
goto error;
data->temp11[REMOTE2_HIGH] = val << 8;
val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
LM90_REG_R_REMOTE_TEMPL);
if (val < 0)
goto error;
data->temp11[REMOTE2_TEMP] = val;
lm90_select_remote_channel(client, data, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment