Message ID | 20220906092743.1327269-1-marten.lindahl@axis.com (mailing list archive) |
---|---|
State | Rejected |
Headers | show |
Series | hwmon: (pmbus) Add debugfs output voltage related commands | expand |
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 > 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,
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,
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,
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. Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com> --- drivers/hwmon/pmbus/pmbus_core.c | 80 +++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-)