ReactOS  0.4.13-dev-544-gede3fdd
ddc.c File Reference
#include "videoprt.h"
#include <debug.h>
Include dependency graph for ddc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DDC_EEPROM_ADDRESS   0xA0
 
#define LOW   0
 
#define HIGH   1
 
#define WRITE   0
 
#define READ   1
 
#define READ_SDA()   (i2c->ReadDataLine(HwDeviceExtension))
 
#define READ_SCL()   (i2c->ReadClockLine(HwDeviceExtension))
 
#define WRITE_SDA(state)   (i2c->WriteDataLine(HwDeviceExtension, state))
 
#define WRITE_SCL(state)   (i2c->WriteClockLine(HwDeviceExtension, state))
 
#define DELAY_HALF()   KeDelayExecutionThread(KernelMode, FALSE, &HalfPeriodDelay)
 

Functions

static BOOL I2CWrite (PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Data)
 
static UCHAR I2CRead (PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, BOOL Ack)
 
static VOID I2CStop (PVOID HwDeviceExtension, PI2C_CALLBACKS i2c)
 
static BOOL I2CStart (PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Address)
 
static BOOL I2CRepStart (PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Address)
 
BOOLEAN NTAPI VideoPortDDCMonitorHelper (PVOID HwDeviceExtension, PVOID I2CFunctions, PUCHAR pEdidBuffer, ULONG EdidBufferSize)
 

Variables

static LARGE_INTEGER HalfPeriodDelay = {{0, 70}}
 

Macro Definition Documentation

◆ DDC_EEPROM_ADDRESS

#define DDC_EEPROM_ADDRESS   0xA0

Definition at line 27 of file ddc.c.

◆ DELAY_HALF

Definition at line 41 of file ddc.c.

◆ HIGH

#define HIGH   1

Definition at line 32 of file ddc.c.

◆ LOW

#define LOW   0

Definition at line 31 of file ddc.c.

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file ddc.c.

◆ READ

#define READ   1

Definition at line 34 of file ddc.c.

◆ READ_SCL

#define READ_SCL ( )    (i2c->ReadClockLine(HwDeviceExtension))

Definition at line 36 of file ddc.c.

◆ READ_SDA

#define READ_SDA ( )    (i2c->ReadDataLine(HwDeviceExtension))

Definition at line 35 of file ddc.c.

◆ WRITE

#define WRITE   0

Definition at line 33 of file ddc.c.

◆ WRITE_SCL

#define WRITE_SCL (   state)    (i2c->WriteClockLine(HwDeviceExtension, state))

Definition at line 38 of file ddc.c.

◆ WRITE_SDA

#define WRITE_SDA (   state)    (i2c->WriteDataLine(HwDeviceExtension, state))

Definition at line 37 of file ddc.c.

Function Documentation

◆ I2CRead()

static UCHAR I2CRead ( PVOID  HwDeviceExtension,
PI2C_CALLBACKS  i2c,
BOOL  Ack 
)
static

Definition at line 79 of file ddc.c.

80 {
81  INT Bit = 0x80;
82  UCHAR Data = 0;
83 
84  /* pull down SCL and release SDA */
85  WRITE_SCL(LOW);
86  WRITE_SDA(HIGH);
87 
88  /* read byte */
89  for (Bit = (1 << 7); Bit != 0; Bit >>= 1)
90  {
91  WRITE_SCL(LOW);
92  DELAY_HALF();
93  WRITE_SCL(HIGH);
94  DELAY_HALF();
95  if (READ_SDA() == HIGH)
96  Data |= Bit;
97  }
98 
99  /* send ack/nak */
100  WRITE_SCL(LOW);
101  WRITE_SDA(Ack ? LOW : HIGH);
102  DELAY_HALF();
103  WRITE_SCL(HIGH);
104  do
105  {
106  DELAY_HALF();
107  }
108  while (READ_SCL() != HIGH);
109 
110  return Data;
111 }
#define LOW
Definition: ddc.c:31
int32_t INT
Definition: typedefs.h:56
#define WRITE_SCL(state)
Definition: ddc.c:38
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
#define READ_SDA()
Definition: ddc.c:35
#define HIGH
Definition: ddc.c:32
unsigned char UCHAR
Definition: xmlstorage.h:181
#define DELAY_HALF()
Definition: ddc.c:41
#define READ_SCL()
Definition: ddc.c:36
#define WRITE_SDA(state)
Definition: ddc.c:37

Referenced by VideoPortDDCMonitorHelper().

◆ I2CRepStart()

static BOOL I2CRepStart ( PVOID  HwDeviceExtension,
PI2C_CALLBACKS  i2c,
UCHAR  Address 
)
static

Definition at line 153 of file ddc.c.

154 {
155  /* setup lines for repeated start condition */
156  WRITE_SCL(LOW);
157  DELAY_HALF();
158  WRITE_SDA(HIGH);
159  DELAY_HALF();
160  WRITE_SCL(HIGH);
161  DELAY_HALF();
162 
163  return I2CStart(HwDeviceExtension, i2c, Address);
164 }
#define LOW
Definition: ddc.c:31
#define WRITE_SCL(state)
Definition: ddc.c:38
static WCHAR Address[46]
Definition: ping.c:68
#define HIGH
Definition: ddc.c:32
#define DELAY_HALF()
Definition: ddc.c:41
static BOOL I2CStart(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Address)
Definition: ddc.c:127
#define WRITE_SDA(state)
Definition: ddc.c:37

Referenced by VideoPortDDCMonitorHelper().

◆ I2CStart()

static BOOL I2CStart ( PVOID  HwDeviceExtension,
PI2C_CALLBACKS  i2c,
UCHAR  Address 
)
static

Definition at line 127 of file ddc.c.

128 {
129  /* make sure the bus is free */
130  if (READ_SDA() == LOW || READ_SCL() == LOW)
131  {
132  WARN_(VIDEOPRT, "I2CStart: Bus is not free!\n");
133  return FALSE;
134  }
135 
136  /* send address */
137  WRITE_SDA(LOW);
138  DELAY_HALF();
139  if (!I2CWrite(HwDeviceExtension, i2c, Address))
140  {
141  /* ??release the bus?? */
142  I2CStop(HwDeviceExtension, i2c);
143  WARN_(VIDEOPRT, "I2CStart: Device not found (Address = 0x%x)\n", Address);
144  return FALSE;
145  }
146 
147  INFO_(VIDEOPRT, "I2CStart: SUCCESS!\n");
148  return TRUE;
149 }
#define TRUE
Definition: types.h:120
#define INFO_(ch,...)
Definition: debug.h:159
#define LOW
Definition: ddc.c:31
static WCHAR Address[46]
Definition: ping.c:68
#define READ_SDA()
Definition: ddc.c:35
static VOID I2CStop(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c)
Definition: ddc.c:115
static BOOL I2CWrite(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Data)
Definition: ddc.c:45
#define DELAY_HALF()
Definition: ddc.c:41
#define READ_SCL()
Definition: ddc.c:36
#define WRITE_SDA(state)
Definition: ddc.c:37
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by I2CRepStart(), and VideoPortDDCMonitorHelper().

◆ I2CStop()

static VOID I2CStop ( PVOID  HwDeviceExtension,
PI2C_CALLBACKS  i2c 
)
static

Definition at line 115 of file ddc.c.

116 {
117  WRITE_SCL(LOW);
118  WRITE_SDA(LOW);
119  DELAY_HALF();
120  WRITE_SCL(HIGH);
121  DELAY_HALF();
122  WRITE_SDA(HIGH);
123 }
#define LOW
Definition: ddc.c:31
#define WRITE_SCL(state)
Definition: ddc.c:38
#define HIGH
Definition: ddc.c:32
#define DELAY_HALF()
Definition: ddc.c:41
#define WRITE_SDA(state)
Definition: ddc.c:37

Referenced by I2CStart(), and VideoPortDDCMonitorHelper().

◆ I2CWrite()

static BOOL I2CWrite ( PVOID  HwDeviceExtension,
PI2C_CALLBACKS  i2c,
UCHAR  Data 
)
static

Definition at line 45 of file ddc.c.

46 {
47  UCHAR Bit;
48  BOOL Ack;
49 
50  /* transmit data */
51  for (Bit = (1 << 7); Bit != 0; Bit >>= 1)
52  {
53  WRITE_SCL(LOW);
54  WRITE_SDA((Data & Bit) ? HIGH : LOW);
55  DELAY_HALF();
56  WRITE_SCL(HIGH);
57  DELAY_HALF();
58  }
59 
60  /* get ack */
61  WRITE_SCL(LOW);
62  WRITE_SDA(HIGH);
63  DELAY_HALF();
64  WRITE_SCL(HIGH);
65  do
66  {
67  DELAY_HALF();
68  }
69  while (READ_SCL() != HIGH);
70  Ack = (READ_SDA() == LOW);
71  DELAY_HALF();
72 
73  INFO_(VIDEOPRT, "I2CWrite: %s\n", Ack ? "Ack" : "Nak");
74  return Ack;
75 }
#define INFO_(ch,...)
Definition: debug.h:159
#define LOW
Definition: ddc.c:31
#define WRITE_SCL(state)
Definition: ddc.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
#define READ_SDA()
Definition: ddc.c:35
#define HIGH
Definition: ddc.c:32
unsigned char UCHAR
Definition: xmlstorage.h:181
#define DELAY_HALF()
Definition: ddc.c:41
#define READ_SCL()
Definition: ddc.c:36
#define WRITE_SDA(state)
Definition: ddc.c:37

Referenced by I2CStart(), and VideoPortDDCMonitorHelper().

◆ VideoPortDDCMonitorHelper()

BOOLEAN NTAPI VideoPortDDCMonitorHelper ( PVOID  HwDeviceExtension,
PVOID  I2CFunctions,
PUCHAR  pEdidBuffer,
ULONG  EdidBufferSize 
)

Definition at line 173 of file ddc.c.

179 {
180  PDDC_CONTROL ddc = (PDDC_CONTROL)I2CFunctions;
181  PI2C_CALLBACKS i2c = &ddc->I2CCallbacks;
182  INT Count, i;
183  PUCHAR pBuffer = (PUCHAR)pEdidBuffer;
184  BOOL Ack;
185 
186  TRACE_(VIDEOPRT, "VideoPortDDCMonitorHelper()\n");
187 
189  if (ddc->Size != sizeof (ddc))
190  {
191  WARN_(VIDEOPRT, "ddc->Size != %d (%d)\n", sizeof (ddc), ddc->Size);
192  return FALSE;
193  }
194 
195  /* select eeprom */
196  if (!I2CStart(HwDeviceExtension, i2c, DDC_EEPROM_ADDRESS | WRITE))
197  return FALSE;
198  /* set address */
199  if (!I2CWrite(HwDeviceExtension, i2c, 0x00))
200  return FALSE;
201  /* change into read mode */
202  if (!I2CRepStart(HwDeviceExtension, i2c, DDC_EEPROM_ADDRESS | READ))
203  return FALSE;
204  /* read eeprom */
205  RtlZeroMemory(pEdidBuffer, EdidBufferSize);
206  Count = min(128, EdidBufferSize);
207  for (i = 0; i < Count; i++)
208  {
209  Ack = ((i + 1) < Count);
210  pBuffer[i] = I2CRead(HwDeviceExtension, i2c, Ack);
211  }
212  I2CStop(HwDeviceExtension, i2c);
213 
214  /* check EDID header */
215  if (pBuffer[0] != 0x00 || pBuffer[1] != 0xff ||
216  pBuffer[2] != 0xff || pBuffer[3] != 0xff ||
217  pBuffer[4] != 0xff || pBuffer[5] != 0xff ||
218  pBuffer[6] != 0xff || pBuffer[7] != 0x00)
219  {
220  WARN_(VIDEOPRT, "VideoPortDDCMonitorHelper(): Invalid EDID header!\n");
221  return FALSE;
222  }
223 
224  INFO_(VIDEOPRT, "VideoPortDDCMonitorHelper(): EDID version %d rev. %d\n", pBuffer[18], pBuffer[19]);
225  INFO_(VIDEOPRT, "VideoPortDDCMonitorHelper() - SUCCESS!\n");
226  return TRUE;
227 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define TRUE
Definition: types.h:120
#define INFO_(ch,...)
Definition: debug.h:159
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned char * PUCHAR
Definition: retypes.h:3
#define READ
Definition: ddc.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
int32_t INT
Definition: typedefs.h:56
IN I2C_CALLBACKS I2CCallbacks
Definition: video.h:699
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
struct _DDC_CONTROL * PDDC_CONTROL
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
static BOOL I2CRepStart(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Address)
Definition: ddc.c:153
#define WRITE
Definition: ddc.c:33
static VOID I2CStop(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c)
Definition: ddc.c:115
static BOOL I2CWrite(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Data)
Definition: ddc.c:45
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DDC_EEPROM_ADDRESS
Definition: ddc.c:27
static UCHAR I2CRead(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, BOOL Ack)
Definition: ddc.c:79
#define min(a, b)
Definition: monoChain.cc:55
IN ULONG Size
Definition: video.h:698
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
static BOOL I2CStart(PVOID HwDeviceExtension, PI2C_CALLBACKS i2c, UCHAR Address)
Definition: ddc.c:127
#define WARN_(ch,...)
Definition: debug.h:157

Variable Documentation

◆ HalfPeriodDelay

LARGE_INTEGER HalfPeriodDelay = {{0, 70}}
static

Definition at line 40 of file ddc.c.