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
37#include "vgaHW.h"
38
39#include "xf86xv.h"
40#include "i740.h"
41
42
43static void i740_I2CPutBits(I2CBusPtr b, int clk,  int dat)
44{
45  I740Ptr pI740=I740PTR(xf86Screens[b->scrnIndex]);
46  unsigned char val;
47
48  val=pI740->readControl(pI740, XRX, 0x1C);
49
50  if(clk) val&=~0x40; else val|=0x40;  if(dat) val&=~0x08; else val|=0x08;
51
52  /*if     ( clk &&  dat) val&=0xBF; else if( clk && !dat) val&=0xF7; else if(!clk &&  dat) val|=0x40; else val|=0x08;*/
53
54  val|=0x90;
55
56  pI740->writeControl(pI740, XRX, 0x1C, val);
57
58  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),
59	 !!(pI740->readControl(pI740, XRX, 0x63) & 0x02), !!(pI740->readControl(pI740, XRX, 0x63) & 0x01) );
60}
61
62static void i740_I2CGetBits(I2CBusPtr b, int *clk, int *dat)
63{
64  I740Ptr pI740=I740PTR(xf86Screens[b->scrnIndex]);
65  unsigned char val;
66
67  {
68    val=pI740->readControl(pI740, XRX, 0x1C);
69    val|=0x90;
70    pI740->writeControl(pI740, XRX, 0x1C, val);
71  }
72
73  {
74    val=pI740->readControl(pI740, XRX, 0x63);
75    *clk=!!(val & 0x02);
76    *dat=!!(val & 0x01);
77  }
78
79  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));
80}
81
82Bool I740_I2CInit(ScrnInfoPtr pScrn)
83{
84  I740Ptr pI740=I740PTR(pScrn);
85  I2CBusPtr I2CPtr;
86
87  { unsigned char val; val=pI740->readControl(pI740, XRX, 0x63); val&=0xFC; pI740->writeControl(pI740, XRX, 0x63, val); }
88  { unsigned char val; val=pI740->readControl(pI740, XRX, 0x1C); val|=0x90; pI740->writeControl(pI740, XRX, 0x1C, val); }
89  { unsigned char val; val=pI740->readControl(pI740, XRX, 0x63); val&=0xFC; pI740->writeControl(pI740, XRX, 0x63, val); }
90
91
92  I2CPtr = xf86CreateI2CBusRec();
93  if(!I2CPtr) return FALSE;
94
95  pI740->rc_i2c = I2CPtr;
96
97  I2CPtr->BusName    = "I2C bus";
98  I2CPtr->scrnIndex  = pScrn->scrnIndex;
99  I2CPtr->I2CPutBits = i740_I2CPutBits;
100  I2CPtr->I2CGetBits = i740_I2CGetBits;
101
102  if (!xf86I2CBusInit(I2CPtr))
103    return FALSE;
104
105  return TRUE;
106}
107