meta-quanta: gbs: add i2cool temperature calibration

Do i2cool temperature calibration by phosphor-virtual-sensor

Also, as the phosphor-virtual-sensor generate the same D-Bus path,
chage the sensor name in hwmon to avoid the duplicate D-Bus path

Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: I334222da51f33256cf921ee0f3965bf2b607c345
diff --git a/meta-gbs/recipes-phosphor/images/obmc-phosphor-image.bbappend b/meta-gbs/recipes-phosphor/images/obmc-phosphor-image.bbappend
index 3b83932..27c3c9f 100644
--- a/meta-gbs/recipes-phosphor/images/obmc-phosphor-image.bbappend
+++ b/meta-gbs/recipes-phosphor/images/obmc-phosphor-image.bbappend
@@ -21,3 +21,4 @@
 OBMC_IMAGE_EXTRA_INSTALL_append_gbs = " phosphor-ipmi-blobs-binarystore"
 OBMC_IMAGE_EXTRA_INSTALL_append_gbs = " gbs-nvme-pwr-ctrl"
 OBMC_IMAGE_EXTRA_INSTALL_append_gbs = " read-margin-temp"
+OBMC_IMAGE_EXTRA_INSTALL_append_gbs = " phosphor-virtual-sensor"
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@0/max31725@54.conf b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@0/max31725@54.conf
index 839a7c6..1e3f5f3 100644
--- a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@0/max31725@54.conf
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@0/max31725@54.conf
@@ -1,8 +1,4 @@
-LABEL_temp1 = "i2cool_0"
-CRITHI_temp1 = "35000"
-CRITLO_temp1 = "0"
-WARNHI_temp1 = "35000"
-WARNLO_temp1 = "0"
+LABEL_temp1 = "inlet"
 MINVALUE_temp1 = "-128"
 MAXVALUE_temp1 = "127"
 ASYNC_READ_TIMEOUT_temp1 = "500"
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@1/max31725@55.conf b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@1/max31725@55.conf
index 174c62b..d13bfab 100644
--- a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@1/max31725@55.conf
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@1/max31725@55.conf
@@ -1,8 +1,4 @@
-LABEL_temp1 = "i2cool_1"
-CRITHI_temp1 = "70000"
-CRITLO_temp1 = "0"
-WARNHI_temp1 = "70000"
-WARNLO_temp1 = "0"
+LABEL_temp1 = "outlet_0"
 MINVALUE_temp1 = "-128"
 MAXVALUE_temp1 = "127"
 ASYNC_READ_TIMEOUT_temp1 = "500"
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@2/max31725@5d.conf b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@2/max31725@5d.conf
index 3fb0cee..e8bcd69 100644
--- a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@2/max31725@5d.conf
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/obmc/hwmon/ahb/apb/i2c@85000/i2c-switch@71/i2c@2/max31725@5d.conf
@@ -1,8 +1,4 @@
-LABEL_temp1 = "i2cool_2"
-CRITHI_temp1 = "70000"
-CRITLO_temp1 = "0"
-WARNHI_temp1 = "70000"
-WARNLO_temp1 = "0"
+LABEL_temp1 = "outlet_1"
 MINVALUE_temp1 = "-128"
 MAXVALUE_temp1 = "127"
 ASYNC_READ_TIMEOUT_temp1 = "500"
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor/config-virtual-sensor.json b/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor/config-virtual-sensor.json
new file mode 100644
index 0000000..6e72910
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor/config-virtual-sensor.json
@@ -0,0 +1,123 @@
+[
+    {
+        "Desc": {
+            "Name": "i2cool_0",
+            "SensorType": "temperature"
+        },
+        "Threshold": {
+            "CriticalHigh": 35,
+            "CriticalLow": 0,
+            "WarningHigh": 35,
+            "WarningLow": 0
+        },
+        "Params": {
+            "DbusParam": [
+                {
+                    "ParamName": "inlet",
+                    "Desc": {
+                        "Name": "inlet",
+                        "SensorType": "temperature"
+                    }
+                },
+                {
+                    "ParamName": "fan0",
+                    "Desc": {
+                        "Name": "fan0",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan1",
+                    "Desc": {
+                        "Name": "fan1",
+                        "SensorType": "fan_tach"
+                    }
+                }
+            ]
+        },
+        "Expression": "round(inlet - 1 - (1.8 * 3700 / avg(fan0, fan1)))"
+    },
+    {
+        "Desc": {
+            "Name": "i2cool_1",
+            "SensorType": "temperature"
+        },
+        "Threshold": {
+            "CriticalHigh": 70,
+            "CriticalLow": 0,
+            "WarningHigh": 70,
+            "WarningLow": 0
+        },
+        "Params": {
+            "DbusParam": [
+                {
+                    "ParamName": "outlet_0",
+                    "Desc": {
+                        "Name": "outlet_0",
+                        "SensorType": "temperature"
+                    }
+                },
+                {
+                    "ParamName": "fan0",
+                    "Desc": {
+                        "Name": "fan0",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan1",
+                    "Desc": {
+                        "Name": "fan1",
+                        "SensorType": "fan_tach"
+                    }
+                }
+            ]
+        },
+        "Expression": "round(outlet_0 - if(avg(fan0, fan1) >= 7400, 3 * 9558 / avg(fan0, fan1), 7 * 3700 / avg(fan0, fan1) - 2))"
+    },
+    {
+        "Desc": {
+            "Name": "i2cool_2",
+            "SensorType": "temperature"
+        },
+        "Threshold": {
+            "CriticalHigh": 70,
+            "CriticalLow": 0,
+            "WarningHigh": 70,
+            "WarningLow": 0
+        },
+        "Params": {
+            "DbusParam": [
+                {
+                    "ParamName": "outlet_1",
+                    "Desc": {
+                        "Name": "outlet_1",
+                        "SensorType": "temperature"
+                    }
+                },
+                {
+                    "ParamName": "fb_fan0",
+                    "Desc": {
+                        "Name": "fb_fan0",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fb_fan1",
+                    "Desc": {
+                        "Name": "fb_fan1",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fb_fan2",
+                    "Desc": {
+                        "Name": "fb_fan2",
+                        "SensorType": "fan_tach"
+                    }
+                }
+            ]
+        },
+        "Expression": "round(outlet_1 - if(avg(fb_fan0, fb_fan1, fb_fan2) >= 7400, 1 * 9558 / avg(fb_fan0, fb_fan1, fb_fan2), 1))"
+    }
+]
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor/phosphor-virtual-sensor.service.replace b/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor/phosphor-virtual-sensor.service.replace
new file mode 100644
index 0000000..8068d3b
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor/phosphor-virtual-sensor.service.replace
@@ -0,0 +1,16 @@
+[Unit]
+Description=Virtual sensors
+Wants=obmc-mapper.target
+After=obmc-mapper.target
+
+[Service]
+ExecStartPre=mapper wait /xyz/openbmc_project/sensors/temperature/inlet
+ExecStartPre=mapper wait /xyz/openbmc_project/sensors/temperature/outlet_0
+ExecStartPre=mapper wait /xyz/openbmc_project/sensors/temperature/outlet_1
+ExecStart=/usr/bin/virtual-sensor
+Type=dbus
+BusName=xyz.openbmc_project.VirtualSensor
+SyslogIdentifier=phosphor-virtual-sensor
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor_%.bbappend b/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor_%.bbappend
new file mode 100644
index 0000000..aadafeb
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-virtual-sensor_%.bbappend
@@ -0,0 +1,15 @@
+FILESEXTRAPATHS_prepend_gbs := "${THISDIR}/${PN}:"
+
+SRC_URI_append_gbs = " file://config-virtual-sensor.json \
+                       file://phosphor-virtual-sensor.service.replace \
+                     "
+
+do_install_append_gbs() {
+    install -d ${D}${datadir}/${PN}
+    install -m 0644 -D ${WORKDIR}/config-virtual-sensor.json \
+        ${D}${datadir}/${PN}/virtual_sensor_config.json
+
+    install -d ${D}${systemd_system_unitdir}
+    install -m 0644 ${WORKDIR}/${PN}.service.replace \
+        ${D}${systemd_system_unitdir}/${PN}.service
+}