All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (pmbus) add MFR_* registers to debugfs
@ 2022-04-19 21:53 Adam Wujek
  2022-04-20 12:22 ` [PATCH 2/2] " Adam Wujek
  0 siblings, 1 reply; 10+ messages in thread
From: Adam Wujek @ 2022-04-19 21:53 UTC (permalink / raw)
  Cc: Adam Wujek, Guenter Roeck, Jean Delvare, linux-hwmon, linux-kernel

Add registers to debugfs:
PMBUS_MFR_ID
PMBUS_MFR_MODEL
PMBUS_MFR_REVISION
PMBUS_MFR_LOCATION
PMBUS_MFR_DATE
PMBUS_MFR_SERIAL

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
 drivers/hwmon/pmbus/pmbus_core.c | 85 ++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index ef9989be8f89..6dc63f364ee6 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2156,6 +2156,31 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
 			 NULL, "0x%04llx\n");

+
+static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
+				       size_t count, loff_t *ppos)
+{
+	int rc;
+	struct pmbus_debugfs_entry *entry = file->private_data;
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+	rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
+	if (rc < 0)
+		return rc;
+
+	data[rc] = '\n';
+	rc += 2;
+
+	return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations pmbus_debugfs_ops_mfr = {
+	.llseek = noop_llseek,
+	.read = pmbus_debugfs_mfr_read,
+	.write = NULL,
+	.open = simple_open,
+};
+
 static int pmbus_init_debugfs(struct i2c_client *client,
 			      struct pmbus_data *data)
 {
@@ -2286,6 +2311,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
 					    &entries[idx++],
 					    &pmbus_debugfs_ops);
 		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_ID;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_MODEL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_REVISION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_LOCATION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_DATE;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_SERIAL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
 	}

 	return 0;
--
2.17.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-19 21:53 [PATCH] hwmon: (pmbus) add MFR_* registers to debugfs Adam Wujek
@ 2022-04-20 12:22 ` Adam Wujek
  2022-04-20 13:53   ` Guenter Roeck
  0 siblings, 1 reply; 10+ messages in thread
From: Adam Wujek @ 2022-04-20 12:22 UTC (permalink / raw)
  Cc: Adam Wujek, Guenter Roeck, Jean Delvare, linux-hwmon, linux-kernel

Add registers to debugfs:
PMBUS_MFR_ID
PMBUS_MFR_MODEL
PMBUS_MFR_REVISION
PMBUS_MFR_LOCATION
PMBUS_MFR_DATE
PMBUS_MFR_SERIAL

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
 drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 0af7a3d74f47..1dc186780ccf 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
 			 NULL, "0x%04llx\n");

+static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
+				       size_t count, loff_t *ppos)
+{
+	int rc;
+	struct pmbus_debugfs_entry *entry = file->private_data;
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+	rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
+	if (rc < 0)
+		return rc;
+
+	data[rc] = '\n';
+	rc += 2;
+
+	return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations pmbus_debugfs_ops_mfr = {
+	.llseek = noop_llseek,
+	.read = pmbus_debugfs_mfr_read,
+	.write = NULL,
+	.open = simple_open,
+};
+
 static int pmbus_debugfs_get_pec(void *data, u64 *val)
 {
 	struct i2c_client *client = data;
@@ -2801,6 +2825,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
 					    &entries[idx++],
 					    &pmbus_debugfs_ops);
 		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_ID;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_MODEL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_REVISION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_LOCATION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_DATE;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_SERIAL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
 	}

 	return devm_add_action_or_reset(data->dev,
--
2.25.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 12:22 ` [PATCH 2/2] " Adam Wujek
@ 2022-04-20 13:53   ` Guenter Roeck
  2022-04-20 13:58     ` wujek dev
  0 siblings, 1 reply; 10+ messages in thread
From: Guenter Roeck @ 2022-04-20 13:53 UTC (permalink / raw)
  To: Adam Wujek; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On 4/20/22 05:22, Adam Wujek wrote:
