Skip to content

Commit 37ec78f

Browse files
VitekSTkartben
authored andcommitted
drivers: misc: Add nxp,rtxxx-dsp-ctrl
Add the nxp,rtxxx-dsp-ctrl driver. Responsibility of this driver is to load code executed by Xtensa-family cores on NXP i.MX RTxxx microcontrollers and to control their run. Signed-off-by: Vit Stanicek <[email protected]>
1 parent 50e0123 commit 37ec78f

File tree

8 files changed

+265
-0
lines changed

8 files changed

+265
-0
lines changed

drivers/misc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ add_subdirectory_ifdef(CONFIG_DEVMUX devmux)
1111
add_subdirectory_ifdef(CONFIG_NORDIC_VPR_LAUNCHER nordic_vpr_launcher)
1212
add_subdirectory_ifdef(CONFIG_MCUX_FLEXIO mcux_flexio)
1313
add_subdirectory_ifdef(CONFIG_RENESAS_RA_EXTERNAL_INTERRUPT renesas_ra_external_interrupt)
14+
add_subdirectory_ifdef(CONFIG_NXP_RTXXX_DSP_CTRL nxp_rtxxx_dsp_ctrl)
15+
1416
add_subdirectory(coresight)

drivers/misc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ source "drivers/misc/nordic_vpr_launcher/Kconfig"
1616
source "drivers/misc/mcux_flexio/Kconfig"
1717
source "drivers/misc/coresight/Kconfig"
1818
source "drivers/misc/renesas_ra_external_interrupt/Kconfig"
19+
source "drivers/misc/nxp_rtxxx_dsp_ctrl/Kconfig"
1920

