meta-bletchley: enable phosphor-pid-control

Enable fan control and apply configuration R02

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: Ie075960623335f9a5800a137c4660439b0b930cd
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/fans/phosphor-pid-control/config.json b/meta-facebook/meta-bletchley/recipes-phosphor/fans/phosphor-pid-control/config.json
new file mode 100644
index 0000000..8ba3e22
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/fans/phosphor-pid-control/config.json
@@ -0,0 +1,238 @@
+{
+    "version": "R02",
+    "sensors": [
+        {
+            "name": "FAN0_TACH_IL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN0_TACH_IL",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/1e610000.pwm_tach/1e610000.pwm_tach:pwm/consumer:platform:pwm-fan0/consumer/hwmon/**/pwm1",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN0_TACH_OL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN0_TACH_OL",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN1_TACH_IL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN1_TACH_IL",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/1e610000.pwm_tach/1e610000.pwm_tach:pwm/consumer:platform:pwm-fan1/consumer/hwmon/**/pwm1",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN1_TACH_OL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN1_TACH_OL",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN2_TACH_IL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN2_TACH_IL",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/1e610000.pwm_tach/1e610000.pwm_tach:pwm/consumer:platform:pwm-fan2/consumer/hwmon/**/pwm1",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN2_TACH_OL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN2_TACH_OL",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN3_TACH_IL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN3_TACH_IL",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/1e610000.pwm_tach/1e610000.pwm_tach:pwm/consumer:platform:pwm-fan3/consumer/hwmon/**/pwm1",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "FAN3_TACH_OL",
+            "type": "fan",
+            "readPath": "/xyz/openbmc_project/sensors/fan_tach/FAN3_TACH_OL",
+            "min": 0,
+            "max": 255
+        },
+        {
+            "name": "Virtual_Inlet_Temp",
+            "type": "temp",
+            "readPath": "/xyz/openbmc_project/sensors/temperature/Virtual_Inlet_Temp",
+            "writePath": "",
+            "min": 0,
+            "max": 0,
+            "ignoreDbusMinMax": true,
+            "timeout": 0
+        },
+        {
+            "name": "MB_U19_THERM_LOCAL",
+            "type": "temp",
+            "readPath": "/xyz/openbmc_project/sensors/temperature/MB_U19_THERM_LOCAL",
+            "writePath": "",
+            "min": 0,
+            "max": 0,
+            "ignoreDbusMinMax": true,
+            "timeout": 0
+        },
+        {
+            "name": "MB_U402_THERM_LOCAL",
+            "type": "temp",
+            "readPath": "/xyz/openbmc_project/sensors/temperature/MB_U402_THERM_LOCAL",
+            "writePath": "",
+            "min": 0,
+            "max": 0,
+            "ignoreDbusMinMax": true,
+            "timeout": 0
+        }
+    ],
+    "zones": [
+        {
+            "id": 1,
+            "minThermalOutput": 0.0,
+            "failsafePercent": 75.0,
+            "pids": [
+                {
+                    "name": "fan_tachs",
+                    "type": "fan",
+                    "inputs": [
+                        "FAN0_TACH_IL",
+                        "FAN0_TACH_OL",
+                        "FAN1_TACH_IL",
+                        "FAN1_TACH_OL",
+                        "FAN2_TACH_IL",
+                        "FAN2_TACH_OL",
+                        "FAN3_TACH_IL",
+                        "FAN3_TACH_OL"
+                    ],
+                    "setpoint": 0.0,
+                    "pid": {
+                        "samplePeriod": 1.0,
+                        "proportionalCoeff": 0.0,
+                        "integralCoeff": 0.0,
+                        "feedFwdOffsetCoeff": 0.0,
+                        "feedFwdGainCoeff": 1.0,
+                        "integralLimit_min": 0.0,
+                        "integralLimit_max": 0.0,
+                        "outLim_min": 0.0,
+                        "outLim_max": 100.0,
+                        "slewNeg": 0.0,
+                        "slewPos": 0.0
+                    }
+                },
+                {
+                    "name": "inlet_Temp",
+                    "type": "stepwise",
+                    "inputs": [
+                        "Virtual_Inlet_Temp"
+                    ],
+                    "setpoint": 10.0,
+                    "pid": {
+                        "samplePeriod": 1.0,
+                        "positiveHysteresis": 1.0,
+                        "negativeHysteresis": 3.0,
+                        "isCeiling": false,
+                        "reading": {
+                            "0": 10.0,
+                            "1": 15.0,
+                            "2": 17.0,
+                            "3": 18.0,
+                            "4": 20.0,
+                            "5": 21.0,
+                            "6": 23.0,
+                            "7": 25.0,
+                            "8": 26.0,
+                            "9": 28.0,
+                            "10": 30.0,
+                            "11": 31.0,
+                            "12": 33.0,
+                            "13": 35.0,
+                            "14": 37.0,
+                            "15": 40.0
+                        },
+                        "output": {
+                            "0": 15.0,
+                            "1": 15.0,
+                            "2": 15.0,
+                            "3": 15.0,
+                            "4": 15.0,
+                            "5": 15.0,
+                            "6": 15.0,
+                            "7": 20.0,
+                            "8": 20.0,
+                            "9": 20.0,
+                            "10": 25.0,
+                            "11": 25.0,
+                            "12": 25.0,
+                            "13": 30.0,
+                            "14": 30.0,
+                            "15": 30.0
+                        }
+                    }
+                },
+                {
+                    "name": "switch_temp",
+                    "type": "stepwise",
+                    "inputs": [
+                        "MB_U402_THERM_LOCAL"
+                    ],
+                    "setpoint": 45.0,
+                    "pid": {
+                        "samplePeriod": 1.0,
+                        "positiveHysteresis": 1.0,
+                        "negativeHysteresis": 1.0,
+                        "isCeiling": false,
+                        "reading": {
+                            "0": 49.0,
+                            "1": 50.0,
+                            "2": 51.0
+                        },
+                        "output": {
+                            "0": 15.0,
+                            "1": 20.0,
+                            "2": 25.0
+                        }
+                    }
+                },
+                {
+                    "name": "retimer_temp",
+                    "type": "stepwise",
+                    "inputs": [
+                        "MB_U19_THERM_LOCAL"
+                    ],
+                    "setpoint": 45.0,
+                    "pid": {
+                        "samplePeriod": 1.0,
+                        "positiveHysteresis": 1.0,
+                        "negativeHysteresis": 1.0,
+                        "isCeiling": false,
+                        "reading": {
+                            "0": 49.0,
+                            "1": 50.0,
+                            "2": 51.0,
+                            "3": 52.0,
+                            "4": 53.0,
+                            "5": 54.0,
+                            "6": 55.0
+                        },
+                        "output": {
+                            "0": 19.0,
+                            "1": 20.0,
+                            "2": 21.0,
+                            "3": 22.0,
+                            "4": 23.0,
+                            "5": 24.0,
+                            "6": 25.0
+                        }
+                    }
+                }
+            ]
+        }
+    ]
+}
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/fans/phosphor-pid-control_%.bbappend b/meta-facebook/meta-bletchley/recipes-phosphor/fans/phosphor-pid-control_%.bbappend
new file mode 100644
index 0000000..3312ea9
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/fans/phosphor-pid-control_%.bbappend
@@ -0,0 +1,17 @@
+FILESEXTRAPATHS:prepend:bletchley := "${THISDIR}/${PN}:"
+SRC_URI:append:bletchley = " \
+                            file://config.json \
+                           "
+
+FILES:${PN}:append:bletchley = " ${datadir}/swampd/config.json"
+
+do_install:append:bletchley() {
+    # Insert service dependencies
+    sed -i '/^\[Unit\]/a After=xyz.openbmc_project.hwmontempsensor.service' \
+        ${D}${systemd_system_unitdir}/phosphor-pid-control.service
+    sed -i '/^\[Unit\]/a After=phosphor-virtual-sensor.service' \
+        ${D}${systemd_system_unitdir}/phosphor-pid-control.service
+
+    install -d ${D}${datadir}/swampd
+    install -m 0644 -D ${WORKDIR}/config.json ${D}${datadir}/swampd/
+}