> Add registers to debugfs:
> PMBUS_MFR_ID
> PMBUS_MFR_MODEL
> PMBUS_MFR_REVISION
> PMBUS_MFR_LOCATION
> PMBUS_MFR_DATE
> PMBUS_MFR_SERIAL
> 
> Signed-off-by: Adam Wujek <dev_public@wujek.eu>

Where is patch 1/2, and why did you resend this patch ?

Guenter

> ---
>   drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
>   1 file changed, 84 insertions(+)
> 
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 0af7a3d74f47..1dc186780ccf 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
>   DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
>   			 NULL, "0x%04llx\n");
> 
> +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
> +				       size_t count, loff_t *ppos)
> +{
> +	int rc;
> +	struct pmbus_debugfs_entry *entry = file->private_data;
> +	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
> +
> +	rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
> +	if (rc < 0)
> +		return rc;
> +
> +	data[rc] = '\n';
> +	rc += 2;
> +
> +	return simple_read_from_buffer(buf, count, ppos, data, rc);
> +}
> +
> +static const struct file_operations pmbus_debugfs_ops_mfr = {
> +	.llseek = noop_llseek,
> +	.read = pmbus_debugfs_mfr_read,
> +	.write = NULL,
> +	.open = simple_open,
> +};
> +
>   static int pmbus_debugfs_get_pec(void *data, u64 *val)
>   {
>   	struct i2c_client *client = data;
> @@ -2801,6 +2825,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
>   					    &entries[idx++],
>   					    &pmbus_debugfs_ops);
>   		}
> +
> +		if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
> +			entries[idx].client = client;
> +			entries[idx].page = i;
> +			entries[idx].reg = PMBUS_MFR_ID;
> +			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
> +			debugfs_create_file(name, 0444, data->debugfs,
> +					    &entries[idx++],
> +					    &pmbus_debugfs_ops_mfr);
> +		}
> +
> +		if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
> +			entries[idx].client = client;
> +			entries[idx].page = i;
> +			entries[idx].reg = PMBUS_MFR_MODEL;
> +			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i);
> +			debugfs_create_file(name, 0444, data->debugfs,
> +					    &entries[idx++],
> +					    &pmbus_debugfs_ops_mfr);
> +		}
> +
> +		if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
> +			entries[idx].client = client;
> +			entries[idx].page = i;
> +			entries[idx].reg = PMBUS_MFR_REVISION;
> +			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i);
> +			debugfs_create_file(name, 0444, data->debugfs,
> +					    &entries[idx++],
> +					    &pmbus_debugfs_ops_mfr);
> +		}
> +
> +		if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
> +			entries[idx].client = client;
> +			entries[idx].page = i;
> +			entries[idx].reg = PMBUS_MFR_LOCATION;
> +			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i);
> +			debugfs_create_file(name, 0444, data->debugfs,
> +					    &entries[idx++],
> +					    &pmbus_debugfs_ops_mfr);
> +		}
> +
> +		if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
> +			entries[idx].client = client;
> +			entries[idx].page = i;
> +			entries[idx].reg = PMBUS_MFR_DATE;
> +			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i);
> +			debugfs_create_file(name, 0444, data->debugfs,
> +					    &entries[idx++],
> +					    &pmbus_debugfs_ops_mfr);
> +		}
> +
> +		if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
> +			entries[idx].client = client;
> +			entries[idx].page = i;
> +			entries[idx].reg = PMBUS_MFR_SERIAL;
> +			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i);
> +			debugfs_create_file(name, 0444, data->debugfs,
> +					    &entries[idx++],
> +					    &pmbus_debugfs_ops_mfr);
> +		}
>   	}
> 
>   	return devm_add_action_or_reset(data->dev,
> --
> 2.25.1
> 
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 13:53   ` Guenter Roeck
@ 2022-04-20 13:58     ` wujek dev
  2022-04-20 14:15       ` Guenter Roeck
  0 siblings, 1 reply; 10+ messages in thread
From: wujek dev @ 2022-04-20 13:58 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, linux-kernel

------- Original Message -------
On Wednesday, April 20th, 2022 at 15:53, Guenter Roeck <linux@roeck-us.net> wrote:

>
>
> On 4/20/22 05:22, Adam Wujek wrote:
>
> > Add registers to debugfs:
> > PMBUS_MFR_ID
> > PMBUS_MFR_MODEL
> > PMBUS_MFR_REVISION
> > PMBUS_MFR_LOCATION
> > PMBUS_MFR_DATE
> > PMBUS_MFR_SERIAL
> >
> > Signed-off-by: Adam Wujek dev_public@wujek.eu
>
>
> Where is patch 1/2, and why did you resend this patch ?
>
There should be no "1/2" since this and the second patch are unrelated.
I resend it because I rebased it on master.

Adam

> Guenter
>
> > ---
> > drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
> > 1 file changed, 84 insertions(+)
> >
> > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > index 0af7a3d74f47..1dc186780ccf 100644
> > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > @@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
> > DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
> > NULL, "0x%04llx\n");
> >
> > +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
> > + size_t count, loff_t *ppos)
> > +{
> > + int rc;
> > + struct pmbus_debugfs_entry *entry = file->private_data;
> > + char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
> > +
> > + rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
> > + if (rc < 0)
> > + return rc;
> > +
> > + data[rc] = '\n';
> > + rc += 2;
> > +
> > + return simple_read_from_buffer(buf, count, ppos, data, rc);
> > +}
> > +
> > +static const struct file_operations pmbus_debugfs_ops_mfr = {
> > + .llseek = noop_llseek,
> > + .read = pmbus_debugfs_mfr_read,
> > + .write = NULL,
> > + .open = simple_open,
> > +};
> > +
> > static int pmbus_debugfs_get_pec(void *data, u64 *val)
> > {
> > struct i2c_client *client = data;
> > @@ -2801,6 +2825,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
> > &entries[idx++],
> > &pmbus_debugfs_ops);
> > }
> > +
> > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
> > + entries[idx].client = client;
> > + entries[idx].page = i;
> > + entries[idx].reg = PMBUS_MFR_ID;
> > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
> > + debugfs_create_file(name, 0444, data->debugfs,
> > + &entries[idx++],
> > + &pmbus_debugfs_ops_mfr);
> > + }
> > +
> > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
> > + entries[idx].client = client;
> > + entries[idx].page = i;
> > + entries[idx].reg = PMBUS_MFR_MODEL;
> > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i);
> > + debugfs_create_file(name, 0444, data->debugfs,
> > + &entries[idx++],
> > + &pmbus_debugfs_ops_mfr);
> > + }
> > +
> > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
> > + entries[idx].client = client;
> > + entries[idx].page = i;
> > + entries[idx].reg = PMBUS_MFR_REVISION;
> > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i);
> > + debugfs_create_file(name, 0444, data->debugfs,
> > + &entries[idx++],
> > + &pmbus_debugfs_ops_mfr);
> > + }
> > +
> > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
> > + entries[idx].client = client;
> > + entries[idx].page = i;
> > + entries[idx].reg = PMBUS_MFR_LOCATION;
> > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i);
> > + debugfs_create_file(name, 0444, data->debugfs,
> > + &entries[idx++],
> > + &pmbus_debugfs_ops_mfr);
> > + }
> > +
> > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
> > + entries[idx].client = client;
> > + entries[idx].page = i;
> > + entries[idx].reg = PMBUS_MFR_DATE;
> > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i);
> > + debugfs_create_file(name, 0444, data->debugfs,
> > + &entries[idx++],
> > + &pmbus_debugfs_ops_mfr);
> > + }
> > +
> > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
> > + entries[idx].client = client;
> > + entries[idx].page = i;
> > + entries[idx].reg = PMBUS_MFR_SERIAL;
> > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i);
> > + debugfs_create_file(name, 0444, data->debugfs,
> > + &entries[idx++],
> > + &pmbus_debugfs_ops_mfr);
> > + }
> > }
> >
> > return devm_add_action_or_reset(data->dev,
> > --
> > 2.25.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 13:58     ` wujek dev
@ 2022-04-20 14:15       ` Guenter Roeck
  2022-04-20 15:41         ` [v3 PATCH] " Adam Wujek
  2022-04-20 15:51         ` [PATCH 2/2] " wujek dev
  0 siblings, 2 replies; 10+ messages in thread
From: Guenter Roeck @ 2022-04-20 14:15 UTC (permalink / raw)
  To: wujek dev; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On 4/20/22 06:58, wujek dev wrote:
> ------- Original Message -------
> On Wednesday, April 20th, 2022 at 15:53, Guenter Roeck <linux@roeck-us.net> wrote:
> 
>>
>>
>> On 4/20/22 05:22, Adam Wujek wrote:
>>
>>> Add registers to debugfs:
>>> PMBUS_MFR_ID
>>> PMBUS_MFR_MODEL
>>> PMBUS_MFR_REVISION
>>> PMBUS_MFR_LOCATION
>>> PMBUS_MFR_DATE
>>> PMBUS_MFR_SERIAL
>>>
>>> Signed-off-by: Adam Wujek dev_public@wujek.eu
>>
>>
>> Where is patch 1/2, and why did you resend this patch ?
>>
> There should be no "1/2" since this and the second patch are unrelated.
> I resend it because I rebased it on master.
> 
Please provide change logs and version your patches in the future.

> Adam
> 
>> Guenter
>>
>>> ---
>>> drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
>>> 1 file changed, 84 insertions(+)
>>>
>>> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
>>> index 0af7a3d74f47..1dc186780ccf 100644
>>> --- a/drivers/hwmon/pmbus/pmbus_core.c
>>> +++ b/drivers/hwmon/pmbus/pmbus_core.c
>>> @@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
>>> DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
>>> NULL, "0x%04llx\n");
>>>
>>> +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
>>> + size_t count, loff_t *ppos)
>>> +{
>>> + int rc;
>>> + struct pmbus_debugfs_entry *entry = file->private_data;
>>> + char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
>>> +
>>> + rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
>>> + if (rc < 0)
>>> + return rc;
>>> +
>>> + data[rc] = '\n';
>>> + rc += 2;

Why +2 ?

>>> +
>>> + return simple_read_from_buffer(buf, count, ppos, data, rc);
>>> +}
>>> +
>>> +static const struct file_operations pmbus_debugfs_ops_mfr = {
>>> + .llseek = noop_llseek,
>>> + .read = pmbus_debugfs_mfr_read,
>>> + .write = NULL,
>>> + .open = simple_open,
>>> +};
>>> +
>>> static int pmbus_debugfs_get_pec(void *data, u64 *val)
>>> {
>>> struct i2c_client *client = data;
>>> @@ -2801,6 +2825,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
>>> &entries[idx++],
>>> &pmbus_debugfs_ops);
>>> }
>>> +
>>> + if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
>>> + entries[idx].client = client;
>>> + entries[idx].page = i;
>>> + entries[idx].reg = PMBUS_MFR_ID;
>>> + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
>>> + debugfs_create_file(name, 0444, data->debugfs,
>>> + &entries[idx++],
>>> + &pmbus_debugfs_ops_mfr);
>>> + }

You are adding several debugfs entries without increasing the size
of the entries array. That means that up to 16 debugfs entries are
now created into an array of size 10. That won't work.

Guenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [v3 PATCH] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 14:15       ` Guenter Roeck
@ 2022-04-20 15:41         ` Adam Wujek
  2022-04-20 15:51         ` [PATCH 2/2] " wujek dev
  1 sibling, 0 replies; 10+ messages in thread
From: Adam Wujek @ 2022-04-20 15:41 UTC (permalink / raw)
  Cc: Adam Wujek, Guenter Roeck, Jean Delvare, linux-hwmon, linux-kernel

Add registers to debugfs:
PMBUS_MFR_ID
PMBUS_MFR_MODEL
PMBUS_MFR_REVISION
PMBUS_MFR_LOCATION
PMBUS_MFR_DATE
PMBUS_MFR_SERIAL

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
Notes:
    Changes in v2:
    - Rebase to the latest kernel
    - Marked wrongly as a part of series of patches

    Changes in v3:
    - Submit as a single patch. V2 was wrongly submitted as a part of
      series of patches
    - add justification for "rc += 2;"
    - increase allocated memory for debugfs entries

 drivers/hwmon/pmbus/pmbus_core.c | 89 +++++++++++++++++++++++++++++++-
 1 file changed, 88 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index d93574d6a1fb..a791e5f08fb2 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2627,6 +2627,33 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
 			 NULL, "0x%04llx\n");

