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 */ 16 /// \file devices.hpp 17 18 #pragma once 19 #include <boost/container/flat_map.hpp> 20 21 namespace devices 22 { 23 24 struct CmpStr 25 { 26 bool operator()(const char* a, const char* b) const 27 { 28 return std::strcmp(a, b) < 0; 29 } 30 }; 31 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 54 struct ExportTemplate 55 { 56 ExportTemplate(const char* params, const char* bus, const char* constructor, 57 const char* destructor, createsHWMon hasHWMonDir) : 58 parameters(params), busPath(bus), add(constructor), remove(destructor), 59 hasHWMonDir(hasHWMonDir) {}; 60 const char* parameters; 61 const char* busPath; 62 const char* add; 63 const char* remove; 64 createsHWMon hasHWMonDir; 65 }; 66 67 const boost::container::flat_map<const char*, ExportTemplate, CmpStr> 68 exportTemplates{ 69 {{"EEPROM_24C01", 70 ExportTemplate("24c01 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 71 "new_device", "delete_device", 72 createsHWMon::noHWMonDir)}, 73 {"EEPROM_24C02", 74 ExportTemplate("24c02 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 75 "new_device", "delete_device", 76 createsHWMon::noHWMonDir)}, 77 {"EEPROM_24C04", 78 ExportTemplate("24c04 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 79 "new_device", "delete_device", 80 createsHWMon::noHWMonDir)}, 81 {"EEPROM_24C08", 82 ExportTemplate("24c08 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 83 "new_device", "delete_device", 84 createsHWMon::noHWMonDir)}, 85 {"EEPROM_24C16", 86 ExportTemplate("24c16 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 87 "new_device", "delete_device", 88 createsHWMon::noHWMonDir)}, 89 {"EEPROM_24C32", 90 ExportTemplate("24c32 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 91 "new_device", "delete_device", 92 createsHWMon::noHWMonDir)}, 93 {"EEPROM_24C64", 94 ExportTemplate("24c64 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 95 "new_device", "delete_device", 96 createsHWMon::noHWMonDir)}, 97 {"EEPROM_24C128", 98 ExportTemplate("24c128 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 99 "new_device", "delete_device", 100 createsHWMon::noHWMonDir)}, 101 {"EEPROM_24C256", 102 ExportTemplate("24c256 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 103 "new_device", "delete_device", 104 createsHWMon::noHWMonDir)}, 105 {"ADS1015", 106 ExportTemplate("ads1015 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 107 "new_device", "delete_device", 108 createsHWMon::noHWMonDir)}, 109 {"ADS7828", 110 ExportTemplate("ads7828 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 111 "new_device", "delete_device", 112 createsHWMon::noHWMonDir)}, 113 {"EEPROM", 114 ExportTemplate("eeprom $Address", "/sys/bus/i2c/devices/i2c-$Bus", 115 "new_device", "delete_device", 116 createsHWMon::noHWMonDir)}, 117 {"Gpio", ExportTemplate("$Index", "/sys/class/gpio", "export", 118 "unexport", createsHWMon::noHWMonDir)}, 119 {"IPSPS1", 120 ExportTemplate("ipsps1 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 121 "new_device", "delete_device", 122 createsHWMon::hasHWMonDir)}, 123 {"MAX34440", 124 ExportTemplate("max34440 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 125 "new_device", "delete_device", 126 createsHWMon::hasHWMonDir)}, 127 {"PCA9537", 128 ExportTemplate("pca9537 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 129 "new_device", "delete_device", 130 createsHWMon::noHWMonDir)}, 131 {"PCA9542Mux", 132 ExportTemplate("pca9542 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 133 "new_device", "delete_device", 134 createsHWMon::noHWMonDir)}, 135 {"PCA9543Mux", 136 ExportTemplate("pca9543 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 137 "new_device", "delete_device", 138 createsHWMon::noHWMonDir)}, 139 {"PCA9544Mux", 140 ExportTemplate("pca9544 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 141 "new_device", "delete_device", 142 createsHWMon::noHWMonDir)}, 143 {"PCA9545Mux", 144 ExportTemplate("pca9545 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 145 "new_device", "delete_device", 146 createsHWMon::noHWMonDir)}, 147 {"PCA9546Mux", 148 ExportTemplate("pca9546 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 149 "new_device", "delete_device", 150 createsHWMon::noHWMonDir)}, 151 {"PCA9547Mux", 152 ExportTemplate("pca9547 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 153 "new_device", "delete_device", 154 createsHWMon::noHWMonDir)}, 155 {"PCA9548Mux", 156 ExportTemplate("pca9548 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 157 "new_device", "delete_device", 158 createsHWMon::noHWMonDir)}, 159 {"PCA9846Mux", 160 ExportTemplate("pca9846 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 161 "new_device", "delete_device", 162 createsHWMon::noHWMonDir)}, 163 {"PCA9847Mux", 164 ExportTemplate("pca9847 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 165 "new_device", "delete_device", 166 createsHWMon::noHWMonDir)}, 167 {"PCA9848Mux", 168 ExportTemplate("pca9848 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 169 "new_device", "delete_device", 170 createsHWMon::noHWMonDir)}, 171 {"PCA9849Mux", 172 ExportTemplate("pca9849 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 173 "new_device", "delete_device", 174 createsHWMon::noHWMonDir)}, 175 {"SIC450", 176 ExportTemplate("sic450 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 177 "new_device", "delete_device", 178 createsHWMon::hasHWMonDir)}, 179 {"Q50SN12072", 180 ExportTemplate("q50sn12072 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 181 "new_device", "delete_device", 182 createsHWMon::hasHWMonDir)}, 183 {"MAX31790", 184 ExportTemplate("max31790 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 185 "new_device", "delete_device", 186 createsHWMon::hasHWMonDir)}, 187 {"PIC32", ExportTemplate("pic32 $Address", 188 "/sys/bus/i2c/devices/i2c-$Bus", "new_device", 189 "delete_device", createsHWMon::hasHWMonDir)}, 190 {"INA226", 191 ExportTemplate("ina226 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 192 "new_device", "delete_device", 193 createsHWMon::hasHWMonDir)}, 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)}, 202 {"PIC32", 203 ExportTemplate("pic32 $Address", "/sys/bus/i2c/devices/i2c-$Bus", 204 "new_device", "delete_device", 205 createsHWMon::hasHWMonDir)}}}; 206 } // namespace devices 207