control:p10bmc:rainier2u: Enable floor altitude offsets

Instead of having a static floor for different altitude ranges, have the
altitude provide an offset to the chosen floor per ambient range. This
allows the thermal team to define the floors per ambient for a baseline
altitude point and then offset those floors by a set amount for some set
of difference in altitude from their baseline.

Included in this change, the altitude continues to be updated in fan
control when the fan control app starts and at any point it is added to
dbus, however it's now refreshed every 24hrs instead of thru properties
changed signals.

Change-Id: I2fc404849130633a927073aa440425b199a30909
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/config_files/p10bmc/ibm,rainier-2u/events.json b/control/config_files/p10bmc/ibm,rainier-2u/events.json
index d2f4c11..ec15299 100644
--- a/control/config_files/p10bmc/ibm,rainier-2u/events.json
+++ b/control/config_files/p10bmc/ibm,rainier-2u/events.json
@@ -1309,14 +1309,113 @@
      ]
    },
    {
+     "name": "Set altitude offset parameter",
+     "groups": [
+       {
+         "name": "altitude",
+         "interface": "xyz.openbmc_project.Sensor.Value",
+         "property": { "name": "Value" }
+       }
+     ],
+     "triggers": [
+       {
+         "class": "init",
+         "method": "get_properties"
+       },
+       {
+         "class": "signal",
+         "signal": "interfaces_added"
+       },
+       {
+         // Refresh altitude every 24hrs
+         "class": "timer",
+         "type": "repeating",
+         "interval": 86400000000,
+         "preload_groups": true
+       }
+     ],
+     "actions": [
+       {
+         "name": "set_parameter_from_group_max",
+         "parameter_name": "ambient_20_altitude_offset",
+         "modifier": {
+           "operator": "less_than",
+           "value": [
+             { "arg_value": 500, "parameter_value": 0 },
+             { "arg_value": 1000, "parameter_value": 800 },
+             { "arg_value": 1500, "parameter_value": 1600 },
+             { "arg_value": 2000, "parameter_value": 2400 },
+             { "arg_value": 2500, "parameter_value": 3200 },
+             { "arg_value": 3000, "parameter_value": 4000 }
+           ]
+         }
+       },
+       {
+         "name": "set_parameter_from_group_max",
+         "parameter_name": "ambient_25_altitude_offset",
+         "modifier": {
+           "operator": "less_than",
+           "value": [
+             { "arg_value": 500, "parameter_value": 0 },
+             { "arg_value": 1000, "parameter_value": 900 },
+             { "arg_value": 1500, "parameter_value": 1800 },
+             { "arg_value": 2000, "parameter_value": 2700 },
+             { "arg_value": 2500, "parameter_value": 3600 },
+             { "arg_value": 3000, "parameter_value": 4400 }
+           ]
+         }
+       },
+       {
+         "name": "set_parameter_from_group_max",
+         "parameter_name": "ambient_30_altitude_offset",
+         "modifier": {
+           "operator": "less_than",
+           "value": [
+             { "arg_value": 500, "parameter_value": 0 },
+             { "arg_value": 1000, "parameter_value": 800 },
+             { "arg_value": 1500, "parameter_value": 1600 },
+             { "arg_value": 2000, "parameter_value": 2400 },
+             { "arg_value": 2500, "parameter_value": 3200 },
+             { "arg_value": 3000, "parameter_value": 4000 }
+           ]
+         }
+       },
+       {
+         "name": "set_parameter_from_group_max",
+         "parameter_name": "ambient_35_altitude_offset",
+         "modifier": {
+           "operator": "less_than",
+           "value": [
+             { "arg_value": 500, "parameter_value": 0 },
+             { "arg_value": 1000, "parameter_value": 900 },
+             { "arg_value": 1500, "parameter_value": 1800 },
+             { "arg_value": 2000, "parameter_value": 2700 },
+             { "arg_value": 2500, "parameter_value": 3600 },
+             { "arg_value": 3000, "parameter_value": 4400 }
+           ]
+         }
+       },
+       {
+         "name": "set_parameter_from_group_max",
+         "parameter_name": "ambient_40_altitude_offset",
+         "modifier": {
+           "operator": "less_than",
+           "value": [
+             { "arg_value": 500, "parameter_value": 0 },
+             { "arg_value": 1000, "parameter_value": 900 },
+             { "arg_value": 1500, "parameter_value": 1800 },
+             { "arg_value": 2000, "parameter_value": 2700 },
+             { "arg_value": 2500, "parameter_value": 3600 },
+             { "arg_value": 3000, "parameter_value": 4400 }
+           ]
+         }
+       }
+     ]
+   },
+   {
      "name": "Fan floors",
      "groups": [
       {
-        "name": "altitude",
-        "interface": "xyz.openbmc_project.Sensor.Value",
-        "property": { "name": "Value" }
-      },
-      {
         "name": "ambient temp",
         "interface": "xyz.openbmc_project.Sensor.Value",
         "property": { "name": "Value" }
@@ -1338,6 +1437,26 @@
        {
          "class": "parameter",
          "parameter": "pcie_floor_index"
+       },
+       {
+         "class": "parameter",
+         "parameter": "ambient_20_altitude_offset"
+       },
+       {
+         "class": "parameter",
+         "parameter": "ambient_25_altitude_offset"
+       },
+       {
+         "class": "parameter",
+         "parameter": "ambient_30_altitude_offset"
+       },
+       {
+         "class": "parameter",
+         "parameter": "ambient_35_altitude_offset"
+       },
+       {
+         "class": "parameter",
+         "parameter": "ambient_40_altitude_offset"
        }
      ],
      "actions": [
@@ -1348,6 +1467,8 @@
           {
             // Entry valid for temps < 20
             "key": 20,
+            "default_floor": 6200,
+            "floor_offset_parameter": "ambient_20_altitude_offset",
             "floors": [
               {
                 "parameter": "pcie_floor_index",
@@ -1358,20 +1479,14 @@
                   { "value": 4, "floor": 9800 },
                   { "value": 5, "floor": 11300 }
                 ]
-              },
-              {
-                "group": "altitude",
-                "floors": [
-                  { "value": 900, "floor": 6200 },
-                  { "value": 1800, "floor": 8500 },
-                  { "value": 3050, "floor": 10500 }
-                ]
               }
             ]
           },
           {
             // Entry valid for temps < 25
             "key": 25,
+            "default_floor": 7500,
+            "floor_offset_parameter": "ambient_25_altitude_offset",
             "floors": [
               {
                 "parameter": "pcie_floor_index",
@@ -1382,20 +1497,14 @@
                   { "value": 4, "floor": 13500 },
                   { "value": 5, "floor": 14900 }
                 ]
-              },
-              {
-                "group": "altitude",
-                "floors": [
-                  { "value": 900, "floor": 7500 },
-                  { "value": 1800, "floor": 10000 },
-                  { "value": 3050, "floor": 12500 }
-                ]
               }
             ]
           },
           {
             // Entry valid for temps < 30
             "key": 30,
+            "default_floor": 10000,
+            "floor_offset_parameter": "ambient_30_altitude_offset",
             "floors": [
               {
                 "parameter": "pcie_floor_index",
@@ -1406,20 +1515,14 @@
                   { "value": 4, "floor": 17300 },
                   { "value": 5, "floor": 18000 }
                 ]
-              },
-              {
-                "group": "altitude",
-                "floors": [
-                  { "value": 900, "floor": 10000 },
-                  { "value": 1800, "floor": 12500 },
-                  { "value": 3050, "floor": 15000 }
-                ]
               }
             ]
           },
           {
             // Entry valid for temps < 35
             "key": 35,
+            "default_floor": 12500,
+            "floor_offset_parameter": "ambient_35_altitude_offset",
             "floors": [
               {
                 "parameter": "pcie_floor_index",
@@ -1430,20 +1533,14 @@
                   { "value": 4, "floor": 18000 },
                   { "value": 5, "floor": 18000 }
                 ]
-              },
-              {
-                "group": "altitude",
-                "floors": [
-                  { "value": 900, "floor": 12500 },
-                  { "value": 1800, "floor": 15000 },
-                  { "value": 3050, "floor": 18000 }
-                ]
               }
             ]
           },
           {
             // Entry valid for temps < 40
             "key": 40,
+            "default_floor": 15000,
+            "floor_offset_parameter": "ambient_40_altitude_offset",
             "floors": [
               {
                 "parameter": "pcie_floor_index",
@@ -1454,14 +1551,6 @@
                   { "value": 4, "floor": 18000 },
                   { "value": 5, "floor": 18000 }
                 ]
-              },
-              {
-                "group": "altitude",
-                "floors": [
-                  { "value": 900, "floor": 15000 },
-                  { "value": 1800, "floor": 18000 },
-                  { "value": 3050, "floor": 18000 }
-                ]
               }
             ]
           }