+static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
+				       size_t count, loff_t *ppos)
+{
+	int rc;
+	struct pmbus_debugfs_entry *entry = file->private_data;
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+	rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
+	if (rc < 0)
+		return rc;
+
+	/* Add newline at the end of a string */
+	data[rc] = '\n';
+	/* Include newline and NULL char into the length as block read from
+	 * SMBUS does not include null character. */
+	rc += 2;
+
+	return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations pmbus_debugfs_ops_mfr = {
+	.llseek = noop_llseek,
+	.read = pmbus_debugfs_mfr_read,
+	.write = NULL,
+	.open = simple_open,
+};
+
 static int pmbus_debugfs_get_pec(void *data, u64 *val)
 {
 	struct i2c_client *client = data;
@@ -2693,7 +2720,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,

 	/* Allocate the max possible entries we need. */
 	entries = devm_kcalloc(data->dev,
-			       data->info->pages * 10, sizeof(*entries),
+			       data->info->pages * 16, sizeof(*entries),
 			       GFP_KERNEL);
 	if (!entries)
 		return -ENOMEM;
@@ -2803,6 +2830,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
 					    &entries[idx++],
 					    &pmbus_debugfs_ops);
 		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_ID;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_MODEL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_REVISION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_LOCATION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_DATE;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_SERIAL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
 	}

 	return devm_add_action_or_reset(data->dev,
--
2.25.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 14:15       ` Guenter Roeck
  2022-04-20 15:41         ` [v3 PATCH] " Adam Wujek
@ 2022-04-20 15:51         ` wujek dev
  2022-04-20 16:06           ` Guenter Roeck
  1 sibling, 1 reply; 10+ messages in thread
From: wujek dev @ 2022-04-20 15:51 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, linux-kernel

------- Original Message -------
On Wednesday, April 20th, 2022 at 16:15, Guenter Roeck <linux@roeck-us.net> wrote:


>
>
> On 4/20/22 06:58, wujek dev wrote:
>
> > ------- Original Message -------
> > On Wednesday, April 20th, 2022 at 15:53, Guenter Roeck linux@roeck-us.net wrote:
> >
> > > On 4/20/22 05:22, Adam Wujek wrote:
> > >
> > > > Add registers to debugfs:
> > > > PMBUS_MFR_ID
> > > > PMBUS_MFR_MODEL
> > > > PMBUS_MFR_REVISION
> > > > PMBUS_MFR_LOCATION
> > > > PMBUS_MFR_DATE
> > > > PMBUS_MFR_SERIAL
> > > >
> > > > Signed-off-by: Adam Wujek dev_public@wujek.eu
> > >
> > > Where is patch 1/2, and why did you resend this patch ?
> >
> > There should be no "1/2" since this and the second patch are unrelated.
> > I resend it because I rebased it on master.
>
> Please provide change logs and version your patches in the future.
ok, thank you for your patience.
>
> > Adam
> >
> > > Guenter
> > >
> > > > ---
> > > > drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
> > > > 1 file changed, 84 insertions(+)
> > > >
> > > > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > > > index 0af7a3d74f47..1dc186780ccf 100644
> > > > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > > > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > > > @@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
> > > > DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
> > > > NULL, "0x%04llx\n");
> > > >
> > > > +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
> > > > + size_t count, loff_t *ppos)
> > > > +{
> > > > + int rc;
> > > > + struct pmbus_debugfs_entry *entry = file->private_data;
> > > > + char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
> > > > +
> > > > + rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
> > > > + if (rc < 0)
> > > > + return rc;
> > > > +
> > > > + data[rc] = '\n';
> > > > + rc += 2;
>
>
> Why +2 ?
>
Copied from another driver.
+1 due to '\n'
+1 due to NULL character (smbus block transfer does not include it in the length)
Explanation included in v3 patch.
> > > > +
> > > > + return simple_read_from_buffer(buf, count, ppos, data, rc);
> > > > +}
> > > > +
> > > > +static const struct file_operations pmbus_debugfs_ops_mfr = {
> > > > + .llseek = noop_llseek,
> > > > + .read = pmbus_debugfs_mfr_read,
> > > > + .write = NULL,
> > > > + .open = simple_open,
> > > > +};
> > > > +
> > > > static int pmbus_debugfs_get_pec(void *data, u64 *val)
> > > > {
> > > > struct i2c_client *client = data;
> > > > @@ -2801,6 +2825,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
> > > > &entries[idx++],
> > > > &pmbus_debugfs_ops);
> > > > }
> > > > +
> > > > + if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
> > > > + entries[idx].client = client;
> > > > + entries[idx].page = i;
> > > > + entries[idx].reg = PMBUS_MFR_ID;
> > > > + scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
> > > > + debugfs_create_file(name, 0444, data->debugfs,
> > > > + &entries[idx++],
> > > > + &pmbus_debugfs_ops_mfr);
> > > > + }
>
>
> You are adding several debugfs entries without increasing the size
> of the entries array. That means that up to 16 debugfs entries are
> now created into an array of size 10. That won't work.
You're right, I just sent another patch.

