Skip to contentSkip to conversation

drm: add drm_edid_to_eld helper extracting SADs from EDID

PATCH In review Rafał Miłecki 3 participants 7 messages Apr 19, 2013 – Apr 22, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm: add drm_edid_to_eld helper extracting SADs from EDID

Some devices (ATI/AMD cards) don't support passing ELD struct to the hardware but just require filling specific registers and then the hardware/firmware does the rest. In such cases we need to read the info from SAD blocks and put them in the correct registers.

---
Changes since RFC:
1) Fixed allocation (and kcalloc instead of kzalloc)
2) Don't duplicate defines for audio codecs
3) Some variables scope

---
 drivers/gpu/drm/drm_edid.c |   58 ++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_edid.h     |    9 +++++++
 2 files changed, 67 insertions(+)
drivers/gpu/drm/drm_edid.c +58 -0
index e2acfdb..89ae211 100644
@@ -2511,6 +2511,64 @@ void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 EXPORT_SYMBOL(drm_edid_to_eld);
 
 /**
+ * drm_edid_to_sad - extracts SADs from EDID
+ * @edid: EDID to parse
+ * @sads: pointer that will be set to the extracted SADs
+ *
+ * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
+ *
+ * Return number of found SADs or negative number on error.
+ */
+int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
+{
+	int count = 0;
+	int i, start, end, dbl;
+	u8 *cea;
+
+	cea = drm_find_cea_extension(edid);
+	if (!cea) {
+		DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
+		return -ENOENT;
+	}
+
+	if (cea_revision(cea) < 3) {
+		DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
+		return -ENOTSUPP;
+	}
+
+	if (cea_db_offsets(cea, &start, &end)) {
+		DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
+		return -EPROTO;
+	}
+
+	for_each_cea_db(cea, i, start, end) {
+		u8 *db = &cea[i];
+
+		if (cea_db_tag(db) == AUDIO_BLOCK) {
+			dbl = cea_db_payload_len(db);
+			int j;
+
+			count = dbl / 3; /* SAD is 3B */
+			*sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
+			if (!*sads)
+				return -ENOMEM;
+			for (j = 0; j < count; j++) {
+				u8 *sad = &db[1 + j * 3];
+
+				(*sads)[j].format = (sad[0] & 0x78) >> 3;
+				(*sads)[j].channels = sad[0] & 0x7;
+				(*sads)[j].freq = sad[1] & 0x7F;
+				(*sads)[j].byte2 = sad[2];
+			}
+			break;
+		}
+	}
+
+	return count;
+}
+EXPORT_SYMBOL(drm_edid_to_sad);
+
+/**
  * drm_av_sync_delay - HDMI/DP sink audio-video sync delay in millisecond
  * @connector: connector associated with the HDMI/DP sink
  * @mode: the display mode
include/drm/drm_edid.h +9 -0
index 5da1b4a..fc481fc 100644
@@ -244,12 +244,21 @@ struct edid {
 
 #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))
 
+/* Short Audio Descriptor */
+struct cea_sad {
+	u8 format;
+	u8 channels; /* max number of channels - 1 */
+	u8 freq;
+	u8 byte2; /* meaning depends on format */
+};
+
 struct drm_encoder;
 struct drm_connector;
 struct drm_display_mode;
 struct hdmi_avi_infoframe;
 
 void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid);
+int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads);
 int drm_av_sync_delay(struct drm_connector *connector,
 		      struct drm_display_mode *mode);
 struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
Signature · 6 lines
1.7.10.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm/radeon/evergreen: set SAD registers

This allows audio (alsa) driver to read them and have a clue about audio capabilities of connected receiver. This has been verified to be compatible with fglrx behaviour for Onkyo TX-SR605 and Denon 1912.

---
 drivers/gpu/drm/radeon/evergreen_hdmi.c |   63 +++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
drivers/gpu/drm/radeon/evergreen_hdmi.c +63 -0
index 380933b..1e046d15 100644
@@ -54,6 +54,68 @@ static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t cloc
 	WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
 }
 
+static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder)
+{
+	struct radeon_device *rdev = encoder->dev->dev_private;
+	struct drm_connector *connector;
+	struct radeon_connector *radeon_connector = NULL;
+	struct cea_sad *sads;
+	int i, sad_count;
+
+	static const u16 eld_reg_to_type[][2] = {
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
+		{ AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
+	};
+
+	list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
+		if (connector->encoder == encoder)
+			radeon_connector = to_radeon_connector(connector);
+	}
+
+	if (!radeon_connector) {
+		DRM_ERROR("Couldn't find encoder's connector\n");
+		return;
+	}
+
+	sad_count = drm_edid_to_sad(radeon_connector->edid, &sads);
+	if (sad_count < 0) {
+		DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
+		return;
+	}
+	BUG_ON(!sads);
+
+	for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
+		u32 value = 0;
+		int j;
+
+		for (j = 0; j < sad_count; j++) {
+			struct cea_sad *sad = &sads[j];
+
+			if (sad->format == eld_reg_to_type[i][1]) {
+				value = MAX_CHANNELS(sad->channels) |
+					DESCRIPTOR_BYTE_2(sad->byte2) |
+					SUPPORTED_FREQUENCIES(sad->freq);
+				if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
+					value |= SUPPORTED_FREQUENCIES_STEREO(sad->freq);
+				break;
+			}
+		}
+		WREG32(eld_reg_to_type[i][0], value);
+	}
+
+	kfree(sads);
+}
+
 /*
  * build a HDMI Video Info Frame
  */
