public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD
Date: Wed, 28 Jun 2023 22:03:59 +0530	[thread overview]
Message-ID: <20230628163359.2879668-4-mitulkumar.ajitkumar.golani@intel.com> (raw)
In-Reply-To: <20230628163359.2879668-1-mitulkumar.ajitkumar.golani@intel.com>

Compute SADs that takes into account the supported rate
and channel based on the capabilities of the audio source.
This wrapper function should encapsulate the logic for
determining the supported rate and channel and should
return a set of SADs that are compatible with the source.

--v1:
- call intel_audio_compute_eld in this commit as it is
defined here

--v2:
- Handle case when max frequency is less than 32k.
- remove drm prefix.
- name change for parse_sad to eld_to_sad.

--v3:
- Use signed int wherever required.
- add debug trace when channel is limited.

--v4:
- remove inline from eld_to_sad.
- declare index outside of for loop with int type.
- Correct mask value calculation.
- remove drm_err, instead just return if eld parsing failed.
- remove unncessary typecast
- reduce indentation while parsing sad
- use intel_audio_compute_eld as static and call bandwidth
calculation just before that.

Signed-off-by: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>
---
 drivers/gpu/drm/i915/display/intel_audio.c | 73 +++++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/display/intel_audio.c b/drivers/gpu/drm/i915/display/intel_audio.c
index 79377e33a59b..9f4fc3f9b224 100644
--- a/drivers/gpu/drm/i915/display/intel_audio.c
+++ b/drivers/gpu/drm/i915/display/intel_audio.c
@@ -806,6 +806,77 @@ static void calc_audio_config_params(struct intel_crtc_state *pipe_config)
 	pipe_config->audio.max_channel_count = 0;
 }
 
+static int sad_to_channels(const u8 *sad)
+{
+	return 1 + (sad[0] & 0x7);
+}
+
+static u8 *eld_to_sad(u8 *eld)
+{
+	int ver, mnl;
+
+	ver = (eld[DRM_ELD_VER] & DRM_ELD_VER_MASK) >> DRM_ELD_VER_SHIFT;
+	if (ver != 2 && ver != 31)
+		return NULL;
+
+	mnl = drm_eld_mnl(eld);
+	if (mnl > 16)
+		return NULL;
+
+	return eld + DRM_ELD_CEA_SAD(mnl, 0);
+}
+
+static int get_supported_freq_mask(struct intel_crtc_state *crtc_state)
+{
+	int rate[] = { 32000, 44100, 48000, 88000, 96000, 176000, 192000 };
+	int mask = 0, index;
+
+	for (index = 0; index < ARRAY_SIZE(rate); index++) {
+		if (rate[index] > crtc_state->audio.max_rate)
+			break;
+
+		mask |= 1 << index;
+
+		if (crtc_state->audio.max_rate != rate[index])
+			continue;
+	}
+
+	return mask;
+}
+
+static void intel_audio_compute_eld(struct intel_crtc_state *crtc_state)
+{
+	struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
+	u8 *eld, *sad;
+	int index, mask = 0;
+
+	eld = crtc_state->eld;
+	if (!eld)
+		return;
+
+	sad = eld_to_sad(eld);
+	if (!sad)
+		return;
+
+	calc_audio_config_params(crtc_state);
+
+	mask = get_supported_freq_mask(crtc_state);
+	for (index = 0; index < drm_eld_sad_count(eld); index++, sad += 3) {
+		/*
+		 * Respect source restricitions. Limit capabilities to a subset that is
+		 * supported both by the source and the sink.
+		 */
+		if (sad_to_channels(sad) >= crtc_state->audio.max_channel_count) {
+			sad[0] &= ~0x7;
+			sad[0] |= crtc_state->audio.max_channel_count - 1;
+			drm_dbg_kms(&i915->drm, "Channel count is limited to %d\n",
+				    crtc_state->audio.max_channel_count - 1);
+		}
+
+		sad[1] &= mask;
+	}
+}
+
 bool intel_audio_compute_config(struct intel_encoder *encoder,
 				struct intel_crtc_state *crtc_state,
 				struct drm_connector_state *conn_state)
@@ -827,7 +898,7 @@ bool intel_audio_compute_config(struct intel_encoder *encoder,
 
 	crtc_state->eld[6] = drm_av_sync_delay(connector, adjusted_mode) / 2;
 
-	calc_audio_config_params(crtc_state);
+	intel_audio_compute_eld(crtc_state);
 
 	return true;
 }
-- 
2.25.1


  parent reply	other threads:[~2023-06-28 16:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 16:33 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-28 16:33 ` [Intel-gfx] [RFC 1/3] drm/i915: Add has_audio to separate audio parameter in crtc_state Mitul Golani
2023-06-28 16:33 ` [Intel-gfx] [RFC 2/3] drm/i915/display: Configure and initialize HDMI audio capabilities Mitul Golani
2023-06-28 16:33 ` Mitul Golani [this message]
2023-06-28 18:18 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for Get optimal audio frequency and channels (rev8) Patchwork
2023-06-28 18:32 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-06-29  8:12 ` [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Jani Nikula
2023-06-30  4:46   ` Golani, Mitulkumar Ajitkumar
2023-06-29 10:36 ` [Intel-gfx] ✓ Fi.CI.IGT: success for Get optimal audio frequency and channels (rev8) Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2023-06-28 16:11 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-28 16:11 ` [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD Mitul Golani
2023-06-26 16:46 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-26 16:46 ` [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD Mitul Golani
2023-06-26 16:38 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-26 16:38 ` [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD Mitul Golani
2023-06-26 17:18   ` Jani Nikula
2023-06-28 16:43     ` Golani, Mitulkumar Ajitkumar
2023-06-15  7:07 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-15  7:07 ` [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD Mitul Golani
2023-06-16  9:24   ` Borah, Chaitanya Kumar
2023-06-15  6:31 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-15  6:31 ` [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD Mitul Golani
2023-06-09 17:42 [Intel-gfx] [RFC 0/3] Get optimal audio frequency and channels Mitul Golani
2023-06-09 17:42 ` [Intel-gfx] [RFC 3/3] drm/i915/display: Add wrapper to Compute SAD Mitul Golani
2023-06-15  3:59   ` Borah, Chaitanya Kumar
2023-06-15  7:09     ` Golani, Mitulkumar Ajitkumar
2023-06-19 11:19   ` Kai Vehmanen
2023-06-26 16:05     ` Golani, Mitulkumar Ajitkumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230628163359.2879668-4-mitulkumar.ajitkumar.golani@intel.com \
    --to=mitulkumar.ajitkumar.golani@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox