gma connectors: Add a Prepare() step

Prepare() will be used to adapt a `Port_Config' to platform quirks.
For instance the FDI usage on Ironlake, USB-C usage on Tiger Lake.

Change-Id: I2fb3ed026077f0371112682b90bea751a28bf994
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.sourcearcade.org/c/libgfxinit/+/462
Tested-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
diff --git a/common/g45/hw-gfx-gma-connectors.adb b/common/g45/hw-gfx-gma-connectors.adb
index ff689bb..6282df7 100644
--- a/common/g45/hw-gfx-gma-connectors.adb
+++ b/common/g45/hw-gfx-gma-connectors.adb
@@ -31,6 +31,17 @@
 
    ----------------------------------------------------------------------------
 
+   procedure Prepare
+     (Port     : in     Active_Port_Type;
+      Port_Cfg : in out Port_Config;
+      Success  :    out Boolean)
+   is
+   begin
+      Success := True;
+   end Prepare;
+
+   ----------------------------------------------------------------------------
+
    procedure Pre_On
      (Pipe        : in     Pipe_Index;
       Port_Cfg    : in     Port_Config;
diff --git a/common/haswell_shared/hw-gfx-gma-connectors.adb b/common/haswell_shared/hw-gfx-gma-connectors.adb
index e81322e..fedf660 100644
--- a/common/haswell_shared/hw-gfx-gma-connectors.adb
+++ b/common/haswell_shared/hw-gfx-gma-connectors.adb
@@ -33,6 +33,19 @@
       DDI.Initialize;
    end Initialize;
 
+   ----------------------------------------------------------------------------
+
+   procedure Prepare
+     (Port     : in     Active_Port_Type;
+      Port_Cfg : in out Port_Config;
+      Success  :    out Boolean)
+   is
+   begin
+      Success := True;
+   end Prepare;
+
+   ----------------------------------------------------------------------------
+
    procedure Pre_On
      (Pipe     : in     Pipe_Index;
       Port_Cfg : in     Port_Config;
diff --git a/common/hw-gfx-gma-connectors.ads b/common/hw-gfx-gma-connectors.ads
index a1d0d1e..89b9c6a 100644
--- a/common/hw-gfx-gma-connectors.ads
+++ b/common/hw-gfx-gma-connectors.ads
@@ -14,14 +14,24 @@
 
 private package HW.GFX.GMA.Connectors is
 
+   pragma Warnings (GNATprove, Off, "unused variable ""P*""",
+                    Reason => "Needed for a common interface");
+   pragma Warnings (GNATprove, Off, """P*"" is not modified, could be IN",
+                    Reason => "Needed for a common interface");
    pragma Warnings (GNATprove, Off, "subprogram ""*"" has no effect",
                     Reason => "Only effects some platforms");
    procedure Post_Reset_Off;
    procedure Initialize;
+   procedure Prepare
+     (Port     : in     Active_Port_Type;
+      Port_Cfg : in out Port_Config;
+      Success  :    out Boolean)
+   with
+      Post => Port_Cfg.Mode = Port_Cfg'Old.Mode;
+
+   pragma Warnings (GNATprove, On, """P*"" is not modified, could be IN");
    pragma Warnings (GNATprove, On, "subprogram ""*"" has no effect");
 
-   pragma Warnings (GNATprove, Off, "unused variable ""P*""",
-                    Reason => "Needed for a common interface");
    procedure Pre_On
      (Pipe        : in     Pipe_Index;
       Port_Cfg    : in     Port_Config;
diff --git a/common/hw-gfx-gma-display_probing.adb b/common/hw-gfx-gma-display_probing.adb
index 72df4ed..673f0ad 100644
--- a/common/hw-gfx-gma-display_probing.adb
+++ b/common/hw-gfx-gma-display_probing.adb
@@ -19,6 +19,7 @@
 with HW.GFX.GMA.I2C;
 with HW.GFX.GMA.DP_Aux_Ch;
 with HW.GFX.GMA.Panel;
+with HW.GFX.GMA.Connectors;
 with HW.GFX.GMA.Port_Detect;
 with HW.GFX.GMA.Power_And_Clocks;
 
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index e26e751..2a7b7a6 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -162,6 +162,10 @@
          Connector_Info.Preferred_Link_Setting (Port_Cfg, Success);
       end if;
 
+      if Success then
+         Connectors.Prepare (Pipe_Cfg.Port, Port_Cfg, Success);
+      end if;
+
       -- loop over all possible DP-lane configurations
       -- (non-DP ports use a single fake configuration)
       while Success loop
@@ -217,6 +221,9 @@
          end if;
 
          Connector_Info.Next_Link_Setting (Port_Cfg, Success);
+         exit when not Success;
+
+         Connectors.Prepare (Pipe_Cfg.Port, Port_Cfg, Success);
       end loop;
 
       if Success then
diff --git a/common/i945/hw-gfx-gma-connectors.adb b/common/i945/hw-gfx-gma-connectors.adb
index e774227..383f7d3 100644
--- a/common/i945/hw-gfx-gma-connectors.adb
+++ b/common/i945/hw-gfx-gma-connectors.adb
@@ -28,6 +28,17 @@
 
    ----------------------------------------------------------------------------
 
+   procedure Prepare
+     (Port     : in     Active_Port_Type;
+      Port_Cfg : in out Port_Config;
+      Success  :    out Boolean)
+   is
+   begin
+      Success := True;
+   end Prepare;
+
+   ----------------------------------------------------------------------------
+
    procedure Pre_On
      (Pipe        : in     Pipe_Index;
       Port_Cfg    : in     Port_Config;
diff --git a/common/ironlake/hw-gfx-gma-connectors.adb b/common/ironlake/hw-gfx-gma-connectors.adb
index 1c3a243..db8e6d0 100644
--- a/common/ironlake/hw-gfx-gma-connectors.adb
+++ b/common/ironlake/hw-gfx-gma-connectors.adb
@@ -32,6 +32,19 @@
    procedure Post_Reset_Off is null;
    procedure Initialize is null;
 
+   ----------------------------------------------------------------------------
+
+   procedure Prepare
+     (Port     : in     Active_Port_Type;
+      Port_Cfg : in out Port_Config;
+      Success  :    out Boolean)
+   is
+   begin
+      Success := True;
+   end Prepare;
+
+   ----------------------------------------------------------------------------
+
    function Is_Internal (Port_Cfg : Port_Config) return Boolean
    is
    begin
diff --git a/common/tigerlake/hw-gfx-gma-connectors.adb b/common/tigerlake/hw-gfx-gma-connectors.adb
index 5e66b96..35e0692 100644
--- a/common/tigerlake/hw-gfx-gma-connectors.adb
+++ b/common/tigerlake/hw-gfx-gma-connectors.adb
@@ -30,6 +30,19 @@
       pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
    end Initialize;
 
+   ---------------------------------------------------------------------
+
+   procedure Prepare
+     (Port     : in     Active_Port_Type;
+      Port_Cfg : in out Port_Config;
+      Success  :    out Boolean)
+   is
+   begin
+      Success := False;
+   end;
+
+   ---------------------------------------------------------------------
+
    procedure Pre_On
      (Pipe        : in     Pipe_Index;
       Port_Cfg    : in     Port_Config;