Commit 46243f3a authored by Guenter Roeck's avatar Guenter Roeck

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: default avatarGuenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: default avatarRobert Coulson <robert.coulson@ericsson.com>
parent 2bd05bf4
...@@ -286,6 +286,9 @@ struct pmbus_driver_info { ...@@ -286,6 +286,9 @@ struct pmbus_driver_info {
* necessary. * necessary.
*/ */
int (*read_byte_data)(struct i2c_client *client, int page, int reg); int (*read_byte_data)(struct i2c_client *client, int page, int reg);
int (*read_word_data)(struct i2c_client *client, int page, int reg);
int (*write_word_data)(struct i2c_client *client, int page, int reg,
u16 word);
/* /*
* The identify function determines supported PMBus functionality. * The identify function determines supported PMBus functionality.
* This function is only necessary if a chip driver supports multiple * This function is only necessary if a chip driver supports multiple
...@@ -299,6 +302,7 @@ struct pmbus_driver_info { ...@@ -299,6 +302,7 @@ struct pmbus_driver_info {
int pmbus_set_page(struct i2c_client *client, u8 page); int pmbus_set_page(struct i2c_client *client, u8 page);
int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg); int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg); int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg);
void pmbus_clear_faults(struct i2c_client *client); void pmbus_clear_faults(struct i2c_client *client);
bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
......
...@@ -175,8 +175,7 @@ static int pmbus_write_byte(struct i2c_client *client, u8 page, u8 value) ...@@ -175,8 +175,7 @@ static int pmbus_write_byte(struct i2c_client *client, u8 page, u8 value)
return i2c_smbus_write_byte(client, value); return i2c_smbus_write_byte(client, value);
} }
static int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word)
u16 word)
{ {
int rv; int rv;
...@@ -186,6 +185,28 @@ static int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, ...@@ -186,6 +185,28 @@ static int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg,
return i2c_smbus_write_word_data(client, reg, word); return i2c_smbus_write_word_data(client, reg, word);
} }
EXPORT_SYMBOL_GPL(pmbus_write_word_data);
/*
* _pmbus_write_word_data() is similar to pmbus_write_word_data(), but checks if
* a device specific mapping function exists and calls it if necessary.
*/
static int _pmbus_write_word_data(struct i2c_client *client, int page, int reg,
u16 word)
{
struct pmbus_data *data = i2c_get_clientdata(client);
const struct pmbus_driver_info *info = data->info;
int status;
if (info->write_word_data) {
status = info->write_word_data(client, page, reg, word);
if (status != -ENODATA)
return status;
}
if (reg >= PMBUS_VIRT_BASE)
return -EINVAL;
return pmbus_write_word_data(client, page, reg, word);
}
int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg)
{ {
...@@ -199,6 +220,24 @@ int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg) ...@@ -199,6 +220,24 @@ int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg)
} }
EXPORT_SYMBOL_GPL(pmbus_read_word_data); EXPORT_SYMBOL_GPL(pmbus_read_word_data);
/*
* _pmbus_read_word_data() is similar to pmbus_read_word_data(), but checks if
* a device specific mapping function exists and calls it if necessary.
*/
static int _pmbus_read_word_data(struct i2c_client *client, int page, int reg)
{
struct pmbus_data *data = i2c_get_clientdata(client);
const struct pmbus_driver_info *info = data->info;
int status;
if (info->read_word_data) {
status = info->read_word_data(client, page, reg);
if (status != -ENODATA)
return status;
}
return pmbus_read_word_data(client, page, reg);
}
int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg) int pmbus_read_byte_data(struct i2c_client *client, u8 page, u8 reg)
{ {
int rv; int rv;
...@@ -275,7 +314,7 @@ EXPORT_SYMBOL_GPL(pmbus_get_driver_info); ...@@ -275,7 +314,7 @@ EXPORT_SYMBOL_GPL(pmbus_get_driver_info);
/* /*
* _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
* a device specific mapping funcion exists and calls it if necessary. * a device specific mapping function exists and calls it if necessary.
*/ */
static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg)
{ {
...@@ -350,8 +389,9 @@ static struct pmbus_data *pmbus_update_device(struct device *dev) ...@@ -350,8 +389,9 @@ static struct pmbus_data *pmbus_update_device(struct device *dev)
if (!data->valid || sensor->update) if (!data->valid || sensor->update)
sensor->data sensor->data
= pmbus_read_word_data(client, sensor->page, = _pmbus_read_word_data(client,
sensor->reg); sensor->page,
sensor->reg);
} }
pmbus_clear_faults(client); pmbus_clear_faults(client);
data->last_updated = jiffies; data->last_updated = jiffies;
...@@ -722,7 +762,7 @@ static ssize_t pmbus_set_sensor(struct device *dev, ...@@ -722,7 +762,7 @@ static ssize_t pmbus_set_sensor(struct device *dev,
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
regval = pmbus_data2reg(data, sensor->class, val); regval = pmbus_data2reg(data, sensor->class, val);
ret = pmbus_write_word_data(client, sensor->page, sensor->reg, regval); ret = _pmbus_write_word_data(client, sensor->page, sensor->reg, regval);
if (ret < 0) if (ret < 0)
rv = ret; rv = ret;
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment