s3v_i2c.c revision 1d54945d
1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/s3virge/s3v_i2c.c,v 1.4 2000/03/31 20:13:32 dawes Exp $ */ 2 3/* 4Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 5 6Permission is hereby granted, free of charge, to any person obtaining a copy of 7this software and associated documentation files (the "Software"), to deal in 8the Software without restriction, including without limitation the rights to 9use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10of the Software, and to permit persons to whom the Software is furnished to do 11so, subject to the following conditions: 12 13The above copyright notice and this permission notice shall be included in all 14copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 18NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of the XFree86 Project shall not 24be used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from the XFree86 Project. 26*/ 27 28/* 29Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 30 31Permission is hereby granted, free of charge, to any person obtaining a copy of 32this software and associated documentation files (the "Software"), to deal in 33the Software without restriction, including without limitation the rights to 34use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 35of the Software, and to permit persons to whom the Software is furnished to do 36so, subject to the following conditions: 37 38The above copyright notice and this permission notice shall be included in all 39copies or substantial portions of the Software. 40 41THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 43NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 45AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 46WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 47 48Except as contained in this notice, the name of the XFree86 Project shall not 49be used in advertising or otherwise to promote the sale, use or other dealings 50in this Software without prior written authorization from the XFree86 Project. 51*/ 52 53#ifdef HAVE_CONFIG_H 54#include "config.h" 55#endif 56 57#include "xf86.h" 58#include "xf86_OSproc.h" 59#include "compiler.h" 60 61#include "xf86Pci.h" 62#include "xf86PciInfo.h" 63 64#include "vgaHW.h" 65 66#include "s3v.h" 67 68static void 69s3v_I2CPutBits(I2CBusPtr b, int clock, int data) 70{ 71 S3VPtr ps3v = S3VPTR(xf86Screens[b->scrnIndex]); 72 unsigned int reg = 0x10; 73 74 if(clock) reg |= 0x1; 75 if(data) reg |= 0x2; 76 77 OUTREG(DDC_REG,reg); 78 /*ErrorF("s3v_I2CPutBits: %d %d\n", clock, data); */ 79} 80 81static void 82s3v_I2CGetBits(I2CBusPtr b, int *clock, int *data) 83{ 84 S3VPtr ps3v = S3VPTR(xf86Screens[b->scrnIndex]); 85 unsigned int reg; 86 87 reg = (INREG(DDC_REG)); 88 89 *clock = reg & 0x4; 90 *data = reg & 0x8; 91 92 /*ErrorF("s3v_I2CGetBits: %d %d\n", *clock, *data);*/ 93} 94 95Bool 96S3V_I2CInit(ScrnInfoPtr pScrn) 97{ 98 S3VPtr ps3v = S3VPTR(pScrn); 99 I2CBusPtr I2CPtr; 100 101 102 I2CPtr = xf86CreateI2CBusRec(); 103 if(!I2CPtr) return FALSE; 104 105 ps3v->I2C = I2CPtr; 106 107 I2CPtr->BusName = "I2C bus"; 108 I2CPtr->scrnIndex = pScrn->scrnIndex; 109 I2CPtr->I2CPutBits = s3v_I2CPutBits; 110 I2CPtr->I2CGetBits = s3v_I2CGetBits; 111 112 if (!xf86I2CBusInit(I2CPtr)) 113 return FALSE; 114 115 return TRUE; 116} 117 118 119 120