BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / add-ons / accelerants / s3 / virge_edid.cpp
blobabad312c43d07e774c872dae8aea8898d4018eaf
1 /*
2 Haiku S3 Virge driver adapted from the X.org Virge and Savage driver.
4 Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
6 Copyright 2007-2008 Haiku, Inc. All rights reserved.
7 Distributed under the terms of the MIT license.
9 Authors:
10 Gerald Zajac 2007-2008
13 #include "accel.h"
14 #include "virge.h"
16 #include <string.h>
17 #include <ddc.h>
18 #include <edid.h>
22 static status_t
23 GetI2CSignals_Alt(void* cookie, int* _clock, int* data)
25 uint32 index = (uint32)cookie;
26 uint8 value = ReadCrtcReg(index);
28 *_clock = (value & 0x4) != 0;
29 *data = (value & 0x8) != 0;
30 return B_OK;
34 static status_t
35 SetI2CSignals_Alt(void* cookie, int _clock, int data)
37 uint32 index = (uint32)cookie;
38 uint8 value = 0x10;
40 if (_clock)
41 value |= 0x1;
42 if (data)
43 value |= 0x2;
45 WriteCrtcReg(index, value);
46 return B_OK;
51 static status_t
52 GetI2CSignals(void* cookie, int* _clock, int* data)
54 (void)cookie; // avoid compiler warning for unused arg
56 uint8 reg = ReadReg8(DDC_REG);
58 *_clock = (reg & 0x4) != 0;
59 *data = (reg & 0x8) != 0;
60 return B_OK;
64 static status_t
65 SetI2CSignals(void* cookie, int _clock, int data)
67 (void)cookie; // avoid compiler warning for unused arg
69 uint8 reg = 0x10;
71 if (_clock)
72 reg |= 0x1;
73 if (data)
74 reg |= 0x2;
76 WriteReg8(DDC_REG, reg);
77 return B_OK;
82 bool
83 Virge_GetEdidInfo(edid1_info& edidInfo)
85 // Get the EDID info and return true if successful.
87 SharedInfo& si = *gInfo.sharedInfo;
89 bool bResult = false;
91 if (si.chipType == S3_TRIO_3D_2X) {
92 uint32 DDCPort = 0xAA;
94 i2c_bus bus;
95 bus.cookie = (void*)DDCPort;
96 bus.set_signals = &SetI2CSignals_Alt;
97 bus.get_signals = &GetI2CSignals_Alt;
98 ddc2_init_timing(&bus);
100 uint8 tmp = ReadCrtcReg(DDCPort);
101 WriteCrtcReg(DDCPort, tmp | 0x13);
103 bResult = (ddc2_read_edid1(&bus, &edidInfo, NULL, NULL) == B_OK);
105 WriteCrtcReg(DDCPort, tmp);
106 } else {
107 i2c_bus bus;
108 bus.cookie = (void*)DDC_REG;
109 bus.set_signals = &SetI2CSignals;
110 bus.get_signals = &GetI2CSignals;
111 ddc2_init_timing(&bus);
113 uint8 tmp = ReadReg8(DDC_REG);
114 WriteReg8(DDC_REG, tmp | 0x13);
116 bResult = (ddc2_read_edid1(&bus, &edidInfo, NULL, NULL) == B_OK);
118 WriteReg8(DDC_REG, tmp);
121 return bResult;