1/* (c) Itai Nahshon */ 2 3#ifdef HAVE_CONFIG_H 4#include "config.h" 5#endif 6 7#include "xf86.h" 8#include "xf86_OSproc.h" 9#include "compiler.h" 10 11#include "xf86Pci.h" 12 13#include "vgaHW.h" 14 15#include "cir.h" 16#define _LG_PRIVATE_ 17#include "lg.h" 18 19 20static char strI2CBus1[] = "I2C bus 1"; 21static char strI2CBus2[] = "I2C bus 2"; 22 23 24static void 25LgI2CPutBits(I2CBusPtr b, int clock, int data) 26{ 27 unsigned int regval, regno; 28 CirPtr pCir = ((CirPtr) b->DriverPrivate.ptr); 29 if (b == pCir->I2CPtr1) 30 regno = 0x280; 31 else if (b == pCir->I2CPtr2) 32 regno = 0x282; 33 else 34 return; 35 36 regval = 0xff7e; 37 if (clock) 38 regval |= 0x0080; 39 if (data) 40 regval |= 0x0001; 41 memww(regno, regval); 42 /* 43 ErrorF("LgI2CPutBits: %d %d\n", clock, data); 44 */ 45} 46 47static void 48LgI2CGetBits(I2CBusPtr b, int *clock, int *data) 49{ 50 unsigned int regval, regno; 51 CirPtr pCir = ((CirPtr) b->DriverPrivate.ptr); 52 if (b == pCir->I2CPtr1) 53 regno = 0x280; 54 else if (b == pCir->I2CPtr2) 55 regno = 0x282; 56 else 57 return; 58 59 regval = memrw(regno); 60 *clock = (regval & 0x8000) != 0; 61 *data = (regval & 0x0100) != 0; 62 /* 63 ErrorF("LgI2CGetBits: %d %d\n", *clock, *data); 64 */ 65} 66 67Bool 68LgI2CInit(ScrnInfoPtr pScrn) 69{ 70 CirPtr pCir = CIRPTR(pScrn); 71 I2CBusPtr I2CPtr; 72 73#ifdef LG_DEBUG 74 ErrorF("LgI2CInit\n"); 75#endif 76 77 I2CPtr = xf86CreateI2CBusRec(); 78 if (!I2CPtr) 79 return FALSE; 80 81 pCir->I2CPtr1 = I2CPtr; 82 83 I2CPtr->BusName = strI2CBus1; 84 I2CPtr->scrnIndex = pScrn->scrnIndex; 85 I2CPtr->I2CPutBits = LgI2CPutBits; 86 I2CPtr->I2CGetBits = LgI2CGetBits; 87 I2CPtr->DriverPrivate.ptr = pCir; 88 89 if (!xf86I2CBusInit(I2CPtr)) 90 return FALSE; 91 92 I2CPtr = xf86CreateI2CBusRec(); 93 if (!I2CPtr) 94 return FALSE; 95 96 pCir->I2CPtr2 = I2CPtr; 97 98 I2CPtr->BusName = strI2CBus2; 99 I2CPtr->scrnIndex = pScrn->scrnIndex; 100 I2CPtr->I2CPutBits = LgI2CPutBits; 101 I2CPtr->I2CGetBits = LgI2CGetBits; 102 I2CPtr->DriverPrivate.ptr = pCir; 103 104 if (!xf86I2CBusInit(I2CPtr)) 105 return FALSE; 106 107 return TRUE; 108} 109 110