summaryrefslogtreecommitdiff
path: root/driver/temp_sensor
diff options
context:
space:
mode:
Diffstat (limited to 'driver/temp_sensor')
-rw-r--r--driver/temp_sensor/adt7481.c8
-rw-r--r--driver/temp_sensor/g753.c4
-rw-r--r--driver/temp_sensor/g78x.c4
-rw-r--r--driver/temp_sensor/pct2075.c91
-rw-r--r--driver/temp_sensor/pct2075.h70
-rw-r--r--driver/temp_sensor/thermistor.c6
-rw-r--r--driver/temp_sensor/tmp006.c4
-rw-r--r--driver/temp_sensor/tmp112.c6
-rw-r--r--driver/temp_sensor/tmp112.h66
-rw-r--r--driver/temp_sensor/tmp411.c8
-rw-r--r--driver/temp_sensor/tmp432.c12
11 files changed, 189 insertions, 90 deletions
diff --git a/driver/temp_sensor/adt7481.c b/driver/temp_sensor/adt7481.c
index b10404733c..738fdb776a 100644
--- a/driver/temp_sensor/adt7481.c
+++ b/driver/temp_sensor/adt7481.c
@@ -25,8 +25,8 @@ static uint8_t is_sensor_shutdown;
*/
static int has_power(void)
{
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
- return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
+#ifdef CONFIG_TEMP_SENSOR_POWER
+ return gpio_get_level(GPIO_TEMP_SENSOR_POWER);
#else
return !is_sensor_shutdown;
#endif
@@ -340,12 +340,12 @@ DECLARE_CONSOLE_COMMAND(adt7481, command_adt7481,
int adt7481_set_power(enum adt7481_power_state power_on)
{
-#ifndef CONFIG_TEMP_SENSOR_POWER_GPIO
+#ifndef CONFIG_TEMP_SENSOR_POWER
uint8_t shutdown = (power_on == ADT7481_POWER_OFF) ? 1 : 0;
return adt7481_shutdown(shutdown);
#else
- gpio_set_level(CONFIG_TEMP_SENSOR_POWER_GPIO, power_on);
+ gpio_set_level(GPIO_TEMP_SENSOR_POWER, power_on);
return EC_SUCCESS;
#endif
}
diff --git a/driver/temp_sensor/g753.c b/driver/temp_sensor/g753.c
index 857263c161..e3946e4f43 100644
--- a/driver/temp_sensor/g753.c
+++ b/driver/temp_sensor/g753.c
@@ -22,8 +22,8 @@ static int temp_val_local;
*/
static int has_power(void)
{
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
- return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
+#ifdef CONFIG_TEMP_SENSOR_POWER
+ return gpio_get_level(GPIO_TEMP_SENSOR_POWER);
#else
return 1;
#endif
diff --git a/driver/temp_sensor/g78x.c b/driver/temp_sensor/g78x.c
index aef13d3d68..c4fd0ff243 100644
--- a/driver/temp_sensor/g78x.c
+++ b/driver/temp_sensor/g78x.c
@@ -26,8 +26,8 @@ static int temp_val_remote2;
*/
static int has_power(void)
{
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
- return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
+#ifdef CONFIG_TEMP_SENSOR_POWER
+ return gpio_get_level(GPIO_TEMP_SENSOR_POWER);
#else
return 1;
#endif
diff --git a/driver/temp_sensor/pct2075.c b/driver/temp_sensor/pct2075.c
new file mode 100644
index 0000000000..bde1521edc
--- /dev/null
+++ b/driver/temp_sensor/pct2075.c
@@ -0,0 +1,91 @@
+/* Copyright 2021 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.
+ */
+
+/* PCT2075 temperature sensor module for Chrome EC */
+
+#include "common.h"
+#include "console.h"
+#include "pct2075.h"
+#include "i2c.h"
+#include "hooks.h"
+#include "math_util.h"
+#include "util.h"
+
+#define PCT2075_RESOLUTION 11
+#define PCT2075_SHIFT1 (16 - PCT2075_RESOLUTION)
+#define PCT2075_SHIFT2 (PCT2075_RESOLUTION - 8)
+
+#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
+
+static int temp_mk_local[PCT2075_COUNT];
+
+static int raw_read16(int sensor, const int offset, int *data_ptr)
+{
+#ifdef CONFIG_I2C_BUS_MAY_BE_UNPOWERED
+ /*
+ * Don't try to read if the port is unpowered
+ */
+ if (!board_is_i2c_port_powered(pct2075_sensors[sensor].i2c_port))
+ return EC_ERROR_NOT_POWERED;
+#endif
+ return i2c_read16(pct2075_sensors[sensor].i2c_port,
+ pct2075_sensors[sensor].i2c_addr_flags,
+ offset, data_ptr);
+}
+
+static int get_reg_temp(int sensor, int *temp_ptr)
+{
+ int temp_raw = 0;
+
+ RETURN_ERROR(raw_read16(sensor, PCT2075_REG_TEMP, &temp_raw));
+
+ *temp_ptr = (int)(int16_t)temp_raw;
+ return EC_SUCCESS;
+}
+
+static inline int pct2075_reg_to_mk(int16_t reg)
+{
+ int temp_mc;
+
+ temp_mc = (((reg >> PCT2075_SHIFT1) * 1000) >> PCT2075_SHIFT2);
+
+ return MILLI_CELSIUS_TO_MILLI_KELVIN(temp_mc);
+}
+
+int pct2075_get_val_k(int idx, int *temp_k_ptr)
+{
+ if (idx >= PCT2075_COUNT)
+ return EC_ERROR_INVAL;
+
+ *temp_k_ptr = MILLI_KELVIN_TO_KELVIN(temp_mk_local[idx]);
+ return EC_SUCCESS;
+}
+
+int pct2075_get_val_mk(int idx, int *temp_mk_ptr)
+{
+ if (idx >= PCT2075_COUNT)
+ return EC_ERROR_INVAL;
+
+ *temp_mk_ptr = temp_mk_local[idx];
+ return EC_SUCCESS;
+}
+
+static void pct2075_poll(void)
+{
+ int s;
+ int temp_reg = 0;
+
+ for (s = 0; s < PCT2075_COUNT; s++) {
+ if (get_reg_temp(s, &temp_reg) == EC_SUCCESS)
+ temp_mk_local[s] = pct2075_reg_to_mk(temp_reg);
+ }
+}
+DECLARE_HOOK(HOOK_SECOND, pct2075_poll, HOOK_PRIO_TEMP_SENSOR);
+
+void pct2075_init(void)
+{
+/* Incase we need to initialize somthing */
+}
+DECLARE_HOOK(HOOK_INIT, pct2075_init, HOOK_PRIO_DEFAULT);
diff --git a/driver/temp_sensor/pct2075.h b/driver/temp_sensor/pct2075.h
new file mode 100644
index 0000000000..c09d0e383c
--- /dev/null
+++ b/driver/temp_sensor/pct2075.h
@@ -0,0 +1,70 @@
+/* Copyright 2021 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.
+ */
+
+#ifndef __CROS_EC_PCT2075_H
+#define __CROS_EC_PCT2075_H
+
+#include "i2c.h"
+
+#define PCT2075_I2C_ADDR_FLAGS0 (0x48 | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS1 (0x49 | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS2 (0x4A | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS3 (0x4B | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS4 (0x4C | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS5 (0x4D | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS6 (0x4E | I2C_FLAG_BIG_ENDIAN)
+#define PCT2075_I2C_ADDR_FLAGS7 (0x4F | I2C_FLAG_BIG_ENDIAN)
+
+#define PCT2075_REG_TEMP 0x00
+#define PCT2075_REG_CONF 0x01
+#define PCT2075_REG_THYST 0x02
+#define PCT2075_REG_TOS 0x03
+
+/*
+ * I2C port and address information for all the board PCT2075 sensors should be
+ * defined in an array of the following structures, with an enum PCT2075_sensor
+ * indexing the array. The enum PCT2075_sensor shall end with a PCT2075_COUNT
+ * defining the maximum number of sensors for the board.
+ */
+
+struct pct2075_sensor_t {
+ int i2c_port;
+ int i2c_addr_flags;
+};
+
+extern const struct pct2075_sensor_t pct2075_sensors[];
+
+/**
+ * Get the last polled value of a sensor.
+ *
+ * @param idx Index to read, from board's enum PCT2075_sensor
+ * definition
+ *
+ * @param temp_k_ptr Destination for temperature in K.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int pct2075_get_val_k(int idx, int *temp_k_ptr);
+
+/**
+ * Get the last polled value of a sensor.
+ *
+ * @param idx Index to read, from board's enum PCT2075_sensor
+ * definition
+ *
+ * @param temp_mk_ptr Destination for temperature in mK.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int pct2075_get_val_mk(int idx, int *temp_mk_ptr);
+
+/**
+ * Init the sensors. Note, this will run automatically on HOOK_INIT, but is
+ * made available for boards which may not always power the sensor in all
+ * states.
+ */
+void pct2075_init(void);
+
+#endif /* __CROS_EC_PCT2075_H */
diff --git a/driver/temp_sensor/thermistor.c b/driver/temp_sensor/thermistor.c
index ffa780cb07..bef10416b6 100644
--- a/driver/temp_sensor/thermistor.c
+++ b/driver/temp_sensor/thermistor.c
@@ -77,14 +77,14 @@ int thermistor_get_temperature(int idx_adc, int *temp_ptr,
{
int mv;
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
+#ifdef CONFIG_TEMP_SENSOR_POWER
/*
* If the power rail for the thermistor circuit is not enabled, then
* need to ignore any ADC measurments.
*/
- if (!gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO))
+ if (!gpio_get_level(GPIO_TEMP_SENSOR_POWER))
return EC_ERROR_NOT_POWERED;
-#endif /* CONFIG_TEMP_SENSOR_POWER_GPIO */
+#endif /* CONFIG_TEMP_SENSOR_POWER */
mv = adc_read_channel(idx_adc);
if (mv < 0)
return EC_ERROR_UNKNOWN;
diff --git a/driver/temp_sensor/tmp006.c b/driver/temp_sensor/tmp006.c
index 22f4402747..96922c857c 100644
--- a/driver/temp_sensor/tmp006.c
+++ b/driver/temp_sensor/tmp006.c
@@ -75,8 +75,8 @@ static const struct tmp006_data_t tmp006_data_default = {
static int tmp006_has_power(int idx)
{
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
- return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
+#ifdef CONFIG_TEMP_SENSOR_POWER
+ return gpio_get_level(GPIO_TEMP_SENSOR_POWER);
#else
return 1;
#endif
diff --git a/driver/temp_sensor/tmp112.c b/driver/temp_sensor/tmp112.c
index 4da5c4e0e8..6e726a27b9 100644
--- a/driver/temp_sensor/tmp112.c
+++ b/driver/temp_sensor/tmp112.c
@@ -7,12 +7,16 @@
#include "common.h"
#include "console.h"
-#include "tmp112.h"
#include "i2c.h"
#include "hooks.h"
#include "math_util.h"
+#include "temp_sensor/tmp112.h"
#include "util.h"
+#ifdef CONFIG_ZEPHYR
+#include "temp_sensor/temp_sensor.h"
+#endif
+
#define TMP112_RESOLUTION 12
#define TMP112_SHIFT1 (16 - TMP112_RESOLUTION)
#define TMP112_SHIFT2 (TMP112_RESOLUTION - 8)
diff --git a/driver/temp_sensor/tmp112.h b/driver/temp_sensor/tmp112.h
deleted file mode 100644
index d1b97b138c..0000000000
--- a/driver/temp_sensor/tmp112.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* Copyright 2016 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.
- */
-
-#ifndef __CROS_EC_TMP112_H
-#define __CROS_EC_TMP112_H
-
-#include "i2c.h"
-
-#define TMP112_I2C_ADDR_FLAGS0 (0x48 | I2C_FLAG_BIG_ENDIAN)
-#define TMP112_I2C_ADDR_FLAGS1 (0x49 | I2C_FLAG_BIG_ENDIAN)
-#define TMP112_I2C_ADDR_FLAGS2 (0x4A | I2C_FLAG_BIG_ENDIAN)
-#define TMP112_I2C_ADDR_FLAGS3 (0x4B | I2C_FLAG_BIG_ENDIAN)
-
-#define TMP112_REG_TEMP 0x00
-#define TMP112_REG_CONF 0x01
-#define TMP112_REG_HYST 0x02
-#define TMP112_REG_MAX 0x03
-
-/*
- * I2C port and address information for all the board TMP112 sensors should be
- * defined in an array of the following structures, with an enum tmp112_sensor
- * indexing the array. The enum tmp112_sensor shall end with a TMP112_COUNT
- * defining the maximum number of sensors for the board.
- */
-
-struct tmp112_sensor_t {
- int i2c_port;
- int i2c_addr_flags;
-};
-
-extern const struct tmp112_sensor_t tmp112_sensors[];
-
-/**
- * Get the last polled value of a sensor.
- *
- * @param idx Index to read, from board's enum tmp112_sensor
- * definition
- *
- * @param temp_k_ptr Destination for temperature in K.
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int tmp112_get_val_k(int idx, int *temp_k_ptr);
-
-/**
- * Get the last polled value of a sensor.
- *
- * @param idx Index to read, from board's enum tmp112_sensor
- * definition
- *
- * @param temp_mk_ptr Destination for temperature in mK.
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int tmp112_get_val_mk(int idx, int *temp_mk_ptr);
-
-/**
- * Init the sensors. Note, this will run automatically on HOOK_INIT, but is
- * made available for boards which may not always power the sensor in all
- * states.
- */
-void tmp112_init(void);
-
-#endif /* __CROS_EC_TMP112_H */
diff --git a/driver/temp_sensor/tmp411.c b/driver/temp_sensor/tmp411.c
index ee50d0a894..8db3f9a8d8 100644
--- a/driver/temp_sensor/tmp411.c
+++ b/driver/temp_sensor/tmp411.c
@@ -24,8 +24,8 @@ static uint8_t is_sensor_shutdown;
*/
static int has_power(void)
{
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
- return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
+#ifdef CONFIG_TEMP_SENSOR_POWER
+ return gpio_get_level(GPIO_TEMP_SENSOR_POWER);
#else
return !is_sensor_shutdown;
#endif
@@ -318,12 +318,12 @@ DECLARE_CONSOLE_COMMAND(tmp411, command_tmp411,
int tmp411_set_power(enum tmp411_power_state power_on)
{
-#ifndef CONFIG_TEMP_SENSOR_POWER_GPIO
+#ifndef CONFIG_TEMP_SENSOR_POWER
uint8_t shutdown = (power_on == TMP411_POWER_OFF) ? 1 : 0;
return tmp411_shutdown(shutdown);
#else
- gpio_set_level(CONFIG_TEMP_SENSOR_POWER_GPIO, power_on);
+ gpio_set_level(GPIO_TEMP_SENSOR_POWER, power_on);
return EC_SUCCESS;
#endif
}
diff --git a/driver/temp_sensor/tmp432.c b/driver/temp_sensor/tmp432.c
index 4226f51bfd..8db6a99e19 100644
--- a/driver/temp_sensor/tmp432.c
+++ b/driver/temp_sensor/tmp432.c
@@ -16,7 +16,7 @@
static int temp_val_local;
static int temp_val_remote1;
static int temp_val_remote2;
-#ifndef CONFIG_TEMP_SENSOR_POWER_GPIO
+#ifndef CONFIG_TEMP_SENSOR_POWER
static uint8_t is_sensor_shutdown;
#endif
static int fake_temp[TMP432_IDX_COUNT] = {-1, -1, -1};
@@ -28,8 +28,8 @@ static int fake_temp[TMP432_IDX_COUNT] = {-1, -1, -1};
*/
static int has_power(void)
{
-#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
- return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
+#ifdef CONFIG_TEMP_SENSOR_POWER
+ return gpio_get_level(GPIO_TEMP_SENSOR_POWER);
#else
return !is_sensor_shutdown;
#endif
@@ -92,7 +92,7 @@ int tmp432_get_val(int idx, int *temp_ptr)
return EC_SUCCESS;
}
-#ifndef CONFIG_TEMP_SENSOR_POWER_GPIO
+#ifndef CONFIG_TEMP_SENSOR_POWER
static int tmp432_shutdown(uint8_t want_shutdown)
{
int ret, value;
@@ -388,11 +388,11 @@ DECLARE_CONSOLE_COMMAND(tmp432, command_tmp432,
int tmp432_set_power(enum tmp432_power_state power_on)
{
-#ifndef CONFIG_TEMP_SENSOR_POWER_GPIO
+#ifndef CONFIG_TEMP_SENSOR_POWER
uint8_t shutdown = (power_on == TMP432_POWER_OFF) ? 1 : 0;
return tmp432_shutdown(shutdown);
#else
- gpio_set_level(CONFIG_TEMP_SENSOR_POWER_GPIO, power_on);
+ gpio_set_level(GPIO_TEMP_SENSOR_POWER, power_on);
return EC_SUCCESS;
#endif
}