blob: 25ce2e332ae3cf4db3faa4091ac84f2b2a3f6f66 [file] [log] [blame]
Alexander Hansen4e1142d2025-07-25 17:07:27 +02001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
James Feist053a6642018-10-15 13:17:09 -07003
4#pragma once
5#include <boost/container/flat_map.hpp>
6
7namespace devices
8{
9
10struct CmpStr
11{
James Feista465ccc2019-02-08 12:51:01 -080012 bool operator()(const char* a, const char* b) const
James Feist053a6642018-10-15 13:17:09 -070013 {
14 return std::strcmp(a, b) < 0;
15 }
16};
17
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070018// I2C device drivers may create a /hwmon subdirectory. For example the tmp75
19// driver creates a /sys/bus/i2c/devices/<busnum>-<i2caddr>/hwmon
20// directory. The sensor code relies on the presence of the /hwmon
21// subdirectory to collect sensor readings. Initialization of this subdir is
22// not reliable. I2C devices flagged with hasHWMonDir are tested for correct
23// initialization, and when a failure is detected the device is deleted, and
24// then recreated. The default is to retry 5 times before moving to the next
25// device.
26
27// Devices such as I2C EEPROMs do not generate this file structure. These
28// kinds of devices are flagged using the noHWMonDir enumeration. The
29// expectation is they are created correctly on the first attempt.
30
31// This enumeration class exists to reduce copy/paste errors. It is easy to
32// overlook the trailing parameter in the ExportTemplate structure when it is
33// a simple boolean.
34enum class createsHWMon : bool
35{
36 noHWMonDir,
37 hasHWMonDir
38};
39
James Feist053a6642018-10-15 13:17:09 -070040struct ExportTemplate
41{
Zev Weissc11b5da2022-07-12 16:31:37 -070042 ExportTemplate(const char* params, const char* bus, const char* constructor,
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070043 const char* destructor, createsHWMon hasHWMonDir) :
Patrick Williamsb7077432024-08-16 15:22:21 -040044 parameters(params), busPath(bus), add(constructor), remove(destructor),
45 hasHWMonDir(hasHWMonDir) {};
James Feista465ccc2019-02-08 12:51:01 -080046 const char* parameters;
Zev Weissc11b5da2022-07-12 16:31:37 -070047 const char* busPath;
Johnathan Mantey9b867872020-10-13 15:00:51 -070048 const char* add;
49 const char* remove;
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070050 createsHWMon hasHWMonDir;
James Feist053a6642018-10-15 13:17:09 -070051};
52
James Feista465ccc2019-02-08 12:51:01 -080053const boost::container::flat_map<const char*, ExportTemplate, CmpStr>
Devjit Gopalpur4acdc542019-10-10 22:47:46 -070054 exportTemplates{
Vijay Khemka48328412021-04-12 23:14:53 +000055 {{"EEPROM_24C01",
56 ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070057 "new_device", "delete_device",
58 createsHWMon::noHWMonDir)},
Vijay Khemka48328412021-04-12 23:14:53 +000059 {"EEPROM_24C02",
Johnathan Mantey9b867872020-10-13 15:00:51 -070060 ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070061 "new_device", "delete_device",
62 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070063 {"EEPROM_24C04",
64 ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070065 "new_device", "delete_device",
66 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070067 {"EEPROM_24C08",
68 ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070069 "new_device", "delete_device",
70 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070071 {"EEPROM_24C16",
72 ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070073 "new_device", "delete_device",
74 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070075 {"EEPROM_24C32",
76 ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070077 "new_device", "delete_device",
78 createsHWMon::noHWMonDir)},
Hao Jiangf64d4392021-02-23 14:22:03 -080079 {"EEPROM_24C64",
Johnathan Mantey9b867872020-10-13 15:00:51 -070080 ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070081 "new_device", "delete_device",
82 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070083 {"EEPROM_24C128",
84 ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070085 "new_device", "delete_device",
86 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070087 {"EEPROM_24C256",
88 ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070089 "new_device", "delete_device",
90 createsHWMon::noHWMonDir)},
Joseph Fu9fa8f412022-11-07 09:23:33 +080091 {"ADS1015",
92 ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
93 "new_device", "delete_device",
94 createsHWMon::noHWMonDir)},
Michal Bieleckiff503d82022-04-29 10:20:08 +020095 {"ADS7828",
96 ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070097 "new_device", "delete_device",
98 createsHWMon::noHWMonDir)},
Johnathan Mantey9b867872020-10-13 15:00:51 -070099 {"EEPROM",
100 ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700101 "new_device", "delete_device",
102 createsHWMon::noHWMonDir)},
Johnathan Mantey9b867872020-10-13 15:00:51 -0700103 {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700104 "unexport", createsHWMon::noHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800105 {"IPSPS1",
106 ExportTemplate("ipsps1 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
107 "new_device", "delete_device",
108 createsHWMon::hasHWMonDir)},
Nan Zhou296667f2021-02-23 09:53:14 -0800109 {"MAX34440",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700110 ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700111 "new_device", "delete_device",
112 createsHWMon::hasHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800113 {"PCA9537",
114 ExportTemplate("pca9537 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
115 "new_device", "delete_device",
116 createsHWMon::noHWMonDir)},
Jan Sowinski50b2e0f2022-05-06 16:47:12 +0200117 {"PCA9542Mux",
118 ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700119 "new_device", "delete_device",
120 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700121 {"PCA9543Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700122 ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700123 "new_device", "delete_device",
124 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700125 {"PCA9544Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700126 ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700127 "new_device", "delete_device",
128 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700129 {"PCA9545Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700130 ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700131 "new_device", "delete_device",
132 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700133 {"PCA9546Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700134 ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700135 "new_device", "delete_device",
136 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700137 {"PCA9547Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700138 ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700139 "new_device", "delete_device",
140 createsHWMon::noHWMonDir)},
Sujoy Raye4dc1402022-04-15 10:28:34 -0700141 {"PCA9548Mux",
142 ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700143 "new_device", "delete_device",
144 createsHWMon::noHWMonDir)},
Jan Sowinski50b2e0f2022-05-06 16:47:12 +0200145 {"PCA9846Mux",
146 ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700147 "new_device", "delete_device",
148 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800149 {"PCA9847Mux",
150 ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700151 "new_device", "delete_device",
152 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800153 {"PCA9848Mux",
154 ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700155 "new_device", "delete_device",
156 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800157 {"PCA9849Mux",
158 ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700159 "new_device", "delete_device",
160 createsHWMon::noHWMonDir)},
Yung Sheng Huang2ca85292022-07-15 09:59:50 +0800161 {"SIC450",
162 ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700163 "new_device", "delete_device",
164 createsHWMon::hasHWMonDir)},
Yung Sheng Huang2f464bd2022-09-02 11:37:48 +0800165 {"Q50SN12072",
166 ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
167 "new_device", "delete_device",
168 createsHWMon::hasHWMonDir)},
Scron Chang5d11daf2021-07-26 13:38:26 +0800169 {"MAX31790",
170 ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700171 "new_device", "delete_device",
172 createsHWMon::hasHWMonDir)},
Saitwal, Meghan5e9a3052023-04-13 11:35:29 +0000173 {"PIC32", ExportTemplate("pic32 $Address",
174 "/sys/bus/i2c/devices/i2c-$Bus", "new_device",
175 "delete_device", createsHWMon::hasHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800176 {"INA226",
177 ExportTemplate("ina226 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
178 "new_device", "delete_device",
179 createsHWMon::hasHWMonDir)},
Yung Sheng Huang6d524272022-09-02 11:47:10 +0800180 {"RAA229620",
181 ExportTemplate("raa229620 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
182 "new_device", "delete_device",
183 createsHWMon::hasHWMonDir)},
184 {"RAA229621",
185 ExportTemplate("raa229621 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
186 "new_device", "delete_device",
187 createsHWMon::hasHWMonDir)},
Matt Simmeringe7fb1112023-04-25 13:14:33 -0700188 {"PIC32",
189 ExportTemplate("pic32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Konstantin Aladyshev016f1212023-02-20 18:37:10 +0300190 "new_device", "delete_device",
Zev Weisse22143d2022-08-03 16:29:06 -0700191 createsHWMon::hasHWMonDir)}}};
Jae Hyun Yoo9cdeabb2018-10-16 11:47:09 -0700192} // namespace devices