summaryrefslogtreecommitdiff
path: root/src/trident_i2c.c
blob: 83581d08a150241a74e7623d3d1cf42ab4bbea27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/trident/trident_i2c.c,v 1.2 1999/01/23 09:55:59 dawes Exp $ */

#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "compiler.h"

#include "xf86Pci.h"
#include "xf86PciInfo.h"

#include "vgaHW.h"

#include "trident.h"
#include "trident_regs.h"

static void
TRIDENTI2CPutBits(I2CBusPtr b, int clock, int data) {
    unsigned int reg = 0x0C;
    TRIDENTPtr pTrident = ((TRIDENTPtr)b->DriverPrivate.ptr);
    int vgaIOBase = VGAHWPTR(pTrident->pScrn)->IOBase;
    
#if 0
    if(!TRIDENTI2CSwitchToBus(b))
        return FALSE;
#endif

    if(clock) reg |= 2;
    if(data)  reg |= 1;
    OUTB(vgaIOBase + 4, I2C);
    OUTB(vgaIOBase + 5, reg);
#if 0
    ErrorF("TRIDENTI2CPutBits: %d %d\n", clock, data);
#endif
}

static void
TRIDENTI2CGetBits(I2CBusPtr b, int *clock, int *data) {
    unsigned int reg;
    TRIDENTPtr pTrident = ((TRIDENTPtr)b->DriverPrivate.ptr);
    int vgaIOBase = VGAHWPTR(pTrident->pScrn)->IOBase;

#if 0
    if(!TRIDENTI2CSwitchToBus(b))
        return FALSE;
#endif

    OUTB(vgaIOBase + 4, I2C);
    reg = INB(vgaIOBase + 5);
    *clock = (reg & 0x02) != 0;
    *data  = (reg & 0x01) != 0;
#if 0
    ErrorF("TRIDENTI2CGetBits: %d %d\n", *clock, *data); 
#endif
}

Bool 
TRIDENTI2CInit(ScreenPtr pScreen)
{
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    TRIDENTPtr pTrident = TRIDENTPTR(pScrn);
    I2CBusPtr I2CPtr;

    I2CPtr = xf86CreateI2CBusRec();

    pTrident->DDC = I2CPtr;

    I2CPtr->BusName    = "DDC";
    I2CPtr->scrnIndex  = pScrn->scrnIndex;
    I2CPtr->I2CPutBits = TRIDENTI2CPutBits;
    I2CPtr->I2CGetBits = TRIDENTI2CGetBits;
    I2CPtr->DriverPrivate.ptr = pTrident;
    
    if(!xf86I2CBusInit(I2CPtr))
       return FALSE;

    return TRUE;
}