All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] cros_ec: Add features required for verified boot
@ 2021-01-16 21:52 Simon Glass
  2021-01-16 21:52 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

The Chromium OS EC has developed a few more features. This series adds
support for some of these, to allow a more recent verified-boot
implementation to work.

Also some existing features don't have commands available. It is useful
to be able to check the EC state from the command line, so this series
adds commands for listing features, checking switches, etc.

The following parts of the implementation are added or expanded:
   - SKU ID for finding out basic factory information
   - 'features' for seeing what the EC supports
   - 'switches' for LID open, etc.
   - events for seeing when the EC has an event for the AP
   - vstore (for storing data in the EC)

The current comment style is used for new functions.


Simon Glass (10):
  cros_ec: Add a function for the hello message
  cros_ec: Tidy up a few delays
  cros_ec: Add run-time check for input buffer overflow
  cros_ec: Add support for reading the SKU ID
  cros_ec: Support reading EC features
  cros_ec: Add documentation for cros_ec driver operations
  cros_ec: Add support for switches
  cros_ec: Show events in human-readable form
  cros_ec: Allow use with of-platdata
  cros_ec: Add vstore support

 arch/sandbox/include/asm/test.h |  15 +++
 cmd/cros_ec.c                   | 195 ++++++++++++++++++++++++++++++-
 drivers/misc/cros_ec.c          | 200 +++++++++++++++++++++++++++-----
 drivers/misc/cros_ec_lpc.c      |   7 ++
 drivers/misc/cros_ec_sandbox.c  | 100 +++++++++++++++-
 include/cros_ec.h               | 142 +++++++++++++++++++++++
 include/ec_commands.h           |  45 ++++++-
 test/dm/Makefile                |   1 +
 test/dm/cros_ec.c               | 178 ++++++++++++++++++++++++++++
 9 files changed, 844 insertions(+), 39 deletions(-)
 create mode 100644 test/dm/cros_ec.c

-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 01/10] cros_ec: Add a function for the hello message
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 02/10] cros_ec: Tidy up a few delays Simon Glass
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

This is used several times in this file. Put it in a function to avoid
code duplication.

Also add a test for this function. There are no cros_ec tests at present,
so it is time to update the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/include/asm/test.h | 14 ++++++++++
 drivers/misc/cros_ec.c          | 46 ++++++++++++++++++++++-----------
 drivers/misc/cros_ec_sandbox.c  | 12 +++++++++
 include/cros_ec.h               | 11 ++++++++
 test/dm/Makefile                |  1 +
 test/dm/cros_ec.c               | 32 +++++++++++++++++++++++
 6 files changed, 101 insertions(+), 15 deletions(-)
 create mode 100644 test/dm/cros_ec.c

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 05f66f700ca..8363ca73195 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -57,6 +57,12 @@ enum {
 	SYSCON_COUNT
 };
 
+/**
+ */
+enum cros_ec_test_t {
+	CROSECT_BREAK_HELLO	= BIT(1),
+};
+
 /**
  * sandbox_i2c_set_test_mode() - set test mode for running unit tests
  *
@@ -260,4 +266,12 @@ uint sandbox_pci_read_bar(u32 barval, int type, uint size);
  */
 void sandbox_set_enable_memio(bool enable);
 
+/**
+ * sandbox_cros_ec_set_test_flags() - Set behaviour for testing purposes
+ *
+ * @dev: Device to check
+ * @flags: Flags to control behaviour (CROSECT_...)
+ */
+void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags);
+
 #endif
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index f03b7d55d64..013c67e0464 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -591,6 +591,25 @@ static int cros_ec_invalidate_hash(struct udevice *dev)
 	return 0;
 }
 
+int cros_ec_hello(struct udevice *dev, uint *handshakep)
+{
+	struct ec_params_hello req;
+	struct ec_response_hello *resp;
+
+	req.in_data = 0x12345678;
+	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
+			     (uint8_t **)&resp, sizeof(*resp)) < 0)
+		return -EIO;
+	if (resp->out_data != req.in_data + 0x01020304) {
+		printf("Received invalid handshake %x\n", resp->out_data);
+		if (handshakep)
+			*handshakep = req.in_data;
+		return -ENOTSYNC;
+	}
+
+	return 0;
+}
+
 int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
 {
 	struct ec_params_reboot_ec p;
@@ -738,7 +757,6 @@ static int cros_ec_check_version(struct udevice *dev)
 {
 	struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
 	struct ec_params_hello req;
-	struct ec_response_hello *resp;
 
 	struct dm_cros_ec_ops *ops;
 	int ret;
@@ -767,14 +785,14 @@ static int cros_ec_check_version(struct udevice *dev)
 	/* Try sending a version 3 packet */
 	cdev->protocol_version = 3;
 	req.in_data = 0;
-	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
-			     (uint8_t **)&resp, sizeof(*resp)) > 0)
+	ret = cros_ec_hello(dev, NULL);
+	if (!ret || ret == -ENOTSYNC)
 		return 0;
 
 	/* Try sending a version 2 packet */
 	cdev->protocol_version = 2;
-	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
-			     (uint8_t **)&resp, sizeof(*resp)) > 0)
+	ret = cros_ec_hello(dev, NULL);
+	if (!ret || ret == -ENOTSYNC)
 		return 0;
 
 	/*
@@ -790,18 +808,16 @@ static int cros_ec_check_version(struct udevice *dev)
 
 int cros_ec_test(struct udevice *dev)
 {
-	struct ec_params_hello req;
-	struct ec_response_hello *resp;
+	uint out_data;
+	int ret;
 
-	req.in_data = 0x12345678;
-	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
-		       (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) {
+	ret = cros_ec_hello(dev, &out_data);
+	if (ret == -ENOTSYNC) {
+		printf("Received invalid handshake %x\n", out_data);
+		return ret;
+	} else if (ret) {
 		printf("ec_command_inptr() returned error\n");
-		return -1;
-	}
-	if (resp->out_data != req.in_data + 0x01020304) {
-		printf("Received invalid handshake %x\n", resp->out_data);
-		return -1;
+		return ret;
 	}
 
 	return 0;
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 9fd6cc2086c..1922a9c1b96 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -18,6 +18,7 @@
 #include <asm/malloc.h>
 #include <asm/state.h>
 #include <asm/sdl.h>
+#include <asm/test.h>
 #include <linux/input.h>
 
 /*
@@ -73,6 +74,7 @@ struct ec_keymatrix_entry {
  * @matrix: Information about keyboard matrix
  * @keyscan: Current keyscan information (bit set for each row/column pressed)
  * @recovery_req: Keyboard recovery requested
+ * @test_flags: Flags that control behaviour for tests
  */
 struct ec_state {
 	u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
@@ -84,6 +86,7 @@ struct ec_state {
 	struct ec_keymatrix_entry *matrix;	/* the key matrix info */
 	uint8_t keyscan[KEYBOARD_COLS];
 	bool recovery_req;
+	uint test_flags;
 } s_state, *g_state;
 
 /**
@@ -295,6 +298,8 @@ static int process_cmd(struct ec_state *ec,
 		struct ec_response_hello *resp = resp_data;
 
 		resp->out_data = req->in_data + 0x01020304;
+		if (ec->test_flags & CROSECT_BREAK_HELLO)
+			resp->out_data++;
 		len = sizeof(*resp);
 		break;
 	}
@@ -518,6 +523,13 @@ void cros_ec_check_keyboard(struct udevice *dev)
 	}
 }
 
+void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags)
+{
+	struct ec_state *ec = dev_get_priv(dev);
+
+	ec->test_flags = flags;
+}
+
 int cros_ec_probe(struct udevice *dev)
 {
 	struct ec_state *ec = dev_get_priv(dev);
diff --git a/include/cros_ec.h b/include/cros_ec.h
index f187bd0d4b5..f57e0cc4501 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -497,4 +497,15 @@ int cros_ec_get_lid_shutdown_mask(struct udevice *dev);
  */
 int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable);
 
