xref: /openbmc/phosphor-pid-control/util.cpp (revision ba003434)
1 /**
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <string>
18 
19 #include "util.hpp"
20 
21 
22 static constexpr auto external_sensor =
23     "/xyz/openbmc_project/extsensors/"; // type/
24 static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
25 static constexpr auto dbus_pwm = "/xyz/openbmc_project/control/fanpwm/";
26 static constexpr auto sysfs = "/sys/";
27 
28 
29 IOInterfaceType GetWriteInterfaceType(const std::string& path)
30 {
31     if (path.empty() || "None" == path)
32     {
33         return IOInterfaceType::NONE;
34     }
35 
36     if (path.find(sysfs) != std::string::npos)
37     {
38         // A sysfs read sensor.
39         return IOInterfaceType::SYSFS;
40     }
41 
42     if (path.find(dbus_pwm) != std::string::npos)
43     {
44         return IOInterfaceType::DBUSACTIVE;
45     }
46 
47     return IOInterfaceType::UNKNOWN;
48 }
49 
50 IOInterfaceType GetReadInterfaceType(const std::string& path)
51 {
52     if (path.empty() || "None" == path)
53     {
54         return IOInterfaceType::NONE;
55     }
56 
57     if (path.find(external_sensor) != std::string::npos)
58     {
59         return IOInterfaceType::EXTERNAL;
60     }
61 
62     if (path.find(openbmc_sensor) != std::string::npos)
63     {
64         return IOInterfaceType::DBUSPASSIVE;
65     }
66 
67     if (path.find(sysfs) != std::string::npos)
68     {
69         return IOInterfaceType::SYSFS;
70     }
71 
72     return IOInterfaceType::UNKNOWN;
73 }
74 
75