From: Marten Lindahl <martenli@axis.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: "Mårten Lindahl" <Marten.Lindahl@axis.com>,
"Jean Delvare" <jdelvare@suse.com>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
kernel <kernel@axis.com>
Subject: Re: [PATCH v3 3/3] hwmon: (pmbus) Add get_voltage/set_voltage ops
Date: Thu, 28 Apr 2022 15:04:14 +0200 [thread overview]
Message-ID: <YmqQzoOt7fBzwMoY@axis.com> (raw)
In-Reply-To: <489c0db5-8d90-dfde-0859-2306c808817a@roeck-us.net>
On Wed, Apr 27, 2022 at 03:10:30PM +0200, Guenter Roeck wrote:
> On 4/27/22 06:02, Mårten Lindahl wrote:
> > The pmbus core does not have operations for getting or setting voltage.
> > Add functions get/set voltage for the dynamic regulator framework.
> >
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> > ---
> > drivers/hwmon/pmbus/pmbus_core.c | 43 ++++++++++++++++++++++++++++++++
> > 1 file changed, 43 insertions(+)
> >
> > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > index 1b0728c3c7d8..afc238faa8ce 100644
> > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > @@ -2563,11 +2563,54 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
> > return 0;
> > }
> >
> > +static int pmbus_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 = _pmbus_read_word_data(client, page, 0xff, PMBUS_READ_VOUT);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret *= 1000;
> > +
> > + return ((ret >> 13) * 1000);
>
> That will need to use voltage conversion functions. VOUT isn't the same
> for all chips.
>
Ok, I will fix that. Will change it to use pmbus_reg2data()
> > +}
> > +
> > +static int pmbus_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);
>
> Same as above.
I will make it use pmbus_data2reg() for conversion.
Kind regards
Mårten
>
> > + int ret;
> > + *selector = 0;
> > +
> > + 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 = _pmbus_write_word_data(client, page, PMBUS_VOUT_COMMAND,
> > + (u16)val);
> > +
> > + return ret;
> > +}
> > +
> > const struct regulator_ops pmbus_regulator_ops = {
> > .enable = pmbus_regulator_enable,
> > .disable = pmbus_regulator_disable,
> > .is_enabled = pmbus_regulator_is_enabled,
> > .get_error_flags = pmbus_regulator_get_error_flags,
> > + .get_voltage = pmbus_regulator_get_voltage,
> > + .set_voltage = pmbus_regulator_set_voltage,
> > };
> > EXPORT_SYMBOL_NS_GPL(pmbus_regulator_ops, PMBUS);
> >
>
prev parent reply other threads:[~2022-04-28 13:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 13:02 [PATCH v3 0/3] hwmon: (pmbus/ltc2978) Add regulator ops Mårten Lindahl
2022-04-27 13:02 ` [PATCH v3 1/3] hwmon: (pmbus) Use driver specific ops if they exist Mårten Lindahl
2022-04-27 13:26 ` Guenter Roeck
2022-04-28 13:00 ` Marten Lindahl
2022-04-27 13:02 ` [PATCH v3 2/3] hwmon: (pmbus/ltc2978) Add chip specific write_byte_data Mårten Lindahl
2022-04-27 13:02 ` [PATCH v3 3/3] hwmon: (pmbus) Add get_voltage/set_voltage ops Mårten Lindahl
2022-04-27 13:10 ` Guenter Roeck
2022-04-28 13:04 ` Marten Lindahl [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YmqQzoOt7fBzwMoY@axis.com \
--to=martenli@axis.com \
--cc=Marten.Lindahl@axis.com \
--cc=jdelvare@suse.com \
--cc=kernel@axis.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox