xref: /openbmc/entity-manager/src/devices.hpp (revision dafc6884)
1 /*
2 // Copyright (c) 2018 Intel Corporation
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 /// \file devices.hpp
17 
18 #pragma once
19 #include <boost/container/flat_map.hpp>
20 
21 namespace devices
22 {
23 
24 struct CmpStr
25 {
26     bool operator()(const char* a, const char* b) const
27     {
28         return std::strcmp(a, b) < 0;
29     }
30 };
31 
32 // I2C device drivers may create a /hwmon subdirectory. For example the tmp75
33 // driver creates a /sys/bus/i2c/devices/<busnum>-<i2caddr>/hwmon
34 // directory. The sensor code relies on the presence of the /hwmon
35 // subdirectory to collect sensor readings. Initialization of this subdir is
36 // not reliable. I2C devices flagged with hasHWMonDir are tested for correct
37 // initialization, and when a failure is detected the device is deleted, and
38 // then recreated. The default is to retry 5 times before moving to the next
39 // device.
40 
41 // Devices such as I2C EEPROMs do not generate this file structure. These
42 // kinds of devices are flagged using the noHWMonDir enumeration. The
43 // expectation is they are created correctly on the first attempt.
44 
45 // This enumeration class exists to reduce copy/paste errors. It is easy to
46 // overlook the trailing parameter in the ExportTemplate structure when it is
47 // a simple boolean.
48 enum class createsHWMon : bool
49 {
50     noHWMonDir,
51     hasHWMonDir
52 };
53 
54 struct ExportTemplate
55 {
56     ExportTemplate(const char* params, const char* bus, const char* constructor,
57                    const char* destructor, createsHWMon hasHWMonDir) :
58         parameters(params),
59         busPath(bus), add(constructor), remove(destructor),
60         hasHWMonDir(hasHWMonDir){};
61     const char* parameters;
62     const char* busPath;
63     const char* add;
64     const char* remove;
65     createsHWMon hasHWMonDir;
66 };
67 
68 const boost::container::flat_map<const char*, ExportTemplate, CmpStr>
69     exportTemplates{
70         {{"EEPROM_24C01",
71           ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
72                          "new_device", "delete_device",
73                          createsHWMon::noHWMonDir)},
74          {"EEPROM_24C02",
75           ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
76                          "new_device", "delete_device",
77                          createsHWMon::noHWMonDir)},
78          {"EEPROM_24C04",
79           ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
80                          "new_device", "delete_device",
81                          createsHWMon::noHWMonDir)},
82          {"EEPROM_24C08",
83           ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
84                          "new_device", "delete_device",
85                          createsHWMon::noHWMonDir)},
86          {"EEPROM_24C16",
87           ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
88                          "new_device", "delete_device",
89                          createsHWMon::noHWMonDir)},
90          {"EEPROM_24C32",
91           ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
92                          "new_device", "delete_device",
93                          createsHWMon::noHWMonDir)},
94          {"EEPROM_24C64",
95           ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
96                          "new_device", "delete_device",
97                          createsHWMon::noHWMonDir)},
98          {"EEPROM_24C128",
99           ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
100                          "new_device", "delete_device",
101                          createsHWMon::noHWMonDir)},
102          {"EEPROM_24C256",
103           ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
104                          "new_device", "delete_device",
105                          createsHWMon::noHWMonDir)},
106          {"ADM1266",
107           ExportTemplate("adm1266 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
108                          "new_device", "delete_device",
109                          createsHWMon::noHWMonDir)},
110          {"ADM1272",
111           ExportTemplate("adm1272 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
112                          "new_device", "delete_device",
113                          createsHWMon::noHWMonDir)},
114          {"ADS1015",
115           ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
116                          "new_device", "delete_device",
117                          createsHWMon::noHWMonDir)},
118          {"ADS7828",
119           ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
120                          "new_device", "delete_device",
121                          createsHWMon::noHWMonDir)},
122          {"EEPROM",
123           ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus",
124                          "new_device", "delete_device",
125                          createsHWMon::noHWMonDir)},
126          {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export",
127                                  "unexport", createsHWMon::noHWMonDir)},
128          {"INA230",
129           ExportTemplate("ina230 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
130                          "new_device", "delete_device",
131                          createsHWMon::hasHWMonDir)},
132          {"ISL68137",
133           ExportTemplate("isl68137 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
134                          "new_device", "delete_device",
135                          createsHWMon::hasHWMonDir)},
136          {"ISL68220",
137           ExportTemplate("isl68220 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
138                          "new_device", "delete_device",
139                          createsHWMon::hasHWMonDir)},
140          {"ISL69225",
141           ExportTemplate("isl69225 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
142                          "new_device", "delete_device",
143                          createsHWMon::hasHWMonDir)},
144          {"ISL68223",
145           ExportTemplate("isl68223 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
146                          "new_device", "delete_device",
147                          createsHWMon::hasHWMonDir)},
148          {"ISL69243",
149           ExportTemplate("isl69243 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
150                          "new_device", "delete_device",
151                          createsHWMon::hasHWMonDir)},
152          {"ISL69260",
153           ExportTemplate("isl69260 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
154                          "new_device", "delete_device",
155                          createsHWMon::hasHWMonDir)},
156          {"MAX16601",
157           ExportTemplate("max16601 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
158                          "new_device", "delete_device",
159                          createsHWMon::hasHWMonDir)},
160          {"MAX20710",
161           ExportTemplate("max20710 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
162                          "new_device", "delete_device",
163                          createsHWMon::hasHWMonDir)},
164          {"MAX20730",
165           ExportTemplate("max20730 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
166                          "new_device", "delete_device",
167                          createsHWMon::hasHWMonDir)},
168          {"MAX20734",
169           ExportTemplate("max20734 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
170                          "new_device", "delete_device",
171                          createsHWMon::hasHWMonDir)},
172          {"MAX20796",
173           ExportTemplate("max20796 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
174                          "new_device", "delete_device",
175                          createsHWMon::hasHWMonDir)},
176          {"MAX34440",
177           ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
178                          "new_device", "delete_device",
179                          createsHWMon::hasHWMonDir)},
180          {"MAX34451",
181           ExportTemplate("max34451 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
182                          "new_device", "delete_device",
183                          createsHWMon::hasHWMonDir)},
184          {"PCA9542Mux",
185           ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
186                          "new_device", "delete_device",
187                          createsHWMon::noHWMonDir)},
188          {"PCA9543Mux",
189           ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
190                          "new_device", "delete_device",
191                          createsHWMon::noHWMonDir)},
192          {"PCA9544Mux",
193           ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
194                          "new_device", "delete_device",
195                          createsHWMon::noHWMonDir)},
196          {"PCA9545Mux",
197           ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
198                          "new_device", "delete_device",
199                          createsHWMon::noHWMonDir)},
200          {"PCA9546Mux",
201           ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
202                          "new_device", "delete_device",
203                          createsHWMon::noHWMonDir)},
204          {"PCA9547Mux",
205           ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
206                          "new_device", "delete_device",
207                          createsHWMon::noHWMonDir)},
208          {"PCA9548Mux",
209           ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
210                          "new_device", "delete_device",
211                          createsHWMon::noHWMonDir)},
212          {"PCA9846Mux",
213           ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
214                          "new_device", "delete_device",
215                          createsHWMon::noHWMonDir)},
216          {"PCA9847Mux",
217           ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
218                          "new_device", "delete_device",
219                          createsHWMon::noHWMonDir)},
220          {"PCA9848Mux",
221           ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
222                          "new_device", "delete_device",
223                          createsHWMon::noHWMonDir)},
224          {"PCA9849Mux",
225           ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
226                          "new_device", "delete_device",
227                          createsHWMon::noHWMonDir)},
228          {"SIC450",
229           ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
230                          "new_device", "delete_device",
231                          createsHWMon::hasHWMonDir)},
232          {"pmbus", ExportTemplate("pmbus $Address",
233                                   "/sys/bus/i2c/devices/i2c-$Bus", "new_device",
234                                   "delete_device", createsHWMon::hasHWMonDir)},
235          {"PXE1610",
236           ExportTemplate("pxe1610 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
237                          "new_device", "delete_device",
238                          createsHWMon::hasHWMonDir)},
239          {"Q50SN12072",
240           ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
241                          "new_device", "delete_device",
242                          createsHWMon::hasHWMonDir)},
243          {"XDPE12284",
244           ExportTemplate("xdpe12284 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
245                          "new_device", "delete_device",
246                          createsHWMon::hasHWMonDir)},
247          {"XDPE152C4",
248           ExportTemplate("xdpe152c4 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
249                          "new_device", "delete_device",
250                          createsHWMon::hasHWMonDir)},
251          {"LM25066",
252           ExportTemplate("lm25066 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
253                          "new_device", "delete_device",
254                          createsHWMon::hasHWMonDir)},
255          {"RAA228000",
256           ExportTemplate("raa228000 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
257                          "new_device", "delete_device",
258                          createsHWMon::hasHWMonDir)},
259          {"DPS800",
260           ExportTemplate("dps800 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
261                          "new_device", "delete_device",
262                          createsHWMon::hasHWMonDir)},
263          {"MAX31790",
264           ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
265                          "new_device", "delete_device",
266                          createsHWMon::hasHWMonDir)},
267          {"PIC32", ExportTemplate("pic32 $Address",
268                                   "/sys/bus/i2c/devices/i2c-$Bus", "new_device",
269                                   "delete_device", createsHWMon::hasHWMonDir)},
270          {"ADM1293",
271           ExportTemplate("adm1293 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
272                          "new_device", "delete_device",
273                          createsHWMon::hasHWMonDir)},
274          {"INA219",
275           ExportTemplate("ina219 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
276                          "new_device", "delete_device",
277                          createsHWMon::hasHWMonDir)},
278          {"RAA229004",
279           ExportTemplate("raa229004 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
280                          "new_device", "delete_device",
281                          createsHWMon::hasHWMonDir)},
282          {"RAA229126",
283           ExportTemplate("raa229126 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
284                          "new_device", "delete_device",
285                          createsHWMon::hasHWMonDir)},
286          {"RAA229620",
287           ExportTemplate("raa229620 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
288                          "new_device", "delete_device",
289                          createsHWMon::hasHWMonDir)},
290          {"RAA229621",
291           ExportTemplate("raa229621 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
292                          "new_device", "delete_device",
293                          createsHWMon::hasHWMonDir)},
294          {"TPS53679",
295           ExportTemplate("tps53679 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
296                          "new_device", "delete_device",
297                          createsHWMon::hasHWMonDir)},
298          {"MP2971",
299           ExportTemplate("mp2971 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
300                          "new_device", "delete_device",
301                          createsHWMon::hasHWMonDir)},
302          {"MP2973",
303           ExportTemplate("mp2973 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
304                          "new_device", "delete_device",
305                          createsHWMon::hasHWMonDir)},
306          {"MP2975",
307           ExportTemplate("mp2975 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
308                          "new_device", "delete_device",
309                          createsHWMon::hasHWMonDir)}}};
310 } // namespace devices
311