aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/smm665.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/smm665.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/smm665.c')
-rw-r--r--drivers/hwmon/smm665.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c
index 425df5bccd4..411638181fd 100644
--- a/drivers/hwmon/smm665.c
+++ b/drivers/hwmon/smm665.c
@@ -214,33 +214,26 @@ static int smm665_read_adc(struct smm665_data *data, int adc)
214 * 214 *
215 * Neither i2c_smbus_read_byte() nor 215 * Neither i2c_smbus_read_byte() nor
216 * i2c_smbus_read_block_data() worked here, 216 * i2c_smbus_read_block_data() worked here,
217 * so use i2c_smbus_read_word_data() instead. 217 * so use i2c_smbus_read_word_swapped() instead.
218 * We could also try to use i2c_master_recv(), 218 * We could also try to use i2c_master_recv(),
219 * but that is not always supported. 219 * but that is not always supported.
220 */ 220 */
221 rv = i2c_smbus_read_word_data(client, 0); 221 rv = i2c_smbus_read_word_swapped(client, 0);
222 if (rv < 0) { 222 if (rv < 0) {
223 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); 223 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv);
224 return -1; 224 return -1;
225 } 225 }
226 /* 226 /*
227 * Validate/verify readback adc channel (in bit 11..14). 227 * Validate/verify readback adc channel (in bit 11..14).
228 * High byte is in lower 8 bit of rv, so only shift by 3.
229 */ 228 */
230 radc = (rv >> 3) & 0x0f; 229 radc = (rv >> 11) & 0x0f;
231 if (radc != adc) { 230 if (radc != adc) {
232 dev_dbg(&client->dev, "Unexpected RADC: Expected %d got %d", 231 dev_dbg(&client->dev, "Unexpected RADC: Expected %d got %d",
233 adc, radc); 232 adc, radc);
234 return -EIO; 233 return -EIO;
235 } 234 }
236 /*
237 * Chip replies with H/L, while SMBus expects L/H.
238 * Thus, byte order is reversed, and we have to swap
239 * the result.
240 */
241 rv = swab16(rv) & SMM665_ADC_MASK;
242 235
243 return rv; 236 return rv & SMM665_ADC_MASK;
244} 237}
245 238
246static struct smm665_data *smm665_update_device(struct device *dev) 239static struct smm665_data *smm665_update_device(struct device *dev)