i740_i2c.c revision 0cc67336
1/*
2 * Copyright 2001 by Patrick LERDA
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Patrick LERDA not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  Patrick LERDA makes no representations
11 * about the suitability of this software for any purpose.  It is provided
12 * "as is" without express or implied warranty.
13 *
14 * PATRICK LERDA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL PATRICK LERDA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Authors:  Patrick LERDA
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29/* not working at this time */
30
31#include "xf86.h"
32#include "xf86_OSproc.h"
33#include "compiler.h"
34
35#include "xf86Pci.h"
36#include "xf86PciInfo.h"
37
38#include "vgaHW.h"
39
40#include "xf86xv.h"
41#include "i740.h"
42
43
44static void i740_I2CPutBits(I2CBusPtr b, int clk,  int dat)
45{
46  I740Ptr pI740=I740PTR(xf86Screens[b->scrnIndex]);
47  unsigned char val;
48
49  val=pI740->readControl(pI740, XRX, 0x1C);
50
51  if(clk) val&=~0x40; else val|=0x40;  if(dat) val&=~0x08; else val|=0x08;
52
53  /*if     ( clk &&  dat) val&=0xBF; else if( clk && !dat) val&=0xF7; else if(!clk &&  dat) val|=0x40; else val|=0x08;*/
54
55  val|=0x90;
56
57  pI740->writeControl(pI740, XRX, 0x1C, val);
58
59  ErrorF("i740_I2CPutBits: clk=%d dat=%d [<1c>=0x%02x] [<63>=0x%02x] clk=%d dat=%d\n", clk, dat,val,pI740->readControl(pI740, XRX, 0x63),
60	 !!(pI740->readControl(pI740, XRX, 0x63) & 0x02), !!(pI740->readControl(pI740, XRX, 0x63) & 0x01) );
61}
62
63static void i740_I2CGetBits(I2CBusPtr b, int *clk, int *dat)
64{
65  I740Ptr pI740=I740PTR(xf86Screens[b->scrnIndex]);
66  unsigned char val;
67
68  {
69    val=pI740->readControl(pI740, XRX, 0x1C);
70    val|=0x90;
71    pI740->writeControl(pI740, XRX, 0x1C, val);
72  }
73
74  {
75    val=pI740->readControl(pI740, XRX, 0x63);
76    *clk=!!(val & 0x02);
77    *dat=!!(val & 0x01);
78  }
79
80  ErrorF("i740_I2CGetBits: clk=%d dat=%d [<1c>=0x%02x] [<63>=0x%02x]\n", *clk, *dat,pI740->readControl(pI740, XRX, 0x1c) & 0xff,pI740->readControl(pI740, XRX, 0x63));
81}
82
83Bool I740_I2CInit(ScrnInfoPtr pScrn)
84{
85  I740Ptr pI740=I740PTR(pScrn);
86  I2CBusPtr I2CPtr;
87
88  { unsigned char val; val=pI740->readControl(pI740, XRX, 0x63); val&=0xFC; pI740->writeControl(pI740, XRX, 0x63, val); }
89  { unsigned char val; val=pI740->readControl(pI740, XRX, 0x1C); val|=0x90; pI740->writeControl(pI740, XRX, 0x1C, val); }
90  { unsigned char val; val=pI740->readControl(pI740, XRX, 0x63); val&=0xFC; pI740->writeControl(pI740, XRX, 0x63, val); }
91
92
93  I2CPtr = xf86CreateI2CBusRec();
94  if(!I2CPtr) return FALSE;
95
96  pI740->rc_i2c = I2CPtr;
97
98  I2CPtr->BusName    = "I2C bus";
99  I2CPtr->scrnIndex  = pScrn->scrnIndex;
100  I2CPtr->I2CPutBits = i740_I2CPutBits;
101  I2CPtr->I2CGetBits = i740_I2CGetBits;
102
103  if (!xf86I2CBusInit(I2CPtr))
104    return FALSE;
105
106  return TRUE;
107}
108