Wednesday, November 20, 2019

Weirdness with VGA to HDMI adapter and i915

So I've got an older TV that I wanted to use with a laptop and do triple monitors. The laptop has got its own 1600x900 built-in screen, and on the hdmi port I've connected a DVI 1920x1200 monitor and then there's a Toshiba 40FT1U on the VGA port.

The only problem is that the Toshiba 40FT1U doesn't like anything higher than 1280x1024 or 1366x768 on the VGA port. Checking with the manual, sure enough that's the maximum on VGA-in but HDMI-in will give you the full 1080p resolution.



I got on ebay and found a cheap VGA to HDMI adapter. The only problem is that I couldn't get Ubuntu 19.04 to output a video signal that xrandr would like.

The VGA to HDMI adapter had no EDID information, and get-edid wouldn't return anything.

Firing up cvt 1920 1080 60, I would make an xrandr newmode of 1920x1080.


$ cvt 1920 1080 60
# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
$ xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
$ xrandr --addmode VGA-1 "1920x1080_60.00"
$ xrandr --output VGA-1 --mode "1920x1080_60.00"
xrandr: Configure crtc 1 failed



Sadly, that didn't work at all giving a "Configure crtc 1 failed" message.

Looking at my xorg log it says just Invalid argument:


$ less ~/.local/share/xorg/Xorg.0.log 
[   405.766] (II) modeset(0): Allocate new frame buffer 5440x1200 stride
[  1196.778] (EE) modeset(0): failed to set mode: Invalid argument




What's strange is that I can do a resolution of 1912x1080:


$ cvt 1912 1080 60
# 1912x1080 59.91 Hz (CVT) hsync: 67.10 kHz; pclk: 171.25 MHz
Modeline "1912x1080_60.00"  171.25  1912 2032 2232 2552  1080 1083 1093 1120 -hsync +vsync
$ xrandr --newmode "1912x1080_60.00"  171.25  1912 2032 2232 2552  1080 1083 1093 1120 -hsync +vsync
$ xrandr --addmode VGA-1 "1912x1080_60.00"
$ xrandr --output VGA-1 --mode "1912x1080_60.00"



So 1912x1080x60 works no problem, which is really strange. The only problem is that my VGA to HDMI adapter scrunches the screen horizontally, which is usable but it offends me terribly. Not having 1 to 1 pixels grated on me.

I've got another television a 50 inch emerson with a VGA input, and weirdly, plugging the VGA into it allows me to set a 1920x1080x60 resolution. Oddly, it has no EDID information either but the 1920x1080 resolution will work.


So I thought, let's see if we can get a working edid from another monitor and use that.

On another system with a sceptre monitor that was 1920x1080 I ran "sudo get-edid > sceptre_edid.bin".

Then I made a /usr/firmware/edid directory with "sudo mkdir /usr/firmware/edid" then "sudo cp sceptre_edid.bin /usr/firmware/edid/"/

Locating the file /etc/default/grub and running "sudo nano /etc/default/grub"


and making these changes:
GRUB_TIMEOUT=10
GRUB_TIMEOUT_STYLE=menu

GRUB_CMDLINE_LINUX=" drm.edid_firmware=VGA-1:edid/sceptre_edid.bin"



then "sudo update-grub"

and now it comes up just fine with 1920x1080 on the VGA-1 port.

So what is actually not working? Let's take a closer look at the EDID file with parse-edid.


$ cat sceptre_edid.bin | parse-edid
Checksum Correct

Section "Monitor"
 Identifier "E275W-1920"
 ModelName "E275W-1920"
 VendorName "SPT"
 # Monitor Manufactured week 6 of 2015
 # EDID version 1.3
 # Analog Display
 Option "SyncOnGreen" "true"
 DisplaySize 600 340
 Gamma 2.20
 Option "DPMS" "true"
 Horizsync 30-95
 VertRefresh 56-75
 # Maximum pixel clock is 180MHz
 #Not giving standard mode: 1280x800, 60Hz
 #Not giving standard mode: 1280x960, 60Hz
 #Not giving standard mode: 1280x1024, 60Hz
 #Not giving standard mode: 1440x900, 60Hz
 #Not giving standard mode: 1600x1200, 60Hz
 #Not giving standard mode: 1680x1050, 60Hz
 Modeline  "Mode 0" 148.50 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync 
 Modeline  "Mode 1" 118.97 1600 1712 1864 2112 900 901 904 932 -hsync +vsync 
