Skip to contentSkip to conversation

platform/chrome: wilco_ec: Add debugfs test_event file

PATCH Superseded Daniel Campello 3 participants 4 messages Sep 18, 2019 – Sep 24, 2019 Chrome hardware platform support

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 platform/chrome: wilco_ec: Add debugfs test_event file

This change introduces a new debugfs file 'test_event' that when written to causes the EC to generate a test event.

---
Changes for v2:
- Cleaned up and added comments.
- Renamed and updated function signature from write_to_mailbox to send_ec_cmd.
Changes for v3:
- Switched NULL format string to empty format string
- Renamed val parameter on send_ec_cmd to out_val
Changes for v4:
- Provided a format string to avoid -Wformat-zero-length warning

 drivers/platform/chrome/wilco_ec/debugfs.c | 46 +++++++++++++++++-----
 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +36 -10
index 8d65a1e2f1a3..ba86c38421ff 100644
@@ -160,29 +160,29 @@ static const struct file_operations fops_raw = {
 
 #define CMD_KB_CHROME		0x88
 #define SUB_CMD_H1_GPIO		0x0A
+#define SUB_CMD_TEST_EVENT	0x0B
 
-struct h1_gpio_status_request {
+struct ec_request {
 	u8 cmd;		/* Always CMD_KB_CHROME */
 	u8 reserved;
-	u8 sub_cmd;	/* Always SUB_CMD_H1_GPIO */
+	u8 sub_cmd;
 } __packed;
 
-struct hi_gpio_status_response {
+struct ec_response {
 	u8 status;	/* 0 if allowed */
-	u8 val;		/* BIT(0)=ENTRY_TO_FACT_MODE, BIT(1)=SPI_CHROME_SEL */
+	u8 val;
 } __packed;
 
-static int h1_gpio_get(void *arg, u64 *val)
+static int send_ec_cmd(struct wilco_ec_device *ec, u8 sub_cmd, u8 *out_val)
 {
-	struct wilco_ec_device *ec = arg;
-	struct h1_gpio_status_request rq;
-	struct hi_gpio_status_response rs;
+	struct ec_request rq;
+	struct ec_response rs;
 	struct wilco_ec_message msg;
 	int ret;
 
 	memset(&rq, 0, sizeof(rq));
 	rq.cmd = CMD_KB_CHROME;
-	rq.sub_cmd = SUB_CMD_H1_GPIO;
+	rq.sub_cmd = sub_cmd;
 
 	memset(&msg, 0, sizeof(msg));
 	msg.type = WILCO_EC_MSG_LEGACY;
@@ -196,13 +196,37 @@ static int h1_gpio_get(void *arg, u64 *val)
 	if (rs.status)
 		return -EIO;
 
-	*val = rs.val;
+	*out_val = rs.val;
 
 	return 0;
 }
+/**
+ * h1_gpio_get() - Gets h1 gpio status.
+ * @arg: The wilco EC device.
+ * @val: BIT(0)=ENTRY_TO_FACT_MODE, BIT(1)=SPI_CHROME_SEL
+ */
+static int h1_gpio_get(void *arg, u64 *val)
+{
+	return send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val);
+}
 
 DEFINE_DEBUGFS_ATTRIBUTE(fops_h1_gpio, h1_gpio_get, NULL, "0x%02llx\n");
 
+/**
+ * test_event_set() - Sends command to EC to cause an EC test event.
+ * @arg: The wilco EC device.
+ * @val: unused.
+ */
+static int test_event_set(void *arg, u64 val)
+{
+	u8 ret;
+
+	return send_ec_cmd(arg, SUB_CMD_TEST_EVENT, &ret);
+}
+
+/* Format is unused since it is only required for get method which is NULL */
+DEFINE_DEBUGFS_ATTRIBUTE(fops_test_event, NULL, test_event_set, "%llu\n");
+
 /**
  * wilco_ec_debugfs_probe() - Create the debugfs node
  * @pdev: The platform device, probably created in core.c
@@ -226,6 +250,8 @@ static int wilco_ec_debugfs_probe(struct platform_device *pdev)
 	debugfs_create_file("raw", 0644, debug_info->dir, NULL, &fops_raw);
 	debugfs_create_file("h1_gpio", 0444, debug_info->dir, ec,
 			    &fops_h1_gpio);
+	debugfs_create_file("test_event", 0200, debug_info->dir, ec,
+			    &fops_test_event);
 
 	return 0;
 }

--
2.23.0.237.gc6a4ce50a0-goog

Reviewed-by on v4 1/1
#1 lore raw

Assuming that the Kbuild bot doesn't get mad about the format string now, LGTM. Thanks Daniel!

Quoted 113 lines · Daniel Campello

This change introduces a new debugfs file 'test_event' that when written to causes the EC to generate a test event.

---
Changes for v2:
- Cleaned up and added comments.
- Renamed and updated function signature from write_to_mailbox to send_ec_cmd.
Changes for v3:
- Switched NULL format string to empty format string
- Renamed val parameter on send_ec_cmd to out_val
Changes for v4:
- Provided a format string to avoid -Wformat-zero-length warning

 drivers/platform/chrome/wilco_ec/debugfs.c | 46 +++++++++++++++++-----
 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +36 -11
index 8d65a1e2f1a3..ba86c38421ff 100644
@@ -160,29 +160,29 @@ static const struct file_operations fops_raw = {
 
 #define CMD_KB_CHROME          0x88
 #define SUB_CMD_H1_GPIO                0x0A
+#define SUB_CMD_TEST_EVENT     0x0B
 
-struct h1_gpio_status_request {
+struct ec_request {
        u8 cmd;         /* Always CMD_KB_CHROME */
        u8 reserved;
-       u8 sub_cmd;     /* Always SUB_CMD_H1_GPIO */
+       u8 sub_cmd;
 } __packed;
 
-struct hi_gpio_status_response {
+struct ec_response {
        u8 status;      /* 0 if allowed */
-       u8 val;         /* BIT(0)=ENTRY_TO_FACT_MODE, BIT(1)=SPI_CHROME_SEL */
+       u8 val;
 } __packed;
 
-static int h1_gpio_get(void *arg, u64 *val)
+static int send_ec_cmd(struct wilco_ec_device *ec, u8 sub_cmd, u8 *out_val)
 {
-       struct wilco_ec_device *ec = arg;
-       struct h1_gpio_status_request rq;
-       struct hi_gpio_status_response rs;
+       struct ec_request rq;
+       struct ec_response rs;
        struct wilco_ec_message msg;
        int ret;
 
        memset(&rq, 0, sizeof(rq));
        rq.cmd = CMD_KB_CHROME;
-       rq.sub_cmd = SUB_CMD_H1_GPIO;
+       rq.sub_cmd = sub_cmd;
 
        memset(&msg, 0, sizeof(msg));
        msg.type = WILCO_EC_MSG_LEGACY;
@@ -196,13 +196,37 @@ static int h1_gpio_get(void *arg, u64 *val)
        if (rs.status)
                return -EIO;
 
-       *val = rs.val;
+       *out_val = rs.val;
 
        return 0;
 }
+/**
+ * h1_gpio_get() - Gets h1 gpio status.
+ * @arg: The wilco EC device.
+ * @val: BIT(0)=ENTRY_TO_FACT_MODE, BIT(1)=SPI_CHROME_SEL
+ */
+static int h1_gpio_get(void *arg, u64 *val)
+{
+       return send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val);
+}
 
 DEFINE_DEBUGFS_ATTRIBUTE(fops_h1_gpio, h1_gpio_get, NULL, "0x%02llx\n");
 
+/**
+ * test_event_set() - Sends command to EC to cause an EC test event.
+ * @arg: The wilco EC device.
+ * @val: unused.
+ */
+static int test_event_set(void *arg, u64 val)
+{
+       u8 ret;
+
+       return send_ec_cmd(arg, SUB_CMD_TEST_EVENT, &ret);
+}
+
+/* Format is unused since it is only required for get method which is NULL */
+DEFINE_DEBUGFS_ATTRIBUTE(fops_test_event, NULL, test_event_set, "%llu\n");
+
 /**
  * wilco_ec_debugfs_probe() - Create the debugfs node
  * @pdev: The platform device, probably created in core.c
@@ -226,6 +250,8 @@ static int wilco_ec_debugfs_probe(struct platform_device *pdev)
        debugfs_create_file("raw", 0644, debug_info->dir, NULL, &fops_raw);
        debugfs_create_file("h1_gpio", 0444, debug_info->dir, ec,
                            &fops_h1_gpio);
+       debugfs_create_file("test_event", 0200, debug_info->dir, ec,
+                           &fops_test_event);
 
        return 0;
 }
--

2.23.0.237.gc6a4ce50a0-goog

#2 lore raw
In reply to Daniel Campello

Hi Daniel,

Thanks for sending this.

Quoted 2 lines · Daniel Campello

This change introduces a new debugfs file 'test_event' that when written to causes the EC to generate a test event.

Please mention that this adds a second sub cmd for the test event, and pulls out send_ec_cmd to be a common helper between h1_gpio_get and test_event_set.

Quoted 60 lines

---
Changes for v2:
- Cleaned up and added comments.
- Renamed and updated function signature from write_to_mailbox to send_ec_cmd.
Changes for v3:
- Switched NULL format string to empty format string
- Renamed val parameter on send_ec_cmd to out_val
Changes for v4:
- Provided a format string to avoid -Wformat-zero-length warning

 drivers/platform/chrome/wilco_ec/debugfs.c | 46 +++++++++++++++++-----
 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +9 -9
index 8d65a1e2f1a3..ba86c38421ff 100644
@@ -160,29 +160,29 @@ static const struct file_operations fops_raw = {
 
 #define CMD_KB_CHROME		0x88
 #define SUB_CMD_H1_GPIO		0x0A
+#define SUB_CMD_TEST_EVENT	0x0B
 
-struct h1_gpio_status_request {
+struct ec_request {
 	u8 cmd;		/* Always CMD_KB_CHROME */
 	u8 reserved;
-	u8 sub_cmd;	/* Always SUB_CMD_H1_GPIO */
+	u8 sub_cmd;
 } __packed;
 
