109885543Smrg/* Header: //Mercury/Projects/archives/XFree86/4.0/smi_i2c.c-arc 1.10 27 Nov 2000 15:47:58 Frido $ */ 209885543Smrg 309885543Smrg/* 409885543SmrgCopyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 509885543SmrgCopyright (C) 2000 Silicon Motion, Inc. All Rights Reserved. 609885543Smrg 709885543SmrgPermission is hereby granted, free of charge, to any person obtaining a copy of 809885543Smrgthis software and associated documentation files (the "Software"), to deal in 909885543Smrgthe Software without restriction, including without limitation the rights to 1009885543Smrguse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 1109885543Smrgof the Software, and to permit persons to whom the Software is furnished to do 1209885543Smrgso, subject to the following conditions: 1309885543Smrg 1409885543SmrgThe above copyright notice and this permission notice shall be included in all 1509885543Smrgcopies or substantial portions of the Software. 1609885543Smrg 1709885543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1809885543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 1909885543SmrgNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2009885543SmrgXFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2109885543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2209885543SmrgWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2309885543Smrg 2409885543SmrgExcept as contained in this notice, the names of the XFree86 Project and 2509885543SmrgSilicon Motion shall not be used in advertising or otherwise to promote the 2609885543Smrgsale, use or other dealings in this Software without prior written 2709885543Smrgauthorization from the XFree86 Project and Silicon Motion. 2809885543Smrg*/ 2909885543Smrg 3009885543Smrg#ifdef HAVE_CONFIG_H 3109885543Smrg#include "config.h" 3209885543Smrg#endif 3309885543Smrg 3409885543Smrg#include "xf86.h" 3509885543Smrg#include "xf86_OSproc.h" 3609885543Smrg#include "compiler.h" 3709885543Smrg#include "xf86Pci.h" 3809885543Smrg#include "vgaHW.h" 3909885543Smrg 4009885543Smrg#include "smi.h" 4109885543Smrg 4209885543Smrgstatic void 4309885543SmrgSMI_I2CPutBits(I2CBusPtr b, int clock, int data) 4409885543Smrg{ 4509885543Smrg SMIPtr pSmi = SMIPTR(xf86Screens[b->scrnIndex]); 4609885543Smrg unsigned int reg = 0x30; 4709885543Smrg 4809885543Smrg if (clock) reg |= 0x01; 4909885543Smrg if (data) reg |= 0x02; 5009885543Smrg 5109885543Smrg VGAOUT8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x72, reg); 5209885543Smrg} 5309885543Smrg 5409885543Smrgstatic void 5509885543SmrgSMI_I2CGetBits(I2CBusPtr b, int *clock, int *data) 5609885543Smrg{ 5709885543Smrg SMIPtr pSmi = SMIPTR(xf86Screens[b->scrnIndex]); 5809885543Smrg unsigned int reg = VGAIN8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x72); 5909885543Smrg 6009885543Smrg *clock = reg & 0x04; 6109885543Smrg *data = reg & 0x08; 6209885543Smrg} 6309885543Smrg 6409885543SmrgBool 6509885543SmrgSMI_I2CInit(ScrnInfoPtr pScrn) 6609885543Smrg{ 6709885543Smrg SMIPtr pSmi = SMIPTR(pScrn); 6809885543Smrg 6909885543Smrg if (pSmi->I2C == NULL) { 7009885543Smrg I2CBusPtr I2CPtr = xf86CreateI2CBusRec(); 717104f784Smrg if (I2CPtr == NULL) 7209885543Smrg return FALSE; 7309885543Smrg 7409885543Smrg I2CPtr->BusName = "I2C bus"; 7509885543Smrg I2CPtr->scrnIndex = pScrn->scrnIndex; 7609885543Smrg I2CPtr->I2CPutBits = SMI_I2CPutBits; 7709885543Smrg I2CPtr->I2CGetBits = SMI_I2CGetBits; 7809885543Smrg 7909885543Smrg if (!xf86I2CBusInit(I2CPtr)) { 8009885543Smrg xf86DestroyI2CBusRec(I2CPtr, TRUE, TRUE); 8109885543Smrg return FALSE; 8209885543Smrg } 8309885543Smrg 8409885543Smrg pSmi->I2C = I2CPtr; 8509885543Smrg } 8609885543Smrg 8709885543Smrg return TRUE; 8809885543Smrg} 8909885543Smrg 90