summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-10 16:39:42 -0700
committerVincent Palatin <vpalatin@chromium.org>2012-10-16 09:43:56 -0700
commit14380985e1e6e892876fb3e45f089331dbc24ca0 (patch)
tree932f4fb7b0dd7a40535ca39cd867e08805c599cd
parent7e9fba676508b3b63247171e25de93fd17593445 (diff)
downloadchrome-ec-14380985e1e6e892876fb3e45f089331dbc24ca0.tar.gz
Add host command to get/set TMP006 calibration data
Needed for host-based thermal control and tweaking. BUG=chrome-os-partner:14955 BRANCH=link TEST=manual From a root shell, ectool tmp006cal 0 3.5e-14 -2.8e-5 -5.5e-7 4.5e-9 ectool tmp006cal 2 3.6e-14 -2.9e-5 -5.6e-7 4.6e-9 ectool tmp006cal 0 S0: 3.500000e-14 b0: -2.800000e-05 b1: -5.500000e-07 b2: 4.500000e-09 ectool tmp006cal 2 S0: 3.600000e-14 b0: -2.900000e-05 b1: -5.600000e-07 b2: 4.600000e-09 At the ec console, "t6cal" should show the settings took effect as well. Original-Change-Id: If43b11e1e827483f0a20db1a2e5644f3475fd95e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35215 (cherry picked from commit d1bebbbe66f78d2dcfb9380456a80e7c2f26a662 only the host part of the patch: ectool and ec_commands.h) Change-Id: I78f4649ded835f164c1bf2cf928874dcdbce8f48 Signed-off-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35584 Reviewed-by: Sameer Nanda <snanda@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--include/ec_commands.h26
-rw-r--r--util/ectool.c75
2 files changed, 101 insertions, 0 deletions
diff --git a/include/ec_commands.h b/include/ec_commands.h
index c3d0fa17e2..7e2a99ea84 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -842,6 +842,32 @@ struct ec_response_thermal_get_threshold {
/* Toggle automatic fan control */
#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
+/* Get TMP006 calibration data */
+#define EC_CMD_TMP006_GET_CALIBRATION 0x53
+
+struct ec_params_tmp006_get_calibration {
+ uint8_t index;
+} __packed;
+
+struct ec_response_tmp006_get_calibration {
+ float s0;
+ float b0;
+ float b1;
+ float b2;
+} __packed;
+
+/* Set TMP006 calibration data */
+#define EC_CMD_TMP006_SET_CALIBRATION 0x54
+
+struct ec_params_tmp006_set_calibration {
+ uint8_t index;
+ uint8_t reserved[3]; /* Reserved; set 0 */
+ float s0;
+ float b0;
+ float b1;
+ float b2;
+} __packed;
+
/*****************************************************************************/
/* MKBP - Matrix KeyBoard Protocol */
diff --git a/util/ectool.c b/util/ectool.c
index 531ca31a9e..b7d1ed89fa 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -128,6 +128,8 @@ const char help_str[] =
" Get the threshold temperature value from thermal engine.\n"
" thermalset <sensor_id> <threshold_id> <value>\n"
" Set the threshold temperature value for thermal engine.\n"
+ " tmp006cal <tmp006_index> [<S0> <b0> <b1> <b2>]\n"
+ " Get/set TMP006 calibration\n"
" usbchargemode <port> <mode>\n"
" Set USB charging mode\n"
" version\n"
@@ -2209,6 +2211,78 @@ int cmd_port_80_flood(int argc, char *argv[])
return 0;
}
+int cmd_tmp006cal(int argc, char *argv[])
+{
+ struct ec_params_tmp006_set_calibration p;
+ char *e;
+ int idx;
+ int rv;
+
+ if (argc < 2) {
+ fprintf(stderr, "Must specify tmp006 index.\n");
+ return -1;
+ }
+
+ idx = strtol(argv[1], &e, 0);
+ if ((e && *e) || idx < 0 || idx > 255) {
+ fprintf(stderr, "Bad index.\n");
+ return -1;
+ }
+
+ if (argc == 2) {
+ struct ec_params_tmp006_get_calibration pg;
+ struct ec_response_tmp006_get_calibration r;
+
+ pg.index = idx;
+
+ rv = ec_command(EC_CMD_TMP006_GET_CALIBRATION, 0,
+ &pg, sizeof(pg), &r, sizeof(r));
+ if (rv < 0)
+ return rv;
+
+ printf("S0: %e\n", r.s0);
+ printf("b0: %e\n", r.b0);
+ printf("b1: %e\n", r.b1);
+ printf("b2: %e\n", r.b2);
+ return EC_SUCCESS;
+ }
+
+ if (argc != 6) {
+ fprintf(stderr, "Must specify all calibration params.\n");
+ return -1;
+ }
+
+ memset(&p, 0, sizeof(p));
+ p.index = idx;
+
+ p.s0 = strtod(argv[2], &e);
+ if (e && *e) {
+ fprintf(stderr, "Bad S0.\n");
+ return -1;
+ }
+
+ p.b0 = strtod(argv[3], &e);
+ if (e && *e) {
+ fprintf(stderr, "Bad b0.\n");
+ return -1;
+ }
+
+ p.b1 = strtod(argv[4], &e);
+ if (e && *e) {
+ fprintf(stderr, "Bad b1.\n");
+ return -1;
+ }
+
+ p.b2 = strtod(argv[5], &e);
+ if (e && *e) {
+ fprintf(stderr, "Bad b2.\n");
+ return -1;
+ }
+
+ return ec_command(EC_CMD_TMP006_SET_CALIBRATION, 0,
+ &p, sizeof(p), NULL, 0);
+}
+
struct command {
const char *name;
int (*handler)(int argc, char *argv[]);
@@ -2267,6 +2341,7 @@ const struct command commands[] = {
{"tempsinfo", cmd_temp_sensor_info},
{"thermalget", cmd_thermal_get_threshold},
{"thermalset", cmd_thermal_set_threshold},
+ {"tmp006cal", cmd_tmp006cal},
{"usbchargemode", cmd_usb_charge_set_mode},
{"version", cmd_version},
{"wireless", cmd_wireless},