diff options
author | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-07-08 13:41:24 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-07-28 19:55:13 -0400 |
commit | 46243f3ab44ad0d2e9ca62e6485ca433659f3881 (patch) | |
tree | 93b542f63ff4de15f1ddf25c842ff326287a15f7 /drivers/hwmon/pmbus/pmbus_core.c | |
parent | 2bd05bf4d2a5807dcc1c52788b842827e5ef0ee9 (diff) |
hwmon: (pmbus) Support reading and writing of word registers in device specific code
Some PMBus devices use non-standard registers for some of the sensors and/or
limits. To support such devices, add code to support reading and writing of word
size registers in device specific code.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
Diffstat (limited to 'drivers/hwmon/pmbus/pmbus_core.c')
-rw-r--r-- | drivers/hwmon/pmbus/pmbus_core.c | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 8ff7ebf53380..29143bf886b6 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -175,8 +175,7 @@ static int pmbus_write_byte(struct i2c_client *client, u8 page, u8 value) | |||
175 | return i2c_smbus_write_byte(client, value); | 175 | return i2c_smbus_write_byte(client, value); |
176 | } | 176 | } |
177 | 177 | ||
178 | static int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, | 178 | int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word) |
179 | u16 word) | ||
180 | { | 179 | { |
181 | int rv; | 180 | int rv; |
182 | 181 | ||
@@ -186,6 +185,28 @@ static int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, | |||
186 | 185 | ||
187 | return i2c_smbus_write_word_data(client, reg, word); | 186 | return i2c_smbus_write_word_data(client, reg, word); |
188 | } | 187 | } |
188 | EXPORT_SYMBOL_GPL(pmbus_write_word_data); | ||
189 | |||
190 | /* | ||
191 | * _pmbus_write_word_data() is similar to pmbus_write_word_data(), but checks if | ||
192 | * a device specific mapping function exists and calls it if necessary. | ||
193 | */ | ||
194 | static int _pmbus_write_word_data(struct i2c_client *client, int page, int reg, | ||
195 | u16 word) | ||
196 | { | ||
197 | struct pmbus_data *data = i2c_get_clientdata(client); | ||
198 | const struct pmbus_driver_info *info = data->info; | ||
199 | int status; | ||
200 | |||
201 | if (info->write_word_data) { | ||
202 | status = info->write_word_data(client, page, reg, word); | ||
203 | if (status != -ENODATA) | ||
204 | return status; | ||
205 | } | ||
206 | if (reg >= PMBUS_VIRT_BASE) | ||
207 | return -EINVAL; | ||
208 | return pmbus_write_word_data(client, page, reg, word); | ||
209 | } | ||
189 | 210 | ||
190 | int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) | 211 | int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) |
191 | { | 212 | { |
@@ -199,6 +220,24 @@ int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) | |||
199 | } | 220 | } |
200 | EXPORT_SYMBOL_GPL(pmbus_read_word_data); | 221 | EXPORT_SYMBOL_GPL(pmbus_read_word_data); |
201 | 222 | ||
223 | /* | ||
224 | * _pmbus_read_word_data() is similar to pmbus_read_word_data(), but checks if | ||
225 | * a device specific mapping function exists and calls it if necessary. | ||
226 | */ | ||
227 | static int _pmbus_read_word_data(struct i2c_client *client, int page, int reg) | ||
228 | { | ||
229 | struct pmbus_data *data = i2c_get_clientdata(client); | ||
230 | const struct pmbus_driver_info *info = data->info; | ||
231 | int status; | ||
232 | |||
233 | if (info->read_word_data) { | ||
234 | status = info->read_word_data(client, page, reg); | ||
235 | if (status != -ENODATA) | ||
236 | return status; | ||
237 | } | ||
238 | return pmbus_read_word_data(client, page, reg); | ||
239 | } | ||
240 | |||
202 | int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg) | 241 | int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg) |
203 | { | 242 | { |
204 | int rv; | 243 | int rv; |
@@ -275,7 +314,7 @@ EXPORT_SYMBOL_GPL(pmbus_get_driver_info); | |||
275 | 314 | ||
276 | /* | 315 | /* |
277 | * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if | 316 | * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if |
278 | * a device specific mapping funcion exists and calls it if necessary. | 317 | * a device specific mapping function exists and calls it if necessary. |
279 | */ | 318 | */ |
280 | static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) | 319 | static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) |
281 | { | 320 | { |
@@ -350,8 +389,9 @@ static struct pmbus_data *pmbus_update_device(struct device *dev) | |||
350 | 389 | ||
351 | if (!data->valid || sensor->update) | 390 | if (!data->valid || sensor->update) |
352 | sensor->data | 391 | sensor->data |
353 | = pmbus_read_word_data(client, sensor->page, | 392 | = _pmbus_read_word_data(client, |
354 | sensor->reg); | 393 | sensor->page, |
394 | sensor->reg); | ||
355 | } | 395 | } |
356 | pmbus_clear_faults(client); | 396 | pmbus_clear_faults(client); |
357 | data->last_updated = jiffies; | 397 | data->last_updated = jiffies; |
@@ -722,7 +762,7 @@ static ssize_t pmbus_set_sensor(struct device *dev, | |||
722 | 762 | ||
723 | mutex_lock(&data->update_lock); | 763 | mutex_lock(&data->update_lock); |
724 | regval = pmbus_data2reg(data, sensor->class, val); | 764 | regval = pmbus_data2reg(data, sensor->class, val); |
725 | ret = pmbus_write_word_data(client, sensor->page, sensor->reg, regval); | 765 | ret = _pmbus_write_word_data(client, sensor->page, sensor->reg, regval); |
726 | if (ret < 0) | 766 | if (ret < 0) |
727 | rv = ret; | 767 | rv = ret; |
728 | else | 768 | else |