xref: /haiku/src/add-ons/accelerants/s3/savage_edid.cpp (revision 3f388e607f400ccd68246c9680ebe79332d3366d)
135db13eaSAxel Dörfler /*
235db13eaSAxel Dörfler 	Haiku S3 Savage driver adapted from the X.org Savage driver.
335db13eaSAxel Dörfler 
435db13eaSAxel Dörfler 	Copyright (C) 1994-2000 The XFree86 Project, Inc.	All Rights Reserved.
535db13eaSAxel Dörfler 	Copyright (c) 2003-2006, X.Org Foundation
635db13eaSAxel Dörfler 
735db13eaSAxel Dörfler 	Copyright 2007-2008 Haiku, Inc.  All rights reserved.
835db13eaSAxel Dörfler 	Distributed under the terms of the MIT license.
935db13eaSAxel Dörfler 
1035db13eaSAxel Dörfler 	Authors:
1135db13eaSAxel Dörfler 	Gerald Zajac 2007-2008
1235db13eaSAxel Dörfler */
1335db13eaSAxel Dörfler 
1435db13eaSAxel Dörfler #include "accel.h"
1535db13eaSAxel Dörfler #include "savage.h"
1635db13eaSAxel Dörfler 
1735db13eaSAxel Dörfler #include <string.h>
1835db13eaSAxel Dörfler #include <ddc.h>
1935db13eaSAxel Dörfler #include <edid.h>
2035db13eaSAxel Dörfler 
2135db13eaSAxel Dörfler 
2235db13eaSAxel Dörfler 
2335db13eaSAxel Dörfler static status_t
GetI2CSignals(void * cookie,int * _clock,int * data)2435db13eaSAxel Dörfler GetI2CSignals(void* cookie, int* _clock, int* data)
2535db13eaSAxel Dörfler {
26*3f388e60SJaroslaw Pelczar 	uint32 index = (uint32)(addr_t)cookie;
2735db13eaSAxel Dörfler 	uint8 value = ReadCrtcReg(index);
2835db13eaSAxel Dörfler 
2935db13eaSAxel Dörfler 	*_clock = (value & 0x4) != 0;
3035db13eaSAxel Dörfler 	*data = (value & 0x8) != 0;
3135db13eaSAxel Dörfler 	return B_OK;
3235db13eaSAxel Dörfler }
3335db13eaSAxel Dörfler 
3435db13eaSAxel Dörfler 
3535db13eaSAxel Dörfler static status_t
SetI2CSignals(void * cookie,int _clock,int data)3635db13eaSAxel Dörfler SetI2CSignals(void* cookie, int _clock, int data)
3735db13eaSAxel Dörfler {
38*3f388e60SJaroslaw Pelczar 	uint32 index = (uint32)(addr_t)cookie;
3935db13eaSAxel Dörfler 	uint8 value = 0x10;
4035db13eaSAxel Dörfler 
4135db13eaSAxel Dörfler 	if (_clock)
4235db13eaSAxel Dörfler 		value |= 0x1;
4335db13eaSAxel Dörfler 	if (data)
4435db13eaSAxel Dörfler 		value |= 0x2;
4535db13eaSAxel Dörfler 
4635db13eaSAxel Dörfler 	WriteCrtcReg(index, value);
4735db13eaSAxel Dörfler 	return B_OK;
4835db13eaSAxel Dörfler }
4935db13eaSAxel Dörfler 
5035db13eaSAxel Dörfler 
5135db13eaSAxel Dörfler 
5235db13eaSAxel Dörfler bool
Savage_GetEdidInfo(edid1_info & edidInfo)53c1379d35SAxel Dörfler Savage_GetEdidInfo(edid1_info& edidInfo)
5435db13eaSAxel Dörfler {
5535db13eaSAxel Dörfler 	// Get the EDID info and return true if successful.
5635db13eaSAxel Dörfler 
5735db13eaSAxel Dörfler 	SharedInfo& si = *gInfo.sharedInfo;
5835db13eaSAxel Dörfler 
5935db13eaSAxel Dörfler 	uint32 DDCPort = 0;
6035db13eaSAxel Dörfler 
6135db13eaSAxel Dörfler     switch (si.chipType) {
6235db13eaSAxel Dörfler 	case S3_SAVAGE_3D:
6335db13eaSAxel Dörfler 	case S3_SAVAGE_MX:
6435db13eaSAxel Dörfler 	case S3_SUPERSAVAGE:
6535db13eaSAxel Dörfler 	case S3_SAVAGE2000:
6635db13eaSAxel Dörfler 		DDCPort = 0xAA;
6735db13eaSAxel Dörfler 		break;
6835db13eaSAxel Dörfler 
6935db13eaSAxel Dörfler 	case S3_SAVAGE4:
7035db13eaSAxel Dörfler 	case S3_PROSAVAGE:
7135db13eaSAxel Dörfler 	case S3_TWISTER:
7235db13eaSAxel Dörfler 	case S3_PROSAVAGE_DDR:
7335db13eaSAxel Dörfler 		DDCPort = 0xB1;
7435db13eaSAxel Dörfler 		break;
7535db13eaSAxel Dörfler     }
7635db13eaSAxel Dörfler 
7735db13eaSAxel Dörfler 	i2c_bus bus;
78*3f388e60SJaroslaw Pelczar 	bus.cookie = (void*)(addr_t)DDCPort;
7935db13eaSAxel Dörfler 	bus.set_signals = &SetI2CSignals;
8035db13eaSAxel Dörfler 	bus.get_signals = &GetI2CSignals;
8135db13eaSAxel Dörfler 	ddc2_init_timing(&bus);
8235db13eaSAxel Dörfler 
8335db13eaSAxel Dörfler 	uint8 tmp = ReadCrtcReg(DDCPort);
8435db13eaSAxel Dörfler 	WriteCrtcReg(DDCPort, tmp | 0x13);
8535db13eaSAxel Dörfler 
86c1379d35SAxel Dörfler 	bool bResult = (ddc2_read_edid1(&bus, &edidInfo, NULL, NULL) == B_OK);
8735db13eaSAxel Dörfler 	WriteCrtcReg(DDCPort, tmp);
8835db13eaSAxel Dörfler 
89c1379d35SAxel Dörfler 	return bResult;
9035db13eaSAxel Dörfler }
91