xserver: Branch 'master' - 11 commits

Adam Jackson ajax at kemper.freedesktop.org
Fri Jul 17 11:55:31 PDT 2009


 dbe/dbestruct.h                       |   10 
 hw/xfree86/ddc/Makefile.am            |    5 
 hw/xfree86/ddc/ddc.c                  |  507 ++++++++++++++++++++++++++++++++++
 hw/xfree86/ddc/ddcPriv.h              |    9 
 hw/xfree86/ddc/ddcProperty.c          |   53 +--
 hw/xfree86/ddc/edid.c                 |  140 ---------
 hw/xfree86/ddc/edid.h                 |    9 
 hw/xfree86/ddc/xf86DDC.c              |  346 -----------------------
 hw/xfree86/ddc/xf86DDC.h              |   13 
 hw/xfree86/modes/Makefile.am          |    1 
 hw/xfree86/modes/xf86DisplayIDModes.c |  437 +++++++++++++++++++++++++++++
 hw/xfree86/modes/xf86EdidModes.c      |    6 
 12 files changed, 1003 insertions(+), 533 deletions(-)

New commits:
commit b4ee3bf700e04ae1b3c4ec021373424ed6e5338f
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jul 17 14:57:50 2009 -0400

    dbe: Fix indentation

diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 38b4440..002ffbe 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -43,16 +43,16 @@
 
 typedef struct
 {
-        VisualID    visual;    /* one visual ID that supports double-buffering */
-            int         depth;     /* depth of visual in bits                      */
-                int         perflevel; /* performance level of visual                  */
+    VisualID    visual;    /* one visual ID that supports double-buffering */
+    int         depth;     /* depth of visual in bits                      */
+    int         perflevel; /* performance level of visual                  */
 }
 XdbeVisualInfo;
 
 typedef struct
 {
-        int                 count;          /* number of items in visual_depth   */
-            XdbeVisualInfo      *visinfo;       /* list of visuals & depths for scrn */
+    int                 count;          /* number of items in visual_depth   */
+    XdbeVisualInfo      *visinfo;       /* list of visuals & depths for scrn */
 }
 XdbeScreenVisualInfo;
 
commit 0bb9a7e1650180a24246d14493a8168487cf8914
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 9 11:49:41 2009 -0400

    displayid: Implement mode decoding.

diff --git a/hw/xfree86/ddc/xf86DDC.h b/hw/xfree86/ddc/xf86DDC.h
index 2deadce..64869da 100644
--- a/hw/xfree86/ddc/xf86DDC.h
+++ b/hw/xfree86/ddc/xf86DDC.h
@@ -62,4 +62,15 @@ extern _X_EXPORT DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC);
 extern _X_EXPORT Bool
 xf86MonitorIsHDMI(xf86MonPtr mon);
 
+extern _X_EXPORT xf86MonPtr
+xf86DoDisplayID(int scrnIndex, I2CBusPtr pBus);
+
+extern _X_EXPORT void
+xf86DisplayIDMonitorSet(int scrnIndex, MonPtr mon, xf86MonPtr DDC);
+
+extern _X_EXPORT DisplayModePtr
+FindDMTMode(int hsize, int vsize, int refresh, Bool rb);
+
+extern _X_EXPORT const DisplayModeRec DMTModes[];
+
 #endif
diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am
index dc090cf..9236426 100644
--- a/hw/xfree86/modes/Makefile.am
+++ b/hw/xfree86/modes/Makefile.am
@@ -10,6 +10,7 @@ libxf86modes_la_SOURCES = \
 	xf86Cursors.c \
 	xf86cvt.c \
 	xf86gtf.c \
+	xf86DisplayIDModes.c \
 	xf86EdidModes.c \
 	xf86Modes.c \
 	xf86Modes.h \
