gma: Always clear hot-plug events before enabling a pipe

For cold plugging, we don't wait for a hot-plug event. But, even if we
are not supposed to wait for a hot-plug event, we have to clear any
pending event. Also, a failed DP training can result in another hot-plug
event.

A stale event would be spuriously interpreted as a disconnect, resul-
ting in an infinite loop of cycling the pipe on and off.

Change-Id: I4c7bbe0ac792553c94e928ba0a5eeb822a857f9c
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/18122
Tested-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/common/haswell_shared/hw-gfx-gma-port_detect.adb b/common/haswell_shared/hw-gfx-gma-port_detect.adb
index 2f5854d..01bd0fe 100644
--- a/common/haswell_shared/hw-gfx-gma-port_detect.adb
+++ b/common/haswell_shared/hw-gfx-gma-port_detect.adb
@@ -189,4 +189,14 @@
       end if;
    end Hotplug_Detect;
 
+   procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
+   is
+      Ignored_HPD : Boolean;
+   begin
+      pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
+                       Reason => "We want to clear pending events only");
+      Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
+      pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
+   end Clear_Hotplug_Detect;
+
 end HW.GFX.GMA.Port_Detect;
diff --git a/common/hw-gfx-gma-port_detect.ads b/common/hw-gfx-gma-port_detect.ads
index 1cd8d6b..adf0681 100644
--- a/common/hw-gfx-gma-port_detect.ads
+++ b/common/hw-gfx-gma-port_detect.ads
@@ -20,4 +20,6 @@
      (Port     : in Active_Port_Type;
       Detected : out Boolean);
 
+   procedure Clear_Hotplug_Detect (Port : Active_Port_Type);
+
 end HW.GFX.GMA.Port_Detect;
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index 616a170..ca27175 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -121,6 +121,9 @@
                pragma Loop_Invariant
                  (Pipe_Cfg.Port in Active_Port_Type);
 
+               -- Clear pending hot-plug events before every try
+               Port_Detect.Clear_Hotplug_Detect (Pipe_Cfg.Port);
+
                Connectors.Pre_On
                  (Pipe        => Pipe,
                   Port_Cfg    => Port_Cfg,
diff --git a/common/ironlake/hw-gfx-gma-port_detect.adb b/common/ironlake/hw-gfx-gma-port_detect.adb
index ff4ff88..142f712 100644
--- a/common/ironlake/hw-gfx-gma-port_detect.adb
+++ b/common/ironlake/hw-gfx-gma-port_detect.adb
@@ -159,4 +159,14 @@
       end case;
    end Hotplug_Detect;
 
+   procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
+   is
+      Ignored_HPD : Boolean;
+   begin
+      pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
+                       Reason => "We want to clear pending events only");
+      Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
+      pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
+   end Clear_Hotplug_Detect;
+
 end HW.GFX.GMA.Port_Detect;