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