+/**
+ * cros_ec_hello() - Send a hello message
+ *
+ * Sends a message with a fixed input value and checks that the expected output
+ * value is received
+ *
+ * @dev: CROS-EC device
+ * @handshakep: If non-NULL, returns received handshake value on error
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_hello(struct udevice *dev, uint *handshakep);
 #endif
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 46e076ed099..afcabfacc1b 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BUTTON) += button.o
 obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o
 obj-$(CONFIG_CLK) += clk.o clk_ccf.o
+obj-$(CONFIG_CROS_EC) += cros_ec.o
 obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
 obj-$(CONFIG_DM_ETH) += eth.o
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
new file mode 100644
index 00000000000..823245ca70b
--- /dev/null
+++ b/test/dm/cros_ec.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <cros_ec.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_cros_ec_hello(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	uint val;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+
+	ut_assertok(cros_ec_hello(dev, NULL));
+
+	val = 0xdead1357;
+	ut_assertok(cros_ec_hello(dev, &val));
+	ut_asserteq(0xdead1357, val);
+
+	sandbox_cros_ec_set_test_flags(dev, CROSECT_BREAK_HELLO);
+	ut_asserteq(-ENOTSYNC, cros_ec_hello(dev, &val));
+	ut_asserteq(0x12345678, val);
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT);
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 02/10] cros_ec: Tidy up a few delays
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
  2021-01-16 21:52 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Simon Glass
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

Allow a longer time for the EC to reboot. Also use a constant for the
hash delay time, so it is clear what it is for.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 013c67e0464..ce5fa5bee35 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -44,6 +44,10 @@ enum {
 	CROS_EC_CMD_TIMEOUT_MS	= 5000,
 	/* Timeout waiting for a synchronous hash to be recomputed */
 	CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
+
+	/* Wait 10 ms between attempts to check if EC's hash is ready */
+	CROS_EC_HASH_CHECK_DELAY_MS = 10,
+
 };
 
 #define INVALID_HCMD 0xFF
@@ -502,9 +506,10 @@ static int cros_ec_wait_on_hash_done(struct udevice *dev,
 
 	start = get_timer(0);
 	while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) {
-		mdelay(50);	/* Insert some reasonable delay */
+		mdelay(CROS_EC_HASH_CHECK_DELAY_MS);
 
 		p->cmd = EC_VBOOT_HASH_GET;
+
 		if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, p, sizeof(*p), hash,
 			       sizeof(*hash)) < 0)
 			return -1;
