From c5d8647eff7a9cca501dc32334fcc08144abf626 Mon Sep 17 00:00:00 2001
From: Andrei-Liviu Simion <andrei.simion@xilinx.com>
Date: Wed, 28 Jan 2015 19:15:28 -0800
Subject: [PATCH] dptx: Only increment segment pointer if required.

It seems that monitors capable of MST, upon switching to SST mode in the monitor
options menu, respond with NACK when the segment pointer is written.
These same monitors ACK segment pointer writes when running in MST mode.
Tested monitors that are SST only monitors also ACK segment pointer writes.

The issue here is that MST monitors running in SST mode will error out when the
I2C read function is called because the segment pointer is always being written
to 0 (segment pointer is reset), and thus receives a NACK.
This patch prevents this from happening.

From now on, if the user changes the segment pointer, it is up to them to reset
it to 0.
The I2C read will only increment the segment pointer when required to do a read
outside of the base EDID block.

Signed-off-by: Andrei-Liviu Simion <andrei.simion@xilinx.com>
---
 XilinxProcessorIPLib/drivers/dptx/src/xdptx.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/XilinxProcessorIPLib/drivers/dptx/src/xdptx.c b/XilinxProcessorIPLib/drivers/dptx/src/xdptx.c
index 94ae22b0..81b832ab 100644
--- a/XilinxProcessorIPLib/drivers/dptx/src/xdptx.c
+++ b/XilinxProcessorIPLib/drivers/dptx/src/xdptx.c
@@ -831,9 +831,8 @@ u32 XDptx_IicRead(XDptx *InstancePtr, u8 IicAddress, u16 Offset,
 	NumBytesLeftInSeg = 256 - Offset;
 
 	/* Set the segment pointer to 0. */
-	Status = XDptx_IicWrite(InstancePtr, XDPTX_SEGPTR_ADDR, 1, &SegPtr);
-	if (Status != XST_SUCCESS) {
-		return Status;
+	if (SegPtr != 0) {
+		XDptx_IicWrite(InstancePtr, XDPTX_SEGPTR_ADDR, 1, &SegPtr);
 	}
 
 	/* Send I2C read message. Multiple transactions are required if the
@@ -875,11 +874,8 @@ u32 XDptx_IicRead(XDptx *InstancePtr, u8 IicAddress, u16 Offset,
 				Offset %= 256;
 				SegPtr++;
 
-				Status = XDptx_IicWrite(InstancePtr,
-						XDPTX_SEGPTR_ADDR, 1, &SegPtr);
-				if (Status != XST_SUCCESS) {
-					return Status;
-				}
+				XDptx_IicWrite(InstancePtr, XDPTX_SEGPTR_ADDR,
+								1, &SegPtr);
 			}
 		}
 		/* Last I2C read. */
@@ -889,8 +885,10 @@ u32 XDptx_IicRead(XDptx *InstancePtr, u8 IicAddress, u16 Offset,
 	}
 
 	/* Reset the segment pointer to 0. */
-	SegPtr = 0;
-	Status = XDptx_IicWrite(InstancePtr, XDPTX_SEGPTR_ADDR, 1, &SegPtr);
+	if (SegPtr != 0) {
+		SegPtr = 0;
+		XDptx_IicWrite(InstancePtr, XDPTX_SEGPTR_ADDR, 1, &SegPtr);
+	}
 
 	return Status;
 }