Detect LVDS or HMI and set the vidargs accordingly in U-boot

Hi

I have IMX6 module plugged into the custom board which has HDMI output to monitor and LVDS display

Yocto version is thud (2.6.4)

root@apalis-imx6:~# uname -a
Linux apalis-imx6 4.14.170-3.0.4+gbaa6c24240a4 #1 SMP Thu Jul 11 11:39:01 UTC 2024 armv7l armv7l armv7l GNU/Linux

How can I set the vidargs depending upon the display connected on the startup of the imx6 module?
if LVDS display is connected then execute

setenv vidargs 'video=mxcfb0:dev=ldb,if=RGB24 fbmem=32M'

if HDMI display is connected then execute
setenv vidargs ‘mxc_hdmi.only_cea=1 video=mxcfb0:dev=hdmi,1920x1080M@60,if=RGB24 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off fbmem=32M’

I shall be thankful to you

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


:handshake:

To set the vidargs depending on whether an LVDS or HDMI display is connected at startup on your i.MX6 module, you can use a script in U-Boot to detect the display type and set the appropriate environment variables. Here’s a step-by-step guide:

  1. Modify U-Boot Script:
    Create a U-Boot script that checks for the presence of an HDMI display and sets the vidargs accordingly. If HDMI is not detected, it defaults to LVDS.

  2. Detect HDMI Display:
    Use the i2c command in U-Boot to check for the presence of an HDMI display. HDMI displays typically have an EDID EEPROM that can be read over I2C.

  3. Set Environment Variables:
    Based on the detection, set the vidargs environment variable.

Here is an example U-Boot script:

# Check for HDMI display by reading EDID over I2C
i2c dev 2
i2c probe 0x50
if test $? -eq 0; then
    # HDMI display detected
    setenv vidargs 'mxc_hdmi.only_cea=1 video=mxcfb0:dev=hdmi,1920x1080M@60,if=RGB24 video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off fbmem=32M'
else
    # Default to LVDS display
    setenv vidargs 'video=mxcfb0:dev=ldb,if=RGB24 fbmem=32M'
fi

# Save the environment variables
saveenv
  1. Integrate Script into U-Boot:
    You can integrate this script into your U-Boot environment by adding it to the boot command sequence. For example, you can add it to the bootcmd environment variable:
setenv bootcmd 'run detect_display; run boot_sequence'
setenv detect_display 'i2c dev 2; i2c probe 0x50; if test $? -eq 0; then setenv vidargs "mxc_hdmi.only_cea=1 video=mxcfb0:dev=hdmi,1920x1080M@60,if=RGB24 video=mxcfb1:off video=mxcfb2:off video=mxcfb3

this script has some issues. I am not familiar much with U-Boot. Can someone help me out? Thanks

Hello @Usman,

While the approach suggested by @ToradexAI is not absurd and could work for some use cases, I don’t believe it will work for the Apalis iMX6.

What you could do is check the status of the HDMI_IH_PHY_STAT0 register.
When the system boots without HDMI connected it should be 0, otherwise it should be different from 0.

Here is an example of running this on u-boot:

setexpr.b hdmistat *120104
if test "${hdmistat}" = "00"; then echo "HDMI was not connected"; else echo "HDMI was connected"; fi

Best Regards,
Bruno

Hi @bruno.tx ,

i have tested it out and it works. I am wondering from where this memory address *120104 comes from. Can we put general purpose register. I am asking if upgrade the version of U-boot, this may fail.

Through i2c I tried to detect the HDMI bus and in the kernel space I see the bus 3 is connected to HDMI

root@apalis-imx6:~# i2cdetect 2 
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- UU -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
root@apalis-imx6:~# i2cdetect 1 
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n] ^[[Ay
Aborting on user request.
root@apalis-imx6:~# i2cdetect 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
root@apalis-imx6:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- UU UU -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
root@apalis-imx6:~# i2cdetect 3 
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- 38 -- 3a 3b -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: UU -- -- -- 54 -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

But in the U-boot space, there is no bus 3

Apalis iMX6 # i2c dev 3
Setting bus to 3
Failure changing bus number (-19)
Apalis iMX6 # i2c dev 1
Setting bus to 1
Apalis iMX6 # i2c probe
Valid chip addresses: 00 08 41 78
Apalis iMX6 # i2c dev 0
Setting bus to 0
Apalis iMX6 # i2c probe
Valid chip addresses: 21 22
Apalis iMX6 # i2c dev 2
Setting bus to 2
Apalis iMX6 # i2c probe
Valid chip addresses:
Apalis iMX6 # i2c dev 3
Setting bus to 3
Failure changing bus number (-19)
Apalis iMX6 # i2c probe
Valid chip addresses:

where to find the dts file used in my Uboot?

Thanks for your reply

Hello @Usman,

This is the address of the PHY Interface Interrupt Status Register (HDMI_IH_PHY_STAT0).
Therefore it should not change even if u-boot is updated.
You can check more information about it in the i.MX6Q/D Reference Manual (Requires Login).

About the device tree for the module, it should be available in the u-boot repository.
Which version of the repository will depend on which version you are using of u-boot.
For example: imx6-apalis.dts « dts « arm « arch - u-boot-toradex.git - U-Boot bootloader for Apalis and Colibri modules

Best Regards,
Bruno

Hi @bruno.tx

This check works fine if I have carrier board with HDMI and LVDS display ports and either of the ports are connected. Old carrier boards have Display port and LVDS. This solution does not work with the old carrier boards,

In older boards it always landed on else condition.

How can I make the generic solution. Can we read out the status of LVDS status instead? Thanks

Usman

Hello @Usman,

This behavior indicates that the boards with DisplayPort always keep the HDMI interface “connected”.
Therefore, it may be hard to determine which one of the interfaces is connected in this case.

Checking with LVDS is connected may be possible, if your LVDS display has an I2C address that can be checked in u-boot.
However, this will be very specific to your design, so you need to check if this would be possible in your specific setup.

Best Regards,
Bruno

Unfortunately i2c probe does not show any devices but I came up with one simple solution in my case

On older boards with DP and LVDS ports ${hdmistat} always give 3 (the hardware nice in that board is not properly connected but it is of no use physically)

and in new boards (with LVDS and HDMI display ports enabled) shows ${hdmistat} to 0 when HDMI cable is not connected and ${hdmistat} to 3d when HDMI cable is connected so I do following in UBoot

setenv detect_disp 'setexpr.b hdmistat *120104; if test ${hdmistat} = 3d; then run hdmi_vidargs; else run lvds_vidargs; fi; '

Thanks alot @bruno.tx for your suggestions

Hello @Usman,

It is good to know you found a suitable solution.
Thanks for the update.

Best Regards,
Bruno