195b296d0Smrg
295b296d0Smrg#ifdef HAVE_CONFIG_H
395b296d0Smrg#include "config.h"
495b296d0Smrg#endif
595b296d0Smrg
695b296d0Smrg#include "xf86.h"
795b296d0Smrg#include "xf86_OSproc.h"
895b296d0Smrg#include "compiler.h"
995b296d0Smrg
1095b296d0Smrg#include "xf86Pci.h"
1195b296d0Smrg
1295b296d0Smrg#include "vgaHW.h"
1395b296d0Smrg
1495b296d0Smrg#include "trident.h"
1595b296d0Smrg#include "trident_regs.h"
1695b296d0Smrg
1795b296d0Smrgstatic void
1895b296d0SmrgTRIDENTI2CPutBits(I2CBusPtr b, int clock, int data) {
1995b296d0Smrg    unsigned int reg = 0x0C;
2095b296d0Smrg    TRIDENTPtr pTrident = ((TRIDENTPtr)b->DriverPrivate.ptr);
2195b296d0Smrg    int vgaIOBase = VGAHWPTR(pTrident->pScrn)->IOBase;
2295b296d0Smrg
2395b296d0Smrg#if 0
2495b296d0Smrg    if(!TRIDENTI2CSwitchToBus(b))
2595b296d0Smrg        return FALSE;
2695b296d0Smrg#endif
2795b296d0Smrg
2895b296d0Smrg    if(clock) reg |= 2;
2995b296d0Smrg    if(data)  reg |= 1;
3095b296d0Smrg    OUTB(vgaIOBase + 4, I2C);
3195b296d0Smrg    OUTB(vgaIOBase + 5, reg);
3295b296d0Smrg#if 0
3395b296d0Smrg    ErrorF("TRIDENTI2CPutBits: %d %d\n", clock, data);
3495b296d0Smrg#endif
3595b296d0Smrg}
3695b296d0Smrg
3795b296d0Smrgstatic void
3895b296d0SmrgTRIDENTI2CGetBits(I2CBusPtr b, int *clock, int *data) {
3995b296d0Smrg    unsigned int reg;
4095b296d0Smrg    TRIDENTPtr pTrident = ((TRIDENTPtr)b->DriverPrivate.ptr);
4195b296d0Smrg    int vgaIOBase = VGAHWPTR(pTrident->pScrn)->IOBase;
4295b296d0Smrg
4395b296d0Smrg#if 0
4495b296d0Smrg    if(!TRIDENTI2CSwitchToBus(b))
4595b296d0Smrg        return FALSE;
4695b296d0Smrg#endif
4795b296d0Smrg
4895b296d0Smrg    OUTB(vgaIOBase + 4, I2C);
4995b296d0Smrg    reg = INB(vgaIOBase + 5);
5095b296d0Smrg    *clock = (reg & 0x02) != 0;
5195b296d0Smrg    *data  = (reg & 0x01) != 0;
5295b296d0Smrg#if 0
5395b296d0Smrg    ErrorF("TRIDENTI2CGetBits: %d %d\n", *clock, *data);
5495b296d0Smrg#endif
5595b296d0Smrg}
5695b296d0Smrg
5795b296d0SmrgBool
5895b296d0SmrgTRIDENTI2CInit(ScreenPtr pScreen)
5995b296d0Smrg{
60eca46af7Smrg    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
6195b296d0Smrg    TRIDENTPtr pTrident = TRIDENTPTR(pScrn);
6295b296d0Smrg    I2CBusPtr I2CPtr;
6395b296d0Smrg
6495b296d0Smrg    I2CPtr = xf86CreateI2CBusRec();
6595b296d0Smrg
6695b296d0Smrg    pTrident->DDC = I2CPtr;
6795b296d0Smrg
6895b296d0Smrg    I2CPtr->BusName    = "DDC";
6995b296d0Smrg    I2CPtr->scrnIndex  = pScrn->scrnIndex;
7095b296d0Smrg    I2CPtr->I2CPutBits = TRIDENTI2CPutBits;
7195b296d0Smrg    I2CPtr->I2CGetBits = TRIDENTI2CGetBits;
7295b296d0Smrg    I2CPtr->DriverPrivate.ptr = pTrident;
7395b296d0Smrg
7495b296d0Smrg    if(!xf86I2CBusInit(I2CPtr))
7595b296d0Smrg       return FALSE;
7695b296d0Smrg
7795b296d0Smrg    return TRUE;
7895b296d0Smrg}
79