EndSection


That modeline of "Mode 0" is 1920x1080 but the numbers are different from what cvt gives:


Comparing the two modelines, the numbers vary slightly and the hsync is opposite polarity.

Modeline "1920x1080_60.00"  173.00   1920 2048 2248 2576   1080 1083 1088 1120 -hsync +vsync
Modeline "Mode 0"           148.50   1920 2008 2052 2200   1080 1084 1089 1125 +hsync +vsync


Let's compare it to a reduced blanking modeline from cvt, now you'll notice that the vsync is opposite.

$ cvt 1920 1080 60 -r
# 1920x1080 59.93 Hz (CVT 2.07M9-R) hsync: 66.59 kHz; pclk: 138.50 MHz
Modeline "1920x1080R" 138.50 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync
Modeline "Mode 0" 148.50 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync



So I tried rebooting ubuntu *without* the drm.edid_firmware=VGA-1:edid/sceptre_edid.bin and it went right back to hating my cvt 1920 1080 60 modeline.

But let's try the modeline from the sceptre edid "Mode 0".

$ xrandr --newmode "Mode 0" 148.50 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync
$ xrandr --addmode VGA-1 "Mode 0"
$ xrandr --output VGA-1 --mode "Mode 0"

Hah! It likes that modeline!

It also seems to like the reduced blanking version.

$ cvt -r 1920 1080 60
# 1920x1080 59.93 Hz (CVT 2.07M9-R) hsync: 66.59 kHz; pclk: 138.50 MHz
Modeline "1920x1080R" 138.50 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync
$ xrandr --newmode "1920x1080R" 138.50 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync
$ xrandr --addmode VGA-1 "1920x1080R"
$ xrandr --output VGA-1 --mode "1920x1080R"


I also tried gtf and that didn't work. xrandr: Configure crtc 1 failed

Strangely, using drm.edid_firmware=VGA-1:edid/1920x1080.bin would work on the VGA to HDMI but for some reason I'd lose the other monitor.
(This would use a "built-in" 1920x1080 edid file)


The actual 1920x1080 timings can vary, here's a couple of monitors that have 1125 as the last number of the modeline.


From https://cdn.kramerav.com/web/downloads/white-papers/analog_edid_whitepaper_6.pdf:

"Knowing that the standardization problem exists mostly in widescreen resolutions, let us look at an example using 1920x1080.
These mode lines came from the EDIDs of the computer graphics video inputs of different 1080p monitors:"


Monitor 1 – LG LCD 
• Detailed timing #1....... 1920x1080p at 60Hz (16:9) 
• Mode line............... “1920x1080” 148.500 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync 
Monitor 2 – Westinghouse LCD 
• Native/preferred timing.... 1920x1080p at 60Hz (16:9) 
• Mode line............... “1920x1080” 138.500 1920 1968 2000 2080 1080 1082 1087 1111 +hsync -vsync 
Monitor 3 – Samsung LCD 
• Native/preferred timing.. 1920x1080p at 60Hz (16:9) 
• Mode line............... “1920x1080” 138.500 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync 
Monitor 4 – Panasonic Plasma 
• Detailed timing #1....... 1920x1080p at 60Hz 
• Mode line............... “1920x1080” 148.500 1920 2008 2052 2200 1080 1084 1089 1125 -hsync –vsync 
Monitor 5 – Vizio LCD 
• Native/preferred timing.. 1920x1080p at 60Hz 
• Mode line............... “1920x1080” 136.500 1920 1952 1984 2048 1080 1081 1084 1111 +hsync +vsync 

"You can clearly see that while all these monitors claim to be 1920x1080 monitors, they each support a different version of 1920x1080. It is also clear that describing active pixels alone is not specific enough to define a resolution. Display manufacturers have taken to producing non-standard displays, because the specific timings are completely described in the EDID of the monitors they build. When a computer is connected directly to any of these monitors, the mode line is read by the PC and automatically the PC modifies its output to comply properly with that display."



Now with the edid file I can get my VGA to HDMI adapter to work with full 1920x1080 resolution automatically or using the "Mode 0" modeline from the edid file I can get xrandr to work. The VGA to HDMI output really looks good on the tv.