4 #include "ddk750_sii164.h"
5 #include "ddk750_hwi2c.h"
7 /* I2C Address of each SII164 chip */
8 #define SII164_I2C_ADDRESS 0x70
10 /* Define this definition to use hardware i2c. */
14 #define i2cWriteReg hwI2CWriteReg
15 #define i2cReadReg hwI2CReadReg
17 #define i2cWriteReg swI2CWriteReg
18 #define i2cReadReg swI2CReadReg
21 /* SII164 Vendor and Device ID */
22 #define SII164_VENDOR_ID 0x0001
23 #define SII164_DEVICE_ID 0x0006
25 #ifdef SII164_FULL_FUNCTIONS
26 /* Name of the DVI Controller chip */
27 static char *gDviCtrlChipName = "Silicon Image SiI 164";
32 * This function gets the vendor ID of the DVI controller chip.
37 unsigned short sii164GetVendorID(void)
39 unsigned short vendorID;
41 vendorID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_HIGH) << 8) |
42 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_LOW);
49 * This function gets the device ID of the DVI controller chip.
54 unsigned short sii164GetDeviceID(void)
56 unsigned short deviceID;
58 deviceID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_HIGH) << 8) |
59 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_LOW);
66 /* DVI.C will handle all SiI164 chip stuffs and try it best to make code minimal and useful */
70 * This function initialize and detect the DVI controller chip.
73 * edgeSelect - Edge Select:
74 * 0 = Input data is falling edge latched (falling edge
75 * latched first in dual edge mode)
76 * 1 = Input data is rising edge latched (rising edge
77 * latched first in dual edge mode)
78 * busSelect - Input Bus Select:
79 * 0 = Input data bus is 12-bits wide
80 * 1 = Input data bus is 24-bits wide
81 * dualEdgeClkSelect - Dual Edge Clock Select
82 * 0 = Input data is single edge latched
83 * 1 = Input data is dual edge latched
84 * hsyncEnable - Horizontal Sync Enable:
85 * 0 = HSYNC input is transmitted as fixed LOW
86 * 1 = HSYNC input is transmitted as is
87 * vsyncEnable - Vertical Sync Enable:
88 * 0 = VSYNC input is transmitted as fixed LOW
89 * 1 = VSYNC input is transmitted as is
90 * deskewEnable - De-skewing Enable:
91 * 0 = De-skew disabled
93 * deskewSetting - De-skewing Setting (increment of 260psec)
94 * 0 = 1 step --> minimum setup / maximum hold
101 * 7 = 8 step --> maximum setup / minimum hold
102 * continuousSyncEnable- SYNC Continuous:
105 * pllFilterEnable - PLL Filter Enable
106 * 0 = Disable PLL Filter
107 * 1 = Enable PLL Filter
108 * pllFilterValue - PLL Filter characteristics:
109 * 0~7 (recommended value is 4)
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
128 //unsigned char ucRegIndex, ucRegValue;
129 //unsigned char ucDeviceAddress,
130 unsigned char config;
131 //unsigned long delayCount;
133 /* Initialize the i2c bus */
138 swI2CInit(DEFAULT_I2C_SCL, DEFAULT_I2C_SDA);
141 /* Check if SII164 Chip exists */
142 if ((sii164GetVendorID() == SII164_VENDOR_ID) && (sii164GetDeviceID() == SII164_DEVICE_ID))
146 //sii164PrintRegisterValues();
149 * Initialize SII164 controller chip.
152 /* Select the edge */
154 config = SII164_CONFIGURATION_LATCH_FALLING;
156 config = SII164_CONFIGURATION_LATCH_RISING;
158 /* Select bus wide */
160 config |= SII164_CONFIGURATION_BUS_12BITS;
162 config |= SII164_CONFIGURATION_BUS_24BITS;
164 /* Select Dual/Single Edge Clock */
165 if (dualEdgeClkSelect == 0)
166 config |= SII164_CONFIGURATION_CLOCK_SINGLE;
168 config |= SII164_CONFIGURATION_CLOCK_DUAL;
170 /* Select HSync Enable */
171 if (hsyncEnable == 0)
172 config |= SII164_CONFIGURATION_HSYNC_FORCE_LOW;
174 config |= SII164_CONFIGURATION_HSYNC_AS_IS;
176 /* Select VSync Enable */
177 if (vsyncEnable == 0)
178 config |= SII164_CONFIGURATION_VSYNC_FORCE_LOW;
180 config |= SII164_CONFIGURATION_VSYNC_AS_IS;
182 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
184 /* De-skew enabled with default 111b value.
185 This will fix some artifacts problem in some mode on board 2.2.
186 Somehow this fix does not affect board 2.1.
188 if (deskewEnable == 0)
189 config = SII164_DESKEW_DISABLE;
191 config = SII164_DESKEW_ENABLE;
193 switch (deskewSetting)
196 config |= SII164_DESKEW_1_STEP;
199 config |= SII164_DESKEW_2_STEP;
202 config |= SII164_DESKEW_3_STEP;
205 config |= SII164_DESKEW_4_STEP;
208 config |= SII164_DESKEW_5_STEP;
211 config |= SII164_DESKEW_6_STEP;
214 config |= SII164_DESKEW_7_STEP;
217 config |= SII164_DESKEW_8_STEP;
220 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DESKEW, config);
222 /* Enable/Disable Continuous Sync. */
223 if (continuousSyncEnable == 0)
224 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_DISABLE;
226 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_ENABLE;
228 /* Enable/Disable PLL Filter */
229 if (pllFilterEnable == 0)
230 config |= SII164_PLL_FILTER_DISABLE;
232 config |= SII164_PLL_FILTER_ENABLE;
234 /* Set the PLL Filter value */
235 config |= ((pllFilterValue & 0x07) << 1);
237 i2cWriteReg(SII164_I2C_ADDRESS, SII164_PLL, config);
239 /* Recover from Power Down and enable output. */
240 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION);
241 config |= SII164_CONFIGURATION_POWER_NORMAL;
242 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
245 //sii164PrintRegisterValues();
251 /* Return -1 if initialization fails. */
259 /* below sii164 function is not neccessary */
261 #ifdef SII164_FULL_FUNCTIONS
265 * This function resets the DVI Controller Chip.
267 void sii164ResetChip(void)
276 * sii164GetChipString
277 * This function returns a char string name of the current DVI Controller chip.
278 * It's convenient for application need to display the chip name.
280 char *sii164GetChipString(void)
282 return gDviCtrlChipName;
288 * This function sets the power configuration of the DVI Controller Chip.
291 * powerUp - Flag to set the power down or up
294 unsigned char powerUp
297 unsigned char config;
299 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION);
302 /* Power up the chip */
303 config &= ~SII164_CONFIGURATION_POWER_MASK;
304 config |= SII164_CONFIGURATION_POWER_NORMAL;
305 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
309 /* Power down the chip */
310 config &= ~SII164_CONFIGURATION_POWER_MASK;
311 config |= SII164_CONFIGURATION_POWER_DOWN;
312 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
318 * sii164SelectHotPlugDetectionMode
319 * This function selects the mode of the hot plug detection.
321 static void sii164SelectHotPlugDetectionMode(
322 sii164_hot_plug_mode_t hotPlugMode
325 unsigned char detectReg;
327 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & ~SII164_DETECT_MONITOR_SENSE_OUTPUT_FLAG;
330 case SII164_HOTPLUG_DISABLE:
331 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HIGH;
333 case SII164_HOTPLUG_USE_MDI:
334 detectReg &= ~SII164_DETECT_INTERRUPT_MASK;
335 detectReg |= SII164_DETECT_INTERRUPT_BY_HTPLG_PIN;
336 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_MDI;
338 case SII164_HOTPLUG_USE_RSEN:
339 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_RSEN;
341 case SII164_HOTPLUG_USE_HTPLG:
342 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HTPLG;
346 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg);
350 * sii164EnableHotPlugDetection
351 * This function enables the Hot Plug detection.
353 * enableHotPlug - Enable (=1) / disable (=0) Hot Plug detection
355 void sii164EnableHotPlugDetection(
356 unsigned char enableHotPlug
359 unsigned char detectReg;
360 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT);
362 /* Depending on each DVI controller, need to enable the hot plug based on each
363 individual chip design. */
364 if (enableHotPlug != 0)
365 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_USE_MDI);
367 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_DISABLE);
372 * Check if the DVI Monitor is connected.
378 unsigned char sii164IsConnected(void)
380 unsigned char hotPlugValue;
382 hotPlugValue = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_HOT_PLUG_STATUS_MASK;
383 if (hotPlugValue == SII164_DETECT_HOT_PLUG_STATUS_ON)
390 * sii164CheckInterrupt
391 * Checks if interrupt has occured.
395 * 1 - Interrupt occurs
397 unsigned char sii164CheckInterrupt(void)
399 unsigned char detectReg;
401 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_MONITOR_STATE_MASK;
402 if (detectReg == SII164_DETECT_MONITOR_STATE_CHANGE)
409 * sii164ClearInterrupt
410 * Clear the hot plug interrupt.
412 void sii164ClearInterrupt(void)
414 unsigned char detectReg;
416 /* Clear the MDI interrupt */
417 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT);
418 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg | SII164_DETECT_MONITOR_STATE_CLEAR);