Commit f0a5c839 authored by Mårten Lindahl's avatar Mårten Lindahl Committed by Guenter Roeck

hwmon: (pmbus) Use _pmbus_read_byte_data with callback

Some of the pmbus core functions uses pmbus_read_byte_data, which does
not support driver callbacks for chip specific write operations. This
could potentially influence some specific regulator chips that for
example need a time delay before each data access.

Lets use _pmbus_read_byte_data with callback check.
Signed-off-by: default avatarMårten Lindahl <marten.lindahl@axis.com>
Link: https://lore.kernel.org/r/20220428144039.2464667-3-marten.lindahl@axis.comSigned-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 5de3e13f
...@@ -294,6 +294,24 @@ static int _pmbus_write_byte_data(struct i2c_client *client, int page, int reg, ...@@ -294,6 +294,24 @@ static int _pmbus_write_byte_data(struct i2c_client *client, int page, int reg,
return pmbus_write_byte_data(client, page, reg, value); return pmbus_write_byte_data(client, page, reg, value);
} }
/*
* _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
* 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)
{
struct pmbus_data *data = i2c_get_clientdata(client);
const struct pmbus_driver_info *info = data->info;
int status;
if (info->read_byte_data) {
status = info->read_byte_data(client, page, reg);
if (status != -ENODATA)
return status;
}
return pmbus_read_byte_data(client, page, reg);
}
int pmbus_update_fan(struct i2c_client *client, int page, int id, int pmbus_update_fan(struct i2c_client *client, int page, int id,
u8 config, u8 mask, u16 command) u8 config, u8 mask, u16 command)
{ {
...@@ -301,7 +319,7 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id, ...@@ -301,7 +319,7 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,
int rv; int rv;
u8 to; u8 to;
from = pmbus_read_byte_data(client, page, from = _pmbus_read_byte_data(client, page,
pmbus_fan_config_registers[id]); pmbus_fan_config_registers[id]);
if (from < 0) if (from < 0)
return from; return from;
...@@ -408,7 +426,7 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg, ...@@ -408,7 +426,7 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
unsigned int tmp; unsigned int tmp;
int rv; int rv;
rv = pmbus_read_byte_data(client, page, reg); rv = _pmbus_read_byte_data(client, page, reg);
if (rv < 0) if (rv < 0)
return rv; return rv;
...@@ -421,24 +439,6 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg, ...@@ -421,24 +439,6 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
} }
EXPORT_SYMBOL_NS_GPL(pmbus_update_byte_data, PMBUS); EXPORT_SYMBOL_NS_GPL(pmbus_update_byte_data, PMBUS);
/*
* _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
* 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)
{
struct pmbus_data *data = i2c_get_clientdata(client);
const struct pmbus_driver_info *info = data->info;
int status;
if (info->read_byte_data) {
status = info->read_byte_data(client, page, reg);
if (status != -ENODATA)
return status;
}
return pmbus_read_byte_data(client, page, reg);
}
static struct pmbus_sensor *pmbus_find_sensor(struct pmbus_data *data, int page, static struct pmbus_sensor *pmbus_find_sensor(struct pmbus_data *data, int page,
int reg) int reg)
{ {
...@@ -473,7 +473,7 @@ static int pmbus_get_fan_rate(struct i2c_client *client, int page, int id, ...@@ -473,7 +473,7 @@ static int pmbus_get_fan_rate(struct i2c_client *client, int page, int id,
return s->data; return s->data;
} }
config = pmbus_read_byte_data(client, page, config = _pmbus_read_byte_data(client, page,
pmbus_fan_config_registers[id]); pmbus_fan_config_registers[id]);
if (config < 0) if (config < 0)
return config; return config;
...@@ -2417,7 +2417,7 @@ static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) ...@@ -2417,7 +2417,7 @@ static int pmbus_regulator_is_enabled(struct regulator_dev *rdev)
int ret; int ret;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
ret = pmbus_read_byte_data(client, page, PMBUS_OPERATION); ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
if (ret < 0) if (ret < 0)
...@@ -2516,7 +2516,7 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned ...@@ -2516,7 +2516,7 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
if (!(func & cat->func)) if (!(func & cat->func))
continue; continue;
status = pmbus_read_byte_data(client, page, cat->reg); status = _pmbus_read_byte_data(client, page, cat->reg);
if (status < 0) { if (status < 0) {
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return status; return status;
......
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