tools/intel_display_poller: Try to fix pipe<->plane handling on gen2/3

Check the pipe assignment for each plane (excluding plane C since the
kernel doesn't use that one) and pick the first one that's assigned to
the target pipe.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
diff --git a/tools/intel_display_poller.c b/tools/intel_display_poller.c
index ec3e30e..8b66b53 100644
--- a/tools/intel_display_poller.c
+++ b/tools/intel_display_poller.c
@@ -88,6 +88,11 @@
 	OUTREG(vlv_offset + reg, val);
 }
 
+static char pipe_name(int pipe)
+{
+	return pipe + 'A';
+}
+
 static int pipe_to_plane(uint32_t devid, int pipe)
 {
 	if (!IS_GEN2(devid) && !IS_GEN3(devid))
@@ -95,13 +100,21 @@
 
 	switch (pipe) {
 	case 0:
-		if ((read_reg(DSPACNTR) & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE_B)
-			return 1;
-		return 0;
-	case 1:
 		if ((read_reg(DSPACNTR) & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE_A)
 			return 0;
-		return 1;
+		if ((read_reg(DSPBCNTR) & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE_A)
+			return 1;
+		fprintf(stderr, "no plane assigned to pipe %c, assuming %c\n",
+			pipe_name(pipe), pipe_name(pipe));
+		return pipe;
+	case 1:
+		if ((read_reg(DSPACNTR) & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE_B)
+			return 0;
+		if ((read_reg(DSPBCNTR) & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE_B)
+			return 1;
+		fprintf(stderr, "no plane assigned to pipe %c, assuming %c\n",
+			pipe_name(pipe), pipe_name(pipe));
+		return pipe;
 	}
 
 	assert(0);
@@ -886,11 +899,6 @@
 	}
 }
 
-static char pipe_name(int pipe)
-{
-	return pipe + 'A';
-}
-
 static const char *test_name(enum test test, int pipe, int bit, bool test_pixel_count)
 {
 	static char str[32];