@@ -622,18 +627,23 @@ int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
 		return -1;
 
 	if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) {
+		ulong start;
+
 		/*
 		 * EC reboot will take place immediately so delay to allow it
 		 * to complete.  Note that some reboot types (EC_REBOOT_COLD)
 		 * will reboot the AP as well, in which case we won't actually
 		 * get to this point.
 		 */
-		/*
-		 * TODO(rspangler@chromium.org): Would be nice if we had a
-		 * better way to determine when the reboot is complete.  Could
-		 * we poll a memory-mapped LPC value?
-		 */
-		udelay(50000);
+		mdelay(50);
+		start = get_timer(0);
+		while (cros_ec_hello(dev, NULL)) {
+			if (get_timer(start) > 3000) {
+				log_err("EC did not return from reboot\n");
+				return -ETIMEDOUT;
+			}
+			mdelay(5);
+		}
 	}
 
 	return 0;
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
  2021-01-16 21:52 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass
  2021-01-16 21:52 ` [PATCH 02/10] cros_ec: Tidy up a few delays Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 04/10] cros_ec: Add support for reading the SKU ID Simon Glass
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

This should not happen in normal operation, but the EC might have a bug,
so add a run-time check just in case.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index ce5fa5bee35..e51ac874098 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -404,6 +404,8 @@ static int ec_command(struct udevice *dev, uint cmd, int cmd_version,
 		 */
 		if (din && in_buffer) {
 			assert(len <= din_len);
+			if (len > din_len)
+				return -ENOSPC;
 			memmove(din, in_buffer, len);
 		}
 	}
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 04/10] cros_ec: Add support for reading the SKU ID
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (2 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 05/10] cros_ec: Support reading EC features Simon Glass
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

This allows reading strapping pins attached to the EC. Add an
implementation for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/cros_ec.c                  | 10 ++++++++++
 drivers/misc/cros_ec.c         | 13 +++++++++++++
 drivers/misc/cros_ec_sandbox.c |  7 +++++++
 include/cros_ec.h              |  8 ++++++++
 test/dm/cros_ec.c              | 17 +++++++++++++++++
 5 files changed, 55 insertions(+)

diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c
index ce1f59a740c..4e85e184fee 100644
--- a/cmd/cros_ec.c
+++ b/cmd/cros_ec.c
@@ -352,6 +352,15 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 			debug("%s: Could not access LDO%d\n", __func__, index);
 			return ret;
 		}
+	} else if (!strcmp("sku", cmd)) {
+		ret = cros_ec_get_sku_id(dev);
+
+		if (ret >= 0) {
+			printf("%d\n", ret);
+			ret = 0;
+		} else {
+			printf("Error: %d\n", ret);
+		}
 	} else {
 		return CMD_RET_USAGE;
 	}
@@ -382,6 +391,7 @@ U_BOOT_CMD(
 	"crosec write <ro|rw> <addr> [<size>]  Write EC image\n"
 	"crosec vbnvcontext [hexstring]        Read [write] VbNvContext from EC\n"
 	"crosec ldo <idx> [<state>] Switch/Read LDO state\n"
+	"crosec sku                 Read board SKU ID\n"
 	"crosec test                run tests on cros_ec\n"
 	"crosec version             Read CROS-EC version"
 );
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index e51ac874098..80709be2f15 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1105,6 +1105,19 @@ int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image,
 	return 0;
 }
 
+int cros_ec_get_sku_id(struct udevice *dev)
+{
+	struct ec_sku_id_info *r;
+	int ret;
+
+	ret = ec_command_inptr(dev, EC_CMD_GET_SKU_ID, 0, NULL, 0,
+			       (uint8_t **)&r, sizeof(*r));
+	if (ret != sizeof(*r))
+		return -ret;
+
+	return r->sku_id;
+}
+
 int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size)
 {
 	struct ec_params_vbnvcontext p;
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 1922a9c1b96..93243847048 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -473,6 +473,13 @@ static int process_cmd(struct ec_state *ec,
 		len = sizeof(*resp);
 		break;
 	}
+	case EC_CMD_GET_SKU_ID: {
+		struct ec_sku_id_info *resp = resp_data;
+
+		resp->sku_id = 1234;
+		len = sizeof(*resp);
+		break;
+	}
 	default:
 		printf("   ** Unknown EC command %#02x\n", req_hdr->command);
 		return -1;
diff --git a/include/cros_ec.h b/include/cros_ec.h
index f57e0cc4501..1154cdc52b8 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -329,6 +329,14 @@ int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
 int cros_ec_flash_offset(struct udevice *dev, enum ec_flash_region region,
 			 uint32_t *offset, uint32_t *size);
 
+/**
+ * cros_ec_get_sku_id() - Read the SKU ID
+ *
+ * @dev: CROS-EC device
+ * return SKU ID, or -ve on error
+ */
+int cros_ec_get_sku_id(struct udevice *dev);
+
 /**
  * Read/write non-volatile data from/to a CROS-EC device.
  *
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
index 823245ca70b..3d0e5dc08d3 100644
--- a/test/dm/cros_ec.c
+++ b/test/dm/cros_ec.c
@@ -30,3 +30,20 @@ static int dm_test_cros_ec_hello(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT);
+
+static int dm_test_cros_ec_sku_id(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+	ut_asserteq(1234, cros_ec_get_sku_id(dev));
+
+	/* try the command */
+	console_record_reset();
+	ut_assertok(run_command("crosec sku", 0));
+	ut_assert_nextline("1234");
+	ut_assert_console_end();
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT);
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 05/10] cros_ec: Support reading EC features
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (3 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 04/10] cros_ec: Add support for reading the SKU ID Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Simon Glass
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

The EC can support a variety of features and provides a way to find out
what is available. Add support for this.

Also update the feature list to the lastest available while we are here.
This is at:

   https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/include/ec_commands.h

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/cros_ec.c                  | 74 ++++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec.c         | 26 +++++++++---
 drivers/misc/cros_ec_sandbox.c | 11 +++++
 include/cros_ec.h              | 21 ++++++++++
 include/ec_commands.h          | 45 +++++++++++++++++++--
 test/dm/cros_ec.c              | 28 +++++++++++++
 6 files changed, 195 insertions(+), 10 deletions(-)

diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c
index 4e85e184fee..77656a2308c 100644
--- a/cmd/cros_ec.c
+++ b/cmd/cros_ec.c
@@ -94,6 +94,74 @@ static int do_read_write(struct udevice *dev, int is_write, int argc,
 	return 0;
 }
 
+static const char *const feat_name[64] = {
+	"limited",
+	"flash",
+	"pwm_fan",
+	"pwm_keyb",
+	"lightbar",
+	"led",
+	"motion_sense",
+	"keyb",
+	"pstore",
+	"port80",
+	"thermal",
+	"bklight_switch",
+	"wifi_switch",
+	"host_events",
+	"gpio",
+	"i2c",
+	"charger",
+	"battery",
+	"smart_battery",
+	"hang_detect",
+	"pmu",
+	"sub_mcu",
+	"usb_pd",
+	"usb_mux",
+	"motion_sense_fifo",
+	"vstore",
+	"usbc_ss_mux_virtual",
+	"rtc",
+	"fingerprint",
+	"touchpad",
+	"rwsig",
+	"device_event",
+	"unified_wake_masks",
+	"host_event64",
+	"exec_in_ram",
+	"cec",
+	"motion_sense_tight_timestamps",
+	"refined_tablet_mode_hysteresis",
+	"efs2",
+	"scp",
+	"ish",
+	"typec_cmd",
+	"typec_require_ap_mode_entry",
+	"typec_mux_require_ap_ack",
+};
+
+static int do_show_features(struct udevice *dev)
+{
+	u64 feat;
+	int ret;
+	uint i;
+
+	ret = cros_ec_get_features(dev, &feat);
+	if (ret)
+		return ret;
+	for (i = 0; i < ARRAY_SIZE(feat_name); i++) {
+		if (feat & (1ULL << i)) {
+			if (feat_name[i])
+				printf("%s\n", feat_name[i]);
+			else
+				printf("unknown %d\n", i);
+		}
+	}
+
+	return 0;
+}
+
 static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
@@ -140,6 +208,11 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 		printf("rows     = %u\n", info.rows);
 		printf("cols     = %u\n", info.cols);
+	} else if (!strcmp("features", cmd)) {
+		ret = do_show_features(dev);
+
+		if (ret)
+			printf("Error: %d\n", ret);
 	} else if (0 == strcmp("curimage", cmd)) {
 		enum ec_current_image image;
 
@@ -379,6 +452,7 @@ U_BOOT_CMD(
 	"init                Re-init CROS-EC (done on startup automatically)\n"
 	"crosec id                  Read CROS-EC ID\n"
 	"crosec info                Read CROS-EC info\n"
+	"crosec features            Read CROS-EC features\n"
 	"crosec curimage            Read CROS-EC current image\n"
 	"crosec hash                Read CROS-EC hash\n"
 	"crosec reboot [rw | ro | cold]  Reboot CROS-EC\n"
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 80709be2f15..fd2f2abd7e8 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1344,19 +1344,33 @@ int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
 	return 0;
 }
 
-int cros_ec_check_feature(struct udevice *dev, int feature)
+int cros_ec_get_features(struct udevice *dev, u64 *featuresp)
 {
 	struct ec_response_get_features r;
 	int rv;
 
-	rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, &r, sizeof(r), NULL, 0);
-	if (rv)
-		return rv;
+	rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r));
+	if (rv != sizeof(r))
+		return -EIO;
+	*featuresp = r.flags[0] | (u64)r.flags[1] << 32;
+
+	return 0;
+}
+
+int cros_ec_check_feature(struct udevice *dev, uint feature)
+{
+	struct ec_response_get_features r;
+	int rv;
+
+	rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r));
+	if (rv != sizeof(r))
+		return -EIO;
 
 	if (feature >= 8 * sizeof(r.flags))
-		return -1;
+		return -EINVAL;
 
-	return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature);
+	return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature) ? true :
+		 false;
 }
 
 /*
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 93243847048..7213313c1ac 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -480,6 +480,17 @@ static int process_cmd(struct ec_state *ec,
 		len = sizeof(*resp);
 		break;
 	}
+	case EC_CMD_GET_FEATURES: {
+		struct ec_response_get_features *resp = resp_data;
+
+		resp->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FLASH) |
+			EC_FEATURE_MASK_0(EC_FEATURE_I2C);
+		resp->flags[1] =
+			EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS) |
+			EC_FEATURE_MASK_1(EC_FEATURE_ISH);
+		len = sizeof(*resp);
+		break;
+	}
 	default:
 		printf("   ** Unknown EC command %#02x\n", req_hdr->command);
 		return -1;
diff --git a/include/cros_ec.h b/include/cros_ec.h
index 1154cdc52b8..338878c3bed 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -516,4 +516,25 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable);
  * @return 0 if OK, -ve on error
  */
 int cros_ec_hello(struct udevice *dev, uint *handshakep);
+
+/**
+ * cros_ec_get_features() - Get the set of features provided by the EC
+ *
+ * See enum ec_feature_code for the list of available features
+ *
+ * @dev: CROS-EC device
+ * @featuresp: Returns a bitmask of supported features
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_get_features(struct udevice *dev, u64 *featuresp);
+
+/**
+ * cros_ec_check_feature() - Check if a feature is supported
+ *
+ * @dev: CROS-EC device
+ * @feature: Feature number to check (enum ec_feature_code)
+ * @return true if supported, false if not, -ve on error
+ */
+int cros_ec_check_feature(struct udevice *dev, uint feature);
+
 #endif
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 444ba61e591..36f4a02f936 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1101,13 +1101,50 @@ enum ec_feature_code {
 	EC_FEATURE_DEVICE_EVENT = 31,
 	/* EC supports the unified wake masks for LPC/eSPI systems */
 	EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
+	/* EC supports 64-bit host events */
+	EC_FEATURE_HOST_EVENT64 = 33,
+	/* EC runs code in RAM (not in place, a.k.a. XIP) */
+	EC_FEATURE_EXEC_IN_RAM = 34,
+	/* EC supports CEC commands */
+	EC_FEATURE_CEC = 35,
+	/* EC supports tight sensor timestamping. */
+	EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
+	/*
+	 * EC supports tablet mode detection aligned to Chrome and allows
+	 * setting of threshold by host command using
+	 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
+	 */
+	EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
+	/*
+	 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
+	 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
+	 * be sent to RO to be precise.
+	 */
+	EC_FEATURE_EFS2 = 38,
+	/* The MCU is a System Companion Processor (SCP). */
+	EC_FEATURE_SCP = 39,
+	/* The MCU is an Integrated Sensor Hub */
+	EC_FEATURE_ISH = 40,
+	/* New TCPMv2 TYPEC_ prefaced commands supported */
+	EC_FEATURE_TYPEC_CMD = 41,
+	/*
+	 * The EC will wait for direction from the AP to enter Type-C alternate
+	 * modes or USB4.
+	 */
+	EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
+	/*
+	 * The EC will wait for an acknowledge from the AP after setting the
+	 * mux.
+	 */
+	EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
 };
 
-#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
-#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
-struct __ec_align4 ec_response_get_features {
+#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
+#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
+
+struct ec_response_get_features {
 	uint32_t flags[2];
-};
+} __ec_align4;
 
 /*****************************************************************************/
 /* Get the board's SKU ID from EC */
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
index 3d0e5dc08d3..a1ec9fccf3a 100644
--- a/test/dm/cros_ec.c
+++ b/test/dm/cros_ec.c
@@ -47,3 +47,31 @@ static int dm_test_cros_ec_sku_id(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT);
+
+static int dm_test_cros_ec_features(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	u64 feat;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+	ut_assertok(cros_ec_get_features(dev, &feat));
+	ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C |
+		1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH,
+		feat);
+
+	ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_I2C));
+	ut_asserteq(false, cros_ec_check_feature(dev, EC_FEATURE_MOTION_SENSE));
+	ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_ISH));
+
+	/* try the command */
+	console_record_reset();
+	ut_assertok(run_command("crosec features", 0));
+	ut_assert_nextline("flash");
+	ut_assert_nextline("i2c");
+	ut_assert_nextline("unified_wake_masks");
+	ut_assert_nextline("ish");
+	ut_assert_console_end();
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT);
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (4 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 05/10] cros_ec: Support reading EC features Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 07/10] cros_ec: Add support for switches Simon Glass
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

Add comments to these methods so it is documented in this central place,
not just in each driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/cros_ec.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/include/cros_ec.h b/include/cros_ec.h
index 338878c3bed..26e3f3ba0cb 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -234,10 +234,50 @@ int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t  *image,
 struct udevice *board_get_cros_ec_dev(void);
 
 struct dm_cros_ec_ops {
+	/**
+	 * check_version() - Check the protocol version being used (optional)
+	 *
+	 * If provided, this function should check that the EC can be supported
+	 * by the driver. If not provided, HELLO messages will be sent to try
+	 * to determine the protocol version.
+	 *
+	 * @dev: Device to check
+	 * @return 0 if the protocol is valid, -ve if not supported
+	 */
 	int (*check_version)(struct udevice *dev);
+
+	/**
+	 * command() - Old-style command interface
+	 *
+	 * This sends a command and receives a response (deprecated, use
+	 * packet())
+	 *
+	 * @dev: Device to use
+	 * @cmd: Command to send (only supports 0-0xff)
+	 * @cmd_version: Version of command to send (often 0)
+	 * @dout: Output data (may be NULL If dout_len=0)
+	 * @dout_len: Length of output data excluding 4-byte header
+	 * @dinp: On input, set to point to input data, often struct
+	 *	cros_ec_dev->din - typically this is left alone but may be
+	 *	updated by the driver
+	 * @din_len: Maximum length of response
+	 * @return number of bytes in response, or -ve on error
+	 */
 	int (*command)(struct udevice *dev, uint8_t cmd, int cmd_version,
 		       const uint8_t *dout, int dout_len,
 		       uint8_t **dinp, int din_len);
+
+	/**
+	 * packet() - New-style command interface
+	 *
+	 * This interface is preferred over command(), since it is typically
+	 * easier to implement.
+	 *
+	 * @dev: Device to use
+	 * @out_bytes: Number of bytes to send (from struct cros_ec_dev->dout)
+	 * @in_bytes: Maximum number of bytes to expect in response
+	 * @return number of bytes in response, or -ve on error
+	 */
 	int (*packet)(struct udevice *dev, int out_bytes, int in_bytes);
 };
 
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 07/10] cros_ec: Add support for switches
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (5 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 08/10] cros_ec: Show events in human-readable form Simon Glass
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

On x86 platforms the EC provides a way to read 'switches', which are
on/off values determined by the EC.

Add a new driver method for this and implement it for LPC.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/include/asm/test.h |  1 +
 cmd/cros_ec.c                   | 41 +++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec.c          | 16 +++++++++++++
 drivers/misc/cros_ec_lpc.c      |  7 ++++++
 drivers/misc/cros_ec_sandbox.c  | 10 ++++++++
 include/cros_ec.h               | 19 +++++++++++++++
 test/dm/cros_ec.c               | 26 +++++++++++++++++++++
 7 files changed, 120 insertions(+)

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 8363ca73195..1cb960ac240 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -61,6 +61,7 @@ enum {
  */
 enum cros_ec_test_t {
 	CROSECT_BREAK_HELLO	= BIT(1),
+	CROSECT_LID_OPEN	= BIT(2),
 };
 
 /**
diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c
index 77656a2308c..a222c75c17c 100644
--- a/cmd/cros_ec.c
+++ b/cmd/cros_ec.c
@@ -162,6 +162,41 @@ static int do_show_features(struct udevice *dev)
 	return 0;
 }
 
+static const char *const switch_name[8] = {
+	"lid open",
+	"power button pressed",
+	"write-protect disabled",
+	NULL,
+	"dedicated recovery",
+	NULL,
+	NULL,
+	NULL,
+};
+
+static int do_show_switches(struct udevice *dev)
+{
+	uint switches;
+	int ret;
+	uint i;
+
+	ret = cros_ec_get_switches(dev);
+	if (ret < 0)
+		return log_msg_ret("get", ret);
+	switches = ret;
+	for (i = 0; i < ARRAY_SIZE(switch_name); i++) {
+		uint mask = 1 << i;
+
+		if (switches & mask) {
+			if (switch_name[i])
+				printf("%s\n", switch_name[i]);
+			else
+				printf("unknown %02x\n", mask);
+		}
+	}
+
+	return 0;
+}
+
 static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
@@ -211,6 +246,11 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 	} else if (!strcmp("features", cmd)) {
 		ret = do_show_features(dev);
 
+		if (ret)
+			printf("Error: %d\n", ret);
+	} else if (!strcmp("switches", cmd)) {
+		ret = do_show_switches(dev);
+
 		if (ret)
 			printf("Error: %d\n", ret);
 	} else if (0 == strcmp("curimage", cmd)) {
@@ -453,6 +493,7 @@ U_BOOT_CMD(
 	"crosec id                  Read CROS-EC ID\n"
 	"crosec info                Read CROS-EC info\n"
 	"crosec features            Read CROS-EC features\n"
+	"crosec switches            Read CROS-EC switches\n"
 	"crosec curimage            Read CROS-EC current image\n"
 	"crosec hash                Read CROS-EC hash\n"
 	"crosec reboot [rw | ro | cold]  Reboot CROS-EC\n"
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index fd2f2abd7e8..0bc28e882c9 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1557,6 +1557,22 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
 	return 0;
 }
 
+int cros_ec_get_switches(struct udevice *dev)
+{
+	struct dm_cros_ec_ops *ops;
+	int ret;
+
+	ops = dm_cros_ec_get_ops(dev);
+	if (!ops->get_switches)
+		return -ENOSYS;
+
+	ret = ops->get_switches(dev);
+	if (ret < 0)
+		return log_msg_ret("get", ret);
+
+	return ret;
+}
+
 UCLASS_DRIVER(cros_ec) = {
 	.id		= UCLASS_CROS_EC,
 	.name		= "cros-ec",
diff --git a/drivers/misc/cros_ec_lpc.c b/drivers/misc/cros_ec_lpc.c
index e0002b9753f..f40375978dd 100644
--- a/drivers/misc/cros_ec_lpc.c
+++ b/drivers/misc/cros_ec_lpc.c
@@ -207,6 +207,12 @@ int cros_ec_lpc_init(struct cros_ec_dev *dev, const void *blob)
 	return 0;
 }
 
+/* Return the byte of EC switch states */
+static int cros_ec_lpc_get_switches(struct udevice *dev)
+{
+	return inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
+}
+
 /*
  * Test if LPC command args are supported.
  *
@@ -239,6 +245,7 @@ static struct dm_cros_ec_ops cros_ec_ops = {
 	.packet = cros_ec_lpc_packet,
 	.command = cros_ec_lpc_command,
 	.check_version = cros_ec_lpc_check_version,
+	.get_switches = cros_ec_lpc_get_switches,
 };
 
 static const struct udevice_id cros_ec_ids[] = {
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 7213313c1ac..38a2614a993 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -75,6 +75,7 @@ struct ec_keymatrix_entry {
  * @keyscan: Current keyscan information (bit set for each row/column pressed)
  * @recovery_req: Keyboard recovery requested
  * @test_flags: Flags that control behaviour for tests
+ * @switches: Current switches value (EC_SWITCH_)
  */
 struct ec_state {
 	u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
@@ -541,6 +542,14 @@ void cros_ec_check_keyboard(struct udevice *dev)
 	}
 }
 
+/* Return the byte of EC switch states */
+static int cros_ec_sandbox_get_switches(struct udevice *dev)
+{
+	struct ec_state *ec = dev_get_priv(dev);
+
+	return ec->test_flags & CROSECT_LID_OPEN ? EC_SWITCH_LID_OPEN : 0;
+}
+
 void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags)
 {
 	struct ec_state *ec = dev_get_priv(dev);
@@ -603,6 +612,7 @@ int cros_ec_probe(struct udevice *dev)
 
 struct dm_cros_ec_ops cros_ec_ops = {
 	.packet = cros_ec_sandbox_packet,
+	.get_switches = cros_ec_sandbox_get_switches,
 };
 
 static const struct udevice_id cros_ec_ids[] = {
diff --git a/include/cros_ec.h b/include/cros_ec.h
index 26e3f3ba0cb..cb91343e3d8 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -279,6 +279,16 @@ struct dm_cros_ec_ops {
 	 * @return number of bytes in response, or -ve on error
 	 */
 	int (*packet)(struct udevice *dev, int out_bytes, int in_bytes);
+
+	/**
+	 * get_switches() - Get value of EC switches
+	 *
+	 * This is currently supported on the LPC EC.
+	 *
+	 * @dev: Device to use
+	 * @return current switches value, or -ENOSYS if not supported
+	 */
+	int (*get_switches)(struct udevice *dev);
 };
 
 #define dm_cros_ec_get_ops(dev) \
@@ -577,4 +587,13 @@ int cros_ec_get_features(struct udevice *dev, u64 *featuresp);
  */
 int cros_ec_check_feature(struct udevice *dev, uint feature);
 
+/**
+ * cros_ec_get_switches() - Get switches value
+ *
+ * @dev: CROS-EC device
+ * @return switches value, or -ENOSYS if not supported, or other -ve value on
+ *	other error
+ */
+int cros_ec_get_switches(struct udevice *dev);
+
 #endif
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
index a1ec9fccf3a..43774400a1e 100644
--- a/test/dm/cros_ec.c
+++ b/test/dm/cros_ec.c
@@ -75,3 +75,29 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT);
+
+static int dm_test_cros_ec_switches(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+	ut_asserteq(0, cros_ec_get_switches(dev));
+
+	/* try the command */
+	console_record_reset();
+	ut_assertok(run_command("crosec switches", 0));
+	ut_assert_console_end();
+
+	/* Open the lid and check the switch changes */
+	sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN);
+	ut_asserteq(EC_SWITCH_LID_OPEN, cros_ec_get_switches(dev));
+
+	/* try the command */
+	console_record_reset();
+	ut_assertok(run_command("crosec switches", 0));
+	ut_assert_nextline("lid open");
+	ut_assert_console_end();
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT);
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 08/10] cros_ec: Show events in human-readable form
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (6 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 07/10] cros_ec: Add support for switches Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 09/10] cros_ec: Allow use with of-platdata Simon Glass
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

Add a command to show the current events as a list of names. This is
easier to decipher than a bit mask.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/cros_ec.c                  | 70 +++++++++++++++++++++++++++++++---
 drivers/misc/cros_ec_sandbox.c | 12 +++++-
 test/dm/cros_ec.c              | 37 ++++++++++++++++++
 3 files changed, 112 insertions(+), 7 deletions(-)

diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c
index a222c75c17c..eb5053d6424 100644
--- a/cmd/cros_ec.c
+++ b/cmd/cros_ec.c
@@ -197,6 +197,66 @@ static int do_show_switches(struct udevice *dev)
 	return 0;
 }
 
+static const char *const event_name[] = {
+	"lid_closed",
+	"lid_open",
+	"power_button",
+	"ac_connected",
+	"ac_disconnected",
+	"battery_low",
+	"battery_critical",
+	"battery",
+	"thermal_threshold",
+	"device",
+	"thermal",
+	"usb_charger",
+	"key_pressed",
+	"interface_ready",
+	"keyboard_recovery",
+	"thermal_shutdown",
+	"battery_shutdown",
+	"throttle_start",
+	"throttle_stop",
+	"hang_detect",
+	"hang_reboot",
+	"pd_mcu",
+	"battery_status",
+	"panic",
+	"keyboard_fastboot",
+	"rtc",
+	"mkbp",
+	"usb_mux",
+	"mode_change",
+	"keyboard_recovery_hw_reinit",
+	"extended",
+	"invalid",
+};
+
+static int do_show_events(struct udevice *dev)
+{
+	u32 events;
+	int ret;
+	uint i;
+
+	ret = cros_ec_get_host_events(dev, &events);
+	if (ret)
+		return ret;
+	printf("%08x\n", events);
+	for (i = 0; i < ARRAY_SIZE(event_name); i++) {
+		enum host_event_code code = i + 1;
+		u64 mask = EC_HOST_EVENT_MASK(code);
+
+		if (events & mask) {
+			if (event_name[i])
+				printf("%s\n", event_name[i]);
+			else
+				printf("unknown code %#x\n", code);
+		}
+	}
+
+	return 0;
+}
+
 static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
@@ -303,13 +363,10 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
 			return 1;
 		}
 	} else if (0 == strcmp("events", cmd)) {
-		uint32_t events;
+		ret = do_show_events(dev);
 
-		if (cros_ec_get_host_events(dev, &events)) {
-			debug("%s: Could not read host events\n", __func__);
-			return 1;
-		}
-		printf("0x%08x\n", events);
+		if (ret)
+			printf("Error: %d\n", ret);
 	} else if (0 == strcmp("clrevents", cmd)) {
 		uint32_t events = 0x7fffffff;
 
@@ -498,6 +555,7 @@ U_BOOT_CMD(
 	"crosec hash                Read CROS-EC hash\n"
 	"crosec reboot [rw | ro | cold]  Reboot CROS-EC\n"
 	"crosec events              Read CROS-EC host events\n"
+	"crosec eventsb             Read CROS-EC host events_b\n"
 	"crosec clrevents [mask]    Clear CROS-EC host events\n"
 	"crosec regioninfo <ro|rw>  Read image info\n"
 	"crosec flashinfo           Read flash info\n"
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 38a2614a993..845876cfb0c 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -364,10 +364,20 @@ static int process_cmd(struct ec_state *ec,
 			resp->mask |= EC_HOST_EVENT_MASK(
 					EC_HOST_EVENT_KEYBOARD_RECOVERY);
 		}
-
+		if (ec->test_flags & CROSECT_LID_OPEN)
+			resp->mask |=
+				EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN);
 		len = sizeof(*resp);
 		break;
 	}
+	case EC_CMD_HOST_EVENT_CLEAR_B: {
+		const struct ec_params_host_event_mask *req = req_data;
+
+		if (req->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN))
+			ec->test_flags &= ~CROSECT_LID_OPEN;
+		len = 0;
+		break;
+		}
 	case EC_CMD_VBOOT_HASH: {
 		const struct ec_params_vboot_hash *req = req_data;
 		struct ec_response_vboot_hash *resp = resp_data;
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
index 43774400a1e..0da7548fd24 100644
--- a/test/dm/cros_ec.c
+++ b/test/dm/cros_ec.c
@@ -101,3 +101,40 @@ static int dm_test_cros_ec_switches(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT);
+
+static int dm_test_cros_ec_events(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	u32 events;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+	ut_assertok(cros_ec_get_host_events(dev, &events));
+	ut_asserteq(0, events);
+
+	/* try the command */
+	console_record_reset();
+	ut_assertok(run_command("crosec events", 0));
+	ut_assert_nextline("00000000");
+	ut_assert_console_end();
+
+	/* Open the lid and check the event appears */
+	sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN);
+	ut_assertok(cros_ec_get_host_events(dev, &events));
+	ut_asserteq(EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN), events);
+
+	/* try the command */
+	console_record_reset();
+	ut_assertok(run_command("crosec events", 0));
+	ut_assert_nextline("00000002");
+	ut_assert_nextline("lid_open");
+	ut_assert_console_end();
+
+	/* Clear the event */
+	ut_assertok(cros_ec_clear_host_events(dev,
+		EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)));
+	ut_assertok(cros_ec_get_host_events(dev, &events));
+	ut_asserteq(0, events);
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_events, UT_TESTF_SCAN_FDT);
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 09/10] cros_ec: Allow use with of-platdata
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (7 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 08/10] cros_ec: Show events in human-readable form Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-16 21:52 ` [PATCH 10/10] cros_ec: Add vstore support Simon Glass
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

