[PATCH v16 8/8] drm/mediatek: Use cached audio config when changing resolution

Bo-Chen Chen rex-bc.chen at mediatek.com
Fri Aug 5 03:14:59 PDT 2022


When the audio is playing, we need to use the original configuration to
set the audio instead of using new configuration. Therefore, use the
cached audio configuration during a resolution switch to avoid loss of
sound.

Signed-off-by: Jitao Shi <jitao.shi at mediatek.com>
Signed-off-by: Bo-Chen Chen <rex-bc.chen at mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
---
 drivers/gpu/drm/mediatek/mtk_dp.c | 108 +++++-------------------------
 1 file changed, 17 insertions(+), 91 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index 3efac9920304..e725e3104147 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -45,18 +45,6 @@
 #define MTK_DP_TRAIN_DOWNSCALE_RETRY 8
 #define MTK_DP_VERSION 0x11
 
-#define MTK_DP_CEA_SAD_FREQ_32KHZ  BIT(0)
-#define MTK_DP_CEA_SAD_FREQ_44KHZ  BIT(1)
-#define MTK_DP_CEA_SAD_FREQ_48KHZ  BIT(2)
-#define MTK_DP_CEA_SAD_FREQ_88KHZ  BIT(3)
-#define MTK_DP_CEA_SAD_FREQ_96KHZ  BIT(4)
-#define MTK_DP_CEA_SAD_FREQ_176KHZ BIT(5)
-#define MTK_DP_CEA_SAD_FREQ_192KHZ BIT(6)
-
-#define MTK_DP_CEA_SAD_UNCOMPRESSED_WORD_16BIT BIT(0)
-#define MTK_DP_CEA_SAD_UNCOMPRESSED_WORD_20BIT BIT(1)
-#define MTK_DP_CEA_SAD_UNCOMPRESSED_WORD_24BIT BIT(2)
-
 struct mtk_dp_train_info {
 	bool tps3;
 	bool tps4;
@@ -106,7 +94,7 @@ struct mtk_dp_info {
 	struct videomode vm;
 	u8 frame_rate;
 	u32 pix_rate_khz;
-	struct mtk_dp_audio_cfg audio_caps;
+	struct mtk_dp_audio_cfg audio_cur_cfg;
 };
 
 struct dp_cal_data {
@@ -413,48 +401,6 @@ static void mtk_dp_pg_enable(struct mtk_dp *mtk_dp, bool enable)
 			   4 << PGEN_PATTERN_SEL_SHIFT, PGEN_PATTERN_SEL_MASK);
 }
 
