psusensor: Convert sensorTypes to I2CDeviceTypeMap
Similar to change
https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/56127.
Tested: same sensors get initialized before and after change.
Change-Id: I57aca3738b01aa22da4dab5d8b1ed251578d9123
Signed-off-by: Matt Simmering <matthew.simmering@intel.com>
diff --git a/src/DeviceMgmt.hpp b/src/DeviceMgmt.hpp
index 07b28b5..c8c76f1 100644
--- a/src/DeviceMgmt.hpp
+++ b/src/DeviceMgmt.hpp
@@ -14,8 +14,16 @@
bool createsHWMon;
};
+struct I2CDeviceComparator
+{
+ bool operator()(const std::string& a, const std::string& b) const noexcept
+ {
+ return strcasecmp(a.c_str(), b.c_str()) < 0;
+ }
+};
+
using I2CDeviceTypeMap =
- boost::container::flat_map<std::string, I2CDeviceType, std::less<>>;
+ boost::container::flat_map<std::string, I2CDeviceType, I2CDeviceComparator>;
struct I2CDeviceParams
{
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index 8058996..07802cd 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -14,6 +14,7 @@
// limitations under the License.
*/
+#include "DeviceMgmt.hpp"
#include "PSUEvent.hpp"
#include "PSUSensor.hpp"
#include "Utils.hpp"
@@ -40,104 +41,54 @@
static constexpr bool debug = false;
-// clang-format off
-static constexpr auto sensorTypes{std::to_array<const char*>({
- "ADM1266",
- "ADM1272",
- "ADM1275",
- "ADM1278",
- "ADM1293",
- "ADS7830",
- "AHE50DC_FAN",
- "BMR490",
- "DPS800",
- "INA219",
- "INA230",
- "IPSPS",
- "IR38060",
- "IR38164",
- "IR38263",
- "ISL68137",
- "ISL68220",
- "ISL68223",
- "ISL69225",
- "ISL69243",
- "ISL69260",
- "LM25066",
- "MAX16601",
- "MAX20710",
- "MAX20730",
- "MAX20734",
- "MAX20796",
- "MAX34451",
- "MP2971",
- "MP2973",
- "MP2975",
- "MP5023",
- "NCP4200",
- "PLI1209BC",
- "pmbus",
- "PXE1610",
- "RAA228000",
- "RAA228228",
- "RAA228620",
- "RAA229001",
- "RAA229004",
- "RAA229126",
- "TPS53679",
- "TPS546D24",
- "XDPE11280",
- "XDPE12284"})};
-
-static constexpr auto pmbusNames{std::to_array<const char*>({
- "adm1266",
- "adm1272",
- "adm1275",
- "adm1278",
- "adm1293",
- "ads7830",
- "ahe50dc_fan",
- "bmr490",
- "dps800",
- "ina219",
- "ina230",
- "ipsps1",
- "ir38060",
- "ir38164",
- "ir38263",
- "isl68137",
- "isl68220",
- "isl68223",
- "isl69225",
- "isl69243",
- "isl69260",
- "lm25066",
- "max16601",
- "max20710",
- "max20730",
- "max20734",
- "max20796",
- "max34451",
- "mp2971",
- "mp2973",
- "mp2975",
- "mp5023",
- "ncp4200",
- "pli1209bc",
- "pmbus",
- "pxe1610",
- "raa228000",
- "raa228228",
- "raa228620",
- "raa229001",
- "raa229004",
- "raa229126",
- "tps53679",
- "tps546d24",
- "xdpe11280",
- "xdpe12284"
-})};
-//clang-format on
+static const I2CDeviceTypeMap sensorTypes{
+ {"ADM1266", I2CDeviceType{"adm1266", true}},
+ {"ADM1272", I2CDeviceType{"adm1272", true}},
+ {"ADM1275", I2CDeviceType{"adm1275", true}},
+ {"ADM1278", I2CDeviceType{"adm1278", true}},
+ {"ADM1293", I2CDeviceType{"adm1293", true}},
+ {"ADS7830", I2CDeviceType{"ads7830", true}},
+ {"AHE50DC_FAN", I2CDeviceType{"ahe50dc_fan", true}},
+ {"BMR490", I2CDeviceType{"bmr490", true}},
+ {"DPS800", I2CDeviceType{"dps800", true}},
+ {"INA219", I2CDeviceType{"ina219", true}},
+ {"INA230", I2CDeviceType{"ina230", true}},
+ {"IPSPS", I2CDeviceType{"ipsps", true}},
+ {"IR38060", I2CDeviceType{"ir38060", true}},
+ {"IR38164", I2CDeviceType{"ir38164", true}},
+ {"IR38263", I2CDeviceType{"ir38263", true}},
+ {"ISL68137", I2CDeviceType{"isl68137", true}},
+ {"ISL68220", I2CDeviceType{"isl68220", true}},
+ {"ISL68223", I2CDeviceType{"isl68223", true}},
+ {"ISL69225", I2CDeviceType{"isl69225", true}},
+ {"ISL69243", I2CDeviceType{"isl69243", true}},
+ {"ISL69260", I2CDeviceType{"isl69260", true}},
+ {"LM25066", I2CDeviceType{"lm25066", true}},
+ {"MAX16601", I2CDeviceType{"max16601", true}},
+ {"MAX20710", I2CDeviceType{"max20710", true}},
+ {"MAX20730", I2CDeviceType{"max20730", true}},
+ {"MAX20734", I2CDeviceType{"max20734", true}},
+ {"MAX20796", I2CDeviceType{"max20796", true}},
+ {"MAX34451", I2CDeviceType{"max34451", true}},
+ {"MP2971", I2CDeviceType{"mp2971", true}},
+ {"MP2973", I2CDeviceType{"mp2973", true}},
+ {"MP2975", I2CDeviceType{"mp2975", true}},
+ {"MP5023", I2CDeviceType{"mp5023", true}},
+ {"NCP4200", I2CDeviceType{"ncp4200", true}},
+ {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
+ {"pmbus", I2CDeviceType{"pmbus", true}},
+ {"PXE1610", I2CDeviceType{"pxe1610", true}},
+ {"RAA228000", I2CDeviceType{"raa228000", true}},
+ {"RAA228228", I2CDeviceType{"raa228228", true}},
+ {"RAA228620", I2CDeviceType{"raa228620", true}},
+ {"RAA229001", I2CDeviceType{"raa229001", true}},
+ {"RAA229004", I2CDeviceType{"raa229004", true}},
+ {"RAA229126", I2CDeviceType{"raa229126", true}},
+ {"TPS53679", I2CDeviceType{"tps53679", true}},
+ {"TPS546D24", I2CDeviceType{"tps546d24", true}},
+ {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
+ {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
+};
namespace fs = std::filesystem;
@@ -358,8 +309,7 @@
std::getline(nameFile, pmbusName);
nameFile.close();
- if (std::find(pmbusNames.begin(), pmbusNames.end(), pmbusName) ==
- pmbusNames.end())
+ if (sensorTypes.find(pmbusName) == sensorTypes.end())
{
// To avoid this error message, add your driver name to
// the pmbusNames vector at the top of this file.
@@ -406,13 +356,13 @@
const SensorBaseConfigMap* baseConfig = nullptr;
const SensorData* sensorData = nullptr;
const std::string* interfacePath = nullptr;
- const char* sensorType = nullptr;
+ std::string sensorType;
size_t thresholdConfSize = 0;
for (const auto& [path, cfgData] : sensorConfigs)
{
sensorData = &cfgData;
- for (const char* type : sensorTypes)
+ for (const auto& [type, dt] : sensorTypes)
{
auto sensorBase = sensorData->find(configInterfaceName(type));
if (sensorBase != sensorData->end())
@@ -962,8 +912,12 @@
createSensorsCallback(io, objectServer, dbusConnection,
sensorConfigs, sensorsChanged);
});
- getter->getConfiguration(
- std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
+ std::vector<std::string> types(sensorTypes.size());
+ for (const auto& [type, dt] : sensorTypes)
+ {
+ types.push_back(type);
+ }
+ getter->getConfiguration(types);
}
void propertyInitialize(void)
@@ -1097,7 +1051,8 @@
propertyInitialize();
- boost::asio::post(io, [&]() { createSensors(io, objectServer, systemBus, nullptr); });
+ boost::asio::post(
+ io, [&]() { createSensors(io, objectServer, systemBus, nullptr); });
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
diff --git a/src/meson.build b/src/meson.build
index 6f47fb0..665517a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -208,6 +208,7 @@
'PSUSensorMain.cpp',
dependencies: [
default_deps,
+ devicemgmt_dep,
pwmsensor_dep,
thresholds_dep,
utils_dep,