Avoid reading the device tree when of-platdata is in use.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 0bc28e882c9..c22bb4b5b50 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1577,6 +1577,8 @@ UCLASS_DRIVER(cros_ec) = {
 	.id		= UCLASS_CROS_EC,
 	.name		= "cros-ec",
 	.per_device_auto	= sizeof(struct cros_ec_dev),
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.post_bind	= dm_scan_fdt_dev,
+#endif
 	.flags		= DM_UC_FLAG_ALLOC_PRIV_DMA,
 };
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 10/10] cros_ec: Add vstore support
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (8 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 09/10] cros_ec: Allow use with of-platdata Simon Glass
@ 2021-01-16 21:52 ` Simon Glass
  2021-01-24 20:23 ` Simon Glass
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-16 21:52 UTC (permalink / raw)
  To: u-boot

The EC can store small amounts of data for the benefit of the
verified boot process. Since the EC is seldom reset, this can allow the
AP to store data that survives a reboot or a suspend/resume cycle.

Add support for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c         | 71 ++++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec_sandbox.c | 52 ++++++++++++++++++++++++-
 include/cros_ec.h              | 43 ++++++++++++++++++++
 test/dm/cros_ec.c              | 38 ++++++++++++++++++
 4 files changed, 202 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index c22bb4b5b50..ebfa7c41c25 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1557,6 +1557,77 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
 	return 0;
 }
 
