summaryrefslogtreecommitdiff
path: root/src/neo_i2c.c
blob: 5bbb3fb6f0e9bc26a5225be5d6d1d248d6ef8ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**********************************************************************
Copyright 1998, 1999 by Precision Insight, Inc., Cedar Park, Texas.

                        All Rights Reserved

Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Precision Insight not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.  Precision Insight
and its suppliers make no representations about the suitability of this
software for any purpose.  It is provided "as is" without express or 
implied warranty.

PRECISION INSIGHT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**********************************************************************/

/*
 * The original Precision Insight driver for
 * XFree86 v.3.3 has been sponsored by Red Hat.
 *
 * Authors:
 *   Jens Owen (jens@tungstengraphics.com)
 *   Kevin E. Martin (kevin@precisioninsight.com)
 *
 * Port to Xfree86 v.4.0
 *   1998, 1999 by Egbert Eich (Egbert.Eich@Physik.TU-Darmstadt.DE)
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "xf86.h"
#include "xf86_OSproc.h"
#include "compiler.h"

#include "xf86Pci.h"

#include "vgaHW.h"

#include "neo.h"

static void
neo_I2CPutBits(I2CBusPtr b, int clock,  int data) {
    vgaHWPtr hwp = VGAHWPTR(xf86Screens[b->scrnIndex]);
    unsigned int reg = 0xF0;

    VGAwCR(0x21,0x00);
    VGAwCR(0x1D,0x01);
    
    if(clock) reg |= 1;
    if(data)  reg |= 0x4;
    VGAwGR(0xA1,reg);
    /*ErrorF("neo_I2CPutBits: %d %d\n", clock, data); */
}

static void
neo_I2CGetBits(I2CBusPtr b, int *clock, int *data) {
    unsigned int reg;
    vgaHWPtr hwp = VGAHWPTR(xf86Screens[b->scrnIndex]);
    
    reg = VGArGR(0xA1);
    *clock = 1 /* (reg & 0x?? ) */;
    *data  = (reg & 0x8) != 0;
    /*ErrorF("neo_I2CGetBits: %d %d\n", *clock, *data);*/
}

Bool 
neo_I2CInit(ScrnInfoPtr pScrn)
{
    NEOPtr pNeo = NEOPTR(pScrn);
    I2CBusPtr I2CPtr;

    I2CPtr = xf86CreateI2CBusRec();

    if(!I2CPtr) return FALSE;

    pNeo->I2C = I2CPtr;

    I2CPtr->BusName    = "I2C bus";
    I2CPtr->scrnIndex  = pScrn->scrnIndex;
    I2CPtr->I2CPutBits = neo_I2CPutBits;
    I2CPtr->I2CGetBits = neo_I2CGetBits;
    /* increase these as the defaults are too low */
    I2CPtr->RiseFallTime = 2;
    I2CPtr->HoldTime = 40;

    if (!xf86I2CBusInit(I2CPtr))
      return FALSE;

    return TRUE;
}