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