Skip to content

Commit 8cc4d6e

Browse files
Jaska UimonenJaska Uimonen
authored andcommitted
ASoC: SOF: topology: parse sof process mux/demux tokens
Currently sof process (dapm effect type) components have only binary blob parameter parsing. Change sof mux/demux component to use tuples arrays so that the parameters are easier to set in topology. Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
1 parent 2399287 commit 8cc4d6e

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

include/sound/sof/topology.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ struct sof_ipc_comp_asrc {
174174
uint32_t reserved[4];
175175
} __attribute__((packed));
176176

177+
struct mux_stream_data {
178+
uint32_t data_id;
179+
uint32_t pipeline_id;
180+
uint8_t num_channels;
181+
uint8_t mask[8];
182+
uint8_t reserved[3]; /* padding */
183+
} __packed;
184+
185+
struct sof_mux_config {
186+
uint16_t frame_format;
187+
uint16_t num_channels;
188+
uint16_t num_streams;
189+
uint16_t reserved; /* padding to ensure proper alignment */
190+
struct mux_stream_data streams[];
191+
} __packed;
192+
177193
/* generic MUX component */
178194
struct sof_ipc_comp_mux {
179195
struct sof_ipc_comp comp;

include/uapi/sound/sof/tokens.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,9 @@
126126
#define SOF_TKN_MUTE_LED_USE 1300
127127
#define SOF_TKN_MUTE_LED_DIRECTION 1301
128128

129+
#define SOF_TKN_MUX_NUM_STREAMS 1400
130+
#define SOF_TKN_MUX_NUM_CHANNELS 1401
131+
#define SOF_TKN_MUX_STREAM_PIPELINE_ID 1402
132+
#define SOF_TKN_MUX_STREAM_CHANNELS 1403
133+
129134
#endif

sound/soc/sof/topology.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ static int get_token_u16(void *elem, void *object, u32 offset, u32 size)
486486
return 0;
487487
}
488488

489+
static int get_token_u8(void *elem, void *object, u32 offset, u32 size)
490+
{
491+
struct snd_soc_tplg_vendor_value_elem *velem = elem;
492+
u8 *val = (u8 *)object + offset;
493+
494+
*val = (u8)velem->value;
495+
return 0;
496+
}
497+
489498
static int get_token_comp_format(void *elem, void *object, u32 offset, u32 size)
490499
{
491500
struct snd_soc_tplg_vendor_string_elem *velem = elem;
@@ -614,6 +623,22 @@ static const struct sof_topology_token stream_tokens[] = {
614623
offsetof(struct snd_sof_pcm, stream[1].d0i3_compatible), 0},
615624
};
616625

626+
/* Mux data */
627+
static const struct sof_topology_token mux_tokens[] = {
628+
{SOF_TKN_MUX_NUM_CHANNELS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
629+
offsetof(struct sof_mux_config, num_channels), 0},
630+
{SOF_TKN_MUX_NUM_STREAMS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
631+
offsetof(struct sof_mux_config, num_streams), 0},
632+
};
633+
634+
/* Mux stream data */
635+
static const struct sof_topology_token mux_stream_tokens[] = {
636+
{SOF_TKN_MUX_STREAM_PIPELINE_ID, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
637+
offsetof(struct mux_stream_data, pipeline_id), 0},
638+
{SOF_TKN_MUX_STREAM_CHANNELS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u8,
639+
offsetof(struct mux_stream_data, num_channels), 0},
640+
};
641+
617642
/* Generic components */
618643
static const struct sof_topology_token comp_tokens[] = {
619644
{SOF_TKN_COMP_PERIOD_SINK_COUNT,
@@ -2017,6 +2042,60 @@ static int sof_get_control_data(struct snd_soc_component *scomp,
20172042
return 0;
20182043
}
20192044

2045+
/*
2046+
* Sof mux/demux component
2047+
*/
2048+
static int sof_process_load_mux(struct snd_soc_component *scomp,
2049+
struct sof_ipc_comp_process *process,
2050+
struct snd_soc_tplg_private *private)
2051+
{
2052+
struct sof_mux_config *mc = (struct sof_mux_config *)&process->data;
2053+
struct mux_stream_data *msd = (struct mux_stream_data *)
2054+
((u8 *)process->data + sizeof(struct sof_mux_config));
2055+
struct snd_soc_tplg_vendor_array *varray;
2056+
int pos = 0;
2057+
int ret;
2058+
int i;
2059+
2060+
/* parse mux config array */
2061+
ret = sof_parse_tokens(scomp, mc, mux_tokens,
2062+
ARRAY_SIZE(mux_tokens), private->array,
2063+
le32_to_cpu(private->size));
2064+
if (ret < 0) {
2065+
dev_err(scomp->dev, "error: parse mux tokens failed %d\n",
2066+
private->size);
2067+
return ret;
2068+
}
2069+
2070+
/* parse mux stream config arrays */
2071+
for (i = 0; i < mc->num_streams; i++) {
2072+
varray = (struct snd_soc_tplg_vendor_array *)
2073+
((u8 *)private->array + pos);
2074+
ret = sof_parse_tokens(scomp, msd, mux_stream_tokens,
2075+
ARRAY_SIZE(mux_stream_tokens),
2076+
varray,
2077+
le32_to_cpu(private->size) - pos);
2078+
if (ret < 0) {
2079+
dev_err(scomp->dev, "error: mux stream tokens %d\n",
2080+
private->size);
2081+
return ret;
2082+
}
2083+
2084+
/* track position for multiple same type arrays */
2085+
pos += ret;
2086+
msd++;
2087+
}
2088+
2089+
/* get the channel byte masks after stream arrays */
2090+
msd -= mc->num_streams;
2091+
for (i = 0; i < mc->num_streams; i++) {
2092+
memcpy(&msd->mask[0], (u8 *)private->array + pos + i * 8, 8);
2093+
msd++;
2094+
}
2095+
2096+
return ret;
2097+
}
2098+
20202099
static int sof_process_load(struct snd_soc_component *scomp, int index,
20212100
struct snd_sof_widget *swidget,
20222101
struct snd_soc_tplg_dapm_widget *tw,
@@ -2092,6 +2171,30 @@ static int sof_process_load(struct snd_soc_component *scomp, int index,
20922171

20932172
sof_dbg_comp_config(scomp, &process->config);
20942173

2174+
/* possible tuplet and data parsing for process components */
2175+
switch (type) {
2176+
case SOF_COMP_EQ_FIR:
2177+
/* fallthrough */
2178+
case SOF_COMP_EQ_IIR:
2179+
/* fallthrough */
2180+
case SOF_COMP_KEYWORD_DETECT:
2181+
/* fallthrough */
2182+
case SOF_COMP_KPB:
2183+
/* fallthrough */
2184+
case SOF_COMP_SELECTOR:
2185+
break;
2186+
case SOF_COMP_MUX:
2187+
case SOF_COMP_DEMUX:
2188+
offset = sof_process_load_mux(scomp, process, private);
2189+
break;
2190+
}
2191+
2192+
if (offset < 0) {
2193+
dev_err(scomp->dev, "error: parse process tokens failed %d\n",
2194+
le32_to_cpu(private->size));
2195+
goto err;
2196+
}
2197+
20952198
/*
20962199
* found private data in control, so copy it.
20972200
* get possible component controls - get size of all pdata,

0 commit comments

Comments
 (0)