diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-03-30 15:46:40 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-03-30 15:46:40 -0400 |
commit | e4879e28abd67b894fb9d2db0afd08f1945670ba (patch) | |
tree | e6e9c1269c9ed949fb89bf7d31e116ace255d2ff /drivers/hwmon/ds1621.c | |
parent | 594592dc6f68356a3b7278eb4d260a50a66f0a06 (diff) |
hwmon: (ds1621) Avoid unneeded register access
Register access over SMBus isn't cheap, so avoid register access where
possible:
* Only write back the configuration register if it changed.
* Don't refresh the register cache when we don't have to.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Diffstat (limited to 'drivers/hwmon/ds1621.c')
-rw-r--r-- | drivers/hwmon/ds1621.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index fe160c54b959..53f88f511816 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -101,17 +101,20 @@ static int ds1621_write_temp(struct i2c_client *client, u8 reg, u16 value) | |||
101 | 101 | ||
102 | static void ds1621_init_client(struct i2c_client *client) | 102 | static void ds1621_init_client(struct i2c_client *client) |
103 | { | 103 | { |
104 | int reg = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); | 104 | u8 conf, new_conf; |
105 | |||
106 | new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); | ||
105 | /* switch to continuous conversion mode */ | 107 | /* switch to continuous conversion mode */ |
106 | reg &= ~ DS1621_REG_CONFIG_1SHOT; | 108 | new_conf &= ~DS1621_REG_CONFIG_1SHOT; |
107 | 109 | ||
108 | /* setup output polarity */ | 110 | /* setup output polarity */ |
109 | if (polarity == 0) | 111 | if (polarity == 0) |
110 | reg &= ~DS1621_REG_CONFIG_POLARITY; | 112 | new_conf &= ~DS1621_REG_CONFIG_POLARITY; |
111 | else if (polarity == 1) | 113 | else if (polarity == 1) |
112 | reg |= DS1621_REG_CONFIG_POLARITY; | 114 | new_conf |= DS1621_REG_CONFIG_POLARITY; |
113 | 115 | ||
114 | i2c_smbus_write_byte_data(client, DS1621_REG_CONF, reg); | 116 | if (conf != new_conf) |
117 | i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf); | ||
115 | 118 | ||
116 | /* start conversion */ | 119 | /* start conversion */ |
117 | i2c_smbus_write_byte(client, DS1621_COM_START); | 120 | i2c_smbus_write_byte(client, DS1621_COM_START); |
@@ -170,7 +173,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
170 | { | 173 | { |
171 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 174 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
172 | struct i2c_client *client = to_i2c_client(dev); | 175 | struct i2c_client *client = to_i2c_client(dev); |
173 | struct ds1621_data *data = ds1621_update_client(dev); | 176 | struct ds1621_data *data = i2c_get_clientdata(client); |
174 | u16 val = LM75_TEMP_TO_REG(simple_strtol(buf, NULL, 10)); | 177 | u16 val = LM75_TEMP_TO_REG(simple_strtol(buf, NULL, 10)); |
175 | 178 | ||
176 | mutex_lock(&data->update_lock); | 179 | mutex_lock(&data->update_lock); |