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