From 36ac5741398aef1d2d0bea2dc5d15b1764adb185 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Fri, 5 Sep 2025 17:12:44 +0800 Subject: [PATCH 1/4] modules: hal_nxp: Pull in romapi for RT7xx Pull in romapi for RT7xx Signed-off-by: Zhaoxiang Jin --- modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake b/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake index 455c9823b8ad6..b9c52ed300b69 100644 --- a/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake +++ b/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake @@ -260,6 +260,9 @@ if(CONFIG_SOC_SERIES_IMXRT5XX OR CONFIG_SOC_SERIES_IMXRT6XX) endif() if(CONFIG_SOC_SERIES_IMXRT7XX) + if(CONFIG_DT_HAS_NXP_PMC_TMPSNS_ENABLED) + set(CONFIG_MCUX_COMPONENT_driver.romapi ON) + endif() set_variable_ifdef(CONFIG_HWINFO_MCUX_RSTCTL CONFIG_MCUX_COMPONENT_driver.reset) endif() From f4c8e5273391f51b14d2a9daecb790e62a41a921 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Fri, 5 Sep 2025 17:14:15 +0800 Subject: [PATCH 2/4] drivers: sensor: Enable NXP pmc tmpsns driver This commit introduced NXP pmc temperature sensor (pmc-tmpsns) driver. Signed-off-by: Zhaoxiang Jin --- drivers/sensor/nxp/CMakeLists.txt | 1 + drivers/sensor/nxp/Kconfig | 1 + .../sensor/nxp/nxp_pmc_tmpsns/CMakeLists.txt | 5 + drivers/sensor/nxp/nxp_pmc_tmpsns/Kconfig | 21 +++ .../nxp/nxp_pmc_tmpsns/nxp_pmc_tmpsns.c | 141 ++++++++++++++++++ dts/bindings/sensor/nxp,pmc-tmpsns.yaml | 15 ++ 6 files changed, 184 insertions(+) create mode 100644 drivers/sensor/nxp/nxp_pmc_tmpsns/CMakeLists.txt create mode 100644 drivers/sensor/nxp/nxp_pmc_tmpsns/Kconfig create mode 100644 drivers/sensor/nxp/nxp_pmc_tmpsns/nxp_pmc_tmpsns.c create mode 100644 dts/bindings/sensor/nxp,pmc-tmpsns.yaml diff --git a/drivers/sensor/nxp/CMakeLists.txt b/drivers/sensor/nxp/CMakeLists.txt index d124904beac8c..3bafd1d68dc86 100644 --- a/drivers/sensor/nxp/CMakeLists.txt +++ b/drivers/sensor/nxp/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory_ifdef(CONFIG_FXLS8974 fxls8974) add_subdirectory_ifdef(CONFIG_FXOS8700 fxos8700) add_subdirectory_ifdef(CONFIG_LPADC_TEMP40 nxp_lpadc_temp40) add_subdirectory_ifdef(CONFIG_MCUX_LPCMP mcux_lpcmp) +add_subdirectory_ifdef(CONFIG_NXP_PMC_TMPSNS nxp_pmc_tmpsns) add_subdirectory_ifdef(CONFIG_NXP_TEMPMON nxp_tempmon) add_subdirectory_ifdef(CONFIG_NXP_TMPSNS nxp_tmpsns) add_subdirectory_ifdef(CONFIG_P3T1755 p3t1755) diff --git a/drivers/sensor/nxp/Kconfig b/drivers/sensor/nxp/Kconfig index b669accaad933..48553b8266eda 100644 --- a/drivers/sensor/nxp/Kconfig +++ b/drivers/sensor/nxp/Kconfig @@ -9,6 +9,7 @@ source "drivers/sensor/nxp/mcux_acmp/Kconfig" source "drivers/sensor/nxp/mcux_lpcmp/Kconfig" source "drivers/sensor/nxp/nxp_kinetis_temp/Kconfig" source "drivers/sensor/nxp/nxp_lpadc_temp40/Kconfig" +source "drivers/sensor/nxp/nxp_pmc_tmpsns/Kconfig" source "drivers/sensor/nxp/nxp_tempmon/Kconfig" source "drivers/sensor/nxp/nxp_tmpsns/Kconfig" source "drivers/sensor/nxp/p3t1755/Kconfig" diff --git a/drivers/sensor/nxp/nxp_pmc_tmpsns/CMakeLists.txt b/drivers/sensor/nxp/nxp_pmc_tmpsns/CMakeLists.txt new file mode 100644 index 0000000000000..e9adea63cc815 --- /dev/null +++ b/drivers/sensor/nxp/nxp_pmc_tmpsns/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2025 NXP +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources(nxp_pmc_tmpsns.c) diff --git a/drivers/sensor/nxp/nxp_pmc_tmpsns/Kconfig b/drivers/sensor/nxp/nxp_pmc_tmpsns/Kconfig new file mode 100644 index 0000000000000..a5c9d1209e85a --- /dev/null +++ b/drivers/sensor/nxp/nxp_pmc_tmpsns/Kconfig @@ -0,0 +1,21 @@ +# Copyright 2025 NXP +# SPDX-License-Identifier: Apache-2.0 + +config NXP_PMC_TMPSNS + bool "NXP PMC Temperature Sensor (TMPSNS)" + default y + depends on DT_HAS_NXP_PMC_TMPSNS_ENABLED + select FPU if CPU_HAS_FPU + help + Enable driver for the NXP PMC temperature sensor. + This is used to retrieve on-die operational temperature. + +if NXP_PMC_TMPSNS +config NXP_PMC_TMPSNS_CALIBRATION_OTP_FUSE_INDEX + int "OTP FUSE index" + default 77 if SOC_SERIES_IMXRT7XX + help + TSENS_CAL is an 8-bit signed calibration constant + retrieved from non-volatile memory. We need this + index to read the fuse to get TSENS_CAL. +endif diff --git a/drivers/sensor/nxp/nxp_pmc_tmpsns/nxp_pmc_tmpsns.c b/drivers/sensor/nxp/nxp_pmc_tmpsns/nxp_pmc_tmpsns.c new file mode 100644 index 0000000000000..de1e30f1ed98c --- /dev/null +++ b/drivers/sensor/nxp/nxp_pmc_tmpsns/nxp_pmc_tmpsns.c @@ -0,0 +1,141 @@ +/* + * Copyright 2025 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "fsl_romapi_otp.h" +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(nxp_pmc_tmpsns, CONFIG_SENSOR_LOG_LEVEL); + +#define DT_DRV_COMPAT nxp_pmc_tmpsns + +struct nxp_pmc_tmpsns_config { + const struct device *adc; + struct adc_sequence adc_seq; + struct adc_channel_cfg ch_cfg; +}; + +struct nxp_pmc_tmpsns_data { + uint16_t buffer; + uint32_t pmc_tmpsns_calibration; + float pmc_tmpsns_value; +}; + +static int nxp_pmc_tmpsns_sample_fetch(const struct device *dev, enum sensor_channel chan) +{ + uint8_t pmc_tmpsns_select[15] = {0, 1, 3, 2, 6, 7, 5, 4, 5, 7, 6, 2, 3, 1, 0}; + const struct nxp_pmc_tmpsns_config *config = dev->config; + struct nxp_pmc_tmpsns_data *data = dev->data; + uint16_t pmc_tmpsns_value[15] = {0}; + float cm_vref, cm_ctat, cm_temp; + int8_t calibration = 0; + int ret; + + if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_DIE_TEMP) { + return -ENOTSUP; + } + + for (uint8_t index = 0; index < sizeof(pmc_tmpsns_select); ++index) { + PMC0->TSENSOR = PMC_TSENSOR_TSENSM(pmc_tmpsns_select[index]); + + ret = adc_read(config->adc, &config->adc_seq); + if (ret) { + LOG_ERR("Failed to read ADC channels with code %d", ret); + return ret; + } + pmc_tmpsns_value[index] = data->buffer; + } + + cm_ctat = (float)(2 * pmc_tmpsns_value[1] - pmc_tmpsns_value[2] + + 2 * pmc_tmpsns_value[13] - pmc_tmpsns_value[12] + + 2 * pmc_tmpsns_value[6] - pmc_tmpsns_value[5] + + 2 * pmc_tmpsns_value[8] - pmc_tmpsns_value[9]) / 4.0f; + + cm_temp = (float)(2 * pmc_tmpsns_value[0] - pmc_tmpsns_value[3] + + 2 * pmc_tmpsns_value[14] - pmc_tmpsns_value[11] + + 4 * pmc_tmpsns_value[7] - pmc_tmpsns_value[4] - + pmc_tmpsns_value[10]) / 4.0f; + + calibration = (int8_t)(data->pmc_tmpsns_calibration & 0xFF); + + cm_vref = cm_ctat + (953.36f + calibration) * cm_temp / 2048; + + data->pmc_tmpsns_value = 370.98f * (cm_temp / cm_vref) - 273.15f; + + return 0; +} + +static int nxp_pmc_tmpsns_channel_get(const struct device *dev, + enum sensor_channel chan, + struct sensor_value *val) +{ + const struct nxp_pmc_tmpsns_data *data = dev->data; + + if (chan != SENSOR_CHAN_DIE_TEMP) { + return -ENOTSUP; + } + + return sensor_value_from_float(val, data->pmc_tmpsns_value); +} + +static int nxp_pmc_tmpsns_init(const struct device *dev) +{ + const struct nxp_pmc_tmpsns_config *config = dev->config; + struct nxp_pmc_tmpsns_data *data = dev->data; + int ret; + + if (!device_is_ready(config->adc)) { + LOG_ERR("ADC device not ready"); + return -ENODEV; + } + + ret = adc_channel_setup(config->adc, &config->ch_cfg); + if (ret) { + LOG_ERR("Failed to setup ADC channel with code %d", ret); + return ret; + } + + ret = otp_fuse_read(CONFIG_NXP_PMC_TMPSNS_CALIBRATION_OTP_FUSE_INDEX, + &data->pmc_tmpsns_calibration); + if (ret) { + LOG_ERR("Failed to get calibration value form FUSE."); + return -ENOTSUP; + } + + return 0; +} + +static DEVICE_API(sensor, nxp_pmc_tmpsns_api) = { + .sample_fetch = nxp_pmc_tmpsns_sample_fetch, + .channel_get = nxp_pmc_tmpsns_channel_get, +}; + +#define NXP_PMC_TMPSNS_INIT(inst) \ + static struct nxp_pmc_tmpsns_data _CONCAT(nxp_pmc_tmpsns_data, inst); \ + \ + static const struct nxp_pmc_tmpsns_config _CONCAT(nxp_pmc_tmpsns_config, inst) = { \ + .adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \ + .adc_seq = { \ + .channels = BIT(DT_INST_IO_CHANNELS_INPUT(inst)), \ + .buffer = &_CONCAT(nxp_pmc_tmpsns_data, inst).buffer, \ + .buffer_size = sizeof(_CONCAT(nxp_pmc_tmpsns_data, inst)), \ + .resolution = 16, \ + .oversampling = 7, \ + }, \ + .ch_cfg = ADC_CHANNEL_CFG_DT(DT_CHILD(DT_INST_IO_CHANNELS_CTLR(inst), \ + UTIL_CAT(channel_, DT_INST_IO_CHANNELS_INPUT(inst)))), \ + }; \ + \ + SENSOR_DEVICE_DT_INST_DEFINE(inst, nxp_pmc_tmpsns_init, NULL, \ + &_CONCAT(nxp_pmc_tmpsns_data, inst), \ + &_CONCAT(nxp_pmc_tmpsns_config, inst), \ + POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ + &nxp_pmc_tmpsns_api); + +DT_INST_FOREACH_STATUS_OKAY(NXP_PMC_TMPSNS_INIT) diff --git a/dts/bindings/sensor/nxp,pmc-tmpsns.yaml b/dts/bindings/sensor/nxp,pmc-tmpsns.yaml new file mode 100644 index 0000000000000..750e96950fb59 --- /dev/null +++ b/dts/bindings/sensor/nxp,pmc-tmpsns.yaml @@ -0,0 +1,15 @@ +# Copyright NXP 2025 +# SPDX-License-Identifier: Apache-2.0 + +description: NXP PMC temperature sensor (PMC-TMPSNS) + +compatible: "nxp,pmc-tmpsns" + +include: sensor-device.yaml + +properties: + io-channels: + required: true + description: | + This should point to an ADC channel (e.g., <&adc0 0>) + to read from the PMC internal temperature sensor. From 7fb85b259715cc09c6f081265a5746279c096e99 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Tue, 30 Sep 2025 06:12:40 +0800 Subject: [PATCH 3/4] dts: nxp: add pmc-tmpsns to rt7xx dts 1. add pmc-tmpsns to rt7xx dts 2. add pmc-tmpsns to rt700 evk Signed-off-by: Zhaoxiang Jin --- boards/nxp/mimxrt700_evk/board.c | 9 +++++++++ dts/arm/nxp/nxp_rt7xx_cm33_cpu0.dtsi | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/boards/nxp/mimxrt700_evk/board.c b/boards/nxp/mimxrt700_evk/board.c index a4b75c20d55de..07b66dbaf6057 100644 --- a/boards/nxp/mimxrt700_evk/board.c +++ b/boards/nxp/mimxrt700_evk/board.c @@ -8,6 +8,9 @@ #include "fsl_clock.h" #include #include +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pmc_tmpsns)) +#include "fsl_romapi_otp.h" +#endif /*!< System oscillator settling time in us */ #define SYSOSC_SETTLING_US 220U @@ -544,6 +547,12 @@ void board_early_init_hook(void) CLOCK_EnableClock(kCLOCK_Acmp0); RESET_ClearPeripheralReset(kACMP0_RST_SHIFT_RSTn); #endif + +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pmc_tmpsns)) + POWER_DisablePD(kPDRUNCFG_PD_PMC_TEMPSNS); + POWER_ApplyPD(); + otp_init(SystemCoreClock); +#endif } static void GlikeyWriteEnable(GLIKEY_Type *base, uint8_t idx) diff --git a/dts/arm/nxp/nxp_rt7xx_cm33_cpu0.dtsi b/dts/arm/nxp/nxp_rt7xx_cm33_cpu0.dtsi index 451491ce28f24..1c16dcfbd1f45 100644 --- a/dts/arm/nxp/nxp_rt7xx_cm33_cpu0.dtsi +++ b/dts/arm/nxp/nxp_rt7xx_cm33_cpu0.dtsi @@ -9,6 +9,10 @@ #include / { + aliases { + die-temp0 = &pmc_tmpsns; + }; + cpus { #address-cells = <1>; #size-cells = <0>; @@ -1105,6 +1109,11 @@ interrupts = <17 0>; status = "disabled"; }; + + pmc_tmpsns: pmc-tmpsns { + compatible = "nxp,pmc-tmpsns"; + status = "disabled"; + }; }; &xspi0 { From e57e5fd69cb26d3e5910b013df78d84e7561867f Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Fri, 5 Sep 2025 17:17:21 +0800 Subject: [PATCH 4/4] samples: enable rt700 die_temp_polling sample enable rt700 die_temp_polling sample Signed-off-by: Zhaoxiang Jin --- ...mimxrt700_evk_mimxrt798s_cm33_cpu0.overlay | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 samples/sensor/die_temp_polling/boards/mimxrt700_evk_mimxrt798s_cm33_cpu0.overlay diff --git a/samples/sensor/die_temp_polling/boards/mimxrt700_evk_mimxrt798s_cm33_cpu0.overlay b/samples/sensor/die_temp_polling/boards/mimxrt700_evk_mimxrt798s_cm33_cpu0.overlay new file mode 100644 index 0000000000000..afebe0d98a339 --- /dev/null +++ b/samples/sensor/die_temp_polling/boards/mimxrt700_evk_mimxrt798s_cm33_cpu0.overlay @@ -0,0 +1,28 @@ +/* + * Copyright 2025 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +&pmc_tmpsns { + status = "okay"; + io-channels = <&lpadc0 0>; +}; + +&lpadc0 { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_EXTERNAL0"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; + zephyr,input-negative = ; + zephyr,differential; + }; +};