s3v_i2c.c revision ba85709e
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#include "xf86PciInfo.h"
62
63#include "vgaHW.h"
64
65#include "s3v.h"
66
67static void
68s3v_I2CPutBits(I2CBusPtr b, int clock,  int data)
69{
70    S3VPtr ps3v = S3VPTR(xf86Screens[b->scrnIndex]);
71    unsigned int reg = 0x10;
72
73    if(clock) reg |= 0x1;
74    if(data)  reg |= 0x2;
75
76    OUTREG(DDC_REG,reg);
77    /*ErrorF("s3v_I2CPutBits: %d %d\n", clock, data); */
78}
79
80static void
81s3v_I2CGetBits(I2CBusPtr b, int *clock, int *data)
82{
83    S3VPtr ps3v = S3VPTR(xf86Screens[b->scrnIndex]);
84    unsigned int reg;
85
86    reg = (INREG(DDC_REG));
87
88    *clock = reg & 0x4;
89    *data = reg & 0x8;
90
91    /*ErrorF("s3v_I2CGetBits: %d %d\n", *clock, *data);*/
92}
93
94Bool
95S3V_I2CInit(ScrnInfoPtr pScrn)
96{
97    S3VPtr ps3v = S3VPTR(pScrn);
98    I2CBusPtr I2CPtr;
99
100
101    I2CPtr = xf86CreateI2CBusRec();
102    if(!I2CPtr) return FALSE;
103
104    ps3v->I2C = I2CPtr;
105
106    I2CPtr->BusName    = "I2C bus";
107    I2CPtr->scrnIndex  = pScrn->scrnIndex;
108    I2CPtr->I2CPutBits = s3v_I2CPutBits;
109    I2CPtr->I2CGetBits = s3v_I2CGetBits;
110
111    if (!xf86I2CBusInit(I2CPtr))
112      return FALSE;
113
114    return TRUE;
115}
116
117
118
119