hwmon: (lm90) Read limit registers only once

Read limit registers only once at startup or after errors to improve
driver performance.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Guenter Roeck 2016-06-13 19:26:45 -07:00
parent 37ad04d7a9
commit 10bfef47bd

View File

@ -508,6 +508,102 @@ static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data,
data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64);
} }
static int lm90_update_limits(struct device *dev)
{
struct lm90_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int val;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT);
if (val < 0)
return val;
data->temp8[LOCAL_CRIT] = val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
if (val < 0)
return val;
data->temp8[REMOTE_CRIT] = val;
val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST);
if (val < 0)
return val;
data->temp_hyst = val;
lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
if (val < 0)
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)
return val;
data->temp11[REMOTE_LOW] |= val;
}
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
if (val < 0)
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)
return val;
data->temp11[REMOTE_HIGH] |= val;
}
if (data->flags & LM90_HAVE_OFFSET) {
val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH,
LM90_REG_R_REMOTE_OFFSL);
if (val < 0)
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)
return val;
data->temp8[LOCAL_EMERG] = val;
val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
if (val < 0)
return val;
data->temp8[REMOTE_EMERG] = val;
}
if (data->kind == max6696) {
val = lm90_select_remote_channel(client, data, 1);
if (val < 0)
return val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
if (val < 0)
return val;
data->temp8[REMOTE2_CRIT] = val;
val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
if (val < 0)
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) static struct lm90_data *lm90_update_device(struct device *dev)
{ {
struct lm90_data *data = dev_get_drvdata(dev); struct lm90_data *data = dev_get_drvdata(dev);
@ -517,10 +613,19 @@ static struct lm90_data *lm90_update_device(struct device *dev)
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
if (!data->valid) {
val = lm90_update_limits(dev);
if (val < 0)
goto error;
}
next_update = data->last_updated + next_update = data->last_updated +
msecs_to_jiffies(data->update_interval); msecs_to_jiffies(data->update_interval);
if (time_after(jiffies, next_update) || !data->valid) { if (time_after(jiffies, next_update) || !data->valid) {
dev_dbg(&client->dev, "Updating lm90 data.\n"); dev_dbg(&client->dev, "Updating lm90 data.\n");
data->valid = 0;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW); val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW);
if (val < 0) if (val < 0)
goto error; goto error;
@ -531,20 +636,6 @@ static struct lm90_data *lm90_update_device(struct device *dev)
goto error; goto error;
data->temp8[LOCAL_HIGH] = val; data->temp8[LOCAL_HIGH] = val;
val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT);
if (val < 0)
goto error;
data->temp8[LOCAL_CRIT] = val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
if (val < 0)
goto error;
data->temp8[REMOTE_CRIT] = val;
val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST);
if (val < 0)
goto error;
data->temp_hyst = val;
if (data->reg_local_ext) { if (data->reg_local_ext) {
val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP, val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
data->reg_local_ext); data->reg_local_ext);
@ -563,44 +654,6 @@ static struct lm90_data *lm90_update_device(struct device *dev)
goto error; goto error;
data->temp11[REMOTE_TEMP] = val; data->temp11[REMOTE_TEMP] = val;
lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
if (val < 0)
goto error;
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;
data->temp11[REMOTE_LOW] |= val;
}
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
if (val < 0)
goto error;
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;
data->temp11[REMOTE_HIGH] |= val;
}
if (data->flags & LM90_HAVE_OFFSET) {
val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH,
LM90_REG_R_REMOTE_OFFSL);
if (val < 0)
goto error;
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;
data->temp8[LOCAL_EMERG] = val;
val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
if (val < 0)
goto error;
data->temp8[REMOTE_EMERG] = val;
}
val = lm90_read_reg(client, LM90_REG_R_STATUS); val = lm90_read_reg(client, LM90_REG_R_STATUS);
if (val < 0) if (val < 0)
goto error; goto error;
@ -611,32 +664,12 @@ static struct lm90_data *lm90_update_device(struct device *dev)
if (val < 0) if (val < 0)
goto error; goto error;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
if (val < 0)
goto error;
data->temp8[REMOTE2_CRIT] = val;
val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
if (val < 0)
goto error;
data->temp8[REMOTE2_EMERG] = val;
val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
LM90_REG_R_REMOTE_TEMPL); LM90_REG_R_REMOTE_TEMPL);
if (val < 0) if (val < 0)
goto error; goto error;
data->temp11[REMOTE2_TEMP] = val; data->temp11[REMOTE2_TEMP] = val;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
if (val < 0)
goto error;
data->temp11[REMOTE2_LOW] = val << 8;
val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
if (val < 0)
goto error;
data->temp11[REMOTE2_HIGH] = val << 8;
lm90_select_remote_channel(client, data, 0); lm90_select_remote_channel(client, data, 0);
val = lm90_read_reg(client, MAX6696_REG_R_STATUS2); val = lm90_read_reg(client, MAX6696_REG_R_STATUS2);