meta-quanta: gbs: fix sensor value type and hwmon patch issues

Since the sensor value type had been changed to double, we have to
modify the sensor value type to double and remove the scale in sensor
YAML config and also update the patch for hwmon fix for this changing

Change sensor type to double:
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-dbus-interfaces/+/11739

hwmon fixes for the sensor type changing:
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-hwmon/+/34481
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-hwmon/+/34983

Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: Ia538957f1cfc47f9460ad09029f3fe3c38d69213
diff --git a/meta-gbs/recipes-phosphor/configuration/gbs-yaml-config/gbs-ipmi-sensors.yaml b/meta-gbs/recipes-phosphor/configuration/gbs-yaml-config/gbs-ipmi-sensors.yaml
index 6747280..63d4e6c 100644
--- a/meta-gbs/recipes-phosphor/configuration/gbs-yaml-config/gbs-ipmi-sensors.yaml
+++ b/meta-gbs/recipes-phosphor/configuration/gbs-yaml-config/gbs-ipmi-sensors.yaml
@@ -8,7 +8,6 @@
   offsetB: 0
   bExp: 0
   rExp: 0
-  scale: -3
   unit: xyz.openbmc_project.Sensor.Value.Unit.DegreesC
   mutability: Mutability::Write|Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
@@ -19,7 +18,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 0x11:
   <<: *temperature
@@ -59,7 +58,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 0x16:
   <<: *nvme_temperature
@@ -159,7 +158,6 @@
   offsetB: 0
   bExp: 0
   rExp: -4
-  scale: -3
   unit: xyz.openbmc_project.Sensor.Value.Unit.Volts
   mutability: Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
@@ -170,7 +168,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 0x31:
   <<: *voltage
@@ -273,7 +271,6 @@
   offsetB: 0
   bExp: 0
   unit: xyz.openbmc_project.Sensor.Value.Unit.Volts
-  scale: -3
   rExp: -3
   mutability: Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
@@ -283,7 +280,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 0x3D:
   <<: *voltage
@@ -300,7 +297,6 @@
   sensorReadingType: 0x01
   multiplierM: 78
   rExp: -3
-  scale: -3
   unit: xyz.openbmc_project.Sensor.Value.Unit.Amperes
   mutability: Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
@@ -311,7 +307,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 0x51:
   <<: *current
@@ -500,7 +496,6 @@
   offsetB: 0
   bExp: 0
   rExp: -1
-  scale: -6
   unit: xyz.openbmc_project.Sensor.Value.Unit.Watts
   mutability: Mutability::Write|Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
@@ -511,7 +506,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 # fan/pwm mapping
 # fan0/1 on Mobo, fb_fan0/1/2 on fan board
@@ -530,7 +525,6 @@
   offsetB: 0
   bExp: 0
   rExp: 0
-  scale: 0
   unit: xyz.openbmc_project.Sensor.Value.Unit.RPMS
   mutability: Mutability::Write|Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
@@ -541,7 +535,7 @@
       Value:
         Offsets:
           0xFF:
-            type: int64_t
+            type: double
 
 0x61:
   <<: *fan_rpm_read
@@ -580,7 +574,7 @@
       Target:
         Offsets:
           0xFF:
-            type: uint64_t
+            type: double
 
 0x66:
   <<: *fan_pwm
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0001-lev-add-poweron-monitor-feature.patch b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0001-lev-add-poweron-monitor-feature.patch
index dfe82ef..c279e0b 100644
--- a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0001-lev-add-poweron-monitor-feature.patch
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0001-lev-add-poweron-monitor-feature.patch
@@ -1,18 +1,18 @@
-From 58eec8f1f80e274ff669bd19c00b8f1ea8ceae0f Mon Sep 17 00:00:00 2001
-From: Duke Du <Duke.Du@quantatw.com>
-Date: Mon, 18 May 2020 19:45:27 +0800
-Subject: [PATCH] lev-add-poweron-monitor-feature
+From 2cea5d289b278db4468b16bf6b64102655811fd0 Mon Sep 17 00:00:00 2001
+From: Eddielu <Eddie.Lu@quantatw.com>
+Date: Mon, 27 Jul 2020 20:30:22 +0800
+Subject: [PATCH] Update lev-add-poweron-monitor-feature patch.
 
 ---
  Makefile.am    |   2 ++
- mainloop.cpp   | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ mainloop.cpp   | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  sensor.cpp     |  11 ++++++-
  sensor.hpp     |  13 ++++++++
  thresholds.hpp |   2 --
- 5 files changed, 126 insertions(+), 3 deletions(-)
+ 5 files changed, 127 insertions(+), 3 deletions(-)
 
 diff --git a/Makefile.am b/Makefile.am