Adam
>
> Guenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 15:51         ` [PATCH 2/2] " wujek dev
@ 2022-04-20 16:06           ` Guenter Roeck
  2022-04-20 21:37             ` wujek dev
  2022-04-20 21:41             ` [v4 PATCH] " Adam Wujek
  0 siblings, 2 replies; 10+ messages in thread
From: Guenter Roeck @ 2022-04-20 16:06 UTC (permalink / raw)
  To: wujek dev; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On 4/20/22 08:51, wujek dev wrote:
> ------- Original Message -------
> On Wednesday, April 20th, 2022 at 16:15, Guenter Roeck <linux@roeck-us.net> wrote:
> 
> 
>>
>>
>> On 4/20/22 06:58, wujek dev wrote:
>>
>>> ------- Original Message -------
>>> On Wednesday, April 20th, 2022 at 15:53, Guenter Roeck linux@roeck-us.net wrote:
>>>
>>>> On 4/20/22 05:22, Adam Wujek wrote:
>>>>
>>>>> Add registers to debugfs:
>>>>> PMBUS_MFR_ID
>>>>> PMBUS_MFR_MODEL
>>>>> PMBUS_MFR_REVISION
>>>>> PMBUS_MFR_LOCATION
>>>>> PMBUS_MFR_DATE
>>>>> PMBUS_MFR_SERIAL
>>>>>
>>>>> Signed-off-by: Adam Wujek dev_public@wujek.eu
>>>>
>>>> Where is patch 1/2, and why did you resend this patch ?
>>>
>>> There should be no "1/2" since this and the second patch are unrelated.
>>> I resend it because I rebased it on master.
>>
>> Please provide change logs and version your patches in the future.
> ok, thank you for your patience.
>>
>>> Adam
>>>
>>>> Guenter
>>>>
>>>>> ---
>>>>> drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
>>>>> 1 file changed, 84 insertions(+)
>>>>>
>>>>> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
>>>>> index 0af7a3d74f47..1dc186780ccf 100644
>>>>> --- a/drivers/hwmon/pmbus/pmbus_core.c
>>>>> +++ b/drivers/hwmon/pmbus/pmbus_core.c
>>>>> @@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
>>>>> DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
>>>>> NULL, "0x%04llx\n");
>>>>>
>>>>> +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
>>>>> + size_t count, loff_t *ppos)
>>>>> +{
>>>>> + int rc;
>>>>> + struct pmbus_debugfs_entry *entry = file->private_data;
>>>>> + char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
>>>>> +
>>>>> + rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
>>>>> + if (rc < 0)
>>>>> + return rc;
>>>>> +
>>>>> + data[rc] = '\n';
>>>>> + rc += 2;
>>
>>
>> Why +2 ?
>>
> Copied from another driver.
> +1 due to '\n'
> +1 due to NULL character (smbus block transfer does not include it in the length)
> Explanation included in v3 patch.

"copied from another driver" is not really a good argument.
That other driver might just be buggy.

What do you see in userspace when you read the data ? A string that ends with
"\n\0" ? If so, does the "\0" at the end add any value ?

Guenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 16:06           ` Guenter Roeck
@ 2022-04-20 21:37             ` wujek dev
  2022-04-20 21:41             ` [v4 PATCH] " Adam Wujek
  1 sibling, 0 replies; 10+ messages in thread
From: wujek dev @ 2022-04-20 21:37 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, linux-kernel

------- Original Message -------
On Wednesday, April 20th, 2022 at 18:06, Guenter Roeck <linux@roeck-us.net> wrote:


>
>
> On 4/20/22 08:51, wujek dev wrote:
>
> > ------- Original Message -------
> > On Wednesday, April 20th, 2022 at 16:15, Guenter Roeck linux@roeck-us.net wrote:
> >
> > > On 4/20/22 06:58, wujek dev wrote:
> > >
> > > > ------- Original Message -------
> > > > On Wednesday, April 20th, 2022 at 15:53, Guenter Roeck linux@roeck-us.net wrote:
> > > >
> > > > > On 4/20/22 05:22, Adam Wujek wrote:
> > > > >
> > > > > > Add registers to debugfs:
> > > > > > PMBUS_MFR_ID
> > > > > > PMBUS_MFR_MODEL
> > > > > > PMBUS_MFR_REVISION
> > > > > > PMBUS_MFR_LOCATION
> > > > > > PMBUS_MFR_DATE
> > > > > > PMBUS_MFR_SERIAL
> > > > > >
> > > > > > Signed-off-by: Adam Wujek dev_public@wujek.eu
> > > > >
> > > > > Where is patch 1/2, and why did you resend this patch ?
> > > >
> > > > There should be no "1/2" since this and the second patch are unrelated.
> > > > I resend it because I rebased it on master.
> > >
> > > Please provide change logs and version your patches in the future.
> > > ok, thank you for your patience.
> > >
> > > > Adam
> > > >
> > > > > Guenter
> > > > >
> > > > > > ---
> > > > > > drivers/hwmon/pmbus/pmbus_core.c | 84 ++++++++++++++++++++++++++++++++
> > > > > > 1 file changed, 84 insertions(+)
> > > > > >
> > > > > > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > > > > > index 0af7a3d74f47..1dc186780ccf 100644
> > > > > > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > > > > > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > > > > > @@ -2625,6 +2625,30 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
> > > > > > DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
> > > > > > NULL, "0x%04llx\n");
> > > > > >
> > > > > > +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
> > > > > > + size_t count, loff_t *ppos)
> > > > > > +{
> > > > > > + int rc;
> > > > > > + struct pmbus_debugfs_entry *entry = file->private_data;
> > > > > > + char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
> > > > > > +
> > > > > > + rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
> > > > > > + if (rc < 0)
> > > > > > + return rc;
> > > > > > +
> > > > > > + data[rc] = '\n';
> > > > > > + rc += 2;
> > >
> > > Why +2 ?
> >
> > Copied from another driver.
> > +1 due to '\n'
> > +1 due to NULL character (smbus block transfer does not include it in the length)
> > Explanation included in v3 patch.
>
>
> "copied from another driver" is not really a good argument.
> That other driver might just be buggy.
yes, you're right. There is a bug in that driver.
>
> What do you see in userspace when you read the data ? A string that ends with
> "\n\0" ? If so, does the "\0" at the end add any value ?
I confirm I see "\n\0". I will fix it right now. Thank you for pointing it out.

Adam
>
> Guenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [v4 PATCH] hwmon: (pmbus) add MFR_* registers to debugfs
  2022-04-20 16:06           ` Guenter Roeck
  2022-04-20 21:37             ` wujek dev
@ 2022-04-20 21:41             ` Adam Wujek
  1 sibling, 0 replies; 10+ messages in thread
From: Adam Wujek @ 2022-04-20 21:41 UTC (permalink / raw)
  Cc: Adam Wujek, Guenter Roeck, Jean Delvare, linux-hwmon, linux-kernel

Add registers to debugfs:
PMBUS_MFR_ID
PMBUS_MFR_MODEL
PMBUS_MFR_REVISION
PMBUS_MFR_LOCATION
PMBUS_MFR_DATE
PMBUS_MFR_SERIAL

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
Notes:
    Changes in v2:
    - Rebase to the latest kernel
    - Marked wrongly as a part of series of patches

    Changes in v3:
    - Submit as a single patch. V2 was wrongly submitted as a part of
      series of patches
    - Add justification for "rc += 2;"
    - Increase allocated memory for debugfs entries

    Changes in v4:
    - Change "rc += 2;" into "rc += 1;". With "rc += 2" an extra '\0' is
      observed after '\n' at the end of debugfs file's output.

 drivers/hwmon/pmbus/pmbus_core.c | 89 +++++++++++++++++++++++++++++++-
 1 file changed, 88 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index d93574d6a1fb..a791e5f08fb2 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2627,6 +2627,33 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
 			 NULL, "0x%04llx\n");

