Skip to contentSkip to conversation

Provide workarounds to use DRM/KMS with broken graphics hardware

PATCH Superseded Carsten Emde 4 participants 7 messages Mar 15, 2012

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Provide workarounds to use DRM/KMS with broken graphics hardware

Changes from V2 to V3:

1. The help text of the DRM_LOAD_EDID_FIRMWARE Kconfig item and the related explanation in Documentation/kernel-parameters.txt now contain a pointer to the documentation as suggested by Paul.
2. Removed the "brightness_inverted" parameter of the i915 module and replaced it by a quirk that is specific to the affected Acer Aspire 5734Z notebook as suggested by Keith.

Thanks,
-Carsten.

#1 lore raw

PATCH v3 1/2 drivers-gpu-drm-allow-to-load-edid-firmware.patch

Broken monitors and/or broken graphic boards may send erroneous or no EDID data. This also applies to broken KVM devices that are unable to correctly forward the EDID data of the connected monitor but invent their own fantasy data.

This patch allows to specify an EDID data set to be used instead of probing the monitor for it. It contains built-in data sets of frequently used screen resolutions. In addition, a particular EDID data set may be provided in the /lib/firmware directory and loaded via the firmware interface. The name is passed to the kernel as module parameter of the drm_kms_helper module either when loaded
options drm_kms_helper edid_firmware=edid/1280x1024.bin
or as kernel commandline parameter
drm_kms_helper.edid_firmware=edid/1280x1024.bin

The built-in data sets are
Resolution Name
--------------------------------

1024x768      edid/1024x768.bin
1280x1024     edid/1280x1024.bin
1680x1050     edid/1680x1050.bin
1920x1080     edid/1920x1080.bin

They are ignored, if a file with the same name is available in the /lib/firmware directory.

The built-in EDID data sets are based on standard timings that may not apply to a particular monitor and even crash it. Ideally, EDID data of the connected monitor should be used. They may be obtained through the drm/cardX/cardX-<connector>/edid entry in the /sys/devices PCI directory of a correctly working graphics adapter.

It is also possible to specify the name of an EDID data set on-the-fly via the /sys/module interface, e.g.
echo edid/myedid.bin >/sys/module/drm_kms_helper/parameters/edid_firmware The new screen mode is considered when the related kernel function is called for the first time after the change. Such calls are made when the X server is started or when the display settings dialog is opened in an already running X server.

---
 Documentation/EDID/1024x768.S       |   44 ++++++
 Documentation/EDID/1280x1024.S      |   44 ++++++
 Documentation/EDID/1680x1050.S      |   44 ++++++
 Documentation/EDID/1920x1080.S      |   44 ++++++
 Documentation/EDID/HOWTO.txt        |   39 +++++
 Documentation/EDID/Makefile         |   26 +++
 Documentation/EDID/edid.S           |  261 ++++++++++++++++++++++++++++++++++++
 Documentation/EDID/hex              |    1 
 Documentation/kernel-parameters.txt |   12 +
 drivers/gpu/drm/Kconfig             |   12 +
 drivers/gpu/drm/Makefile            |    3 
 drivers/gpu/drm/drm_crtc_helper.c   |    8 -
 drivers/gpu/drm/drm_edid.c          |    4 
 drivers/gpu/drm/drm_edid_load.c     |  241 +++++++++++++++++++++++++++++++++
 include/drm/drm_crtc.h              |    1 
 include/drm/drm_edid.h              |    1 
 16 files changed, 782 insertions(+), 3 deletions(-)
