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