3131 * encoder block has CEC support.
3232 */
3333
34+ #include <drm/display/drm_hdmi_audio_helper.h>
3435#include <drm/display/drm_hdmi_helper.h>
3536#include <drm/display/drm_hdmi_state_helper.h>
3637#include <drm/display/drm_scdc_helper.h>
@@ -584,6 +585,7 @@ static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs =
584585};
585586
586587static const struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs ;
588+ static const struct drm_connector_hdmi_audio_funcs vc4_hdmi_audio_funcs ;
587589
588590static int vc4_hdmi_connector_init (struct drm_device * dev ,
589591 struct vc4_hdmi * vc4_hdmi )
@@ -609,6 +611,12 @@ static int vc4_hdmi_connector_init(struct drm_device *dev,
609611 if (ret )
610612 return ret ;
611613
614+ ret = drm_connector_hdmi_audio_init (connector , dev -> dev ,
615+ & vc4_hdmi_audio_funcs ,
616+ 8 , false, -1 );
617+ if (ret )
618+ return ret ;
619+
612620 drm_connector_helper_add (connector , & vc4_hdmi_connector_helper_funcs );
613621
614622 /*
@@ -1921,9 +1929,9 @@ static bool vc4_hdmi_audio_can_stream(struct vc4_hdmi *vc4_hdmi)
19211929 return true;
19221930}
19231931
1924- static int vc4_hdmi_audio_startup (struct device * dev , void * data )
1932+ static int vc4_hdmi_audio_startup (struct drm_connector * connector )
19251933{
1926- struct vc4_hdmi * vc4_hdmi = dev_get_drvdata ( dev );
1934+ struct vc4_hdmi * vc4_hdmi = connector_to_vc4_hdmi ( connector );
19271935 struct drm_device * drm = vc4_hdmi -> connector .dev ;
19281936 unsigned long flags ;
19291937 int ret = 0 ;
@@ -1985,9 +1993,9 @@ static void vc4_hdmi_audio_reset(struct vc4_hdmi *vc4_hdmi)
19851993 spin_unlock_irqrestore (& vc4_hdmi -> hw_lock , flags );
19861994}
19871995
1988- static void vc4_hdmi_audio_shutdown (struct device * dev , void * data )
1996+ static void vc4_hdmi_audio_shutdown (struct drm_connector * connector )
19891997{
1990- struct vc4_hdmi * vc4_hdmi = dev_get_drvdata ( dev );
1998+ struct vc4_hdmi * vc4_hdmi = connector_to_vc4_hdmi ( connector );
19911999 struct drm_device * drm = vc4_hdmi -> connector .dev ;
19922000 unsigned long flags ;
19932001 int idx ;
@@ -2057,13 +2065,12 @@ static int sample_rate_to_mai_fmt(int samplerate)
20572065}
20582066
20592067/* HDMI audio codec callbacks */
2060- static int vc4_hdmi_audio_prepare (struct device * dev , void * data ,
2068+ static int vc4_hdmi_audio_prepare (struct drm_connector * connector ,
20612069 struct hdmi_codec_daifmt * daifmt ,
20622070 struct hdmi_codec_params * params )
20632071{
2064- struct vc4_hdmi * vc4_hdmi = dev_get_drvdata ( dev );
2072+ struct vc4_hdmi * vc4_hdmi = connector_to_vc4_hdmi ( connector );
20652073 struct drm_device * drm = vc4_hdmi -> connector .dev ;
2066- struct drm_connector * connector = & vc4_hdmi -> connector ;
20672074 struct vc4_dev * vc4 = to_vc4_dev (drm );
20682075 unsigned int sample_rate = params -> sample_rate ;
20692076 unsigned int channels = params -> channels ;
@@ -2075,7 +2082,7 @@ static int vc4_hdmi_audio_prepare(struct device *dev, void *data,
20752082 int ret = 0 ;
20762083 int idx ;
20772084
2078- dev_dbg (dev , "%s: %u Hz, %d bit, %d channels\n" , __func__ ,
2085+ dev_dbg (& vc4_hdmi -> pdev -> dev , "%s: %u Hz, %d bit, %d channels\n" , __func__ ,
20792086 sample_rate , params -> sample_width , channels );
20802087
20812088 mutex_lock (& vc4_hdmi -> mutex );
@@ -2214,48 +2221,19 @@ static const struct snd_dmaengine_pcm_config pcm_conf = {
22142221 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config ,
22152222};
22162223
2217- static int vc4_hdmi_audio_get_eld (struct device * dev , void * data ,
2218- uint8_t * buf , size_t len )
2219- {
2220- struct vc4_hdmi * vc4_hdmi = dev_get_drvdata (dev );
2221- struct drm_connector * connector = & vc4_hdmi -> connector ;
2222-
2223- mutex_lock (& connector -> eld_mutex );
2224- memcpy (buf , connector -> eld , min (sizeof (connector -> eld ), len ));
2225- mutex_unlock (& connector -> eld_mutex );
2226-
2227- return 0 ;
2228- }
2229-
2230- static const struct hdmi_codec_ops vc4_hdmi_codec_ops = {
2231- .get_eld = vc4_hdmi_audio_get_eld ,
2224+ static const struct drm_connector_hdmi_audio_funcs vc4_hdmi_audio_funcs = {
2225+ .startup = vc4_hdmi_audio_startup ,
22322226 .prepare = vc4_hdmi_audio_prepare ,
2233- .audio_shutdown = vc4_hdmi_audio_shutdown ,
2234- .audio_startup = vc4_hdmi_audio_startup ,
2235- };
2236-
2237- static struct hdmi_codec_pdata vc4_hdmi_codec_pdata = {
2238- .ops = & vc4_hdmi_codec_ops ,
2239- .max_i2s_channels = 8 ,
2240- .i2s = 1 ,
2227+ .shutdown = vc4_hdmi_audio_shutdown ,
22412228};
22422229
2243- static void vc4_hdmi_audio_codec_release (void * ptr )
2244- {
2245- struct vc4_hdmi * vc4_hdmi = ptr ;
2246-
2247- platform_device_unregister (vc4_hdmi -> audio .codec_pdev );
2248- vc4_hdmi -> audio .codec_pdev = NULL ;
2249- }
2250-
22512230static int vc4_hdmi_audio_init (struct vc4_hdmi * vc4_hdmi )
22522231{
22532232 const struct vc4_hdmi_register * mai_data =
22542233 & vc4_hdmi -> variant -> registers [HDMI_MAI_DATA ];
22552234 struct snd_soc_dai_link * dai_link = & vc4_hdmi -> audio .link ;
22562235 struct snd_soc_card * card = & vc4_hdmi -> audio .card ;
22572236 struct device * dev = & vc4_hdmi -> pdev -> dev ;
2258- struct platform_device * codec_pdev ;
22592237 const __be32 * addr ;
22602238 int index , len ;
22612239 int ret ;
@@ -2348,20 +2326,6 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
23482326 return ret ;
23492327 }
23502328
2351- codec_pdev = platform_device_register_data (dev , HDMI_CODEC_DRV_NAME ,
2352- PLATFORM_DEVID_AUTO ,
2353- & vc4_hdmi_codec_pdata ,
2354- sizeof (vc4_hdmi_codec_pdata ));
2355- if (IS_ERR (codec_pdev )) {
2356- dev_err (dev , "Couldn't register the HDMI codec: %ld\n" , PTR_ERR (codec_pdev ));
2357- return PTR_ERR (codec_pdev );
2358- }
2359- vc4_hdmi -> audio .codec_pdev = codec_pdev ;
2360-
2361- ret = devm_add_action_or_reset (dev , vc4_hdmi_audio_codec_release , vc4_hdmi );
2362- if (ret )
2363- return ret ;
2364-
23652329 dai_link -> cpus = & vc4_hdmi -> audio .cpu ;
23662330 dai_link -> codecs = & vc4_hdmi -> audio .codec ;
23672331 dai_link -> platforms = & vc4_hdmi -> audio .platform ;
@@ -2374,7 +2338,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
23742338 dai_link -> stream_name = "MAI PCM" ;
23752339 dai_link -> codecs -> dai_name = "i2s-hifi" ;
23762340 dai_link -> cpus -> dai_name = dev_name (dev );
2377- dai_link -> codecs -> name = dev_name (& codec_pdev -> dev );
2341+ dai_link -> codecs -> name = dev_name (& vc4_hdmi -> connector . hdmi_audio . codec_pdev -> dev );
23782342 dai_link -> platforms -> name = dev_name (dev );
23792343
23802344 card -> dai_link = dai_link ;
0 commit comments