Documentation/EDID/1024x768.S new file +44 -0
Index: linux-3.3-rc7/Documentation/EDID/1024x768.S
===================================================================
@@ -0,0 +1,44 @@
+/*
+   1024x768.S: EDID data set for standard 1024x768 60 Hz monitor
+
+   Copyright (C) 2011 Carsten Emde <[email protected]>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
+*/
+
+/* EDID */
+#define VERSION 1
+#define REVISION 3
+
+/* Display */
+#define CLOCK 65000 /* kHz */
+#define XPIX 1024
+#define YPIX 768
+#define XY_RATIO XY_RATIO_4_3
+#define XBLANK 320
+#define YBLANK 38
+#define XOFFSET 8
+#define XPULSE 144
+#define YOFFSET (63+3)
+#define YPULSE (63+6)
+#define DPI 72
+#define VFREQ 60 /* Hz */
+#define TIMING_NAME "Linux XGA"
+#define ESTABLISHED_TIMINGS_BITS 0x08 /* Bit 3 -> 1024x768 @60 Hz */
+#define HSYNC_POL 0
+#define VSYNC_POL 0
+#define CRC 0x55
+
+#include "edid.S"
Documentation/EDID/1280x1024.S new file +44 -0

44 lines not on this page · raw message

Documentation/EDID/1680x1050.S new file +44 -0

44 lines not on this page · raw message

Documentation/EDID/1920x1080.S new file +44 -0

44 lines not on this page · raw message

Documentation/EDID/HOWTO.txt new file +39 -0
Index: linux-3.3-rc7/Documentation/EDID/HOWTO.txt
===================================================================
@@ -0,0 +1,39 @@
+In the good old days when graphics parameters were configured explicitly
+in a file called xorg.conf, even broken hardware could be managed.
+
+Today, with the advent of Kernel Mode Setting, a graphics board is
+either correctly working because all components follow the standards -
+or the computer is unusable, because the screen remains dark after
+booting or it displays the wrong area. Cases when this happens are:
+- The graphics board does not recognize the monitor.
+- The graphics board is unable to detect any EDID data.
+- The graphics board incorrectly forwards EDID data to the driver.
+- The monitor sends no or bogus EDID data.
+- A KVM sends its own EDID data instead of querying the connected monitor.
+Adding the kernel parameter "nomodeset" helps in most cases, but causes
+restrictions later on.
+
+As a remedy for such situations, the kernel configuration item
+CONFIG_DRM_LOAD_EDID_FIRMWARE was introduced. It allows to provide an
+individually prepared or corrected EDID data set in the /lib/firmware
+directory from where it is loaded via the firmware interface. The code
+(see drivers/gpu/drm/drm_edid_load.c) contains built-in data sets for
+commonly used screen resolutions (1024x768, 1280x1024, 1680x1050,
+1920x1080) as binary blobs, but the kernel source tree does not contain
+code to create these data. In order to elucidate the origin of the
+built-in binary EDID blobs and to facilitate the creation of individual
+data for a specific misbehaving monitor, commented sources and a
+Makefile environment are given here.
+
+To create binary EDID and C source code files from the existing data
+material, simply type "make".
+
+If you want to create your own EDID file, copy the file 1024x768.S and
+replace the settings with your own data. The CRC value in the last line
+  #define CRC 0x55
+is a bit tricky. After a first version of the binary data set is
+created, it must be be checked with the "edid-decode" utility which will
+most probably complain about a wrong CRC. Fortunately, the utility also
+displays the correct CRC which must then be inserted into the source
+file. After the make procedure is repeated, the EDID data set is ready
+to be used.
Documentation/EDID/Makefile new file +26 -0
Index: linux-3.3-rc7/Documentation/EDID/Makefile
===================================================================
@@ -0,0 +1,26 @@
+
+SOURCES	:= $(wildcard [0-9]*x[0-9]*.S)
+
+BIN	:= $(patsubst %.S, %.bin, $(SOURCES))
+
+IHEX	:= $(patsubst %.S, %.bin.ihex, $(SOURCES))
+
+CODE	:= $(patsubst %.S, %.c, $(SOURCES))
+
+all:	$(BIN) $(IHEX) $(CODE)
+
+clean:
+	@rm -f *.o *.bin.ihex *.bin *.c
+
+%.o:	%.S
+	@cc -c $^
+
+%.bin:	%.o
+	@objcopy -Obinary $^ $@
+
+%.bin.ihex:	%.o
+	@objcopy -Oihex $^ $@
+	@dos2unix $@ 2>/dev/null
+
+%.c:	%.bin
+	@echo "{" >$@; hexdump -f hex $^ >>$@; echo "};" >>$@
Documentation/EDID/edid.S new file +261 -0

