X11 Configuration / xrandr / Refresh Rates

I’m using the TX1 dev kit as a processing unit for a camera system. The output device (connected via HDMI) is a hardware recorder unit, and it is very picky about what refresh rates it will accept. It will only work with exact standards, so for the “60fps” I need that means either 59.94Hz or 60.00Hz.

Running xrandr shows that the refresh rates available for 3840x2160 are 60.02Hz or 59.98Hz. Neither of these are accepted by the recorder (it says “No Input”). The 30.00Hz option does work at that resolution, and the 60.00Hz option for 1920x1080 also works fine.

I’ve run cvt and it does look like it would be possible to create a custom mode for X11 that comes out to exactly 60.00Hz:
“3840x2160_60.00” 713.00 3840 4160 4576 5312 2160 2163 2168 2237 -HSync +VSync

I can add that mode with “xrandr --newmode …” but then I get an error when trying to assign that new mode to the display:

xrandr --addmode HDMI-0 "3840x2160_60.00"

X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 140 (RANDR)
Minor opcode of failed request: 18 (RRAddOutputMode)
Serial number of failed request: 20

I have also tried setting up the mode with xorg.config by adding it as a Modeline in the Monitor section, but that doesn’t appear to do anything. (I’ve tried many different configurations over the last few days, with ignoring EDID, ignoring EDID frequencies, custom EDID, ExactModeTimingsDVI, direct monitor assignment, specifying HorizSync/VertRefresh, and many combinations of those).

Can anyone help me add a custom mode to X11 so I can get the 4K UHD output actually running at exactly 60.00Hz?

If you go to this URL there is a modeline calculator:
https://arachnoid.com/modelines/

To recap, the modeline you have at exactly 60 Hz, but fails:

"3840x2160_60.00" 713.00 3840 4160 4576 5312 2160 2163 2168 2237 -HSync +VSync

When I use that modeline calculator for exactly 60 Hz, I get this:

# 3840x2160 @ 60.00 Hz (GTF) hsync: 134.10 kHz; pclk: 712.34 MHz
"3840x2160_60.00" 712.34 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync

When I use that modeline calculator for exactly 59.98 Hz, I get this:

# 3840x2160 @ 59.98 Hz (GTF) hsync: 134.06 kHz; pclk: 712.10 MHz
"3840x2160_59.98" 712.10 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync

…these are all very close, but you might try these very slightly different modelines.

I forgot to add that detail (been at this since Tuesday, so I’ve tried a lot of stuff). I tried both the cvt modeline (in my first post) and the gtf one that matches the calculator you used. I also tried both for 59.94Hz. All four have been tried in xorg.conf, and manually with xrandr. Here they all are:

# 3840x2160 60.00 Hz (CVT) hsync: 134.22 kHz; pclk: 713.00 MHz
    Modeline    "3840x2160_60.00cvt" 713.00 3840 4160 4576 5312 2160 2163 2168 2237 -HSync +VSync

    # 3840x2160 59.94 Hz (CVT) hsync: 134.08 kHz; pclk: 712.25 MHz
    Modeline    "3840x2160_59.94cvt" 712.25 3840 4160 4576 5312 2160 2163 2168 2237 -HSync +VSync

    # 3840x2160 @ 60.00 Hz (GTF) hsync: 134.10 kHz; pclk: 712.34 MHz
    Modeline    "3840x2160_60.00gtf" 712.34 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync

    # 3840x2160 @ 59.94 Hz (GTF) hsync: 133.97 kHz; pclk: 711.63 MHz
    Modeline    "3840x2160_59.94gtf" 711.63 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync

The xorg log shows that my xorg.conf is loading, and doesn’t have any fatal errors. It appears to select all the sections and options I specify, except when it comes to assigning the modes, where it does this:

[    24.163] (WW) NVIDIA(0): No valid modes for "DFP-0:3840x2160_60.00cvt"; removing.
[    24.164] (WW) NVIDIA(0): No valid modes for "DFP-0:3840x2160_59.94cvt"; removing.
[    24.164] (WW) NVIDIA(0): No valid modes for "DFP-0:3840x2160_60.00gtf"; removing.
[    24.164] (WW) NVIDIA(0): No valid modes for "DFP-0:3840x2160_59.94gtf"; removing.
[    24.164] (WW) NVIDIA(0): 
[    24.164] (WW) NVIDIA(0): Unable to validate any modes; falling back to the default mode
[    24.164] (WW) NVIDIA(0):     "nvidia-auto-select".
[    24.164] (WW) NVIDIA(0): 
[    24.164] (II) NVIDIA(0): Validated MetaModes:
[    24.164] (II) NVIDIA(0):     "DFP-0:nvidia-auto-select"

I’m wondering if perhaps the EDID data is disagreeing. What do you get from:

sudo -s
cat `find /sys -name 'edid'`
exit

What is the content of your “/etc/X11/xorg.conf”?

edid output:

00 ff ff ff ff ff ff 00 06 93 0d a7 01 00 00 00
 01 1a 01 03 80 50 2d 78 1a da ff a3 58 4a a2 29
 17 49 4b 20 00 00 01 01 01 01 01 01 01 01 01 01
 01 01 01 01 01 01 02 3a 80 18 71 38 2d 40 58 2c
 45 00 00 00 00 00 00 1e 01 1d 80 18 71 38 2d 40
 58 2c 45 00 00 00 00 00 00 1e 00 00 00 fc 00 53
 48 4f 47 55 4e 20 49 4e 46 52 4e 4f 00 00 00 fd
 00 18 78 0f 87 3c 00 0a 20 20 20 20 20 20 01 dc
 02 03 48 71 56 61 60 5f 5e 5d 66 65 64 63 62 3f
 40 10 1f 22 21 20 05 14 04 13 01 23 0f 04 07 83
 0f 00 00 6e 03 0c 00 10 00 18 3c 20 00 80 01 02
 03 04 67 d8 5d c4 01 78 80 00 e2 00 f9 e2 0f 63
 e3 05 ff 00 e3 06 07 01 02 3a 80 18 71 38 2d 40
 58 2c 45 00 00 00 00 00 00 1e 02 3a 80 d0 72 38
 2d 40 10 2c 45 80 00 00 00 00 00 1e 01 1d 80 18
 71 38 2d 40 58 2c 45 00 00 00 00 00 00 1e 00 db

I ran that through a parser, and it does appear to specify 3840x2160p @ 59.94Hz/60Hz in the video data block.

Current xorg.conf (has been tried with and without the EDID ignore options):

Section "ServerFlags"
    Option      "DefaultServerLayout" "Layout0"
EndSection

Section "Module"
    Disable     "dri"
    SubSection  "extmod"
        Option  "omit xfree86-dga"
    EndSubSection
EndSection

Section "Device"
    Identifier  "Tegra0"
    Driver      "nvidia"
    Option      "AllowEmptyInitialConfiguration" "true"
    Option      "ExactModeTimingsDVI" "true"
    Option      "Monitor-HDMI-0" "Rec0"
EndSection

Section "Monitor"
    Identifier  "Rec0"
    HorizSync    30.0 - 83.0
    VertRefresh  56.0 - 75.0
    Option      "IgnoreEDID" "true"
    Option      "UseEdidFreqs" "false"
    # 3840x2160 60.00 Hz (CVT) hsync: 134.22 kHz; pclk: 713.00 MHz
    Modeline    "3840x2160_60.00cvt" 713.00 3840 4160 4576 5312 2160 2163 2168 2237 -HSync +VSync

    # 3840x2160 59.94 Hz (CVT) hsync: 134.08 kHz; pclk: 712.25 MHz
    Modeline    "3840x2160_59.94cvt" 712.25 3840 4160 4576 5312 2160 2163 2168 2237 -HSync +VSync

    # 3840x2160 @ 60.00 Hz (GTF) hsync: 134.10 kHz; pclk: 712.34 MHz
    Modeline    "3840x2160_60.00gtf" 712.34 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync

    # 3840x2160 @ 59.94 Hz (GTF) hsync: 133.97 kHz; pclk: 711.63 MHz
    Modeline    "3840x2160_59.94gtf" 711.63 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync
EndSection

Section "Screen"
    Identifier  "Screen0"
    Device      "Tegra0"
    Monitor     "Rec0"
    DefaultDepth 24
    SubSection "Display"
        Depth      24
        Modes      "3840x2160_60.00cvt" "3840x2160_59.94cvt" "3840x2160_60.00gtf" "3840x2160_59.94gtf"
    EndSubSection
EndSection

Section "ServerLayout"
    Identifier     "Layout0"
    Screen         "Screen0"
EndSection

I think that EDID works with the modes you mentioned, you might double check here (just paste in the EDID data):
http://www.edidreader.com

The modes you reported as working are native, there may be a video or Xorg bug not working with the extension modes from EDID (non-native modes). Either this is the case or the driver itself does not allow those modes (e.g., being beyond the capability of the driver).

I had thought perhaps you could ignore the EDID, but your xorg.conf already does that. Does anything change when you comment these out:

#    Option      "IgnoreEDID" "true"
#    Option      "UseEdidFreqs" "false"

