linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adam Wujek <dev_public@wujek.eu>
To: unlisted-recipients:; (no To-header on input)
Cc: Adam Wujek <dev_public@wujek.eu>,
	Guenter Roeck <linux@roeck-us.net>,
	Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [v4 PATCH] hwmon: (pmbus) add MFR_* registers to debugfs
Date: Wed, 20 Apr 2022 21:41:08 +0000	[thread overview]
Message-ID: <20220420214053.482902-1-dev_public@wujek.eu> (raw)
In-Reply-To: <1b12cb3a-3d87-8254-b229-dcf83ad0bc0a@roeck-us.net>

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



      parent reply	other threads:[~2022-04-20 21:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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             ` Adam Wujek [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=20220420214053.482902-1-dev_public@wujek.eu \
    --to=dev_public@wujek.eu \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@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 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).