Elitebook 840 Docking/Undocking laptop screen issues

I have a recent install of Manjaro KDE on a HP Elitebook 840 G5, and I am using the HP Ultraslim docking station, everything works apart from undocking if I start the laptop docked.

Symptoms - If the laptop is started with the lid closed and docked, NO mode settings are found for the screen and xrandr indicates the following (using the Intel driver, the modesetting driver does have modes but they are wrong) -

Output eDP1 is not disconnected but has no modes.

If I try and add modes, it allows it, but undocking still results in a black screen on the laptop screen (on both drivers). I have tried to then SSH in and execute - xrandr --output eDP1 --auto (or the actual added mode as below), but it fails with -

xrandr: Configure crtc 0 failed

I have tried to add the mode by both --addmode for xrandr (and used cvt to get the settings - unfortunately, the xorg.0.log does not contain the necessary information from the Arch wiki on xrandr and Adding_undetected_resolutions) or putting the necessary lines in 10-monitor.conf under /etc/X11/xorg.conf.d.

xrandr command -

xrandr --newmode "1920x1080_120.00" 369.75 1920 2080 2288 2656 1080 1083 1088 1160 -hsync +vsync

xrandr --addmode eDP1 1920x1080_120.00

xorg config -

Section “Monitor”
Identifier “eDP1” Modeline “1920x1080_120.00” 369.75 1920 2080 2288 2656 1080 1083 1088 1160 -hsync +vsync
Option “PreferredMode” “1920x1080_120.00”
EndSection

If I start the laptop with the screen open, but docked, the modes are are detected correctly on both the Intel driver, and the modesetting driver.

However, if you undock the laptop with the Intel driver (undocking works fine) and then redock it, the external screen comes up and the laptop screen goes dark, but about 5/10 seconds later, the external screen also goes dark and I see a log entry within journalctl for -

Jan 13 22:20:58 Misaka kscreen_backend_launcher[1372]: kscreen.xrandr: Output 71 : connected = true , enabled = true

Jan 13 22:20:58 Misaka upowerd[1293]: treating change event as add on /sys/devices/pci0000:00/0000:00:14.0/usb2/2-4

Jan 13 22:20:58 Misaka kscreen_backend_launcher[1372]: kscreen.xrandr: Emitting configChanged()

Various messages re networking reconnecting on the dock etc…

Jan 13 22:21:07 Misaka kscreen_backend_launcher[1372]: kscreen.xrandr: Output 71 : connected = true , enabled = false

Jan 13 22:21:07 Misaka kscreen_backend_launcher[1372]: kscreen.xrandr: Emitting configChanged()

Jan 13 22:21:08 Misaka kded5[1159]: kscreen.kded: Config does not have at least one screen enabled, WILL NOT save this config, this is not what user wants.

I can see in the logs that Output 71 is the external screen and Output 67 is the laptop screen. At this point as well, with the Intel driver, plasma crashes and I have to issue -

kwin_x11 --replace; plasmashell --replace

I do not have to do this with the modesetting driver.

Finally, if I start the laptop undocked, and then dock it, EVERYTHING works as expected. I can dock and undock as often as I want, and both drivers work without issue, the screens switch as necessary. While this is a workaround, I would rather get it working correctly, as I will often start and use the laptop docked. In this case, the Intel driver seems to work fine so will stay with that, the marginal benefit of the modesetting driver working in one small instance doesn’t seem to be worth the performance penalty.

Also, this is using both the 5.4 and 5.10 kernel.

I can post the full exported logs for when the laptop is undocked and then redocked, if I have missed something important. I have also tried to use autorandr and set it up with docked and mobile profiles, but that also doesn’t work. It is clearly related to the laptop screen not being properly detected when closed on boot, but am unsure where to go with it. I have looked at the i915 module options here - Arch Wiki and Intel driver - Module-based_options but cannot see anything obvious that would help.

Thanks!