1616#include <sound/pcm.h>
1717#include <sound/pcm_params.h>
1818#include <sound/soc-dapm.h>
19+ #include <sound/soc_sdw_utils.h>
1920#include <sound/initval.h>
2021#include <sound/tlv.h>
2122#include <sound/sdw.h>
@@ -251,6 +252,7 @@ static const struct reg_sequence rt1320_vc_blind_write[] = {
251252 { 0xc06b , 0x0a },
252253 { 0xd172 , 0x2a },
253254 { 0xc5d6 , 0x01 },
255+ { 0xc5d0 , 0x8f }, /* DP6 Data Select: SRCIN OUT for companion output setting */
254256 { SDW_SDCA_CTL (FUNC_NUM_AMP , RT1320_SDCA_ENT_PDE23 , RT1320_SDCA_CTL_REQ_POWER_STATE , 0 ), 0x03 },
255257};
256258
@@ -1090,7 +1092,7 @@ static int rt1320_read_prop(struct sdw_slave *slave)
10901092 prop -> lane_control_support = true;
10911093
10921094 /* first we need to allocate memory for set bits in port lists */
1093- prop -> source_ports = BIT (4 ) | BIT (8 ) | BIT (10 );
1095+ prop -> source_ports = BIT (4 ) | BIT (6 ) | BIT ( 8 ) | BIT (10 );
10941096 prop -> sink_ports = BIT (1 );
10951097
10961098 nval = hweight32 (prop -> source_ports );
@@ -3183,6 +3185,9 @@ static const struct snd_soc_dapm_widget rt1320_dapm_widgets[] = {
31833185 /* Audio Interface */
31843186 SND_SOC_DAPM_AIF_IN ("DP1RX" , "DP1 Playback" , 0 , SND_SOC_NOPM , 0 , 0 ),
31853187 SND_SOC_DAPM_AIF_OUT ("DP4TX" , "DP4 Capture" , 0 , SND_SOC_NOPM , 0 , 0 ),
3188+ SND_SOC_DAPM_AIF_OUT ("DP6TX" , "DP6 Comp-Out" , 0 , SND_SOC_NOPM , 0 , 0 ),
3189+ SND_SOC_DAPM_AIF_IN ("DP6RX" , "DP6 Comp-Playback" , 0 , SND_SOC_NOPM , 0 , 0 ),
3190+
31863191 SND_SOC_DAPM_AIF_OUT ("DP8-10TX" , "DP8-10 Capture" , 0 , SND_SOC_NOPM , 0 , 0 ),
31873192
31883193 /* Digital Interface */
@@ -3221,6 +3226,9 @@ static const struct snd_soc_dapm_route rt1320_dapm_routes[] = {
32213226 { "AEC Data" , NULL , "AEC Gen" },
32223227 { "DP4TX" , NULL , "AEC Data" },
32233228
3229+ { "DP6TX" , NULL , "DP1RX" },
3230+ { "DP6RX" , NULL , "DP1RX" },
3231+
32243232 {"DP8-10TX" , NULL , "FU" },
32253233 {"FU" , NULL , "PDE 11" },
32263234 {"FU" , NULL , "FU 113" },
@@ -3251,6 +3259,10 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
32513259 struct sdw_stream_config stream_config = {0 };
32523260 struct sdw_port_config port_config ;
32533261 struct sdw_port_config dmic_port_config [2 ];
3262+ struct sdw_port_config companion_config = {
3263+ .num = 6 ,
3264+ .ch_mask = BIT (0 ) | BIT (1 ),
3265+ };
32543266 struct sdw_stream_runtime * sdw_stream ;
32553267 int retval , num_channels ;
32563268 unsigned int sampling_rate ;
@@ -3267,6 +3279,9 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
32673279 /* SoundWire specific configuration */
32683280 snd_sdw_params_to_config (substream , params , & stream_config , & port_config );
32693281
3282+ if (dai -> id == RT1320_AIF3 )
3283+ goto _add_slave_ ;
3284+
32703285 if (substream -> stream == SNDRV_PCM_STREAM_PLAYBACK ) {
32713286 if (dai -> id == RT1320_AIF1 )
32723287 port_config .num = 1 ;
@@ -3295,6 +3310,7 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
32953310 return - EINVAL ;
32963311 }
32973312
3313+ _add_slave_ :
32983314 if (dai -> id == RT1320_AIF1 )
32993315 retval = sdw_stream_add_slave (rt1320 -> sdw_slave , & stream_config ,
33003316 & port_config , 1 , sdw_stream );
@@ -3312,6 +3328,21 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
33123328 dev_err (dai -> dev , "%s: Unknown device ID %d\n" , __func__ , rt1320 -> dev_id );
33133329 return - EINVAL ;
33143330 }
3331+ } else if (dai -> id == RT1320_AIF3 ) {
3332+ retval = asoc_sdw_c_amp_hw_params (substream , params , dai );
3333+ if (retval ) {
3334+ dev_err (dai -> dev , "%s: master companion stream configuration failed, ret=%d\n" ,
3335+ __func__ , retval );
3336+ return retval ;
3337+ }
3338+ stream_config .transport_type = SDW_TRANSPORT_PERIPHERAL_PERIPHERAL ;
3339+ retval = sdw_stream_add_slave (rt1320 -> sdw_slave , & stream_config ,
3340+ & companion_config , 1 , sdw_stream );
3341+ if (retval ) {
3342+ sdw_stream_remove_master (rt1320 -> sdw_slave -> bus , sdw_stream );
3343+ dev_err (dai -> dev , "%s: Unable to add slave, ret=%d\n" , __func__ , retval );
3344+ return retval ;
3345+ }
33153346 } else
33163347 return - EINVAL ;
33173348 if (retval ) {
@@ -3350,7 +3381,7 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
33503381 regmap_write (rt1320 -> regmap ,
33513382 SDW_SDCA_CTL (FUNC_NUM_AMP , RT1320_SDCA_ENT_CS21 , RT1320_SDCA_CTL_SAMPLE_FREQ_INDEX , 0 ),
33523383 sampling_rate );
3353- else {
3384+ else if ( dai -> id == RT1320_AIF2 ) {
33543385 regmap_write (rt1320 -> regmap ,
33553386 SDW_SDCA_CTL (FUNC_NUM_MIC , RT1320_SDCA_ENT_CS113 , RT1320_SDCA_CTL_SAMPLE_FREQ_INDEX , 0 ),
33563387 sampling_rate );
@@ -3469,6 +3500,17 @@ static const struct snd_soc_dai_ops rt1320_aif_dai_ops = {
34693500 .shutdown = rt1320_sdw_shutdown ,
34703501};
34713502
3503+ static const struct snd_soc_dai_ops rt1320_comp_dai_asoc_ops = {
3504+ .probe = asoc_sdw_c_amp_probe ,
3505+ .startup = asoc_sdw_c_amp_startup ,
3506+ .prepare = asoc_sdw_c_amp_prepare ,
3507+ .hw_params = rt1320_sdw_hw_params ,
3508+ .hw_free = asoc_sdw_c_amp_hw_free ,
3509+ .set_stream = rt1320_set_sdw_stream ,
3510+ .shutdown = asoc_sdw_c_amp_shutdown ,
3511+ .get_stream = asoc_sdw_c_amp_get_sdw_stream ,
3512+ };
3513+
34723514#define RT1320_STEREO_RATES (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
34733515 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
34743516#define RT1320_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
@@ -3507,6 +3549,28 @@ static struct snd_soc_dai_driver rt1320_sdw_dai[] = {
35073549 },
35083550 .ops = & rt1320_aif_dai_ops ,
35093551 },
3552+ /* Companion stream output */
3553+ {
3554+ .name = "rt1320-aif3" ,
3555+ .id = RT1320_AIF3 ,
3556+ .playback = {
3557+ .stream_name = "DP6 Comp-Playback" ,
3558+ .channels_min = 2 ,
3559+ .channels_max = 2 ,
3560+ .rates = RT1320_STEREO_RATES ,
3561+ .formats = RT1320_FORMATS ,
3562+ },
3563+ .capture = {
3564+ .stream_name = "DP6 Comp-Out" ,
3565+ .channels_min = 2 ,
3566+ .channels_max = 2 ,
3567+ .rates = RT1320_STEREO_RATES ,
3568+ .formats = RT1320_FORMATS ,
3569+ },
3570+ .ops = & rt1320_comp_dai_asoc_ops ,
3571+ .symmetric_rate = 1 ,
3572+ .symmetric_channels = 1 ,
3573+ },
35103574};
35113575
35123576static int rt1320_parse_dp (struct rt1320_sdw_priv * rt1320 , struct device * dev )
@@ -3694,3 +3758,4 @@ module_sdw_driver(rt1320_sdw_driver);
36943758MODULE_DESCRIPTION ("ASoC RT1320 driver SDCA SDW" );
36953759MODULE_AUTHOR ("Shuming Fan <shumingf@realtek.com>" );
36963760MODULE_LICENSE ("GPL" );
3761+ MODULE_IMPORT_NS ("SND_SOC_SDW_UTILS" );
0 commit comments