xref: /openbmc/entity-manager/src/entity_manager/devices.hpp (revision fc9e7fda2bd21c5cc9afca2cef8af0f19b28dc08)
1*fc9e7fdaSChristopher Meis /*
2*fc9e7fdaSChristopher Meis // Copyright (c) 2018 Intel Corporation
3*fc9e7fdaSChristopher Meis //
4*fc9e7fdaSChristopher Meis // Licensed under the Apache License, Version 2.0 (the "License");
5*fc9e7fdaSChristopher Meis // you may not use this file except in compliance with the License.
6*fc9e7fdaSChristopher Meis // You may obtain a copy of the License at
7*fc9e7fdaSChristopher Meis //
8*fc9e7fdaSChristopher Meis //      http://www.apache.org/licenses/LICENSE-2.0
9*fc9e7fdaSChristopher Meis //
10*fc9e7fdaSChristopher Meis // Unless required by applicable law or agreed to in writing, software
11*fc9e7fdaSChristopher Meis // distributed under the License is distributed on an "AS IS" BASIS,
12*fc9e7fdaSChristopher Meis // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*fc9e7fdaSChristopher Meis // See the License for the specific language governing permissions and
14*fc9e7fdaSChristopher Meis // limitations under the License.
15*fc9e7fdaSChristopher Meis */
16*fc9e7fdaSChristopher Meis /// \file devices.hpp
17*fc9e7fdaSChristopher Meis 
18*fc9e7fdaSChristopher Meis #pragma once
19*fc9e7fdaSChristopher Meis #include <boost/container/flat_map.hpp>
20*fc9e7fdaSChristopher Meis 
21*fc9e7fdaSChristopher Meis namespace devices
22*fc9e7fdaSChristopher Meis {
23*fc9e7fdaSChristopher Meis 
24*fc9e7fdaSChristopher Meis struct CmpStr
25*fc9e7fdaSChristopher Meis {
operator ()devices::CmpStr26*fc9e7fdaSChristopher Meis     bool operator()(const char* a, const char* b) const
27*fc9e7fdaSChristopher Meis     {
28*fc9e7fdaSChristopher Meis         return std::strcmp(a, b) < 0;
29*fc9e7fdaSChristopher Meis     }
30*fc9e7fdaSChristopher Meis };
31*fc9e7fdaSChristopher Meis 
32*fc9e7fdaSChristopher Meis // I2C device drivers may create a /hwmon subdirectory. For example the tmp75
33*fc9e7fdaSChristopher Meis // driver creates a /sys/bus/i2c/devices/<busnum>-<i2caddr>/hwmon
34*fc9e7fdaSChristopher Meis // directory. The sensor code relies on the presence of the /hwmon
35*fc9e7fdaSChristopher Meis // subdirectory to collect sensor readings. Initialization of this subdir is
36*fc9e7fdaSChristopher Meis // not reliable. I2C devices flagged with hasHWMonDir are tested for correct
37*fc9e7fdaSChristopher Meis // initialization, and when a failure is detected the device is deleted, and
38*fc9e7fdaSChristopher Meis // then recreated. The default is to retry 5 times before moving to the next
39*fc9e7fdaSChristopher Meis // device.
40*fc9e7fdaSChristopher Meis 
41*fc9e7fdaSChristopher Meis // Devices such as I2C EEPROMs do not generate this file structure. These
42*fc9e7fdaSChristopher Meis // kinds of devices are flagged using the noHWMonDir enumeration. The
43*fc9e7fdaSChristopher Meis // expectation is they are created correctly on the first attempt.
44*fc9e7fdaSChristopher Meis 
45*fc9e7fdaSChristopher Meis // This enumeration class exists to reduce copy/paste errors. It is easy to
46*fc9e7fdaSChristopher Meis // overlook the trailing parameter in the ExportTemplate structure when it is
47*fc9e7fdaSChristopher Meis // a simple boolean.
48*fc9e7fdaSChristopher Meis enum class createsHWMon : bool
49*fc9e7fdaSChristopher Meis {
50*fc9e7fdaSChristopher Meis     noHWMonDir,
51*fc9e7fdaSChristopher Meis     hasHWMonDir
52*fc9e7fdaSChristopher Meis };
53*fc9e7fdaSChristopher Meis 
54*fc9e7fdaSChristopher Meis struct ExportTemplate
55*fc9e7fdaSChristopher Meis {
ExportTemplatedevices::ExportTemplate56*fc9e7fdaSChristopher Meis     ExportTemplate(const char* params, const char* bus, const char* constructor,
57*fc9e7fdaSChristopher Meis                    const char* destructor, createsHWMon hasHWMonDir) :
58*fc9e7fdaSChristopher Meis         parameters(params), busPath(bus), add(constructor), remove(destructor),
59*fc9e7fdaSChristopher Meis         hasHWMonDir(hasHWMonDir) {};
60*fc9e7fdaSChristopher Meis     const char* parameters;
61*fc9e7fdaSChristopher Meis     const char* busPath;
62*fc9e7fdaSChristopher Meis     const char* add;
63*fc9e7fdaSChristopher Meis     const char* remove;
64*fc9e7fdaSChristopher Meis     createsHWMon hasHWMonDir;
65*fc9e7fdaSChristopher Meis };
66*fc9e7fdaSChristopher Meis 
67*fc9e7fdaSChristopher Meis const boost::container::flat_map<const char*, ExportTemplate, CmpStr>
68*fc9e7fdaSChristopher Meis     exportTemplates{
69*fc9e7fdaSChristopher Meis         {{"EEPROM_24C01",
70*fc9e7fdaSChristopher Meis           ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
71*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
72*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
73*fc9e7fdaSChristopher Meis          {"EEPROM_24C02",
74*fc9e7fdaSChristopher Meis           ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
75*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
76*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
77*fc9e7fdaSChristopher Meis          {"EEPROM_24C04",
78*fc9e7fdaSChristopher Meis           ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
79*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
80*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
81*fc9e7fdaSChristopher Meis          {"EEPROM_24C08",
82*fc9e7fdaSChristopher Meis           ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
83*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
84*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
85*fc9e7fdaSChristopher Meis          {"EEPROM_24C16",
86*fc9e7fdaSChristopher Meis           ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
87*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
88*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
89*fc9e7fdaSChristopher Meis          {"EEPROM_24C32",
90*fc9e7fdaSChristopher Meis           ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
91*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
92*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
93*fc9e7fdaSChristopher Meis          {"EEPROM_24C64",
94*fc9e7fdaSChristopher Meis           ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
95*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
96*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
97*fc9e7fdaSChristopher Meis          {"EEPROM_24C128",
98*fc9e7fdaSChristopher Meis           ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
99*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
100*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
101*fc9e7fdaSChristopher Meis          {"EEPROM_24C256",
102*fc9e7fdaSChristopher Meis           ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
103*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
104*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
105*fc9e7fdaSChristopher Meis          {"ADS1015",
106*fc9e7fdaSChristopher Meis           ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
107*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
108*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
109*fc9e7fdaSChristopher Meis          {"ADS7828",
110*fc9e7fdaSChristopher Meis           ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
111*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
112*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
113*fc9e7fdaSChristopher Meis          {"EEPROM",
114*fc9e7fdaSChristopher Meis           ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus",
115*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
116*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
117*fc9e7fdaSChristopher Meis          {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export",
118*fc9e7fdaSChristopher Meis                                  "unexport", createsHWMon::noHWMonDir)},
119*fc9e7fdaSChristopher Meis          {"IPSPS1",
120*fc9e7fdaSChristopher Meis           ExportTemplate("ipsps1 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
121*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
122*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
123*fc9e7fdaSChristopher Meis          {"MAX34440",
124*fc9e7fdaSChristopher Meis           ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
125*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
126*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
127*fc9e7fdaSChristopher Meis          {"PCA9537",
128*fc9e7fdaSChristopher Meis           ExportTemplate("pca9537 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
129*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
130*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
131*fc9e7fdaSChristopher Meis          {"PCA9542Mux",
132*fc9e7fdaSChristopher Meis           ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
133*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
134*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
135*fc9e7fdaSChristopher Meis          {"PCA9543Mux",
136*fc9e7fdaSChristopher Meis           ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
137*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
138*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
139*fc9e7fdaSChristopher Meis          {"PCA9544Mux",
140*fc9e7fdaSChristopher Meis           ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
141*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
142*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
143*fc9e7fdaSChristopher Meis          {"PCA9545Mux",
144*fc9e7fdaSChristopher Meis           ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
145*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
146*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
147*fc9e7fdaSChristopher Meis          {"PCA9546Mux",
148*fc9e7fdaSChristopher Meis           ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
149*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
150*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
151*fc9e7fdaSChristopher Meis          {"PCA9547Mux",
152*fc9e7fdaSChristopher Meis           ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
153*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
154*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
155*fc9e7fdaSChristopher Meis          {"PCA9548Mux",
156*fc9e7fdaSChristopher Meis           ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
157*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
158*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
159*fc9e7fdaSChristopher Meis          {"PCA9846Mux",
160*fc9e7fdaSChristopher Meis           ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
161*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
162*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
163*fc9e7fdaSChristopher Meis          {"PCA9847Mux",
164*fc9e7fdaSChristopher Meis           ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
165*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
166*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
167*fc9e7fdaSChristopher Meis          {"PCA9848Mux",
168*fc9e7fdaSChristopher Meis           ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
169*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
170*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
171*fc9e7fdaSChristopher Meis          {"PCA9849Mux",
172*fc9e7fdaSChristopher Meis           ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
173*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
174*fc9e7fdaSChristopher Meis                          createsHWMon::noHWMonDir)},
175*fc9e7fdaSChristopher Meis          {"SIC450",
176*fc9e7fdaSChristopher Meis           ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
177*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
178*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
179*fc9e7fdaSChristopher Meis          {"Q50SN12072",
180*fc9e7fdaSChristopher Meis           ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
181*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
182*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
183*fc9e7fdaSChristopher Meis          {"MAX31790",
184*fc9e7fdaSChristopher Meis           ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
185*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
186*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
187*fc9e7fdaSChristopher Meis          {"PIC32", ExportTemplate("pic32 $Address",
188*fc9e7fdaSChristopher Meis                                   "/sys/bus/i2c/devices/i2c-$Bus", "new_device",
189*fc9e7fdaSChristopher Meis                                   "delete_device", createsHWMon::hasHWMonDir)},
190*fc9e7fdaSChristopher Meis          {"INA226",
191*fc9e7fdaSChristopher Meis           ExportTemplate("ina226 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
192*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
193*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
194*fc9e7fdaSChristopher Meis          {"RAA229620",
195*fc9e7fdaSChristopher Meis           ExportTemplate("raa229620 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
196*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
197*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
198*fc9e7fdaSChristopher Meis          {"RAA229621",
199*fc9e7fdaSChristopher Meis           ExportTemplate("raa229621 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
200*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
201*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)},
202*fc9e7fdaSChristopher Meis          {"PIC32",
203*fc9e7fdaSChristopher Meis           ExportTemplate("pic32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
204*fc9e7fdaSChristopher Meis                          "new_device", "delete_device",
205*fc9e7fdaSChristopher Meis                          createsHWMon::hasHWMonDir)}}};
206*fc9e7fdaSChristopher Meis } // namespace devices
207