aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ads7828.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/ads7828.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/ads7828.c')
-rw-r--r--drivers/hwmon/ads7828.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index c42c5a69a664..cfcc3b6fb6bf 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -74,13 +74,6 @@ static int ads7828_detect(struct i2c_client *client,
74static int ads7828_probe(struct i2c_client *client, 74static int ads7828_probe(struct i2c_client *client,
75 const struct i2c_device_id *id); 75 const struct i2c_device_id *id);
76 76
77/* The ADS7828 returns the 12-bit sample in two bytes,
78 these are read as a word then byte-swapped */
79static u16 ads7828_read_value(struct i2c_client *client, u8 reg)
80{
81 return swab16(i2c_smbus_read_word_data(client, reg));
82}
83
84static inline u8 channel_cmd_byte(int ch) 77static inline u8 channel_cmd_byte(int ch)
85{ 78{
86 /* cmd byte C2,C1,C0 - see datasheet */ 79 /* cmd byte C2,C1,C0 - see datasheet */
@@ -104,7 +97,8 @@ static struct ads7828_data *ads7828_update_device(struct device *dev)
104 97
105 for (ch = 0; ch < ADS7828_NCH; ch++) { 98 for (ch = 0; ch < ADS7828_NCH; ch++) {
106 u8 cmd = channel_cmd_byte(ch); 99 u8 cmd = channel_cmd_byte(ch);
107 data->adc_input[ch] = ads7828_read_value(client, cmd); 100 data->adc_input[ch] =
101 i2c_smbus_read_word_swapped(client, cmd);
108 } 102 }
109 data->last_updated = jiffies; 103 data->last_updated = jiffies;
110 data->valid = 1; 104 data->valid = 1;
@@ -203,7 +197,7 @@ static int ads7828_detect(struct i2c_client *client,
203 for (ch = 0; ch < ADS7828_NCH; ch++) { 197 for (ch = 0; ch < ADS7828_NCH; ch++) {
204 u16 in_data; 198 u16 in_data;
205 u8 cmd = channel_cmd_byte(ch); 199 u8 cmd = channel_cmd_byte(ch);
206 in_data = ads7828_read_value(client, cmd); 200 in_data = i2c_smbus_read_word_swapped(client, cmd);
207 if (in_data & 0xF000) { 201 if (in_data & 0xF000) {
208 pr_debug("%s : Doesn't look like an ads7828 device\n", 202 pr_debug("%s : Doesn't look like an ads7828 device\n",
209 __func__); 203 __func__);