From 16c0dbba1429180fc74d9210a47bae5f2ebab119 Mon Sep 17 00:00:00 2001 From: Kevin Brace Date: Sat, 16 Jan 2016 20:35:28 -0600 Subject: [PATCH 2/7] General improvement of via_i2c.c Added debug messages to via_i2c.c in order to aid the debugging effort. Adjusted bus timing related parameters for I2C bus 2 and 3. --- src/via_i2c.c | 161 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 114 insertions(+), 47 deletions(-) diff --git a/src/via_i2c.c b/src/via_i2c.c index bde073c..ca3c459 100644 --- a/src/via_i2c.c +++ b/src/via_i2c.c @@ -1,4 +1,6 @@ /* + * Copyright 2005-2015 The Openchrome Project + * [http://www.freedesktop.org/wiki/Openchrome] * Copyright 2004 The Unichrome Project [unichrome.sf.net] * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved. @@ -24,7 +26,7 @@ */ /* - * Implements three i2c busses through registers SR26, SR2c, and SR31. + * Implements three I2C buses through registers SR26, SR2C, and SR31. */ #ifdef HAVE_CONFIG_H @@ -39,7 +41,7 @@ #define SCL_WRITE 0x20 /* - * CRT I2C + * First I2C bus: Typically used for detecting a VGA monitor. */ static void ViaI2C1PutBits(I2CBusPtr Bus, int clock, int data) @@ -69,33 +71,54 @@ ViaI2C1GetBits(I2CBusPtr Bus, int *clock, int *data) static I2CBusPtr ViaI2CBus1Init(ScrnInfoPtr pScrn) { - I2CBusPtr pI2CBus = xf86CreateI2CBusRec(); vgaHWPtr hwp = VGAHWPTR(pScrn); - - DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ViaI2CBus1Init\n")); - - if (!pI2CBus) + I2CBusPtr pI2CBus = NULL; + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Entered ViaI2CBus1Init.\n")); + + pI2CBus = xf86CreateI2CBusRec(); + if (!pI2CBus) { + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "xf86CreateI2CBusRec failed.\n")); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Initialization of I2C Bus 1 failed.\n"); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus1Init.\n")); return NULL; + } - pI2CBus->BusName = "I2C bus 1"; + pI2CBus->BusName = "I2C Bus 1"; pI2CBus->scrnIndex = pScrn->scrnIndex; + pI2CBus->DriverPrivate.ptr = hwp; + pI2CBus->I2CPutBits = ViaI2C1PutBits; pI2CBus->I2CGetBits = ViaI2C1GetBits; - pI2CBus->DriverPrivate.ptr = hwp; + pI2CBus->ByteTimeout = 2200; pI2CBus->StartTimeout = 550; pI2CBus->HoldTime = 40; pI2CBus->BitTimeout = 40; if (!xf86I2CBusInit(pI2CBus)) { + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "xf86I2CBusInit failed.\n")); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Initialization of I2C Bus 1 failed.\n"); xf86DestroyI2CBusRec(pI2CBus, TRUE, FALSE); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus1Init.\n")); return NULL; } + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus1Init.\n")); return pI2CBus; } /* - * First data bus I2C: tends to have TV-encoders. + * Second I2C bus: Used to detect a DVI monitor, VGA monitor via + * a DVI-I connector, or TV encoders. */ static void ViaI2C2PutBits(I2CBusPtr Bus, int clock, int data) @@ -125,30 +148,55 @@ ViaI2C2GetBits(I2CBusPtr Bus, int *clock, int *data) static I2CBusPtr ViaI2CBus2Init(ScrnInfoPtr pScrn) { - I2CBusPtr pI2CBus = xf86CreateI2CBusRec(); vgaHWPtr hwp = VGAHWPTR(pScrn); - - DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ViaI2cBus2Init\n")); - - if (!pI2CBus) + I2CBusPtr pI2CBus = NULL; + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Entered ViaI2CBus2Init.\n")); + + pI2CBus = xf86CreateI2CBusRec(); + if (!pI2CBus) { + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "xf86CreateI2CBusRec failed.\n")); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Initialization of I2C Bus 2 failed.\n"); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus2Init.\n")); return NULL; + } - pI2CBus->BusName = "I2C bus 2"; + pI2CBus->BusName = "I2C Bus 2"; pI2CBus->scrnIndex = pScrn->scrnIndex; + pI2CBus->DriverPrivate.ptr = hwp; + pI2CBus->I2CPutBits = ViaI2C2PutBits; pI2CBus->I2CGetBits = ViaI2C2GetBits; - pI2CBus->DriverPrivate.ptr = hwp; + +/* The following 4 lines were copied from ViaI2CBus1Init function. */ + pI2CBus->ByteTimeout = 2200; + pI2CBus->StartTimeout = 550; + pI2CBus->HoldTime = 40; + pI2CBus->BitTimeout = 40; if (!xf86I2CBusInit(pI2CBus)) { + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "xf86I2CBusInit failed.\n")); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Initialization of I2C Bus 2 failed.\n"); xf86DestroyI2CBusRec(pI2CBus, TRUE, FALSE); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus2Init.\n")); return NULL; } + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus2Init.\n")); return pI2CBus; } /* - * A third I2C bus is implemented by a few IO pins. - * Requires higher level functions to be used properly. + * Third I2C bus: Implemented via manipulation of GPIO (General + * Purpose I/O) pins. */ static Bool ViaI2C3Start(I2CBusPtr b, int timeout) @@ -333,46 +381,55 @@ ViaI2C3SimpleGetBits(I2CBusPtr Bus, int *clock, int *data) static I2CBusPtr ViaI2CBus3Init(ScrnInfoPtr pScrn) { - I2CBusPtr pI2CBus = xf86CreateI2CBusRec(); vgaHWPtr hwp = VGAHWPTR(pScrn); VIAPtr pVia = VIAPTR(pScrn); - - DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ViaI2CBus3Init\n")); - - if (!pI2CBus) + I2CBusPtr pI2CBus = NULL; + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Entered ViaI2CBus3Init.\n")); + + pI2CBus = xf86CreateI2CBusRec(); + if (!pI2CBus) { + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "xf86CreateI2CBusRec failed.\n")); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Initialization of I2C Bus 3 failed.\n"); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus3Init.\n")); return NULL; + } - pI2CBus->BusName = "I2C bus 3"; + pI2CBus->BusName = "I2C Bus 3"; pI2CBus->scrnIndex = pScrn->scrnIndex; pI2CBus->DriverPrivate.ptr = hwp; - switch (pVia->Chipset) { - case VIA_P4M800PRO: - DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using alternative PutBits/GetBits functions for I2C Bus 3\n")); - pI2CBus->I2CPutBits = ViaI2C3SimplePutBits; - pI2CBus->I2CGetBits = ViaI2C3SimpleGetBits; - break; - default: - pI2CBus->I2CAddress = ViaI2C3Address; + pI2CBus->I2CAddress = ViaI2C3Address; #ifdef X_NEED_I2CSTART - pI2CBus->I2CStart = ViaI2C3Start; + pI2CBus->I2CStart = ViaI2C3Start; #endif - pI2CBus->I2CStop = ViaI2C3Stop; - pI2CBus->I2CPutByte = ViaI2C3PutByte; - pI2CBus->I2CGetByte = ViaI2C3GetByte; - pI2CBus->DriverPrivate.ptr = hwp; - - pI2CBus->BitTimeout = 10; - pI2CBus->ByteTimeout = 10; - pI2CBus->HoldTime = 10; - pI2CBus->StartTimeout = 10; - break; - } + pI2CBus->I2CStop = ViaI2C3Stop; + pI2CBus->I2CPutByte = ViaI2C3PutByte; + pI2CBus->I2CGetByte = ViaI2C3GetByte; + +/* The following 4 lines were copied from ViaI2CBus1Init function. */ + pI2CBus->ByteTimeout = 2200; + pI2CBus->StartTimeout = 550; + pI2CBus->HoldTime = 40; + pI2CBus->BitTimeout = 40; if (!xf86I2CBusInit(pI2CBus)) { + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "xf86I2CBusInit failed.\n")); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Initialization of I2C Bus 3 failed.\n"); xf86DestroyI2CBusRec(pI2CBus, TRUE, FALSE); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus3Init.\n")); return NULL; } + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CBus3Init.\n")); return pI2CBus; } @@ -382,13 +439,19 @@ ViaI2CScan(I2CBusPtr Bus) { CARD8 i; - xf86DrvMsg(Bus->scrnIndex, X_INFO, "ViaI2CScan: Scanning %s\n", + DEBUG(xf86DrvMsg(Bus->scrnIndex, X_INFO, + "Entered ViaI2CScan.\n")); + + xf86DrvMsg(Bus->scrnIndex, X_INFO, "Scanning %s\n", Bus->BusName); for (i = 0x10; i < 0xF0; i += 2) if (xf86I2CProbeAddress(Bus, i)) xf86DrvMsg(Bus->scrnIndex, X_PROBED, "Found slave on %s " "- 0x%02X\n", Bus->BusName, i); + + DEBUG(xf86DrvMsg(Bus->scrnIndex, X_INFO, + "Exiting ViaI2CScan.\n")); } #endif /* HAVE_DEBUG */ @@ -397,7 +460,8 @@ ViaI2CInit(ScrnInfoPtr pScrn) { VIAPtr pVia = VIAPTR(pScrn); - DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ViaI2CInit\n")); + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Entered ViaI2CInit.\n")); if (pVia->I2CDevices & VIA_I2C_BUS1) pVia->pI2CBus1 = ViaI2CBus1Init(pScrn); @@ -414,4 +478,7 @@ ViaI2CInit(ScrnInfoPtr pScrn) ViaI2CScan(pVia->pI2CBus3); } #endif + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Exiting ViaI2CInit.\n")); } -- 1.7.9.5