1#define USE_DVICHIP
2#ifdef USE_DVICHIP
3
4#include "ddk750_sii164.h"
5#include "ddk750_hwi2c.h"
6
7
8#define SII164_I2C_ADDRESS 0x70
9
10
11#define USE_HW_I2C
12
13#ifdef USE_HW_I2C
14 #define i2cWriteReg sm750_hw_i2c_write_reg
15 #define i2cReadReg sm750_hw_i2c_read_reg
16#else
17 #define i2cWriteReg sm750_sw_i2c_write_reg
18 #define i2cReadReg sm750_sw_i2c_read_reg
19#endif
20
21
22#define SII164_VENDOR_ID 0x0001
23#define SII164_DEVICE_ID 0x0006
24
25#ifdef SII164_FULL_FUNCTIONS
26
27static char *gDviCtrlChipName = "Silicon Image SiI 164";
28#endif
29
30
31
32
33
34
35
36
37unsigned short sii164GetVendorID(void)
38{
39 unsigned short vendorID;
40
41 vendorID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_HIGH) << 8) |
42 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_LOW);
43
44 return vendorID;
45}
46
47
48
49
50
51
52
53
54unsigned short sii164GetDeviceID(void)
55{
56 unsigned short deviceID;
57
58 deviceID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_HIGH) << 8) |
59 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_LOW);
60
61 return deviceID;
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
115long sii164InitChip(
116 unsigned char edgeSelect,
117 unsigned char busSelect,
118 unsigned char dualEdgeClkSelect,
119 unsigned char hsyncEnable,
120 unsigned char vsyncEnable,
121 unsigned char deskewEnable,
122 unsigned char deskewSetting,
123 unsigned char continuousSyncEnable,
124 unsigned char pllFilterEnable,
125 unsigned char pllFilterValue
126)
127{
128 unsigned char config;
129
130
131#ifdef USE_HW_I2C
132
133 sm750_hw_i2c_init(1);
134#else
135 sm750_sw_i2c_init(DEFAULT_I2C_SCL, DEFAULT_I2C_SDA);
136#endif
137
138
139 if ((sii164GetVendorID() == SII164_VENDOR_ID) && (sii164GetDeviceID() == SII164_DEVICE_ID)) {
140
141
142
143
144
145 if (edgeSelect == 0)
146 config = SII164_CONFIGURATION_LATCH_FALLING;
147 else
148 config = SII164_CONFIGURATION_LATCH_RISING;
149
150
151 if (busSelect == 0)
152 config |= SII164_CONFIGURATION_BUS_12BITS;
153 else
154 config |= SII164_CONFIGURATION_BUS_24BITS;
155
156
157 if (dualEdgeClkSelect == 0)
158 config |= SII164_CONFIGURATION_CLOCK_SINGLE;
159 else
160 config |= SII164_CONFIGURATION_CLOCK_DUAL;
161
162
163 if (hsyncEnable == 0)
164 config |= SII164_CONFIGURATION_HSYNC_FORCE_LOW;
165 else
166 config |= SII164_CONFIGURATION_HSYNC_AS_IS;
167
168
169 if (vsyncEnable == 0)
170 config |= SII164_CONFIGURATION_VSYNC_FORCE_LOW;
171 else
172 config |= SII164_CONFIGURATION_VSYNC_AS_IS;
173
174 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
175
176
177
178
179
180 if (deskewEnable == 0)
181 config = SII164_DESKEW_DISABLE;
182 else
183 config = SII164_DESKEW_ENABLE;
184
185 switch (deskewSetting) {
186 case 0:
187 config |= SII164_DESKEW_1_STEP;
188 break;
189 case 1:
190 config |= SII164_DESKEW_2_STEP;
191 break;
192 case 2:
193 config |= SII164_DESKEW_3_STEP;
194 break;
195 case 3:
196 config |= SII164_DESKEW_4_STEP;
197 break;
198 case 4:
199 config |= SII164_DESKEW_5_STEP;
200 break;
201 case 5:
202 config |= SII164_DESKEW_6_STEP;
203 break;
204 case 6:
205 config |= SII164_DESKEW_7_STEP;
206 break;
207 case 7:
208 config |= SII164_DESKEW_8_STEP;
209 break;
210 }
211 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DESKEW, config);
212
213
214 if (continuousSyncEnable == 0)
215 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_DISABLE;
216 else
217 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_ENABLE;
218
219
220 if (pllFilterEnable == 0)
221 config |= SII164_PLL_FILTER_DISABLE;
222 else
223 config |= SII164_PLL_FILTER_ENABLE;
224
225
226 config |= ((pllFilterValue & 0x07) << 1);
227
228 i2cWriteReg(SII164_I2C_ADDRESS, SII164_PLL, config);
229
230
231 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION);
232 config |= SII164_CONFIGURATION_POWER_NORMAL;
233 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
234
235 return 0;
236 }
237
238
239 return -1;
240}
241
242
243
244
245
246
247
248#ifdef SII164_FULL_FUNCTIONS
249
250
251
252
253
254void sii164ResetChip(void)
255{
256
257 sii164SetPower(0);
258 sii164SetPower(1);
259}
260
261
262
263
264
265
266
267char *sii164GetChipString(void)
268{
269 return gDviCtrlChipName;
270}
271
272
273
274
275
276
277
278
279
280void sii164SetPower(
281 unsigned char powerUp
282)
283{
284 unsigned char config;
285
286 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION);
287 if (powerUp == 1) {
288
289 config &= ~SII164_CONFIGURATION_POWER_MASK;
290 config |= SII164_CONFIGURATION_POWER_NORMAL;
291 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
292 } else {
293
294 config &= ~SII164_CONFIGURATION_POWER_MASK;
295 config |= SII164_CONFIGURATION_POWER_DOWN;
296 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
297 }
298}
299
300
301
302
303
304
305static void sii164SelectHotPlugDetectionMode(
306 sii164_hot_plug_mode_t hotPlugMode
307)
308{
309 unsigned char detectReg;
310
311 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & ~SII164_DETECT_MONITOR_SENSE_OUTPUT_FLAG;
312 switch (hotPlugMode) {
313 case SII164_HOTPLUG_DISABLE:
314 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HIGH;
315 break;
316 case SII164_HOTPLUG_USE_MDI:
317 detectReg &= ~SII164_DETECT_INTERRUPT_MASK;
318 detectReg |= SII164_DETECT_INTERRUPT_BY_HTPLG_PIN;
319 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_MDI;
320 break;
321 case SII164_HOTPLUG_USE_RSEN:
322 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_RSEN;
323 break;
324 case SII164_HOTPLUG_USE_HTPLG:
325 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HTPLG;
326 break;
327 }
328
329 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg);
330}
331
332
333
334
335
336
337
338void sii164EnableHotPlugDetection(
339 unsigned char enableHotPlug
340)
341{
342 unsigned char detectReg;
343
344 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT);
345
346
347
348 if (enableHotPlug != 0)
349 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_USE_MDI);
350 else
351 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_DISABLE);
352}
353
354
355
356
357
358
359
360
361
362unsigned char sii164IsConnected(void)
363{
364 unsigned char hotPlugValue;
365
366 hotPlugValue = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_HOT_PLUG_STATUS_MASK;
367 if (hotPlugValue == SII164_DETECT_HOT_PLUG_STATUS_ON)
368 return 1;
369 else
370 return 0;
371}
372
373
374
375
376
377
378
379
380
381unsigned char sii164CheckInterrupt(void)
382{
383 unsigned char detectReg;
384
385 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_MONITOR_STATE_MASK;
386 if (detectReg == SII164_DETECT_MONITOR_STATE_CHANGE)
387 return 1;
388 else
389 return 0;
390}
391
392
393
394
395
396void sii164ClearInterrupt(void)
397{
398 unsigned char detectReg;
399
400
401 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT);
402 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg | SII164_DETECT_MONITOR_STATE_CLEAR);
403}
404
405#endif
406
407#endif
408
409
410