Someone who knows the limits of the video driver might be able to comment if those modes are within the hardware’s abilities.

I tried the ModeDebug option, and it appears that custom modes are disabled.

[    24.205] (WW) NVIDIA(GPU-0):   Validating Mode "3840x2160_60":
[    24.205] (WW) NVIDIA(GPU-0):     Mode Source: X Configuration file ModeLine
[    24.205] (WW) NVIDIA(GPU-0):     3840 x 2160 @ 60 Hz
[    24.205] (WW) NVIDIA(GPU-0):       Pixel Clock      : 713.00 MHz
[    24.205] (WW) NVIDIA(GPU-0):       HRes, HSyncStart : 3840, 4160
[    24.205] (WW) NVIDIA(GPU-0):       HSyncEnd, HTotal : 4576, 5312
[    24.205] (WW) NVIDIA(GPU-0):       VRes, VSyncStart : 2160, 2163
[    24.205] (WW) NVIDIA(GPU-0):       VSyncEnd, VTotal : 2168, 2237
[    24.205] (WW) NVIDIA(GPU-0):       H/V Polarity     : -/+
[    24.205] (WW) NVIDIA(GPU-0):     Mode is rejected: Only modes from the NVIDIA X driver's
[    24.205] (WW) NVIDIA(GPU-0):     predefined list and modes from the EDID are allowed
[    24.206] (WW) NVIDIA(GPU-0):     Mode "3840x2160_60" is invalid.
[    24.206] (WW) NVIDIA(GPU-0): 
[    24.206] (WW) NVIDIA(GPU-0):   Validating Mode "3840x2160_60":
[    24.206] (WW) NVIDIA(GPU-0):     Mode Source: X Configuration file ModeLine
[    24.206] (WW) NVIDIA(GPU-0):     3840 x 2160 @ 60 Hz
[    24.206] (WW) NVIDIA(GPU-0):       Pixel Clock      : 712.25 MHz
[    24.206] (WW) NVIDIA(GPU-0):       HRes, HSyncStart : 3840, 4160
[    24.206] (WW) NVIDIA(GPU-0):       HSyncEnd, HTotal : 4576, 5312
[    24.206] (WW) NVIDIA(GPU-0):       VRes, VSyncStart : 2160, 2163
[    24.206] (WW) NVIDIA(GPU-0):       VSyncEnd, VTotal : 2168, 2237
[    24.206] (WW) NVIDIA(GPU-0):       H/V Polarity     : -/+
[    24.206] (WW) NVIDIA(GPU-0):     Mode is rejected: Only modes from the NVIDIA X driver's
[    24.206] (WW) NVIDIA(GPU-0):     predefined list and modes from the EDID are allowed
[    24.206] (WW) NVIDIA(GPU-0):     Mode "3840x2160_60" is invalid.
[    24.206] (WW) NVIDIA(GPU-0): 
[    24.206] (WW) NVIDIA(GPU-0):   Validating Mode "3840x2160_60":
[    24.206] (WW) NVIDIA(GPU-0):     Mode Source: X Configuration file ModeLine
[    24.206] (WW) NVIDIA(GPU-0):     3840 x 2160 @ 60 Hz
[    24.206] (WW) NVIDIA(GPU-0):       Pixel Clock      : 712.34 MHz
[    24.206] (WW) NVIDIA(GPU-0):       HRes, HSyncStart : 3840, 4152
[    24.206] (WW) NVIDIA(GPU-0):       HSyncEnd, HTotal : 4576, 5312
[    24.206] (WW) NVIDIA(GPU-0):       VRes, VSyncStart : 2160, 2161
[    24.206] (WW) NVIDIA(GPU-0):       VSyncEnd, VTotal : 2164, 2235
[    24.206] (WW) NVIDIA(GPU-0):       H/V Polarity     : -/+
[    24.206] (WW) NVIDIA(GPU-0):     Mode is rejected: Only modes from the NVIDIA X driver's
[    24.206] (WW) NVIDIA(GPU-0):     predefined list and modes from the EDID are allowed
[    24.206] (WW) NVIDIA(GPU-0):     Mode "3840x2160_60" is invalid.
[    24.206] (WW) NVIDIA(GPU-0): 
[    24.206] (WW) NVIDIA(GPU-0):   Validating Mode "3840x2160_60":
[    24.206] (WW) NVIDIA(GPU-0):     Mode Source: X Configuration file ModeLine
[    24.206] (WW) NVIDIA(GPU-0):     3840 x 2160 @ 60 Hz
[    24.206] (WW) NVIDIA(GPU-0):       Pixel Clock      : 711.63 MHz
[    24.206] (WW) NVIDIA(GPU-0):       HRes, HSyncStart : 3840, 4152
[    24.206] (WW) NVIDIA(GPU-0):       HSyncEnd, HTotal : 4576, 5312
[    24.206] (WW) NVIDIA(GPU-0):       VRes, VSyncStart : 2160, 2161
[    24.206] (WW) NVIDIA(GPU-0):       VSyncEnd, VTotal : 2164, 2235
[    24.206] (WW) NVIDIA(GPU-0):       H/V Polarity     : -/+
[    24.206] (WW) NVIDIA(GPU-0):     Mode is rejected: Only modes from the NVIDIA X driver's
[    24.206] (WW) NVIDIA(GPU-0):     predefined list and modes from the EDID are allowed
[    24.206] (WW) NVIDIA(GPU-0):     Mode "3840x2160_60" is invalid.

