mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user