aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/tmp102.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/tmp102.c')
-rw-r--r--drivers/hwmon/tmp102.c44
1 files changed, 17 insertions, 27 deletions
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
index 5bd194968801..643aa8c94535 100644
--- a/drivers/hwmon/tmp102.c
+++ b/drivers/hwmon/tmp102.c
@@ -55,19 +55,6 @@ struct tmp102 {
55 int temp[3]; 55 int temp[3];
56}; 56};
57 57
58/* SMBus specifies low byte first, but the TMP102 returns high byte first,
59 * so we have to swab16 the values */
60static inline int tmp102_read_reg(struct i2c_client *client, u8 reg)
61{
62 int result = i2c_smbus_read_word_data(client, reg);
63 return result < 0 ? result : swab16(result);
64}
65
66static inline int tmp102_write_reg(struct i2c_client *client, u8 reg, u16 val)
67{
68 return i2c_smbus_write_word_data(client, reg, swab16(val));
69}
70
71/* convert left adjusted 13-bit TMP102 register value to milliCelsius */ 58/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
72static inline int tmp102_reg_to_mC(s16 val) 59static inline int tmp102_reg_to_mC(s16 val)
73{ 60{
@@ -94,7 +81,8 @@ static struct tmp102 *tmp102_update_device(struct i2c_client *client)
94 if (time_after(jiffies, tmp102->last_update + HZ / 3)) { 81 if (time_after(jiffies, tmp102->last_update + HZ / 3)) {
95 int i; 82 int i;
96 for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) { 83 for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) {
97 int status = tmp102_read_reg(client, tmp102_reg[i]); 84 int status = i2c_smbus_read_word_swapped(client,
85 tmp102_reg[i]);
98 if (status > -1) 86 if (status > -1)
99 tmp102->temp[i] = tmp102_reg_to_mC(status); 87 tmp102->temp[i] = tmp102_reg_to_mC(status);
100 } 88 }
@@ -130,8 +118,8 @@ static ssize_t tmp102_set_temp(struct device *dev,
130 118
131 mutex_lock(&tmp102->lock); 119 mutex_lock(&tmp102->lock);
132 tmp102->temp[sda->index] = val; 120 tmp102->temp[sda->index] = val;
133 status = tmp102_write_reg(client, tmp102_reg[sda->index], 121 status = i2c_smbus_write_word_swapped(client, tmp102_reg[sda->index],
134 tmp102_mC_to_reg(val)); 122 tmp102_mC_to_reg(val));
135 mutex_unlock(&tmp102->lock); 123 mutex_unlock(&tmp102->lock);
136 return status ? : count; 124 return status ? : count;
137} 125}
@@ -178,18 +166,19 @@ static int __devinit tmp102_probe(struct i2c_client *client,
178 } 166 }
179 i2c_set_clientdata(client, tmp102); 167 i2c_set_clientdata(client, tmp102);
180 168
181 status = tmp102_read_reg(client, TMP102_CONF_REG); 169 status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
182 if (status < 0) { 170 if (status < 0) {
183 dev_err(&client->dev, "error reading config register\n"); 171 dev_err(&client->dev, "error reading config register\n");
184 goto fail_free; 172 goto fail_free;
185 } 173 }
186 tmp102->config_orig = status; 174 tmp102->config_orig = status;
187 status = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG); 175 status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
176 TMP102_CONFIG);
188 if (status < 0) { 177 if (status < 0) {
189 dev_err(&client->dev, "error writing config register\n"); 178 dev_err(&client->dev, "error writing config register\n");
190 goto fail_restore_config; 179 goto fail_restore_config;
191 } 180 }
192 status = tmp102_read_reg(client, TMP102_CONF_REG); 181 status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
193 if (status < 0) { 182 if (status < 0) {
194 dev_err(&client->dev, "error reading config register\n"); 183 dev_err(&client->dev, "error reading config register\n");
195 goto fail_restore_config; 184 goto fail_restore_config;
@@ -222,7 +211,8 @@ static int __devinit tmp102_probe(struct i2c_client *client,
222fail_remove_sysfs: 211fail_remove_sysfs:
223 sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group); 212 sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group);
224fail_restore_config: 213fail_restore_config:
225 tmp102_write_reg(client, TMP102_CONF_REG, tmp102->config_orig); 214 i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
215 tmp102->config_orig);
226fail_free: 216fail_free:
227 kfree(tmp102); 217 kfree(tmp102);
228 218
@@ -240,10 +230,10 @@ static int __devexit tmp102_remove(struct i2c_client *client)
240 if (tmp102->config_orig & TMP102_CONF_SD) { 230 if (tmp102->config_orig & TMP102_CONF_SD) {
241 int config; 231 int config;
242 232
243 config = tmp102_read_reg(client, TMP102_CONF_REG); 233 config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
244 if (config >= 0) 234 if (config >= 0)
245 tmp102_write_reg(client, TMP102_CONF_REG, 235 i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
246 config | TMP102_CONF_SD); 236 config | TMP102_CONF_SD);
247 } 237 }
248 238
249 kfree(tmp102); 239 kfree(tmp102);
@@ -257,12 +247,12 @@ static int tmp102_suspend(struct device *dev)
257 struct i2c_client *client = to_i2c_client(dev); 247 struct i2c_client *client = to_i2c_client(dev);
258 int config; 248 int config;
259 249
260 config = tmp102_read_reg(client, TMP102_CONF_REG); 250 config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
261 if (config < 0) 251 if (config < 0)
262 return config; 252 return config;
263 253
264 config |= TMP102_CONF_SD; 254 config |= TMP102_CONF_SD;
265 return tmp102_write_reg(client, TMP102_CONF_REG, config); 255 return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config);
266} 256}
267 257
268static int tmp102_resume(struct device *dev) 258static int tmp102_resume(struct device *dev)
@@ -270,12 +260,12 @@ static int tmp102_resume(struct device *dev)
270 struct i2c_client *client = to_i2c_client(dev); 260 struct i2c_client *client = to_i2c_client(dev);
271 int config; 261 int config;
272 262
273 config = tmp102_read_reg(client, TMP102_CONF_REG); 263 config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
274 if (config < 0) 264 if (config < 0)
275 return config; 265 return config;
276 266
277 config &= ~TMP102_CONF_SD; 267 config &= ~TMP102_CONF_SD;
278 return tmp102_write_reg(client, TMP102_CONF_REG, config); 268 return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config);
279} 269}
280 270
281static const struct dev_pm_ops tmp102_dev_pm_ops = { 271static const struct dev_pm_ops tmp102_dev_pm_ops = {