So, now I just need to convince it to accept modelines from the xorg.conf

Aha…this says a LOT:

(WW) NVIDIA(GPU-0):     Mode is rejected: Only modes from the NVIDIA X driver's
(WW) NVIDIA(GPU-0):     predefined list and modes from the EDID are allowed
(WW) NVIDIA(GPU-0):     Mode "3840x2160_60" is invalid.

I think we are on to something which has had an effect on many users on all of the Jetson platforms. Can someone from NVIDIA find out what modes the graphics driver does predefine? Also, is there some hardware limitation which prevents anything but predefined modes from being used? Knowing this could lead to a breakthrough on why many valid EDIDs are not working.

Btw, when all modes are rejected the proper thing to do would be to fall back to 640x480@60Hz. Other modes should not be used for fallback unless there is a reason. Ever since the days of old VGA 640x480@60Hz has bee defined as one of the standard modes, and when changing drivers (e.g., upgrade), this mode was considered the “safe” mode to manually switch to prior to changing drivers. I don’t know if there is actually some standard for this, but this has been at minimum the de facto mode to expect to work in case all automatic configuration fails. I will suggest that the video driver in L4T (all of them…TK1 through TX2) make 640x480@60Hz the fallback…this would leave a usable display for debugging in cases where EDID does not succeed.

I only included the custom ones I added with modelines. There are a lot more in the debug that come from the driver and the EDID that end up passing validation. If there really was nothing to use then 640x480 would be a safe fallback, but in this case it is finding other modes, and using the preferred one from the EDID.

It’s also been a pain trying to find documentation on what options will work in xorg.conf. Most of what I find is for the XFree86 version, and most of the options listed, specifically the ModeValidation ones that appear to do exactly what I need, don’t actually work in the Nvidia X version (x log notes that they are not valid and being ignored).

Ok… bumping this again looking for some more help.

The debug says that only modes from the EDID or the NVIDIA X driver are allowed. I attempted to use a custom EDID file (started with a copy of the one from my device, then altered it to include the corrected refresh rate), but X seems to be ignoring the CustomEDID option.

My next idea would be to alter what’s baked into the NVIDIA X driver. Linux_for_Tegra_64_tx1/sources/kernel_source/drivers/video/tegra/dc/modedb.c appears to have video modes defined. Does anyone know if that’s what will get used by X11?

Before the 4.x kernel series the mode setting was through X and the video driver. This implied that console modes and GUI modes had separate mode setting software. In the 4.x kernel series the separate mode setting in X was removed, and all mode setting was put into the kernel. The kernel still must talk to the NVIDIA video driver…what changes is the path of software leading up to asking the video driver to load a different mode. Restrictions on what is asked of the NVIDIA video driver could be modified in the kernel, but what the NVIDIA video driver allows could not be changed there.

There is a need for NVIDIA to publish what modes which are available in the TX2 (and K1 and TX1) video drivers. If there is a hardware restriction to the extension modes listed in this thread which had valid EDID it would be good to know…if it is a software restriction, then it would be good to see if this can be adjusted for valid EDID modes which are currently being rejected.

Also forgot to add… before anyone notes that the modes I was trying before have too high a pixel clock for the TX1, here’s the updated modeline that fits within the limitations:

Modeline    "4k60"  533.25  3840 3888 3920 4000  2160 2163 2168 2222 +hsync -vsync

Is it correct that this modeline is rejected?

Yes, and for the same reason as the others: “Only modes from the NVIDIA X driver’s predefined list and modes from the EDID are allowed”

Turns out the modes available can be edited in the kernel source, then compiled.

[JetPack Install Dir]/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/drivers/video/modedb.c contains the definitions of the modes used by the framebuffer and X11 in const struct fb_videomode cea_modes. In my specific example:

