: EDID parser
PATCH 1/1 : EDID parser
Hi James,
Attached is a diff against 2.5.66. It includes a reasonably complete EDID parser and also includes some new functions that can be used by fbdev drivers (for mode selection purposes)
1. fb_create_modedb()
creates a mode database which can be fed to fb_find_mode(). This means that fb_find_mode() should not be __init anymore.
2. fb_destroy_modedb()
destroy mode database created by fb_create_modedb()
3. fb_get_monitor_limits()
gets monitor operating limits (max and min hscan, max and min refresh, max pixclock, DPMS and GTF capability)
useful for validating video modes and calculating mode timings (if GTF capable)
4. show_edid()
just prints EDID data into human-readable format.
All of of the above depends on valid EDID data.
Tony
drivers/video/edid.h +128 -0
@@ -0,0 +1,128 @@ +/* +* drivers/video/edid.h - EDID parser definitions +* +* portions of this file were based on the EDID parser by +* John Fremlin <[email protected]> and Ani Joshi <[email protected]> +*/ + +#ifndef __EDID_H__ +#define __EDID_H__ + +#define EDID_LENGTH 0x80 +#define EDID_HEADER 0x00 +#define EDID_HEADER_END 0x07 + +#define ID_MANUFACTURER_NAME 0x08 +#define ID_MANUFACTURER_NAME_END 0x09 +#define ID_MODEL 0x0a + +#define ID_SERIAL_NUMBER 0x0c + +#define MANUFACTURE_WEEK 0x10 +#define MANUFACTURE_YEAR 0x11 + +#define EDID_STRUCT_VERSION 0x12 +#define EDID_STRUCT_REVISION 0x13 + +#define EDID_STRUCT_DISPLAY 0x14 + +#define DPMS_FLAGS 0x18 +#define ESTABLISHED_TIMING_1 0x23 +#define ESTABLISHED_TIMING_2 0x24 +#define MANUFACTURERS_TIMINGS 0x25 + +/* standard timings supported */ +#define STD_TIMING 8 +#define STD_TIMING_DESCRIPTION_SIZE 2 +#define STD_TIMING_DESCRIPTIONS_START 0x26 + +#define DETAILED_TIMING_DESCRIPTIONS_START 0x36 +#define DETAILED_TIMING_DESCRIPTION_SIZE 18 +#define NO_DETAILED_TIMING_DESCRIPTIONS 4 + +#define DETAILED_TIMING_DESCRIPTION_1 0x36 +#define DETAILED_TIMING_DESCRIPTION_2 0x48 +#define DETAILED_TIMING_DESCRIPTION_3 0x5a +#define DETAILED_TIMING_DESCRIPTION_4 0x6c + +#define DESCRIPTOR_DATA 5 + +#define UPPER_NIBBLE ( x ) \ + (((128|64|32|16) & (x)) >> 4) + +#define LOWER_NIBBLE ( x ) \ + ((1|2|4|8) & (x)) + +#define COMBINE_HI_8LO ( hi, lo ) \ + ( (((unsigned)hi) << 8) | (unsigned)lo ) + +#define COMBINE_HI_4LO ( hi, lo ) \ + ( (((unsigned)hi) << 4) | (unsigned)lo ) + +#define PIXEL_CLOCK_LO (unsigned)block[ 0 ] +#define PIXEL_CLOCK_HI (unsigned)block[ 1 ] +#define PIXEL_CLOCK (COMBINE_HI_8LO( PIXEL_CLOCK_HI,PIXEL_CLOCK_LO )*10000) +#define H_ACTIVE_LO (unsigned)block[ 2 ] +#define H_BLANKING_LO (unsigned)block[ 3 ] +#define H_ACTIVE_HI UPPER_NIBBLE( (unsigned)block[ 4 ] ) +#define H_ACTIVE COMBINE_HI_8LO( H_ACTIVE_HI, H_ACTIVE_LO ) +#define H_BLANKING_HI LOWER_NIBBLE( (unsigned)block[ 4 ] ) +#define H_BLANKING COMBINE_HI_8LO( H_BLANKING_HI, H_BLANKING_LO ) + +#define V_ACTIVE_LO (unsigned)block[ 5 ] +#define V_BLANKING_LO (unsigned)block[ 6 ] +#define V_ACTIVE_HI UPPER_NIBBLE( (unsigned)block[ 7 ] ) +#define V_ACTIVE COMBINE_HI_8LO( V_ACTIVE_HI, V_ACTIVE_LO ) +#define V_BLANKING_HI LOWER_NIBBLE( (unsigned)block[ 7 ] ) +#define V_BLANKING COMBINE_HI_8LO( V_BLANKING_HI, V_BLANKING_LO ) + +#define H_SYNC_OFFSET_LO (unsigned)block[ 8 ] +#define H_SYNC_WIDTH_LO (unsigned)block[ 9 ] + +#define V_SYNC_OFFSET_LO UPPER_NIBBLE( (unsigned)block[ 10 ] ) +#define V_SYNC_WIDTH_LO LOWER_NIBBLE( (unsigned)block[ 10 ] ) + +#define V_SYNC_WIDTH_HI ((unsigned)block[ 11 ] & (1|2)) +#define V_SYNC_OFFSET_HI (((unsigned)block[ 11 ] & (4|8)) >> 2) + +#define H_SYNC_WIDTH_HI (((unsigned)block[ 11 ] & (16|32)) >> 4) +#define H_SYNC_OFFSET_HI (((unsigned)block[ 11 ] & (64|128)) >> 6) + +#define V_SYNC_WIDTH COMBINE_HI_4LO( V_SYNC_WIDTH_HI, V_SYNC_WIDTH_LO ) +#define V_SYNC_OFFSET COMBINE_HI_4LO( V_SYNC_OFFSET_HI, V_SYNC_OFFSET_LO ) + +#define H_SYNC_WIDTH COMBINE_HI_4LO( H_SYNC_WIDTH_HI, H_SYNC_WIDTH_LO ) +#define H_SYNC_OFFSET COMBINE_HI_4LO( H_SYNC_OFFSET_HI, H_SYNC_OFFSET_LO ) + +#define H_SIZE_LO (unsigned)block[ 12 ] +#define V_SIZE_LO (unsigned)block[ 13 ] + +#define H_SIZE_HI UPPER_NIBBLE( (unsigned)block[ 14 ] ) +#define V_SIZE_HI LOWER_NIBBLE( (unsigned)block[ 14 ] ) + +#define H_SIZE COMBINE_HI_8LO( H_SIZE_HI, H_SIZE_LO ) +#define V_SIZE COMBINE_HI_8LO( V_SIZE_HI, V_SIZE_LO ) + +#define H_BORDER (unsigned)block[ 15 ] +#define V_BORDER (unsigned)block[ 16 ] + +#define FLAGS (unsigned)block[ 17 ] + +#define INTERLACED (FLAGS&128) +#define SYNC_TYPE (FLAGS&3<<3)/* bits 4,3 */ +#define SYNC_SEPARATE (3<<3) +#define HSYNC_POSITIVE (FLAGS & 4) +#define VSYNC_POSITIVE (FLAGS & 2) + +#define V_MIN_RATE block[ 5 ] +#define V_MAX_RATE block[ 6 ] +#define H_MIN_RATE block[ 7 ] +#define H_MAX_RATE block[ 8 ] +#define MAX_PIXEL_CLOCK (((int)block[ 9 ]) * 10) +#define GTF_SUPPORT block[10] + +#define DPMS_ACTIVE_OFF (1 << 5) +#define DPMS_SUSPEND (1 << 6) +#define DPMS_STANDBY (1 << 7) + +#endif /* __EDID_H__ */
drivers/video/fbmon.c +601 -158
859 lines not on this page · raw message
drivers/video/modedb.c +105 -0
114 lines not on this page · raw message
include/linux/fb.h +10 -0
@@ -505,6 +505,16 @@ struct fb_info *info);extern int fb_validate_mode (struct fb_var_screeninfo *var,struct fb_info *info); +extern int parse_edid (unsigned char *edid,struct fb_var_screeninfo *var); +extern char *get_EDID (struct pci_dev *pdev); +extern void show_edid (unsigned char *edid); +extern int fb_get_monitor_limits (unsigned char *edid,struct fb_monspecs *specs); +extern struct fb_videomode *fb_create_modedb (unsigned char *edid,int *dbsize); +extern void fb_destroy_modedb (struct fb_videomode *modedb); + +/* drivers/video/modedb.c */ +#define VESA_MODEDB_SIZE 34 +extern const struct fb_videomode vesa_modes[];/* drivers/video/fbcmap.c */ extern int fb_alloc_cmap (struct fb_cmap *cmap,int len,int transp);
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth! No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
Quoted 20 lines · Antonino Daplas
Hi James,
Attached is a diff against 2.5.66. It includes a reasonably complete EDID parser and also includes some new functions that can be used by fbdev drivers (for mode selection purposes)
1.
fb_create_modedb()creates a mode database which can be fed to
fb_find_mode(). This means thatfb_find_mode()should not be__initanymore.2.
fb_destroy_modedb()destroy mode database created by
fb_create_modedb()3.
fb_get_monitor_limits()gets monitor operating limits (max and min hscan, max and min refresh, max pixclock, DPMS and GTF capability)
Quoted 9 lines
useful for validating video modes and calculating mode timings (if GTF capable)
4.
show_edid()just prints EDID data into human-readable format.
All of of the above depends on valid EDID data.
James,
Here's a revised patch. I was able to receive source code from SciTech (c/o Kendall Bennett) which allowed me to fix bugs and complete the parser. It's probably around 90-95% complete in terms of basic parsing.
It also fixes memory leaks which was present in the old patch.
Tony
drivers/video/edid.h +138 -0
@@ -0,0 +1,138 @@ +/* +* drivers/video/edid.h - EDID/DDC Header +* +* Based on: +* 1. XFree86 4.3.0, edid.h +* Copyright 1998 by Egbert Eich <[email protected]> +* +* 2. John Fremlin <[email protected]> and +* Ani Joshi <[email protected]> +* +* DDC is a Trademark of VESA (Video Electronics Standard Association). +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of this archive +* for more details. +*/ + +#ifndef __EDID_H__ +#define __EDID_H__ + +#define EDID_LENGTH 0x80 +#define EDID_HEADER 0x00 +#define EDID_HEADER_END 0x07 + +#define ID_MANUFACTURER_NAME 0x08 +#define ID_MANUFACTURER_NAME_END 0x09 +#define ID_MODEL 0x0a + +#define ID_SERIAL_NUMBER 0x0c + +#define MANUFACTURE_WEEK 0x10 +#define MANUFACTURE_YEAR 0x11 + +#define EDID_STRUCT_VERSION 0x12 +#define EDID_STRUCT_REVISION 0x13 + +#define EDID_STRUCT_DISPLAY 0x14 + +#define DPMS_FLAGS 0x18 +#define ESTABLISHED_TIMING_1 0x23 +#define ESTABLISHED_TIMING_2 0x24 +#define MANUFACTURERS_TIMINGS 0x25 + +/* standard timings supported */ +#define STD_TIMING 8 +#define STD_TIMING_DESCRIPTION_SIZE 2 +#define STD_TIMING_DESCRIPTIONS_START 0x26 + +#define DETAILED_TIMING_DESCRIPTIONS_START 0x36 +#define DETAILED_TIMING_DESCRIPTION_SIZE 18 +#define NO_DETAILED_TIMING_DESCRIPTIONS 4 + +#define DETAILED_TIMING_DESCRIPTION_1 0x36 +#define DETAILED_TIMING_DESCRIPTION_2 0x48 +#define DETAILED_TIMING_DESCRIPTION_3 0x5a +#define DETAILED_TIMING_DESCRIPTION_4 0x6c + +#define DESCRIPTOR_DATA 5 + +#define UPPER_NIBBLE ( x ) \ + (((128|64|32|16) & (x)) >> 4) + +#define LOWER_NIBBLE ( x ) \ + ((1|2|4|8) & (x)) + +#define COMBINE_HI_8LO ( hi, lo ) \ + ( (((unsigned)hi) << 8) | (unsigned)lo ) + +#define COMBINE_HI_4LO ( hi, lo ) \ + ( (((unsigned)hi) << 4) | (unsigned)lo ) + +#define PIXEL_CLOCK_LO (unsigned)block[ 0 ] +#define PIXEL_CLOCK_HI (unsigned)block[ 1 ] +#define PIXEL_CLOCK (COMBINE_HI_8LO( PIXEL_CLOCK_HI,PIXEL_CLOCK_LO )*10000) +#define H_ACTIVE_LO (unsigned)block[ 2 ] +#define H_BLANKING_LO (unsigned)block[ 3 ] +#define H_ACTIVE_HI UPPER_NIBBLE( (unsigned)block[ 4 ] ) +#define H_ACTIVE COMBINE_HI_8LO( H_ACTIVE_HI, H_ACTIVE_LO ) +#define H_BLANKING_HI LOWER_NIBBLE( (unsigned)block[ 4 ] ) +#define H_BLANKING COMBINE_HI_8LO( H_BLANKING_HI, H_BLANKING_LO ) + +#define V_ACTIVE_LO (unsigned)block[ 5 ] +#define V_BLANKING_LO (unsigned)block[ 6 ] +#define V_ACTIVE_HI UPPER_NIBBLE( (unsigned)block[ 7 ] ) +#define V_ACTIVE COMBINE_HI_8LO( V_ACTIVE_HI, V_ACTIVE_LO ) +#define V_BLANKING_HI LOWER_NIBBLE( (unsigned)block[ 7 ] ) +#define V_BLANKING COMBINE_HI_8LO( V_BLANKING_HI, V_BLANKING_LO ) + +#define H_SYNC_OFFSET_LO (unsigned)block[ 8 ] +#define H_SYNC_WIDTH_LO (unsigned)block[ 9 ] + +#define V_SYNC_OFFSET_LO UPPER_NIBBLE( (unsigned)block[ 10 ] ) +#define V_SYNC_WIDTH_LO LOWER_NIBBLE( (unsigned)block[ 10 ] ) + +#define V_SYNC_WIDTH_HI ((unsigned)block[ 11 ] & (1|2)) +#define V_SYNC_OFFSET_HI (((unsigned)block[ 11 ] & (4|8)) >> 2) + +#define H_SYNC_WIDTH_HI (((unsigned)block[ 11 ] & (16|32)) >> 4) +#define H_SYNC_OFFSET_HI (((unsigned)block[ 11 ] & (64|128)) >> 6) + +#define V_SYNC_WIDTH COMBINE_HI_4LO( V_SYNC_WIDTH_HI, V_SYNC_WIDTH_LO ) +#define V_SYNC_OFFSET COMBINE_HI_4LO( V_SYNC_OFFSET_HI, V_SYNC_OFFSET_LO ) + +#define H_SYNC_WIDTH COMBINE_HI_4LO( H_SYNC_WIDTH_HI, H_SYNC_WIDTH_LO ) +#define H_SYNC_OFFSET COMBINE_HI_4LO( H_SYNC_OFFSET_HI, H_SYNC_OFFSET_LO ) + +#define H_SIZE_LO (unsigned)block[ 12 ] +#define V_SIZE_LO (unsigned)block[ 13 ] + +#define H_SIZE_HI UPPER_NIBBLE( (unsigned)block[ 14 ] ) +#define V_SIZE_HI LOWER_NIBBLE( (unsigned)block[ 14 ] ) + +#define H_SIZE COMBINE_HI_8LO( H_SIZE_HI, H_SIZE_LO ) +#define V_SIZE COMBINE_HI_8LO( V_SIZE_HI, V_SIZE_LO ) + +#define H_BORDER (unsigned)block[ 15 ] +#define V_BORDER (unsigned)block[ 16 ] + +#define FLAGS (unsigned)block[ 17 ] + +#define INTERLACED (FLAGS&128) +#define SYNC_TYPE (FLAGS&3<<3)/* bits 4,3 */ +#define SYNC_SEPARATE (3<<3) +#define HSYNC_POSITIVE (FLAGS & 4) +#define VSYNC_POSITIVE (FLAGS & 2) + +#define V_MIN_RATE block[ 5 ] +#define V_MAX_RATE block[ 6 ] +#define H_MIN_RATE block[ 7 ] +#define H_MAX_RATE block[ 8 ] +#define MAX_PIXEL_CLOCK (((int)block[ 9 ]) * 10) +#define GTF_SUPPORT block[10] + +#define DPMS_ACTIVE_OFF (1 << 5) +#define DPMS_SUSPEND (1 << 6) +#define DPMS_STANDBY (1 << 7) + +#endif /* __EDID_H__ */
drivers/video/fbmon.c +732 -164
1,003 lines not on this page · raw message
drivers/video/modedb.c +105 -0
114 lines not on this page · raw message
include/linux/fb.h +14 -0
@@ -492,6 +492,10 @@extern int num_registered_fb;/* drivers/video/fbmon.c */ +#ifdef CONFIG_PCI +#include <linux/pci.h> +#endif +#define FB_MAXTIMINGS 0#define FB_VSYNCTIMINGS 1#define FB_HSYNCTIMINGS 2
@@ -505,6 +509,16 @@ struct fb_info *info);extern int fb_validate_mode (struct fb_var_screeninfo *var,struct fb_info *info); +extern int parse_edid (unsigned char *edid,struct fb_var_screeninfo *var); +extern char *get_EDID (struct pci_dev *pdev); +extern void show_edid (unsigned char *edid); +extern int fb_get_monitor_limits (unsigned char *edid,struct fb_monspecs *specs); +extern struct fb_videomode *fb_create_modedb (unsigned char *edid,int *dbsize); +extern void fb_destroy_modedb (struct fb_videomode *modedb); + +/* drivers/video/modedb.c */ +#define VESA_MODEDB_SIZE 34 +extern const struct fb_videomode vesa_modes[];/* drivers/video/fbcmap.c */ extern int fb_alloc_cmap (struct fb_cmap *cmap,int len,int transp);
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth! No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
Quoted 8 lines
James,
Here's a revised patch. I was able to receive source code from SciTech (c/o Kendall Bennett) which allowed me to fix bugs and complete the parser. It's probably around 90-95% complete in terms of basic parsing.
It also fixes memory leaks which was present in the old patch.
Let really good. I applied it to my local tree but haven't passed it to BK fbdev yet. The only thing I like to see changed is get_EDID. At present it accepts a struct pci_dev. Now for generic support for the intel platform we can get this from the BIOS. You already have a patch that does this. It doesn't need a struct pci_dev in this case. It is possible to get this info from the i2c bus but I never seen any drivers do this. What data would we have to pass in get the EDID inforamtion? So the question is how generic will get_EDID end up being or will we have to have driver specfic hooks since I don't pitcure i2c approaches being the same for each video card. Petr didn't you attempt this with the matrox driver at one time?
Quoted 11 lines
Let really good. I applied it to my local tree but haven't passed it to BK fbdev yet. The only thing I like to see changed is
get_EDID. At present it accepts a structpci_dev. Now for generic support for the intel platform we can get this from the BIOS. You already have a patch that does this. It doesn't need a structpci_devin this case. It is possible to get this info from the i2c bus but I never seen any drivers do this. What data would we have to pass in get the EDID inforamtion? So the question is how generic willget_EDIDend up being or will we have to have driver specfic hooks since I don't pitcure i2c approaches being the same for each video card. Petr didn't you attempt this with the matrox driver at one time?
get_EDID() has to be a driver specific hook
EDID via BIOS is a way to get it, BIOS emulation in userland is another, on PPC, I can retreive it from the firmware device-tree in a different way with some cards, and finally, I plan to implement i2c sooner or later with some drivers...
Ben.
Quoted 9 lines · James Simmons
Quoted 8 lines
James,
Here's a revised patch. I was able to receive source code from SciTech (c/o Kendall Bennett) which allowed me to fix bugs and complete the parser. It's probably around 90-95% complete in terms of basic parsing.
It also fixes memory leaks which was present in the old patch.
Quoted 11 lines
Let really good. I applied it to my local tree but haven't passed it to BK fbdev yet. The only thing I like to see changed is
get_EDID. At present it accepts a structpci_dev. Now for generic support for the intel platform we can get this from the BIOS. You already have a patch that does this. It doesn't need a structpci_devin this case. It is possible to get this info from the i2c bus but I never seen any drivers do this. What data would we have to pass in get the EDID inforamtion? So the question is how generic willget_EDIDend up being or will we have to have driver specfic hooks since I don't pitcure i2c approaches being the same for each video card. Petr didn't you attempt this with the matrox driver at one time?
I think we just need an additional method in struct fb_ops. Something like this:
unsigned char *fb_get_edid(struct fb_info *info)
{
if (info->fbops->fb_get_edid)
return info->fbops->fb_get_edid(info);
else
return fallback_get_edid_method();
}We can get the EDID by different methods:
1. User uploads EDID to kernel via an ioctl. This is always preferred, as it gives the user the power to override machine settings, or if there is no other method to get the EDID. We can also have a userland utility that encodes user-specified monitor information and modelines into EDID info (a reverse EDID parser). For instance, selected entries in /etc/fb.modes can be easily converted to EDID which the user can upload to fbdev.
2. Gets it through device-specific hooks (i2c, whatever), if available. This is second choice, as it can get the EDID anytime. This is useful when a user decides to change monitors without rebooting, or if the device is a non-primary display.
3. Some architecture specific methods, such as doing it via the BIOS. This is the last choice, our fallback method. as this EDID may be static and represents only the display detected at boot time.
For supplementary functions, we also need some kind of control that allows the user to tell fbdev "I've switched monitors, please reread the EDID". We want to avoid doing DDC each time fbdev does an fb_set_var(), especially for DDC1 which can be very slow.
Also, a way to download the EDID from kernel to userland.
Tony
Quoted 9 lines
3. Some architecture specific methods, such as doing it via the BIOS. This is the last choice, our fallback method. as this EDID may be static and represents only the display detected at boot time.
For supplementary functions, we also need some kind of control that allows the user to tell fbdev "I've switched monitors, please reread the EDID". We want to avoid doing DDC each time fbdev does an
fb_set_var(), especially for DDC1 which can be very slow.
That's also what Apple does indeed. It's too complicated/long to dynamically detect hotplug, but they do have a button you can click to force a re-detect of the displays in the GUI and this goes via some kind of ioctl to the video driver to ask for new connection informations (basically EDID).
Quoted 1 line
Also, a way to download the EDID from kernel to userland.
Just define an ioctl for that and let each driver that support EDID return something seem to be the simplest way.
If we really want to make EDID a generic thing, then we can eventually have the EDID block attached to each fb_info and then a generic fbmem.c ioctl to read it, but then make sure that EDID block isn"t mandatory (it has no sense to some specific HW like some embedded stuffs) and I always prefer when drivers are the real target of the calls like this ioctl, eventually using fbdev "tools" as helpers instead of having fbdev do something directly as a "mid-mayer".
Ben.
Quoted 3 lines
Just define an ioctl for that and let each driver that support EDID return something seem to be the simplest way.
Replying to myself... and definitely not the best way for 2.5 (would be ok for 2.4 but do we care at this point ?)
Instead, we'd rather add the EDID as an attribute of the fb to sysfs.
Actually, I suggest that each fbdev driver defines ones or more nodes in sysfs below the actual driver node, representing the various heads. Each head would then have attributes representing the various display properties, one beeing the EDID block.
Quoted 15 lines
If we really want to make EDID a generic thing, then we can eventually have the EDID block attached to each
fb_infoand then a genericfbmem.cioctl to read it, but then make sure that EDID block isn"t mandatory (it has no sense to some specific HW like some embedded stuffs) and I always prefer when drivers are the real target of the calls like this ioctl, eventually using fbdev "tools" as helpers instead of having fbdev do something directly as a "mid-mayer".Ben.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 1 line
Benjamin Herrenschmidt <[email protected]>