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