261 lines not on this page · raw message

Documentation/EDID/hex new file +1 -0
Index: linux-3.3-rc7/Documentation/EDID/hex
===================================================================
@@ -0,0 +1 @@
+"\t" 8/1 "0x%02x, " "\n"
Documentation/kernel-parameters.txt +12 -0
Index: linux-3.3-rc7/Documentation/kernel-parameters.txt
===================================================================
@@ -713,6 +713,18 @@ bytes respectively. Such letter suffixes
 			The filter can be disabled or changed to another
 			driver later using sysfs.
 
+	drm_kms_helper.edid_firmware=<file>
+			Broken monitors, graphic adapters and KVMs may
+			send no or broken EDID data sets. This parameter
+			allows to specify an EDID data set in the
+			/lib/firmware directory that is used instead.
+			Generic built-in EDID data sets are used, if one of
+			edid/1024x768.bin, edid/1280x1024.bin,
+			edid/1680x1050.bin, or edid/1920x1080.bin is given
+			and no file with the same name exists. Details and
+			instructions how to build your own EDID data are
+			given in Documentation/EDID/HOWTO.txt.
+
 	dscc4.setup=	[NET]
 
 	earlycon=	[KNL] Output early console device and options.
drivers/gpu/drm/Kconfig +12 -0
Index: linux-3.3-rc7/drivers/gpu/drm/Kconfig
===================================================================
@@ -27,6 +27,18 @@ config DRM_KMS_HELPER
 	help
 	  FB and CRTC helpers for KMS drivers.
 
+config DRM_LOAD_EDID_FIRMWARE
+	bool "Allow to specify an EDID data set instead of probing for it"
+	depends on DRM_KMS_HELPER
+	help
+	  Say Y here, if you want to use EDID data to be loaded from the
+	  /lib/firmware directory or one of the provided built-in
+	  data sets. This may be necessary, if the graphics adapter or
+	  monitor are unable to provide appropriate EDID data. Since this
+	  feature is provided as a workaround for broken hardware, the
+	  default case is N. Details and instructions how to build your own
+	  EDID data are given in Documentation/EDID/HOWTO.txt.
+
 config DRM_TTM
 	tristate
 	depends on DRM
drivers/gpu/drm/Makefile +3 -0
Index: linux-3.3-rc7/drivers/gpu/drm/Makefile
===================================================================
@@ -17,6 +17,9 @@ drm-y       :=	drm_auth.o drm_buffer.o d
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 
 drm_kms_helper-y := drm_fb_helper.o drm_crtc_helper.o drm_dp_i2c_helper.o
+ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE
+drm_kms_helper-y += drm_edid_load.o
+endif
 
 obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
 
drivers/gpu/drm/drm_crtc_helper.c +7 -1
Index: linux-3.3-rc7/drivers/gpu/drm/drm_crtc_helper.c
===================================================================
@@ -37,6 +37,7 @@
 #include "drm_fourcc.h"
 #include "drm_crtc_helper.h"
 #include "drm_fb_helper.h"
+#include "drm_edid.h"
 
 static bool drm_kms_helper_poll = true;
 module_param_named(poll, drm_kms_helper_poll, bool, 0600);
@@ -118,7 +119,12 @@ int drm_helper_probe_single_connector_mo
 		goto prune;
 	}
 
