gma hsw+: Add default value for HDMI buffer levels

Add a configuration option to override the default HDMI translation.
It's not exported yet, as we've never seen a non-default value being
used. So this is just to have a common place for the defaults.

Also sets the recommended default value for Broxton as defined in the
PRM.

Change-Id: I59fae0fb4f444d9193a98b6a0edf337ecbba3b62
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/20165
Tested-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
diff --git a/common/broxton/hw-gfx-gma-ddi_phy.ads b/common/broxton/hw-gfx-gma-ddi_phy.ads
index 98d0594..fc6cacf 100644
--- a/common/broxton/hw-gfx-gma-ddi_phy.ads
+++ b/common/broxton/hw-gfx-gma-ddi_phy.ads
@@ -38,7 +38,7 @@
      (Port        : Digital_Port;
       Train_Set   : DP_Info.Train_Set);
 
-   type HDMI_Buf_Trans_Range is range 0 .. 9;
+   subtype HDMI_Buf_Trans_Range is DDI_HDMI_Buf_Trans_Range range 0 .. 9;
    procedure Set_HDMI_Signal_Levels
      (Port  : DDI_Phy_Port;
       Level : HDMI_Buf_Trans_Range);
diff --git a/common/haswell_shared/hw-gfx-gma-connectors-ddi.adb b/common/haswell_shared/hw-gfx-gma-connectors-ddi.adb
index 4440376..a7c1b9e 100644
--- a/common/haswell_shared/hw-gfx-gma-connectors-ddi.adb
+++ b/common/haswell_shared/hw-gfx-gma-connectors-ddi.adb
@@ -507,10 +507,16 @@
             Port_Cfg.Display = HDMI and then
             Port_Cfg.Port in DDI_Phy.DDI_Phy_Port
          then
-            DDI_Phy.Set_HDMI_Signal_Levels
-              (Port  => Port_Cfg.Port,
-               Level => DDI_Phy.HDMI_Buf_Trans_Range'Last);
-            Success := True;
+            declare
+               HDMI_Level : constant DDI_Phy.HDMI_Buf_Trans_Range :=
+                 (if Config.DDI_HDMI_Buffer_Translation
+                     in DDI_Phy.HDMI_Buf_Trans_Range
+                  then Config.DDI_HDMI_Buffer_Translation
+                  else Config.Default_DDI_HDMI_Buffer_Translation);
+            begin
+               DDI_Phy.Set_HDMI_Signal_Levels (Port_Cfg.Port, HDMI_Level);
+               Success := True;
+            end;
          else
             Success := True;
          end if;
diff --git a/common/haswell_shared/hw-gfx-gma-ddi_phy_stub.ads b/common/haswell_shared/hw-gfx-gma-ddi_phy_stub.ads
index b37e955..6099c50 100644
--- a/common/haswell_shared/hw-gfx-gma-ddi_phy_stub.ads
+++ b/common/haswell_shared/hw-gfx-gma-ddi_phy_stub.ads
@@ -27,7 +27,7 @@
      (Port        : Digital_Port;
       Train_Set   : DP_Info.Train_Set) is null;
 
-   type HDMI_Buf_Trans_Range is range 0 .. 9;
+   subtype HDMI_Buf_Trans_Range is DDI_HDMI_Buf_Trans_Range;
    procedure Set_HDMI_Signal_Levels
      (Port  : DDI_Phy_Port;
       Level : HDMI_Buf_Trans_Range) is null;
diff --git a/common/hw-gfx-gma-config.ads.template b/common/hw-gfx-gma-config.ads.template
index 2bb916a..7d6806a 100644
--- a/common/hw-gfx-gma-config.ads.template
+++ b/common/hw-gfx-gma-config.ads.template
@@ -27,6 +27,8 @@
 
    EDP_Low_Voltage_Swing : constant Boolean := False;
 
+   DDI_HDMI_Buffer_Translation : constant Integer := -1;
+
    Default_MMIO_Base : constant := <<DEFAULT_MMIO_BASE>>;
 
    LVDS_Dual_Threshold : constant := 95_000_000;
@@ -206,6 +208,13 @@
 
    ----------------------------------------------------------------------------
 
+   Default_DDI_HDMI_Buffer_Translation : constant DDI_HDMI_Buf_Trans_Range :=
+     (case CPU is
+         when Broxton   => 8,
+         when others    => 0);
+
+   ----------------------------------------------------------------------------
+
    Default_CDClk_Freq : constant Frequency_Type :=
      (case CPU is
          when Ironlake     |
diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads
index 8d51960..c8fc398 100644
--- a/common/hw-gfx-gma.ads
+++ b/common/hw-gfx-gma.ads
@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2015-2016 secunet Security Networks AG
+-- Copyright (C) 2015-2017 secunet Security Networks AG
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -133,4 +133,8 @@
 
    type DP_Port is (DP_A, DP_B, DP_C, DP_D);
 
+   ----------------------------------------------------------------------------
+
+   subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11;
+
 end HW.GFX.GMA;