aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/pmbus
diff options
context:
space:
mode:
authorAlan Tull <atull@opensource.altera.com>2014-10-15 14:55:08 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-11-30 23:13:13 -0500
commit11c119986f2700e9daca0d795fbe84a988939655 (patch)
tree42749a9012146e67645a597cbff2c2d6503e53a7 /drivers/hwmon/pmbus
parent7e9d62d3878654f485bde016f54d1b9d2c84cf6b (diff)
hwmon: (pmbus) add helpers for byte write and read modify write
Add two helper functions: * pmbus_write_byte_data = paged byte write * pmbus_update_byte_data = paged byte read/modify/write Signed-off-by: Alan Tull <atull@opensource.altera.com> Cc: Mark Brown <broonie@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/pmbus')
-rw-r--r--drivers/hwmon/pmbus/pmbus.h4
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c31
2 files changed, 35 insertions, 0 deletions
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index fa9beb3eb60c..3ae79a7d1b00 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -375,6 +375,10 @@ int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
375int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word); 375int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
376int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg); 376int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
377int pmbus_write_byte(struct i2c_client *client, int page, u8 value); 377int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
378int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
379 u8 value);
380int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
381 u8 mask, u8 value);
378void pmbus_clear_faults(struct i2c_client *client); 382void pmbus_clear_faults(struct i2c_client *client);
379bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); 383bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
380bool pmbus_check_word_register(struct i2c_client *client, int page, int reg); 384bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 291d11fe93e7..d6c3701eb7f9 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -253,6 +253,37 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)
253} 253}
254EXPORT_SYMBOL_GPL(pmbus_read_byte_data); 254EXPORT_SYMBOL_GPL(pmbus_read_byte_data);
255 255
256int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value)
257{
258 int rv;
259
260 rv = pmbus_set_page(client, page);
261 if (rv < 0)
262 return rv;
263
264 return i2c_smbus_write_byte_data(client, reg, value);
265}
266EXPORT_SYMBOL_GPL(pmbus_write_byte_data);
267
268int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
269 u8 mask, u8 value)
270{
271 unsigned int tmp;
272 int rv;
273
274 rv = pmbus_read_byte_data(client, page, reg);
275 if (rv < 0)
276 return rv;
277
278 tmp = (rv & ~mask) | (value & mask);
279
280 if (tmp != rv)
281 rv = pmbus_write_byte_data(client, page, reg, tmp);
282
283 return rv;
284}
285EXPORT_SYMBOL_GPL(pmbus_update_byte_data);
286
256/* 287/*
257 * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if 288 * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
258 * a device specific mapping function exists and calls it if necessary. 289 * a device specific mapping function exists and calls it if necessary.