diff --git a/hw/xfree86/modes/xf86DisplayIDModes.c b/hw/xfree86/modes/xf86DisplayIDModes.c
new file mode 100644
index 0000000..182d43e
--- /dev/null
+++ b/hw/xfree86/modes/xf86DisplayIDModes.c
@@ -0,0 +1,437 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software")
+ * to deal in the software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * them Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTIBILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *	Adam Jackson <ajax at redhat.com>
+ */
+
+#include "xorg-config.h"
+#include "xf86.h"
+#include "xf86str.h"
+#include "edid.h"
+#include "xf86DDC.h"
+
+typedef void (*did_proc)(int scrnIndex, unsigned char *data, void *closure);
+
+#define DID_PRODUCT_ID		    0x00
+#define DID_DISPLAY_PARAMETERS	    0x01
+#define DID_COLOR_INFO		    0x02
+#define DID_TIMING_1_DETAILED	    0x03
+#define DID_TIMING_2_DETAILED	    0x04
+#define DID_TIMING_3_SHORT	    0x05
+#define DID_TIMING_4_DMT	    0x06
+#define DID_TIMING_VESA		    0x07
+#define DID_TIMING_CEA		    0x08
+#define DID_TIMING_RANGE_LIMITS	    0x09
+#define DID_PRODUCT_SERIAL	    0x0A
+#define DID_ASCII_STRING	    0x0B
+#define DID_DISPLAY_DEVICE	    0x0C
+#define DID_POWER_SEQUENCING	    0x0D
+#define DID_TRANSFER_INFO	    0x0E
+#define DID_DISPLAY_INTERFACE	    0x0F
+#define DID_STEREO		    0x10
+#define DID_VENDOR		    0x7F
+
+#define extract_le16(x, i) ((x[i+1] << 8) + (x[i]))
+#define extract_le24(x, i) ((x[i+2] << 16) + (x[i+1] << 8) + (x[i]))
+
+static DisplayModePtr
+modeCalloc(void)
+{
+    return xcalloc(1, sizeof(DisplayModeRec));
+}
+
+/*
+ * How awesome is it to have two detailed timing formats, neither of which
+ * are compatible with the format in EDID?  So awesome.
+ */
+
+static void
+didDetailedTiming1(int i, unsigned char *x, MonPtr mon)
+{
+    DisplayModePtr m = modeCalloc();
+
+    if (!m)
+	return;
+
+    m->Clock = extract_le24(x, 0);
+
+    m->HDisplay = extract_le16(x, 4);
+    m->HSyncStart = m->HDisplay + (extract_le16(x, 8) & 0x7f);
+    m->HSyncEnd = m->HSyncStart + extract_le16(x, 10);
+    m->HTotal = m->HDisplay + extract_le16(x, 6);
+    m->Flags |= (x[9] & 0x80) ? V_PHSYNC : V_NHSYNC;
+
+    m->VDisplay = extract_le16(x, 12);
+    m->VSyncStart = m->VDisplay + (extract_le16(x, 16) & 0x7f);
+    m->VSyncEnd = m->VSyncStart + extract_le16(x, 18);
+    m->VTotal = m->VDisplay + extract_le16(x, 14);
+    m->Flags |= (x[17] & 0x80) ? V_PVSYNC : V_NVSYNC;
+
+    m->type = M_T_DRIVER;
+    if (x[3] & 0x80)
+	m->type |= M_T_PREFERRED;
+
+    /* XXX double check handling of this */
+    if (x[3] & 0x10)
+	m->Flags |= V_INTERLACE;
+
+    mon->Modes = xf86ModesAdd(mon->Modes, m);
+}
+
+/* XXX no sync bits.  what to do? */
+static void
+didDetailedTiming2(int i, unsigned char *x, MonPtr mon)
+{
+    DisplayModePtr mode = modeCalloc();
+
+    if (!mode)
+	return;
+
+    mode->Clock = extract_le24(x, 0);
+
+    /* horiz sizes are in character cells, not pixels, hence * 8 */
+    mode->HDisplay = ((extract_le16(x, 4) & 0x01ff) + 1) * 8;
+    mode->HSyncStart = mode->HDisplay + (((x[6] & 0xf0) >> 4) + 1) * 8;
+    mode->HSyncEnd = mode->HSyncStart + ((x[6] & 0x0f) + 1) * 8;
+    mode->HTotal = mode->HDisplay + ((x[5] >> 1) + 1) * 8;
+
+    mode->VDisplay = extract_le16(x, 7) & 0x07ff;
+    mode->VSyncStart = mode->VDisplay + (x[10] >> 4) + 1;
+    mode->VSyncEnd = mode->VSyncStart + (x[10] & 0x0f) + 1;
+    mode->VTotal = mode->VDisplay + x[9];
+
+    mode->status = M_T_DRIVER;
+    if (x[3] & 0x80)
+	mode->status |= M_T_PREFERRED;
+
+    /* XXX double check handling of this */
+    if (x[3] & 0x10)
+	mode->Flags |= V_INTERLACE;
+
+    mon->Modes = xf86ModesAdd(mon->Modes, mode);
+}
+
+static void
+didShortTiming(int i, unsigned char *x, MonPtr mon)
+{
+    DisplayModePtr m;
+    int w, h, r;
+
+    w = (x[1] + 1) * 8;
+    switch (x[0] & 0x0f) {
+	case 0:
+	    h = w;
+	    break;
+	case 1:
+	    h = (w * 4) / 5;
+	    break;
+	case 2:
+	    h = (w * 3) / 4;
+	    break;
+	case 3:
+	    h = (w * 9) / 15;
+	    break;
+	case 4:
+	    h = (w * 9) / 16;
+	    break;
+	case 5:
+	    h = (w * 10) / 16;
+	    break;
+	default:
+	    return;
+    }
+    r = (x[2] & 0x7f) + 1;
+ 
+    m = xf86CVTMode(w, h, r, !!(x[0] & 0x10), !!(x[2] & 0x80));
+
+    m->type = M_T_DRIVER;
+    if (x[0] & 0x80)
+	m->type |= M_T_PREFERRED;
+
+    mon->Modes = xf86ModesAdd(mon->Modes, m);
+}
+
+static void
+didDMTTiming(int i, unsigned char *x, void *closure)
+{
+    MonPtr mon = closure;
+
+    mon->Modes = xf86ModesAdd(mon->Modes,
+			      xf86DuplicateMode(DMTModes + *x));
+}
+
+#define RB 1
+#define INT 2
+static const struct did_dmt {
+    short w, h, r, f;
+} did_dmt[] = {
+    /* byte 3 */
+    { 640, 350, 85, 0 },
+    { 640, 400, 85, 0 },
+    { 720, 400, 85, 0 },
+    { 640, 480, 60, 0 },
+    { 640, 480, 72, 0 },
+    { 640, 480, 75, 0 },
+    { 640, 480, 85, 0 },
+    { 800, 600, 56, 0 },
+    /* byte 4 */
+    { 800, 600, 60, 0 },
+    { 800, 600, 72, 0 },
+    { 800, 600, 75, 0 },
+    { 800, 600, 85, 0 },
+    { 800, 600, 120, RB },
+    { 848, 480, 60, 0 },
+    { 1024, 768, 43, INT },
+    { 1024, 768, 60, 0 },
+    /* byte 5 */
+    { 1024, 768, 70, 0 },
+    { 1024, 768, 75, 0 },
+    { 1024, 768, 85, 0 },
+    { 1024, 768, 120, RB },
+    { 1152, 864, 75, 0 },
+    { 1280, 768, 60, RB },
+    { 1280, 768, 60, 0 },
+    { 1280, 768, 75, 0 },
+    /* byte 6 */
+    { 1280, 768, 85, 0 },
+    { 1280, 768, 120, RB },
+    { 1280, 800, 60, RB },
+    { 1280, 800, 60, 0 },
+    { 1280, 800, 75, 0 },
+    { 1280, 800, 85, 0 },
+    { 1280, 800, 120, RB },
+    { 1280, 960, 60, 0 },
+    /* byte 7 */
+    { 1280, 960, 85, 0 },
+    { 1280, 960, 120, RB },
+    { 1280, 1024, 60, 0 },
+    { 1280, 1024, 75, 0 },
+    { 1280, 1024, 85, 0 },
+    { 1280, 1024, 120, RB },
+    { 1360, 768, 60, 0 },
+    { 1360, 768, 120, RB },
+    /* byte 8 */
+    { 1400, 1050, 60, RB },
+    { 1400, 1050, 60, 0 },
+    { 1400, 1050, 75, 0 },
+    { 1400, 1050, 85, 0 },
+    { 1400, 1050, 120, RB },
+    { 1440, 900, 60, RB },
+    { 1440, 900, 60, 0 },
+    { 1440, 900, 75, 0 },
+    /* byte 9 */
+    { 1440, 900, 85, 0 },
+    { 1440, 900, 120, RB },
+    { 1600, 1200, 60, 0 },
+    { 1600, 1200, 65, 0 },
+    { 1600, 1200, 70, 0 },
+    { 1600, 1200, 75, 0 },
+    { 1600, 1200, 85, 0 },
+    { 1600, 1200, 120, RB },
+    /* byte a */
+    { 1680, 1050, 60, RB },
+    { 1680, 1050, 60, 0 },
+    { 1680, 1050, 75, 0 },
+    { 1680, 1050, 85, 0 },
+    { 1680, 1050, 120, RB },
+    { 1792, 1344, 60, 0 },
+    { 1792, 1344, 75, 0 },
+    { 1792, 1344, 120, RB },
+    /* byte b */
+    { 1856, 1392, 60, 0 },
+    { 1856, 1392, 75, 0 },
+    { 1856, 1392, 120, RB },
+    { 1920, 1200, 60, RB },
+    { 1920, 1200, 60, 0 },
+    { 1920, 1200, 75, 0 },
+    { 1920, 1200, 85, 0 },
+    { 1920, 1200, 120, RB },
+    /* byte c */
+    { 1920, 1440, 60, 0 },
+    { 1920, 1440, 75, 0 },
+    { 1920, 1440, 120, RB },
+    { 2560, 1600, 60, RB },
+    { 2560, 1600, 60, 0 },
+    { 2560, 1600, 75, 0 },
+    { 2560, 1600, 85, 0 },
+    { 2560, 1600, 120, RB },
+};
+
+static void
+didVesaTiming(int scrn, unsigned char *x, MonPtr mon)
+{
+    int i, j;
+
+    x += 3;
+    
+    for (i = 0; i < 10; i++)
+	for (j = 0; j < 8; j++)
+	    if (x[i] & (1 << j)) {
+		const struct did_dmt *d = &(did_dmt[i * 8 + j]);
+		if (d->f == INT)
+		    continue;
+		mon->Modes = xf86ModesAdd(mon->Modes,
+					  FindDMTMode(d->w, d->h, d->r,
+						      d->f == RB));
+	    }
+
+}
+
+static void
+handleDisplayIDBlock(int scrnIndex, unsigned char *x, void *closure)
+{
+    MonPtr mon = closure;
+
+    switch (x[0]) {
+	case DID_DISPLAY_PARAMETERS:
+	    /* w/h are in decimillimeters */
+	    mon->widthmm = (extract_le16(x, 3) + 5) / 10;
+	    mon->heightmm = (extract_le16(x, 5) + 5) / 10;
+	    /* XXX pixel count, feature flags, gamma, aspect, color depth */
+	    break;
+
+	case DID_TIMING_RANGE_LIMITS:
+	{
+	    int n;
+
+	    mon->maxPixClock = max(mon->maxPixClock, extract_le24(x, 6) * 10);
+
+	    n = mon->nHsync++;
+	    if (n < MAX_HSYNC) {
+		mon->hsync[n].lo = x[9];
+		mon->hsync[n].hi = x[10];
+	    } else {
+		n = MAX_HSYNC;
+	    }
+	    n = mon->nVrefresh++;
+	    if (n < MAX_VREFRESH) {
+		mon->vrefresh[n].lo = x[13];
+		mon->vrefresh[n].hi = x[14];
+	    } else {
+		n = MAX_VREFRESH;
+	    }
+	    break;
+	}
+
+	case DID_TIMING_1_DETAILED:
+	{
+	    int i;
+	    for (i = 0; i < x[2]; i += 20)
+		didDetailedTiming1(scrnIndex, x + i + 3, mon);
+	    break;
+	}
+
+	case DID_TIMING_2_DETAILED:
+	{
+	    int i;
+	    for (i = 0; i < x[2]; i += 11)
+		didDetailedTiming2(scrnIndex, x + i + 3, mon);
+	    break;
+	}
+
+	case DID_TIMING_3_SHORT:
+	{
+	    int i;
+	    for (i = 0; i < x[2]; i += 3)
+		didShortTiming(scrnIndex, x + i + 3, mon);
+	    break;
+	}
+
+	case DID_TIMING_4_DMT:
+	{
+	    int i;
+	    for (i = 0; i < x[2]; i++)
+		didDMTTiming(scrnIndex, x + i + 3, mon);
+	    break;
+	}
+
+	case DID_TIMING_VESA:
+	    didVesaTiming(scrnIndex, x, mon);
+	    break;
+
+	/* XXX pixel format, ar, orientation, subpixel, dot pitch, bit depth */
+	case DID_DISPLAY_DEVICE:
+
+	/* XXX interface, links, color encoding, ss, drm */
+	case DID_DISPLAY_INTERFACE:
+
+	/* XXX stereo */
+	case DID_STEREO:
+
+	/* nothing interesting in these */
+	case DID_COLOR_INFO:
+	case DID_PRODUCT_SERIAL:
+	case DID_ASCII_STRING:
+	case DID_POWER_SEQUENCING:
+	case DID_TRANSFER_INFO:
+	case DID_VENDOR:
+	    break;
+
+	/* warn about anything else */
+	default:
+	    xf86DrvMsg(scrnIndex, X_WARNING,
+		       "Unknown DisplayID block type %hx\n", x[0]);
+	    break;
+    }
+}
+
+static void
+forEachDisplayIDBlock(int scrnIndex, unsigned char *did, did_proc proc,
+		      void *closure)
+{
+    int num_extensions = did[3];
+    int section_size = did[1];
+    unsigned char *block;
+
+    do {
+	if ((did[0] & 0xf0) != 0x10) /* not 1.x, abort */
+	    return;
+	/* XXX also, checksum */
+
+	block = did + 4;
+
+	while (section_size > 0) {
+	    int block_size = (block[2] + 2);
+
+	    proc(scrnIndex, block, closure);
+
+	    section_size -= block_size;
+	    block += block_size;
+	}
+
+	did += (did[1] + 5);
+    } while (num_extensions--);
+}
+
+/*
+ * Fill out MonPtr with xf86MonPtr information.
+ */
+void
+xf86DisplayIDMonitorSet(int scrnIndex, MonPtr mon, xf86MonPtr DDC)
+{
+    if (!mon || !DDC)
+        return;
+
+    mon->DDC = DDC;
+
+    forEachDisplayIDBlock(scrnIndex, DDC->rawData, handleDisplayIDBlock, mon);
+}
diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 4bf178d..6e11f9a 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -338,7 +338,7 @@ DDCModesFromEstablished(int scrnIndex, struct established_timings *timing,
 }
 
 /* Autogenerated from the DMT spec */
