aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/pmbus
diff options
context:
space:
mode:
authorGuenter Roeck <guenter.roeck@ericsson.com>2011-07-08 13:41:24 -0400
committerGuenter Roeck <guenter.roeck@ericsson.com>2011-07-28 19:55:13 -0400
commit46243f3ab44ad0d2e9ca62e6485ca433659f3881 (patch)
tree93b542f63ff4de15f1ddf25c842ff326287a15f7 /drivers/hwmon/pmbus
parent2bd05bf4d2a5807dcc1c52788b842827e5ef0ee9 (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')
-rw-r--r--drivers/hwmon/pmbus/pmbus.h4
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c52
2 files changed, 50 insertions, 6 deletions
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index cc5b6a23260..d631caeda10 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -286,6 +286,9 @@ struct pmbus_driver_info {
286 * necessary. 286 * necessary.
287 */ 287 */
288 int (*read_byte_data)(struct i2c_client *client, int page, int reg); 288 int (*read_byte_data)(struct i2c_client *client, int page, int reg);
289 int (*read_word_data)(struct i2c_client *client, int page, int reg);
290 int (*write_word_data)(struct i2c_client *client, int page, int reg,
291 u16 word);
289 /* 292 /*
290 * The identify function determines supported PMBus functionality. 293 * The identify function determines supported PMBus functionality.
291 * This function is only necessary if a chip driver supports multiple 294 * This function is only necessary if a chip driver supports multiple
@@ -299,6 +302,7 @@ struct pmbus_driver_info {
299 302
300int pmbus_set_page(struct i2c_client *client, u8 page); 303int pmbus_set_page(struct i2c_client *client, u8 page);
301int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg); 304int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
305int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
302int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg); 306int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg);
303void pmbus_clear_faults(struct i2c_client *client); 307void pmbus_clear_faults(struct i2c_client *client);
304bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); 308bool pmbus_check_byte_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 8ff7ebf5338..29143bf886b 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
178static int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, 178int 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}
188EXPORT_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 */
194static 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
190int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) 211int 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}
200EXPORT_SYMBOL_GPL(pmbus_read_word_data); 221EXPORT_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 */
227static 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
202int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg) 241int 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 */
280static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) 319static 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