aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/jc42.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/jc42.c')
-rw-r--r--drivers/hwmon/jc42.c52
1 files changed, 20 insertions, 32 deletions
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
index 02cebb74e206..2d3d72805ff4 100644
--- a/drivers/hwmon/jc42.c
+++ b/drivers/hwmon/jc42.c
@@ -154,8 +154,6 @@ static int jc42_probe(struct i2c_client *client,
154 const struct i2c_device_id *id); 154 const struct i2c_device_id *id);
155static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info); 155static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info);
156static int jc42_remove(struct i2c_client *client); 156static int jc42_remove(struct i2c_client *client);
157static int jc42_read_value(struct i2c_client *client, u8 reg);
158static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value);
159 157
160static struct jc42_data *jc42_update_device(struct device *dev); 158static struct jc42_data *jc42_update_device(struct device *dev);
161 159
@@ -187,7 +185,7 @@ static int jc42_suspend(struct device *dev)
187 struct jc42_data *data = i2c_get_clientdata(client); 185 struct jc42_data *data = i2c_get_clientdata(client);
188 186
189 data->config |= JC42_CFG_SHUTDOWN; 187 data->config |= JC42_CFG_SHUTDOWN;
190 jc42_write_value(client, JC42_REG_CONFIG, data->config); 188 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config);
191 return 0; 189 return 0;
192} 190}
193 191
@@ -197,7 +195,7 @@ static int jc42_resume(struct device *dev)
197 struct jc42_data *data = i2c_get_clientdata(client); 195 struct jc42_data *data = i2c_get_clientdata(client);
198 196
199 data->config &= ~JC42_CFG_SHUTDOWN; 197 data->config &= ~JC42_CFG_SHUTDOWN;
200 jc42_write_value(client, JC42_REG_CONFIG, data->config); 198 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config);
201 return 0; 199 return 0;
202} 200}
203 201
@@ -315,7 +313,7 @@ static ssize_t set_##value(struct device *dev, \
315 return -EINVAL; \ 313 return -EINVAL; \
316 mutex_lock(&data->update_lock); \ 314 mutex_lock(&data->update_lock); \
317 data->value = jc42_temp_to_reg(val, data->extended); \ 315 data->value = jc42_temp_to_reg(val, data->extended); \
318 err = jc42_write_value(client, reg, data->value); \ 316 err = i2c_smbus_write_word_swapped(client, reg, data->value); \
319 if (err < 0) \ 317 if (err < 0) \
320 ret = err; \ 318 ret = err; \
321 mutex_unlock(&data->update_lock); \ 319 mutex_unlock(&data->update_lock); \
@@ -357,7 +355,8 @@ static ssize_t set_temp_crit_hyst(struct device *dev,
357 data->config = (data->config 355 data->config = (data->config
358 & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT)) 356 & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT))
359 | (hyst << JC42_CFG_HYST_SHIFT); 357 | (hyst << JC42_CFG_HYST_SHIFT);
360 err = jc42_write_value(client, JC42_REG_CONFIG, data->config); 358 err = i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
359 data->config);
361 if (err < 0) 360 if (err < 0)
362 ret = err; 361 ret = err;
363 mutex_unlock(&data->update_lock); 362 mutex_unlock(&data->update_lock);
@@ -452,10 +451,10 @@ static int jc42_detect(struct i2c_client *new_client,
452 I2C_FUNC_SMBUS_WORD_DATA)) 451 I2C_FUNC_SMBUS_WORD_DATA))
453 return -ENODEV; 452 return -ENODEV;
454 453
455 cap = jc42_read_value(new_client, JC42_REG_CAP); 454 cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP);
456 config = jc42_read_value(new_client, JC42_REG_CONFIG); 455 config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG);
457 manid = jc42_read_value(new_client, JC42_REG_MANID); 456 manid = i2c_smbus_read_word_swapped(new_client, JC42_REG_MANID);
458 devid = jc42_read_value(new_client, JC42_REG_DEVICEID); 457 devid = i2c_smbus_read_word_swapped(new_client, JC42_REG_DEVICEID);
459 458
460 if (cap < 0 || config < 0 || manid < 0 || devid < 0) 459 if (cap < 0 || config < 0 || manid < 0 || devid < 0)
461 return -ENODEV; 460 return -ENODEV;
@@ -489,14 +488,14 @@ static int jc42_probe(struct i2c_client *new_client,
489 i2c_set_clientdata(new_client, data); 488 i2c_set_clientdata(new_client, data);
490 mutex_init(&data->update_lock); 489 mutex_init(&data->update_lock);
491 490
492 cap = jc42_read_value(new_client, JC42_REG_CAP); 491 cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP);
493 if (cap < 0) { 492 if (cap < 0) {
494 err = -EINVAL; 493 err = -EINVAL;
495 goto exit_free; 494 goto exit_free;
496 } 495 }
497 data->extended = !!(cap & JC42_CAP_RANGE); 496 data->extended = !!(cap & JC42_CAP_RANGE);
498 497
499 config = jc42_read_value(new_client, JC42_REG_CONFIG); 498 config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG);
500 if (config < 0) { 499 if (config < 0) {
501 err = -EINVAL; 500 err = -EINVAL;
502 goto exit_free; 501 goto exit_free;
@@ -504,7 +503,8 @@ static int jc42_probe(struct i2c_client *new_client,
504 data->orig_config = config; 503 data->orig_config = config;
505 if (config & JC42_CFG_SHUTDOWN) { 504 if (config & JC42_CFG_SHUTDOWN) {
506 config &= ~JC42_CFG_SHUTDOWN; 505 config &= ~JC42_CFG_SHUTDOWN;
507 jc42_write_value(new_client, JC42_REG_CONFIG, config); 506 i2c_smbus_write_word_swapped(new_client, JC42_REG_CONFIG,
507 config);
508 } 508 }
509 data->config = config; 509 data->config = config;
510 510
@@ -535,25 +535,12 @@ static int jc42_remove(struct i2c_client *client)
535 hwmon_device_unregister(data->hwmon_dev); 535 hwmon_device_unregister(data->hwmon_dev);
536 sysfs_remove_group(&client->dev.kobj, &jc42_group); 536 sysfs_remove_group(&client->dev.kobj, &jc42_group);
537 if (data->config != data->orig_config) 537 if (data->config != data->orig_config)
538 jc42_write_value(client, JC42_REG_CONFIG, data->orig_config); 538 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
539 data->orig_config);
539 kfree(data); 540 kfree(data);
540 return 0; 541 return 0;
541} 542}
542 543
543/* All registers are word-sized. */
544static int jc42_read_value(struct i2c_client *client, u8 reg)
545{
546 int ret = i2c_smbus_read_word_data(client, reg);
547 if (ret < 0)
548 return ret;
549 return swab16(ret);
550}
551
552static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value)
553{
554 return i2c_smbus_write_word_data(client, reg, swab16(value));
555}
556
557static struct jc42_data *jc42_update_device(struct device *dev) 544static struct jc42_data *jc42_update_device(struct device *dev)
558{ 545{
559 struct i2c_client *client = to_i2c_client(dev); 546 struct i2c_client *client = to_i2c_client(dev);
@@ -564,28 +551,29 @@ static struct jc42_data *jc42_update_device(struct device *dev)
564 mutex_lock(&data->update_lock); 551 mutex_lock(&data->update_lock);
565 552
566 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 553 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
567 val = jc42_read_value(client, JC42_REG_TEMP); 554 val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP);
568 if (val < 0) { 555 if (val < 0) {
569 ret = ERR_PTR(val); 556 ret = ERR_PTR(val);
570 goto abort; 557 goto abort;
571 } 558 }
572 data->temp_input = val; 559 data->temp_input = val;
573 560
574 val = jc42_read_value(client, JC42_REG_TEMP_CRITICAL); 561 val = i2c_smbus_read_word_swapped(client,
562 JC42_REG_TEMP_CRITICAL);
575 if (val < 0) { 563 if (val < 0) {
576 ret = ERR_PTR(val); 564 ret = ERR_PTR(val);
577 goto abort; 565 goto abort;
578 } 566 }
579 data->temp_crit = val; 567 data->temp_crit = val;
580 568
581 val = jc42_read_value(client, JC42_REG_TEMP_LOWER); 569 val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_LOWER);
582 if (val < 0) { 570 if (val < 0) {
583 ret = ERR_PTR(val); 571 ret = ERR_PTR(val);
584 goto abort; 572 goto abort;
585 } 573 }
586 data->temp_min = val; 574 data->temp_min = val;
587 575
588 val = jc42_read_value(client, JC42_REG_TEMP_UPPER); 576 val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_UPPER);
589 if (val < 0) { 577 if (val < 0) {
590 ret = ERR_PTR(val); 578 ret = ERR_PTR(val);
591 goto abort; 579 goto abort;