From feda8a46e7a35d364c2cc5d5146de6ca24fea0e0 Mon Sep 17 00:00:00 2001 From: loganliao Date: Tue, 18 Feb 2020 09:29:18 +0800 Subject: Mushu : Add GPU temperature sensor driver Add GPU temperature sensor driver in driver/temp_sensor for temperature read . BUG=b:148968367 BRANCH=none TEST=make BOARD=mushu Change-Id: Ide1613597dbb3712637649c098a7b804370f5e02 Signed-off-by: loganliao Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2062117 Reviewed-by: Tim Wawrzynczak Reviewed-by: Logan Liao Commit-Queue: Logan Liao Tested-by: Logan Liao --- driver/build.mk | 1 + driver/temp_sensor/amd_r19me4070.c | 76 ++++++++++++++++++++++++++++++++++++++ driver/temp_sensor/amd_r19me4070.h | 20 ++++++++++ include/config.h | 1 + 4 files changed, 98 insertions(+) create mode 100644 driver/temp_sensor/amd_r19me4070.c create mode 100644 driver/temp_sensor/amd_r19me4070.h diff --git a/driver/build.mk b/driver/build.mk index 3950df93f8..fcc8c9334c 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -109,6 +109,7 @@ driver-$(CONFIG_TEMP_SENSOR_TMP112)+=temp_sensor/tmp112.o driver-$(CONFIG_TEMP_SENSOR_TMP411)+=temp_sensor/tmp411.o driver-$(CONFIG_TEMP_SENSOR_TMP432)+=temp_sensor/tmp432.o driver-$(CONFIG_TEMP_SENSOR_TMP468)+=temp_sensor/tmp468.o +driver-$(CONFIG_TEMP_SENSOR_AMD_R19ME4070)+=temp_sensor/amd_r19me4070.o # Touchpads driver-$(CONFIG_TOUCHPAD_GT7288)+=touchpad_gt7288.o diff --git a/driver/temp_sensor/amd_r19me4070.c b/driver/temp_sensor/amd_r19me4070.c new file mode 100644 index 0000000000..5da1129052 --- /dev/null +++ b/driver/temp_sensor/amd_r19me4070.c @@ -0,0 +1,76 @@ +/* Copyright 2020 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. + */ + +/* R19ME4070 temperature sensor module for Chrome EC */ + +#include "chipset.h" +#include "common.h" +#include "console.h" +#include "hooks.h" +#include "i2c.h" +#include "amd_r19me4070.h" + +#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) + +/* GPU I2C address */ +#define GPU_ADDR_FLAGS 0x82 + +/* + * Tell SMBus slave which register to read before GPU read + * temperature, call it "GPU INIT". + */ +#define GPU_INIT_OFFSET 0x01 +#define GPU_TEMPERATURE_OFFSET 0x03 +#define GPU_INIT_WRITE_VALUE 0x0F01665A + +static int initialized; + +static int read_gpu_temp(int *temp) +{ + return i2c_read32(I2C_PORT_GPU, GPU_ADDR_FLAGS, GPU_TEMPERATURE_OFFSET, + temp); +} + +static void gpu_init_temp_sensor(void) +{ + int rv; + + rv = i2c_write32(I2C_PORT_GPU, GPU_ADDR_FLAGS, GPU_INIT_OFFSET, + GPU_INIT_WRITE_VALUE); + if (rv == EC_SUCCESS) { + initialized = 1; + return; + } + CPRINTS("init GPU fail"); +} +DECLARE_HOOK(HOOK_INIT, gpu_init_temp_sensor, HOOK_PRIO_INIT_I2C + 1); + +/* INIT GPU first before read the GPU's die tmeperature. */ +int get_temp_R19ME4070(int idx, int *temp_ptr) +{ + int reg, rv; + + /* if no INIT GPU, must init it first and wait 1 sec. */ + if (!initialized) { + gpu_init_temp_sensor(); + return EC_ERROR_BUSY; + } + rv = read_gpu_temp(®); + if (rv) { + CPRINTS("read GPU Temperature fail"); + return rv; + } + /* + * The register is four bytes, bit[17:9] represents the GPU temperature. + * 0x000 : 0 ゚C + * 0x001 : 1 ゚C + * 0x002 : 2 ゚C + * ... + * 0x1FF : 511 ゚C + */ + *temp_ptr = C_TO_K((reg >> 9) & (0x1ff)); + return EC_SUCCESS; +} diff --git a/driver/temp_sensor/amd_r19me4070.h b/driver/temp_sensor/amd_r19me4070.h new file mode 100644 index 0000000000..d3c7977ba5 --- /dev/null +++ b/driver/temp_sensor/amd_r19me4070.h @@ -0,0 +1,20 @@ +/* Copyright 2020 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. + */ + +/* GPU R19ME4070 configuration */ + +#ifndef __CROS_EC_R19ME4070_H +#define __CROS_EC_R19ME4070_H + +/* GPU features */ +#define R19ME4070_LOCAL 0 + +/* + * get GPU temperature value and move to *tem_ptr + * One second trigger ,Use I2C read GPU's Die temperature. + */ +int get_temp_R19ME4070(int idx, int *temp_ptr); + +#endif /* __CROS_EC_AMD_R19ME4070_H */ diff --git a/include/config.h b/include/config.h index 89b622cd85..85baa50193 100644 --- a/include/config.h +++ b/include/config.h @@ -3420,6 +3420,7 @@ #undef CONFIG_TEMP_SENSOR_TMP432 /* TI TMP432 sensor, on I2C bus */ #undef CONFIG_TEMP_SENSOR_TMP468 /* TI TMP468 sensor, on I2C bus */ #undef CONFIG_TEMP_SENSOR_F75303 /* Fintek F75303 sensor, on I2C bus */ +#undef CONFIG_TEMP_SENSOR_AMD_R19ME4070 /* AMD_R19ME4070 sensor, on I2C bus */ /* Compile common code for thermistor support */ #undef CONFIG_THERMISTOR -- cgit v1.2.1