aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/sht21.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-11-04 07:00:47 -0400
committerJean Delvare <khali@endymion.delvare>2011-11-04 07:00:47 -0400
commit90f4102ce59226954edbe960b2434d8b3da5f086 (patch)
tree93fd275039932253b16ea125c1ba5eea2995b719 /drivers/hwmon/sht21.c
parent371f2e083b9b081adf68d04fba4978a27dc4e618 (diff)
hwmon: Use i2c_smbus_{read,write}_word_swapped
Make use of the new i2c_smbus_{read,write}_word_swapped functions. This makes the driver code more compact and readable. It also ensures proper error handling. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Jonathan Cameron <jic23@cam.ac.uk> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com> Cc: Dirk Eibach <eibach@gdsys.de> Cc: "Mark M. Hoffman" <mhoffman@lightlink.com> Cc: Guillaume Ligneul <guillaume.ligneul@gmail.com>
Diffstat (limited to 'drivers/hwmon/sht21.c')
-rw-r--r--drivers/hwmon/sht21.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 1c8c9812f244..15398780cc00 100644
--- a/drivers/hwmon/sht21.c
+++ b/drivers/hwmon/sht21.c
@@ -83,25 +83,6 @@ static inline int sht21_rh_ticks_to_per_cent_mille(int ticks)
83} 83}
84 84
85/** 85/**
86 * sht21_read_word_data() - read word from register
87 * @client: I2C client device
88 * @reg: I2C command byte
89 *
90 * Returns value, negative errno on error.
91 */
92static inline int sht21_read_word_data(struct i2c_client *client, u8 reg)
93{
94 int ret = i2c_smbus_read_word_data(client, reg);
95 if (ret < 0)
96 return ret;
97 /*
98 * SMBus specifies low byte first, but the SHT21 returns MSB
99 * first, so we have to swab16 the values
100 */
101 return swab16(ret);
102}
103
104/**
105 * sht21_update_measurements() - get updated measurements from device 86 * sht21_update_measurements() - get updated measurements from device
106 * @client: I2C client device 87 * @client: I2C client device
107 * 88 *
@@ -119,12 +100,13 @@ static int sht21_update_measurements(struct i2c_client *client)
119 * maximum two measurements per second at 12bit accuracy shall be made. 100 * maximum two measurements per second at 12bit accuracy shall be made.
120 */ 101 */
121 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) { 102 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) {
122 ret = sht21_read_word_data(client, SHT21_TRIG_T_MEASUREMENT_HM); 103 ret = i2c_smbus_read_word_swapped(client,
104 SHT21_TRIG_T_MEASUREMENT_HM);
123 if (ret < 0) 105 if (ret < 0)
124 goto out; 106 goto out;
125 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret); 107 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret);
126 ret = sht21_read_word_data(client, 108 ret = i2c_smbus_read_word_swapped(client,
127 SHT21_TRIG_RH_MEASUREMENT_HM); 109 SHT21_TRIG_RH_MEASUREMENT_HM);
128 if (ret < 0) 110 if (ret < 0)
129 goto out; 111 goto out;
130 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret); 112 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret);