@@ -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+
489498static 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 */
618643static const struct sof_topology_token comp_tokens [] = {
619644 {SOF_TKN_COMP_PERIOD_SINK_COUNT ,
@@ -2029,6 +2054,61 @@ static int sof_get_control_data(struct snd_soc_component *scomp,
20292054 return 0 ;
20302055}
20312056
2057+ /*
2058+ * Sof mux/demux component
2059+ */
2060+ static int sof_process_load_mux (struct snd_soc_component * scomp ,
2061+ struct sof_ipc_comp_process * process ,
2062+ struct snd_soc_tplg_private * private ,
2063+ int * bytes_written )
2064+ {
2065+ struct sof_mux_config * mc = (struct sof_mux_config * )& process -> data ;
2066+ struct mux_stream_data * msd = (struct mux_stream_data * )
2067+ ((u8 * )process -> data + sizeof (struct sof_mux_config ));
2068+ struct snd_soc_tplg_vendor_array * varray ;
2069+ int read_bytes = 0 ;
2070+ int pos = 0 ;
2071+ int ret ;
2072+ int i ;
2073+
2074+ /* parse mux config array */
2075+ ret = sof_parse_tokens (scomp , mc , mux_tokens ,
2076+ ARRAY_SIZE (mux_tokens ), private -> array ,
2077+ le32_to_cpu (private -> size ), & read_bytes );
2078+ if (ret != 0 ) {
2079+ dev_err (scomp -> dev , "error: parse mux tokens failed %d\n" ,
2080+ private -> size );
2081+ return ret ;
2082+ }
2083+
2084+ /* parse mux stream config arrays */
2085+ for (i = 0 ; i < mc -> num_streams ; i ++ , msd ++ ) {
2086+ varray = (struct snd_soc_tplg_vendor_array * )
2087+ ((u8 * )private -> array + pos );
2088+ ret = sof_parse_tokens (scomp , msd , mux_stream_tokens ,
2089+ ARRAY_SIZE (mux_stream_tokens ),
2090+ varray ,
2091+ le32_to_cpu (private -> size ) - pos ,
2092+ & read_bytes );
2093+ if (ret != 0 ) {
2094+ dev_err (scomp -> dev , "error: mux stream tokens %d\n" ,
2095+ private -> size );
2096+ return ret ;
2097+ }
2098+ pos += read_bytes ;
2099+ }
2100+
2101+ /* get the channel byte masks after stream arrays */
2102+ msd -= mc -> num_streams ;
2103+ for (i = 0 ; i < mc -> num_streams ; i ++ , msd ++ , pos += 8 )
2104+ memcpy (& msd -> mask [0 ], (u8 * )private -> array + pos , 8 );
2105+
2106+ * bytes_written = sizeof (struct sof_mux_config ) +
2107+ mc -> num_streams * sizeof (struct mux_stream_data );
2108+
2109+ return ret ;
2110+ }
2111+
20322112static int sof_process_load (struct snd_soc_component * scomp , int index ,
20332113 struct snd_sof_widget * swidget ,
20342114 struct snd_soc_tplg_dapm_widget * tw ,
@@ -2105,6 +2185,18 @@ static int sof_process_load(struct snd_soc_component *scomp, int index,
21052185
21062186 sof_dbg_comp_config (scomp , & process -> config );
21072187
2188+ /* possible tuplet parsing for process components */
2189+ switch (type ) {
2190+ case SOF_COMP_MUX :
2191+ case SOF_COMP_DEMUX :
2192+ ret = sof_process_load_mux (scomp , process , private , & offset );
2193+ if (ret < 0 ) {
2194+ dev_err (scomp -> dev , "error: parse mux tokens failed %d\n" ,
2195+ le32_to_cpu (private -> size ));
2196+ goto err ;
2197+ }
2198+ }
2199+
21082200 /*
21092201 * found private data in control, so copy it.
21102202 * get possible component controls - get size of all pdata,
0 commit comments