]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cros_ec: Add support for reading the SKU ID
authorSimon Glass <sjg@chromium.org>
Sat, 16 Jan 2021 21:52:25 +0000 (14:52 -0700)
committerSimon Glass <sjg@chromium.org>
Sat, 30 Jan 2021 21:25:41 +0000 (14:25 -0700)
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
drivers/misc/cros_ec.c
drivers/misc/cros_ec_sandbox.c
include/cros_ec.h
test/dm/cros_ec.c

index ce1f59a740c19cd46ec0d76fa0bc02d5f88f894e..4e85e184fee8e0c8c127b4fb3c22bd82d8de179c 100644 (file)
@@ -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"
 );
index e51ac874098433c3507efcff49cb8477e2fdcfee..80709be2f1568d9e6799e3f6ab2439062ae1996e 100644 (file)
@@ -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;
index 1922a9c1b966d2033b11786ce76807739af841ba..932438470480238911cb8c0da338d7b255283a03 100644 (file)
@@ -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;
index f57e0cc45017f6e996c396b0c3e648f635095c1d..1154cdc52b8d9c0f0fa6e3ebec14a61eb1f61a50 100644 (file)
@@ -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.
  *
index 823245ca70b19259439e70ff59c8aae1484e2a53..3d0e5dc08d33757ab29673e232d0e54279d889c8 100644 (file)
@@ -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);