Skip to contentSkip to conversation

i915: enable AVI infoframe for intel_hdmi.c [v2]

PATCH In review David Härdeman 2 participants 6 messages Sep 9, 2010 – Sep 21, 2010

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

PATCH 1/1 i915: enable AVI infoframe for intel_hdmi.c [v2]

This patch enables the sending of AVI infoframes in drivers/gpu/drm/i915/intel_hdmi.c.

My receiver currently loses sync when the HDMI output on my computer (DG45FC motherboard) is switched from 800x600 (the BIOS resolution) to 1920x1080 as part of the boot. Fixable by switching inputs on the receiver a couple of times.

With this patch, my receiver has not lost sync yet (> 40 tries).

I'm not sure that the general approach is sound, which is why I'm sending this out for some feedback and review (in particular, is the SDVOB and SDVOC handling in intel_hdmi_set_avi_infoframe() correct?).

This is the second version which merges the infoframe code from intel_hdmi.c and intel_sdvo.c, I hope this is something along the lines Chris Wilson had in mind. Note that I'm assuming that the sdvo hardware also stores a header ECC byte in the MSB of the first dword (haven't found any documentation for the sdvo).

---
 drivers/gpu/drm/i915/i915_reg.h   |   16 +++++
 drivers/gpu/drm/i915/intel_drv.h  |   27 +++++++++
 drivers/gpu/drm/i915/intel_hdmi.c |   76 ++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_sdvo.c |  117 +++++--------------------------------
 4 files changed, 136 insertions(+), 100 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +16 -0
index 67e3ec1..6c2d9a6 100644
@@ -1330,6 +1330,22 @@
 #define   LVDS_B0B3_POWER_DOWN		(0 << 2)
 #define   LVDS_B0B3_POWER_UP		(3 << 2)
 
+/* Video Data Island Packet control */
+#define VIDEO_DIP_DATA		0x61178
+#define VIDEO_DIP_CTL		0x61170
+#define   VIDEO_DIP_ENABLE		(1 << 31)
+#define   VIDEO_DIP_PORT_B		(1 << 29)
+#define   VIDEO_DIP_PORT_C		(2 << 29)
+#define   VIDEO_DIP_ENABLE_AVI		(1 << 21)
+#define   VIDEO_DIP_ENABLE_VENDOR	(2 << 21)
+#define   VIDEO_DIP_ENABLE_SPD		(8 << 21)
+#define   VIDEO_DIP_SELECT_AVI		(0 << 19)
+#define   VIDEO_DIP_SELECT_VENDOR	(1 << 19)
+#define   VIDEO_DIP_SELECT_SPD		(3 << 19)
+#define   VIDEO_DIP_FREQ_ONCE		(0 << 16)
+#define   VIDEO_DIP_FREQ_VSYNC		(1 << 16)
+#define   VIDEO_DIP_FREQ_2VSYNC		(2 << 16)
+
 /* Panel power sequencing */
 #define PP_STATUS	0x61200
 #define   PP_ON		(1 << 31)
drivers/gpu/drm/i915/intel_drv.h +27 -0
index 0e92aa0..f5808e7 100644
@@ -176,6 +176,30 @@ struct intel_crtc {
 #define enc_to_intel_encoder(x) container_of(x, struct intel_encoder, enc)
 #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
 
+#define DIP_TYPE_AVI    0x82
+#define DIP_VERSION_AVI 0x2
+#define DIP_LEN_AVI     13
+
+struct dip_infoframe {
+	uint8_t type;		/* HB0 */
+	uint8_t ver;		/* HB1 */
+	uint8_t len;		/* HB2 - body len, not including checksum */
+	uint8_t ecc;		/* HW specific, not part of the infoframe */
+	uint8_t checksum;	/* PB0 */
+	uint8_t Y_A_B_S;	/* PB1 - Y 6:5, A 4:4, B 3:2, S 1:0 */
+	uint8_t C_M_R;		/* PB2 - C 7:6, M 5:4, R 3:0 */
+	uint8_t ITC_EC_Q_SC;	/* PB3 - ITC 7:7, EC 6:4, Q 3:2, SC 1:0 */
+	uint8_t VIC;		/* PB4 - VIC 6:0 */
+	uint8_t PR;		/* PB5 - PR 3:0 */
+	/* PB6 - PB13 */
+	uint16_t top_bar_end;
+	uint16_t bottom_bar_start;
+	uint16_t left_bar_end;
+	uint16_t right_bar_start;
+	/* Pad to 32-bit */
+	uint16_t padding;
+} __attribute__((packed));
+
 struct i2c_adapter *intel_i2c_create(struct drm_device *dev, const u32 reg,
 				     const char *name);
 void intel_i2c_destroy(struct i2c_adapter *adapter);
@@ -186,6 +210,9 @@ void intel_i2c_reset_gmbus(struct drm_device *dev);
 
 extern void intel_crt_init(struct drm_device *dev);
 extern void intel_hdmi_init(struct drm_device *dev, int sdvox_reg);
+extern bool intel_hdmi_proc_infoframe(struct drm_encoder *encoder,
+				      struct dip_infoframe *avi_if,
+				      bool (*write_func)(struct drm_encoder *, uint8_t *)); 
 extern bool intel_sdvo_init(struct drm_device *dev, int output_device);
 extern void intel_dvo_init(struct drm_device *dev);
 extern void intel_tv_init(struct drm_device *dev);
drivers/gpu/drm/i915/intel_hdmi.c +76 -0

94 lines not on this page · raw message

drivers/gpu/drm/i915/intel_sdvo.c +17 -100

139 lines not on this page · raw message

#1 lore raw
Quoted 5 lines · David Härdeman

This is the second version which merges the infoframe code from intel_hdmi.c and intel_sdvo.c, I hope this is something along the lines Chris Wilson had in mind. Note that I'm assuming that the sdvo hardware also stores a header ECC byte in the MSB of the first dword (haven't found any documentation for the sdvo).

