linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <alexandru.tachici@analog.com>
To: <linux-hwmon@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>
Cc: <robh+dt@kernel.org>, <linux@roeck-us.net>,
	Alexandru Tachici <alexandru.tachici@analog.com>
Subject: [PATCH v5 6/7] hwmon: pmbus: adm1266: debugfs for blackbox info
Date: Wed, 24 Jun 2020 18:17:35 +0300	[thread overview]
Message-ID: <20200624151736.95785-7-alexandru.tachici@analog.com> (raw)
In-Reply-To: <20200624151736.95785-1-alexandru.tachici@analog.com>

From: Alexandru Tachici <alexandru.tachici@analog.com>

Add a debugfs file to print information in the
BLACKBOX_INFORMATION register. Contains information
about the number of stored records, logic index and id
of the latest record.

Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
---
 drivers/hwmon/pmbus/adm1266.c | 56 ++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index b9e92ab1e39a..ea2dc481094b 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -60,6 +60,7 @@ struct adm1266_data {
 	const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR];
 	struct i2c_client *client;
 	struct mutex ioctl_mutex; /* lock ioctl access */
+	struct dentry *debugfs_dir;
 	struct nvmem_config nvmem_config;
 	struct nvmem_device *nvmem;
 	u8 *dev_mem;
@@ -406,6 +407,28 @@ static const struct proc_ops adm1266_proc_ops = {
 	.proc_ioctl	= adm1266_ioctl,
 };
 
+static int adm1266_blackbox_information_read(struct seq_file *s, void *pdata)
+{
+	struct device *dev = s->private;
+	struct i2c_client *client = to_i2c_client(dev);
+	u8 read_buf[5];
+	unsigned int latest_id;
+	int ret;
+
+	ret = i2c_smbus_read_block_data(client, ADM1266_BLACKBOX_INFO,
+					read_buf);
+	if (ret < 0)
+		return ret;
+
+	seq_puts(s, "BLACKBOX_INFORMATION:\n");
+	latest_id = read_buf[0] + (read_buf[1] << 8);
+	seq_printf(s, "Black box ID: %u\n", latest_id);
+	seq_printf(s, "Logic index: %u\n", read_buf[2]);
+	seq_printf(s, "Record count: %u\n", read_buf[3]);
+
+	return 0;
+}
+
 static int adm1266_init_procfs(struct adm1266_data *data)
 {
 	struct proc_dir_entry *proc_dir;
@@ -423,6 +446,29 @@ static int adm1266_init_procfs(struct adm1266_data *data)
 	return 0;
 }
 
+static int adm1266_init_debugfs(struct adm1266_data *data)
+{
+	struct dentry *entry;
+	struct dentry *root;
+
+	root = pmbus_get_debugfs_dir(data->client);
+	if (!root)
+		return -ENOENT;
+
+	data->debugfs_dir = debugfs_create_dir(data->client->name, root);
+	if (!data->debugfs_dir)
+		return -ENOENT;
+
+	entry = debugfs_create_devm_seqfile(&data->client->dev,
+					    "blackbox_information",
+					    data->debugfs_dir,
+					    adm1266_blackbox_information_read);
+	if (!entry)
+		return -ENOENT;
+
+	return 0;
+}
+
 static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *buf)
 {
 	u8 read_buf[5];
@@ -571,7 +617,15 @@ static int adm1266_probe(struct i2c_client *client,
 	for (i = 0; i < info->pages; i++)
 		info->func[i] = funcs;
 
-	return pmbus_do_probe(client, id, info);
+	ret = pmbus_do_probe(client, id, info);
+	if (ret)
+		return ret;
+
+	ret = adm1266_init_debugfs(data);
+	if (ret)
+		dev_warn(&client->dev, "Failed to register debugfs: %d\n", ret);
+
+	return 0;
 }
 
 static const struct of_device_id adm1266_of_match[] = {
-- 
2.20.1


  parent reply	other threads:[~2020-06-24 15:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24 15:17 [PATCH v5 0/7] hwmon: pmbus: adm1266: add support alexandru.tachici
2020-06-24 15:17 ` [PATCH v5 1/7] " alexandru.tachici
2020-06-24 15:17 ` [PATCH v5 2/7] hwmon: pmbus: adm1266: Add Block process call alexandru.tachici
2020-06-24 17:00   ` kernel test robot
2020-06-30  2:43   ` [RFC PATCH] hwmon: pmbus: adm1266: pmbus_block_xfer() can be static kernel test robot
2020-06-24 15:17 ` [PATCH v5 3/7] hwmon: pmbus: adm1266: Add support for GPIOs alexandru.tachici
2020-06-24 15:17 ` [PATCH v5 4/7] hwmon: pmbus: adm1266: Add ioctl commands alexandru.tachici
2020-06-24 15:36   ` Guenter Roeck
2020-06-24 15:17 ` [PATCH v5 5/7] hwmon: pmbus: adm1266: read blackbox alexandru.tachici
2020-06-24 15:17 ` alexandru.tachici [this message]
2020-06-24 21:53   ` [PATCH v5 6/7] hwmon: pmbus: adm1266: debugfs for blackbox info Guenter Roeck
2020-06-24 15:17 ` [PATCH v5 7/7] dt-bindings: hwmon: Add bindings for ADM1266 alexandru.tachici
2020-07-09 22:14   ` Rob Herring

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=20200624151736.95785-7-alexandru.tachici@analog.com \
    --to=alexandru.tachici@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh+dt@kernel.org \
    /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).