smi_i2c.c revision 09885543
1/* Header:   //Mercury/Projects/archives/XFree86/4.0/smi_i2c.c-arc   1.10   27 Nov 2000 15:47:58   Frido  $ */
2
3/*
4Copyright (C) 1994-2000 The XFree86 Project, Inc.  All Rights Reserved.
5Copyright (C) 2000 Silicon Motion, Inc.  All Rights Reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software and associated documentation files (the "Software"), to deal in
9the Software without restriction, including without limitation the rights to
10use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11of the Software, and to permit persons to whom the Software is furnished to do
12so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
19NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the names of the XFree86 Project and
25Silicon Motion shall not be used in advertising or otherwise to promote the
26sale, use or other dealings in this Software without prior written
27authorization from the XFree86 Project and Silicon Motion.
28*/
29/* $XFree86$ */
30
31#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include "xf86.h"
36#include "xf86_OSproc.h"
37#include "compiler.h"
38#include "xf86Pci.h"
39#include "xf86PciInfo.h"
40#include "vgaHW.h"
41
42#include "smi.h"
43
44#undef VERBLEV
45#undef ENTER_PROC
46#undef DEBUG_PROC
47#undef LEAVE_PROC
48#undef DEBUG
49#define VERBLEV 2
50#define ENTER_PROC(PROCNAME)
51#define DEBUG_PROC(PROCNAME)
52#define LEAVE_PROC(PROCNAME)
53#define DEBUG(arg)
54
55static void
56SMI_I2CPutBits(I2CBusPtr b, int clock,  int data)
57{
58    SMIPtr pSmi = SMIPTR(xf86Screens[b->scrnIndex]);
59    unsigned int reg = 0x30;
60
61    ENTER_PROC("SMI_I2CPutBits");
62
63    if (clock) reg |= 0x01;
64    if (data)  reg |= 0x02;
65
66    VGAOUT8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x72, reg);
67
68    LEAVE_PROC("SMI_I2CPutBits");
69}
70
71static void
72SMI_I2CGetBits(I2CBusPtr b, int *clock, int *data)
73{
74    SMIPtr pSmi = SMIPTR(xf86Screens[b->scrnIndex]);
75    unsigned int reg = VGAIN8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x72);
76
77    ENTER_PROC("SMI_I2CGetBits");
78
79    *clock = reg & 0x04;
80    *data  = reg & 0x08;
81
82    LEAVE_PROC("SMI_I2CGetBits");
83}
84
85Bool
86SMI_I2CInit(ScrnInfoPtr pScrn)
87{
88    SMIPtr pSmi = SMIPTR(pScrn);
89
90    ENTER_PROC("SMI_I2CInit");
91
92    if (pSmi->I2C == NULL) {
93	I2CBusPtr I2CPtr = xf86CreateI2CBusRec();
94	if (I2CPtr == NULL) {
95	    LEAVE_PROC("SMI_I2CInit");
96	    return FALSE;
97	}
98
99	I2CPtr->BusName    = "I2C bus";
100	I2CPtr->scrnIndex  = pScrn->scrnIndex;
101	I2CPtr->I2CPutBits = SMI_I2CPutBits;
102	I2CPtr->I2CGetBits = SMI_I2CGetBits;
103
104	if (!xf86I2CBusInit(I2CPtr)) {
105	    xf86DestroyI2CBusRec(I2CPtr, TRUE, TRUE);
106	    LEAVE_PROC("SMI_I2CInit");
107	    return FALSE;
108	}
109
110	pSmi->I2C = I2CPtr;
111    }
112
113    LEAVE_PROC("SMI_I2CInit");
114    return TRUE;
115}
116
117