-index 378c565..5fa230a 100644
+index 706a6cc..c620fa4 100644
 --- a/Makefile.am
 +++ b/Makefile.am
 @@ -46,6 +46,7 @@ libhwmon_la_LIBADD = \
@@ -22,8 +22,8 @@
 +	$(PTHREAD_LIBS) \
  	$(GPIOPLUS_LIBS) \
  	$(STDPLUS_LIBS) \
- 	$(CODE_COVERAGE_LIBS)
-@@ -54,6 +55,7 @@ libhwmon_la_CXXFLAGS = \
+ 	$(CODE_COVERAGE_LIBS) \
+@@ -55,6 +56,7 @@ libhwmon_la_CXXFLAGS = \
  	$(SDEVENTPLUS_CFLAGS) \
  	$(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
  	$(PHOSPHOR_LOGGING_CFLAGS) \
@@ -32,10 +32,10 @@
  	$(CODE_COVERAGE_CXXFLAGS)
  
 diff --git a/mainloop.cpp b/mainloop.cpp
-index bd334a0..1769e94 100644
+index 3e7e0bf..4789a80 100644
 --- a/mainloop.cpp
 +++ b/mainloop.cpp
-@@ -39,6 +39,12 @@
+@@ -41,6 +41,12 @@
  #include <string>
  #include <unordered_set>
  #include <xyz/openbmc_project/Sensor/Device/error.hpp>
@@ -48,20 +48,20 @@
  
  using namespace phosphor::logging;
  
-@@ -74,6 +80,12 @@ decltype(
+@@ -76,6 +82,12 @@ decltype(
      Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi =
      &CriticalObject::criticalAlarmHigh;
  
 +static std::unique_ptr<phosphor::Timer> cacheTimer = nullptr;
 +static std::unique_ptr<sdbusplus::bus::match::match> powerMatch = nullptr;
 +static bool powerStatusOn = false;
-+static boost::asio::io_service io; 
++static boost::asio::io_service io;
 +static auto conn = std::make_shared<sdbusplus::asio::connection>(io);
 +
- void updateSensorInterfaces(InterfaceMap& ifaces, int64_t value)
+ void updateSensorInterfaces(InterfaceMap& ifaces, SensorValueType value)
  {
      for (auto& iface : ifaces)
-@@ -101,6 +113,83 @@ void updateSensorInterfaces(InterfaceMap& ifaces, int64_t value)
+@@ -103,6 +115,84 @@ void updateSensorInterfaces(InterfaceMap& ifaces, SensorValueType value)
      }
  }
  
@@ -134,18 +134,19 @@
 +            powerStatusOn =
 +                boost::ends_with(std::get<std::string>(state), "Running");
 +        },
-+        "xyz.openbmc_project.State.Host", 
-+	"/xyz/openbmc_project/state/host0", 
++        "xyz.openbmc_project.State.Host",
++	"/xyz/openbmc_project/state/host0",
 +	"org.freedesktop.DBus.Properties", "Get",
 +        "xyz.openbmc_project.State.Host", "CurrentHostState");
 +
 +    createTimer();
 +}
 +
++
  std::string MainLoop::getID(SensorSet::container_t::const_reference sensor)
  {
      std::string id;
-@@ -385,6 +474,7 @@ void MainLoop::init()
+@@ -384,6 +474,7 @@ void MainLoop::init()
              _interval = std::strtoull(interval.c_str(), NULL, 10);
          }
      }
@@ -153,7 +154,7 @@
  }
  
  void MainLoop::read()
-@@ -429,6 +519,12 @@ void MainLoop::read()
+@@ -428,6 +519,12 @@ void MainLoop::read()
  
          try
          {
@@ -166,23 +167,23 @@
              if (sensor->hasFaultFile())
              {
                  auto fault = _ioAccess->read(sensorSysfsType, sensorSysfsNum,
-@@ -491,6 +587,11 @@ void MainLoop::read()
+@@ -490,6 +587,11 @@ void MainLoop::read()
                  }
              }
  
 +            if(sensor->pwrOnMonitor() && !isPowerOn())
 +            {
 +		statusIface->functional(false);
-+	        continue;    
++	        continue;
 +            }
              updateSensorInterfaces(obj, value);
          }
          catch (const std::system_error& e)
 diff --git a/sensor.cpp b/sensor.cpp
-index 145ba6c..93bbb03 100644
+index 09aeca6..b1cb470 100644
 --- a/sensor.cpp
 +++ b/sensor.cpp
