diff options
author | Simon Glass <sjg@chromium.org> | 2021-01-16 14:52:28 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-01-30 14:25:41 -0700 |
commit | 3a6c994f3896d66e617acdf9bb58ffc4def08b71 (patch) | |
tree | d8b222358a56ab098e8a66a3f09a5b2b0d0066ee /cmd | |
parent | 2b4b65339110e11b4a859fceeb1eec82b2ebb5f1 (diff) | |
download | u-boot-3a6c994f3896d66e617acdf9bb58ffc4def08b71.zip u-boot-3a6c994f3896d66e617acdf9bb58ffc4def08b71.tar.gz u-boot-3a6c994f3896d66e617acdf9bb58ffc4def08b71.tar.bz2 |
cros_ec: Add support for switches
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>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/cros_ec.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index 77656a2..a222c75 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[]) { @@ -213,6 +248,11 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, 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)) { enum ec_current_image image; @@ -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" |