diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-11-04 07:00:47 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-11-04 07:00:47 -0400 |
commit | 90f4102ce59226954edbe960b2434d8b3da5f086 (patch) | |
tree | 93fd275039932253b16ea125c1ba5eea2995b719 /drivers/hwmon/ds1621.c | |
parent | 371f2e083b9b081adf68d04fba4978a27dc4e618 (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/ds1621.c')
-rw-r--r-- | drivers/hwmon/ds1621.c | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index e11363467a8d..ef1ac996752e 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -80,24 +80,6 @@ struct ds1621_data { | |||
80 | u8 conf; /* Register encoding, combined */ | 80 | u8 conf; /* Register encoding, combined */ |
81 | }; | 81 | }; |
82 | 82 | ||
83 | /* Temperature registers are word-sized. | ||
84 | DS1621 uses a high-byte first convention, which is exactly opposite to | ||
85 | the SMBus standard. */ | ||
86 | static int ds1621_read_temp(struct i2c_client *client, u8 reg) | ||
87 | { | ||
88 | int ret; | ||
89 | |||
90 | ret = i2c_smbus_read_word_data(client, reg); | ||
91 | if (ret < 0) | ||
92 | return ret; | ||
93 | return swab16(ret); | ||
94 | } | ||
95 | |||
96 | static int ds1621_write_temp(struct i2c_client *client, u8 reg, u16 value) | ||
97 | { | ||
98 | return i2c_smbus_write_word_data(client, reg, swab16(value)); | ||
99 | } | ||
100 | |||
101 | static void ds1621_init_client(struct i2c_client *client) | 83 | static void ds1621_init_client(struct i2c_client *client) |
102 | { | 84 | { |
103 | u8 conf, new_conf; | 85 | u8 conf, new_conf; |
@@ -136,7 +118,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev) | |||
136 | data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); | 118 | data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); |
137 | 119 | ||
138 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) | 120 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) |
139 | data->temp[i] = ds1621_read_temp(client, | 121 | data->temp[i] = i2c_smbus_read_word_swapped(client, |
140 | DS1621_REG_TEMP[i]); | 122 | DS1621_REG_TEMP[i]); |
141 | 123 | ||
142 | /* reset alarms if necessary */ | 124 | /* reset alarms if necessary */ |
@@ -177,8 +159,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
177 | 159 | ||
178 | mutex_lock(&data->update_lock); | 160 | mutex_lock(&data->update_lock); |
179 | data->temp[attr->index] = val; | 161 | data->temp[attr->index] = val; |
180 | ds1621_write_temp(client, DS1621_REG_TEMP[attr->index], | 162 | i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index], |
181 | data->temp[attr->index]); | 163 | data->temp[attr->index]); |
182 | mutex_unlock(&data->update_lock); | 164 | mutex_unlock(&data->update_lock); |
183 | return count; | 165 | return count; |
184 | } | 166 | } |