linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Naresh Solanki <naresh.solanki@9elements.com>
Cc: devicetree@vger.kernel.org, Jean Delvare <jdelvare@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	Patrick Rudolph <patrick.rudolph@9elements.com>
Subject: Re: [PATCH RESEND v6 1/5] hwmon: (pmbus/core): Add interrupt support
Date: Tue, 3 Jan 2023 09:40:04 -0800	[thread overview]
Message-ID: <20230103174004.GA202902@roeck-us.net> (raw)
In-Reply-To: <dc604c81-b447-3bc0-18c3-13e03ba56c40@9elements.com>

On Tue, Jan 03, 2023 at 08:56:59PM +0530, Naresh Solanki wrote:
> Hi Guenter
> 
> On 03-01-2023 05:56 pm, Guenter Roeck wrote:
> > On Tue, Jan 03, 2023 at 12:18:49PM +0530, Naresh Solanki wrote:
> > > Hi Guenter,
> > > 
> > > On 29-12-2022 08:10 pm, Guenter Roeck wrote:
> > > > On Wed, Dec 14, 2022 at 09:07:11AM +0100, Naresh Solanki wrote:
> > > > > From: Patrick Rudolph <patrick.rudolph@9elements.com>
> > > > > 
> > > > > Implement PMBUS irq handler.
> > > > > 
> > > > > Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> > > > > Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
> > > > 
> > > > $ scripts/checkpatch.pl --strict index.html
> > > > CHECK: Blank lines aren't necessary after an open brace '{'
> > > > #131: FILE: drivers/hwmon/pmbus/pmbus_core.c:3088:
> > > > +	for (i = 0; i < data->info->pages; i++) {
> > > > +
> > > > 
> > > > CHECK: Alignment should match open parenthesis
> > > > #183: FILE: drivers/hwmon/pmbus/pmbus_core.c:3140:
> > > > +	ret = devm_request_threaded_irq(dev, client->irq, NULL, pmbus_fault_handler,
> > > > +			      0, "pmbus-irq", data);
> > > > 
> > > > CHECK: Please use a blank line after function/struct/union/enum declarations
> > > > #197: FILE: drivers/hwmon/pmbus/pmbus_core.c:3154:
> > > >    }
> > > > +static int pmbus_irq_setup(struct i2c_client *client, struct pmbus_data *data)
> > > > 
> > > > total: 0 errors, 0 warnings, 3 checks, 109 lines checked
> > > > 
> > > > NOTE: For some of the reported defects, checkpatch may be able to
> > > >         mechanically convert to the typical style using --fix or --fix-inplace.
> > > > 
> > > > index.html has style problems, please review.
> > > > 
> > > > Please run checkpatch --strict on your patches.
> > > > Also see Documentation/hwmon/submitting-patches.rst.
> > > I will take care of these errors in the updated version.
> > > > 
> > > > > ---
> > > > >    drivers/hwmon/pmbus/pmbus.h      |  2 +-
> > > > >    drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
> > > > >    2 files changed, 85 insertions(+), 1 deletion(-)
> > > > > 
> > > > > 
> > > > > base-commit: 364ffd2537c44cb6914ff5669153f4a86fffad29
> > > > > 
> > > > > diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
> > > > > index 10fb17879f8e..6b2e6cf93b19 100644
> > > > > --- a/drivers/hwmon/pmbus/pmbus.h
> > > > > +++ b/drivers/hwmon/pmbus/pmbus.h
> > > > > @@ -26,7 +26,7 @@ enum pmbus_regs {
> > > > >    	PMBUS_CAPABILITY		= 0x19,
> > > > >    	PMBUS_QUERY			= 0x1A,
> > > > > -
> > > > > +	PMBUS_SMBALERT_MASK		= 0x1B,
> > > > >    	PMBUS_VOUT_MODE			= 0x20,
> > > > >    	PMBUS_VOUT_COMMAND		= 0x21,
> > > > >    	PMBUS_VOUT_TRIM			= 0x22,
> > > > > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > > > > index 95e95783972a..244fd2597252 100644
> > > > > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > > > > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > > > > @@ -3072,11 +3072,89 @@ static int pmbus_regulator_register(struct pmbus_data *data)
> > > > >    	return 0;
> > > > >    }
> > > > > +
> > > > > +static int pmbus_write_smbalert_mask(struct i2c_client *client, u8 page, u8 reg, u8 val)
> > > > > +{
> > > > > +	return pmbus_write_word_data(client, page, PMBUS_SMBALERT_MASK, reg | (val << 8));
> > > > > +}
> > > > > +
> > > > > +static irqreturn_t pmbus_fault_handler(int irq, void *pdata)
> > > > > +{
> > > > > +	struct pmbus_data *data = pdata;
> > > > > +	struct i2c_client *client = to_i2c_client(data->dev);
> > > > > +	int i, status;
> > > > > +
> > > > > +	for (i = 0; i < data->info->pages; i++) {
> > > > > +
> > > > > +		mutex_lock(&data->update_lock);
> > > > > +		status = pmbus_read_status_word(client, i);
> > > > > +		if (status < 0) {
> > > > > +			mutex_unlock(&data->update_lock);
> > > > > +			return status;
> > > > > +		}
> > > > > +
> > > > > +		if (status & ~(PB_STATUS_OFF | PB_STATUS_BUSY | PB_STATUS_POWER_GOOD_N))
> > > > > +			pmbus_clear_fault_page(client, i);
> > > > > +
> > > > > +		mutex_unlock(&data->update_lock);
> > > > > +	}
> > > > > +
> > > > > +	return IRQ_HANDLED;
> > > > > +}
> > > > > +
> > > > > +static int pmbus_irq_setup(struct i2c_client *client, struct pmbus_data *data)
> > > > > +{
> > > > > +	struct device *dev = &client->dev;
> > > > > +	const struct pmbus_regulator_status_category *cat;
> > > > > +	const struct pmbus_regulator_status_assoc *bit;
> > > > > +	int i, j, err, ret, func;
> > > > > +	u8 mask;
> > > > > +
> > > > > +	for (i = 0; i < data->info->pages; i++) {
> > > > > +		func = data->info->func[i];
> > > > > +
> > > > > +		for (j = 0; j < ARRAY_SIZE(pmbus_regulator_flag_map); j++) {
> > > > > +			cat = &pmbus_regulator_flag_map[j];
> > > > > +			if (!(func & cat->func))
> > > > > +				continue;
> > > > > +			mask = 0;
> > > > > +			for (bit = cat->bits; bit->pflag; bit++)
> > > > > +				mask |= bit->pflag;
> > > > > +
> > > > > +			err = pmbus_write_smbalert_mask(client, i, cat->reg, ~mask);
> > > > > +			if (err)
> > > > > +				dev_err(dev, "Failed to set smbalert for reg 0x%02x\n",	cat->reg);
> > > > 
> > > > This concerns me. It might mean that the chip does not support
> > > > PMBUS_SMBALERT_MASK. If so, there would be lots of error messages.
> > > After going through the PMBus specification, it appears that this should not
> > > be an issue unless there is a violation of the specification.
> > 
> > PMBus chips have lots of issues which violate the specification.
> > Have a look at the various drivers and the workarounds implemented there.
> > You'll need to check if the command/register is supported before using it.
> > Also, if you want to keep the error message, make it dev_err_once().
> > 
> > Either case, an error is an error, not to be ignored. An error here
> > should result in an error abort.
> Yes, I agree that PMBus chips can have issues that violate the
> specification, and that it is important to check whether a command or
> register is supported before using it.
> I have noticed that many drivers use the PMBUS_HAVE_* flags to expose the
> presence of specific registers, and I think it would be a good idea to add a
> PMBUS_HAVE_SMBALERT flag as well, so that drivers for supported chips can
> use it to determine whether they should set up an IRQ handler or not. If
> PMBUS_HAVE_SMBALERT is set, then the IRQ handler should be set up, otherwise
> it should be ignored.
> Will this approach be right?

Not really. PMBUS_HAVE_ flags are intended to indicate sensor register
support, not to indicate compliance problems. What you'd be looking for
would be the flags in struct pmbus_platform_data. However, those are only
intended to be used if registers/commands can not be auto-detected or if
doing so causes problems. See include/linux/pmbus.h for details.
Unless there is reason to believe that chips are misbehaving when trying
to read from or to set PMBUS_SMBALERT_MASK, we should stick with auto-
detection. After all, that is what pmbus_check_{status,byte,word}_register()
functions are for.

Thanks,
Guenter

      reply	other threads:[~2023-01-03 17:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14  8:07 [PATCH RESEND v6 1/5] hwmon: (pmbus/core): Add interrupt support Naresh Solanki
2022-12-14  8:07 ` [PATCH RESEND v6 2/5] hwmon: (pmbus/core): Notify hwmon events Naresh Solanki
2022-12-29 14:46   ` Guenter Roeck
2023-01-03  6:54     ` Naresh Solanki
2022-12-14  8:07 ` [PATCH RESEND v6 3/5] hwmon: (pmbus/core): Add rdev in pmbus_data struct Naresh Solanki
2022-12-14  8:07 ` [PATCH RESEND v6 4/5] hwmon: (pmbus/core): Add regulator event support Naresh Solanki
2022-12-14  8:07 ` [PATCH RESEND v6 5/5] hwmon: (pmbus/core): Notify regulator events Naresh Solanki
2022-12-29 14:40 ` [PATCH RESEND v6 1/5] hwmon: (pmbus/core): Add interrupt support Guenter Roeck
2023-01-03  6:48   ` Naresh Solanki
2023-01-03 12:26     ` Guenter Roeck
2023-01-03 15:26       ` Naresh Solanki
2023-01-03 17:40         ` Guenter Roeck [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=20230103174004.GA202902@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naresh.solanki@9elements.com \
    --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;
as well as URLs for NNTP newsgroup(s).