Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: sensor: temperature: Add i.MX RT die temperature sensor #83880

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/sensor/nxp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_subdirectory_ifdef(CONFIG_FXLS8974 fxls8974)
add_subdirectory_ifdef(CONFIG_FXOS8700 fxos8700)
add_subdirectory_ifdef(CONFIG_MCUX_LPCMP mcux_lpcmp)
add_subdirectory_ifdef(CONFIG_NXP_TEMPMON nxp_tempmon)
add_subdirectory_ifdef(CONFIG_NXP_TMPSNS nxp_tmpsns)
add_subdirectory_ifdef(CONFIG_P3T1755 p3t1755)
add_subdirectory_ifdef(CONFIG_QDEC_MCUX qdec_mcux)
add_subdirectory_ifdef(CONFIG_QDEC_NXP_S32 qdec_nxp_s32)
Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/nxp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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_tempmon/Kconfig"
source "drivers/sensor/nxp/nxp_tmpsns/Kconfig"
source "drivers/sensor/nxp/p3t1755/Kconfig"
source "drivers/sensor/nxp/qdec_mcux/Kconfig"
source "drivers/sensor/nxp/qdec_nxp_s32/Kconfig"
Expand Down
3 changes: 3 additions & 0 deletions drivers/sensor/nxp/nxp_tmpsns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zephyr_library()

zephyr_library_sources(nxp_tmpsns.c)
13 changes: 13 additions & 0 deletions drivers/sensor/nxp/nxp_tmpsns/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# NXP i.MX RT temperature sensor configuration options

# Copyright (c) 2025 Polytech A/S
# SPDX-License-Identifier: Apache-2.0

config NXP_TMPSNS
bool "NXP TMPSNS sensor"
depends on SENSOR
depends on DT_HAS_NXP_TMPSNS_ENABLED
depends on SOC_SERIES_IMXRT11XX || SOC_SERIES_IMXRT118X
default y
help
Enable temperature measurement for NXP TMPSNS sensor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Enable temperature measurement for NXP TMPSNS sensor
Enable temperature measurement for NXP TMPSNS sensor

68 changes: 68 additions & 0 deletions drivers/sensor/nxp/nxp_tmpsns/nxp_tmpsns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2025 Polytech A/S
*
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT nxp_tmpsns

#include <fsl_tempsensor.h>
#include <zephyr/drivers/sensor.h>

struct nxp_tmpsns_data {
float die_temp;
};

static int nxp_tmpsns_channel_get(const struct device *dev, enum sensor_channel chan,
struct sensor_value *val)
{
const struct nxp_tmpsns_data *data = dev->data;

switch (chan) {
case SENSOR_CHAN_ALL:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line.
get cannot support SENSOR_CHAN_ALL since there is only one val reference.

case SENSOR_CHAN_DIE_TEMP:
return sensor_value_from_float(val, data->die_temp);
default:
return -ENOTSUP;
}
}

static int nxp_tmpsns_channel_fetch(const struct device *dev, enum sensor_channel chan)
{
struct nxp_tmpsns_data *data = dev->data;

switch (chan) {
case SENSOR_CHAN_ALL:
case SENSOR_CHAN_DIE_TEMP:
data->die_temp = TMPSNS_GetCurrentTemperature(TMPSNS);
return 0;
default:
return -ENOTSUP;
}
}

static const struct sensor_driver_api tmpsns_driver_api = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static const struct sensor_driver_api tmpsns_driver_api = {
static DEVICE_API(sensor, tmpsns_driver_api) = {

.channel_get = nxp_tmpsns_channel_get,
.sample_fetch = nxp_tmpsns_channel_fetch,
};

static int nxp_tmpsns_init(const struct device *dev)
{
tmpsns_config_t config;

TMPSNS_GetDefaultConfig(&config);
config.measureMode = kTEMPSENSOR_ContinuousMode;
config.frequency = 0x03U;
TMPSNS_Init(TMPSNS, &config);
TMPSNS_StartMeasure(TMPSNS);

return 0;
}

#define NXP_TMPSNS_DEFINE(inst) \
struct nxp_tmpsns_data nxp_tmpsns_data_##inst; \
SENSOR_DEVICE_DT_INST_DEFINE(inst, nxp_tmpsns_init, NULL, &nxp_tmpsns_data_##inst, NULL, \
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \
&tmpsns_driver_api);

DT_INST_FOREACH_STATUS_OKAY(NXP_TMPSNS_DEFINE)
7 changes: 7 additions & 0 deletions dts/arm/nxp/nxp_rt118x.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
};
};
};

soc {
temp: temp {
compatible = "nxp,tmpsns";
status = "disabled";
};
};
};

&peripheral {
Expand Down
5 changes: 5 additions & 0 deletions dts/arm/nxp/nxp_rt11xx.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,11 @@
status = "disabled";
};
};

temp: temp {
compatible = "nxp,tmpsns";
status = "disabled";
};
};
};

Expand Down