All of lore.kernel.org
 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 v3 4/6] hwmon: pmbus: adm1266: add debugfs attr for states
Date: Fri, 29 May 2020 16:05:04 +0300	[thread overview]
Message-ID: <20200529130506.73511-5-alexandru.tachici@analog.com> (raw)
In-Reply-To: <20200529130506.73511-1-alexandru.tachici@analog.com>

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

Add debugfs files for go_command and read_state.

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

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index 190170300ef1..85d6795b79d3 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -19,6 +19,8 @@
 #include "pmbus.h"
 
 #define ADM1266_PDIO_CONFIG	0xD4
+#define ADM1266_GO_COMMAND	0xD8
+#define ADM1266_READ_STATE	0xD9
 #define ADM1266_GPIO_CONFIG	0xE1
 #define ADM1266_PDIO_STATUS	0xE9
 #define ADM1266_GPIO_STATUS	0xEA
@@ -41,6 +43,7 @@ struct adm1266_data {
 	struct gpio_chip gc;
 	const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR];
 	struct i2c_client *client;
+	struct dentry *debugfs_dir;
 };
 
 #if IS_ENABLED(CONFIG_GPIOLIB)
@@ -234,6 +237,48 @@ static inline int adm1266_config_gpio(struct adm1266_data *data)
 }
 #endif
 
+static int adm1266_get_state_op(void *pdata, u64 *state)
+{
+	struct adm1266_data *data = pdata;
+	int ret;
+
+	ret = i2c_smbus_read_word_data(data->client, ADM1266_READ_STATE);
+	if (ret < 0)
+		return ret;
+
+	*state = ret;
+
+	return 0;
+}
+
+static int adm1266_set_go_command_op(void *pdata, u64 val)
+{
+	struct adm1266_data *data = pdata;
+	u8 reg;
+
+	reg = FIELD_GET(GENMASK(4, 0), val);
+
+	return i2c_smbus_write_word_data(data->client, ADM1266_GO_COMMAND, reg);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(go_command_fops, NULL, adm1266_set_go_command_op,
+			 "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(read_state_fops, adm1266_get_state_op, NULL, "%llu\n");
+
+static void adm1266_debug_init(struct adm1266_data *data)
+{
+	struct dentry *root;
+	char dir_name[30];
+
+	sprintf(dir_name, "adm1266-%x_debugfs", data->client->addr);
+	root = debugfs_create_dir(dir_name, NULL);
+	data->debugfs_dir = root;
+	debugfs_create_file_unsafe("go_command", 0200, root, data,
+				   &go_command_fops);
+	debugfs_create_file_unsafe("read_state", 0400, root, data,
+				   &read_state_fops);
+}
+
 static int adm1266_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -254,6 +299,8 @@ static int adm1266_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
+	adm1266_debug_init(data);
+
 	info = &data->info;
 	info->pages = 17;
 	info->format[PSC_VOLTAGE_OUT] = linear;
-- 
2.20.1


  parent reply	other threads:[~2020-05-29 13:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29 13:05 [PATCH v3 0/6] hwmon: pmbus: adm1266: add support alexandru.tachici
2020-05-29 13:05 ` [PATCH v3 1/6] " alexandru.tachici
2020-05-29 13:05 ` [PATCH v3 2/6] hwmon: (pmbus/core) Add Block WR alexandru.tachici
2020-05-29 17:55   ` Guenter Roeck
2020-05-29 13:05 ` [PATCH v3 3/6] hwmon: pmbus: adm1266: Add support for GPIOs alexandru.tachici
2020-05-29 18:36   ` Guenter Roeck
2020-05-29 13:05 ` alexandru.tachici [this message]
2020-05-29 18:43   ` [PATCH v3 4/6] hwmon: pmbus: adm1266: add debugfs attr for states Guenter Roeck
2020-05-29 13:05 ` [PATCH v3 5/6] hwmon: pmbus: adm1266: read blackbox alexandru.tachici
2020-05-29 18:45   ` Guenter Roeck
2020-05-29 13:05 ` [PATCH v3 6/6] dt-bindings: hwmon: Add bindings for ADM1266 alexandru.tachici
2020-05-29 21:17   ` 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=20200529130506.73511-5-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 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.