+int cros_ec_vstore_supported(struct udevice *dev)
+{
+	return cros_ec_check_feature(dev, EC_FEATURE_VSTORE);
+}
+
+int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp)
+{
+	struct ec_response_vstore_info *resp;
+
+	if (ec_command_inptr(dev, EC_CMD_VSTORE_INFO, 0, NULL, 0,
+			     (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+		return -EIO;
+
+	if (lockedp)
+		*lockedp = resp->slot_locked;
+
+	return resp->slot_count;
+}
+
+/*
+ * cros_ec_vstore_read - Read data from EC vstore slot
+ *
+ * @slot: vstore slot to read from
+ * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
+ */
+int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data)
+{
+	struct ec_params_vstore_read req;
+	struct ec_response_vstore_read *resp;
+
+	req.slot = slot;
+	if (ec_command_inptr(dev, EC_CMD_VSTORE_READ, 0, &req, sizeof(req),
+			     (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+		return -EIO;
+
+	if (!data || req.slot >= EC_VSTORE_SLOT_MAX)
+		return -EINVAL;
+
+	memcpy(data, resp->data, sizeof(resp->data));
+
+	return 0;
+}
+
+/*
+ * cros_ec_vstore_write - Save data into EC vstore slot
+ *
+ * @slot: vstore slot to write into
+ * @data: data to write
+ * @size: size of data in bytes
+ *
+ * Maximum size of data is EC_VSTORE_SLOT_SIZE.  It is the callers
+ * responsibility to check the number of implemented slots by
+ * querying the vstore info.
+ */
+int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data,
+			 size_t size)
+{
+	struct ec_params_vstore_write req;
+
+	if (slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE)
+		return -EINVAL;
+
+	req.slot = slot;
+	memcpy(req.data, data, size);
+
+	if (ec_command(dev, EC_CMD_VSTORE_WRITE, 0, &req, sizeof(req), NULL, 0))
+		return -EIO;
+
+	return 0;
+}
+
 int cros_ec_get_switches(struct udevice *dev)
 {
 	struct dm_cros_ec_ops *ops;
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 845876cfb0c..cb8adc4495a 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -62,6 +62,15 @@ struct ec_keymatrix_entry {
 	int keycode;	/* corresponding linux key code */
 };
 
+enum {
+	VSTORE_SLOT_COUNT	= 4,
+};
+
+struct vstore_slot {
+	bool locked;
+	u8 data[EC_VSTORE_SLOT_SIZE];
+};
+
 /**
  * struct ec_state - Information about the EC state
  *
@@ -75,7 +84,7 @@ struct ec_keymatrix_entry {
  * @keyscan: Current keyscan information (bit set for each row/column pressed)
  * @recovery_req: Keyboard recovery requested
  * @test_flags: Flags that control behaviour for tests
- * @switches: Current switches value (EC_SWITCH_)
+ * @slot_locked: Locked vstore slots (mask)
  */
 struct ec_state {
 	u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
@@ -88,6 +97,7 @@ struct ec_state {
 	uint8_t keyscan[KEYBOARD_COLS];
 	bool recovery_req;
 	uint test_flags;
+	struct vstore_slot slot[VSTORE_SLOT_COUNT];
 } s_state, *g_state;
 
 /**
@@ -495,13 +505,51 @@ static int process_cmd(struct ec_state *ec,
 		struct ec_response_get_features *resp = resp_data;
 
 		resp->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FLASH) |
-			EC_FEATURE_MASK_0(EC_FEATURE_I2C);
+			EC_FEATURE_MASK_0(EC_FEATURE_I2C) |
+			EC_FEATURE_MASK_0(EC_FEATURE_VSTORE);
 		resp->flags[1] =
 			EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS) |
 			EC_FEATURE_MASK_1(EC_FEATURE_ISH);
 		len = sizeof(*resp);
 		break;
 	}
+	case EC_CMD_VSTORE_INFO: {
+		struct ec_response_vstore_info *resp = resp_data;
+		int i;
+
+		resp->slot_count = VSTORE_SLOT_COUNT;
+		resp->slot_locked = 0;
+		for (i = 0; i < VSTORE_SLOT_COUNT; i++) {
+			if (ec->slot[i].locked)
+				resp->slot_locked |= 1 << i;
+		}
+		len = sizeof(*resp);
+		break;
+	};
+	case EC_CMD_VSTORE_WRITE: {
+		const struct ec_params_vstore_write *req = req_data;
+		struct vstore_slot *slot;
+
+		if (req->slot >= EC_VSTORE_SLOT_MAX)
+			return -EINVAL;
+		slot = &ec->slot[req->slot];
+		slot->locked = true;
+		memcpy(slot->data, req->data, EC_VSTORE_SLOT_SIZE);
+		len = 0;
+		break;
+	}
+	case EC_CMD_VSTORE_READ: {
+		const struct ec_params_vstore_read *req = req_data;
+		struct ec_response_vstore_read *resp = resp_data;
+		struct vstore_slot *slot;
+
+		if (req->slot >= EC_VSTORE_SLOT_MAX)
+			return -EINVAL;
+		slot = &ec->slot[req->slot];
+		memcpy(resp->data, slot->data, EC_VSTORE_SLOT_SIZE);
+		len = sizeof(*resp);
+		break;
+	}
 	default:
 		printf("   ** Unknown EC command %#02x\n", req_hdr->command);
 		return -1;
diff --git a/include/cros_ec.h b/include/cros_ec.h
index cb91343e3d8..eddc23d48f8 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -596,4 +596,47 @@ int cros_ec_check_feature(struct udevice *dev, uint feature);
  */
 int cros_ec_get_switches(struct udevice *dev);
 
+/**
+ * cros_ec_vstore_supported() - Check if vstore is supported
+ *
+ * @dev: CROS-EC device
+ * @return false if not supported, true if supported, -ve on error
+ */
+int cros_ec_vstore_supported(struct udevice *dev);
+
+/**
+ * cros_ec_vstore_info() - Get vstore information
+ *
+ * @dev: CROS-EC device
+ * @lockedp: mask of locked slots
+ * @return number of vstore slots supported by the EC,, -ve on error
+ */
+int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp);
+
+/**
+ * cros_ec_vstore_read() - Read data from EC vstore slot
+ *
+ * @dev: CROS-EC device
+ * @slot: vstore slot to read from
+ * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data);
+
+/**
+ * cros_ec_vstore_write() - Save data into EC vstore slot
+ *
+ * The maximum size of data is EC_VSTORE_SLOT_SIZE.  It is the caller's
+ * responsibility to check the number of implemented slots by querying the
+ * vstore info.
+ *
+ * @dev: CROS-EC device
+ * @slot: vstore slot to write into
+ * @data: data to write
+ * @size: size of data in bytes
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data,
+			 size_t size);
+
 #endif
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
index 0da7548fd24..30cb70e0882 100644
--- a/test/dm/cros_ec.c
+++ b/test/dm/cros_ec.c
@@ -56,6 +56,7 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts)
 	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
 	ut_assertok(cros_ec_get_features(dev, &feat));
 	ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C |
+		1u << EC_FEATURE_VSTORE |
 		1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH,
 		feat);
 
@@ -68,6 +69,7 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts)
 	ut_assertok(run_command("crosec features", 0));
 	ut_assert_nextline("flash");
 	ut_assert_nextline("i2c");
+	ut_assert_nextline("vstore");
 	ut_assert_nextline("unified_wake_masks");
 	ut_assert_nextline("ish");
 	ut_assert_console_end();
@@ -138,3 +140,39 @@ static int dm_test_cros_ec_events(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_cros_ec_events, UT_TESTF_SCAN_FDT);
+
+static int dm_test_cros_ec_vstore(struct unit_test_state *uts)
+{
+	const int size = EC_VSTORE_SLOT_SIZE;
+	u8 test_data[size], data[size];
+	struct udevice *dev;
+	u32 locked;
+	int i;
+
+	ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+	ut_asserteq(true, cros_ec_vstore_supported(dev));
+
+	ut_asserteq(4, cros_ec_vstore_info(dev, &locked));
+	ut_asserteq(0, locked);
+
+	/* Write some data */
+	for (i = 0; i < size; i++)
+		test_data[i] = ' ' + i;
+	ut_assertok(cros_ec_vstore_write(dev, 2, test_data, size));
+
+	/* Check it is locked */
+	ut_asserteq(4, cros_ec_vstore_info(dev, &locked));
+	ut_asserteq(1 << 2, locked);
+
+	/* Read it back and compare */
+	ut_assertok(cros_ec_vstore_read(dev, 2, data));
+	ut_asserteq_mem(test_data, data, size);
+
+	/* Try another slot to make sure it is empty */
+	ut_assertok(cros_ec_vstore_read(dev, 0, data));
+	for (i = 0; i < size; i++)
+		ut_asserteq(0, data[i]);
+
+	return 0;
+}
+DM_TEST(dm_test_cros_ec_vstore, UT_TESTF_SCAN_FDT);
-- 
2.30.0.284.gd98b1dd5eaa7-goog

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

* [PATCH 10/10] cros_ec: Add vstore support
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (9 preceding siblings ...)
  2021-01-16 21:52 ` [PATCH 10/10] cros_ec: Add vstore support Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 09/10] cros_ec: Allow use with of-platdata Simon Glass
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

The EC can store small amounts of data for the benefit of the
verified boot process. Since the EC is seldom reset, this can allow the
AP to store data that survives a reboot or a suspend/resume cycle.

Add support for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c         | 71 ++++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec_sandbox.c | 52 ++++++++++++++++++++++++-
 include/cros_ec.h              | 43 ++++++++++++++++++++
 test/dm/cros_ec.c              | 38 ++++++++++++++++++
 4 files changed, 202 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

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

* [PATCH 09/10] cros_ec: Allow use with of-platdata
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (10 preceding siblings ...)
  2021-01-24 20:23 ` Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 08/10] cros_ec: Show events in human-readable form Simon Glass
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

Avoid reading the device tree when of-platdata is in use.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH 08/10] cros_ec: Show events in human-readable form
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (11 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 09/10] cros_ec: Allow use with of-platdata Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 07/10] cros_ec: Add support for switches Simon Glass
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

Add a command to show the current events as a list of names. This is
easier to decipher than a bit mask.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/cros_ec.c                  | 70 +++++++++++++++++++++++++++++++---
 drivers/misc/cros_ec_sandbox.c | 12 +++++-
 test/dm/cros_ec.c              | 37 ++++++++++++++++++
 3 files changed, 112 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!

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

* [PATCH 07/10] cros_ec: Add support for switches
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (12 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 08/10] cros_ec: Show events in human-readable form Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Simon Glass
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

On x86 platforms the EC provides a way to read 'switches', which are
on/off values determined by the EC.

Add a new driver method for this and implement it for LPC.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/include/asm/test.h |  1 +
 cmd/cros_ec.c                   | 41 +++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec.c          | 16 +++++++++++++
 drivers/misc/cros_ec_lpc.c      |  7 ++++++
 drivers/misc/cros_ec_sandbox.c  | 10 ++++++++
 include/cros_ec.h               | 19 +++++++++++++++
 test/dm/cros_ec.c               | 26 +++++++++++++++++++++
 7 files changed, 120 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (13 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 07/10] cros_ec: Add support for switches Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 05/10] cros_ec: Support reading EC features Simon Glass
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

