James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 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 | */ |
Brad Bishop | 1fb9f3f | 2020-08-28 08:15:13 -0400 | [diff] [blame] | 16 | /// \file devices.hpp |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 17 | |
| 18 | #pragma once |
| 19 | #include <boost/container/flat_map.hpp> |
| 20 | |
| 21 | namespace devices |
| 22 | { |
| 23 | |
| 24 | struct CmpStr |
| 25 | { |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 26 | bool operator()(const char* a, const char* b) const |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 27 | { |
| 28 | return std::strcmp(a, b) < 0; |
| 29 | } |
| 30 | }; |
| 31 | |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 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 | |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 54 | struct ExportTemplate |
| 55 | { |
Zev Weiss | c11b5da | 2022-07-12 16:31:37 -0700 | [diff] [blame] | 56 | ExportTemplate(const char* params, const char* bus, const char* constructor, |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 57 | const char* destructor, createsHWMon hasHWMonDir) : |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 58 | parameters(params), |
Zev Weiss | c11b5da | 2022-07-12 16:31:37 -0700 | [diff] [blame] | 59 | busPath(bus), add(constructor), remove(destructor), |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 60 | hasHWMonDir(hasHWMonDir){}; |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 61 | const char* parameters; |
Zev Weiss | c11b5da | 2022-07-12 16:31:37 -0700 | [diff] [blame] | 62 | const char* busPath; |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 63 | const char* add; |
| 64 | const char* remove; |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 65 | createsHWMon hasHWMonDir; |
James Feist | 053a664 | 2018-10-15 13:17:09 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 68 | const boost::container::flat_map<const char*, ExportTemplate, CmpStr> |
Devjit Gopalpur | 4acdc54 | 2019-10-10 22:47:46 -0700 | [diff] [blame] | 69 | exportTemplates{ |
Vijay Khemka | 4832841 | 2021-04-12 23:14:53 +0000 | [diff] [blame] | 70 | {{"EEPROM_24C01", |
| 71 | ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 72 | "new_device", "delete_device", |
| 73 | createsHWMon::noHWMonDir)}, |
Vijay Khemka | 4832841 | 2021-04-12 23:14:53 +0000 | [diff] [blame] | 74 | {"EEPROM_24C02", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 75 | ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 76 | "new_device", "delete_device", |
| 77 | createsHWMon::noHWMonDir)}, |
Jae Hyun Yoo | 8602201 | 2022-04-01 16:04:29 -0700 | [diff] [blame] | 78 | {"EEPROM_24C04", |
| 79 | ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 80 | "new_device", "delete_device", |
| 81 | createsHWMon::noHWMonDir)}, |
Jae Hyun Yoo | 8602201 | 2022-04-01 16:04:29 -0700 | [diff] [blame] | 82 | {"EEPROM_24C08", |
| 83 | ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 84 | "new_device", "delete_device", |
| 85 | createsHWMon::noHWMonDir)}, |
Jae Hyun Yoo | 8602201 | 2022-04-01 16:04:29 -0700 | [diff] [blame] | 86 | {"EEPROM_24C16", |
| 87 | ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 88 | "new_device", "delete_device", |
| 89 | createsHWMon::noHWMonDir)}, |
Jae Hyun Yoo | 8602201 | 2022-04-01 16:04:29 -0700 | [diff] [blame] | 90 | {"EEPROM_24C32", |
| 91 | ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 92 | "new_device", "delete_device", |
| 93 | createsHWMon::noHWMonDir)}, |
Hao Jiang | f64d439 | 2021-02-23 14:22:03 -0800 | [diff] [blame] | 94 | {"EEPROM_24C64", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 95 | ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 96 | "new_device", "delete_device", |
| 97 | createsHWMon::noHWMonDir)}, |
Jae Hyun Yoo | 8602201 | 2022-04-01 16:04:29 -0700 | [diff] [blame] | 98 | {"EEPROM_24C128", |
| 99 | ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 100 | "new_device", "delete_device", |
| 101 | createsHWMon::noHWMonDir)}, |
Jae Hyun Yoo | 8602201 | 2022-04-01 16:04:29 -0700 | [diff] [blame] | 102 | {"EEPROM_24C256", |
| 103 | ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 104 | "new_device", "delete_device", |
| 105 | createsHWMon::noHWMonDir)}, |
Joseph Fu | 9fa8f41 | 2022-11-07 09:23:33 +0800 | [diff] [blame] | 106 | {"ADS1015", |
| 107 | ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
| 108 | "new_device", "delete_device", |
| 109 | createsHWMon::noHWMonDir)}, |
Michal Bielecki | ff503d8 | 2022-04-29 10:20:08 +0200 | [diff] [blame] | 110 | {"ADS7828", |
| 111 | ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 112 | "new_device", "delete_device", |
| 113 | createsHWMon::noHWMonDir)}, |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 114 | {"EEPROM", |
| 115 | ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 116 | "new_device", "delete_device", |
| 117 | createsHWMon::noHWMonDir)}, |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 118 | {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 119 | "unexport", createsHWMon::noHWMonDir)}, |
Tingting Chen | a591d6c | 2022-11-21 19:20:11 +0800 | [diff] [blame] | 120 | {"IPSPS1", |
| 121 | ExportTemplate("ipsps1 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
| 122 | "new_device", "delete_device", |
| 123 | createsHWMon::hasHWMonDir)}, |
Nan Zhou | 296667f | 2021-02-23 09:53:14 -0800 | [diff] [blame] | 124 | {"MAX34440", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 125 | ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 126 | "new_device", "delete_device", |
| 127 | createsHWMon::hasHWMonDir)}, |
Tingting Chen | a591d6c | 2022-11-21 19:20:11 +0800 | [diff] [blame] | 128 | {"PCA9537", |
| 129 | ExportTemplate("pca9537 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
| 130 | "new_device", "delete_device", |
| 131 | createsHWMon::noHWMonDir)}, |
Jan Sowinski | 50b2e0f | 2022-05-06 16:47:12 +0200 | [diff] [blame] | 132 | {"PCA9542Mux", |
| 133 | ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 134 | "new_device", "delete_device", |
| 135 | createsHWMon::noHWMonDir)}, |
Devjit Gopalpur | 4acdc54 | 2019-10-10 22:47:46 -0700 | [diff] [blame] | 136 | {"PCA9543Mux", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 137 | ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 138 | "new_device", "delete_device", |
| 139 | createsHWMon::noHWMonDir)}, |
Devjit Gopalpur | 4acdc54 | 2019-10-10 22:47:46 -0700 | [diff] [blame] | 140 | {"PCA9544Mux", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 141 | ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 142 | "new_device", "delete_device", |
| 143 | createsHWMon::noHWMonDir)}, |
Devjit Gopalpur | 4acdc54 | 2019-10-10 22:47:46 -0700 | [diff] [blame] | 144 | {"PCA9545Mux", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 145 | ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 146 | "new_device", "delete_device", |
| 147 | createsHWMon::noHWMonDir)}, |
Devjit Gopalpur | 4acdc54 | 2019-10-10 22:47:46 -0700 | [diff] [blame] | 148 | {"PCA9546Mux", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 149 | ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 150 | "new_device", "delete_device", |
| 151 | createsHWMon::noHWMonDir)}, |
Devjit Gopalpur | 4acdc54 | 2019-10-10 22:47:46 -0700 | [diff] [blame] | 152 | {"PCA9547Mux", |
Johnathan Mantey | 9b86787 | 2020-10-13 15:00:51 -0700 | [diff] [blame] | 153 | ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 154 | "new_device", "delete_device", |
| 155 | createsHWMon::noHWMonDir)}, |
Sujoy Ray | e4dc140 | 2022-04-15 10:28:34 -0700 | [diff] [blame] | 156 | {"PCA9548Mux", |
| 157 | ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 158 | "new_device", "delete_device", |
| 159 | createsHWMon::noHWMonDir)}, |
Jan Sowinski | 50b2e0f | 2022-05-06 16:47:12 +0200 | [diff] [blame] | 160 | {"PCA9846Mux", |
| 161 | ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 162 | "new_device", "delete_device", |
| 163 | createsHWMon::noHWMonDir)}, |
Jiaqing Zhao | 88333fe | 2022-05-06 15:00:15 +0800 | [diff] [blame] | 164 | {"PCA9847Mux", |
| 165 | ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 166 | "new_device", "delete_device", |
| 167 | createsHWMon::noHWMonDir)}, |
Jiaqing Zhao | 88333fe | 2022-05-06 15:00:15 +0800 | [diff] [blame] | 168 | {"PCA9848Mux", |
| 169 | ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 170 | "new_device", "delete_device", |
| 171 | createsHWMon::noHWMonDir)}, |
Jiaqing Zhao | 88333fe | 2022-05-06 15:00:15 +0800 | [diff] [blame] | 172 | {"PCA9849Mux", |
| 173 | ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 174 | "new_device", "delete_device", |
| 175 | createsHWMon::noHWMonDir)}, |
Yung Sheng Huang | 2ca8529 | 2022-07-15 09:59:50 +0800 | [diff] [blame] | 176 | {"SIC450", |
| 177 | ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 178 | "new_device", "delete_device", |
| 179 | createsHWMon::hasHWMonDir)}, |
Yung Sheng Huang | 2f464bd | 2022-09-02 11:37:48 +0800 | [diff] [blame] | 180 | {"Q50SN12072", |
| 181 | ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
| 182 | "new_device", "delete_device", |
| 183 | createsHWMon::hasHWMonDir)}, |
Scron Chang | 5d11daf | 2021-07-26 13:38:26 +0800 | [diff] [blame] | 184 | {"MAX31790", |
| 185 | ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Johnathan Mantey | 7b21ef2 | 2022-08-08 12:57:55 -0700 | [diff] [blame] | 186 | "new_device", "delete_device", |
| 187 | createsHWMon::hasHWMonDir)}, |
Saitwal, Meghan | 5e9a305 | 2023-04-13 11:35:29 +0000 | [diff] [blame] | 188 | {"PIC32", ExportTemplate("pic32 $Address", |
| 189 | "/sys/bus/i2c/devices/i2c-$Bus", "new_device", |
| 190 | "delete_device", createsHWMon::hasHWMonDir)}, |
Tingting Chen | a591d6c | 2022-11-21 19:20:11 +0800 | [diff] [blame] | 191 | {"INA226", |
| 192 | ExportTemplate("ina226 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
| 193 | "new_device", "delete_device", |
| 194 | createsHWMon::hasHWMonDir)}, |
Yung Sheng Huang | 6d52427 | 2022-09-02 11:47:10 +0800 | [diff] [blame] | 195 | {"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 Simmering | e7fb111 | 2023-04-25 13:14:33 -0700 | [diff] [blame] | 203 | {"PIC32", |
| 204 | ExportTemplate("pic32 $Address", "/sys/bus/i2c/devices/i2c-$Bus", |
Konstantin Aladyshev | 016f121 | 2023-02-20 18:37:10 +0300 | [diff] [blame] | 205 | "new_device", "delete_device", |
Zev Weiss | e22143d | 2022-08-03 16:29:06 -0700 | [diff] [blame] | 206 | createsHWMon::hasHWMonDir)}}}; |
Jae Hyun Yoo | 9cdeabb | 2018-10-16 11:47:09 -0700 | [diff] [blame] | 207 | } // namespace devices |