summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-05-08 07:34:00 -0600
committerchrome-bot <chrome-bot@chromium.org>2019-05-16 09:04:34 -0700
commit45434aed20e695e08fcbb3f74c43e03f6fa19bf2 (patch)
tree598942ce75f9d28801d011d0f68a47d59b61ae97 /util
parentf88989e7518b97c83afc93497f97e33d9d4c12f4 (diff)
downloadchrome-ec-45434aed20e695e08fcbb3f74c43e03f6fa19bf2.tar.gz
i2c: add i2clookup host command
Add a new host command that will allow you to lookup a well known device on the EC. This is useful for FAFT tests that want to talk directly with i2c devices but don't know the physical address for each platform. BRANCH=octopus BUG=b:119065537 TEST=Used this with new faft test in CL:1601300 Change-Id: I82c2d5462fcb4edbc92ea60765971190fed7ae81 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1601060 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/ectool.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 21b8d5d51c..570a7bf3ba 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -6144,7 +6144,6 @@ int cmd_i2c_write(int argc, char *argv[])
return 0;
}
-
int cmd_i2c_xfer(int argc, char *argv[])
{
unsigned int port, addr;
@@ -6221,6 +6220,58 @@ int cmd_i2c_xfer(int argc, char *argv[])
return 0;
}
+static void cmd_i2c_lookup_help(const char *const cmd)
+{
+ fprintf(stderr,
+ "Usage: %s <type>\n"
+ " <type> is one of:\n"
+ " 1: CBI_EEPROM\n",
+ cmd);
+}
+
+int cmd_i2c_lookup(int argc, char *argv[])
+{
+ struct ec_params_i2c_lookup p;
+ struct ec_response_i2c_lookup r;
+ char *e;
+ int rv;
+
+ if (argc != 2) {
+ cmd_i2c_lookup_help(argv[0]);
+ return -1;
+ }
+
+ p.type = strtol(argv[1], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad type.\n");
+ cmd_i2c_lookup_help(argv[0]);
+ return -1;
+ }
+
+ rv = ec_command(EC_CMD_I2C_LOOKUP, 0, &p, sizeof(p), &r, sizeof(r));
+
+ if (rv == -EC_RES_INVALID_PARAM - EECRESULT) {
+ fprintf(stderr, "Lookup type %d not supported.\n", p.type);
+ return rv;
+ }
+
+ if (rv == -EC_RES_UNAVAILABLE - EECRESULT) {
+ fprintf(stderr, "Device not found\n");
+ return rv;
+ }
+
+ if (rv < 0)
+ return rv;
+
+ /*
+ * Do not change the format of this print. firmware_ECCbiEeprom FAFT
+ * test depends on this, and will silently start skipping tests.
+ */
+ printf("Port: %d; Address: 0x%02x (7-bit format)\n", r.i2c_port,
+ r.i2c_addr);
+ return 0;
+}
+
int cmd_lcd_backlight(int argc, char *argv[])
{
struct ec_params_switch_enable_backlight p;
@@ -8586,6 +8637,7 @@ const struct command commands[] = {
{"hello", cmd_hello},
{"hibdelay", cmd_hibdelay},
{"hostsleepstate", cmd_hostsleepstate},
+ {"i2clookup", cmd_i2c_lookup},
{"i2cprotect", cmd_i2c_protect},
{"i2cread", cmd_i2c_read},
{"i2cwrite", cmd_i2c_write},