Skip to content

Commit f6d8e3f

Browse files
drivers: dai: Add virtual DAI driver
Introduce a virtual DAI driver for prototyping, loopback, and testing without requiring physical DAI hardware. This includes: - Initial virtual DAI implementation (logging only) - DTS binding (dai-virtual.yaml) - Kconfig and CMake updates - i.MX8M DTS integration Signed-off-by: Suraj Sonawane <[email protected]>
1 parent 04dfa77 commit f6d8e3f

File tree

8 files changed

+159
-0
lines changed

8 files changed

+159
-0
lines changed

drivers/dai/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ add_subdirectory_ifdef(CONFIG_DAI_INTEL_HDA intel/hda)
77
add_subdirectory_ifdef(CONFIG_DAI_NXP_SAI nxp/sai)
88
add_subdirectory_ifdef(CONFIG_DAI_NXP_ESAI nxp/esai)
99
add_subdirectory_ifdef(CONFIG_DAI_NXP_MICFIL nxp/micfil)
10+
add_subdirectory_ifdef(CONFIG_DAI_VIRTUAL virtual)

drivers/dai/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ source "drivers/dai/intel/hda/Kconfig.hda"
3232
source "drivers/dai/nxp/sai/Kconfig.sai"
3333
source "drivers/dai/nxp/esai/Kconfig.esai"
3434
source "drivers/dai/nxp/micfil/Kconfig.micfil"
35+
source "drivers/dai/virtual/Kconfig.virtual"
3536

3637
endif # DAI

drivers/dai/virtual/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Suraj Sonawane <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_library()
5+
zephyr_library_sources_ifdef(CONFIG_DAI_VIRTUAL virtual_dai.c)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025, Suraj Sonawane <[email protected]@gmail.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config DAI_VIRTUAL
5+
bool "Virtual DAI driver support for SOF"
6+
default n
7+
help
8+
Enable support for a Virtual DAI (Digital Audio Interface) in SOF.
9+
This driver is useful for debugging and rapid prototyping without
10+
real hardware. It simulates audio input/output behavior in software
11+
and is useful in memory-to-memory pipelines.

