gma config_helpers: Add dot-clock helper functions

Highest_Dotclock() returns the highest dot clock in a set of
pipe configurations.

Limit_Dotclocks() reduces any dot clock to the given maximum
if it exceeds the latter. To prove that Limit_Dotclocks() only
changes timing, we introduce Stable_FB().

Change-Id: Iaa25e774d38c7af12150523739d902cf8e758674
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/libgfxinit/+/35529
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/common/hw-gfx-gma-config_helpers.adb b/common/hw-gfx-gma-config_helpers.adb
index c95bebc..162c9c6 100644
--- a/common/hw-gfx-gma-config_helpers.adb
+++ b/common/hw-gfx-gma-config_helpers.adb
@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2015-2016 secunet Security Networks AG
+-- Copyright (C) 2015-2016, 2019 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
@@ -80,6 +80,33 @@
             when DP1 .. DP3      => DP);
    end To_Display_Type;
 
+   function Highest_Dotclock (Configs : Pipe_Configs) return Frequency_Type
+   is
+      Max : Frequency_Type := Frequency_Type'First;
+   begin
+      for I in Pipe_Index loop
+         if Configs (I).Port /= Disabled and
+            Max < Configs (I).Mode.Dotclock
+         then
+            Max := Configs (I).Mode.Dotclock;
+         end if;
+      end loop;
+      return Max;
+   end Highest_Dotclock;
+
+   procedure Limit_Dotclocks
+     (Configs  : in out Pipe_Configs;
+      Max      : in     Frequency_Type) is
+   begin
+      for I in Pipe_Index loop
+         if Configs (I).Port /= Disabled and
+            Max < Configs (I).Mode.Dotclock
+         then
+            Configs (I).Mode.Dotclock := Max;
+         end if;
+      end loop;
+   end Limit_Dotclocks;
+
    ----------------------------------------------------------------------------
 
    -- Prepares link rate and lane count settings for an FDI connection.