Files
OpenCellular/common/temp_sensor.c
Bill Richardson 754ae5a942 Show the fan-cooling percentage for each active temp sensor
When displaying the temps, if the sensor has valid entries to
control the target fan speed, show them. This lets us see which
sensor is the main player in the cooling needed without doing a
bunch of math.

BUG=none
BRANCH=none
TEST=manual

On the EC console:

> thermalget
sensor  warn  high  halt   fan_off fan_max   name
  0      368   370    372    316     358     PECI
  1        0     0      0      0       0     ECInternal
  2        0     0      0    314     328     I2C-Charger-Die
  3        0     0      0      0       0     I2C-Charger-Object
  4        0     0      0    308     322     I2C-CPU-Die
  5        0     0      0      0       0     I2C-CPU-Object
  6        0     0      0    301     317     I2C-Left C-Die
  7        0     0      0      0       0     I2C-Left C-Object
  8        0     0      0    302     316     I2C-Right C-Die
  9        0     0      0      0       0     I2C-Right C-Object
 10        0     0      0    303     317     I2C-Right D-Die
 11        0     0      0      0       0     I2C-Right D-Object
 12        0     0      0    316     327     I2C-Left D-Die
 13        0     0      0      0       0     I2C-Left D-Object

Then, before this CL:

> temps
  PECI                : 308 K = 35 C
  ECInternal          : 309 K = 36 C
  I2C-Charger-Die     : 307 K = 34 C
  I2C-Charger-Object  : Not calibrated
  I2C-CPU-Die         : 304 K = 31 C
  I2C-CPU-Object      : Not calibrated
  I2C-Left C-Die      : 302 K = 29 C
  I2C-Left C-Object   : Not calibrated
  I2C-Right C-Die     : 303 K = 30 C
  I2C-Right C-Object  : Not calibrated
  I2C-Right D-Die     : 303 K = 30 C
  I2C-Right D-Object  : Not calibrated
  I2C-Left D-Die      : 306 K = 33 C
  I2C-Left D-Object   : Not calibrated

After this CL:

> temps
  PECI                : 308 K = 35 C  0%
  ECInternal          : 309 K = 36 C
  I2C-Charger-Die     : 307 K = 34 C  0%
  I2C-Charger-Object  : Not calibrated
  I2C-CPU-Die         : 304 K = 31 C  0%
  I2C-CPU-Object      : Not calibrated
  I2C-Left C-Die      : 302 K = 29 C  6%
  I2C-Left C-Object   : Not calibrated
  I2C-Right C-Die     : 303 K = 30 C  7%
  I2C-Right C-Object  : Not calibrated
  I2C-Right D-Die     : 303 K = 30 C  0%
  I2C-Right D-Object  : Not calibrated
  I2C-Left D-Die      : 306 K = 33 C  0%
  I2C-Left D-Object   : Not calibrated

Change-Id: I12bca5826e8a5a3325710fa5d39cec88f1cc95b1
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/240517
2015-01-14 03:15:41 +00:00

163 lines
4.1 KiB
C

/* Copyright (c) 2012 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 "common.h"
#include "console.h"
#include "hooks.h"
#include "host_command.h"
#include "task.h"
#include "temp_sensor.h"
#include "thermal.h"
#include "timer.h"
#include "util.h"
int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr)
{
const struct temp_sensor_t *sensor;
if (id < 0 || id >= TEMP_SENSOR_COUNT)
return EC_ERROR_INVAL;
sensor = temp_sensors + id;
return sensor->read(sensor->idx, temp_ptr);
}
static void update_mapped_memory(void)
{
int i, t;
uint8_t *mptr = host_get_memmap(EC_MEMMAP_TEMP_SENSOR);
for (i = 0; i < TEMP_SENSOR_COUNT; i++, mptr++) {
/*
* Switch to second range if first one is full, or stop if
* second range is also full.
*/
if (i == EC_TEMP_SENSOR_ENTRIES)
mptr = host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B);
else if (i >= EC_TEMP_SENSOR_ENTRIES +
EC_TEMP_SENSOR_B_ENTRIES)
break;
switch (temp_sensor_read(i, &t)) {
case EC_ERROR_NOT_POWERED:
*mptr = EC_TEMP_SENSOR_NOT_POWERED;
break;
case EC_ERROR_NOT_CALIBRATED:
*mptr = EC_TEMP_SENSOR_NOT_CALIBRATED;
break;
case EC_SUCCESS:
*mptr = t - EC_TEMP_SENSOR_OFFSET;
break;
default:
*mptr = EC_TEMP_SENSOR_ERROR;
}
}
}
/* Run after other TEMP tasks, so sensors will have updated first. */
DECLARE_HOOK(HOOK_SECOND, update_mapped_memory, HOOK_PRIO_TEMP_SENSOR_DONE);
static void temp_sensor_init(void)
{
int i;
uint8_t *base, *base_b;
/*
* Initialize memory-mapped data so that if a temperature value is read
* before we actually poll the sensors, we don't end up with an insane
* value.
*/
base = host_get_memmap(EC_MEMMAP_TEMP_SENSOR);
base_b = host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B);
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
if (i < EC_TEMP_SENSOR_ENTRIES)
base[i] = EC_TEMP_SENSOR_DEFAULT;
else
base_b[i - EC_TEMP_SENSOR_ENTRIES] =
EC_TEMP_SENSOR_DEFAULT;
}
/* Set the rest of memory region to SENSOR_NOT_PRESENT */
for (; i < EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES; ++i) {
if (i < EC_TEMP_SENSOR_ENTRIES)
base[i] = EC_TEMP_SENSOR_NOT_PRESENT;
else
base_b[i - EC_TEMP_SENSOR_ENTRIES] =
EC_TEMP_SENSOR_NOT_PRESENT;
}
/* Temp sensor data is present, with B range supported. */
*host_get_memmap(EC_MEMMAP_THERMAL_VERSION) = 2;
}
DECLARE_HOOK(HOOK_INIT, temp_sensor_init, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
/* Console commands */
static int command_temps(int argc, char **argv)
{
int t, i;
int rv, rv1 = EC_SUCCESS;
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
ccprintf(" %-20s: ", temp_sensors[i].name);
rv = temp_sensor_read(i, &t);
if (rv)
rv1 = rv;
switch (rv) {
case EC_SUCCESS:
ccprintf("%d K = %d C", t, K_TO_C(t));
if (thermal_params[i].temp_fan_off &&
thermal_params[i].temp_fan_max)
ccprintf(" %d%%",
thermal_fan_percent(
thermal_params[i].temp_fan_off,
thermal_params[i].temp_fan_max,
t));
ccprintf("\n");
break;
case EC_ERROR_NOT_POWERED:
ccprintf("Not powered\n");
break;
case EC_ERROR_NOT_CALIBRATED:
ccprintf("Not calibrated\n");
break;
default:
ccprintf("Error %d\n", rv);
}
}
return rv1;
}
DECLARE_CONSOLE_COMMAND(temps, command_temps,
NULL,
"Print temp sensors",
NULL);
/*****************************************************************************/
/* Host commands */
int temp_sensor_command_get_info(struct host_cmd_handler_args *args)
{
const struct ec_params_temp_sensor_get_info *p = args->params;
struct ec_response_temp_sensor_get_info *r = args->response;
int id = p->id;
if (id >= TEMP_SENSOR_COUNT)
return EC_RES_ERROR;
strzcpy(r->sensor_name, temp_sensors[id].name, sizeof(r->sensor_name));
r->sensor_type = temp_sensors[id].type;
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO,
temp_sensor_command_get_info,
EC_VER_MASK(0));