diff options
author | Vic Yang <victoryang@chromium.org> | 2012-02-24 10:35:36 -0800 |
---|---|---|
committer | Vic Yang <victoryang@chromium.org> | 2012-02-24 13:09:44 -0800 |
commit | 675cddb258a282a41533d6976c799f42485ddcd2 (patch) | |
tree | 5f67d22fcdebcbeef9f4cb5f333a793107a98fc1 | |
parent | c977d241b3aec49fed7ed7344f2ebf6e59885d63 (diff) | |
download | chrome-ec-675cddb258a282a41533d6976c799f42485ddcd2.tar.gz |
Write temperature values to LPC mapped value space.
Add a task to update temperature values in LPC mapped value space every
second. Also modify ectool to read directly from LPC mapped space.
Signed-off-by: Vic Yang <victoryang@chromium.org>
BUG=chrome-os-partner:8065
TEST="ectool temps" gives same result as "temps" from ec console.
Change-Id: Idcdef8d822724f9bd22d7e819c717cba5af5eb77
-rw-r--r-- | common/temp_sensor.c | 19 | ||||
-rw-r--r-- | include/lpc_commands.h | 15 | ||||
-rw-r--r-- | util/ectool.c | 22 |
3 files changed, 49 insertions, 7 deletions
diff --git a/common/temp_sensor.c b/common/temp_sensor.c index cc7dc25599..4d4c54de18 100644 --- a/common/temp_sensor.c +++ b/common/temp_sensor.c @@ -15,6 +15,8 @@ #include "tmp006.h" #include "task.h" #include "chip_temp_sensor.h" +#include "lpc.h" +#include "lpc_commands.h" /* Defined in board_temp_sensor.c. Must be in the same order as * in enum temp_sensor_id. @@ -44,10 +46,27 @@ void poll_all_sensors(void) #endif } + +static void update_lpc_mapped_memory(void) +{ + int i, t; + uint8_t *mapped = lpc_get_memmap_range() + EC_LPC_MEMMAP_TEMP_SENSOR; + + memset(mapped, 0xff, 16); + + for (i = 0; i < TEMP_SENSOR_COUNT && i < 16; ++i) { + t = temp_sensor_read(i); + if (t != -1) + mapped[i] = t - EC_LPC_TEMP_SENSOR_OFFSET; + } +} + + void temp_sensor_task(void) { while (1) { poll_all_sensors(); + update_lpc_mapped_memory(); /* Wait 1s */ task_wait_msg(1000000); } diff --git a/include/lpc_commands.h b/include/lpc_commands.h index 6a2bf099ed..05293ed232 100644 --- a/include/lpc_commands.h +++ b/include/lpc_commands.h @@ -30,6 +30,21 @@ #define EC_LPC_ADDR_MEMMAP 0x900 #define EC_LPC_MEMMAP_SIZE 256 +/* The offset address of each type of data in mapped memory. */ +#define EC_LPC_MEMMAP_TEMP_SENSOR 0x00 +#define EC_LPC_MEMMAP_FAN 0x10 +#define EC_LPC_MEMMAP_BATT_VOLT 0x20 +#define EC_LPC_MEMMAP_BATT_RATE 0x24 +#define EC_LPC_MEMMAP_BATT_CAP 0x28 +#define EC_LPC_MEMMAP_BATT_FLAG 0x2c +#define EC_LPC_MEMMAP_LID 0x30 + +/* The offset of temperature value stored in mapped memory. + * This allows reporting a temperature range of + * 200K to 454K = -73C to 181C. + */ +#define EC_LPC_TEMP_SENSOR_OFFSET 200 + /* LPC command status byte masks */ /* EC is busy processing a command. This covers both bit 0x04, which * is the busy-bit, and 0x02, which is the bit which indicates the diff --git a/util/ectool.c b/util/ectool.c index 5fa124e743..1a4ba232fb 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -117,6 +117,11 @@ int ec_command(int command, const void *indata, int insize, return 0; } +uint8_t read_mapped_mem8(uint8_t offset) +{ + return inb(EC_LPC_ADDR_MEMMAP + offset); +} + void print_help(const char *prog) { @@ -444,8 +449,6 @@ int cmd_serial_test(int argc, char *argv[]) int cmd_temperature(int argc, char *argv[]) { - struct lpc_params_temp_sensor_get_readings p; - struct lpc_response_temp_sensor_get_readings r; int rv; int id; char *e; @@ -461,14 +464,19 @@ int cmd_temperature(int argc, char *argv[]) return -1; } - p.temp_sensor_id = id; + /* Currently we only store up to 16 temperature sensor data in + * mapped memory. */ + if (id >= 16) { + printf("Sensor with ID greater than 16 unsupported.\n"); + return -1; + } + printf("Reading temperature..."); - rv = ec_command(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS, - &p, sizeof(p), &r, sizeof(r)); - if (rv) + rv = read_mapped_mem8(id); + if (rv == 0xff) printf("Error\n"); else - printf("%d\n", r.value); + printf("%d\n", rv + EC_LPC_TEMP_SENSOR_OFFSET); return rv; } |