Pretty close. Using a callback function for writing the data is overkill, just call the common function to compute the avi csum, then pass the avi to the sdvo or hdmi handlers. It just makes following the logic that little bit easier.

drm-intel-next has changed slightly since you wrote the patch, so can you respin it - just a couple of the macro names have changed to be consistent.

drivers/gpu/drm/i915/intel_hdmi.c static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) · line 51

Quoted 10 lines

---

drivers/gpu/drm/i915/intel_hdmi.c +1 -0
index ccd4c97..4fc323c 100644
@@ -48,6 +48,79 @@ static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
 	return container_of(enc_to_intel_encoder(encoder), struct intel_hdmi, base);
 }
 
+static void intel_hdmi_calc_infoframe_csum(struct dip_infoframe *avi_if)

void intel_dip_infoframe_csum(struct dip_infoframe *avi_if)

Quoted 30 lines
drivers/gpu/drm/i915/intel_hdmi.c +30 -0
+{
+	uint8_t *data = (uint8_t *)avi_if;
+	uint8_t sum = 0;
+	unsigned i;
+
+	avi_if->checksum = 0;
+	avi_if->ecc = 0;
+	avi_if->padding = 0;
+
+	for (i = 0; i < sizeof(*avi_if); i++)
+		sum += data[i];
+
+	avi_if->checksum = 0x100 - sum;
+}
+
+static bool intel_hdmi_write_avi_infoframe(struct drm_encoder *encoder,
+					   uint8_t *data)
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	I915_WRITE(VIDEO_DIP_DATA, *((u32 *)data));
+	return true;
+}
+
+bool intel_hdmi_proc_infoframe(struct drm_encoder *encoder,
+			    struct dip_infoframe *avi_if,
+			    bool (*write_func)(struct drm_encoder *, uint8_t *))
+{
+	unsigned size;

drivers/gpu/drm/i915/intel_hdmi.c static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) · line 91

Quoted 10 lines
drivers/gpu/drm/i915/intel_hdmi.c +10 -0
+	uint8_t *data = (uint8_t *)avi_if;
+
+	intel_hdmi_calc_infoframe_csum(avi_if);
+	for (size = sizeof(*avi_if); size > 0; size -= 4) {
+		if (!write_func(encoder, data))
+			return false;
+		data += 4;
+	}
+	return true;
+}

This I think is unnecessary, especially as the current SDVO code handles it in 8 byte chunks.

Quoted 16 lines
drivers/gpu/drm/i915/intel_hdmi.c +16 -0
+
+static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
+{
+	struct dip_infoframe avi_if = {
+		.type = DIP_TYPE_AVI,
+		.ver = DIP_VERSION_AVI,
+		.len = DIP_LEN_AVI,
+		.Y_A_B_S = 0x02,
+		.C_M_R = 0x28,
+	};
+	struct drm_device *dev = encoder->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
+	u32 port;
+
+	if (!intel_hdmi->has_hdmi_sink)

drivers/gpu/drm/i915/intel_hdmi.c static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) · line 117

Quoted 10 lines
drivers/gpu/drm/i915/intel_hdmi.c +10 -0
+		return;
+
+	if (intel_hdmi->sdvox_reg == SDVOB)
+		port = VIDEO_DIP_PORT_B;
+	else if (intel_hdmi->sdvox_reg == SDVOC)
+		port = VIDEO_DIP_PORT_C;
+	else
+		return;
+
+	I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | port | VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC);

Split this up over multiple lines to fit within 80-columns.

drivers/gpu/drm/i915/intel_hdmi.c static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) · line 118

Quoted 1 line
drivers/gpu/drm/i915/intel_hdmi.c +1 -0
+	POSTING_READ(VIDEO_DIP_ENABLE);

Shouldn't need to flush the write here.

drivers/gpu/drm/i915/intel_hdmi.c static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) · line 119

Quoted 1 line
drivers/gpu/drm/i915/intel_hdmi.c +1 -0
+	intel_hdmi_proc_infoframe(encoder, &avi_if, intel_hdmi_write_avi_infoframe);

