aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ad7418.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/ad7418.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/ad7418.c')
-rw-r--r--drivers/hwmon/ad7418.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c
index ffc781fec185..8cb718ce8237 100644
--- a/drivers/hwmon/ad7418.c
+++ b/drivers/hwmon/ad7418.c
@@ -76,20 +76,6 @@ static struct i2c_driver ad7418_driver = {
76 .id_table = ad7418_id, 76 .id_table = ad7418_id,
77}; 77};
78 78
79/* All registers are word-sized, except for the configuration registers.
80 * AD7418 uses a high-byte first convention. Do NOT use those functions to
81 * access the configuration registers CONF and CONF2, as they are byte-sized.
82 */
83static inline int ad7418_read(struct i2c_client *client, u8 reg)
84{
85 return swab16(i2c_smbus_read_word_data(client, reg));
86}
87
88static inline int ad7418_write(struct i2c_client *client, u8 reg, u16 value)
89{
90 return i2c_smbus_write_word_data(client, reg, swab16(value));
91}
92
93static void ad7418_init_client(struct i2c_client *client) 79static void ad7418_init_client(struct i2c_client *client)
94{ 80{
95 struct ad7418_data *data = i2c_get_clientdata(client); 81 struct ad7418_data *data = i2c_get_clientdata(client);
@@ -128,7 +114,9 @@ static struct ad7418_data *ad7418_update_device(struct device *dev)
128 udelay(30); 114 udelay(30);
129 115
130 for (i = 0; i < 3; i++) { 116 for (i = 0; i < 3; i++) {
131 data->temp[i] = ad7418_read(client, AD7418_REG_TEMP[i]); 117 data->temp[i] =
118 i2c_smbus_read_word_swapped(client,
119 AD7418_REG_TEMP[i]);
132 } 120 }
133 121
134 for (i = 0, ch = 4; i < data->adc_max; i++, ch--) { 122 for (i = 0, ch = 4; i < data->adc_max; i++, ch--) {
@@ -138,11 +126,12 @@ static struct ad7418_data *ad7418_update_device(struct device *dev)
138 126
139 udelay(15); 127 udelay(15);
140 data->in[data->adc_max - 1 - i] = 128 data->in[data->adc_max - 1 - i] =
141 ad7418_read(client, AD7418_REG_ADC); 129 i2c_smbus_read_word_swapped(client,
130 AD7418_REG_ADC);
142 } 131 }
143 132
144 /* restore old configuration value */ 133 /* restore old configuration value */
145 ad7418_write(client, AD7418_REG_CONF, cfg); 134 i2c_smbus_write_word_swapped(client, AD7418_REG_CONF, cfg);
146 135
147 data->last_updated = jiffies; 136 data->last_updated = jiffies;
148 data->valid = 1; 137 data->valid = 1;
@@ -182,7 +171,9 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
182 171
183 mutex_lock(&data->lock); 172 mutex_lock(&data->lock);
184 data->temp[attr->index] = LM75_TEMP_TO_REG(temp); 173 data->temp[attr->index] = LM75_TEMP_TO_REG(temp);
185 ad7418_write(client, AD7418_REG_TEMP[attr->index], data->temp[attr->index]); 174 i2c_smbus_write_word_swapped(client,
175 AD7418_REG_TEMP[attr->index],
176 data->temp[attr->index]);
186 mutex_unlock(&data->lock); 177 mutex_unlock(&data->lock);
187 return count; 178 return count;
188} 179}