-static const DisplayModeRec DMTModes[] = {
+const DisplayModeRec DMTModes[] = {
     { MODEPREFIX,    31500,  640,  672,  736,  832, 0,  350,  382,  385,  445, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x350 at 85Hz */
     { MODEPREFIX,    31500,  640,  672,  736,  832, 0,  400,  401,  404,  445, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX }, /* 640x400 at 85Hz */
     { MODEPREFIX,    35500,  720,  756,  828,  936, 0,  400,  401,  404,  446, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX }, /* 720x400 at 85Hz */
@@ -448,7 +448,7 @@ ModeRefresh(const DisplayModeRec *mode)
  * part of the DMT pool.  For the 'standard' EDID mode descriptor there's
  * no way to specify whether the mode should be RB or not.
  */
-static DisplayModePtr
+DisplayModePtr
 FindDMTMode(int hsize, int vsize, int refresh, Bool rb)
 {
     int i;
commit 2f1a9c5baa367818bf017bdb72f20a2f6fa7ac21
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 9 10:13:47 2009 -0400

    ddc: s/xf86DDCMonitorSet/xf86EdidMonitorSet/
    
    Since we need a second path for DisplayID.

diff --git a/hw/xfree86/ddc/ddcProperty.c b/hw/xfree86/ddc/ddcProperty.c
index 834f695..329a639 100644
--- a/hw/xfree86/ddc/ddcProperty.c
+++ b/hw/xfree86/ddc/ddcProperty.c
@@ -114,7 +114,10 @@ xf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
     if (!pScrn || !pScrn->monitor || !DDC)
         return FALSE;
 
-    xf86DDCMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC);
+    if (DDC->flags & MONITOR_DISPLAYID)
+	;
+    else
+	xf86EdidMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC);
 
     addRootWindowProperties(pScrn, DDC);
 
diff --git a/hw/xfree86/ddc/xf86DDC.h b/hw/xfree86/ddc/xf86DDC.h
index 07411b8..2deadce 100644
--- a/hw/xfree86/ddc/xf86DDC.h
+++ b/hw/xfree86/ddc/xf86DDC.h
@@ -50,7 +50,7 @@ extern _X_EXPORT xf86MonPtr xf86InterpretEEDID(
 );
 
 extern _X_EXPORT void
-xf86DDCMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC);
+xf86EdidMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC);
 
 extern _X_EXPORT Bool xf86SetDDCproperties(
     ScrnInfoPtr pScreen,
diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index e7cb167..4bf178d 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -943,7 +943,7 @@ xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC)
  * Fill out MonPtr with xf86MonPtr information.
  */
 void
-xf86DDCMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC)
+xf86EdidMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC)
 {
     DisplayModePtr Modes = NULL, Mode;
     int i, clock;
commit d0cb4f5a91932e901d10cac5f2a4ba12bb8a0e6f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 9 10:10:18 2009 -0400

    ddc: Refactor root window property code

diff --git a/hw/xfree86/ddc/ddcProperty.c b/hw/xfree86/ddc/ddcProperty.c
index 66d734a..834f695 100644
--- a/hw/xfree86/ddc/ddcProperty.c
+++ b/hw/xfree86/ddc/ddcProperty.c
@@ -31,16 +31,28 @@
 #include "property.h"
 #include "propertyst.h"
 #include "xf86DDC.h"
+#include <string.h>
 
 #define EDID1_ATOM_NAME         "XFree86_DDC_EDID1_RAWDATA"
 #define EDID2_ATOM_NAME         "XFree86_DDC_EDID2_RAWDATA"
 
 static void
+edidMakeAtom(int i, const char *name, CARD8 *data, int size)
+{
+    Atom atom;
+    unsigned char *atom_data;
+
+    if (!(atom_data = xalloc(size*sizeof(CARD8))))
+	return;
+
+    atom = MakeAtom(name, strlen(name), TRUE);
+    memcpy(atom_data, data, size);
+    xf86RegisterRootWindowProperty(i, atom, XA_INTEGER, 8, size, atom_data);
+}
+
+static void
 addRootWindowProperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
 {
-    Atom EDID1Atom=-1, EDID2Atom=-1;
-    CARD8 *EDID1rawdata = NULL;
-    CARD8 *EDID2rawdata = NULL;
     int i, scrnIndex = pScrn->scrnIndex;
     Bool makeEDID1prop = FALSE;
     Bool makeEDID2prop = FALSE;
@@ -86,29 +98,14 @@ addRootWindowProperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
     }
 
     if (makeEDID1prop) {
-	int size = 128;
-
-	if (DDC->flags & EDID_COMPLETE_RAWDATA)
-	    size += DDC->no_sections * 128;
-
-	if ((EDID1rawdata = xalloc(size*sizeof(CARD8)))==NULL)
-	    return;
+	int size = 128 +
+	    (DDC->flags & EDID_COMPLETE_RAWDATA ? DDC->no_sections * 128 : 0);
 
-	EDID1Atom = MakeAtom(EDID1_ATOM_NAME, sizeof(EDID1_ATOM_NAME) - 1, TRUE);
-	memcpy(EDID1rawdata, DDC->rawData, size);
-	xf86RegisterRootWindowProperty(scrnIndex, EDID1Atom, XA_INTEGER, 8,
-		size, (unsigned char *)EDID1rawdata);
+	edidMakeAtom(scrnIndex, EDID1_ATOM_NAME, DDC->rawData, size);
     } 
 
-    if (makeEDID2prop) {
-	if ((EDID2rawdata = xalloc(256*sizeof(CARD8)))==NULL)
-	    return;
-
-	memcpy(EDID2rawdata, DDC->rawData, 256);
-	EDID2Atom = MakeAtom(EDID2_ATOM_NAME, sizeof(EDID2_ATOM_NAME) - 1, TRUE);
-	xf86RegisterRootWindowProperty(scrnIndex, EDID2Atom, XA_INTEGER, 8,
-		256, (unsigned char *)EDID2rawdata);
-    }
+    if (makeEDID2prop)
+	edidMakeAtom(scrnIndex, EDID2_ATOM_NAME, DDC->rawData, 256);
 }
 
 Bool
commit 14103b781201bc36896cbe9112a2e0d991fb785d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 9 10:05:01 2009 -0400

    ddc: Don't try to publish a root window property for DisplayID

diff --git a/hw/xfree86/ddc/ddcProperty.c b/hw/xfree86/ddc/ddcProperty.c
index a4384f1..66d734a 100644
--- a/hw/xfree86/ddc/ddcProperty.c
+++ b/hw/xfree86/ddc/ddcProperty.c
@@ -45,7 +45,10 @@ addRootWindowProperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
     Bool makeEDID1prop = FALSE;
     Bool makeEDID2prop = FALSE;
 
-    if (DDC->ver.version == 1) {
+    if (DDC->flags & MONITOR_DISPLAYID) {
+	/* Don't bother, use RANDR already */
+	return;
+    } else if (DDC->ver.version == 1) {
 	makeEDID1prop = TRUE;
     } else if (DDC->ver.version == 2) {
 	int checksum1;
commit c302a5ff49146bff24df196fc36ed38745d42911
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 8 17:42:10 2009 -0400

    ddc: Skeleton for xf86DoDisplayID()

diff --git a/hw/xfree86/ddc/ddc.c b/hw/xfree86/ddc/ddc.c
index 33b77fc..6fad9fb 100644
--- a/hw/xfree86/ddc/ddc.c
+++ b/hw/xfree86/ddc/ddc.c
@@ -426,7 +426,7 @@ xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
     }
 
     if (tmp && complete)
-	tmp->flags |= EDID_COMPLETE_RAWDATA;
+	tmp->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
 
     return tmp;
 }
@@ -447,3 +447,61 @@ xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus)
 {
     return xf86DoEEDID(scrnIndex, pBus, FALSE);
 }
+
+/* XXX write me */
+static void *
+DDC2ReadDisplayID(void)
+{
+    return FALSE;
+}
+
+/**
+ * Attempts to probe the monitor for DisplayID information, if NoDDC and
+ * NoDDC2 are unset.  DisplayID blocks are interpreted and the results
+ * returned in an xf86MonPtr.
+ *
+ * This function does not affect the list of modes used by drivers -- it is up
+ * to the driver to decide policy on what to do with DisplayID information.
+ *
+ * @return pointer to a new xf86MonPtr containing the DisplayID information.
+ * @return NULL if no monitor attached or failure to interpret the DisplayID.
+ */
+xf86MonPtr
+xf86DoDisplayID(int scrnIndex, I2CBusPtr pBus)
+{
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    unsigned char *did = NULL;
+    xf86MonPtr tmp = NULL;
+    I2CDevPtr dev = NULL;
+    /* Default DDC and DDC2 to enabled. */
+    Bool noddc = FALSE, noddc2 = FALSE;
+    OptionInfoPtr options;
+
+    options = xalloc(sizeof(DDCOptions));
+    if (!options)
+	return NULL;
+    memcpy(options, DDCOptions, sizeof(DDCOptions));
+    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
+
+    xf86GetOptValBool(options, DDCOPT_NODDC, &noddc);
+    xf86GetOptValBool(options, DDCOPT_NODDC2, &noddc2);
+    xfree(options);
+
+    if (noddc || noddc2)
+	return NULL;
+
+    if (!(dev = DDC2Init(scrnIndex, pBus)))
+	return NULL;
+
+    if ((did = DDC2ReadDisplayID())) {
+	tmp = xcalloc(1, sizeof(*tmp));
+	if (!tmp)
+	    return NULL;
+
+	tmp->scrnIndex = scrnIndex;
+	tmp->flags |= MONITOR_DISPLAYID;
+	tmp->rawData = did;
+    }
+
+    return tmp;
+}
commit 0b36f68efb1171fcdbe53e93064394f5609b7fb5
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 8 15:36:15 2009 -0400

    ddc: mv xf86DDC.c ddc.c

