This driver does not have regulator specific operations for getting or setting voltage. Add functions get/set voltage for the dynamic regulator framework. Signed-off-by: Mårten Lindahl <marten.lindahl@xxxxxxxx> --- drivers/hwmon/pmbus/ltc2978.c | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c index 822edec33ba7..fce08c33e66a 100644 --- a/drivers/hwmon/pmbus/ltc2978.c +++ b/drivers/hwmon/pmbus/ltc2978.c @@ -596,10 +596,65 @@ static int ltc2978_regulator_disable(struct regulator_dev *rdev) return ltc2978_regulator_on_off(rdev, 0); } +static int ltc2978_regulator_get_voltage(struct regulator_dev *rdev) +{ + struct device *dev = rdev_get_dev(rdev); + struct i2c_client *client = to_i2c_client(dev->parent); + u8 page = rdev_get_id(rdev); + int ret; + + ret = ltc_wait_ready(client); + if (ret < 0) + return ret; + + ret = pmbus_read_word_data(client, page, 0xff, PMBUS_READ_VOUT); + if (ret < 0) + return ret; + + ret *= 1000; + + return ((ret >> 13) * 1000); +} + +static int ltc2978_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, + int max_uV, unsigned int *selector) +{ + struct device *dev = rdev_get_dev(rdev); + struct i2c_client *client = to_i2c_client(dev->parent); + u8 page = rdev_get_id(rdev); + long tmp = DIV_ROUND_CLOSEST(min_uV, 1000); + u32 val = DIV_ROUND_CLOSEST(tmp << 13, 1000); + int ret; + *selector = 0; + + ret = ltc_wait_ready(client); + if (ret < 0) + return ret; + + ret = pmbus_read_word_data(client, page, 0xff, PMBUS_VOUT_MARGIN_LOW); + if (ret < 0) + return ret; + + /* Select the voltage closest to min_uV */ + if (ret > val) + val = ret; + + ret = ltc_wait_ready(client); + if (ret < 0) + return ret; + + ret = pmbus_write_word_data(client, page, PMBUS_VOUT_COMMAND, + (u16)val); + + return ret; +} + static const struct regulator_ops ltc2978_regulator_ops = { .enable = ltc2978_regulator_enable, .disable = ltc2978_regulator_disable, .is_enabled = ltc2978_regulator_is_enabled, + .get_voltage = ltc2978_regulator_get_voltage, + .set_voltage = ltc2978_regulator_set_voltage, }; /* Macro for filling in array of struct regulator_desc */ -- 2.30.2