summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammed Habibulla <moch@chromium.org>2014-10-07 14:42:26 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-10 18:47:43 +0000
commitebfed795adc6395c662c877c7a31099b6f8f1fc6 (patch)
treea3a2089ac80b8894c3e658026ca7f6ef10d1f55c
parent39117d8eabe8f6bf45f510c595ef1cbc6db6c2bc (diff)
downloadchrome-ec-ebfed795adc6395c662c877c7a31099b6f8f1fc6.tar.gz
CHERRY-PICK: ectool: replace thermal_threshold_version with ec_cmd_version_supported
BUG=none TEST='ectool thermalget' works as expected BRANCH=none Change-Id: I31cd96996c1027308557285c4aa27419185dd2cd Original-Change-Id: Ie225ef0aaeae913162e8cd6c56193dedd9f56f2f Signed-off-by: Mohammed Habibulla <moch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/221745 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/222872
-rw-r--r--util/ectool.c70
1 files changed, 12 insertions, 58 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 314cb5aa44..123825e6da 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1323,72 +1323,26 @@ int cmd_thermal_set_threshold_v1(int argc, char *argv[])
return rv;
}
-/**
- * Detect the version of EC_CMD_THERMAL_GET_THRESHOLD that the EC supports.
- *
- * @return The version, or -1 if error.
- */
-static int thermal_threshold_version(void)
-{
- struct ec_params_thermal_get_threshold v0_p;
- struct ec_response_thermal_get_threshold v0_r;
- struct ec_params_thermal_get_threshold_v1 v1_p;
- struct ec_thermal_config v1_r;
- int rv;
-
- v1_p.sensor_num = 0;
- rv = ec_command(EC_CMD_THERMAL_GET_THRESHOLD, 1,
- &v1_p, sizeof(v1_p), &v1_r, sizeof(v1_r));
-
- /*
- * TODO(crosbug.com/p/23828): Version 1 of the threshold command will
- * only return EC_RES_SUCCESS or EC_RES_INVALID_PARAM?
- */
- if (rv > 0)
- return 1;
-
- v0_p.sensor_type = 0;
- v0_p.threshold_id = 0;
- rv = ec_command(EC_CMD_THERMAL_GET_THRESHOLD, 0,
- &v0_p, sizeof(v0_p), &v0_r, sizeof(v0_r));
- /*
- * TODO(crosbug.com/p/23828): Version 0 of the threshold command will
- * only return EC_RES_SUCCESS or EC_RES_ERROR?
- */
- if (rv > 0)
- return 0;
-
- /*
- * Anything else is most likely EC_RES_INVALID_COMMAND, but we don't
- * care because it's nothing we can use.
- */
- return -1;
-}
-
int cmd_thermal_get_threshold(int argc, char *argv[])
{
- switch (thermal_threshold_version()) {
- case 0:
- return cmd_thermal_get_threshold_v0(argc, argv);
- case 1:
+ if (ec_cmd_version_supported(EC_CMD_THERMAL_GET_THRESHOLD, 1))
return cmd_thermal_get_threshold_v1(argc, argv);
- default:
- printf("I got nuthin.\n");
- return -1;
- }
+ else if (ec_cmd_version_supported(EC_CMD_THERMAL_GET_THRESHOLD, 0))
+ return cmd_thermal_get_threshold_v0(argc, argv);
+
+ printf("I got nuthin.\n");
+ return -1;
}
int cmd_thermal_set_threshold(int argc, char *argv[])
{
- switch (thermal_threshold_version()) {
- case 0:
- return cmd_thermal_set_threshold_v0(argc, argv);
- case 1:
+ if (ec_cmd_version_supported(EC_CMD_THERMAL_SET_THRESHOLD, 1))
return cmd_thermal_set_threshold_v1(argc, argv);
- default:
- printf("I got nuthin.\n");
- return -1;
- }
+ else if (ec_cmd_version_supported(EC_CMD_THERMAL_SET_THRESHOLD, 0))
+ return cmd_thermal_set_threshold_v0(argc, argv);
+
+ printf("I got nuthin.\n");
+ return -1;
}