-@@ -41,7 +41,7 @@ Sensor::Sensor(const SensorSet::key_type& sensor,
+@@ -31,7 +31,7 @@ Sensor::Sensor(const SensorSet::key_type& sensor,
                 const hwmonio::HwmonIOInterface* ioAccess,
                 const std::string& devPath) :
      _sensor(sensor),
@@ -191,7 +192,7 @@
  {
      auto chip = env::getEnv("GPIOCHIP", sensor);
      auto access = env::getEnv("GPIO", sensor);
-@@ -70,6 +70,15 @@ Sensor::Sensor(const SensorSet::key_type& sensor,
+@@ -60,6 +60,15 @@ Sensor::Sensor(const SensorSet::key_type& sensor,
      auto senRmRCs = env::getEnv("REMOVERCS", sensor);
      // Add sensor removal return codes defined per sensor
      addRemoveRCs(senRmRCs);
diff --git a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0002-lev-add-sensors-slow-readings.patch b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0002-lev-add-sensors-slow-readings.patch
index 0a2efd8..0ab2f20 100644
--- a/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0002-lev-add-sensors-slow-readings.patch
+++ b/meta-gbs/recipes-phosphor/sensors/phosphor-hwmon/0002-lev-add-sensors-slow-readings.patch
@@ -1,20 +1,21 @@
-From 61b91122b72d7a3a5c93b80b6fb6d3ac892619dc Mon Sep 17 00:00:00 2001
+From 8eafa1b0513dd2f5898182487b4524a485bf1e21 Mon Sep 17 00:00:00 2001
 From: Eddielu <Eddie.Lu@quantatw.com>
-Date: Mon, 1 Jun 2020 14:18:33 +0800
-Subject: [PATCH] add sensors slow readings
+Date: Mon, 27 Jul 2020 20:54:28 +0800
+Subject: [PATCH] Update add sensors slow readings patch.
 
 ---
- mainloop.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
+ mainloop.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
  mainloop.hpp |  3 +++
- sensor.cpp   | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
- sensor.hpp   | 21 +++++++++++++++--
- 4 files changed, 158 insertions(+), 15 deletions(-)
+ meson.build  |  1 +
+ sensor.cpp   | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
+ sensor.hpp   | 20 ++++++++++++++--
+ 5 files changed, 158 insertions(+), 14 deletions(-)
 
 diff --git a/mainloop.cpp b/mainloop.cpp
-index 1769e94..5094343 100644
+index 4789a80..98d0658 100644
 --- a/mainloop.cpp
 +++ b/mainloop.cpp
-@@ -32,6 +32,7 @@
+@@ -34,6 +34,7 @@
  #include <cassert>
  #include <cstdlib>
  #include <functional>
@@ -22,7 +23,7 @@
  #include <iostream>
  #include <memory>
  #include <phosphor-logging/elog-errors.hpp>
-@@ -296,7 +297,7 @@ std::optional<ObjectStateData>
+@@ -299,7 +300,7 @@ std::optional<ObjectStateData>
      {
          // Add status interface based on _fault file being present
          sensorObj->addStatus(info);
@@ -48,12 +49,12 @@
 +                    std::chrono::milliseconds asyncReadTimeout{
 +                        std::stoi(asyncRead)};
 +                    bool valueIsValid = false;
-+                    std::future<SensorValueType> asyncThread;
++                    std::future<int64_t> asyncThread;
 +
 +                    auto asyncIter = _timedoutMap.find(sensorSetKey);
 +                    if (asyncIter == _timedoutMap.end())
 +                    {
-+                        // If sesnor not found in timedoutMap, spawn an async
++                        // If sensor not found in timedoutMap, spawn an async
 +                        // thread
 +                        asyncThread = std::async(
 +                            std::launch::async,
@@ -110,7 +111,7 @@
                  statusIface->functional(true);
  
 diff --git a/mainloop.hpp b/mainloop.hpp
-index 6c5b8e0..cfe34d5 100644
+index b3de022..6803c4b 100644
 --- a/mainloop.hpp
 +++ b/mainloop.hpp
 @@ -9,6 +9,7 @@
@@ -126,15 +127,27 @@
      std::map<SensorSet::key_type, std::unique_ptr<sensor::Sensor>>
          _sensorObjects;
 +    /** @brief Store the async futures of timed out sensor objects */
-+    std::map<SensorSet::key_type, std::future<SensorValueType>> _timedoutMap;
++    std::map<SensorSet::key_type, std::future<int64_t>> _timedoutMap;
  
      /**
       * @brief Map of removed sensors
+diff --git a/meson.build b/meson.build
+index 66e6801..d6a92f8 100644
+--- a/meson.build
++++ b/meson.build
+@@ -84,6 +84,7 @@ libhwmon_all = static_library(
+         gpioplus,
+         phosphor_dbus_interfaces,
+         phosphor_logging,
++        threads,
+     ],
+     link_with: [
+         libaverage,
 diff --git a/sensor.cpp b/sensor.cpp
-index 93bbb03..7b681e1 100644
+index b1cb470..72b45f8 100644
 --- a/sensor.cpp
 +++ b/sensor.cpp
-@@ -13,6 +13,7 @@
+@@ -15,6 +15,7 @@
  #include <cmath>
  #include <cstring>
  #include <filesystem>
@@ -142,7 +155,7 @@
  #include <phosphor-logging/elog-errors.hpp>
  #include <thread>
  #include <xyz/openbmc_project/Common/error.hpp>
-@@ -135,8 +136,9 @@ SensorValueType Sensor::adjustValue(SensorValueType value)
+@@ -125,8 +126,9 @@ SensorValueType Sensor::adjustValue(SensorValueType value)
      return value;
  }
  
@@ -150,11 +163,11 @@
 -                                              ObjectInfo& info)
 +std::shared_ptr<ValueObject> Sensor::addValue(
 +    const RetryIO& retryIO, ObjectInfo& info,
-+    std::map<SensorSet::key_type, std::future<SensorValueType>>& timedoutMap)
++    std::map<SensorSet::key_type, std::future<int64_t>>& timedoutMap)
  {
      static constexpr bool deferSignals = true;
  
-@@ -163,13 +165,69 @@ std::shared_ptr<ValueObject> Sensor::addValue(const RetryIO& retryIO,
+@@ -153,12 +155,69 @@ std::shared_ptr<ValueObject> Sensor::addValue(const RetryIO& retryIO,
              // RAII object for GPIO unlock / lock
              auto locker = gpioUnlock(getGpio());
  
@@ -164,7 +177,6 @@
 -                _ioAccess->read(_sensor.first, _sensor.second,
 -                                hwmon::entry::cinput, std::get<size_t>(retryIO),
 -                                std::get<std::chrono::milliseconds>(retryIO));
--
 +            // For sensors with attribute ASYNC_READ_TIMEOUT,
 +            // spawn a thread with timeout
 +            auto asyncRead = env::getEnv("ASYNC_READ_TIMEOUT", _sensor);
@@ -174,12 +186,12 @@
 +                std::chrono::milliseconds asyncReadTimeout{
 +                    std::stoi(asyncRead)};
 +                bool valueIsValid = false;
-+                std::future<SensorValueType> asyncThread;
++                std::future<int64_t> asyncThread;
 +
 +                auto asyncIter = timedoutMap.find(_sensor);
 +                if (asyncIter == timedoutMap.end())
 +                {
-+                    // If sesnor not found in timedoutMap, spawn an async thread
++                    // If sensor not found in timedoutMap, spawn an async thread
 +                    asyncThread = std::async(
 +                        std::launch::async, &hwmonio::HwmonIOInterface::read,
 +                        _ioAccess, _sensor.first, _sensor.second,
@@ -228,11 +240,11 @@
 +                    std::get<size_t>(retryIO),
 +                    std::get<std::chrono::milliseconds>(retryIO));
 +            }
-             val = adjustValue(val);
          }
  #ifdef UPDATE_FUNCTIONAL_ON_FAIL
+         catch (const std::system_error& e)
 diff --git a/sensor.hpp b/sensor.hpp
-index 369a252..d1d6730 100644
+index 369a252..41c0fe7 100644
 --- a/sensor.hpp
 +++ b/sensor.hpp
 @@ -4,6 +4,8 @@
@@ -262,7 +274,7 @@
  /** @class Sensor
   *  @brief Sensor object based on a SensorSet container's key type
   *  @details Sensor object to create and modify an associated device's sensor
-@@ -87,10 +100,14 @@ class Sensor
+@@ -87,10 +100,13 @@ class Sensor
       *                      (number of and delay between)
       * @param[in] info - Sensor object information
       *
@@ -272,10 +284,9 @@
       */
 -    std::shared_ptr<ValueObject> addValue(const RetryIO& retryIO,
 -                                          ObjectInfo& info);
-+    std::shared_ptr<ValueObject>
-+        addValue(const RetryIO& retryIO, ObjectInfo& info,
-+                 std::map<SensorSet::key_type, std::future<SensorValueType>>&
-+                     timedoutMap);
++    std::shared_ptr<ValueObject> addValue(
++        const RetryIO& retryIO, ObjectInfo& info,
++        std::map<SensorSet::key_type, std::future<int64_t>>& timedoutMap);
  
      /**
       * @brief Add status interface and functional property for sensor