From: Naresh Solanki <naresh.solanki@9elements.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org, Jean Delvare <jdelvare@suse.com>,
Patrick Rudolph <patrick.rudolph@9elements.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: pm_bus: core: Implement regulator get_status
Date: Fri, 18 Nov 2022 14:17:03 +0530 [thread overview]
Message-ID: <ccfa3067-302f-56a9-cbf7-6ba14350718a@9elements.com> (raw)
In-Reply-To: <20221117223856.GA675221@roeck-us.net>
Hi Guenter,
On 18-11-2022 04:08 am, Guenter Roeck wrote:
> On Thu, Nov 17, 2022 at 08:43:51PM +0100, Naresh Solanki wrote:
>> From: Patrick Rudolph <patrick.rudolph@9elements.com>
>>
>> Add get_status for pmbus_regulator_ops.
>>
>> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
>> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
>> ---
>> drivers/hwmon/pmbus/pmbus_core.c | 78 ++++++++++++++++++++++++++++++++
>> 1 file changed, 78 insertions(+)
>>
>> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
>> index 7ec04934747e..d5e2b0662da5 100644
>> --- a/drivers/hwmon/pmbus/pmbus_core.c
>> +++ b/drivers/hwmon/pmbus/pmbus_core.c
>> @@ -2851,6 +2851,83 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
>> return 0;
>> }
>>
>> +static int pmbus_regulator_get_status(struct regulator_dev *rdev)
>> +{
>> + struct device *dev = rdev_get_dev(rdev);
>> + struct i2c_client *client = to_i2c_client(dev->parent);
>> + struct pmbus_data *data = i2c_get_clientdata(client);
>> + u8 page = rdev_get_id(rdev);
>> + int status, status2;
>> +
>> + mutex_lock(&data->update_lock);
>> + status = pmbus_get_status(client, page, PMBUS_STATUS_WORD);
>> + mutex_unlock(&data->update_lock);
>> + if (status < 0)
>> + return status;
>> +
>> + if (status & PB_STATUS_VIN_UV ||
>> + status & PB_STATUS_IOUT_OC ||
>> + status & PB_STATUS_VOUT_OV ||
>> + status & PB_STATUS_UNKNOWN)
>> + return REGULATOR_STATUS_ERROR;
>
> if (status & (PB_STATUS_VIN_UV | PB_STATUS_IOUT_OC | ...))
>
> PB_STATUS_UNKNOWN can mean anything and doesn't necessarily indicate
> an error. Not sure if it makes sense to report that as error.
I wasn't sure about this but as per spec, it still means unknown fault
or warning. Thats why I've considered it for returning error status.
>
>> +
>> + if (status & PB_STATUS_VOUT_OV &&
>
> PB_STATUS_VOUT_OV was checked above already, and the code won't get here
> if the bit is set.
Oh yes. Will change to PB_STATUS_VOUT so that other VOUT faults can be
checked.
>
>> + data->info->func[page] & PMBUS_HAVE_STATUS_VOUT) {
>> + mutex_lock(&data->update_lock);
>> + status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_VOUT);
>> + mutex_unlock(&data->update_lock);
>> + if (status2 < 0)
>> + return status2;
>> + if (status2 & PB_VOLTAGE_OV_FAULT ||
>> + status2 & PB_VOLTAGE_UV_FAULT)
>
> if (status2 & (...))
>
Sure will update this way.
>> + return REGULATOR_STATUS_ERROR;
>> + }
>> + if (status & PB_STATUS_IOUT_OC &&
>
> Same as above - this condition will never be true.
>
Will change to PB_STATUS_IOUT_POUT so that STATUS_IOUT can be checked
for other faults related to POUT & IOUT which aren't present in STATUS_WORD.
>> + data->info->func[page] & PMBUS_HAVE_STATUS_IOUT) {
>> + mutex_lock(&data->update_lock);
>> + status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT);
>> + mutex_unlock(&data->update_lock);
>> + if (status2 < 0)
>> + return status2;
>> + if (status2 & PB_POUT_OP_FAULT ||
>> + status2 & PB_IOUT_UC_FAULT ||
>> + status2 & PB_IOUT_OC_LV_FAULT ||
>> + status2 & PB_IOUT_OC_FAULT)
>
> if (status2 & (...))
>
Will update accordingly.
>> + return REGULATOR_STATUS_ERROR;
>> + }
>> + if (status & PB_STATUS_VIN_UV &&
>
> and again.
>
Will update to PB_STATUS_INPUT.
>> + data->info->func[page] & PMBUS_HAVE_STATUS_INPUT) {
>> + mutex_lock(&data->update_lock);
>> + status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_INPUT);
>> + mutex_unlock(&data->update_lock);
>> + if (status2 < 0)
>> + return status2;
>> + if (status2 & PB_IIN_OC_FAULT ||
>> + status2 & PB_VOLTAGE_OV_FAULT ||
>> + status2 & PB_VOLTAGE_UV_FAULT)
>
> and again
>
Will update to right way.
>> + return REGULATOR_STATUS_ERROR;
>> + }
>> + if (status & PB_STATUS_TEMPERATURE &&
>> + data->info->func[page] & PMBUS_HAVE_STATUS_TEMP) {
>> + mutex_lock(&data->update_lock);
>> + status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_TEMPERATURE);
>> + mutex_unlock(&data->update_lock);
>> + if (status2 < 0)
>> + return status2;
>> + if (status2 & PB_TEMP_UT_FAULT ||
>> + status2 & PB_TEMP_OT_FAULT)
>
> and again
>
Will update.
>> + return REGULATOR_STATUS_ERROR;
>> + }
>> +
>> + if (status & PB_STATUS_OFF)
>> + return REGULATOR_STATUS_OFF;
>> +
>> + if (status & PB_STATUS_POWER_GOOD_N)
>> + return REGULATOR_STATUS_OFF;
>
> Wouldn't it be better to check those bits first ?
> Also, it should be
>
> if (status & (PB_STATUS_OFF | PB_STATUS_POWER_GOOD_N))
>
Yes makes sense. Will update.
>> +
>> + return REGULATOR_STATUS_ON;
>> +}
>> +
>> static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)
>> {
>> struct pmbus_data *data = i2c_get_clientdata(client);
>> @@ -2991,6 +3068,7 @@ const struct regulator_ops pmbus_regulator_ops = {
>> .disable = pmbus_regulator_disable,
>> .is_enabled = pmbus_regulator_is_enabled,
>> .get_error_flags = pmbus_regulator_get_error_flags,
>> + .get_status = pmbus_regulator_get_status,
>> .get_voltage = pmbus_regulator_get_voltage,
>> .set_voltage = pmbus_regulator_set_voltage,
>> .list_voltage = pmbus_regulator_list_voltage,
>>
>> base-commit: 27fea302952d8c90cafbdbee96bafeca03544401
>> --
>> 2.37.3
>>
Regards,
Naresh
prev parent reply other threads:[~2022-11-18 8:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 19:43 Naresh Solanki
2022-11-17 22:38 ` Guenter Roeck
2022-11-18 8:47 ` Naresh Solanki [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=ccfa3067-302f-56a9-cbf7-6ba14350718a@9elements.com \
--to=naresh.solanki@9elements.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=patrick.rudolph@9elements.com \
/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
all inboxes | Powered by JetHome®