ddcProperty.c revision 4642e01f
1/* 2 * Copyright 2006 Luc Verhaegen. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sub license, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the 12 * next paragraph) shall be included in all copies or substantial portions 13 * of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24#ifdef HAVE_XORG_CONFIG_H 25#include <xorg-config.h> 26#endif 27 28#include "xf86.h" 29#include "xf86DDC.h" 30#include <X11/Xatom.h> 31#include "property.h" 32#include "propertyst.h" 33#include "xf86DDC.h" 34 35#define EDID1_ATOM_NAME "XFree86_DDC_EDID1_RAWDATA" 36#define EDID2_ATOM_NAME "XFree86_DDC_EDID2_RAWDATA" 37 38static void 39addRootWindowProperties(ScrnInfoPtr pScrn, xf86MonPtr DDC) 40{ 41 Atom EDID1Atom=-1, EDID2Atom=-1; 42 CARD8 *EDID1rawdata = NULL; 43 CARD8 *EDID2rawdata = NULL; 44 int i, scrnIndex = pScrn->scrnIndex; 45 Bool makeEDID1prop = FALSE; 46 Bool makeEDID2prop = FALSE; 47 48 if (DDC->ver.version == 1) { 49 makeEDID1prop = TRUE; 50 } else if (DDC->ver.version == 2) { 51 int checksum1; 52 int checksum2; 53 makeEDID2prop = TRUE; 54 55 /* Some monitors (eg Panasonic PanaSync4) 56 * report version==2 because they used EDID v2 spec document, 57 * although they use EDID v1 data structure :-( 58 * 59 * Try using checksum to determine when we have such a monitor. 60 */ 61 checksum2 = 0; 62 for (i = 0; i < 256; i++) 63 checksum2 += DDC->rawData[i]; 64 if (checksum2 % 256) { 65 xf86DrvMsg(scrnIndex, X_INFO, "Monitor EDID v2 checksum failed\n"); 66 xf86DrvMsg(scrnIndex, X_INFO, 67 "XFree86_DDC_EDID2_RAWDATA property may be bad\n"); 68 checksum1 = 0; 69 for (i = 0; i < 128; i++) 70 checksum1 += DDC->rawData[i]; 71 if (!(checksum1 % 256)) { 72 xf86DrvMsg(scrnIndex, X_INFO, 73 "Monitor EDID v1 checksum passed,\n"); 74 xf86DrvMsg(scrnIndex, X_INFO, 75 "XFree86_DDC_EDID1_RAWDATA property created\n"); 76 makeEDID1prop = TRUE; 77 } 78 } 79 } else { 80 xf86DrvMsg(scrnIndex, X_PROBED, "unexpected EDID version %d.%d\n", 81 DDC->ver.version, DDC->ver.revision); 82 return; 83 } 84 85 if (makeEDID1prop) { 86 int size = 128; 87 88 if (DDC->flags & EDID_COMPLETE_RAWDATA) 89 size += DDC->no_sections * 128; 90 91 if ((EDID1rawdata = xalloc(size*sizeof(CARD8)))==NULL) 92 return; 93 94 EDID1Atom = MakeAtom(EDID1_ATOM_NAME, sizeof(EDID1_ATOM_NAME) - 1, TRUE); 95 memcpy(EDID1rawdata, DDC->rawData, size); 96 xf86RegisterRootWindowProperty(scrnIndex, EDID1Atom, XA_INTEGER, 8, 97 size, (unsigned char *)EDID1rawdata); 98 } 99 100 if (makeEDID2prop) { 101 if ((EDID2rawdata = xalloc(256*sizeof(CARD8)))==NULL) 102 return; 103 104 memcpy(EDID2rawdata, DDC->rawData, 256); 105 EDID2Atom = MakeAtom(EDID2_ATOM_NAME, sizeof(EDID2_ATOM_NAME) - 1, TRUE); 106 xf86RegisterRootWindowProperty(scrnIndex, EDID2Atom, XA_INTEGER, 8, 107 256, (unsigned char *)EDID2rawdata); 108 } 109} 110 111Bool 112xf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC) 113{ 114 if (!pScrn || !pScrn->monitor || !DDC) 115 return FALSE; 116 117 xf86DDCMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC); 118 119 addRootWindowProperties(pScrn, DDC); 120 121 return TRUE; 122} 123