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
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include "xf86.h"
35#include "xf86_OSproc.h"
36#include "compiler.h"
37#include "xf86Pci.h"
38#include "vgaHW.h"
39
40#include "smi.h"
41
42static void
43SMI_I2CPutBits(I2CBusPtr b, int clock,  int data)
44{
45    SMIPtr pSmi = SMIPTR(xf86Screens[b->scrnIndex]);
46    unsigned int reg = 0x30;
47
48    if (clock) reg |= 0x01;
49    if (data)  reg |= 0x02;
50
51    VGAOUT8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x72, reg);
52}
53
54static void
55SMI_I2CGetBits(I2CBusPtr b, int *clock, int *data)
56{
57    SMIPtr pSmi = SMIPTR(xf86Screens[b->scrnIndex]);
58    unsigned int reg = VGAIN8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x72);
59
60    *clock = reg & 0x04;
61    *data  = reg & 0x08;
62}
63
64Bool
65SMI_I2CInit(ScrnInfoPtr pScrn)
66{
67    SMIPtr pSmi = SMIPTR(pScrn);
68
69    if (pSmi->I2C == NULL) {
70	I2CBusPtr I2CPtr = xf86CreateI2CBusRec();
71	if (I2CPtr == NULL)
72	    return FALSE;
73
74	I2CPtr->BusName    = "I2C bus";
75	I2CPtr->scrnIndex  = pScrn->scrnIndex;
76	I2CPtr->I2CPutBits = SMI_I2CPutBits;
77	I2CPtr->I2CGetBits = SMI_I2CGetBits;
78
79	if (!xf86I2CBusInit(I2CPtr)) {
80	    xf86DestroyI2CBusRec(I2CPtr, TRUE, TRUE);
81	    return FALSE;
82	}
83
84	pSmi->I2C = I2CPtr;
85    }
86
87    return TRUE;
88}
89
90