1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2006 Luc Verhaegen.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sub license,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the
12*4882a593Smuzhiyun * next paragraph) shall be included in all copies or substantial portions
13*4882a593Smuzhiyun * of the Software.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18*4882a593Smuzhiyun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #ifdef HAVE_XORG_CONFIG_H
25*4882a593Smuzhiyun #include <xorg-config.h>
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #include "xf86.h"
29*4882a593Smuzhiyun #include "xf86DDC.h"
30*4882a593Smuzhiyun #include "xf86Priv.h"
31*4882a593Smuzhiyun #include <X11/Xatom.h>
32*4882a593Smuzhiyun #include "property.h"
33*4882a593Smuzhiyun #include "propertyst.h"
34*4882a593Smuzhiyun #include <string.h>
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #define EDID1_ATOM_NAME "XFree86_DDC_EDID1_RAWDATA"
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun static int
edidSize(const xf86MonPtr DDC)39*4882a593Smuzhiyun edidSize(const xf86MonPtr DDC)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun int ret = 128;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun if (DDC->flags & EDID_COMPLETE_RAWDATA)
44*4882a593Smuzhiyun ret += DDC->no_sections * 128;
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun return ret;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun static void
setRootWindowEDID(ScreenPtr pScreen,xf86MonPtr DDC)50*4882a593Smuzhiyun setRootWindowEDID(ScreenPtr pScreen, xf86MonPtr DDC)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun Atom atom = MakeAtom(EDID1_ATOM_NAME, strlen(EDID1_ATOM_NAME), TRUE);
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun dixChangeWindowProperty(serverClient, pScreen->root, atom, XA_INTEGER,
55*4882a593Smuzhiyun 8, PropModeReplace, edidSize(DDC), DDC->rawData,
56*4882a593Smuzhiyun FALSE);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static void
addEDIDProp(CallbackListPtr * pcbl,void * scrn,void * screen)60*4882a593Smuzhiyun addEDIDProp(CallbackListPtr *pcbl, void *scrn, void *screen)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun ScreenPtr pScreen = screen;
63*4882a593Smuzhiyun ScrnInfoPtr pScrn = scrn;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun if (xf86ScreenToScrn(pScreen) == pScrn)
66*4882a593Smuzhiyun setRootWindowEDID(pScreen, pScrn->monitor->DDC);
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun Bool
xf86SetDDCproperties(ScrnInfoPtr pScrn,xf86MonPtr DDC)70*4882a593Smuzhiyun xf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun if (!pScrn || !pScrn->monitor || !DDC)
73*4882a593Smuzhiyun return FALSE;
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun xf86EdidMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC);
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun if (xf86Initialising)
78*4882a593Smuzhiyun AddCallback(&RootWindowFinalizeCallback, addEDIDProp, pScrn);
79*4882a593Smuzhiyun else
80*4882a593Smuzhiyun setRootWindowEDID(pScrn->pScreen, DDC);
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun return TRUE;
83*4882a593Smuzhiyun }
84