Add comments to these methods so it is documented in this central place,
not just in each driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/cros_ec.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH 05/10] cros_ec: Support reading EC features
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (14 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 04/10] cros_ec: Add support for reading the SKU ID Simon Glass
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

The EC can support a variety of features and provides a way to find out
what is available. Add support for this.

Also update the feature list to the lastest available while we are here.
This is at:

   https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/include/ec_commands.h

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/cros_ec.c                  | 74 ++++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec.c         | 26 +++++++++---
 drivers/misc/cros_ec_sandbox.c | 11 +++++
 include/cros_ec.h              | 21 ++++++++++
 include/ec_commands.h          | 45 +++++++++++++++++++--
 test/dm/cros_ec.c              | 28 +++++++++++++
 6 files changed, 195 insertions(+), 10 deletions(-)

Applied to u-boot-dm, thanks!

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

* [PATCH 04/10] cros_ec: Add support for reading the SKU ID
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (15 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 05/10] cros_ec: Support reading EC features Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Simon Glass
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

This allows reading strapping pins attached to the EC. Add an
implementation for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/cros_ec.c                  | 10 ++++++++++
 drivers/misc/cros_ec.c         | 13 +++++++++++++
 drivers/misc/cros_ec_sandbox.c |  7 +++++++
 include/cros_ec.h              |  8 ++++++++
 test/dm/cros_ec.c              | 17 +++++++++++++++++
 5 files changed, 55 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (16 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 04/10] cros_ec: Add support for reading the SKU ID Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 02/10] cros_ec: Tidy up a few delays Simon Glass
  2021-01-24 20:23 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