2021
endmenu
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/misc/nxp_rtxxx_dsp_ctrl/nxp_rtxxx_dsp_ctrl.h)
5+
6+
zephyr_library()
7+
8+
zephyr_library_sources_ifdef(CONFIG_NXP_RTXXX_DSP_CTRL
9+
nxp_rtxxx_dsp_ctrl.c
10+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config NXP_RTXXX_DSP_CTRL
5+
bool "NXP i.MX RTxxx DSP control"
6+
depends on DT_HAS_NXP_RTXXX_DSP_CTRL_ENABLED
7+
default y
8+
help
9+
Enables a DSP control driver for NXP i.MX RTxxx devices.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT nxp_rtxxx_dsp_ctrl
8+
9+
#include <zephyr/drivers/misc/nxp_rtxxx_dsp_ctrl/nxp_rtxxx_dsp_ctrl.h>
10+
#include <zephyr/dt-bindings/misc/nxp_rtxxx_dsp_ctrl.h>
11+
12+
#include <fsl_device_registers.h>
13+
#include <fsl_dsp.h>
14+
#include <fsl_clock.h>
15+
16+
#include <errno.h>
17+
#include <zephyr/init.h>
18+
#include <zephyr/device.h>
19+
#include <zephyr/devicetree.h>
20+
21+
struct nxp_rtxxx_dsp_ctrl_region {
22+
void *base;
23+
int32_t length;
24+
};
25+
26+
struct nxp_rtxxx_dsp_ctrl_config {
27+
SYSCTL0_Type *sysctl;
28+
struct nxp_rtxxx_dsp_ctrl_region regions[NXP_RTXXX_DSP_REGION_MAX];
29+
};
30+
31+
static void dsp_ctrl_enable(const struct device *dev)
32+
{
33+
SYSCTL0_Type *sysctl = ((struct nxp_rtxxx_dsp_ctrl_config *)dev->config)->sysctl;
34+
35+
sysctl->DSPSTALL = 0;
36+
}
37+
38+
static void dsp_ctrl_disable(const struct device *dev)
39+
{
40+
SYSCTL0_Type *sysctl = ((struct nxp_rtxxx_dsp_ctrl_config *)dev->config)->sysctl;
41+
42+
sysctl->DSPSTALL = 1;
43+
}
44+
45+
static int dsp_ctrl_load_section(const struct device *dev, const void *base, size_t length,
46+
enum nxp_rtxxx_dsp_ctrl_section_type section)
47+
{
48+
if (section >= NXP_RTXXX_DSP_REGION_MAX) {
49+
return -EINVAL;
50+
}
51+
52+
const struct nxp_rtxxx_dsp_ctrl_config *cfg =
53+
(const struct nxp_rtxxx_dsp_ctrl_config *)dev->config;
54+
55+
if (cfg->regions[section].base == NULL) {
56+
return -EINVAL;
57+
}
58+
59+
if (length > cfg->regions[section].length) {
60+
return -ENOMEM;
61+
}
62+
63+
/*
64+
* Custom memcpy implementation is needed because the DSP TCMs can be accessed
65+
* only by 32 bits.
66+
*/
67+
const uint32_t *src = (const uint32_t *)base;
68+
uint32_t *dst = cfg->regions[section].base;
69+
70+
for (size_t remaining = length; remaining > 0; remaining -= sizeof(uint32_t)) {
71+
*dst++ = *src++;
72+
73+
if (remaining < sizeof(uint32_t)) {
74+
break;
75+
}
76+
}
77+
78+
return 0;
79+
}
80+
81+
static int nxp_rtxxx_dsp_ctrl_init(const struct device *dev)
82+
{
83+
/*
84+
* Initialize clocks associated with the DSP.
85+
* Taken from DSP examples for the MIMXRT685-EVK in the MCUXpresso SDK.
86+
*/
87+
CLOCK_InitSysPfd(kCLOCK_Pfd1, 16);
88+
CLOCK_AttachClk(kDSP_PLL_to_DSP_MAIN_CLK);
89+
CLOCK_SetClkDiv(kCLOCK_DivDspCpuClk, 1);
90+
CLOCK_SetClkDiv(kCLOCK_DivDspRamClk, 2);
91+
92+
DSP_Init();
93+
94+
return 0;
95+
}
96+
97+
static struct nxp_rtxxx_dsp_ctrl_api nxp_rtxxx_dsp_ctrl_api = {
98+
.load_section = dsp_ctrl_load_section,
99+
.enable = dsp_ctrl_enable,
100+
.disable = dsp_ctrl_disable
101+
};
102+
103+
#define NXP_RTXXX_DSP_SECTION(child_node_id, n) \
104+
[DT_PROP(child_node_id, type)] = { \
105+
.base = (void *)DT_REG_ADDR(child_node_id), \
106+
.length = DT_REG_SIZE(child_node_id) \
107+
},
108+
109+
#define NXP_RTXXX_DSP_CTRL(n) \
110+
static const struct nxp_rtxxx_dsp_ctrl_config nxp_rtxxx_dsp_ctrl_##n##_config = { \
111+
.sysctl = (SYSCTL0_Type *)DT_REG_ADDR(DT_INST_PHANDLE(n, sysctl)), \
112+
.regions = {DT_INST_FOREACH_CHILD_VARGS(n, NXP_RTXXX_DSP_SECTION, n)}}; \
113+
\
114+
DEVICE_DT_INST_DEFINE(n, nxp_rtxxx_dsp_ctrl_init, NULL, NULL, \
115+
&nxp_rtxxx_dsp_ctrl_##n##_config, PRE_KERNEL_1, \
116+
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &nxp_rtxxx_dsp_ctrl_api);
117+
118+
DT_INST_FOREACH_STATUS_OKAY(NXP_RTXXX_DSP_CTRL);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include: [base.yaml]
5+
6+
compatible: "nxp,rtxxx-dsp-ctrl"
7+
description: NXP i.MX RTxxx DSP control driver
8+
9+
properties:
10+
"#address-cells":
11+
const: 1
12+
"#size-cells":
13+
const: 1
14+
sysctl:
15+
required: true
16+
type: phandle
17+
description: phandle to a SYSCTL node
18+
19+
child-binding:
20+
description: Memory region definition
21+
22+
properties:
23+
reg:
24+
required: true
25+
type: array
26+
description: Base address and length of a memory region
27+
28+
type:
29+
required: true
30+
type: int
31+
description: Memory region type (NXP_RTXXX_DSP_REGION_*)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/device.h>
8+
#include <zephyr/dt-bindings/misc/nxp_rtxxx_dsp_ctrl.h>
9+
10+
#ifndef __NXP_RTXXX_DSP_CTRL_H__
11+
#define __NXP_RTXXX_DSP_CTRL_H__
12+
13+
/**
14+
* @brief Describes an image section type selection.
15+
*/
16+
enum nxp_rtxxx_dsp_ctrl_section_type {
17+
NXP_RTXXX_DSP_CTRL_SECTION_RESET = NXP_RTXXX_DSP_REGION_RESET,
18+
NXP_RTXXX_DSP_CTRL_SECTION_TEXT = NXP_RTXXX_DSP_REGION_TEXT,
19+
NXP_RTXXX_DSP_CTRL_SECTION_DATA = NXP_RTXXX_DSP_REGION_DATA
20+
};
21+
22+
typedef int (*nxp_rtxxx_dsp_ctrl_api_load_section)(
23+
const struct device *,
24+
const void *,
25+
size_t,
26+
enum nxp_rtxxx_dsp_ctrl_section_type
27+
);
28+
typedef void (*nxp_rtxxx_dsp_ctrl_api_enable)(const struct device *dev);
29+
typedef void (*nxp_rtxxx_dsp_ctrl_api_disable)(const struct device *dev);
30+
31+
struct nxp_rtxxx_dsp_ctrl_api {
32+
nxp_rtxxx_dsp_ctrl_api_load_section load_section;
33+
nxp_rtxxx_dsp_ctrl_api_enable enable;
34+
nxp_rtxxx_dsp_ctrl_api_disable disable;
35+
};
36+
37+
/**
38+
* @brief Loads a specified image representing a specified section to a particular region in the
39+
* DSP's memory.
40+
*
41+
* @param dev DSP device
42+
* @param base Base pointer of the image to load
43+
* @param length Length of the image
44+
* @param section Section type which specified image represents
45+
* @return int 0 on success, -EINVAL for invalid parameters, -ENOMEM for image bigger than the
46+
* target region
47+
*/
48+
static inline int nxp_rtxxx_dsp_ctrl_load_section(
49+
const struct device *dev,
50+
const void *base,
51+
size_t length,
52+
enum nxp_rtxxx_dsp_ctrl_section_type section
53+
)
54+
{
55+
return ((struct nxp_rtxxx_dsp_ctrl_api *)dev->api)
56+
->load_section(dev, base, length, section);
57+
}
58+
59+
/**
60+
* @brief Starts (unstalls) the DSP.
61+
*
62+
* @param dev DSP device
63+
*/
64+
static inline void nxp_rtxxx_dsp_ctrl_enable(const struct device *dev)
65+
{
66+
((struct nxp_rtxxx_dsp_ctrl_api *)dev->api)->enable(dev);
67+
}
68+
69+
/**
70+
* @brief Stops (stalls) the DSP.
71+
*
72+
* @param dev DSP device
73+
*/
74+
static inline void nxp_rtxxx_dsp_ctrl_disable(const struct device *dev)
75+
{
76+
((struct nxp_rtxxx_dsp_ctrl_api *)dev->api)->disable(dev);
77+
}
78+
79+
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef __NXP_RTXXX_DSP_CTRL_DT_CONST_H__
8+
#define __NXP_RTXXX_DSP_CTRL_DT_CONST_H__
9+
10+
#define NXP_RTXXX_DSP_REGION_RESET 0
11+
#define NXP_RTXXX_DSP_REGION_TEXT 1
12+
#define NXP_RTXXX_DSP_REGION_DATA 2
13+
#define NXP_RTXXX_DSP_REGION_MAX 3
14+
15+
#endif

0 commit comments

Comments
 (0)