Add host command to read temperature sensor value

Add a LPC host command to read temperature sensor value with given
sensor id.
Add ectool command to read temperature sensor value through LPC.

BUG=chrome-os-partner:7329
TEST=Manual check the reading received is the same as value printed by
console command.

Change-Id: Id3386774435be6c3ae010a143f4fa894568efdb8
This commit is contained in:
Vic Yang
2011-12-21 17:03:43 +08:00
parent 84a286b1f4
commit b228bc14c0
6 changed files with 100 additions and 1 deletions

View File

@@ -4,4 +4,4 @@
common-objs=main.o util.o console.o vboot.o
common-objs+=flash_commands.o host_command.o port80.o keyboard.o i8042.o
common-objs+=memory_commands.o shared_mem.o
common-objs+=memory_commands.o shared_mem.o temp_sensor_commands.o

View File

@@ -9,6 +9,7 @@
#include "console.h"
#include "flash_commands.h"
#include "host_command.h"
#include "temp_sensor_commands.h"
#include "lpc.h"
#include "lpc_commands.h"
#include "system.h"
@@ -172,6 +173,9 @@ static void command_process(int slot)
lpc_send_host_response(slot, flash_command_checksum(data));
return;
#endif
case EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS:
lpc_send_host_response(slot, temp_sensor_command_get_readings(data));
return;
default:
lpc_send_host_response(slot, EC_LPC_STATUS_INVALID_COMMAND);
}

View File

@@ -0,0 +1,33 @@
/* 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 */
#include "console.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_STATUS_ERROR;
r->value = rv;
return EC_LPC_STATUS_SUCCESS;
}

View File

@@ -205,4 +205,16 @@ struct lpc_response_flash_checksum {
#endif /* SUPPORT_CHECKSUM */
/*****************************************************************************/
/* Temperature sensor commands */
/* Get temperature readings */
#define EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS 0x30
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));
#endif /* __CROS_EC_LPC_COMMANDS_H */

View File

@@ -0,0 +1,19 @@
/* 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 */
#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 */

View File

@@ -10,6 +10,7 @@
#include <unistd.h>
#include "lpc_commands.h"
#include "temp_sensor.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/* Don't use a macro where an inline will do... */
@@ -34,6 +35,8 @@ const char help_str[] =
" Serial output test for COM2\n"
" version\n"
" Prints EC version\n"
" temps\n"
" Print temperature\n"
"\n"
"Not working for you? Make sure LPC I/O is configured:\n"
" pci_write32 0 0x1f 0 0x88 0x007c0801\n"
@@ -430,6 +433,32 @@ int cmd_serial_test(int argc, char *argv[])
return 0;
}
int get_temperature(int sensor_id, const char* name)
{
struct lpc_params_temp_sensor_get_readings p;
struct lpc_response_temp_sensor_get_readings r;
int rv;
p.temp_sensor_id = sensor_id;
printf("Reading %s...", name);
rv = ec_command(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS, &p, sizeof(p), &r, sizeof(r));
if (rv)
printf("Error\n");
else
printf("%d\n", r.value);
return rv;
}
int cmd_temperature(void)
{
int rv1, rv2, rv3;
rv1 = get_temperature(TEMP_SENSOR_CASE, "TEMP_SENSOR_CASE");
rv2 = get_temperature(TEMP_SENSOR_CASE_DIE, "TEMP_SENSOR_CASE_DIE");
rv3 = get_temperature(TEMP_SENSOR_EC_INTERNAL, "TEMP_SENSOR_EC_INTERNAL");
if (rv1 || rv2 || rv3)
return -1;
return 0;
}
int main(int argc, char *argv[])
{
@@ -462,6 +491,8 @@ int main(int argc, char *argv[])
return cmd_serial_test(argc - 2, argv + 2);
if (!strcasecmp(argv[1], "version"))
return cmd_version();
if (!strcasecmp(argv[1], "temps"))
return cmd_temperature();
/* If we're still here, command was unknown */
fprintf(stderr, "Unknown command '%s'\n\n", argv[1]);