xref: /haiku/src/add-ons/accelerants/3dfx/3dfx_edid.cpp (revision a56bc48835ebabc25dfd5ec8a6a52e3cd5906bb1)
1 /*
2  * Copyright 2010 Haiku, Inc.  All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Gerald Zajac
7  */
8 
9 #include "accelerant.h"
10 #include "3dfx.h"
11 
12 #include <string.h>
13 #include <ddc.h>
14 #include <edid.h>
15 
16 
17 
18 static status_t
GetI2CSignals(void * cookie,int * _clock,int * data)19 GetI2CSignals(void* cookie, int* _clock, int* data)
20 {
21 	(void)cookie;		// avoid compiler warning for unused arg
22 
23 	uint32 reg = INREG32(VIDEO_SERIAL_PARALLEL_PORT);
24 	*_clock = (reg & VSP_SCL0_IN) ? 1 : 0;;
25 	*data = (reg & VSP_SDA0_IN) ? 1 : 0;
26 	return B_OK;
27 }
28 
29 
30 static status_t
SetI2CSignals(void * cookie,int _clock,int data)31 SetI2CSignals(void* cookie, int _clock, int data)
32 {
33 	(void)cookie;		// avoid compiler warning for unused arg
34 
35 	uint32 reg = (INREG32(VIDEO_SERIAL_PARALLEL_PORT)
36 		& ~(VSP_SDA0_OUT | VSP_SCL0_OUT));
37 	reg = (reg | (_clock ? VSP_SCL0_OUT : 0) | (data ? VSP_SDA0_OUT : 0));
38 	OUTREG32(VIDEO_SERIAL_PARALLEL_PORT, reg);
39 	return B_OK;
40 }
41 
42 
43 
44 bool
TDFX_GetEdidInfo(edid1_info & edidInfo)45 TDFX_GetEdidInfo(edid1_info& edidInfo)
46 {
47 	// Get the EDID info and return true if successful.
48 
49 	i2c_bus bus;
50 
51 	bus.cookie = (void*)NULL;
52 	bus.set_signals = &SetI2CSignals;
53 	bus.get_signals = &GetI2CSignals;
54 	ddc2_init_timing(&bus);
55 
56 	uint32 reg = INREG32(VIDEO_SERIAL_PARALLEL_PORT);
57 	OUTREG32(VIDEO_SERIAL_PARALLEL_PORT, reg | VSP_ENABLE_IIC0);
58 
59 	bool bResult = (ddc2_read_edid1(&bus, &edidInfo, NULL, NULL) == B_OK);
60 
61 	OUTREG32(VIDEO_SERIAL_PARALLEL_PORT, reg);
62 
63 	return bResult;
64 }
65