summaryrefslogtreecommitdiff
path: root/src/sil164/sil164.c
blob: 66dc7ac32e3974494a2844abaea26c85807c7909 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**************************************************************************

Copyright © 2006 Dave Airlie

All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

**************************************************************************/
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86Resources.h"
#include "compiler.h"
#include "miscstruct.h"
#include "xf86i2c.h"

#include "sil164.h"

static Bool sil164ReadByte(SIL164Ptr sil, int addr, unsigned char *ch)
{
  if (!xf86I2CReadByte(&(sil->d), addr, ch)) {
    xf86DrvMsg(sil->d.pI2CBus->scrnIndex, X_ERROR, "Unable to read from %s Slave %d.\n", sil->d.pI2CBus->BusName, sil->d.SlaveAddr);
    return FALSE;
  }
  return TRUE;
}

static Bool sil164WriteByte(SIL164Ptr sil, int addr, unsigned char ch)
{
  if (!xf86I2CWriteByte(&(sil->d), addr, ch)) {
    xf86DrvMsg(sil->d.pI2CBus->scrnIndex, X_ERROR, "Unable to write to %s Slave %d.\n", sil->d.pI2CBus->BusName, sil->d.SlaveAddr);
    return FALSE;
  }
  return TRUE;
}

/* Silicon Image 164 driver for chip on i2c bus */
static void *sil164Detect(I2CBusPtr b, I2CSlaveAddr addr)
{
  /* this will detect the SIL164 chip on the specified i2c bus */
  SIL164Ptr sil;
  unsigned char ch;

  xf86DrvMsg(b->scrnIndex, X_ERROR, "detecting sil164\n");
  
  sil = xcalloc(1, sizeof(SIL164Rec));
  if (sil == NULL)
    return NULL;

  sil->d.DevName = "SIL164 TMDS Controller";
  sil->d.SlaveAddr = addr;
  sil->d.pI2CBus = b;
  sil->d.StartTimeout = b->StartTimeout;
  sil->d.BitTimeout = b->BitTimeout;
  sil->d.AcknTimeout = b->AcknTimeout;
  sil->d.ByteTimeout = b->ByteTimeout;
  sil->d.DriverPrivate.ptr = sil;

  if (!sil164ReadByte(sil, SIL164_VID_LO, &ch))
    goto out;

  if (ch!=(SIL164_VID & 0xFF))
  {
    xf86DrvMsg(sil->d.pI2CBus->scrnIndex, X_ERROR, "sil164 not detected got %d: from %s Slave %d.\n", ch, sil->d.pI2CBus->BusName, sil->d.SlaveAddr);
    goto out;
  }


  if (!sil164ReadByte(sil, SIL164_DID_LO, &ch))
    goto out;

  if (ch!=(SIL164_DID & 0xFF))
  {
    xf86DrvMsg(sil->d.pI2CBus->scrnIndex, X_ERROR, "sil164 not detected got %d: from %s Slave %d.\n", ch, sil->d.pI2CBus->BusName, sil->d.SlaveAddr);
    goto out;
  }


  if (!xf86I2CDevInit(&(sil->d)))
  {
    goto out;
  }

  return sil;
  
 out:
  xfree(sil);
  return NULL;
}


static Bool sil164Init(I2CDevPtr d)
{
  SIL164Ptr sil = SILPTR(d);

  /* not much to do */
  return TRUE;
}

static ModeStatus sil164ModeValid(I2CDevPtr d, DisplayModePtr mode)
{
  SIL164Ptr sil = SILPTR(d);
  
  return MODE_OK;
}

static void sil164Mode(I2CDevPtr d, DisplayModePtr mode)
{
  SIL164Ptr sil = SILPTR(d);

  /* don't do much */
  return;
}

/* set the SIL164 power state */
static void sil164Power(I2CDevPtr d, Bool On)
{
  SIL164Ptr sil = SILPTR(d);
  int ret;
  unsigned char ch;
  
  ret = sil164ReadByte(sil, SIL164_REG8, &ch);
  if (ret)
    return;

  if (On)
    ch |= SIL164_8_PD;
  else
    ch &= ~SIL164_8_PD;

  sil164WriteByte(sil, SIL164_REG8, ch);
  return;
}

static void sil164PrintRegs(I2CDevPtr d)
{
  SIL164Ptr sil = SILPTR(d);
}

static void sil164SaveRegs(I2CDevPtr d)
{
  SIL164Ptr sil = SILPTR(d);
  
  if (!sil164ReadByte(sil, SIL164_FREQ_LO, &sil->SavedReg.freq_lo))
      return;

  if (!sil164ReadByte(sil, SIL164_FREQ_HI, &sil->SavedReg.freq_hi))
      return;

  if (!sil164ReadByte(sil, SIL164_REG8, &sil->SavedReg.reg8))
    return;
  
  if (!sil164ReadByte(sil, SIL164_REG9, &sil->SavedReg.reg9))
    return;

  if (!sil164ReadByte(sil, SIL164_REGC, &sil->SavedReg.regc))
    return;
  
  return;

}

I830I2CVidOutputRec SIL164VidOutput = {
  sil164Detect,
  sil164Init,
  sil164ModeValid,
  sil164Mode,
  sil164Power,
  sil164PrintRegs,
  sil164SaveRegs,
  NULL,
};