All of lore.kernel.org
 help / color / mirror / Atom feed
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] hwmon: (pmbus) Add debugfs output voltage related commands
Date: Wed, 7 Sep 2022 10:07:38 +0200	[thread overview]
Message-ID: <YxhRSgo3GNNHGVbP@axis.com> (raw)
In-Reply-To: <20220906171532.GA1523417@roeck-us.net>

On Tue, Sep 06, 2022 at 07:15:32PM +0200, Guenter Roeck wrote:
> On Tue, Sep 06, 2022 at 11:27:43AM +0200, Mårten Lindahl wrote:
> > Export vout_command, vout_margin_high, and vout_margin_low through
> > debugfs. This is useful in order to manually configure the output
> > voltage on a channel.
> > 
> 
> NACK, voltages must be set through regulators which is already supported.
> We are not going to start bypassing regulators. Also, I don't think it
> is a good idea to allow manipulating margin voltages. Those are critical
> and should be set by manufacturing.
> 
> Guenter

Ok, accepted. Thanks.

Kind regards
Mårten
> 
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> > ---
> >  drivers/hwmon/pmbus/pmbus_core.c | 80 +++++++++++++++++++++++++++++++-
> >  1 file changed, 78 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > index 81d3f91dd204..25da2ff2d09f 100644
> > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > @@ -3050,6 +3050,41 @@ static int pmbus_debugfs_get(void *data, u64 *val)
> >  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops, pmbus_debugfs_get, NULL,
> >  			 "0x%02llx\n");
> >  
> > +static int pmbus_debugfs_get_word(void *data, u64 *val)
> > +{
> > +	struct pmbus_debugfs_entry *entry = data;
> > +	struct pmbus_sensor s = {
> > +		.page = entry->page,
> > +		.class = PSC_VOLTAGE_OUT,
> > +		.convert = true,
> > +		.data = -1,
> > +	};
> > +
> > +	s.data = _pmbus_read_word_data(entry->client, entry->page, 0xff, entry->reg);
> > +	if (s.data < 0)
> > +		return s.data;
> > +	*val = pmbus_reg2data(i2c_get_clientdata(entry->client), &s);
> > +
> > +	return 0;
> > +}
> > +
> > +static int pmbus_debugfs_set_word(void *data, u64 val)
> > +{
> > +	struct pmbus_debugfs_entry *entry = data;
> > +	struct pmbus_sensor s = {
> > +		.page = entry->page,
> > +		.class = PSC_VOLTAGE_OUT,
> > +		.convert = true,
> > +		.data = -1,
> > +	};
> > +	val = pmbus_data2reg(i2c_get_clientdata(entry->client), &s, val);
> > +
> > +	return _pmbus_write_word_data(entry->client, entry->page, entry->reg,
> > +				      (u16)val);
> > +}
> > +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_rw_word, pmbus_debugfs_get_word,
> > +			 pmbus_debugfs_set_word, "%llu\n");
> > +
> >  static int pmbus_debugfs_get_status(void *data, u64 *val)
> >  {
> >  	int rc;
> > @@ -3126,10 +3161,10 @@ static int pmbus_init_debugfs(struct i2c_client *client,
> >  	/*
> >  	 * Allocate the max possible entries we need.
> >  	 * 6 entries device-specific
> > -	 * 10 entries page-specific
> > +	 * 13 entries page-specific
> >  	 */
> >  	entries = devm_kcalloc(data->dev,
> > -			       6 + data->info->pages * 10, sizeof(*entries),
> > +			       6 + data->info->pages * 13, sizeof(*entries),
> >  			       GFP_KERNEL);
> >  	if (!entries)
> >  		return -ENOMEM;
> > @@ -3299,6 +3334,47 @@ static int pmbus_init_debugfs(struct i2c_client *client,
> >  					    &entries[idx++],
> >  					    &pmbus_debugfs_ops);
> >  		}
> > +
> > +		/*
> > +		 * VOUT_COMMAND - Nominal DC/DC output voltage setpoint.
> > +		 */
> > +		if (data->info->func[i] & PMBUS_HAVE_VOUT) {
> > +			entries[idx].client = client;
> > +			entries[idx].page = i;
> > +			entries[idx].reg = PMBUS_VOUT_COMMAND;
> > +			scnprintf(name, PMBUS_NAME_SIZE, "vout%d_command", i);
> > +			debugfs_create_file(name, 0644, data->debugfs,
> > +					    &entries[idx++],
> > +					    &pmbus_debugfs_ops_rw_word);
> > +		}
> > +
> > +		/*
> > +		 * VOUT_MARGIN_HIGH - Margin high DC/DC converter output.
> > +		 */
> > +		if (data->info->func[i] & PMBUS_HAVE_VOUT) {
> > +			entries[idx].client = client;
> > +			entries[idx].page = i;
> > +			entries[idx].reg = PMBUS_VOUT_MARGIN_HIGH;
> > +			scnprintf(name, PMBUS_NAME_SIZE,
> > +				  "vout%d_margin_high", i);
> > +			debugfs_create_file(name, 0644, data->debugfs,
> > +					    &entries[idx++],
> > +					    &pmbus_debugfs_ops_rw_word);
> > +		}
> > +
> > +		/*
> > +		 * VOUT_MARGIN_LOW - Margin low DC/DC converter output.
> > +		 */
> > +		if (data->info->func[i] & PMBUS_HAVE_VOUT) {
> > +			entries[idx].client = client;
> > +			entries[idx].page = i;
> > +			entries[idx].reg = PMBUS_VOUT_MARGIN_LOW;
> > +			scnprintf(name, PMBUS_NAME_SIZE,
> > +				  "vout%d_margin_low", i);
> > +			debugfs_create_file(name, 0644, data->debugfs,
> > +					    &entries[idx++],
> > +					    &pmbus_debugfs_ops_rw_word);
> > +		}
> >  	}
> >  
> >  	return devm_add_action_or_reset(data->dev,

      reply	other threads:[~2022-09-07  8:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06  9:27 [PATCH] hwmon: (pmbus) Add debugfs output voltage related commands Mårten Lindahl
2022-09-06 17:15 ` Guenter Roeck
2022-09-07  8:07   ` 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=YxhRSgo3GNNHGVbP@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.