drivers/dai/virtual/virtual_dai.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2025 Suraj Sonawane <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/logging/log.h>
9+
#include <zephyr/drivers/dai.h>
10+
#include <zephyr/pm/device_runtime.h>
11+
#include <string.h>
12+
13+
#define DT_DRV_COMPAT virtual_dai
14+
LOG_MODULE_REGISTER(virtual_dai, CONFIG_DAI_LOG_LEVEL);
15+
16+
struct virtual_dai_data {
17+
struct dai_config cfg;
18+
};
19+
20+
static int virtual_dai_probe(const struct device *dev)
21+
{
22+
LOG_INF("%s", __func__);
23+
return 0;
24+
}
25+
26+
static int virtual_dai_remove(const struct device *dev)
27+
{
28+
LOG_INF("%s", __func__);
29+
return 0;
30+
}
31+
32+
static int virtual_dai_config_set(const struct device *dev,
33+
const struct dai_config *cfg,
34+
const void *bespoke_data)
35+
{
36+
if (cfg->type != DAI_VIRTUAL) {
37+
LOG_ERR("wrong DAI type: %d", cfg->type);
38+
return -EINVAL;
39+
}
40+
41+
LOG_INF("%s", __func__);
42+
return 0;
43+
}
44+
45+
static int virtual_dai_config_get(const struct device *dev,
46+
struct dai_config *cfg,
47+
enum dai_dir dir)
48+
{
49+
LOG_INF("%s", __func__);
50+
struct virtual_dai_data *data = dev->data;
51+
52+
/* dump content of the DAI configuration */
53+
memcpy(cfg, &data->cfg, sizeof(*cfg));
54+
55+
return 0;
56+
}
57+
58+
static const struct dai_properties
59+
*virtual_dai_get_properties(const struct device *dev, enum dai_dir dir, int stream_id)
60+
{
61+
LOG_INF("%s", __func__);
62+
return NULL;
63+
}
64+
65+
static int virtual_dai_trigger(const struct device *dev,
66+
enum dai_dir dir,
67+
enum dai_trigger_cmd cmd)
68+
{
69+
switch (cmd) {
70+
case DAI_TRIGGER_START:
71+
LOG_INF("virtual_dai: START (dir=%d)", dir);
72+
return 0;
73+
case DAI_TRIGGER_STOP:
74+
LOG_INF("virtual_dai: STOP (dir=%d)", dir);
75+
return 0;
76+
case DAI_TRIGGER_PAUSE:
77+
LOG_INF("virtual_dai: PAUSE (dir=%d)", dir);
78+
return 0;
79+
case DAI_TRIGGER_PRE_START:
80+
case DAI_TRIGGER_COPY:
81+
LOG_INF("virtual_dai: DAI_TRIGGER_COPY");
82+
return 0;
83+
default:
84+
LOG_WRN("virtual_dai: Unknown trigger %d", cmd);
85+
return -EINVAL;
86+
}
87+
88+
CODE_UNREACHABLE;
89+
}
90+
91+
static DEVICE_API(dai, virtual_dai_api) = {
92+
.probe = virtual_dai_probe,
93+
.remove = virtual_dai_remove,
94+
.config_set = virtual_dai_config_set,
95+
.config_get = virtual_dai_config_get,
96+
.get_properties = virtual_dai_get_properties,
97+
.trigger = virtual_dai_trigger,
98+
};
99+
100+
static int virtual_dai_init(const struct device *dev)
101+
{
102+
return 0;
103+
}
104+
105+
#define VIRTUAL_DAI_INIT(inst) \
106+
static struct virtual_dai_data virtual_dai_data_##inst = { \
107+
.cfg.type = DAI_VIRTUAL, \
108+
.cfg.dai_index = DT_INST_PROP_OR(inst, dai_index, 0), \
109+
}; \
110+
\
111+
DEVICE_DT_INST_DEFINE(inst, \
112+
&virtual_dai_init, NULL, \
113+
&virtual_dai_data_##inst, NULL, \
114+
POST_KERNEL, CONFIG_DAI_INIT_PRIORITY, \
115+
&virtual_dai_api);
116+
117+
DT_INST_FOREACH_STATUS_OKAY(VIRTUAL_DAI_INIT);

dts/bindings/dai/dai-virtual.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Copyright (c) 2025 Suraj Sonawane <[email protected]>
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: |
6+
Zephyr binding for a Virtual DAI (Digital Audio Interface).
7+
This DAI is not connected to real hardware and is used for software-only
8+
audio routing or testing within SOF + Zephyr systems.
9+
compatible: "virtual_dai"
10+
11+
include: base.yaml
12+
13+
properties:
14+
dai-index:
15+
type: int
16+
description: |
17+
DAI index used to identify this virtual DAI in IPC and topology.

dts/xtensa/nxp/nxp_imx8m.dtsi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@
122122
status = "disabled";
123123
};
124124

125+
virtual_dai: virtual_dai {
126+
compatible = "virtual_dai";
127+
dai-index = <7>;
128+
status = "disabled";
129+
};
130+
125131
iomuxc: iomuxc@30330000 {
126132
compatible = "nxp,imx-iomuxc";
127133
reg = <0x30330000 DT_SIZE_K(64)>;

include/zephyr/drivers/dai.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ enum dai_type {
116116
DAI_INTEL_HDA_NHLT, /**< nhlt Intel HD/A */
117117
DAI_INTEL_ALH_NHLT, /**< nhlt Intel ALH */
118118
DAI_IMX_MICFIL, /**< i.MX PDM MICFIL */
119+
DAI_VIRTUAL, /**< Virtual DAI*/
119120
};
120121

121122
/**

0 commit comments

Comments
 (0)