-	count = (*connector_funcs->get_modes)(connector);
+#ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE
+	count = load_edid_firmware(connector);
+	if (count == 0)
+#endif
+		count = (*connector_funcs->get_modes)(connector);
+
 	if (count == 0 && connector->status == connector_status_connected)
 		count = drm_add_modes_noedid(connector, 1024, 768);
 	if (count == 0)
drivers/gpu/drm/drm_edid.c +2 -2
Index: linux-3.3-rc7/drivers/gpu/drm/drm_edid.c
===================================================================
@@ -149,8 +149,7 @@ EXPORT_SYMBOL(drm_edid_header_is_valid);
  * Sanity check the EDID block (base or extension).  Return 0 if the block
  * doesn't check out, or 1 if it's valid.
  */
-static bool
-drm_edid_block_valid(u8 *raw_edid)
+bool drm_edid_block_valid(u8 *raw_edid)
 {
 	int i;
 	u8 csum = 0;
@@ -203,6 +202,7 @@ bad:
 	}
 	return 0;
 }
+EXPORT_SYMBOL(drm_edid_block_valid);
 
 /**
  * drm_edid_is_valid - sanity check EDID data
drivers/gpu/drm/drm_edid_load.c new file +241 -0

241 lines not on this page · raw message

include/drm/drm_crtc.h +1 -0
Index: linux-3.3-rc7/include/drm/drm_crtc.h
===================================================================
@@ -995,6 +995,7 @@ extern int drm_add_modes_noedid(struct d
 				int hdisplay, int vdisplay);
 
 extern int drm_edid_header_is_valid(const u8 *raw_edid);
+extern bool drm_edid_block_valid(u8 *raw_edid);
 extern bool drm_edid_is_valid(struct edid *edid);
 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
 					   int hsize, int vsize, int fresh);
include/drm/drm_edid.h +1 -0
Index: linux-3.3-rc7/include/drm/drm_edid.h
===================================================================
@@ -238,5 +238,6 @@ int drm_av_sync_delay(struct drm_connect
 		      struct drm_display_mode *mode);
 struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
 				     struct drm_display_mode *mode);
+int load_edid_firmware(struct drm_connector *connector);
 
 #endif /* __DRM_EDID_H__ */
#2 lore raw

Re: [V3 PATCH 1/2] drivers-gpu-drm-allow-to-load-edid-firmware.patch

Quoted 5 lines · Carsten Emde

Broken monitors and/or broken graphic boards may send erroneous or no EDID data. This also applies to broken KVM devices that are unable to correctly forward the EDID data of the connected monitor but invent their own fantasy data.

Quoted 9 lines

This patch allows to specify an EDID data set to be used instead of probing the monitor for it. It contains built-in data sets of frequently used screen resolutions. In addition, a particular EDID data set may be provided in the /lib/firmware directory and loaded via the firmware interface. The name is passed to the kernel as module parameter of the drm_kms_helper module either when loaded
 options drm_kms_helper edid_firmware=edid/1280x1024.bin
or as kernel commandline parameter drm_kms_helper.edid_firmware=edid/1280x1024.bin

Windows allow vendor to override eddid based on 3 bytes manufacturer and product code.

Seems a reasonnable approach to follow.

Bastien

#3 lore raw

Re: [V3 PATCH 1/2] drivers-gpu-drm-allow-to-load-edid-firmware.patch

Bastien,

Quoted 15 lines
Quoted 5 lines

Broken monitors and/or broken graphic boards may send erroneous or no EDID data. This also applies to broken KVM devices that are unable to correctly forward the EDID data of the connected monitor but invent their own fantasy data.

Quoted 9 lines

This patch allows to specify an EDID data set to be used instead of probing the monitor for it. It contains built-in data sets of frequently used screen resolutions. In addition, a particular EDID data set may be provided in the /lib/firmware directory and loaded via the firmware interface. The name is passed to the kernel as module parameter of the drm_kms_helper module either when loaded
options drm_kms_helper edid_firmware=edid/1280x1024.bin
or as kernel commandline parameter
drm_kms_helper.edid_firmware=edid/1280x1024.bin