@@ -163,6 +225,7 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
 	       AFMT_AUDIO_CHANNEL_ENABLE(0xff));
 
 	/* fglrx sets 0x40 in 0x5f80 here */
+	evergreen_hdmi_write_sad_regs(encoder);
 
 	err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
 	if (err < 0) {
Signature · 6 lines
1.7.10.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/2
#2 lore raw
In reply to Rafał Miłecki

Am 19.04.2013 19:01, schrieb Rafał Miłecki:

Quoted 6 lines

Some devices (ATI/AMD cards) don't support passing ELD struct to the hardware but just require filling specific registers and then the hardware/firmware does the rest. In such cases we need to read the info from SAD blocks and put them in the correct registers.

Maybe add some comment that the returned pointer needs to be kfreed, but apart from that it is good enough for me and:

Quoted 95 lines

---
Changes since RFC:
1) Fixed allocation (and kcalloc instead of kzalloc)
2) Don't duplicate defines for audio codecs
3) Some variables scope

---
  drivers/gpu/drm/drm_edid.c |   58 ++++++++++++++++++++++++++++++++++++++++++++
  include/drm/drm_edid.h     |    9 +++++++
  2 files changed, 67 insertions(+)
drivers/gpu/drm/drm_edid.c +58 -0
index e2acfdb..89ae211 100644
@@ -2511,6 +2511,64 @@ void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
  EXPORT_SYMBOL(drm_edid_to_eld);
 
  /**
+ * drm_edid_to_sad - extracts SADs from EDID
+ * @edid: EDID to parse
+ * @sads: pointer that will be set to the extracted SADs
+ *
+ * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
+ *
+ * Return number of found SADs or negative number on error.
+ */
+int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
+{
+	int count = 0;
+	int i, start, end, dbl;
+	u8 *cea;
+
+	cea = drm_find_cea_extension(edid);
+	if (!cea) {
+		DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
+		return -ENOENT;
+	}
+
+	if (cea_revision(cea) < 3) {
+		DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
+		return -ENOTSUPP;
+	}
+
+	if (cea_db_offsets(cea, &start, &end)) {
+		DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
+		return -EPROTO;
+	}
+
+	for_each_cea_db(cea, i, start, end) {
+		u8 *db = &cea[i];
+
+		if (cea_db_tag(db) == AUDIO_BLOCK) {
+			dbl = cea_db_payload_len(db);
+			int j;
+
+			count = dbl / 3; /* SAD is 3B */
+			*sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
+			if (!*sads)
+				return -ENOMEM;
+			for (j = 0; j < count; j++) {
+				u8 *sad = &db[1 + j * 3];
+
+				(*sads)[j].format = (sad[0] & 0x78) >> 3;
+				(*sads)[j].channels = sad[0] & 0x7;
+				(*sads)[j].freq = sad[1] & 0x7F;
+				(*sads)[j].byte2 = sad[2];
+			}
+			break;
+		}
+	}
+
+	return count;
+}
+EXPORT_SYMBOL(drm_edid_to_sad);
+
+/**
   * drm_av_sync_delay - HDMI/DP sink audio-video sync delay in millisecond
   * @connector: connector associated with the HDMI/DP sink
   * @mode: the display mode
include/drm/drm_edid.h +8 -0
index 5da1b4a..fc481fc 100644
@@ -244,12 +244,21 @@ struct edid {
 
  #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))
 
+/* Short Audio Descriptor */
+struct cea_sad {
+	u8 format;
+	u8 channels; /* max number of channels - 1 */
+	u8 freq;
+	u8 byte2; /* meaning depends on format */
+};
+

include/drm/drm_edid.h struct edid { · line 264

Quoted 10 lines
include/drm/drm_edid.h +1 -0
  struct drm_encoder;
  struct drm_connector;
  struct drm_display_mode;
  struct hdmi_avi_infoframe;
 
  void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid);
+int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads);
  int drm_av_sync_delay(struct drm_connector *connector,
  		      struct drm_display_mode *mode);
  struct drm_connector *drm_select_eld(struct drm_encoder *encoder,

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
In reply to Rafał Miłecki
Quoted 6 lines · Rafał Miłecki

Some devices (ATI/AMD cards) don't support passing ELD struct to the hardware but just require filling specific registers and then the hardware/firmware does the rest. In such cases we need to read the info from SAD blocks and put them in the correct registers.

Thanks both patches applied. I added a comment about needing to kfree the returned pointer as per Christian's comment.

Alex

Quoted 106 lines

---
Changes since RFC:
1) Fixed allocation (and kcalloc instead of kzalloc)
2) Don't duplicate defines for audio codecs
3) Some variables scope

