video: Fix issues with edid parsing
cover video: Fix issues with edid parsing
This series fixes some issues with edid parsing, which prevents some board/monitors combinations to work properly. Those issues were mainly found by using sunxi board (OrangePi 2) and DVI screen (Waveshare 10 inch, 1024x600). However, improvements should help other platforms too.
Patch 1 initializes and sets flags in timing info.
Patch 2 adds support for distinguishing HDMI and DVI monitor based on edid data.
Patch 3 use newly added flag in dw_hdmi driver to properly select DVI or HDMI mode.
Best regards,
Jernej
Jernej Skrabec (3):
edid: Set timings flags according to edid
edid: Add HDMI flag to timing info
video: dw_hdmi: Select HDMI mode only if monitor supports it
common/edid.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/video/dw_hdmi.c | 31 ++++++++++++++------------- include/edid.h | 14 +++++++++++++ include/fdtdec.h | 1 + 4 files changed, 87 insertions(+), 15 deletions(-)
Signature · 1 line
2.12.2
PATCH 1/3 edid: Set timings flags according to edid
Timing flags are never set, so they may contain garbage. Since some drivers check them, video output may be broken on those drivers.
Initialize them to 0 and check for few common flags.
---
common/edid.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
common/edid.c +14 -0
@@ -85,6 +85,7 @@ static void decode_timing(u8 *buf, struct display_timing *timing)uint x_mm, y_mm;unsigned int ha, hbl, hso, hspw, hborder;unsigned int va, vbl, vso, vspw, vborder; +struct edid_detailed_timing *t = (struct edid_detailed_timing *)buf;/* Edid contains pixel clock in terms of 10KHz */ set_entry (&timing->pixelclock, (buf[0 ] + (buf[1 ] <<8 )) *10000 );
@@ -111,6 +112,19 @@ static void decode_timing(u8 *buf, struct display_timing *timing)set_entry (&timing->vback_porch, vbl - vso - vspw);set_entry (&timing->vsync_len, vspw); + timing->flags =0 ; +if (EDID_DETAILED_TIMING_FLAG_HSYNC_POLARITY (*t)) + timing->flags |=DISPLAY_FLAGS_HSYNC_HIGH ; +else + timing->flags |=DISPLAY_FLAGS_HSYNC_LOW ; +if (EDID_DETAILED_TIMING_FLAG_VSYNC_POLARITY (*t)) + timing->flags |=DISPLAY_FLAGS_VSYNC_HIGH ; +else + timing->flags |=DISPLAY_FLAGS_VSYNC_LOW ; + +if (EDID_DETAILED_TIMING_FLAG_INTERLACED (*t)) + timing->flags =DISPLAY_FLAGS_INTERLACED ; + debug("Detailed mode clock %u Hz, %d mm x %d mm\n" " %04x %04x %04x %04x hborder %x\n" " %04x %04x %04x %04x vborder %x\n",
Signature · 1 line
2.12.2
PATCH 1/3 edid: Set timings flags according to edid
Quoted 10 lines · Jernej Skrabec
Timing flags are never set, so they may contain garbage. Since some drivers check them, video output may be broken on those drivers.
Initialize them to 0 and check for few common flags.
Signed-off-by Jernej Skrabec <[email protected]>---
common/edid.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
PATCH 1/3 edid: Set timings flags according to edid
In reply to Jernej SkrabecQuoted 10 lines · On Sat, 29 Apr 2017 14:43:35 +0200 Jernej Skrabec jernej.skrabec at siol.net…
Timing flags are never set, so they may contain garbage. Since some drivers check them, video output may be broken on those drivers.
Initialize them to 0 and check for few common flags.
Signed-off-by Jernej Skrabec <[email protected]>---
common/edid.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
applied to u-boot-video/master, thanks!
--
Anatolij
PATCH 2/3 edid: Add HDMI flag to timing info
In reply to Jernej SkrabecSome DVI monitors don't show anything in HDMI mode since audio stream confuses them. To solve this situation, this commit adds HDMI flag in timing data and sets it accordingly during edid parsing.
First existence of extension block is checked. If it exists and it is CEA861 extension, then data blocks are checked for presence of HDMI vendor specific data block. If it is present, HDMI flag is set.
---
common/edid.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/edid.h | 14 ++++++++++++++ include/fdtdec.h | 1 + 3 files changed, 57 insertions(+)
common/edid.c +42 -0
@@ -136,6 +136,39 @@ static void decode_timing(u8 *buf, struct display_timing *timing) va + vbl, vborder); } +/** +* Check if HDMI vendor specific data block is present in CEA block +* @param info CEA extension block +* @return true if block is found +*/ +static bool cea_is_hdmi_vsdb_present (struct edid_cea861_info *info) +{ +u8 end, i =0 ; + +/* check for end of data block */ + end = info->dtd_offset; +if (end ==0 ) + end =127 ; +if (end <4 || end >127 ) +return false; + end -=4 ; + +while (i < end) { +/* Look for vendor specific data block of appropriate size */ +if ((EDID_CEA861_DB_TYPE (*info, i) ==EDID_CEA861_DB_VENDOR ) && + (EDID_CEA861_DB_LEN (*info, i) >=5 )) { +u8 *db = &info->data[i +1 ]; +u32 oui = db[0 ] | (db[1 ] <<8 ) | (db[2 ] <<16 ); + +if (oui ==HDMI_IEEE_OUI ) +return true; + } + i +=EDID_CEA861_DB_LEN (*info, i) +1 ; + } + +return false; +} +int edid_get_timing (u8 *buf,int buf_size,struct display_timing *timing,int *panel_bits_per_colourp) {
@@ -181,6 +214,15 @@ int edid_get_timing(u8 *buf, int buf_size, struct display_timing *timing, ((edid->video_input_definition &0x70 ) >>3 ) +4 ; } + timing->hdmi_monitor = false; +if (edid->extension_flag && (buf_size >=EDID_EXT_SIZE )) { +struct edid_cea861_info *info = + (struct edid_cea861_info *)(buf +sizeof (*edid)); + +if (info->extension_tag ==EDID_CEA861_EXTENSION_TAG ) + timing->hdmi_monitor =cea_is_hdmi_vsdb_present (info); + } +return 0 ; }
include/edid.h +14 -0
@@ -19,6 +19,9 @@#define EDID_SIZE 128#define EDID_EXT_SIZE 256 +/* OUI of HDMI vendor specific data block */ +#define HDMI_IEEE_OUI 0x000c03 +#define GET_BIT (_x, _pos) \ (((_x) >> (_pos)) & 1)#define GET_BITS (_x, _pos_msb, _pos_lsb) \
@@ -234,6 +237,13 @@ struct edid1_info {unsigned char checksum; } __attribute__ ((__packed__)); +enum edid_cea861_db_types { +EDID_CEA861_DB_AUDIO =0x01 , +EDID_CEA861_DB_VIDEO =0x02 , +EDID_CEA861_DB_VENDOR =0x03 , +EDID_CEA861_DB_SPEAKER =0x04 , +}; +struct edid_cea861_info {unsigned char extension_tag;#define EDID_CEA861_EXTENSION_TAG 0x02
@@ -251,6 +261,10 @@ struct edid_cea861_info {#define EDID_CEA861_DTD_COUNT (_x) \ GET_BITS(((_x).dtd_count), 3, 0)unsigned char data[124 ]; +#define EDID_CEA861_DB_TYPE (_x, offset) \ + GET_BITS((_x).data[offset], 7, 5) +#define EDID_CEA861_DB_LEN (_x, offset) \ + GET_BITS((_x).data[offset], 4, 0) } __attribute__ ((__packed__));/**
include/fdtdec.h +1 -0
@@ -967,6 +967,7 @@ struct display_timing {struct timing_entry vsync_len;/* ver. sync len */ enum display_flags flags;/* display flags */ +bool hdmi_monitor;/* is hdmi monitor? */ };/**
Signature · 1 line
2.12.2
PATCH 2/3 edid: Add HDMI flag to timing info
Quoted 8 lines · Jernej Skrabec
Some DVI monitors don't show anything in HDMI mode since audio stream confuses them. To solve this situation, this commit adds HDMI flag in timing data and sets it accordingly during edid parsing.
First existence of extension block is checked. If it exists and it is CEA861 extension, then data blocks are checked for presence of HDMI vendor specific data block. If it is present, HDMI flag is set.
Quoted 7 lines
Signed-off-by Jernej Skrabec <[email protected]>---
common/edid.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/edid.h | 14 ++++++++++++++ include/fdtdec.h | 1 + 3 files changed, 57 insertions(+)
PATCH 2/3 edid: Add HDMI flag to timing info
In reply to Jernej SkrabecQuoted 8 lines · On Sat, 29 Apr 2017 14:43:36 +0200 Jernej Skrabec jernej.skrabec at siol.net…
Some DVI monitors don't show anything in HDMI mode since audio stream confuses them. To solve this situation, this commit adds HDMI flag in timing data and sets it accordingly during edid parsing.
First existence of extension block is checked. If it exists and it is CEA861 extension, then data blocks are checked for presence of HDMI vendor specific data block. If it is present, HDMI flag is set.
Quoted 7 lines
Signed-off-by Jernej Skrabec <[email protected]>---
common/edid.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/edid.h | 14 ++++++++++++++ include/fdtdec.h | 1 + 3 files changed, 57 insertions(+)
applied to u-boot-video/master, thanks!
--
Anatolij
PATCH 3/3 video: dw_hdmi: Select HDMI mode only if monitor supports it
In reply to Jernej SkrabecSome DVI monitors don't work in HDMI mode. Set it only if edid data explicitly states that it is supported.
---
drivers/video/dw_hdmi.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
drivers/video/dw_hdmi.c +16 -15
@@ -414,13 +414,9 @@ static void hdmi_av_composer(struct dw_hdmi *hdmi, HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_HIGH : HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_LOW); -/* -* TODO(sjg at chromium.org>: Need to check for HDMI / DVI -* inv_val |= (edid->hdmi_monitor_detected ? -* HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE : -* HDMI_FC_INVIDCONF_DVI_MODEZ_DVI_MODE); -*/ - inv_val |=HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE ; + inv_val |= (edid->hdmi_monitor ? +HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE : +HDMI_FC_INVIDCONF_DVI_MODEZ_DVI_MODE ); inv_val |=HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_LOW ;
@@ -459,7 +455,7 @@ static void hdmi_av_composer(struct dw_hdmi *hdmi, }/* hdmi initialization step b.4 */ -static void hdmi_enable_video_path (struct dw_hdmi *hdmi) +static void hdmi_enable_video_path (struct dw_hdmi *hdmi,bool audio) {uint clkdis;
@@ -484,8 +480,10 @@ static void hdmi_enable_video_path(struct dw_hdmi *hdmi) clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE ;hdmi_write (hdmi, clkdis,HDMI_MC_CLKDIS ); - clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE ; -hdmi_write (hdmi, clkdis,HDMI_MC_CLKDIS ); +if (audio) { + clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE ; +hdmi_write (hdmi, clkdis,HDMI_MC_CLKDIS ); + } }/* workaround to clear the overflow condition */
@@ -716,7 +714,8 @@ int dw_hdmi_enable(struct dw_hdmi *hdmi, const struct display_timing *edid) {int ret; -debug ("hdmi, mode info : clock %d hdis %d vdis %d\n" , +debug ("%s, mode info : clock %d hdis %d vdis %d\n" , + edid->hdmi_monitor ?"hdmi" :"dvi" , edid->pixelclock.typ, edid->hactive.typ, edid->vactive.typ);hdmi_av_composer (hdmi, edid);
@@ -725,11 +724,13 @@ int dw_hdmi_enable(struct dw_hdmi *hdmi, const struct display_timing *edid)if (ret)return ret; -hdmi_enable_video_path (hdmi); +hdmi_enable_video_path (hdmi, edid->hdmi_monitor); -hdmi_audio_fifo_reset (hdmi); -hdmi_audio_set_format (hdmi); -hdmi_audio_set_samplerate (hdmi, edid->pixelclock.typ); +if (edid->hdmi_monitor) { +hdmi_audio_fifo_reset (hdmi); +hdmi_audio_set_format (hdmi); +hdmi_audio_set_samplerate (hdmi, edid->pixelclock.typ); + }hdmi_video_packetize (hdmi);hdmi_video_sample (hdmi);
Signature · 1 line
2.12.2
PATCH 3/3 video: dw_hdmi: Select HDMI mode only if monitor supports it
Quoted 9 lines · Jernej Skrabec
Some DVI monitors don't work in HDMI mode. Set it only if edid data explicitly states that it is supported.
Signed-off-by Jernej Skrabec <[email protected]>---
drivers/video/dw_hdmi.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
PATCH 3/3 video: dw_hdmi: Select HDMI mode only if monitor supports it
In reply to Jernej SkrabecQuoted 8 lines · On Sat, 29 Apr 2017 14:43:37 +0200 Jernej Skrabec jernej.skrabec at siol.net…
Some DVI monitors don't work in HDMI mode. Set it only if edid data explicitly states that it is supported.
Signed-off-by Jernej Skrabec <[email protected]>---
drivers/video/dw_hdmi.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
applied to u-boot-video/master, thanks!
--
Anatolij