Quoted 2 lines

Windows allow vendor to override eddid based on 3 bytes manufacturer and product code.

This may solve the situation when a particular monitor lies about the required setting or its EDID data set has an invalid CRC. However, this does not solve the situation when we do not get any useful EDID information, because something is totally broken. This also applies to the KVM situation when the KVM sends EDID data that are totally unrelated to the monitor at the other side of the KVM.

Quoted 1 line

Seems a reasonnable approach to follow.

I am not yet convinced.

-Carsten.

#4 lore raw

Re: [V3 PATCH 1/2] drivers-gpu-drm-allow-to-load-edid-firmware.patch

Quoted 9 lines · Carsten Emde <C.Emde <at> osadl.org> writes:
Quoted 2 lines

Windows allow vendor to override eddid based on 3 bytes manufacturer and product code.

This may solve the situation when a particular monitor lies about the required setting or its EDID data set has an invalid CRC. However, this does not solve the situation when we do not get any useful EDID information, because something is totally broken. This also applies to the KVM situation when the KVM sends EDID data that are totally unrelated to the monitor at the other side of the KVM.

Quoted 3 lines
Quoted 1 line

Seems a reasonnable approach to follow.

I am not yet convinced.

I second that, I have/had a laptop (with Radeon thou) that I had to override the EDID it read from its own panel, which had most info good but CRC wrong...

This manifested itself as the system thinking all it had was 1024x768 on a 1280x800 panel - not scaling and remaining space filled with garbage. Even its own bios did not recognize that (!), never mind Windows.

Before this patch (and probably some base EDID data...?) I'd have to set mode override in X itself (and I had it working so beautifully)

(laptop's unfortunately not in use any more 'cause of panel hinge damage and post-children keyboard fail and generally 'morally' done&dusted (AMD Mob Sempron 1.8GHz+Mob Radeon X700) but may still boot...)

Quoted 2 lines

-Carsten.

L.

#5 lore raw

PATCH v3 2/2 drivers-gpu-drm-i915-quirk-backlight-inverted.patch

In reply to Carsten Emde

