summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2014-03-07 10:27:28 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-03-07 20:33:31 +0000
commitc42bf9940282bd9d92187b69a81b6ff2f012c1e2 (patch)
treec4bd38f126d548ab55ef83d9d20ce92f9b595215
parentada635006d80064aa9aa2706838eb16d81832cd8 (diff)
downloadchrome-ec-c42bf9940282bd9d92187b69a81b6ff2f012c1e2.tar.gz
samus: Add host command to read raw tmp006 data
This is needed to calibrate the tmp006 remote sensor values. BUG=chrome-os-partner:26581 BRANCH=none TEST='ectool tmp006raw N' works for N=0,1,2,3 And fails with invalid param for N=4. Data matches result of tmp006 ec console command. Change-Id: I04ec093c7727b55caca7d02baaf373d1ff234731 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/189207 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--driver/temp_sensor/tmp006.c22
-rw-r--r--include/ec_commands.h12
-rw-r--r--util/ectool.c33
3 files changed, 67 insertions, 0 deletions
diff --git a/driver/temp_sensor/tmp006.c b/driver/temp_sensor/tmp006.c
index 7400beecf4..1299d5192b 100644
--- a/driver/temp_sensor/tmp006.c
+++ b/driver/temp_sensor/tmp006.c
@@ -324,6 +324,28 @@ DECLARE_HOST_COMMAND(EC_CMD_TMP006_SET_CALIBRATION,
tmp006_set_calibration,
EC_VER_MASK(0));
+int tmp006_get_raw(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_tmp006_get_raw *p = args->params;
+ struct ec_response_tmp006_get_raw *r = args->response;
+ const struct tmp006_data_t *tdata;
+
+ if (p->index >= TMP006_COUNT)
+ return EC_RES_INVALID_PARAM;
+
+ tdata = tmp006_data + p->index;
+
+ r->v = tdata->v;
+ r->t = tdata->t[(tdata->tidx - 1) & 0x3];
+
+ args->response_size = sizeof(*r);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_TMP006_GET_RAW,
+ tmp006_get_raw,
+ EC_VER_MASK(0));
+
/*****************************************************************************/
/* Console commands */
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 1913361250..14efc3eb68 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1323,6 +1323,18 @@ struct ec_params_tmp006_set_calibration {
float b2;
} __packed;
+/* Read raw TMP006 data */
+#define EC_CMD_TMP006_GET_RAW 0x55
+
+struct ec_params_tmp006_get_raw {
+ uint8_t index;
+} __packed;
+
+struct ec_response_tmp006_get_raw {
+ int32_t t; /* In 1/100 K */
+ int32_t v; /* In nV */
+};
+
/*****************************************************************************/
/* MKBP - Matrix KeyBoard Protocol */
diff --git a/util/ectool.c b/util/ectool.c
index 18a498b8d3..abe05e7dcb 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -152,6 +152,8 @@ const char help_str[] =
" Set the threshold temperature values for the thermal engine.\n"
" tmp006cal <tmp006_index> [<S0> <b0> <b1> <b2>]\n"
" Get/set TMP006 calibration\n"
+ " tmp006raw <tmp006_index>\n"
+ " Get raw TMP006 data\n"
" usbchargemode <port> <mode>\n"
" Set USB charging mode\n"
" usbmux <mux>\n"
@@ -3444,6 +3446,36 @@ int cmd_tmp006cal(int argc, char *argv[])
&p, sizeof(p), NULL, 0);
}
+int cmd_tmp006raw(int argc, char *argv[])
+{
+ struct ec_params_tmp006_get_raw p;
+ struct ec_response_tmp006_get_raw r;
+ 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;
+ }
+
+ p.index = idx;
+
+ rv = ec_command(EC_CMD_TMP006_GET_RAW, 0, &p, sizeof(p), &r, sizeof(r));
+ if (rv < 0)
+ return rv;
+
+ printf("T: %d.%02d K\n", r.t / 100, r.t % 100);
+ printf("V: %d nV\n", r.v);
+ return EC_SUCCESS;
+}
+
static int cmd_hang_detect(int argc, char *argv[])
{
struct ec_params_hang_detect req;
@@ -3569,6 +3601,7 @@ const struct command commands[] = {
{"thermalget", cmd_thermal_get_threshold},
{"thermalset", cmd_thermal_set_threshold},
{"tmp006cal", cmd_tmp006cal},
+ {"tmp006raw", cmd_tmp006raw},
{"usbchargemode", cmd_usb_charge_set_mode},
{"usbmux", cmd_usb_mux},
{"version", cmd_version},