summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin TerAvest <teravest@chromium.org>2017-11-29 11:36:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-11-30 20:30:18 -0800
commit0a20b1fc84c6e5b956c92d0523db9116dbf19353 (patch)
treec215654efc1c9c1364318f9e8a9491fd7c76d84b
parent55b87f4847394935d05cdefab2dc18dff9d6fa0e (diff)
downloadchrome-ec-0a20b1fc84c6e5b956c92d0523db9116dbf19353.tar.gz
grunt: Add charger and SOC thermal sensors
This change adds support for collecting voltage readings from the two thermistors on the board. The temperature/resistance values for the thermistors came from: https://www.murata.com/en-eu/products/productdata/8796837609502/NTHCG142.txt?1437969863000 TEST=Build BRANCH=None BUG=b:69379715 Change-Id: Ibcb995c2cc17f72bfcd60a355f99607628f61dad Signed-off-by: Justin TerAvest <teravest@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/801213 Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/grunt/board.c54
-rw-r--r--board/grunt/board.h8
2 files changed, 62 insertions, 0 deletions
diff --git a/board/grunt/board.c b/board/grunt/board.c
index 23e8e0dad6..24c3588b9b 100644
--- a/board/grunt/board.c
+++ b/board/grunt/board.c
@@ -5,6 +5,7 @@
/* Grunt board-specific configuration */
+#include "adc.h"
#include "adc_chip.h"
#include "button.h"
#include "charge_manager.h"
@@ -30,6 +31,8 @@
#include "system.h"
#include "task.h"
#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
#include "usb_mux.h"
#include "usb_pd_tcpm.h"
#include "util.h"
@@ -301,3 +304,54 @@ struct keyboard_scan_config keyscan_config = {
0xa4, 0xff, 0xfe, 0x55, 0xfa, 0xca /* full set */
},
};
+
+/*
+ * We use 11 as the scaling factor so that the maximum mV value below (2761)
+ * can be compressed to fit in a uint8_t.
+ */
+#define THERMISTOR_SCALING_FACTOR 11
+
+/*
+ * Values are calculated from the "Resistance VS. Temperature" table on the
+ * Murata page for part NCP15WB473F03RC. Vdd=3.3V, R=30.9Kohm.
+ */
+static const struct thermistor_data_pair thermistor_data[] = {
+ { 2761 / THERMISTOR_SCALING_FACTOR, 0},
+ { 2492 / THERMISTOR_SCALING_FACTOR, 10},
+ { 2167 / THERMISTOR_SCALING_FACTOR, 20},
+ { 1812 / THERMISTOR_SCALING_FACTOR, 30},
+ { 1462 / THERMISTOR_SCALING_FACTOR, 40},
+ { 1146 / THERMISTOR_SCALING_FACTOR, 50},
+ { 878 / THERMISTOR_SCALING_FACTOR, 60},
+ { 665 / THERMISTOR_SCALING_FACTOR, 70},
+ { 500 / THERMISTOR_SCALING_FACTOR, 80},
+ { 434 / THERMISTOR_SCALING_FACTOR, 85},
+ { 376 / THERMISTOR_SCALING_FACTOR, 90},
+ { 326 / THERMISTOR_SCALING_FACTOR, 95},
+ { 283 / THERMISTOR_SCALING_FACTOR, 100}
+};
+
+static const struct thermistor_info thermistor_info = {
+ .scaling_factor = THERMISTOR_SCALING_FACTOR,
+ .num_pairs = ARRAY_SIZE(thermistor_data),
+ .data = thermistor_data,
+};
+
+static int board_get_temp(int idx, int *temp_k)
+{
+ int mv = adc_read_channel(idx ? NPCX_ADC_CH1 : NPCX_ADC_CH0);
+ int temp_c;
+
+ if (mv < 0)
+ return -1;
+
+ temp_c = thermistor_linear_interpolate(mv, &thermistor_info);
+ *temp_k = C_TO_K(temp_c);
+ return 0;
+}
+
+const struct temp_sensor_t temp_sensors[] = {
+ {"Charger", TEMP_SENSOR_TYPE_BOARD, board_get_temp, 0, 1},
+ {"SOC", TEMP_SENSOR_TYPE_BOARD, board_get_temp, 1, 5},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
diff --git a/board/grunt/board.h b/board/grunt/board.h
index 056a5f0b29..67f14a7b6a 100644
--- a/board/grunt/board.h
+++ b/board/grunt/board.h
@@ -27,6 +27,8 @@
#define CONFIG_ADC
#define CONFIG_I2C
#define CONFIG_LPC
+#define CONFIG_TEMP_SENSOR
+#define CONFIG_THERMISTOR_NCP15WB
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_ODL
@@ -144,6 +146,12 @@ enum power_signal {
POWER_SIGNAL_COUNT
};
+enum temp_sensor_id {
+ TEMP_SENSOR_CHARGER = 0,
+ TEMP_SENSOR_SOC,
+ TEMP_SENSOR_COUNT
+};
+
void board_reset_pd_mcu(void);
void board_tcpc_init(void);