blob: 28028bbde375d012bf996587bbeda6dcf9d577da [file] [log] [blame]
James Feist053a6642018-10-15 13:17:09 -07001/*
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*/
Brad Bishop1fb9f3f2020-08-28 08:15:13 -040016/// \file devices.hpp
James Feist053a6642018-10-15 13:17:09 -070017
18#pragma once
19#include <boost/container/flat_map.hpp>
20
21namespace devices
22{
23
24struct CmpStr
25{
James Feista465ccc2019-02-08 12:51:01 -080026 bool operator()(const char* a, const char* b) const
James Feist053a6642018-10-15 13:17:09 -070027 {
28 return std::strcmp(a, b) < 0;
29 }
30};
31
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070032// 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.
48enum class createsHWMon : bool
49{
50 noHWMonDir,
51 hasHWMonDir
52};
53
James Feist053a6642018-10-15 13:17:09 -070054struct ExportTemplate
55{
Zev Weissc11b5da2022-07-12 16:31:37 -070056 ExportTemplate(const char* params, const char* bus, const char* constructor,
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070057 const char* destructor, createsHWMon hasHWMonDir) :
Patrick Williamsb7077432024-08-16 15:22:21 -040058 parameters(params), busPath(bus), add(constructor), remove(destructor),
59 hasHWMonDir(hasHWMonDir) {};
James Feista465ccc2019-02-08 12:51:01 -080060 const char* parameters;
Zev Weissc11b5da2022-07-12 16:31:37 -070061 const char* busPath;
Johnathan Mantey9b867872020-10-13 15:00:51 -070062 const char* add;
63 const char* remove;
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070064 createsHWMon hasHWMonDir;
James Feist053a6642018-10-15 13:17:09 -070065};
66
James Feista465ccc2019-02-08 12:51:01 -080067const boost::container::flat_map<const char*, ExportTemplate, CmpStr>
Devjit Gopalpur4acdc542019-10-10 22:47:46 -070068 exportTemplates{
Vijay Khemka48328412021-04-12 23:14:53 +000069 {{"EEPROM_24C01",
70 ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070071 "new_device", "delete_device",
72 createsHWMon::noHWMonDir)},
Vijay Khemka48328412021-04-12 23:14:53 +000073 {"EEPROM_24C02",
Johnathan Mantey9b867872020-10-13 15:00:51 -070074 ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070075 "new_device", "delete_device",
76 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070077 {"EEPROM_24C04",
78 ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070079 "new_device", "delete_device",
80 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070081 {"EEPROM_24C08",
82 ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070083 "new_device", "delete_device",
84 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070085 {"EEPROM_24C16",
86 ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070087 "new_device", "delete_device",
88 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070089 {"EEPROM_24C32",
90 ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070091 "new_device", "delete_device",
92 createsHWMon::noHWMonDir)},
Hao Jiangf64d4392021-02-23 14:22:03 -080093 {"EEPROM_24C64",
Johnathan Mantey9b867872020-10-13 15:00:51 -070094 ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070095 "new_device", "delete_device",
96 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070097 {"EEPROM_24C128",
98 ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070099 "new_device", "delete_device",
100 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -0700101 {"EEPROM_24C256",
102 ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700103 "new_device", "delete_device",
104 createsHWMon::noHWMonDir)},
Joseph Fu9fa8f412022-11-07 09:23:33 +0800105 {"ADS1015",
106 ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
107 "new_device", "delete_device",
108 createsHWMon::noHWMonDir)},
Michal Bieleckiff503d82022-04-29 10:20:08 +0200109 {"ADS7828",
110 ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700111 "new_device", "delete_device",
112 createsHWMon::noHWMonDir)},
Johnathan Mantey9b867872020-10-13 15:00:51 -0700113 {"EEPROM",
114 ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700115 "new_device", "delete_device",
116 createsHWMon::noHWMonDir)},
Johnathan Mantey9b867872020-10-13 15:00:51 -0700117 {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700118 "unexport", createsHWMon::noHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800119 {"IPSPS1",
120 ExportTemplate("ipsps1 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
121 "new_device", "delete_device",
122 createsHWMon::hasHWMonDir)},
Nan Zhou296667f2021-02-23 09:53:14 -0800123 {"MAX34440",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700124 ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700125 "new_device", "delete_device",
126 createsHWMon::hasHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800127 {"PCA9537",
128 ExportTemplate("pca9537 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
129 "new_device", "delete_device",
130 createsHWMon::noHWMonDir)},
Jan Sowinski50b2e0f2022-05-06 16:47:12 +0200131 {"PCA9542Mux",
132 ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700133 "new_device", "delete_device",
134 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700135 {"PCA9543Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700136 ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700137 "new_device", "delete_device",
138 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700139 {"PCA9544Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700140 ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700141 "new_device", "delete_device",
142 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700143 {"PCA9545Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700144 ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700145 "new_device", "delete_device",
146 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700147 {"PCA9546Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700148 ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700149 "new_device", "delete_device",
150 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700151 {"PCA9547Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700152 ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700153 "new_device", "delete_device",
154 createsHWMon::noHWMonDir)},
Sujoy Raye4dc1402022-04-15 10:28:34 -0700155 {"PCA9548Mux",
156 ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700157 "new_device", "delete_device",
158 createsHWMon::noHWMonDir)},
Jan Sowinski50b2e0f2022-05-06 16:47:12 +0200159 {"PCA9846Mux",
160 ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700161 "new_device", "delete_device",
162 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800163 {"PCA9847Mux",
164 ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700165 "new_device", "delete_device",
166 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800167 {"PCA9848Mux",
168 ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700169 "new_device", "delete_device",
170 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800171 {"PCA9849Mux",
172 ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700173 "new_device", "delete_device",
174 createsHWMon::noHWMonDir)},
Yung Sheng Huang2ca85292022-07-15 09:59:50 +0800175 {"SIC450",
176 ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700177 "new_device", "delete_device",
178 createsHWMon::hasHWMonDir)},
Yung Sheng Huang2f464bd2022-09-02 11:37:48 +0800179 {"Q50SN12072",
180 ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
181 "new_device", "delete_device",
182 createsHWMon::hasHWMonDir)},
Scron Chang5d11daf2021-07-26 13:38:26 +0800183 {"MAX31790",
184 ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700185 "new_device", "delete_device",
186 createsHWMon::hasHWMonDir)},
Saitwal, Meghan5e9a3052023-04-13 11:35:29 +0000187 {"PIC32", ExportTemplate("pic32 $Address",
188 "/sys/bus/i2c/devices/i2c-$Bus", "new_device",
189 "delete_device", createsHWMon::hasHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800190 {"INA226",
191 ExportTemplate("ina226 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
192 "new_device", "delete_device",
193 createsHWMon::hasHWMonDir)},
Yung Sheng Huang6d524272022-09-02 11:47:10 +0800194 {"RAA229620",
195 ExportTemplate("raa229620 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
196 "new_device", "delete_device",
197 createsHWMon::hasHWMonDir)},
198 {"RAA229621",
199 ExportTemplate("raa229621 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
200 "new_device", "delete_device",
201 createsHWMon::hasHWMonDir)},
Matt Simmeringe7fb1112023-04-25 13:14:33 -0700202 {"PIC32",
203 ExportTemplate("pic32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Konstantin Aladyshev016f1212023-02-20 18:37:10 +0300204 "new_device", "delete_device",
Zev Weisse22143d2022-08-03 16:29:06 -0700205 createsHWMon::hasHWMonDir)}}};
Jae Hyun Yoo9cdeabb2018-10-16 11:47:09 -0700206} // namespace devices