/* 97: 3840x2160p @ 60Hz */
	{.refresh = 60, .xres = 3840, .yres = 2160, .pixclock = 1683,
	 .left_margin = 296, .right_margin = 176,
	 .upper_margin = 72, .lower_margin = 8,
	 .hsync_len = 88, .vsync_len = 10,
	 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
	 .flag = FB_FLAG_RATIO_16_9,
	 .vmode = FB_VMODE_NONINTERLACED},

This defines the 4K UHD @ 60fps mode. While modeline calculators and EDID editors alter the pixel clock in terms of MHz, the way they are defined in modedb.c is as a picosecond divisor. As seen above, the pixclock is set to 1683. 1000000/pixclock = the value in MHz for a modeline (e.g. 1683 -> 1000000/1683 -> 594.18).

The main problem is that this way of defining the pixel clock has a different granularity than the modelines and EDID definitions. While this is one is the closest match for the desired MHz, it creates a rounding error that leads to the 60.02Hz refresh rate (that then gets rejected by devices that have strict allowances).

So, the solution is:

  1. Use a tool that creates modes based off of the modedb.c pixclock format, rather than a "close enough" calculation based on a MHz format.
  2. Alter [JetPack Install Dir]/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/drivers/video/modedb.c -> const struct fb_videomode cea_modes to use the new mode.
  3. Compile the kernel.
  4. Either move the required files (zImage, Image, device tree binaries, modules) to the TX1 and restart, or to the JetPack locaions and flash the TX1.
  5. Configure X11 (/etc/X11/xorg.conf) to use the altered mode.

This is very valuable information! Good to know.

Perhaps a patch is needed for cases of the MHz format needing to find the closest pixclock instead of relying on an exact answer (maybe a case of floating point values being close but not exact causing the mode to be rejected)…many video issues would simply go away.

I tested it on newer release (cf https://devtalk.nvidia.com/default/topic/1016146/jetson-tx2/tx2-development-kit-4k-doesn-t-work-boot-fails-/3, pages 2 and 3).

Same rejection message.

There are several things that I don’t understand/can’t get to work:

  • What tool can be used to make the conversion to put mode into cea_modes? I have no idea how to calculate the left margin values etc.
  • In R28.1 modedb.c, there are four hdmi_ext_modes which resemble what xrandr outputs when plugged to a UHD monitor (23.98Hz, 24Hz, 25Hz, 30Hz modes only for 3840x2160). The pixel clock seems way too low at 3367 (=297Mhz, insufficient for 2160p60). There seems to be nothing about cea_modes (one of which is described as “3840x2160 60Hz”). This mode has a 1683 pixclock which translates to ~594.18MHz with your formula. 594MHz seems a lot better to output 2160p60 than 297MHz. I tried replacing the 30Hz in hdmi_ext_modes (which is the default) with the 60Hz from cea_modes, but it doesn’t change anything (clock is still reported at 297Mhz in boot log and refresh rate is still 30Hz).
  • Calculations from gtf seem wrong to me (as I’ve never seen a 712MHz pix clock, it seems way too high). I also don’t know what all the others number mean (other than 3840 and 2160).

EDIT: in my opinion, a better option would be to convert the “cea_modes” 3840x2160 @ 60Hz entry to a ModeLine that checks out. It avoids recompiling the kernel and modifying driver constants.

There were some modes which need a patch, I don’t know which those are (NVIDIA would need to comment…it is a recent topic and apparently the patch is needed even in R28.1). This may be one of those modes.

I found a workwaround.

On my other post (https://devtalk.nvidia.com/default/topic/1016146/jetson-tx2/tx2-development-kit-4k-doesn-t-work-boot-fails-/, same as above), WayneWWW suggested a patch. It turns out that this patch is a workaround to make UHD work at 60Hz.

The basic idea is to replace the clock with a static pixel clock higher than the normal one using 3840x2160 @ 30Hz (artificially increasing frame rate).
It’s done in /display/drivers/video/tegra/dc/hdmi2.0.c by replacing the

return pclk;

by

return 593583416;

WayneWWW initially suggested using 533250000 which resulted (as reported by the monitor) in a 56Hz refresh rate.
I took the 3840x2160 @ 60Hz entry in “cea_modes” in modedb.c, and calculated the clock with your formula. It gave me a 594177000 clock -rounded to the KHz-, which didn’t work - monitor black).
I made a few other attempts including multiplying it by 1000 and dividing by 1001 which gave me the value 593583416. Now it works on my Dell UP3216Q which reports 60Hz.

The Jetson still thinks it’s outputting 30Hz. But the mouse is definitely more fluid.

Crazy workaround, but it seems to work !