blob: 23c4df7b045c0acd3130dd8a12b0274cadacfdfa [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) :
Johnathan Mantey9b867872020-10-13 15:00:51 -070058 parameters(params),
Zev Weissc11b5da2022-07-12 16:31:37 -070059 busPath(bus), add(constructor), remove(destructor),
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070060 hasHWMonDir(hasHWMonDir){};
James Feista465ccc2019-02-08 12:51:01 -080061 const char* parameters;
Zev Weissc11b5da2022-07-12 16:31:37 -070062 const char* busPath;
Johnathan Mantey9b867872020-10-13 15:00:51 -070063 const char* add;
64 const char* remove;
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070065 createsHWMon hasHWMonDir;
James Feist053a6642018-10-15 13:17:09 -070066};
67
James Feista465ccc2019-02-08 12:51:01 -080068const boost::container::flat_map<const char*, ExportTemplate, CmpStr>
Devjit Gopalpur4acdc542019-10-10 22:47:46 -070069 exportTemplates{
Vijay Khemka48328412021-04-12 23:14:53 +000070 {{"EEPROM_24C01",
71 ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070072 "new_device", "delete_device",
73 createsHWMon::noHWMonDir)},
Vijay Khemka48328412021-04-12 23:14:53 +000074 {"EEPROM_24C02",
Johnathan Mantey9b867872020-10-13 15:00:51 -070075 ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070076 "new_device", "delete_device",
77 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070078 {"EEPROM_24C04",
79 ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070080 "new_device", "delete_device",
81 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070082 {"EEPROM_24C08",
83 ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070084 "new_device", "delete_device",
85 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070086 {"EEPROM_24C16",
87 ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070088 "new_device", "delete_device",
89 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070090 {"EEPROM_24C32",
91 ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070092 "new_device", "delete_device",
93 createsHWMon::noHWMonDir)},
Hao Jiangf64d4392021-02-23 14:22:03 -080094 {"EEPROM_24C64",
Johnathan Mantey9b867872020-10-13 15:00:51 -070095 ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -070096 "new_device", "delete_device",
97 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -070098 {"EEPROM_24C128",
99 ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700100 "new_device", "delete_device",
101 createsHWMon::noHWMonDir)},
Jae Hyun Yoo86022012022-04-01 16:04:29 -0700102 {"EEPROM_24C256",
103 ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700104 "new_device", "delete_device",
105 createsHWMon::noHWMonDir)},
Joseph Fu9fa8f412022-11-07 09:23:33 +0800106 {"ADS1015",
107 ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
108 "new_device", "delete_device",
109 createsHWMon::noHWMonDir)},
Michal Bieleckiff503d82022-04-29 10:20:08 +0200110 {"ADS7828",
111 ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700112 "new_device", "delete_device",
113 createsHWMon::noHWMonDir)},
Johnathan Mantey9b867872020-10-13 15:00:51 -0700114 {"EEPROM",
115 ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700116 "new_device", "delete_device",
117 createsHWMon::noHWMonDir)},
Johnathan Mantey9b867872020-10-13 15:00:51 -0700118 {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700119 "unexport", createsHWMon::noHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800120 {"IPSPS1",
121 ExportTemplate("ipsps1 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
122 "new_device", "delete_device",
123 createsHWMon::hasHWMonDir)},
Nan Zhou296667f2021-02-23 09:53:14 -0800124 {"MAX34440",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700125 ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700126 "new_device", "delete_device",
127 createsHWMon::hasHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800128 {"PCA9537",
129 ExportTemplate("pca9537 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
130 "new_device", "delete_device",
131 createsHWMon::noHWMonDir)},
Jan Sowinski50b2e0f2022-05-06 16:47:12 +0200132 {"PCA9542Mux",
133 ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700134 "new_device", "delete_device",
135 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700136 {"PCA9543Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700137 ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700138 "new_device", "delete_device",
139 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700140 {"PCA9544Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700141 ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700142 "new_device", "delete_device",
143 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700144 {"PCA9545Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700145 ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700146 "new_device", "delete_device",
147 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700148 {"PCA9546Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700149 ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700150 "new_device", "delete_device",
151 createsHWMon::noHWMonDir)},
Devjit Gopalpur4acdc542019-10-10 22:47:46 -0700152 {"PCA9547Mux",
Johnathan Mantey9b867872020-10-13 15:00:51 -0700153 ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700154 "new_device", "delete_device",
155 createsHWMon::noHWMonDir)},
Sujoy Raye4dc1402022-04-15 10:28:34 -0700156 {"PCA9548Mux",
157 ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700158 "new_device", "delete_device",
159 createsHWMon::noHWMonDir)},
Jan Sowinski50b2e0f2022-05-06 16:47:12 +0200160 {"PCA9846Mux",
161 ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700162 "new_device", "delete_device",
163 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800164 {"PCA9847Mux",
165 ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700166 "new_device", "delete_device",
167 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800168 {"PCA9848Mux",
169 ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700170 "new_device", "delete_device",
171 createsHWMon::noHWMonDir)},
Jiaqing Zhao88333fe2022-05-06 15:00:15 +0800172 {"PCA9849Mux",
173 ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700174 "new_device", "delete_device",
175 createsHWMon::noHWMonDir)},
Yung Sheng Huang2ca85292022-07-15 09:59:50 +0800176 {"SIC450",
177 ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700178 "new_device", "delete_device",
179 createsHWMon::hasHWMonDir)},
Yung Sheng Huang2f464bd2022-09-02 11:37:48 +0800180 {"Q50SN12072",
181 ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
182 "new_device", "delete_device",
183 createsHWMon::hasHWMonDir)},
Scron Chang5d11daf2021-07-26 13:38:26 +0800184 {"MAX31790",
185 ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Johnathan Mantey7b21ef22022-08-08 12:57:55 -0700186 "new_device", "delete_device",
187 createsHWMon::hasHWMonDir)},
Saitwal, Meghan5e9a3052023-04-13 11:35:29 +0000188 {"PIC32", ExportTemplate("pic32 $Address",
189 "/sys/bus/i2c/devices/i2c-$Bus", "new_device",
190 "delete_device", createsHWMon::hasHWMonDir)},
Tingting Chena591d6c2022-11-21 19:20:11 +0800191 {"INA226",
192 ExportTemplate("ina226 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
193 "new_device", "delete_device",
194 createsHWMon::hasHWMonDir)},
Yung Sheng Huang6d524272022-09-02 11:47:10 +0800195 {"RAA229620",
196 ExportTemplate("raa229620 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
197 "new_device", "delete_device",
198 createsHWMon::hasHWMonDir)},
199 {"RAA229621",
200 ExportTemplate("raa229621 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
201 "new_device", "delete_device",
202 createsHWMon::hasHWMonDir)},
Matt Simmeringe7fb1112023-04-25 13:14:33 -0700203 {"PIC32",
204 ExportTemplate("pic32 $Address", "/sys/bus/i2c/devices/i2c-$Bus",
Konstantin Aladyshev016f1212023-02-20 18:37:10 +0300205 "new_device", "delete_device",
Zev Weisse22143d2022-08-03 16:29:06 -0700206 createsHWMon::hasHWMonDir)}}};
Jae Hyun Yoo9cdeabb2018-10-16 11:47:09 -0700207} // namespace devices