diff --git a/hw/xfree86/ddc/Makefile.am b/hw/xfree86/ddc/Makefile.am
index 8ffe433..93ea4a2 100644
--- a/hw/xfree86/ddc/Makefile.am
+++ b/hw/xfree86/ddc/Makefile.am
@@ -2,7 +2,7 @@ sdk_HEADERS = edid.h xf86DDC.h
 
 noinst_LTLIBRARIES = libddc.la
 
-libddc_la_SOURCES = xf86DDC.c interpret_edid.c print_edid.c ddcProperty.c
+libddc_la_SOURCES = ddc.c interpret_edid.c print_edid.c ddcProperty.c
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../i2c
 
diff --git a/hw/xfree86/ddc/ddc.c b/hw/xfree86/ddc/ddc.c
new file mode 100644
index 0000000..33b77fc
--- /dev/null
+++ b/hw/xfree86/ddc/ddc.c
@@ -0,0 +1,449 @@
+/* xf86DDC.c 
+ * 
+ * Copyright 1998,1999 by Egbert Eich <Egbert.Eich at Physik.TU-Darmstadt.DE>
+ */
+
+/*
+ * A note on terminology.  DDC1 is the original dumb serial protocol, and
+ * can only do up to 128 bytes of EDID.  DDC2 is I2C-encapsulated and
+ * introduces extension blocks.  EDID is the old display identification
+ * block, DisplayID is the new one.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "misc.h"
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "xf86DDC.h"
+#include <string.h>
+
+#define RETRIES 4
+
+typedef enum {
+    DDCOPT_NODDC1,
+    DDCOPT_NODDC2,
+    DDCOPT_NODDC
+} DDCOpts;
+
+static const OptionInfoRec DDCOptions[] = {
+    { DDCOPT_NODDC1,	"NoDDC1",	OPTV_BOOLEAN,	{0},	FALSE },
+    { DDCOPT_NODDC2,	"NoDDC2",	OPTV_BOOLEAN,	{0},	FALSE },
+    { DDCOPT_NODDC,	"NoDDC",	OPTV_BOOLEAN,	{0},	FALSE },
+    { -1,		NULL,		OPTV_NONE,	{0},	FALSE },
+};
+
+/* DDC1 */
+
+static int
+find_start(unsigned int *ptr)
+{
+    unsigned int comp[9], test[9];
+    int i,j;
+  
+    for (i=0;i<9;i++){
+	comp[i] = *(ptr++);
+	test[i] = 1;
+    }
+    for (i=0;i<127;i++){
+	for (j=0;j<9;j++){
+	    test[j] = test[j] & !(comp[j] ^ *(ptr++));
+	}
+    }
+    for (i=0;i<9;i++)
+	if (test[i]) return (i+1);
+    return (-1);
+}
+
+static unsigned char *
+find_header(unsigned char *block)
+{
+    unsigned char *ptr, *head_ptr, *end;
+    unsigned char header[]={0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
+ 
+    ptr = block;
+    end = block + EDID1_LEN;
+    while (ptr<end) {
+	int i;
+	head_ptr = ptr;
+	for (i=0;i<8;i++){
+	    if (header[i] != *(head_ptr++)) break;
+	    if (head_ptr == end) head_ptr = block;
+	}
+	if (i==8) break;
+	ptr++; 
+    }
+    if (ptr == end) return (NULL);
+    return (ptr);
+}
+
+static unsigned char *
+resort(unsigned char *s_block)
+{
+    unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
+    unsigned char tmp;
+
+    s_end = s_block + EDID1_LEN;
+    d_new = xalloc(EDID1_LEN);
+    if (!d_new) return NULL;
+    d_end = d_new + EDID1_LEN;
+
+    s_ptr = find_header(s_block);
+    if (!s_ptr) return NULL;
+    for (d_ptr=d_new;d_ptr<d_end;d_ptr++){
+	tmp = *(s_ptr++);
+	*d_ptr = tmp; 
+	if (s_ptr == s_end) s_ptr = s_block;
+    }
+    xfree(s_block);
+    return (d_new);
+}
+
+static int
+DDC_checksum(unsigned char *block, int len)
+{
+    int i, result = 0;
+    int not_null = 0;
+    
+    for (i=0;i<len;i++) {
+	not_null |= block[i];
+	result += block[i];
+    }
+    
+#ifdef DEBUG
+    if (result & 0xFF) ErrorF("DDC checksum not correct\n");
+    if (!not_null) ErrorF("DDC read all Null\n");
+#endif
+
+    /* catch the trivial case where all bytes are 0 */
+    if (!not_null) return 1;
+
+    return (result&0xFF);
+}
+
+static unsigned char *
+GetEDID_DDC1(unsigned int *s_ptr)
+{
+    unsigned char *d_block, *d_pos;
+    unsigned int *s_pos, *s_end;
+    int s_start;
+    int i,j;
+    s_start = find_start(s_ptr);
+    if (s_start==-1) return NULL;
+    s_end = s_ptr + NUM;
+    s_pos = s_ptr + s_start;
+    d_block=xalloc(EDID1_LEN);
+    if (!d_block) return NULL;
+    d_pos = d_block;
+    for (i=0;i<EDID1_LEN;i++) {
+	for (j=0;j<8;j++) {
+	    *d_pos <<= 1;
+	    if (*s_pos) {
+		*d_pos |= 0x01;
+	    }
+	    s_pos++; if (s_pos == s_end) s_pos=s_ptr;
+	};
+	s_pos++; if (s_pos == s_end) s_pos=s_ptr;
+	d_pos++;
+    }
+    xfree(s_ptr);
+    if (d_block && DDC_checksum(d_block,EDID1_LEN)) return NULL;
+    return (resort(d_block));
+}
+
+/* fetch entire EDID record; DDC bit needs to be masked */
+static unsigned int * 
+FetchEDID_DDC1(register ScrnInfoPtr pScrn,
+	       register unsigned int (*read_DDC)(ScrnInfoPtr))
+{
+    int count = NUM;
+    unsigned int *ptr, *xp;
+
+    ptr=xp=xalloc(sizeof(int)*NUM); 
+
+    if (!ptr)  return NULL;
+    do {
+	/* wait for next retrace */
+	*xp = read_DDC(pScrn);
+	xp++;
+    } while(--count);
+    return (ptr);
+}
+
+/* test if DDC1  return 0 if not */
+static Bool
+TestDDC1(ScrnInfoPtr pScrn, unsigned int (*read_DDC)(ScrnInfoPtr))
+{
+    int old, count;
+
+    old = read_DDC(pScrn);
+    count = HEADER * BITS_PER_BYTE;
+    do {
+	/* wait for next retrace */
+	if (old != read_DDC(pScrn)) break;
+    } while(count--);
+    return (count);
+}
+
+/* 
+ * read EDID record , pass it to callback function to interpret.
+ * callback function will store it for further use by calling
+ * function; it will also decide if we need to reread it 
+ */
+static unsigned char *
+EDIDRead_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDCSpeed, 
+              unsigned int (*read_DDC)(ScrnInfoPtr))
+{
+    unsigned char *EDID_block = NULL;
+    int count = RETRIES;
+
+    if (!read_DDC) { 
+	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, 
+		   "chipset doesn't support DDC1\n");
+	return NULL; 
+    };
+
+    if (TestDDC1(pScrn,read_DDC)==-1) { 
+	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "No DDC signal\n"); 
+	return NULL; 
+    };
+
+    if (DDCSpeed) DDCSpeed(pScrn,DDC_FAST);
+    do {
+	EDID_block = GetEDID_DDC1(FetchEDID_DDC1(pScrn,read_DDC)); 
+	count --;
+    } while (!EDID_block && count);
+    if (DDCSpeed) DDCSpeed(pScrn,DDC_SLOW);
+
+    return EDID_block;
+}
+
+/**
+ * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC1 are
+ * unset.  EDID information blocks are interpreted and the results returned in
+ * an xf86MonPtr.
+ *
+ * This function does not affect the list of modes used by drivers -- it is up
+ * to the driver to decide policy on what to do with EDID information.
+ *
+ * @return pointer to a new xf86MonPtr containing the EDID information.
+ * @return NULL if no monitor attached or failure to interpret the EDID.
+ */
+xf86MonPtr
+xf86DoEDID_DDC1(
+    int scrnIndex, DDC1SetSpeedProc DDC1SetSpeed, 
+    unsigned int (*DDC1Read)(ScrnInfoPtr)
+)
+{
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    unsigned char *EDID_block = NULL;
+    xf86MonPtr tmp = NULL;
+    int sigio;
+    /* Default DDC and DDC1 to enabled. */
+    Bool noddc = FALSE, noddc1 = FALSE;
+    OptionInfoPtr options;
+
+    options = xnfalloc(sizeof(DDCOptions));
+    (void)memcpy(options, DDCOptions, sizeof(DDCOptions));
+    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
+
+    xf86GetOptValBool(options, DDCOPT_NODDC, &noddc);
+    xf86GetOptValBool(options, DDCOPT_NODDC1, &noddc1);
+    xfree(options);
+    
+    if (noddc || noddc1)
+	return NULL;
+    
+    sigio = xf86BlockSIGIO();
+    EDID_block = EDIDRead_DDC1(pScrn,DDC1SetSpeed,DDC1Read);
+    xf86UnblockSIGIO(sigio);
+
+    if (EDID_block){
+	tmp = xf86InterpretEDID(scrnIndex,EDID_block);
+    }
+#ifdef DEBUG
+	else ErrorF("No EDID block returned\n");
+    if (!tmp)
+	ErrorF("Cannot interpret EDID block\n");
+#endif
+	return tmp;
+}
+
+/* DDC2 */
+
+static I2CDevPtr
+DDC2MakeDevice(I2CBusPtr pBus, int address, char *name)
+{
+    I2CDevPtr dev = NULL;
+
+    if (!(dev = xf86I2CFindDev(pBus, address))) {
+	dev = xf86CreateI2CDevRec();
+	dev->DevName = name;
+	dev->SlaveAddr = address;
+	dev->ByteTimeout = 2200; /* VESA DDC spec 3 p. 43 (+10 %) */
+	dev->StartTimeout = 550;
+	dev->BitTimeout = 40;
+	dev->AcknTimeout = 40;
+
+	dev->pI2CBus = pBus;
+	if (!xf86I2CDevInit(dev)) {
+	    xf86DrvMsg(pBus->scrnIndex, X_PROBED, "No DDC2 device\n");
+	    return NULL;
+	}
+    }
+
+    return dev;
+}
+
+static I2CDevPtr
+DDC2Init(int scrnIndex, I2CBusPtr pBus)
+{
+    I2CDevPtr dev = NULL;
+
+    /*
+     * Slow down the bus so that older monitors don't 
+     * miss things.
+     */
+    pBus->RiseFallTime = 20;
+ 
+    dev = DDC2MakeDevice(pBus, 0x00A0, "ddc2");
+    if (xf86I2CProbeAddress(pBus, 0x0060))
+	DDC2MakeDevice(pBus, 0x0060, "E-EDID segment register");
+    if (xf86I2CProbeAddress(pBus, 0x0062))
+	DDC2MakeDevice(pBus, 0x0062, "EDID EEPROM interface");
+    if (xf86I2CProbeAddress(pBus, 0x006E))
+	DDC2MakeDevice(pBus, 0x006E, "DDC control interface");
+
+    return dev;
+}
+
+/* Mmmm, smell the hacks */
+static void
+EEDIDStop(I2CDevPtr d)
+{
+}
+
+/* block is the EDID block number.  a segment is two blocks. */
+static Bool
+DDC2Read(I2CDevPtr dev, int block, unsigned char *R_Buffer)
+{
+    unsigned char W_Buffer[1];
+    int i, segment;
+    I2CDevPtr seg;
+    void (*stop)(I2CDevPtr);
+
+    for (i = 0; i < RETRIES; i++) {
+	/* Stop bits reset the segment pointer to 0, so be careful here. */
+	segment = block >> 1;
+	if (segment) {
+	    Bool b;
+	    
+	    if (!(seg = xf86I2CFindDev(dev->pI2CBus, 0x0060)))
+		return FALSE;
+
+	    W_Buffer[0] = segment;
+
+	    stop = dev->pI2CBus->I2CStop;
+	    dev->pI2CBus->I2CStop = EEDIDStop;
+
+	    b = xf86I2CWriteRead(seg, W_Buffer, 1, NULL, 0);
+
+	    dev->pI2CBus->I2CStop = stop;
+	    if (!b) {
+		dev->pI2CBus->I2CStop(dev);
+		continue;
+	    }
+	}
+
+	W_Buffer[0] = (block & 0x01) * EDID1_LEN;
+
+	if (xf86I2CWriteRead(dev, W_Buffer, 1, R_Buffer, EDID1_LEN)) {
+	    if (!DDC_checksum(R_Buffer, EDID1_LEN))
+		return TRUE;
+	}
+    }
+ 
+    return FALSE;
+}
+
+/**
+ * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC2 are
+ * unset.  EDID information blocks are interpreted and the results returned in
+ * an xf86MonPtr.  Unlike xf86DoEDID_DDC[12](), this function will return
+ * the complete EDID data, including all extension blocks, if the 'complete'
+ * parameter is TRUE;
+ *
+ * This function does not affect the list of modes used by drivers -- it is up
+ * to the driver to decide policy on what to do with EDID information.
+ *
+ * @return pointer to a new xf86MonPtr containing the EDID information.
+ * @return NULL if no monitor attached or failure to interpret the EDID.
+ */
+xf86MonPtr
+xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
+{
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    unsigned char *EDID_block = NULL;
+    xf86MonPtr tmp = NULL;
+    I2CDevPtr dev = NULL;
+    /* Default DDC and DDC2 to enabled. */
+    Bool noddc = FALSE, noddc2 = FALSE;
+    OptionInfoPtr options;
+
+    options = xalloc(sizeof(DDCOptions));
+    if (!options)
+	return NULL;
+    memcpy(options, DDCOptions, sizeof(DDCOptions));
+    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
+
+    xf86GetOptValBool(options, DDCOPT_NODDC, &noddc);
+    xf86GetOptValBool(options, DDCOPT_NODDC2, &noddc2);
+    xfree(options);
+
+    if (noddc || noddc2)
+	return NULL;
+
+    if (!(dev = DDC2Init(scrnIndex, pBus)))
+	return NULL;
+
+    EDID_block = xcalloc(1, EDID1_LEN);
+    if (!EDID_block)
+	return NULL;
+
+    if (DDC2Read(dev, 0, EDID_block)) {
+	int i, n = EDID_block[0x7e];
+
+	if (complete && n) {
+	    EDID_block = xrealloc(EDID_block, EDID1_LEN * (1+n));
+
+	    for (i = 0; i < n; i++)
+		DDC2Read(dev, i+1, EDID_block + (EDID1_LEN * (1+i)));
+	}
+
+	tmp = xf86InterpretEEDID(scrnIndex, EDID_block);
+    }
+
+    if (tmp && complete)
+	tmp->flags |= EDID_COMPLETE_RAWDATA;
+
+    return tmp;
+}
+
+/**
+ * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC2 are
+ * unset.  EDID information blocks are interpreted and the results returned in
+ * an xf86MonPtr.
+ *
+ * This function does not affect the list of modes used by drivers -- it is up
+ * to the driver to decide policy on what to do with EDID information.
+ *
+ * @return pointer to a new xf86MonPtr containing the EDID information.
+ * @return NULL if no monitor attached or failure to interpret the EDID.
+ */
+xf86MonPtr
+xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus)
+{
+    return xf86DoEEDID(scrnIndex, pBus, FALSE);
+}
diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
deleted file mode 100644
index 33b77fc..0000000
--- a/hw/xfree86/ddc/xf86DDC.c
+++ /dev/null
@@ -1,449 +0,0 @@
-/* xf86DDC.c 
- * 
- * Copyright 1998,1999 by Egbert Eich <Egbert.Eich at Physik.TU-Darmstadt.DE>
- */
-
-/*
- * A note on terminology.  DDC1 is the original dumb serial protocol, and
- * can only do up to 128 bytes of EDID.  DDC2 is I2C-encapsulated and
- * introduces extension blocks.  EDID is the old display identification
- * block, DisplayID is the new one.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "xf86DDC.h"
-#include <string.h>
-
-#define RETRIES 4
-
-typedef enum {
-    DDCOPT_NODDC1,
-    DDCOPT_NODDC2,
-    DDCOPT_NODDC
-} DDCOpts;
-
-static const OptionInfoRec DDCOptions[] = {
-    { DDCOPT_NODDC1,	"NoDDC1",	OPTV_BOOLEAN,	{0},	FALSE },
-    { DDCOPT_NODDC2,	"NoDDC2",	OPTV_BOOLEAN,	{0},	FALSE },
-    { DDCOPT_NODDC,	"NoDDC",	OPTV_BOOLEAN,	{0},	FALSE },
-    { -1,		NULL,		OPTV_NONE,	{0},	FALSE },
-};
-
-/* DDC1 */
-
-static int
-find_start(unsigned int *ptr)
-{
-    unsigned int comp[9], test[9];
-    int i,j;
-  
-    for (i=0;i<9;i++){
-	comp[i] = *(ptr++);
-	test[i] = 1;
-    }
-    for (i=0;i<127;i++){
-	for (j=0;j<9;j++){
-	    test[j] = test[j] & !(comp[j] ^ *(ptr++));
-	}
-    }
-    for (i=0;i<9;i++)
-	if (test[i]) return (i+1);
-    return (-1);
-}
-
-static unsigned char *
-find_header(unsigned char *block)
-{
-    unsigned char *ptr, *head_ptr, *end;
-    unsigned char header[]={0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
- 
-    ptr = block;
-    end = block + EDID1_LEN;
-    while (ptr<end) {
-	int i;
-	head_ptr = ptr;
-	for (i=0;i<8;i++){
-	    if (header[i] != *(head_ptr++)) break;
-	    if (head_ptr == end) head_ptr = block;
-	}
-	if (i==8) break;
-	ptr++; 
-    }
-    if (ptr == end) return (NULL);
-    return (ptr);
-}
-
-static unsigned char *
-resort(unsigned char *s_block)
-{
-    unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
-    unsigned char tmp;
-
-    s_end = s_block + EDID1_LEN;
-    d_new = xalloc(EDID1_LEN);
-    if (!d_new) return NULL;
-    d_end = d_new + EDID1_LEN;
-
-    s_ptr = find_header(s_block);
-    if (!s_ptr) return NULL;
-    for (d_ptr=d_new;d_ptr<d_end;d_ptr++){
-	tmp = *(s_ptr++);
-	*d_ptr = tmp; 
-	if (s_ptr == s_end) s_ptr = s_block;
-    }
-    xfree(s_block);
-    return (d_new);
-}
-
-static int
-DDC_checksum(unsigned char *block, int len)
-{
-    int i, result = 0;
-    int not_null = 0;
-    
-    for (i=0;i<len;i++) {
-	not_null |= block[i];
-	result += block[i];
-    }
-    
-#ifdef DEBUG
-    if (result & 0xFF) ErrorF("DDC checksum not correct\n");
-    if (!not_null) ErrorF("DDC read all Null\n");
-#endif
-
-    /* catch the trivial case where all bytes are 0 */
-    if (!not_null) return 1;
-
-    return (result&0xFF);
-}
-
-static unsigned char *
-GetEDID_DDC1(unsigned int *s_ptr)
-{
-    unsigned char *d_block, *d_pos;
-    unsigned int *s_pos, *s_end;
-    int s_start;
-    int i,j;
-    s_start = find_start(s_ptr);
-    if (s_start==-1) return NULL;
-    s_end = s_ptr + NUM;
-    s_pos = s_ptr + s_start;
-    d_block=xalloc(EDID1_LEN);
-    if (!d_block) return NULL;
-    d_pos = d_block;
-    for (i=0;i<EDID1_LEN;i++) {
-	for (j=0;j<8;j++) {
-	    *d_pos <<= 1;
-	    if (*s_pos) {
-		*d_pos |= 0x01;
-	    }
-	    s_pos++; if (s_pos == s_end) s_pos=s_ptr;
-	};
-	s_pos++; if (s_pos == s_end) s_pos=s_ptr;
-	d_pos++;
-    }
-    xfree(s_ptr);
-    if (d_block && DDC_checksum(d_block,EDID1_LEN)) return NULL;
-    return (resort(d_block));
-}
-
-/* fetch entire EDID record; DDC bit needs to be masked */
-static unsigned int * 
-FetchEDID_DDC1(register ScrnInfoPtr pScrn,
-	       register unsigned int (*read_DDC)(ScrnInfoPtr))
-{
-    int count = NUM;
-    unsigned int *ptr, *xp;
-
-    ptr=xp=xalloc(sizeof(int)*NUM); 
-
-    if (!ptr)  return NULL;
-    do {
-	/* wait for next retrace */
-	*xp = read_DDC(pScrn);
-	xp++;
-    } while(--count);
-    return (ptr);
-}
-
-/* test if DDC1  return 0 if not */
-static Bool
-TestDDC1(ScrnInfoPtr pScrn, unsigned int (*read_DDC)(ScrnInfoPtr))
-{
-    int old, count;
-
-    old = read_DDC(pScrn);
-    count = HEADER * BITS_PER_BYTE;
-    do {
-	/* wait for next retrace */
-	if (old != read_DDC(pScrn)) break;
-    } while(count--);
-    return (count);
-}
-
-/* 
- * read EDID record , pass it to callback function to interpret.
- * callback function will store it for further use by calling
- * function; it will also decide if we need to reread it 
- */
-static unsigned char *
-EDIDRead_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDCSpeed, 
-              unsigned int (*read_DDC)(ScrnInfoPtr))
-{
-    unsigned char *EDID_block = NULL;
-    int count = RETRIES;
-
-    if (!read_DDC) { 
-	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, 
-		   "chipset doesn't support DDC1\n");
-	return NULL; 
-    };
-
-    if (TestDDC1(pScrn,read_DDC)==-1) { 
-	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "No DDC signal\n"); 
-	return NULL; 
-    };
-
-    if (DDCSpeed) DDCSpeed(pScrn,DDC_FAST);
-    do {
-	EDID_block = GetEDID_DDC1(FetchEDID_DDC1(pScrn,read_DDC)); 
-	count --;
-    } while (!EDID_block && count);
-    if (DDCSpeed) DDCSpeed(pScrn,DDC_SLOW);
-
-    return EDID_block;
-}
-
-/**
- * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC1 are
- * unset.  EDID information blocks are interpreted and the results returned in
- * an xf86MonPtr.
- *
- * This function does not affect the list of modes used by drivers -- it is up
- * to the driver to decide policy on what to do with EDID information.
- *
- * @return pointer to a new xf86MonPtr containing the EDID information.
- * @return NULL if no monitor attached or failure to interpret the EDID.
- */
-xf86MonPtr
-xf86DoEDID_DDC1(
-    int scrnIndex, DDC1SetSpeedProc DDC1SetSpeed, 
-    unsigned int (*DDC1Read)(ScrnInfoPtr)
-)
-{
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-    unsigned char *EDID_block = NULL;
-    xf86MonPtr tmp = NULL;
-    int sigio;
-    /* Default DDC and DDC1 to enabled. */
-    Bool noddc = FALSE, noddc1 = FALSE;
-    OptionInfoPtr options;
-
-    options = xnfalloc(sizeof(DDCOptions));
-    (void)memcpy(options, DDCOptions, sizeof(DDCOptions));
-    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
-
-    xf86GetOptValBool(options, DDCOPT_NODDC, &noddc);
-    xf86GetOptValBool(options, DDCOPT_NODDC1, &noddc1);
-    xfree(options);
-    
-    if (noddc || noddc1)
-	return NULL;
-    
-    sigio = xf86BlockSIGIO();
-    EDID_block = EDIDRead_DDC1(pScrn,DDC1SetSpeed,DDC1Read);
-    xf86UnblockSIGIO(sigio);
-
-    if (EDID_block){
-	tmp = xf86InterpretEDID(scrnIndex,EDID_block);
-    }
-#ifdef DEBUG
-	else ErrorF("No EDID block returned\n");
-    if (!tmp)
-	ErrorF("Cannot interpret EDID block\n");
-#endif
-	return tmp;
-}
-
-/* DDC2 */
-
-static I2CDevPtr
-DDC2MakeDevice(I2CBusPtr pBus, int address, char *name)
-{
-    I2CDevPtr dev = NULL;
-
-    if (!(dev = xf86I2CFindDev(pBus, address))) {
-	dev = xf86CreateI2CDevRec();
-	dev->DevName = name;
-	dev->SlaveAddr = address;
-	dev->ByteTimeout = 2200; /* VESA DDC spec 3 p. 43 (+10 %) */
-	dev->StartTimeout = 550;
-	dev->BitTimeout = 40;
-	dev->AcknTimeout = 40;
-
-	dev->pI2CBus = pBus;
-	if (!xf86I2CDevInit(dev)) {
-	    xf86DrvMsg(pBus->scrnIndex, X_PROBED, "No DDC2 device\n");
-	    return NULL;
-	}
-    }
-
-    return dev;
-}
-
-static I2CDevPtr
-DDC2Init(int scrnIndex, I2CBusPtr pBus)
-{
-    I2CDevPtr dev = NULL;
-
-    /*
-     * Slow down the bus so that older monitors don't 
-     * miss things.
-     */
-    pBus->RiseFallTime = 20;
- 
-    dev = DDC2MakeDevice(pBus, 0x00A0, "ddc2");
-    if (xf86I2CProbeAddress(pBus, 0x0060))
-	DDC2MakeDevice(pBus, 0x0060, "E-EDID segment register");
-    if (xf86I2CProbeAddress(pBus, 0x0062))
-	DDC2MakeDevice(pBus, 0x0062, "EDID EEPROM interface");
-    if (xf86I2CProbeAddress(pBus, 0x006E))
-	DDC2MakeDevice(pBus, 0x006E, "DDC control interface");
-
-    return dev;
-}
-
-/* Mmmm, smell the hacks */
-static void
-EEDIDStop(I2CDevPtr d)
-{
-}
-
-/* block is the EDID block number.  a segment is two blocks. */
-static Bool
-DDC2Read(I2CDevPtr dev, int block, unsigned char *R_Buffer)
-{
-    unsigned char W_Buffer[1];
-    int i, segment;
-    I2CDevPtr seg;
-    void (*stop)(I2CDevPtr);
-
-    for (i = 0; i < RETRIES; i++) {
-	/* Stop bits reset the segment pointer to 0, so be careful here. */
-	segment = block >> 1;
-	if (segment) {
-	    Bool b;
-	    
-	    if (!(seg = xf86I2CFindDev(dev->pI2CBus, 0x0060)))
-		return FALSE;
-
-	    W_Buffer[0] = segment;
-
-	    stop = dev->pI2CBus->I2CStop;
-	    dev->pI2CBus->I2CStop = EEDIDStop;
-
-	    b = xf86I2CWriteRead(seg, W_Buffer, 1, NULL, 0);
-
-	    dev->pI2CBus->I2CStop = stop;
-	    if (!b) {
-		dev->pI2CBus->I2CStop(dev);
-		continue;
-	    }
-	}
-
-	W_Buffer[0] = (block & 0x01) * EDID1_LEN;
-
-	if (xf86I2CWriteRead(dev, W_Buffer, 1, R_Buffer, EDID1_LEN)) {
-	    if (!DDC_checksum(R_Buffer, EDID1_LEN))
-		return TRUE;
-	}
-    }
- 
-    return FALSE;
-}
-
-/**
- * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC2 are
- * unset.  EDID information blocks are interpreted and the results returned in
- * an xf86MonPtr.  Unlike xf86DoEDID_DDC[12](), this function will return
- * the complete EDID data, including all extension blocks, if the 'complete'
- * parameter is TRUE;
- *
- * This function does not affect the list of modes used by drivers -- it is up
- * to the driver to decide policy on what to do with EDID information.
- *
- * @return pointer to a new xf86MonPtr containing the EDID information.
- * @return NULL if no monitor attached or failure to interpret the EDID.
- */
-xf86MonPtr
-xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
-{
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-    unsigned char *EDID_block = NULL;
-    xf86MonPtr tmp = NULL;
-    I2CDevPtr dev = NULL;
-    /* Default DDC and DDC2 to enabled. */
-    Bool noddc = FALSE, noddc2 = FALSE;
-    OptionInfoPtr options;
-
-    options = xalloc(sizeof(DDCOptions));
-    if (!options)
-	return NULL;
-    memcpy(options, DDCOptions, sizeof(DDCOptions));
-    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
-
-    xf86GetOptValBool(options, DDCOPT_NODDC, &noddc);
-    xf86GetOptValBool(options, DDCOPT_NODDC2, &noddc2);
-    xfree(options);
-
-    if (noddc || noddc2)
-	return NULL;
-
-    if (!(dev = DDC2Init(scrnIndex, pBus)))
-	return NULL;
-
-    EDID_block = xcalloc(1, EDID1_LEN);
-    if (!EDID_block)
-	return NULL;
-
-    if (DDC2Read(dev, 0, EDID_block)) {
-	int i, n = EDID_block[0x7e];
-
-	if (complete && n) {
-	    EDID_block = xrealloc(EDID_block, EDID1_LEN * (1+n));
-
-	    for (i = 0; i < n; i++)
-		DDC2Read(dev, i+1, EDID_block + (EDID1_LEN * (1+i)));
-	}
-
-	tmp = xf86InterpretEEDID(scrnIndex, EDID_block);
-    }
-
-    if (tmp && complete)
-	tmp->flags |= EDID_COMPLETE_RAWDATA;
-
-    return tmp;
-}
-
-/**
- * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC2 are
- * unset.  EDID information blocks are interpreted and the results returned in
- * an xf86MonPtr.
- *
- * This function does not affect the list of modes used by drivers -- it is up
- * to the driver to decide policy on what to do with EDID information.
- *
- * @return pointer to a new xf86MonPtr containing the EDID information.
- * @return NULL if no monitor attached or failure to interpret the EDID.
- */
-xf86MonPtr
-xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus)
-{
-    return xf86DoEEDID(scrnIndex, pBus, FALSE);
-}
commit 8eb82168fc5c7ea958a4f63676738510647dd203
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 8 15:34:42 2009 -0400

    ddc: Give DisplayID a place to hang its hat

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 42ee9d1..3feb979 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -538,8 +538,15 @@ struct detailed_monitor_section {
 };
 
 /* flags */