I think this works better as:

	intel_dip_infofame_csum(&avi_if);
	intel_hdmi_write_dip_infoframe(encoder, &avi_if);

drivers/gpu/drm/i915/intel_hdmi.c static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) · line 121

Quoted 2 lines
drivers/gpu/drm/i915/intel_hdmi.c +2 -0
+	I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | port | VIDEO_DIP_ENABLE_AVI | VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC);
+	POSTING_READ(VIDEO_DIP_ENABLE);

Same as above.

Thanks, adding a second copy of that data structure would have been too ugly.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
Quoted 9 lines · Chris Wilson
Quoted 6 lines · David Härdeman

This is the second version which merges the infoframe code from intel_hdmi.c and intel_sdvo.c, I hope this is something along the lines Chris Wilson had in mind. Note that I'm assuming that the sdvo hardware also stores a header ECC byte in the MSB of the first dword (haven't found
any documentation for the sdvo).

Quoted 8 lines

Pretty close. Using a callback function for writing the data is overkill, just call the common function to compute the avi csum, then pass the avi to the sdvo or hdmi handlers. It just makes following the logic that little bit easier.

drm-intel-next has changed slightly since you wrote the patch, so can you respin it - just a couple of the macro names have changed to be consistent.

I'll respin the patch, but I still need to know if the intel_sdvo.c hardware has an ECC byte as the MSB of the first dword or not.

Signature · 1 line
David Härdeman
#3 lore raw
In reply to Chris Wilson
Quoted 11 lines · Chris Wilson
Quoted 5 lines · David Härdeman

This is the second version which merges the infoframe code from intel_hdmi.c and intel_sdvo.c, I hope this is something along the lines Chris Wilson had in mind. Note that I'm assuming that the sdvo hardware also stores a header ECC byte in the MSB of the first dword (haven't found any documentation for the sdvo).

drm-intel-next has changed slightly since you wrote the patch, so can you
respin it - just a couple of the macro names have changed to be consistent.

I based my patch on this:
http://git.kernel.org/?p=linux/kernel/git/anholt/drm-intel.git;a=shortlog;h=drm-intel-next

And I'm not seeing any such changes...am I using the wrong tree/branch?

Signature · 1 line
David Härdeman
#4 lore raw
Quoted 2 lines · David Härdeman

I based my patch on this:
http://git.kernel.org/?p=linux/kernel/git/anholt/drm-intel.git;a=shortlog;h=drm-intel-next

Try:

http://git.kernel.org/?p=linux/kernel/git/ickle/drm-intel.git;a=shortlog;h=drm-intel-next

instead, thanks.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw
In reply to David Härdeman
Quoted 5 lines · David Härdeman

This is the second version which merges the infoframe code from intel_hdmi.c and intel_sdvo.c, I hope this is something along the lines Chris Wilson had in mind. Note that I'm assuming that the sdvo hardware also stores a header ECC byte in the MSB of the first dword (haven't found any documentation for the sdvo).

Just to clarify that last sentence a bit...

intel_sdvo.c currently defines this struct:

struct dip_infoframe {
	uint8_t type;
	uint8_t version;
	uint8_t len;
	uint8_t checksum;
	union {
		...
		uint8_t payload[28];
	] __attribute__ ((packed)) u;
} __attribute__((packed));

If the "checksum" member refers to the body checksum of the infoframe, then the payload size is incorrect. The checksum is the first byte of the body which is 28 bytes in total (HDMI spec 1.3a, table 5-15) so the payload array should be 27 bytes. If the payload size is corrected to 27 bytes, then the size of the entire struct is 31 bytes and the writing (which is done in 8 byte chunks in intel_sdvo.c) needs to be fixed.

If, on the other hand, the checksum field refers to the header ecc checksum, then the payload member is correctly sized but the body checksum is missing.

My guess is that the sdvo hardware has the same setup as described in
http://intellinuxgraphics.org/VOL_3_display_registers_updated.pdf,
section 2.8.9, meaning that the correct struct would be:

struct dip_infoframe {
	uint8_t type;
	uint8_t version;
	uint8_t len;
	uint8_t ecc;
	uint8_t checksum;
	union {
		...
		uint8_t payload[27];
	] __attribute__ ((packed)) u;
} __attribute__((packed));

Which would give a 32 byte struct which can be written in 8-byte chunks and which has the correct body size.

However, I can't confirm that suspicion...see:
http://software.intel.com/en-us/forums/showannouncement.php?a=17

Could someone at Intel please clarify?

On a related note, the struct currently defined in intel_sdvo.c relies on bitfields and expect the bits to be encoded in a certain order (which is the reason a casual reader might get the impression that the order of the members of the struct is reversed when compared to the relevant specs). However, the order of the bits within a unit is implementation-defined (C99, 6.7.2.1, point 10), so it shouldn't be relied upon...which is why I didn't use bitfields in my patch.

Signature · 1 line
David Härdeman