Skip to content

Commit 2a3c05f

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 2a3c05f

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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"
6+
help
7+
Select this to enable support for a Virtual DAI driver.
8+
This driver is useful for debugging and rapid prototyping without
9+
real hardware. It simulates audio input/output behavior in software
10+
and is useful in memory-to-memory pipelines.

drivers/dai/virtual/virtual_dai.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
return 0;
23+
}
24+
25+
static int virtual_dai_remove(const struct device *dev)
26+
{
27+
return 0;
28+
}
29+
30+
static int virtual_dai_config_set(const struct device *dev,
31+
const struct dai_config *cfg,
32+
const void *bespoke_data)
33+
{
34+
if (cfg->type != DAI_VIRTUAL) {
35+
LOG_ERR("wrong DAI type: %d", cfg->type);
36+
return -EINVAL;
37+
}
38+
39+
return 0;
40+
}
41+
42+
static int virtual_dai_config_get(const struct device *dev,
43+
struct dai_config *cfg,
44+
enum dai_dir dir)
45+
{
46+
struct virtual_dai_data *data = dev->data;
47+
48+
/* dump content of the DAI configuration */
49+
memcpy(cfg, &data->cfg, sizeof(*cfg));
50+
51+
return 0;
52+
}
53+
54+
static const struct dai_properties *
55+
virtual_dai_get_properties(const struct device *dev, enum dai_dir dir, int stream_id)
56+
{
57+
return NULL;
58+
}
59+
60+
static int virtual_dai_trigger(const struct device *dev,
61+
enum dai_dir dir,
62+
enum dai_trigger_cmd cmd)
63+
{
64+
switch (cmd) {
65+
case DAI_TRIGGER_START:
66+
LOG_DBG("virtual_dai: START (dir=%d)", dir);
67+
return 0;
68+
case DAI_TRIGGER_STOP:
69+
LOG_DBG("virtual_dai: STOP (dir=%d)", dir);
70+
return 0;
71+
case DAI_TRIGGER_PAUSE:
72+
LOG_DBG("virtual_dai: PAUSE (dir=%d)", dir);
73+
return 0;
74+
case DAI_TRIGGER_PRE_START:
75+
case DAI_TRIGGER_COPY:
76+
LOG_DBG("virtual_dai: DAI_TRIGGER_COPY");
77+
return 0;
78+
default:
79+
LOG_WRN("virtual_dai: Unknown trigger %d", cmd);
80+
return -EINVAL;
81+
}
82+
83+
CODE_UNREACHABLE;
84+
}
85+
86+
static DEVICE_API(dai, virtual_dai_api) = {
87+
.probe = virtual_dai_probe,
88+
.remove = virtual_dai_remove,
89+
.config_set = virtual_dai_config_set,
90+
.config_get = virtual_dai_config_get,
91+
.get_properties = virtual_dai_get_properties,
92+
.trigger = virtual_dai_trigger,
93+
};
94+
95+
static int virtual_dai_init(const struct device *dev)
96+
{
97+
return 0;
98+
}
99+
100+
#define VIRTUAL_DAI_INIT(inst) \
101+
static struct virtual_dai_data virtual_dai_data_##inst = { \
102+
.cfg.type = DAI_VIRTUAL, \
103+
.cfg.dai_index = DT_INST_PROP_OR(inst, dai_index, 0), \
104+
}; \
105+
\
106+
DEVICE_DT_INST_DEFINE(inst, \
107+
&virtual_dai_init, NULL, \
108+
&virtual_dai_data_##inst, NULL, \
109+
POST_KERNEL, CONFIG_DAI_INIT_PRIORITY, \
110+
&virtual_dai_api);
111+
112+
DT_INST_FOREACH_STATUS_OKAY(VIRTUAL_DAI_INIT);

dts/bindings/dai/dai-virtual.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2025 Suraj Sonawane <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
title: Zephyr binding for a Virtual DAI (Digital Audio Interface)
5+
6+
description: |
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+
10+
compatible: "virtual_dai"
11+
12+
include: base.yaml
13+
14+
properties:
15+
dai-index:
16+
type: int
17+
description: |
18+
DAI index used to identify this virtual DAI in IPC and topology.

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)