This should not happen in normal operation, but the EC might have a bug,
so add a run-time check just in case.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH 02/10] cros_ec: Tidy up a few delays
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (17 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  2021-01-24 20:23 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

Allow a longer time for the EC to reboot. Also use a constant for the
hash delay time, so it is clear what it is for.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!

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

* [PATCH 01/10] cros_ec: Add a function for the hello message
  2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
                   ` (18 preceding siblings ...)
  2021-01-24 20:23 ` [PATCH 02/10] cros_ec: Tidy up a few delays Simon Glass
@ 2021-01-24 20:23 ` Simon Glass
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Glass @ 2021-01-24 20:23 UTC (permalink / raw)
  To: u-boot

This is used several times in this file. Put it in a function to avoid
code duplication.

Also add a test for this function. There are no cros_ec tests at present,
so it is time to update the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/include/asm/test.h | 14 ++++++++++
 drivers/misc/cros_ec.c          | 46 ++++++++++++++++++++++-----------
 drivers/misc/cros_ec_sandbox.c  | 12 +++++++++
 include/cros_ec.h               | 11 ++++++++
 test/dm/Makefile                |  1 +
 test/dm/cros_ec.c               | 32 +++++++++++++++++++++++
 6 files changed, 101 insertions(+), 15 deletions(-)
 create mode 100644 test/dm/cros_ec.c

Applied to u-boot-dm, thanks!

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

end of thread, other threads:[~2021-01-24 20:23 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-16 21:52 [PATCH 00/10] cros_ec: Add features required for verified boot Simon Glass
2021-01-16 21:52 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass
2021-01-16 21:52 ` [PATCH 02/10] cros_ec: Tidy up a few delays Simon Glass
2021-01-16 21:52 ` [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Simon Glass
2021-01-16 21:52 ` [PATCH 04/10] cros_ec: Add support for reading the SKU ID Simon Glass
2021-01-16 21:52 ` [PATCH 05/10] cros_ec: Support reading EC features Simon Glass
2021-01-16 21:52 ` [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Simon Glass
2021-01-16 21:52 ` [PATCH 07/10] cros_ec: Add support for switches Simon Glass
2021-01-16 21:52 ` [PATCH 08/10] cros_ec: Show events in human-readable form Simon Glass
2021-01-16 21:52 ` [PATCH 09/10] cros_ec: Allow use with of-platdata Simon Glass
2021-01-16 21:52 ` [PATCH 10/10] cros_ec: Add vstore support Simon Glass
2021-01-24 20:23 ` Simon Glass
2021-01-24 20:23 ` [PATCH 09/10] cros_ec: Allow use with of-platdata Simon Glass
2021-01-24 20:23 ` [PATCH 08/10] cros_ec: Show events in human-readable form Simon Glass
2021-01-24 20:23 ` [PATCH 07/10] cros_ec: Add support for switches Simon Glass
2021-01-24 20:23 ` [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Simon Glass
2021-01-24 20:23 ` [PATCH 05/10] cros_ec: Support reading EC features Simon Glass
2021-01-24 20:23 ` [PATCH 04/10] cros_ec: Add support for reading the SKU ID Simon Glass
2021-01-24 20:23 ` [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Simon Glass
2021-01-24 20:23 ` [PATCH 02/10] cros_ec: Tidy up a few delays Simon Glass
2021-01-24 20:23 ` [PATCH 01/10] cros_ec: Add a function for the hello message Simon Glass

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.