+static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
+				       size_t count, loff_t *ppos)
+{
+	int rc;
+	struct pmbus_debugfs_entry *entry = file->private_data;
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+	rc = i2c_smbus_read_block_data(entry->client, entry->reg, data);
+	if (rc < 0)
+		return rc;
+
+	/* Add newline at the end of a read data */
+	data[rc] = '\n';
+
+	/* Include newline into the length */
+	rc += 1;
+
+	return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations pmbus_debugfs_ops_mfr = {
+	.llseek = noop_llseek,
+	.read = pmbus_debugfs_mfr_read,
+	.write = NULL,
+	.open = simple_open,
+};
+
 static int pmbus_debugfs_get_pec(void *data, u64 *val)
 {
 	struct i2c_client *client = data;
@@ -2693,7 +2720,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,

 	/* Allocate the max possible entries we need. */
 	entries = devm_kcalloc(data->dev,
-			       data->info->pages * 10, sizeof(*entries),
+			       data->info->pages * 16, sizeof(*entries),
 			       GFP_KERNEL);
 	if (!entries)
 		return -ENOMEM;
@@ -2803,6 +2830,66 @@ static int pmbus_init_debugfs(struct i2c_client *client,
 					    &entries[idx++],
 					    &pmbus_debugfs_ops);
 		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_ID;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_MODEL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_REVISION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_LOCATION;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_DATE;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
+
+		if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
+			entries[idx].client = client;
+			entries[idx].page = i;
+			entries[idx].reg = PMBUS_MFR_SERIAL;
+			scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i);
+			debugfs_create_file(name, 0444, data->debugfs,
+					    &entries[idx++],
+					    &pmbus_debugfs_ops_mfr);
+		}
 	}

 	return devm_add_action_or_reset(data->dev,
--
2.25.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-04-20 21:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 21:53 [PATCH] hwmon: (pmbus) add MFR_* registers to debugfs Adam Wujek
2022-04-20 12:22 ` [PATCH 2/2] " Adam Wujek
2022-04-20 13:53   ` Guenter Roeck
2022-04-20 13:58     ` wujek dev
2022-04-20 14:15       ` Guenter Roeck
2022-04-20 15:41         ` [v3 PATCH] " Adam Wujek
2022-04-20 15:51         ` [PATCH 2/2] " wujek dev
2022-04-20 16:06           ` Guenter Roeck
2022-04-20 21:37             ` wujek dev
2022-04-20 21:41             ` [v4 PATCH] " Adam Wujek

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.