-static int mtk_dp_cea_sad_get_sample_rate(const struct cea_sad *sad)
-{
-	switch (sad->freq) {
-	case MTK_DP_CEA_SAD_FREQ_32KHZ:
-		return 32000;
-	case MTK_DP_CEA_SAD_FREQ_44KHZ:
-		return 44100;
-	case MTK_DP_CEA_SAD_FREQ_48KHZ:
-		return 48000;
-	case MTK_DP_CEA_SAD_FREQ_88KHZ:
-		return 88200;
-	case MTK_DP_CEA_SAD_FREQ_96KHZ:
-		return 96000;
-	case MTK_DP_CEA_SAD_FREQ_176KHZ:
-		return 176400;
-	case MTK_DP_CEA_SAD_FREQ_192KHZ:
-		return 192000;
-	default:
-		return -EINVAL;
-	}
-}
-
-static int mtk_dp_cea_sad_get_uncompressed_word_length(const struct cea_sad *sad)
-{
-	if (sad->format != HDMI_AUDIO_CODING_TYPE_PCM) {
-		pr_err("Unable to get the uncompressed word length for format: %u\n",
-		       sad->format);
-		return -EINVAL;
-	}
-
-	switch (sad->byte2) {
-	case MTK_DP_CEA_SAD_UNCOMPRESSED_WORD_16BIT:
-		return 16;
-	case MTK_DP_CEA_SAD_UNCOMPRESSED_WORD_20BIT:
-		return 20;
-	case MTK_DP_CEA_SAD_UNCOMPRESSED_WORD_24BIT:
-		return 24;
-	default:
-		return -EINVAL;
-	}
-}
-
 static void mtk_dp_audio_setup_channels(struct mtk_dp *mtk_dp,
 					struct mtk_dp_audio_cfg *cfg)
 {
@@ -1859,9 +1805,7 @@ static bool mtk_dp_edid_parse_audio_capabilities(struct mtk_dp *mtk_dp,
 						 struct mtk_dp_audio_cfg *cfg)
 {
 	struct cea_sad *sads;
-	int sad_count;
-	int i;
-	bool ret = false;
+	int ret;
 
 	if (!mtk_dp->data->audio_supported)
 		return false;
@@ -1872,36 +1816,16 @@ static bool mtk_dp_edid_parse_audio_capabilities(struct mtk_dp *mtk_dp,
 		dev_err(mtk_dp->dev, "EDID not found!\n");
 		return false;
 	}
-	sad_count = drm_edid_to_sad(mtk_dp->edid, &sads);
-	mutex_unlock(&mtk_dp->edid_lock);
 
-	if (sad_count <= 0) {
+	ret = drm_edid_to_sad(mtk_dp->edid, &sads);
+	mutex_unlock(&mtk_dp->edid_lock);
+	if (ret <= 0) {
 		drm_info(mtk_dp->drm_dev, "The SADs is NULL\n");
 		return false;
 	}
-
-	for (i = 0; i < sad_count; i++) {
-		int sample_rate, word_length;
-
-		/* Only PCM supported at the moment */
-		if (sads[i].format != HDMI_AUDIO_CODING_TYPE_PCM)
-			continue;
-
-		sample_rate = mtk_dp_cea_sad_get_sample_rate(&sads[i]);
-		word_length =
-			mtk_dp_cea_sad_get_uncompressed_word_length(&sads[i]);
-		if (sample_rate <= 0 || word_length <= 0)
-			continue;
-
-		cfg->channels = sads[i].channels;
-		cfg->word_length_bits = word_length;
-		cfg->sample_rate = sample_rate;
-		ret = true;
-		break;
-	}
 	kfree(sads);
 
-	return ret;
+	return true;
 }
 
 static void mtk_dp_train_change_mode(struct mtk_dp *mtk_dp)
@@ -2070,13 +1994,13 @@ static int mtk_dp_training(struct mtk_dp *mtk_dp)
 
 	mtk_dp->audio_enable =
 		mtk_dp_edid_parse_audio_capabilities(mtk_dp,
-						     &mtk_dp->info.audio_caps);
+						     &mtk_dp->info.audio_cur_cfg);
 	if (mtk_dp->audio_enable) {
-		mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_caps);
+		mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg);
 		mtk_dp_audio_mute(mtk_dp, false);
 	} else {
-		memset(&mtk_dp->info.audio_caps, 0,
-		       sizeof(mtk_dp->info.audio_caps));
+		memset(&mtk_dp->info.audio_cur_cfg, 0,
+		       sizeof(mtk_dp->info.audio_cur_cfg));
 	}
 
 	return 0;
@@ -2442,6 +2366,9 @@ static void mtk_dp_bridge_atomic_disable(struct drm_bridge *bridge,
 	if (mtk_dp_plug_state(mtk_dp)) {
 		drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3);
 		usleep_range(2000, 3000);
+	} else {
+		memset(&mtk_dp->info.audio_cur_cfg, 0,
+		       sizeof(mtk_dp->info.audio_cur_cfg));
 	}
 
 	mtk_dp_video_mute(mtk_dp, true);
@@ -2641,18 +2568,17 @@ static int mtk_dp_audio_hw_params(struct device *dev, void *data,
 				  struct hdmi_codec_params *params)
 {
 	struct mtk_dp *mtk_dp = dev_get_drvdata(dev);
-	struct mtk_dp_audio_cfg cfg;
 
 	if (!mtk_dp->enabled) {
 		dev_err(mtk_dp->dev, "%s, DP is not ready!\n", __func__);
 		return -ENODEV;
 	}
 
-	cfg.channels = params->cea.channels;
-	cfg.sample_rate = params->sample_rate;
-	cfg.word_length_bits = 24;
+	mtk_dp->info.audio_cur_cfg.channels = params->cea.channels;
+	mtk_dp->info.audio_cur_cfg.sample_rate = params->sample_rate;
+	mtk_dp->info.audio_cur_cfg.word_length_bits = 24;
 
-	mtk_dp_audio_setup(mtk_dp, &cfg);
+	mtk_dp_audio_setup(mtk_dp, &mtk_dp->info.audio_cur_cfg);
 
 	return 0;
 }
-- 
2.18.0




More information about the Linux-mediatek mailing list