Following the documentation of the Legacy Backlight Brightness (LBB) Register in the configuration space of some Intel PCI graphics adapters, setting the LBB register with the value 0x0 causes the backlight to be turned off, and 0xFF causes the backlight to be set to 100% intensity
(http://download.intel.com/embedded/processors/Whitepaper/324567.pdf).
The Acer Aspire 5734Z, however, turns the backlight off at 0xFF and sets it to maximum intensity at 0. In consequence, the screen of this systems becomes dark at an early boot stage which makes it unusable. The same inversion applies to the BLC_PWM_CTL I915 register. This problem was introduced in kernel version 2.6.38 when the PCI device of this system was first supported by the i915 KMS module.

This patch adds a quirk to invert the sense of the brightness variable in case an Acer Aspire 5734Z is encountered.

---
 drivers/gpu/drm/i915/i915_drv.h      |    1 +
 drivers/gpu/drm/i915/intel_display.c |   12 ++++++++++++
 drivers/gpu/drm/i915/intel_panel.c   |   10 ++++++++++
 3 files changed, 23 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +1 -0
Index: linux-3.3-rc7/drivers/gpu/drm/i915/i915_drv.h
===================================================================
@@ -275,6 +275,7 @@ enum intel_pch {
 
 #define QUIRK_PIPEA_FORCE (1<<0)
 #define QUIRK_LVDS_SSC_DISABLE (1<<1)
+#define QUIRK_BRIGHTNESS_INVERTED (1<<2)
 
 struct intel_fbdev;
 struct intel_fbc_work;
drivers/gpu/drm/i915/intel_display.c +12 -0
Index: linux-3.3-rc7/drivers/gpu/drm/i915/intel_display.c
===================================================================
@@ -8950,6 +8950,15 @@ static void quirk_ssc_force_disable(stru
 	dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
 }
 
+/*
+ * At least one machine (Acer Aspire 5734Z) has inverted backlight brightness
+ */
+static void quirk_brightness_inverted(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	dev_priv->quirks |= QUIRK_BRIGHTNESS_INVERTED;
+}
+
 struct intel_quirk {
 	int device;
 	int subsystem_vendor;
@@ -8984,6 +8993,9 @@ struct intel_quirk intel_quirks[] = {
 
 	/* Sony Vaio Y cannot use SSC on LVDS */
 	{ 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
+
+	/* Acer Aspire 5734Z has inverted backlight brightness */
+	{ 0x2a42, 0x1025, 0x0459, quirk_brightness_inverted },
 };
 
 static void intel_init_quirks(struct drm_device *dev)
drivers/gpu/drm/i915/intel_panel.c +10 -0
Index: linux-3.3-rc7/drivers/gpu/drm/i915/intel_panel.c
===================================================================
@@ -28,6 +28,7 @@
  *      Chris Wilson <[email protected]>
  */
 
+#include <linux/moduleparam.h>
 #include "intel_drv.h"
 
 #define PCI_LBPC 0xf4 /* legacy/combination backlight modes */
@@ -212,6 +213,10 @@ u32 intel_panel_get_backlight(struct drm
 	}
 
 	DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val);
+	if (dev_priv->quirks & QUIRK_BRIGHTNESS_INVERTED) {
+		u32 max = intel_panel_get_max_backlight(dev);
+		val = max - val;
+	}
 	return val;
 }
 
@@ -229,6 +234,11 @@ static void intel_panel_actually_set_bac
 
 	DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level);
 
+	if (dev_priv->quirks & QUIRK_BRIGHTNESS_INVERTED) {
+		u32 max = intel_panel_get_max_backlight(dev);
+		level = max - level;
+	}
+
 	if (HAS_PCH_SPLIT(dev))
 		return intel_pch_panel_set_backlight(dev, level);
 
#6 lore raw

Re: [V3 PATCH 2/2] drivers-gpu-drm-i915-quirk-backlight-inverted.patch

Quoted 12 lines · Carsten Emde

Following the documentation of the Legacy Backlight Brightness (LBB) Register in the configuration space of some Intel PCI graphics adapters, setting the LBB register with the value 0x0 causes the backlight to be turned off, and 0xFF causes the backlight to be set to 100% intensity
(http://download.intel.com/embedded/processors/Whitepaper/324567.pdf).
The Acer Aspire 5734Z, however, turns the backlight off at 0xFF and sets it to maximum intensity at 0. In consequence, the screen of this systems becomes dark at an early boot stage which makes it unusable. The same inversion applies to the BLC_PWM_CTL I915 register. This problem was introduced in kernel version 2.6.38 when the PCI device of this system was first supported by the i915 KMS module.

Quoted 4 lines

This patch adds a quirk to invert the sense of the brightness variable in case an Acer Aspire 5734Z is encountered.

That looks a lot better. However, can I ask for another follow-on patch to enable this quirk by a module parameter as well? I would like to make it easier for anyone else hitting this issue to identity the problem and find a temporary solution until their machine is also quirked.

drivers/gpu/drm/i915/intel_panel.c line 32

Quoted 11 lines

static void intel_init_quirks(struct drm_device *dev)
Index: linux-3.3-rc7/drivers/gpu/drm/i915/intel_panel.c
===================================================================

drivers/gpu/drm/i915/intel_panel.c +1 -0
@@ -28,6 +28,7 @@
  *      Chris Wilson <[email protected]>
  */
 
+#include <linux/moduleparam.h>
 #include "intel_drv.h"

That include is now not required.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre