diff --git a/common/build.mk b/common/build.mk index 6d47f8fcc5..a30288d383 100644 --- a/common/build.mk +++ b/common/build.mk @@ -17,7 +17,7 @@ common-$(CONFIG_FLASH)+=flash_commands.o common-$(CONFIG_PSTORE)+=pstore_commands.o common-$(CONFIG_PWM)+=pwm_commands.o common-$(CONFIG_TASK_THERMAL)+=thermal.o thermal_commands.o -common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o +common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o temp_sensor_commands.o common-$(CONFIG_TMP006)+=tmp006.o common-$(CONFIG_LIGHTBAR)+=leds.o diff --git a/common/temp_sensor_commands.c b/common/temp_sensor_commands.c new file mode 100644 index 0000000000..77114aa727 --- /dev/null +++ b/common/temp_sensor_commands.c @@ -0,0 +1,39 @@ +/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Temperature sensor module for Chrome EC */ +/* This LPC command only serves as a workaround to provide reliable temperature + * reading method until we solve the I2C hanging issue. Remove this when + * possible. */ + +#include "console.h" +#include "host_command.h" +#include "temp_sensor.h" +#include "temp_sensor_commands.h" +#include "lpc_commands.h" +#include "uart.h" +#include "util.h" + + +/*****************************************************************************/ +/* Host commands */ + +enum lpc_status temp_sensor_command_get_readings(uint8_t *data) +{ + struct lpc_params_temp_sensor_get_readings *p = + (struct lpc_params_temp_sensor_get_readings *)data; + struct lpc_response_temp_sensor_get_readings *r = + (struct lpc_response_temp_sensor_get_readings *)data; + + int rv; + rv = temp_sensor_read(p->temp_sensor_id); + if (rv == -1) + return EC_LPC_RESULT_ERROR; + r->value = rv; + + return EC_LPC_RESULT_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS, + temp_sensor_command_get_readings); diff --git a/include/lpc_commands.h b/include/lpc_commands.h index 4e92f9da23..dc92a8de87 100644 --- a/include/lpc_commands.h +++ b/include/lpc_commands.h @@ -422,6 +422,18 @@ struct lpc_response_battery_text { /* Get battery OEM name */ #define EC_LPC_COMMAND_BATTERY_OEM 0x64 +/*****************************************************************************/ +/* Temperature sensor commands */ + +/* Get temperature readings */ +#define EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS 0x70 +struct lpc_params_temp_sensor_get_readings { + uint8_t temp_sensor_id; +} __attribute__ ((packed)); +struct lpc_response_temp_sensor_get_readings { + uint32_t value; +} __attribute__((packed)); + /*****************************************************************************/ /* Host event commands */ diff --git a/include/temp_sensor_commands.h b/include/temp_sensor_commands.h new file mode 100644 index 0000000000..68ecdecfc1 --- /dev/null +++ b/include/temp_sensor_commands.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Temperature sensor commands for Chrome EC */ +/* This LPC command only serves as a workaround to provide reliable temperature + * reading method until we solve the I2C hanging issue. Remove this when + * possible. */ + +#ifndef __CROS_EC_TEMP_SENSOR_COMMANDS_H +#define __CROS_EC_TEMP_SENSOR_COMMANDS_H + +#include "common.h" + +/* Initializes the module. */ +int temp_sensor_commands_init(void); + +/* Host command handlers. */ +enum lpc_status temp_sensor_command_get_readings(uint8_t *data); + +#endif /* __CROS_EC_TEMP_SENSOR_COMMANDS_H */ diff --git a/util/ectool.c b/util/ectool.c index 091bf01fec..a7c7c2cbc6 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -60,6 +60,8 @@ const char help_str[] = " Prints EC version\n" " temps \n" " Print temperature.\n" + " tempread \n" + " Force a read of temperature sensor.\n" " thermalget \n" " Get the threshold temperature value from thermal engine.\n" " thermalset \n" @@ -608,6 +610,41 @@ int cmd_temperature(int argc, char *argv[]) } +int cmd_temperature_read(int argc, char *argv[]) +{ + struct lpc_params_temp_sensor_get_readings p; + struct lpc_response_temp_sensor_get_readings r; + char *e; + int rv; + + if (argc != 1) { + fprintf(stderr, "Usage: tempread "); + return -1; + } + + p.temp_sensor_id = strtol(argv[0], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad sensor ID.\n"); + return -1; + } + + printf("Reading temperature..."); + + rv = ec_command(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS, + &p, sizeof(p), &r, sizeof(r)); + if (rv) + return rv; + + if (r.value < 0) { + printf("Error\n"); + return -1; + } + + printf("%d\n", r.value); + return 0; +} + + int cmd_thermal_get_threshold(int argc, char *argv[]) { struct lpc_params_thermal_get_threshold p; @@ -1176,6 +1213,7 @@ const struct command commands[] = { {"sertest", cmd_serial_test}, {"switches", cmd_switches}, {"temps", cmd_temperature}, + {"tempread", cmd_temperature_read}, {"thermalget", cmd_thermal_get_threshold}, {"thermalset", cmd_thermal_set_threshold}, {"usbchargemode", cmd_usb_charge_set_mode},