---
 drivers/gpu/drm/drm_edid.c |   58 ++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_edid.h     |    9 +++++++
 2 files changed, 67 insertions(+)
drivers/gpu/drm/drm_edid.c +58 -0
index e2acfdb..89ae211 100644
@@ -2511,6 +2511,64 @@ void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 EXPORT_SYMBOL(drm_edid_to_eld);
 
 /**
+ * drm_edid_to_sad - extracts SADs from EDID
+ * @edid: EDID to parse
+ * @sads: pointer that will be set to the extracted SADs
+ *
+ * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
+ *
+ * Return number of found SADs or negative number on error.
+ */
+int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
+{
+       int count = 0;
+       int i, start, end, dbl;
+       u8 *cea;
+
+       cea = drm_find_cea_extension(edid);
+       if (!cea) {
+               DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
+               return -ENOENT;
+       }
+
+       if (cea_revision(cea) < 3) {
+               DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
+               return -ENOTSUPP;
+       }
+
+       if (cea_db_offsets(cea, &start, &end)) {
+               DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
+               return -EPROTO;
+       }
+
+       for_each_cea_db(cea, i, start, end) {
+               u8 *db = &cea[i];
+
+               if (cea_db_tag(db) == AUDIO_BLOCK) {
+                       dbl = cea_db_payload_len(db);
+                       int j;
+
+                       count = dbl / 3; /* SAD is 3B */
+                       *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
+                       if (!*sads)
+                               return -ENOMEM;
+                       for (j = 0; j < count; j++) {
+                               u8 *sad = &db[1 + j * 3];
+
+                               (*sads)[j].format = (sad[0] & 0x78) >> 3;
+                               (*sads)[j].channels = sad[0] & 0x7;
+                               (*sads)[j].freq = sad[1] & 0x7F;
+                               (*sads)[j].byte2 = sad[2];
+                       }
+                       break;
+               }
+       }
+
+       return count;
+}
+EXPORT_SYMBOL(drm_edid_to_sad);
+
+/**
  * drm_av_sync_delay - HDMI/DP sink audio-video sync delay in millisecond
  * @connector: connector associated with the HDMI/DP sink
  * @mode: the display mode
include/drm/drm_edid.h +9 -1
index 5da1b4a..fc481fc 100644
@@ -244,12 +244,21 @@ struct edid {
 
 #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))
 
+/* Short Audio Descriptor */
+struct cea_sad {
+       u8 format;
+       u8 channels; /* max number of channels - 1 */
+       u8 freq;
+       u8 byte2; /* meaning depends on format */
+};
+
 struct drm_encoder;
 struct drm_connector;
 struct drm_display_mode;
 struct hdmi_avi_infoframe;
 
 void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid);
+int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads);
 int drm_av_sync_delay(struct drm_connector *connector,
                      struct drm_display_mode *mode);
 struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
--
Quoted 2 lines

1.7.10.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Am 21.04.2013 23:53, schrieb Alex Deucher:

Quoted 9 lines · Rafał Miłecki
Quoted 6 lines

Some devices (ATI/AMD cards) don't support passing ELD struct to the hardware but just require filling specific registers and then the hardware/firmware does the rest. In such cases we need to read the info from SAD blocks and put them in the correct registers.

Thanks both patches applied. I added a comment about needing to kfree the returned pointer as per Christian's comment.

Found one more minor nitpick in this patch:

drivers/gpu/drm/drm_edid.c void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) · line 2550

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +4 -0
+               if (cea_db_tag(db) == AUDIO_BLOCK) {
+                       dbl = cea_db_payload_len(db);
+                       int j;
+

That's code after declaration and so complained on by the compiler.

Christian.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

2013/4/22 Christian König <[email protected]>:

Quoted 10 lines

Found one more minor nitpick in this patch:

drivers/gpu/drm/drm_edid.c void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) · line 2550

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +4 -0
+               if (cea_db_tag(db) == AUDIO_BLOCK) {
+                       dbl = cea_db_payload_len(db);
+                       int j;
+

That's code after declaration and so complained on by the compiler.

I guess you've missed
drm_edid_to_sad: (drm-next-3.10) compiler warnings [PATCH] drm: drm_edid_to_sad: fix declaration warning threads :)

Signature · 5 lines
Rafał
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
Quoted 10 lines · Rafał Miłecki

2013/4/22 Christian König <[email protected]>:

Quoted 9 lines

Found one more minor nitpick in this patch:

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +4 -0
+               if (cea_db_tag(db) == AUDIO_BLOCK) {
+                       dbl = cea_db_payload_len(db);
+                       int j;
+
Quoted 7 lines
Quoted 1 line

That's code after declaration and so complained on by the compiler.

I guess you've missed
drm_edid_to_sad: (drm-next-3.10) compiler warnings [PATCH] drm: drm_edid_to_sad: fix declaration warning threads :)

I've fixed it up in my tree. thanks!

Alex
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel