2 #include "nv_include.h"
5 * DDC1 support only requires DDC_SDA_MASK,
6 * DDC2 support requires DDC_SDA_MASK and DDC_SCL_MASK
8 #define DDC_SDA_READ_MASK (1 << 3)
9 #define DDC_SCL_READ_MASK (1 << 2)
10 #define DDC_SDA_WRITE_MASK (1 << 4)
11 #define DDC_SCL_WRITE_MASK (1 << 5)
14 NVI2CGetBits(I2CBusPtr b, int *clock, int *data)
16 NVPtr pNv = NVPTR(xf86Screens[b->scrnIndex]);
20 /* Doing this on head 0 seems fine. */
21 val = NVReadVgaCrtc(pNv, 0, b->DriverPrivate.uval);
23 *clock = (val & DDC_SCL_READ_MASK) != 0;
24 *data = (val & DDC_SDA_READ_MASK) != 0;
28 NVI2CPutBits(I2CBusPtr b, int clock, int data)
30 NVPtr pNv = NVPTR(xf86Screens[b->scrnIndex]);
33 /* Doing this on head 0 seems fine. */
34 val = NVReadVgaCrtc(pNv, 0, b->DriverPrivate.uval + 1) & 0xf0;
36 val |= DDC_SCL_WRITE_MASK;
38 val &= ~DDC_SCL_WRITE_MASK;
41 val |= DDC_SDA_WRITE_MASK;
43 val &= ~DDC_SDA_WRITE_MASK;
45 /* Doing this on head 0 seems fine. */
46 NVWriteVgaCrtc(pNv, 0, b->DriverPrivate.uval + 1, val | 0x1);
49 static void NV50_I2CPutBits(I2CBusPtr b, int clock, int data)
51 NVPtr pNv = NVPTR(xf86Screens[b->scrnIndex]);
53 NVWrite(pNv, NV50_I2C_PORT(b->DriverPrivate.val), (4 | clock | data << 1));
56 static void NV50_I2CGetBits(I2CBusPtr b, int *clock, int *data)
58 NVPtr pNv = NVPTR(xf86Screens[b->scrnIndex]);
61 val = NVRead(pNv, NV50_I2C_PORT(b->DriverPrivate.val));
67 NV_I2CInit(ScrnInfoPtr pScrn, I2CBusPtr *bus_ptr, int i2c_reg, char *name)
70 NVPtr pNv = NVPTR(pScrn);
72 pI2CBus = xf86CreateI2CBusRec();
76 pI2CBus->BusName = name;
77 pI2CBus->scrnIndex = pScrn->scrnIndex;
78 if (pNv->Architecture == NV_ARCH_50) {
79 pI2CBus->I2CPutBits = NV50_I2CPutBits;
80 pI2CBus->I2CGetBits = NV50_I2CGetBits;
81 /* Could this be used for the rest as well? */
82 pI2CBus->ByteTimeout = 2200; /* VESA DDC spec 3 p. 43 (+10 %) */
83 pI2CBus->StartTimeout = 550;
84 pI2CBus->BitTimeout = 40;
85 pI2CBus->ByteTimeout = 40;
86 pI2CBus->AcknTimeout = 40;
88 pI2CBus->I2CPutBits = NVI2CPutBits;
89 pI2CBus->I2CGetBits = NVI2CGetBits;
90 pI2CBus->AcknTimeout = 5;
93 pI2CBus->DriverPrivate.uval = i2c_reg;
95 if (!xf86I2CBusInit(pI2CBus)) {