105b261ecSmrg/*
205b261ecSmrg * Copyright 2006 Luc Verhaegen.
305b261ecSmrg *
405b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a
505b261ecSmrg * copy of this software and associated documentation files (the "Software"),
605b261ecSmrg * to deal in the Software without restriction, including without limitation
705b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sub license,
805b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the
905b261ecSmrg * Software is furnished to do so, subject to the following conditions:
1005b261ecSmrg *
1105b261ecSmrg * The above copyright notice and this permission notice (including the
1205b261ecSmrg * next paragraph) shall be included in all copies or substantial portions
1305b261ecSmrg * of the Software.
1405b261ecSmrg *
1505b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1605b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1705b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1805b261ecSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1905b261ecSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2005b261ecSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2105b261ecSmrg * DEALINGS IN THE SOFTWARE.
2205b261ecSmrg */
2305b261ecSmrg
2405b261ecSmrg#ifdef HAVE_XORG_CONFIG_H
2505b261ecSmrg#include <xorg-config.h>
2605b261ecSmrg#endif
2705b261ecSmrg
2805b261ecSmrg#include "xf86.h"
2905b261ecSmrg#include "xf86DDC.h"
301b5d61b8Smrg#include "xf86Priv.h"
3105b261ecSmrg#include <X11/Xatom.h>
3205b261ecSmrg#include "property.h"
3305b261ecSmrg#include "propertyst.h"
346747b715Smrg#include <string.h>
3505b261ecSmrg
3605b261ecSmrg#define EDID1_ATOM_NAME         "XFree86_DDC_EDID1_RAWDATA"
3705b261ecSmrg
381b5d61b8Smrgstatic int
391b5d61b8SmrgedidSize(const xf86MonPtr DDC)
406747b715Smrg{
411b5d61b8Smrg    int ret = 128;
426747b715Smrg
431b5d61b8Smrg    if (DDC->flags & EDID_COMPLETE_RAWDATA)
441b5d61b8Smrg       ret += DDC->no_sections * 128;
456747b715Smrg
461b5d61b8Smrg    return ret;
476747b715Smrg}
486747b715Smrg
4905b261ecSmrgstatic void
501b5d61b8SmrgsetRootWindowEDID(ScreenPtr pScreen, xf86MonPtr DDC)
5105b261ecSmrg{
521b5d61b8Smrg    Atom atom = MakeAtom(EDID1_ATOM_NAME, strlen(EDID1_ATOM_NAME), TRUE);
5305b261ecSmrg
541b5d61b8Smrg    dixChangeWindowProperty(serverClient, pScreen->root, atom, XA_INTEGER,
551b5d61b8Smrg                            8, PropModeReplace, edidSize(DDC), DDC->rawData,
561b5d61b8Smrg                            FALSE);
571b5d61b8Smrg}
5805b261ecSmrg
591b5d61b8Smrgstatic void
601b5d61b8SmrgaddEDIDProp(CallbackListPtr *pcbl, void *scrn, void *screen)
611b5d61b8Smrg{
621b5d61b8Smrg    ScreenPtr pScreen = screen;
631b5d61b8Smrg    ScrnInfoPtr pScrn = scrn;
641b5d61b8Smrg
651b5d61b8Smrg    if (xf86ScreenToScrn(pScreen) == pScrn)
661b5d61b8Smrg        setRootWindowEDID(pScreen, pScrn->monitor->DDC);
6705b261ecSmrg}
6805b261ecSmrg
6905b261ecSmrgBool
7005b261ecSmrgxf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
7105b261ecSmrg{
7205b261ecSmrg    if (!pScrn || !pScrn->monitor || !DDC)
7305b261ecSmrg        return FALSE;
7405b261ecSmrg
751b5d61b8Smrg    xf86EdidMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC);
7605b261ecSmrg
771b5d61b8Smrg    if (xf86Initialising)
781b5d61b8Smrg        AddCallback(&RootWindowFinalizeCallback, addEDIDProp, pScrn);
791b5d61b8Smrg    else
801b5d61b8Smrg        setRootWindowEDID(pScrn->pScreen, DDC);
8105b261ecSmrg
8205b261ecSmrg    return TRUE;
8305b261ecSmrg}
84