gma: Add Kaby Lake support

Including some weird Amber Lake Y parts that are treated like Kaby Lake
in Linux' i915.

Only differences to Skylake in the DDI output buffer tuning.

Change-Id: Ice05e07b016cebc7258a9790e38e079e63227a4b
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/libgfxinit/+/28763
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
diff --git a/common/hw-gfx-gma-config.ads.template b/common/hw-gfx-gma-config.ads.template
index 03b4e47..fc14a46 100644
--- a/common/hw-gfx-gma-config.ads.template
+++ b/common/hw-gfx-gma-config.ads.template
@@ -31,7 +31,7 @@
          when Ironlake  => Ivybridge,
          when Haswell   => Broadwell,
          when Broxton   => Broxton,
-         when Skylake   => Skylake);
+         when Skylake   => Kabylake);
    CPU_Var_Last : constant CPU_Variant :=
      (case Gen is
          when Haswell | Skylake  => ULX,
@@ -114,6 +114,8 @@
    CPU_Ivybridge     : <ilkbool> := Gen_Ironlake and then CPU = Ivybridge;
    CPU_Haswell       : <hswbool> := Gen_Haswell and then CPU = Haswell;
    CPU_Broadwell     : <hswbool> := Gen_Haswell and then CPU = Broadwell;
+   CPU_Skylake       : <sklbool> := Gen_Skylake and then CPU = Skylake;
+   CPU_Kabylake      : <sklbool> := Gen_Skylake and then CPU = Kabylake;
 
    Sandybridge_On    : <ilkbool> :=
      ((Gen_Ironlake and then CPU >= Sandybridge) or Haswell_On);
@@ -205,6 +207,7 @@
    Has_DDI_Buffer_Trans          : <genbool> := Haswell_On and not Has_DDI_PHYs;
    Has_Low_Voltage_Swing         : <genbool> := Broxton_On;
    Has_Iboost_Config             : <genbool> := Skylake_On;
+   Use_KBL_DDI_Buf_Trans         : <sklbool> := CPU_Kabylake;
 
    Need_DP_Aux_Mutex             : <genbool> := False; -- Skylake & (PSR | GTC)
 
@@ -257,7 +260,8 @@
 
    ----------------------------------------------------------------------------
 
-   DDI_Buffer_Iboost : <hswsklvar> Natural := (if Is_ULX then 3 else 1);
+   DDI_Buffer_Iboost : <hswsklvar> Natural :=
+     (if Is_ULX or (CPU_Kabylake and Is_ULT) then 3 else 1);
 
    Default_DDI_HDMI_Buffer_Translation : <hswvar> DDI_HDMI_Buf_Trans_Range :=
      (if    CPU_Haswell    then 6
@@ -378,6 +382,20 @@
       (Device_Id and 16#ffcf#) = 16#190b# or
       (Device_Id and 16#ffcf#) = 16#190d#);
 
+   function Is_Kaby_Lake_Y (Device_Id : Word16) return Boolean is
+     ((Device_Id and 16#ffcf#) = 16#5905# or
+      (Device_Id and 16#ffcf#) = 16#590e#);
+   function Is_Kaby_Lake_Y_AML (Device_Id : Word16) return Boolean is
+     (Device_Id = 16#591c# or Device_Id = 16#87c0#);
+   function Is_Kaby_Lake_U (Device_Id : Word16) return Boolean is
+     ((Device_Id and 16#ffcd#) = 16#5901# or
+      (Device_Id and 16#ffce#) = 16#5906#);
+   function Is_Kaby_Lake (Device_Id : Word16) return Boolean is
+     ((Device_Id and 16#ffc7#) = 16#5902# or
+      (Device_Id and 16#ffcf#) = 16#5908# or
+      (Device_Id and 16#ffcf#) = 16#590b# or
+      (Device_Id and 16#ffcf#) = 16#590d#);
+
    function Is_GPU (Device_Id : Word16; CPU : CPU_Type; CPU_Var : CPU_Variant)
       return Boolean is
      (case CPU is
@@ -398,7 +416,12 @@
          when Skylake      => (case CPU_Var is
                                  when Normal => Is_Skylake (Device_Id),
                                  when ULT    => Is_Skylake_U (Device_Id),
-                                 when ULX    => Is_Skylake_Y (Device_Id)));
+                                 when ULX    => Is_Skylake_Y (Device_Id)),
+         when Kabylake     => (case CPU_Var is
+                                 when Normal => Is_Kaby_Lake (Device_Id),
+                                 when ULT    => Is_Kaby_Lake_U (Device_Id),
+                                 when ULX    => Is_Kaby_Lake_Y (Device_Id) or
+                                                Is_Kaby_Lake_Y_AML (Device_Id)));
 
    function Compatible_GPU (Device_Id : Word16) return Boolean is
      (Is_GPU (Device_Id, CPU, CPU_Var));
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index 171d224..15d234a 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -405,7 +405,8 @@
          end case;
          Success :=
            ((Config.Gen_Broxton        and Audio_VID_DID = 16#8086_280a#) or
-            (Config.Gen_Skylake        and Audio_VID_DID = 16#8086_2809#) or
+            (Config.CPU_Kabylake       and Audio_VID_DID = 16#8086_280b#) or
+            (Config.CPU_Skylake        and Audio_VID_DID = 16#8086_2809#) or
             (Config.CPU_Broadwell      and Audio_VID_DID = 16#8086_2808#) or
             (Config.CPU_Haswell        and Audio_VID_DID = 16#8086_2807#) or
             ((Config.CPU_Ivybridge or
diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads
index 40382f8..b9c627b 100644
--- a/common/hw-gfx-gma.ads
+++ b/common/hw-gfx-gma.ads
@@ -43,7 +43,8 @@
       Haswell,
       Broadwell,
       Broxton,
-      Skylake);
+      Skylake,
+      Kabylake);
 
    type CPU_Variant is (Normal, ULT, ULX);
 
diff --git a/common/skylake/hw-gfx-gma-connectors-ddi-buffers.adb b/common/skylake/hw-gfx-gma-connectors-ddi-buffers.adb
index 6ab755b..4c5839e 100644
--- a/common/skylake/hw-gfx-gma-connectors-ddi-buffers.adb
+++ b/common/skylake/hw-gfx-gma-connectors-ddi-buffers.adb
@@ -99,6 +99,42 @@
       16#8000_5012#, 16#0000_00c0#,
       others => 0);
 
+   Kaby_Lake_Trans_DP : constant Buf_Trans_Array :=
+     (16#0000_2016#, 16#0000_00a0#,
+      16#0000_5012#, 16#0000_009b#,
+      16#0000_7011#, 16#0000_0088#,
+      16#8000_9010#, 16#0000_00c0#,
+      16#0000_2016#, 16#0000_009b#,
+      16#0000_5012#, 16#0000_0088#,
+      16#8000_7011#, 16#0000_00c0#,
+      16#0000_2016#, 16#0000_0097#,
+      16#8000_5012#, 16#0000_00c0#,
+      others => 0);
+
+   Kaby_Lake_U_Trans_DP : constant Buf_Trans_Array :=
+     (16#0000_201b#, 16#0000_00a1#,
+      16#0000_5012#, 16#0000_0088#,
+      16#8000_7011#, 16#0000_00cd#,
+      16#8000_9010#, 16#0000_00c0#,
+      16#0000_201b#, 16#0000_009d#,
+      16#8000_5012#, 16#0000_00c0#,
+      16#8000_7011#, 16#0000_00c0#,
+      16#0000_2016#, 16#0000_004f#,
+      16#8000_5012#, 16#0000_00c0#,
+      others => 0);
+
+   Kaby_Lake_Y_Trans_DP : constant Buf_Trans_Array :=
+     (16#0000_1017#, 16#0000_00a1#,
+      16#0000_5012#, 16#0000_0088#,
+      16#8000_7011#, 16#0000_00cd#,
+      16#8000_800f#, 16#0000_00c0#,
+      16#0000_1017#, 16#0000_009d#,
+      16#8000_5012#, 16#0000_00c0#,
+      16#8000_7011#, 16#0000_00c0#,
+      16#0000_1017#, 16#0000_004c#,
+      16#8000_5012#, 16#0000_00c0#,
+      others => 0);
+
    Skylake_Trans_HDMI : constant HDMI_Buf_Trans_Array :=
      ((16#0000_0018#, 16#0000_00ac#),
       (16#0000_5012#, 16#0000_009d#),
@@ -138,18 +174,18 @@
          else Config.Default_DDI_HDMI_Buffer_Translation);
    begin
       Trans :=
-        (if Config.Is_ULX then
-           (if DDIA_Low_Voltage_Swing
-            then Skylake_Y_Trans_EDP
-            else Skylake_Y_Trans_DP)
-         elsif Config.Is_ULT then
-           (if DDIA_Low_Voltage_Swing
-            then Skylake_U_Trans_EDP
-            else Skylake_U_Trans_DP)
+        (if DDIA_Low_Voltage_Swing then
+           (if    Config.Is_ULX  then Skylake_Y_Trans_EDP
+            elsif Config.Is_ULT  then Skylake_U_Trans_EDP
+                                 else Skylake_Trans_EDP)
+         elsif not Config.Use_KBL_DDI_Buf_Trans then
+           (if    Config.Is_ULX  then Skylake_Y_Trans_DP
+            elsif Config.Is_ULT  then Skylake_U_Trans_DP
+                                 else Skylake_Trans_DP)
          else
-           (if DDIA_Low_Voltage_Swing
-            then Skylake_Trans_EDP
-            else Skylake_Trans_DP));
+           (if    Config.Is_ULX  then Kaby_Lake_Y_Trans_DP
+            elsif Config.Is_ULT  then Kaby_Lake_U_Trans_DP
+                                 else Kaby_Lake_Trans_DP));
       if not DDIA_Low_Voltage_Swing then
          if Config.Is_ULX then
             Trans (18) := Skylake_Y_Trans_HDMI (HDMI_Trans).Trans1;