-struct hi_gpio_status_response {
+struct ec_response {
 	u8 status;	/* 0 if allowed */
-	u8 val;		/* BIT(0)=ENTRY_TO_FACT_MODE, BIT(1)=SPI_CHROME_SEL */
+	u8 val;
 } __packed;
 
-static int h1_gpio_get(void *arg, u64 *val)
+static int send_ec_cmd(struct wilco_ec_device *ec, u8 sub_cmd, u8 *out_val)
 {
-	struct wilco_ec_device *ec = arg;
-	struct h1_gpio_status_request rq;
-	struct hi_gpio_status_response rs;
+	struct ec_request rq;
+	struct ec_response rs;
 	struct wilco_ec_message msg;
 	int ret;
 
 	memset(&rq, 0, sizeof(rq));
 	rq.cmd = CMD_KB_CHROME;
-	rq.sub_cmd = SUB_CMD_H1_GPIO;
+	rq.sub_cmd = sub_cmd;
 
 	memset(&msg, 0, sizeof(msg));
 	msg.type = WILCO_EC_MSG_LEGACY;

drivers/platform/chrome/wilco_ec/debugfs.c static int h1_gpio_get(void *arg, u64 *val) · line 203

Quoted 9 lines
drivers/platform/chrome/wilco_ec/debugfs.c +2 -1
@@ -196,13 +196,37 @@ static int h1_gpio_get(void *arg, u64 *val)
 	if (rs.status)
 		return -EIO;
 
-	*val = rs.val;
+	*out_val = rs.val;
 
 	return 0;
 }
+/**

Minor nit. Add one line of whitespace before this comment start.

Quoted 41 lines
drivers/platform/chrome/wilco_ec/debugfs.c +25 -1
+ * h1_gpio_get() - Gets h1 gpio status.
+ * @arg: The wilco EC device.
+ * @val: BIT(0)=ENTRY_TO_FACT_MODE, BIT(1)=SPI_CHROME_SEL
+ */
+static int h1_gpio_get(void *arg, u64 *val)
+{
+	return send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val);
+}
 
 DEFINE_DEBUGFS_ATTRIBUTE(fops_h1_gpio, h1_gpio_get, NULL, "0x%02llx\n");
 
+/**
+ * test_event_set() - Sends command to EC to cause an EC test event.
+ * @arg: The wilco EC device.
+ * @val: unused.
+ */
+static int test_event_set(void *arg, u64 val)
+{
+	u8 ret;
+
+	return send_ec_cmd(arg, SUB_CMD_TEST_EVENT, &ret);
+}
+
+/* Format is unused since it is only required for get method which is NULL */
+DEFINE_DEBUGFS_ATTRIBUTE(fops_test_event, NULL, test_event_set, "%llu\n");
+
 /**
  * wilco_ec_debugfs_probe() - Create the debugfs node
  * @pdev: The platform device, probably created in core.c
@@ -226,6 +250,8 @@ static int wilco_ec_debugfs_probe(struct platform_device *pdev)
 	debugfs_create_file("raw", 0644, debug_info->dir, NULL, &fops_raw);
 	debugfs_create_file("h1_gpio", 0444, debug_info->dir, ec,
 			    &fops_h1_gpio);
+	debugfs_create_file("test_event", 0200, debug_info->dir, ec,
+			    &fops_test_event);
 
 	return 0;
 }
--

2.23.0.237.gc6a4ce50a0-goog

Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]