aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ads1015.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/ads1015.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/ads1015.c')
-rw-r--r--drivers/hwmon/ads1015.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index e9beeda4cbe5..eedca3cf9968 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -59,19 +59,6 @@ struct ads1015_data {
59 struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 59 struct ads1015_channel_data channel_data[ADS1015_CHANNELS];
60}; 60};
61 61
62static s32 ads1015_read_reg(struct i2c_client *client, unsigned int reg)
63{
64 s32 data = i2c_smbus_read_word_data(client, reg);
65
66 return (data < 0) ? data : swab16(data);
67}
68
69static s32 ads1015_write_reg(struct i2c_client *client, unsigned int reg,
70 u16 val)
71{
72 return i2c_smbus_write_word_data(client, reg, swab16(val));
73}
74
75static int ads1015_read_value(struct i2c_client *client, unsigned int channel, 62static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
76 int *value) 63 int *value)
77{ 64{
@@ -87,7 +74,7 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
87 mutex_lock(&data->update_lock); 74 mutex_lock(&data->update_lock);
88 75
89 /* get channel parameters */ 76 /* get channel parameters */
90 res = ads1015_read_reg(client, ADS1015_CONFIG); 77 res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG);
91 if (res < 0) 78 if (res < 0)
92 goto err_unlock; 79 goto err_unlock;
93 config = res; 80 config = res;
@@ -101,13 +88,13 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
101 config |= (pga & 0x0007) << 9; 88 config |= (pga & 0x0007) << 9;
102 config |= (data_rate & 0x0007) << 5; 89 config |= (data_rate & 0x0007) << 5;
103 90
104 res = ads1015_write_reg(client, ADS1015_CONFIG, config); 91 res = i2c_smbus_write_word_swapped(client, ADS1015_CONFIG, config);
105 if (res < 0) 92 if (res < 0)
106 goto err_unlock; 93 goto err_unlock;
107 94
108 /* wait until conversion finished */ 95 /* wait until conversion finished */
109 msleep(conversion_time_ms); 96 msleep(conversion_time_ms);
110 res = ads1015_read_reg(client, ADS1015_CONFIG); 97 res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG);
111 if (res < 0) 98 if (res < 0)
112 goto err_unlock; 99 goto err_unlock;
113 config = res; 100 config = res;
@@ -117,7 +104,7 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
117 goto err_unlock; 104 goto err_unlock;
118 } 105 }
119 106
120 res = ads1015_read_reg(client, ADS1015_CONVERSION); 107 res = i2c_smbus_read_word_swapped(client, ADS1015_CONVERSION);
121 if (res < 0) 108 if (res < 0)
122 goto err_unlock; 109 goto err_unlock;
123 conversion = res; 110 conversion = res;