2020-05-01 09:58:50 -05:00
// SPDX-License-Identifier: GPL-2.0-only
2019-10-29 15:40:11 +02:00
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
2021-05-05 11:36:57 -05:00
# include <linux/module.h>
2019-10-29 15:40:11 +02:00
# include <sound/pcm.h>
# include <sound/soc.h>
# include <sound/hda_codec.h>
# include <sound/hda_i915.h>
# include "../../codecs/hdac_hda.h"
# include "hda_dsp_common.h"
2020-09-23 10:29:39 +03:00
# if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
2019-10-29 15:40:11 +02:00
/*
* Search card topology and return PCM device number
* matching Nth HDMI device ( zero - based index ) .
*/
2020-09-23 10:29:39 +03:00
static struct snd_pcm * hda_dsp_hdmi_pcm_handle ( struct snd_soc_card * card ,
int hdmi_idx )
2019-10-29 15:40:11 +02:00
{
struct snd_soc_pcm_runtime * rtd ;
struct snd_pcm * spcm ;
int i = 0 ;
for_each_card_rtds ( card , rtd ) {
spcm = rtd - > pcm ?
rtd - > pcm - > streams [ SNDRV_PCM_STREAM_PLAYBACK ] . pcm : NULL ;
if ( spcm & & strstr ( spcm - > id , " HDMI " ) ) {
if ( i = = hdmi_idx )
return rtd - > pcm ;
+ + i ;
}
}
return NULL ;
}
/*
* Search card topology and register HDMI PCM related controls
* to codec driver .
*/
int hda_dsp_hdmi_build_controls ( struct snd_soc_card * card ,
struct snd_soc_component * comp )
{
struct hdac_hda_priv * hda_pvt ;
struct hda_codec * hcodec ;
struct snd_pcm * spcm ;
struct hda_pcm * hpcm ;
int err = 0 , i = 0 ;
if ( ! comp )
return - EINVAL ;
hda_pvt = snd_soc_component_get_drvdata ( comp ) ;
2022-08-16 13:17:24 +02:00
hcodec = hda_pvt - > codec ;
2019-10-29 15:40:11 +02:00
list_for_each_entry ( hpcm , & hcodec - > pcm_list_head , list ) {
spcm = hda_dsp_hdmi_pcm_handle ( card , i ) ;
if ( spcm ) {
hpcm - > pcm = spcm ;
hpcm - > device = spcm - > device ;
dev_dbg ( card - > dev ,
2022-06-16 16:53:50 -05:00
" mapping HDMI converter %d to PCM %d (%p) \n " ,
i , hpcm - > device , spcm ) ;
2019-10-29 15:40:11 +02:00
} else {
2020-01-02 13:59:51 -06:00
hpcm - > pcm = NULL ;
2019-10-29 15:40:11 +02:00
hpcm - > device = SNDRV_PCM_INVALID_DEVICE ;
dev_warn ( card - > dev ,
2021-11-28 14:31:46 +00:00
" %s: no PCM in topology for HDMI converter %d \n " ,
2019-10-29 15:40:11 +02:00
__func__ , i ) ;
}
i + + ;
}
snd_hdac_display_power ( hcodec - > core . bus ,
HDA_CODEC_IDX_CONTROLLER , true ) ;
err = snd_hda_codec_build_controls ( hcodec ) ;
if ( err < 0 )
dev_err ( card - > dev , " unable to create controls %d \n " , err ) ;
snd_hdac_display_power ( hcodec - > core . bus ,
HDA_CODEC_IDX_CONTROLLER , false ) ;
return err ;
}
2021-05-05 11:36:57 -05:00
EXPORT_SYMBOL_NS ( hda_dsp_hdmi_build_controls , SND_SOC_INTEL_HDA_DSP_COMMON ) ;
2019-10-29 15:40:11 +02:00
# endif
2021-05-05 11:36:57 -05:00
MODULE_DESCRIPTION ( " ASoC Intel HDMI helpers " ) ;
MODULE_LICENSE ( " GPL " ) ;