gma: Re-structure TC port types

The `USBC1_DP/_HDMI' names did not draw an accurate picture. If
they are implemented as legacy ports (for HDMI always the case),
they don't show as USBC in schematics, the OS or anywhere else.
We also couldn't tell if a `USBCx_DP' was implemented as legacy
or USB-C.

We split them by actual, physical connector type now: HDMI, DP,
and USBC (for DP-Alt mode).  The `_TCx' suffixes should provide
an idea where they are connected to a socket or SoC.

Tiger Lake and seemingly Alder Lake use the first 4 TC register
sets only. Hence we keep only 4 respective TC ports for now.

Also, as any of the 3 Combo-PHYs (DP1..3) can be used as eDP, we
map that to the port,  that is used with the first set of panel-
control lines. This should hopefully match most board designs.

Change-Id: If9755fe8e1f9252e6e77e22fe910964ad3c3743b
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.sourcearcade.org/c/libgfxinit/+/456
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: Nico Huber <nico.h@gmx.de>
diff --git a/common/hw-gfx-gma-config.ads.template b/common/hw-gfx-gma-config.ads.template
index 2c859c5..113bc10 100644
--- a/common/hw-gfx-gma-config.ads.template
+++ b/common/hw-gfx-gma-config.ads.template
@@ -337,7 +337,8 @@
      (Disabled       => False,
       eDP            => False,
       LVDS           => Gen_Ironlake,
-      DP1 .. HDMI3   => Gen_Ironlake,
+      DP1 .. DP3     => Gen_Ironlake,
+      HDMI1 .. HDMI3 => Gen_Ironlake,
       Analog         => Has_PCH_DAC,
       others         => False);
 
diff --git a/common/hw-gfx-gma-config_helpers.adb b/common/hw-gfx-gma-config_helpers.adb
index 3b55968..014d1b2 100644
--- a/common/hw-gfx-gma-config_helpers.adb
+++ b/common/hw-gfx-gma-config_helpers.adb
@@ -26,6 +26,12 @@
       Port : Active_Port_Type)
       return GPU_Port
    is
+      function Combo_PHY (Port : Port_Type) return GPU_Port is
+        (case Port is
+            when HDMI1 | DP1  => DIGI_A,
+            when HDMI2 | DP2  => DIGI_B,
+            when HDMI3 | DP3  => DIGI_C,
+            when others       => LVDS);   -- n/a, actually
    begin
       return
         (case Config.Gen is
@@ -54,18 +60,15 @@
                      when Secondary => DIGI_C,
                      when Tertiary  => DIGI_D)),
             when Tigerlake =>
-              (case Port is
-                  when eDP                   => DIGI_A,
-                  when HDMI1 | DP1           => DIGI_A,
-                  when HDMI2 | DP2           => DIGI_B,
-                  when HDMI3 | DP3           => DIGI_C,
-                  when USBC1_DP | USBC1_HDMI => DDI_TC1,
-                  when USBC2_DP | USBC2_HDMI => DDI_TC2,
-                  when USBC3_DP | USBC3_HDMI => DDI_TC3,
-                  when USBC4_DP | USBC4_HDMI => DDI_TC4,
-                  when USBC5_DP | USBC5_HDMI => DDI_TC5,
-                  when USBC6_DP | USBC6_HDMI => DDI_TC6,
-                  when others                => LVDS),    -- n/a, actually
+                 (case Port is
+                     when DP_TC1 | HDMI_TC1 | USBC1   => DDI_TC1,
+                     when DP_TC2 | HDMI_TC2 | USBC2   => DDI_TC2,
+                     when DP_TC3 | HDMI_TC3 | USBC3   => DDI_TC3,
+                     when DP_TC4 | HDMI_TC4 | USBC4   => DDI_TC4,
+                     when eDP =>
+                        Combo_PHY (Config.Panel_Ports (Panel_1)),
+                     when others =>
+                        Combo_PHY (Port)),
             when others =>             -- everything but VGA directly on CPU
               (case Port is
                   when LVDS         => LVDS,    -- n/a, actually
@@ -83,21 +86,20 @@
       return
         (if Config.Has_Type_C_Ports
          then
-           (case Port is
-               when HDMI1                 => PCH_HDMI_A,
-               when HDMI2                 => PCH_HDMI_B,
-               when HDMI3                 => PCH_HDMI_C,
-               when USBC1_HDMI | USBC1_DP => PCH_TC1,
-               when USBC2_HDMI | USBC2_DP => PCH_TC2,
-               when USBC3_HDMI | USBC3_DP => PCH_TC3,
-               when USBC4_HDMI | USBC4_DP => PCH_TC4,
-               when USBC5_HDMI | USBC5_DP => PCH_TC5,
-               when USBC6_HDMI | USBC6_DP => PCH_TC6,
-               when others                => PCH_LVDS)  -- n/a, actually
+           (case To_GPU_Port (Pipe_Index'First, Port) is
+               when DIGI_A    => PCH_HDMI_A,
+               when DIGI_B    => PCH_HDMI_B,
+               when DIGI_C    => PCH_HDMI_C,
+               when DDI_TC1   => PCH_TC1,
+               when DDI_TC2   => PCH_TC2,
+               when DDI_TC3   => PCH_TC3,
+               when DDI_TC4   => PCH_TC4,
+               when DDI_TC5   => PCH_TC5,
+               when DDI_TC6   => PCH_TC6,
+               when others    => PCH_LVDS)  -- n/a, actually
          else
            (case Port is
                when LVDS      => PCH_LVDS,
-               when eDP       => PCH_LVDS,   -- n/a, actually
                when Analog    => PCH_DAC,
                when HDMI1     => PCH_HDMI_B,
                when HDMI2     => PCH_HDMI_C,
@@ -113,15 +115,12 @@
    begin
       return Display_Type'
         (case Port is
-            when LVDS                                    => LVDS,
-            when eDP                                     => DP,
-            when Analog                                  => VGA,
-            when HDMI1 .. HDMI3                          => HDMI,
-            when DP1 .. DP3                              => DP,
-            when USBC1_DP | USBC2_DP | USBC3_DP |
-                 USBC4_DP | USBC5_DP | USBC6_DP          => DP,
-            when USBC1_HDMI | USBC2_HDMI | USBC3_HDMI |
-                 USBC4_HDMI | USBC5_HDMI | USBC6_HDMI    => HDMI);
+            when LVDS                        => LVDS,
+            when eDP                         => DP,
+            when Analog                      => VGA,
+            when Physical_HDMI_Ports'Range   => HDMI,
+            when Physical_DP_Ports'Range     => DP,
+            when Physical_USBC_Ports'Range   => DP);
    end To_Display_Type;
 
    function To_Panel (Port : Active_Port_Type) return Panel_Control
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index 92c6f5e..f8eab45 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -52,31 +52,31 @@
 is
    pragma Disable_Atomic_Synchronization;
 
-   subtype Port_Name is String (1 .. 10);
+   subtype Port_Name is String (1 .. 8);
    type Port_Name_Array is array (Port_Type) of Port_Name;
    Port_Names : constant Port_Name_Array :=
-     (Disabled   => "Disabled  ",
-      LVDS       => "LVDS      ",
-      eDP        => "eDP       ",
-      DP1        => "DP1       ",
-      DP2        => "DP2       ",
-      DP3        => "DP3       ",
-      HDMI1      => "HDMI1     ",
-      HDMI2      => "HDMI2     ",
-      HDMI3      => "HDMI3     ",
-      Analog     => "Analog    ",
-      USBC1_DP   => "USBC1-DP  ",
-      USBC2_DP   => "USBC2-DP  ",
-      USBC3_DP   => "USBC3-DP  ",
-      USBC4_DP   => "USBC4-DP  ",
-      USBC5_DP   => "USBC5-DP  ",
-      USBC6_DP   => "USBC6-DP  ",
-      USBC1_HDMI => "USBC1-HDMI",
-      USBC2_HDMI => "USBC2-HDMI",
-      USBC3_HDMI => "USBC3-HDMI",
-      USBC4_HDMI => "USBC4-HDMI",
-      USBC5_HDMI => "USBC5-HDMI",
-      USBC6_HDMI => "USBC6-HDMI");
+     (Disabled => "Disabled",
+      LVDS     => "LVDS    ",
+      eDP      => "eDP     ",
+      DP1      => "DP1     ",
+      DP2      => "DP2     ",
+      DP3      => "DP3     ",
+      DP_TC1   => "DP_TC1  ",
+      DP_TC2   => "DP_TC2  ",
+      DP_TC3   => "DP_TC3  ",
+      DP_TC4   => "DP_TC4  ",
+      HDMI1    => "HDMI1   ",
+      HDMI2    => "HDMI2   ",
+      HDMI3    => "HDMI3   ",
+      HDMI_TC1 => "HDMI_TC1",
+      HDMI_TC2 => "HDMI_TC2",
+      HDMI_TC3 => "HDMI_TC3",
+      HDMI_TC4 => "HDMI_TC4",
+      Analog   => "Analog  ",
+      USBC1    => "USBC1   ",
+      USBC2    => "USBC2   ",
+      USBC3    => "USBC3   ",
+      USBC4    => "USBC4   ");
 
    package Dev is new HW.PCI.Dev (PCI.Address'(0, 2, 0));
 
diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads
index c05f4f1..4771dbe 100644
--- a/common/hw-gfx-gma.ads
+++ b/common/hw-gfx-gma.ads
@@ -72,27 +72,28 @@
       DP1,
       DP2,
       DP3,
-      HDMI1, -- or DVI
-      HDMI2, -- or DVI
-      HDMI3, -- or DVI
+      DP_TC1,     -- DP_TC ports use Type-C lanes to
+      DP_TC2,     -- implement physical DP or DP++ ports.
+      DP_TC3,
+      DP_TC4,
+      HDMI1,      -- HDMI ports share lanes with their DP siblings.
+      HDMI2,      -- They can also be implemented as DVI.
+      HDMI3,
+      HDMI_TC1,   -- HDMI_TC use Type-C lanes to implement
+      HDMI_TC2,   -- physical HDMI, DVI or the HDMI part of DP++.
+      HDMI_TC3,
+      HDMI_TC4,
       Analog,
-      USBC1_DP,
-      USBC2_DP,
-      USBC3_DP,
-      USBC4_DP,
-      USBC5_DP,
-      USBC6_DP,
-      USBC1_HDMI,
-      USBC2_HDMI,
-      USBC3_HDMI,
-      USBC4_HDMI,
-      USBC5_HDMI,
-      USBC6_HDMI);
+      USBC1,      -- Type-C lanes used to implement
+      USBC2,      -- physical USB-C ports with DP Alt Mode.
+      USBC3,
+      USBC4);
    subtype Active_Port_Type is Port_Type
       range Port_Type'Succ (Disabled) .. Port_Type'Last;
    subtype Internal_Port_Type is Port_Type range LVDS .. eDP;
-   subtype Combo_Port_Type is Port_Type range DP1 .. HDMI3;
-   subtype USBC_Port_Type is Port_Type range USBC1_DP .. USBC6_HDMI;
+   subtype Physical_DP_Ports is Port_Type range DP1 .. DP_TC4;
+   subtype Physical_HDMI_Ports is Port_Type range HDMI1 .. HDMI_TC4;
+   subtype Physical_USBC_Ports is Port_Type range USBC1 .. USBC4;
 
    type Cursor_Mode is (No_Cursor, ARGB_Cursor);
    type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256);
diff --git a/configs/tigerlake b/configs/tigerlake
index e28e818..a24fb39 100644
--- a/configs/tigerlake
+++ b/configs/tigerlake
@@ -1,6 +1,6 @@
 CONFIG_GFX_GMA_DYN_CPU		= y
 CONFIG_GFX_GMA_GENERATION	= Tigerlake
 CONFIG_GFX_GMA_PCH		= Tiger_Point
-CONFIG_GFX_GMA_PANEL_1_PORT	= eDP
+CONFIG_GFX_GMA_PANEL_1_PORT	= DP1
 CONFIG_GFX_GMA_ANALOG_I2C_PORT	= PCH_DAC # N/A
 CONFIG_GFX_GMA_DEFAULT_MMIO	= 16\#e000_0000\#