-#define EDID_COMPLETE_RAWDATA	0x1
+#define MONITOR_EDID_COMPLETE_RAWDATA	0x01
+/* old, don't use */
+#define EDID_COMPLETE_RAWDATA		0x01
+#define MONITOR_DISPLAYID		0x02
 
+/*
+ * For DisplayID devices, only the scrnIndex, flags, and rawData fields
+ * are meaningful.  For EDID, they all are.
+ */
 typedef struct {
   int scrnIndex;
   struct vendor vendor;
commit ace0fe09aee48d57cd0079260cd8d20d041e8eb6
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 8 14:45:47 2009 -0400

    ddc: Yet more code motion

diff --git a/hw/xfree86/ddc/Makefile.am b/hw/xfree86/ddc/Makefile.am
index d32e2f4..8ffe433 100644
--- a/hw/xfree86/ddc/Makefile.am
+++ b/hw/xfree86/ddc/Makefile.am
@@ -2,11 +2,10 @@ sdk_HEADERS = edid.h xf86DDC.h
 
 noinst_LTLIBRARIES = libddc.la
 
-libddc_la_SOURCES = xf86DDC.c edid.c interpret_edid.c print_edid.c \
-                   ddcProperty.c
+libddc_la_SOURCES = xf86DDC.c interpret_edid.c print_edid.c ddcProperty.c
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../i2c
 
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
-EXTRA_DIST = ddcPriv.h DDC.HOWTO
+EXTRA_DIST = DDC.HOWTO
diff --git a/hw/xfree86/ddc/ddcPriv.h b/hw/xfree86/ddc/ddcPriv.h
deleted file mode 100644
index b5cb9b8..0000000
--- a/hw/xfree86/ddc/ddcPriv.h
+++ /dev/null
@@ -1,9 +0,0 @@
-extern unsigned char *GetEDID_DDC1(
-    unsigned int *
-);
-
-extern int DDC_checksum(
-    unsigned char *,
-    int
-);
-
diff --git a/hw/xfree86/ddc/edid.c b/hw/xfree86/ddc/edid.c
deleted file mode 100644
index 3ebafbb..0000000
--- a/hw/xfree86/ddc/edid.c
+++ /dev/null
@@ -1,140 +0,0 @@
-
-/* edid.c:  retrieve EDID record from raw DDC1 data stream: data 
- * is contained in an array of unsigned int each unsigned int 
- * contains one bit if bit is 0 unsigned int has to be zero else 
- * unsigned int > 0 
- * 
- * Copyright 1998 by Egbert Eich <Egbert.Eich at Physik.TU-Darmstadt.DE>
- */
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "xf86DDC.h"
-#include "ddcPriv.h"
-#include <string.h>
-
-static int find_start(unsigned int *);
-static unsigned char * find_header(unsigned char *);
-static unsigned char * resort(unsigned char *);
-
-unsigned char *
-GetEDID_DDC1(unsigned int *s_ptr)
-{
-    unsigned char *d_block, *d_pos;
-    unsigned int *s_pos, *s_end;
-    int s_start;
-    int i,j;
-    s_start = find_start(s_ptr);
-    if (s_start==-1) return NULL;
-    s_end = s_ptr + NUM;
-    s_pos = s_ptr + s_start;
-    d_block=xalloc(EDID1_LEN);
-    if (!d_block) return NULL;
-    d_pos = d_block;
-    for (i=0;i<EDID1_LEN;i++) {
-	for (j=0;j<8;j++) {
-	    *d_pos <<= 1;
-	    if (*s_pos) {
-		*d_pos |= 0x01;
-	    }
-	    s_pos++; if (s_pos == s_end) s_pos=s_ptr;
-	};
-	s_pos++; if (s_pos == s_end) s_pos=s_ptr;
-	d_pos++;
-    }
-    xfree(s_ptr);
-    if (d_block && DDC_checksum(d_block,EDID1_LEN)) return NULL;
-    return (resort(d_block));
-}
-
-int
-DDC_checksum(unsigned char *block, int len)
-{
-    int i, result = 0;
-    int not_null = 0;
-    
-    for (i=0;i<len;i++) {
-	not_null |= block[i];
-	result += block[i];
-    }
-    
-#ifdef DEBUG
-    if (result & 0xFF) ErrorF("DDC checksum not correct\n");
-    if (!not_null) ErrorF("DDC read all Null\n");
-#endif
-
-    /* catch the trivial case where all bytes are 0 */
-    if (!not_null) return 1;
-
-    return (result&0xFF);
-}
-
-static int
-find_start(unsigned int *ptr)
-{
-    unsigned int comp[9], test[9];
-    int i,j;
-  
-    for (i=0;i<9;i++){
-	comp[i] = *(ptr++);
-	test[i] = 1;
-    }
-    for (i=0;i<127;i++){
-	for (j=0;j<9;j++){
-	    test[j] = test[j] & !(comp[j] ^ *(ptr++));
-	}
-    }
-    for (i=0;i<9;i++)
-	if (test[i]) return (i+1);
-    return (-1);
-}
-
-static unsigned char *
-find_header(unsigned char *block)
-{
-    unsigned char *ptr, *head_ptr, *end;
-    unsigned char header[]={0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
- 
-    ptr = block;
-    end = block + EDID1_LEN;
-    while (ptr<end) {
-	int i;
-	head_ptr = ptr;
-	for (i=0;i<8;i++){
-	    if (header[i] != *(head_ptr++)) break;
-	    if (head_ptr == end) head_ptr = block;
-	}
-	if (i==8) break;
-	ptr++; 
-    }
-    if (ptr == end) return (NULL);
-    return (ptr);
-}
-
-static unsigned char *
-resort(unsigned char *s_block)
-{
-    unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
-    unsigned char tmp;
-
-    s_end = s_block + EDID1_LEN;
-    d_new = xalloc(EDID1_LEN);
-    if (!d_new) return NULL;
-    d_end = d_new + EDID1_LEN;
-
-    s_ptr = find_header(s_block);
-    if (!s_ptr) return NULL;
-    for (d_ptr=d_new;d_ptr<d_end;d_ptr++){
-	tmp = *(s_ptr++);
-	*d_ptr = tmp; 
-	if (s_ptr == s_end) s_ptr = s_block;
-    }
-    xfree(s_block);
-    return (d_new);
-}
-
-
diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index 90ac916..33b77fc 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -18,7 +18,6 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "xf86DDC.h"
-#include "ddcPriv.h"
 #include <string.h>
 
 #define RETRIES 4
@@ -36,6 +35,124 @@ static const OptionInfoRec DDCOptions[] = {
     { -1,		NULL,		OPTV_NONE,	{0},	FALSE },
 };
 
+/* DDC1 */
+
+static int
+find_start(unsigned int *ptr)
+{
+    unsigned int comp[9], test[9];
+    int i,j;
+  
+    for (i=0;i<9;i++){
+	comp[i] = *(ptr++);
+	test[i] = 1;
+    }
+    for (i=0;i<127;i++){
+	for (j=0;j<9;j++){
+	    test[j] = test[j] & !(comp[j] ^ *(ptr++));
+	}
+    }
+    for (i=0;i<9;i++)
+	if (test[i]) return (i+1);
+    return (-1);
+}
+
+static unsigned char *
+find_header(unsigned char *block)
+{
+    unsigned char *ptr, *head_ptr, *end;
+    unsigned char header[]={0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
+ 
+    ptr = block;
+    end = block + EDID1_LEN;
+    while (ptr<end) {
+	int i;
+	head_ptr = ptr;
+	for (i=0;i<8;i++){
+	    if (header[i] != *(head_ptr++)) break;
+	    if (head_ptr == end) head_ptr = block;
+	}
+	if (i==8) break;
+	ptr++; 
+    }
+    if (ptr == end) return (NULL);
+    return (ptr);
+}
+
+static unsigned char *
+resort(unsigned char *s_block)
+{
+    unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
+    unsigned char tmp;
+
+    s_end = s_block + EDID1_LEN;
+    d_new = xalloc(EDID1_LEN);
+    if (!d_new) return NULL;
+    d_end = d_new + EDID1_LEN;
+
+    s_ptr = find_header(s_block);
+    if (!s_ptr) return NULL;
+    for (d_ptr=d_new;d_ptr<d_end;d_ptr++){
+	tmp = *(s_ptr++);
+	*d_ptr = tmp; 
+	if (s_ptr == s_end) s_ptr = s_block;
+    }
+    xfree(s_block);
+    return (d_new);
+}
+
+static int
+DDC_checksum(unsigned char *block, int len)
+{
+    int i, result = 0;
+    int not_null = 0;
+    
+    for (i=0;i<len;i++) {
+	not_null |= block[i];
+	result += block[i];
+    }
+    
+#ifdef DEBUG
+    if (result & 0xFF) ErrorF("DDC checksum not correct\n");
+    if (!not_null) ErrorF("DDC read all Null\n");
+#endif
+
+    /* catch the trivial case where all bytes are 0 */
+    if (!not_null) return 1;
+
+    return (result&0xFF);
+}
+
+static unsigned char *
+GetEDID_DDC1(unsigned int *s_ptr)
+{
+    unsigned char *d_block, *d_pos;
+    unsigned int *s_pos, *s_end;
+    int s_start;
+    int i,j;
+    s_start = find_start(s_ptr);
+    if (s_start==-1) return NULL;
+    s_end = s_ptr + NUM;
+    s_pos = s_ptr + s_start;
+    d_block=xalloc(EDID1_LEN);
+    if (!d_block) return NULL;
+    d_pos = d_block;
+    for (i=0;i<EDID1_LEN;i++) {
+	for (j=0;j<8;j++) {
+	    *d_pos <<= 1;
+	    if (*s_pos) {
+		*d_pos |= 0x01;
+	    }
+	    s_pos++; if (s_pos == s_end) s_pos=s_ptr;
+	};
+	s_pos++; if (s_pos == s_end) s_pos=s_ptr;
+	d_pos++;
+    }
+    xfree(s_ptr);
+    if (d_block && DDC_checksum(d_block,EDID1_LEN)) return NULL;
+    return (resort(d_block));
+}
+
 /* fetch entire EDID record; DDC bit needs to be masked */
 static unsigned int * 
 FetchEDID_DDC1(register ScrnInfoPtr pScrn,
@@ -154,6 +271,8 @@ xf86DoEDID_DDC1(
 	return tmp;
 }
 
+/* DDC2 */
+
 static I2CDevPtr
 DDC2MakeDevice(I2CBusPtr pBus, int address, char *name)
 {
commit 3a350688bbe1257feaf1502b4009f5f701d2640e
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 8 14:37:38 2009 -0400

    ddc: Code motion to eliminate forward decls

diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index f72dd38..90ac916 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -23,22 +23,6 @@
 
 #define RETRIES 4
 
-static unsigned char *EDIDRead_DDC1(
-    ScrnInfoPtr pScrn,
-    DDC1SetSpeedProc,
-    unsigned int (*)(ScrnInfoPtr)
-);
-
-static Bool TestDDC1(
-    ScrnInfoPtr pScrn,
-    unsigned int (*)(ScrnInfoPtr)
-);
-
-static unsigned int *FetchEDID_DDC1(
-    ScrnInfoPtr,
-    register unsigned int (*)(ScrnInfoPtr)
-);
-
 typedef enum {
     DDCOPT_NODDC1,
     DDCOPT_NODDC2,
@@ -52,6 +36,73 @@ static const OptionInfoRec DDCOptions[] = {
     { -1,		NULL,		OPTV_NONE,	{0},	FALSE },
 };
 
+/* fetch entire EDID record; DDC bit needs to be masked */
+static unsigned int * 
+FetchEDID_DDC1(register ScrnInfoPtr pScrn,
+	       register unsigned int (*read_DDC)(ScrnInfoPtr))
+{
+    int count = NUM;
+    unsigned int *ptr, *xp;
+
+    ptr=xp=xalloc(sizeof(int)*NUM); 
+
+    if (!ptr)  return NULL;
+    do {
+	/* wait for next retrace */
+	*xp = read_DDC(pScrn);
+	xp++;
+    } while(--count);
+    return (ptr);
+}
+
+/* test if DDC1  return 0 if not */
+static Bool
+TestDDC1(ScrnInfoPtr pScrn, unsigned int (*read_DDC)(ScrnInfoPtr))
+{
+    int old, count;
+
+    old = read_DDC(pScrn);
+    count = HEADER * BITS_PER_BYTE;
+    do {
+	/* wait for next retrace */
+	if (old != read_DDC(pScrn)) break;
+    } while(count--);
+    return (count);
+}
+
+/* 
+ * read EDID record , pass it to callback function to interpret.
+ * callback function will store it for further use by calling
+ * function; it will also decide if we need to reread it 
+ */
+static unsigned char *
+EDIDRead_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDCSpeed, 
+              unsigned int (*read_DDC)(ScrnInfoPtr))
+{
+    unsigned char *EDID_block = NULL;
+    int count = RETRIES;
+
+    if (!read_DDC) { 
+	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, 
+		   "chipset doesn't support DDC1\n");
+	return NULL; 
+    };
+
+    if (TestDDC1(pScrn,read_DDC)==-1) { 
+	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "No DDC signal\n"); 
+	return NULL; 
+    };
+
+    if (DDCSpeed) DDCSpeed(pScrn,DDC_FAST);
+    do {
+	EDID_block = GetEDID_DDC1(FetchEDID_DDC1(pScrn,read_DDC)); 
+	count --;
+    } while (!EDID_block && count);
+    if (DDCSpeed) DDCSpeed(pScrn,DDC_SLOW);
+
+    return EDID_block;
+}
+
 /**
  * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC1 are
  * unset.  EDID information blocks are interpreted and the results returned in
@@ -277,70 +328,3 @@ xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus)
 {
     return xf86DoEEDID(scrnIndex, pBus, FALSE);
 }
-
-/* 
- * read EDID record , pass it to callback function to interpret.
- * callback function will store it for further use by calling
- * function; it will also decide if we need to reread it 
- */
-static unsigned char *
-EDIDRead_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDCSpeed, 
-              unsigned int (*read_DDC)(ScrnInfoPtr))
-{
-    unsigned char *EDID_block = NULL;
-    int count = RETRIES;
-
-    if (!read_DDC) { 
-	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, 
-		   "chipset doesn't support DDC1\n");
-	return NULL; 
-    };
-
-    if (TestDDC1(pScrn,read_DDC)==-1) { 
-	xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "No DDC signal\n"); 
-	return NULL; 
-    };
-
-    if (DDCSpeed) DDCSpeed(pScrn,DDC_FAST);
-    do {
-	EDID_block = GetEDID_DDC1(FetchEDID_DDC1(pScrn,read_DDC)); 
-	count --;
-    } while (!EDID_block && count);
-    if (DDCSpeed) DDCSpeed(pScrn,DDC_SLOW);
-
-    return EDID_block;
-}
-
-/* test if DDC1  return 0 if not */
-static Bool
-TestDDC1(ScrnInfoPtr pScrn, unsigned int (*read_DDC)(ScrnInfoPtr))
-{
-    int old, count;
-
-    old = read_DDC(pScrn);
-    count = HEADER * BITS_PER_BYTE;
-    do {
-	/* wait for next retrace */
-	if (old != read_DDC(pScrn)) break;
-    } while(count--);
-    return (count);
-}
-
-/* fetch entire EDID record; DDC bit needs to be masked */
-static unsigned int * 
-FetchEDID_DDC1(register ScrnInfoPtr pScrn,
-	       register unsigned int (*read_DDC)(ScrnInfoPtr))
-{
-    int count = NUM;
-    unsigned int *ptr, *xp;
-
-    ptr=xp=xalloc(sizeof(int)*NUM); 
-
-    if (!ptr)  return NULL;
-    do {
-	/* wait for next retrace */
-	*xp = read_DDC(pScrn);
-	xp++;
-    } while(--count);
-    return (ptr);
-}
commit 8797831f82637b0e65a08e1262d1ec57c075cc12
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 8 14:30:53 2009 -0400

    ddc: Update a comment.

diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index dba14d5..f72dd38 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -4,10 +4,10 @@
  */
 
 /*
- * Note that DDC1 does not define any method for returning blocks beyond
- * the first.  DDC2 does, but the original implementation would only ever
- * read the first block.  If you want to read and parse all blocks, use
- * xf86DoEEDID().
+ * A note on terminology.  DDC1 is the original dumb serial protocol, and
+ * can only do up to 128 bytes of EDID.  DDC2 is I2C-encapsulated and
+ * introduces extension blocks.  EDID is the old display identification
+ * block, DisplayID is the new one.
  */
 
 #ifdef HAVE_XORG_CONFIG_H


More information about the xorg-commit mailing list