| 90 | | |
| 91 | | #define CURRMAG 3 |
| 92 | | #define FANMAG 0 |
| 93 | | #define INMAG 3 |
| 94 | | #define TEMPMAG 3 |
| 95 | | |
| 96 | | /* The following are used in getsysname() below */ |
| 97 | | struct match { |
| 98 | | const char * name, * sysname; |
| 99 | | const int sysmag; |
| 100 | | const char * altsysname; |
| 101 | | }; |
| 102 | | |
| 103 | | static const struct match matches[] = { |
| 104 | | { "beeps", "beep_mask", 0 }, |
| 105 | | { "pwm", "pwm1", 0, "fan1_pwm" }, |
| 106 | | { "vid", "cpu0_vid", INMAG, "in0_ref" }, |
| 107 | | { "remote_temp", "temp2_input", TEMPMAG }, |
| 108 | | { "remote_temp_hyst", "temp2_max_hyst", TEMPMAG }, |
| 109 | | { "remote_temp_low", "temp2_min", TEMPMAG }, |
| 110 | | { "remote_temp_over", "temp2_max", TEMPMAG }, |
| 111 | | { "temp", "temp1_input", TEMPMAG }, |
| 112 | | { "temp_hyst", "temp1_max_hyst", TEMPMAG }, |
| 113 | | { "temp_low", "temp1_min", TEMPMAG }, |
| 114 | | { "temp_over", "temp1_max", TEMPMAG }, |
| 115 | | { "temp_high", "temp1_max", TEMPMAG }, |
| 116 | | { "temp_crit", "temp1_crit", TEMPMAG }, |
| 117 | | { NULL, NULL } |
| 118 | | }; |
| 119 | | |
| 120 | | /* |
| 121 | | Returns the sysfs name and magnitude for a given feature. |
| 122 | | First looks for a sysfs name and magnitude in the feature structure. |
| 123 | | These should be added in chips.c for all non-standard feature names. |
| 124 | | If that fails, converts common /proc feature names |
| 125 | | to their sysfs equivalent, and uses common sysfs magnitude. |
| 126 | | Common magnitudes are #defined above. |
| 127 | | Common conversions are as follows: |
| 128 | | fan%d_min -> fan%d_min (for magnitude) |
| 129 | | fan%d_state -> fan%d_status |
| 130 | | fan%d -> fan_input%d |
| 131 | | pwm%d -> fan%d_pwm |
| 132 | | pwm%d_enable -> fan%d_pwm_enable |
| 133 | | in%d_max -> in%d_max (for magnitude) |
| 134 | | in%d_min -> in%d_min (for magnitude) |
| 135 | | in%d -> in%d_input |
| 136 | | vin%d_max -> in%d_max |
| 137 | | vin%d_min -> in%d_min |
| 138 | | vin%d -> in_input%d |
| 139 | | temp%d_over -> temp%d_max |
| 140 | | temp%d_hyst -> temp%d_max_hyst |
| 141 | | temp%d_max -> temp%d_max (for magnitude) |
| 142 | | temp%d_high -> temp%d_max |
| 143 | | temp%d_min -> temp%d_min (for magnitude) |
| 144 | | temp%d_low -> temp%d_min |
| 145 | | temp%d_state -> temp%d_status |
| 146 | | temp%d -> temp%d_input |
| 147 | | sensor%d -> temp%d_type |
| 148 | | AND all conversions listed in the matches[] structure above. |
| 149 | | |
| 150 | | If that fails, returns old /proc feature name and magnitude. |
| 151 | | |
| 152 | | References: doc/developers/proc in the lm_sensors package; |
| 153 | | Documentation/i2c/sysfs_interface in the kernel |
| 154 | | */ |
| 155 | | static int getsysname(const sensors_chip_feature *feature, char *sysname, |
| 156 | | int *sysmag, char *altsysname) |
| 157 | | { |
| 158 | | const char * name = feature->data.name; |
| 159 | | char last; |
| 160 | | char check; /* used to verify end of string */ |
| 161 | | int num; |
| 162 | | const struct match *m; |
| 163 | | |
| 164 | | /* default to a non-existent alternate name (should rarely be tried) */ |
| 165 | | strcpy(altsysname, "_"); |
| 166 | | |
| 167 | | /* use override in feature structure if present */ |
| 168 | | if(feature->sysname != NULL) { |
| 169 | | strcpy(sysname, feature->sysname); |
| 170 | | if(feature->sysscaling) |
| 171 | | *sysmag = feature->sysscaling; |
| 172 | | else |
| 173 | | *sysmag = feature->scaling; |
| 174 | | if(feature->altsysname != NULL) |
| 175 | | strcpy(altsysname, feature->altsysname); |
| 176 | | return 0; |
| 177 | | } |
| 178 | | |
| 179 | | /* check for constant mappings */ |
| 180 | | for(m = matches; m->name != NULL; m++) { |
| 181 | | if(!strcmp(m->name, name)) { |
| 182 | | strcpy(sysname, m->sysname); |
| 183 | | if (m->altsysname != NULL) |
| 184 | | strcpy(altsysname, m->altsysname); |
| 185 | | *sysmag = m->sysmag; |
| 186 | | return 0; |
| 187 | | } |
| 188 | | } |
| 189 | | |
| 190 | | /* convert common /proc names to common sysfs names */ |
| 191 | | if(sscanf(name, "fan%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') { |
| 192 | | strcpy(sysname, name); |
| 193 | | *sysmag = FANMAG; |
| 194 | | return 0; |
| 195 | | } |
| 196 | | if(sscanf(name, "fan%d_stat%c%c", &num, &last, &check) == 2 && last == 'e') { |
| 197 | | sprintf(sysname, "fan%d_status", num); |
| 198 | | *sysmag = 0; |
| 199 | | return 0; |
| 200 | | } |
| 201 | | if(sscanf(name, "fan%d%c", &num, &check) == 1) { |
| 202 | | sprintf(sysname, "fan%d_input", num); |
| 203 | | *sysmag = FANMAG; |
| 204 | | return 0; |
| 205 | | } |
| 206 | | if(sscanf(name, "pwm%d%c", &num, &check) == 1) { |
| 207 | | strcpy(sysname, name); |
| 208 | | *sysmag = 0; |
| 209 | | sprintf(altsysname, "fan%d_pwm", num); |
| 210 | | return 0; |
| 211 | | } |
| 212 | | if(sscanf(name, "pwm%d_enabl%c%c", &num, &last, &check) == 2 && last == 'e') { |
| 213 | | strcpy(sysname, name); |
| 214 | | *sysmag = 0; |
| 215 | | sprintf(altsysname, "fan%d_pwm_enable", num); |
| 216 | | return 0; |
| 217 | | } |
| 218 | | |
| 219 | | if((sscanf(name, "in%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') |
| 220 | | || (sscanf(name, "in%d_ma%c%c", &num, &last, &check) == 2 && last == 'x')) { |
| 221 | | strcpy(sysname, name); |
| 222 | | *sysmag = INMAG; |
| 223 | | return 0; |
| 224 | | } |
| 225 | | if((sscanf(name, "in%d%c", &num, &check) == 1) |
| 226 | | || (sscanf(name, "vin%d%c", &num, &check) == 1)) { |
| 227 | | sprintf(sysname, "in%d_input", num); |
| 228 | | *sysmag = INMAG; |
| 229 | | return 0; |
| 230 | | } |
| 231 | | if(sscanf(name, "vin%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') { |
| 232 | | sprintf(sysname, "in%d_min", num); |
| 233 | | *sysmag = INMAG; |
| 234 | | return 0; |
| 235 | | } |
| 236 | | if(sscanf(name, "vin%d_ma%c%c", &num, &last, &check) == 2 && last == 'x') { |
| 237 | | sprintf(sysname, "in%d_max", num); |
| 238 | | *sysmag = INMAG; |
| 239 | | return 0; |
| 240 | | } |
| 241 | | |
| 242 | | if(sscanf(name, "temp%d_hys%c%c", &num, &last, &check) == 2 && last == 't') { |
| 243 | | sprintf(sysname, "temp%d_max_hyst", num); |
| 244 | | *sysmag = TEMPMAG; |
| 245 | | return 0; |
| 246 | | } |
| 247 | | if((sscanf(name, "temp%d_ove%c%c", &num, &last, &check) == 2 && last == 'r') |
| 248 | | || (sscanf(name, "temp%d_ma%c%c", &num, &last, &check) == 2 && last == 'x') |
| 249 | | || (sscanf(name, "temp%d_hig%c%c", &num, &last, &check) == 2 && last == 'h')) { |
| 250 | | sprintf(sysname, "temp%d_max", num); |
| 251 | | *sysmag = TEMPMAG; |
| 252 | | return 0; |
| 253 | | } |
| 254 | | if((sscanf(name, "temp%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') |
| 255 | | || (sscanf(name, "temp%d_lo%c%c", &num, &last, &check) == 2 && last == 'w')) { |
| 256 | | sprintf(sysname, "temp%d_min", num); |
| 257 | | *sysmag = TEMPMAG; |
| 258 | | return 0; |
| 259 | | } |
| 260 | | if(sscanf(name, "temp%d_cri%c%c", &num, &last, &check) == 2 && last == 't') { |
| 261 | | sprintf(sysname, "temp%d_crit", num); |
| 262 | | *sysmag = TEMPMAG; |
| 263 | | return 0; |
| 264 | | } |
| 265 | | if(sscanf(name, "temp%d_stat%c%c", &num, &last, &check) == 2 && last == 'e') { |
| 266 | | sprintf(sysname, "temp%d_status", num); |
| 267 | | *sysmag = 0; |
| 268 | | return 0; |
| 269 | | } |
| 270 | | if(sscanf(name, "temp%d%c", &num, &check) == 1) { |
| 271 | | sprintf(sysname, "temp%d_input", num); |
| 272 | | *sysmag = TEMPMAG; |
| 273 | | return 0; |
| 274 | | } |
| 275 | | if(sscanf(name, "sensor%d%c", &num, &check) == 1) { |
| 276 | | sprintf(sysname, "temp%d_type", num); |
| 277 | | *sysmag = 0; |
| 278 | | return 0; |
| 279 | | } |
| 280 | | |
| 281 | | /* bmcsensors only, not yet in kernel */ |
| 282 | | /* |
| 283 | | if((sscanf(name, "curr%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') |
| 284 | | || (sscanf(name, "curr%d_ma%c%c", &num, &last, &check) == 2 && last == 'x')) { |
| 285 | | strcpy(sysname, name); |
| 286 | | *sysmag = CURRMAG; |
| 287 | | return 0; |
| 288 | | } |
| 289 | | if(sscanf(name, "curr%d%c", &num, &check) == 1) { |
| 290 | | sprintf(sysname, "curr%d_input", num); |
| 291 | | *sysmag = CURRMAG; |
| 292 | | return 0; |
| 293 | | } |
| 294 | | */ |
| 295 | | |
| 296 | | /* give up, use old name (probably won't work though...) */ |
| 297 | | /* known to be the same: |
| 298 | | "alarms", "beep_enable", "vrm", "fan%d_div" |
| 299 | | */ |
| 300 | | strcpy(sysname, name); |
| 301 | | *sysmag = feature->scaling; |
| 302 | | return 0; |
| 303 | | } |