| 75 | | /* SMBus capabilities */ |
| 76 | | #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \ |
| 77 | | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA) |
| 78 | | #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \ |
| 79 | | I2C_FUNC_SMBUS_WORD_DATA) |
| 80 | | |
| 81 | | /* LM93 BLOCK READ COMMANDS */ |
| 82 | | static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = { |
| 83 | | { 0xf2, 8 }, |
| 84 | | { 0xf3, 8 }, |
| 85 | | { 0xf4, 6 }, |
| 86 | | { 0xf5, 16 }, |
| 87 | | { 0xf6, 4 }, |
| 88 | | { 0xf7, 8 }, |
| 89 | | { 0xf8, 12 }, |
| 90 | | { 0xf9, 32 }, |
| 91 | | { 0xfa, 8 }, |
| 92 | | { 0xfb, 8 }, |
| 93 | | { 0xfc, 16 }, |
| 94 | | { 0xfd, 9 }, |
| 95 | | }; |
| 96 | | |
| 97 | | /* CONVERSIONS */ |
| 98 | | |
| 99 | | /* fan tach register to/from tach values */ |
| 100 | | static const u8 lm93_tach_reg_to_value[16] = |
| 101 | | { 0x00, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, |
| 102 | | 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff, 0x00, 0x00 }; |
| 103 | | |
| 104 | | /* min, max, and nominal voltage readings, per channel (mV)*/ |
| 105 | | static const unsigned long lm93_vin_val_min[16] = { |
| 106 | | 0, 0, 0, 0, 0, 0, 0, 0, |
| 107 | | 0, 0, 0, 0, 0, 0, 0, 3000, |
| 108 | | }; |
| 109 | | static const unsigned long lm93_vin_val_max[16] = { |
| 110 | | 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600, |
| 111 | | 4400, 6667, 3333, 2625, 1312, 1312, 1236, 3600, |
| 112 | | }; |
| 113 | | /* |
| 114 | | static const unsigned long lm93_vin_val_nom[16] = { |
| 115 | | 927, 927, 927, 1200, 1500, 1500, 1200, 1200, |
| 116 | | 3300, 5000, 2500, 1969, 984, 984, 309, 3300, |
| 117 | | }; |
| 118 | | */ |
| 119 | | |
| 120 | | /* min, max, and nominal register values, per channel (u8) */ |
| 121 | | static const u8 lm93_vin_reg_min[16] = { |
| 122 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 123 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, |
| 124 | | }; |
| 125 | | static const u8 lm93_vin_reg_max[16] = { |
| 126 | | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 127 | | 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1, |
| 128 | | }; |
| 129 | | /* |
| 130 | | static const u8 lm93_vin_reg_nom[16] = { |
| 131 | | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, |
| 132 | | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, |
| 133 | | }; |
| 134 | | */ |
| 135 | | |
| 136 | | /* IN: 1/100 V, limits determined by channel nr |
| 137 | | REG: scaling determined by channel nr */ |
| 138 | | static u8 LM93_IN_TO_REG(int nr, unsigned val) |
| 139 | | { |
| 140 | | /* range limit */ |
| 141 | | const long mV = SENSORS_LIMIT(val * 10, |
| 142 | | lm93_vin_val_min[nr], lm93_vin_val_max[nr]); |
| 143 | | |
| 144 | | /* try not to lose too much precision here */ |
| 145 | | const long uV = mV * 1000; |
| 146 | | const long uV_max = lm93_vin_val_max[nr] * 1000; |
| 147 | | const long uV_min = lm93_vin_val_min[nr] * 1000; |
| 148 | | |
| 149 | | /* convert */ |
| 150 | | const long slope = (uV_max - uV_min) / |
| 151 | | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); |
| 152 | | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
| 153 | | |
| 154 | | u8 result = ((uV - intercept + (slope/2)) / slope); |
| 155 | | result = SENSORS_LIMIT(result, |
| 156 | | lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); |
| 157 | | return result; |
| 158 | | } |
| 159 | | |
| 160 | | static unsigned LM93_IN_FROM_REG(int nr, u8 reg) |
| 161 | | { |
| 162 | | const long uV_max = lm93_vin_val_max[nr] * 1000; |
| 163 | | const long uV_min = lm93_vin_val_min[nr] * 1000; |
| 164 | | |
| 165 | | const long slope = (uV_max - uV_min) / |
| 166 | | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); |
| 167 | | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
| 168 | | |
| 169 | | return (slope * reg + intercept + 5000) / 10000; |
| 170 | | } |
| 171 | | |
| 172 | | /* vid in mV , upper == 0 indicates low limit, otherwise upper limit |
| 173 | | upper also determines which nibble of the register is returned |
| 174 | | (the other nibble will be 0x0) */ |
| 175 | | static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) |
| 176 | | { |
| 177 | | long uV_offset = vid * 1000 - val * 10000; |
| 178 | | if (upper) { |
| 179 | | uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000); |
| 180 | | return (u8)((uV_offset / 12500 - 1) << 4); |
| 181 | | } else { |
| 182 | | uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000); |
| 183 | | return (u8)((uV_offset / -25000 - 1) << 0); |
| 184 | | } |
| 185 | | } |
| 186 | | |
| 187 | | /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */ |
| 188 | | static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid) |
| 189 | | { |
| 190 | | const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) : |
| 191 | | (((reg >> 0 & 0x0f) + 1) * -25000); |
| 192 | | const long uV_vid = vid * 1000; |
| 193 | | return (uV_vid + uV_offset + 5000) / 10000; |
| 194 | | } |
| 195 | | |
| 196 | | #define LM93_TEMP_MIN (-1280) |
| 197 | | #define LM93_TEMP_MAX ( 1270) |
| 198 | | |
| 199 | | /* TEMP: 1/10 degrees C (-128C to +127C) |
| 200 | | REG: 1C/bit, two's complement */ |
| 201 | | static u8 LM93_TEMP_TO_REG(int temp) |
| 202 | | { |
| 203 | | int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); |
| 204 | | ntemp += (ntemp<0 ? -5 : 5); |
| 205 | | return (u8)(ntemp / 10); |
| 206 | | } |
| 207 | | |
| 208 | | static int LM93_TEMP_FROM_REG(u8 reg) |
| 209 | | { |
| 210 | | return (s8)reg * 10; |
| 211 | | } |
| 212 | | |
| 213 | | /* Determine 4-bit temperature offset resolution */ |
| 214 | | static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr) |
| 215 | | { |
| 216 | | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| 217 | | return sfc2 & (nr < 2 ? 0x10 : 0x20); |
| 218 | | } |
| 219 | | |
| 220 | | #define LM93_TEMP_OFFSET_MIN ( 0) |
| 221 | | #define LM93_TEMP_OFFSET_MAX0 (150) |
| 222 | | #define LM93_TEMP_OFFSET_MAX1 ( 75) |
| 223 | | |
| 224 | | /* This function is common to all 4-bit temperature offsets |
| 225 | | returns 4 bits right justified |
| 226 | | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ |
| 227 | | static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) |
| 228 | | { |
| 229 | | int factor = mode ? 5 : 10; |
| 230 | | |
| 231 | | off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN, |
| 232 | | mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); |
| 233 | | return (u8)((off + factor/2) / factor); |
| 234 | | } |
| 235 | | |
| 236 | | /* This function is common to all 4-bit temperature offsets |
| 237 | | reg is 4 bits right justified |
| 238 | | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ |
| 239 | | static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode) |
| 240 | | { |
| 241 | | return (reg & 0x0f) * (mode ? 5 : 10); |
| 242 | | } |
| 243 | | |
| 244 | | /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero)) |
| 245 | | REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero) |
| 246 | | 0 <= nr <= 3 */ |
| 247 | | static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode) |
| 248 | | { |
| 249 | | u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode); |
| 250 | | |
| 251 | | /* temp1-temp2 (nr=0,1) use lower nibble */ |
| 252 | | if (nr < 2) |
| 253 | | return (old & 0xf0) | (new & 0x0f); |
| 254 | | |
| 255 | | /* temp3-temp4 (nr=2,3) use upper nibble */ |
| 256 | | else |
| 257 | | return (new << 4 & 0xf0) | (old & 0x0f); |
| 258 | | } |
| 259 | | |
| 260 | | /* 0 <= nr <= 3 */ |
| 261 | | static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode) |
| 262 | | { |
| 263 | | /* temp1-temp2 (nr=0,1) use lower nibble */ |
| 264 | | if (nr < 2) |
| 265 | | return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode); |
| 266 | | |
| 267 | | /* temp3-temp4 (nr=2,3) use upper nibble */ |
| 268 | | else |
| 269 | | return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode); |
| 270 | | } |
| 271 | | |
| 272 | | /* RPM: (82.5 to 1350000) |
| 273 | | REG: 14-bits, LE, *left* justified */ |
| 274 | | static u16 LM93_FAN_TO_REG(long rpm) |
| 275 | | { |
| 276 | | u16 count, regs; |
| 277 | | |
| 278 | | if (rpm == 0) { |
| 279 | | count = 0x3fff; |
| 280 | | } else { |
| 281 | | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| 282 | | count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe); |
| 283 | | } |
| 284 | | |
| 285 | | regs = count << 2; |
| 286 | | return cpu_to_le16(regs); |
| 287 | | } |
| 288 | | |
| 289 | | static int LM93_FAN_FROM_REG(u16 regs) |
| 290 | | { |
| 291 | | const u16 count = le16_to_cpu(regs) >> 2; |
| 292 | | return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count; |
| 293 | | } |
| 294 | | |
| 295 | | /* VID: mV |
| 296 | | REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */ |
| 297 | | static int LM93_VID_FROM_REG(u8 reg) |
| 298 | | { |
| 299 | | return vid_from_reg((reg & 0x3f), 100); |
| 300 | | } |
| 301 | | |
| 302 | | /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6% |
| 303 | | * REG: (same) */ |
| 304 | | static u8 LM93_PROCHOT_TO_REG(long prochot) |
| 305 | | { |
| 306 | | prochot = SENSORS_LIMIT(prochot, 0, 255); |
| 307 | | return (u8)prochot; |
| 308 | | } |
| 309 | | |
| 310 | | /* PROCHOT-OVERRIDE; 0-15, 0 is 6.25%, 15 is 99.88% |
| 311 | | * REG: (same) */ |
| 312 | | static u8 LM93_PROCHOT_OVERRIDE_TO_REG(int force1, int force2, long prochot) |
| 313 | | { |
| 314 | | u8 result = 0; |
| 315 | | |
| 316 | | result |= force1 ? 0x80 : 0x00; |
| 317 | | result |= force2 ? 0x40 : 0x00; |
| 318 | | prochot = SENSORS_LIMIT(prochot, 0, 15); |
| 319 | | result |= prochot; |
| 320 | | return result; |
| 321 | | } |
| 322 | | |
| 323 | | /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds) |
| 324 | | * REG: 0-9 as mapped below */ |
| 325 | | static int lm93_interval_map[10] = { |
| 326 | | 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200, |
| 327 | | }; |
| 328 | | |
| 329 | | static int LM93_INTERVAL_FROM_REG(u8 reg) |
| 330 | | { |
| 331 | | return lm93_interval_map[reg & 0x0f]; |
| 332 | | } |
| 333 | | |
| 334 | | /* round up to nearest match */ |
| 335 | | static u8 LM93_INTERVAL_TO_REG(long interval) |
| 336 | | { |
| 337 | | int i; |
| 338 | | for (i = 0; i < 9; i++) |
| 339 | | if (interval <= lm93_interval_map[i]) |
| 340 | | break; |
| 341 | | |
| 342 | | /* can fall through with i==9 */ |
| 343 | | return (u8)i; |
| 344 | | } |
| 345 | | |
| 346 | | /* PWM: 0-255 per sensors documentation |
| 347 | | REG: 0-13 as mapped below... right justified */ |
| 348 | | typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t; |
| 349 | | static int lm93_pwm_map[2][14] = { |
| 350 | | { |
| 351 | | 0x00, /* 0.00% */ 0x40, /* 25.00% */ |
| 352 | | 0x50, /* 31.25% */ 0x60, /* 37.50% */ |
| 353 | | 0x70, /* 43.75% */ 0x80, /* 50.00% */ |
| 354 | | 0x90, /* 56.25% */ 0xa0, /* 62.50% */ |
| 355 | | 0xb0, /* 68.75% */ 0xc0, /* 75.00% */ |
| 356 | | 0xd0, /* 81.25% */ 0xe0, /* 87.50% */ |
| 357 | | 0xf0, /* 93.75% */ 0xff, /* 100.00% */ |
| 358 | | }, |
| 359 | | { |
| 360 | | 0x00, /* 0.00% */ 0x40, /* 25.00% */ |
| 361 | | 0x49, /* 28.57% */ 0x52, /* 32.14% */ |
| 362 | | 0x5b, /* 35.71% */ 0x64, /* 39.29% */ |
| 363 | | 0x6d, /* 42.86% */ 0x76, /* 46.43% */ |
| 364 | | 0x80, /* 50.00% */ 0x89, /* 53.57% */ |
| 365 | | 0x92, /* 57.14% */ 0xb6, /* 71.43% */ |
| 366 | | 0xdb, /* 85.71% */ 0xff, /* 100.00% */ |
| 367 | | }, |
| 368 | | }; |
| 369 | | |
| 370 | | static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq) |
| 371 | | { |
| 372 | | return lm93_pwm_map[freq][reg & 0x0f]; |
| 373 | | } |
| 374 | | |
| 375 | | /* round up to nearest match */ |
| 376 | | static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq) |
| 377 | | { |
| 378 | | int i; |
| 379 | | for (i = 0; i < 13; i++) |
| 380 | | if (pwm <= lm93_pwm_map[freq][i]) |
| 381 | | break; |
| 382 | | |
| 383 | | /* can fall through with i==13 */ |
| 384 | | return (u8)i; |
| 385 | | } |
| 386 | | |
| 387 | | /* PWM FREQ: HZ |
| 388 | | REG: 0-7 as mapped below */ |
| 389 | | static int lm93_pwm_freq_map[8] = { |
| 390 | | 22500, 96, 84, 72, 60, 48, 36, 12 |
| 391 | | }; |
| 392 | | |
| 393 | | static int LM93_PWM_FREQ_FROM_REG(u8 reg) |
| 394 | | { |
| 395 | | return lm93_pwm_freq_map[reg & 0x07]; |
| 396 | | } |
| 397 | | |
| 398 | | /* round up to nearest match */ |
| 399 | | static u8 LM93_PWM_FREQ_TO_REG(int freq) |
| 400 | | { |
| 401 | | int i; |
| 402 | | for (i = 7; i > 0; i--) |
| 403 | | if (freq <= lm93_pwm_freq_map[i]) |
| 404 | | break; |
| 405 | | |
| 406 | | /* can fall through with i==0 */ |
| 407 | | return (u8)i; |
| 408 | | } |
| 409 | | |
| 410 | | /* GPIO: 0-255, GPIO0 is LSB |
| 411 | | * REG: inverted */ |
| 412 | | static unsigned LM93_GPI_FROM_REG(u8 reg) |
| 413 | | { |
| 414 | | return ~reg & 0xff; |
| 415 | | } |
| 416 | | |
| 417 | | /* ALARMS: SYSCTL format described further below |
| 418 | | REG: 64 bits in 8 registers, as immediately below */ |
| 419 | | struct block1_t { |
| 420 | | u8 host_status_1; |
| 421 | | u8 host_status_2; |
| 422 | | u8 host_status_3; |
| 423 | | u8 host_status_4; |
| 424 | | u8 p1_prochot_status; |
| 425 | | u8 p2_prochot_status; |
| 426 | | u8 gpi_status; |
| 427 | | u8 fan_status; |
| 428 | | }; |
| 429 | | |
| 430 | | static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1) |
| 431 | | { |
| 432 | | unsigned result; |
| 433 | | result = b1.host_status_2; |
| 434 | | result |= b1.host_status_3 << 8; |
| 435 | | result |= (b1.fan_status & 0x04) << 16; |
| 436 | | result |= (b1.p1_prochot_status & 0x80) << 13; |
| 437 | | result |= (b1.p2_prochot_status & 0x80) << 14; |
| 438 | | result |= (b1.host_status_4 & 0xfc) << 20; |
| 439 | | result |= (b1.host_status_1 & 0x07) << 28; |
| 440 | | return result; |
| 441 | | } |
| 442 | | |
| 443 | | /* For each registered client, we need to keep some data in memory. That |
| 444 | | data is pointed to by client->data. The structure itself is dynamically |
| 445 | | allocated, at the same time the client itself is allocated. */ |
| 446 | | |
| 447 | | struct lm93_data { |
| 448 | | struct i2c_client client; |
| 449 | | struct semaphore lock; |
| 450 | | int sysctl_id; |
| 451 | | enum chips type; |
| 452 | | |
| 453 | | struct semaphore update_lock; |
| 454 | | unsigned long last_updated; /* In jiffies */ |
| 455 | | |
| 456 | | /* client update function */ |
| 457 | | void (*update)(struct lm93_data *, struct i2c_client *); |
| 458 | | |
| 459 | | char valid; /* !=0 if following fields are valid */ |
| 460 | | |
| 461 | | /* register values, arranged by block read groups */ |
| 462 | | struct block1_t block1; |
| 463 | | |
| 464 | | /* temp1 - temp4: unfiltered readings |
| 465 | | temp1 - temp2: filtered readings */ |
| 466 | | u8 block2[6]; |
| 467 | | |
| 468 | | /* vin1 - vin16: readings */ |
| 469 | | u8 block3[16]; |
| 470 | | |
| 471 | | /* prochot1 - prochot2: readings */ |
| 472 | | struct { u8 cur; u8 avg; } block4[2]; |
| 473 | | |
| 474 | | /* fan counts 1-4 => 14-bits, LE, *left* justified */ |
| 475 | | u16 block5[4]; |
| 476 | | |
| 477 | | /* block6 has a lot of data we don't need */ |
| 478 | | struct { u8 min; u8 max; } temp_lim[3]; |
| 479 | | |
| 480 | | /* vin1 - vin16: low and high limits */ |
| 481 | | struct { u8 min; u8 max; } block7[16]; |
| 482 | | |
| 483 | | /* fan count limits 1-4 => same format as block5 */ |
| 484 | | u16 block8[4]; |
| 485 | | |
| 486 | | /* pwm control registers (2 pwms, 4 regs) */ |
| 487 | | u8 block9[2][4]; |
| 488 | | |
| 489 | | /* auto/pwm base temp and offset temp registers */ |
| 490 | | struct { u8 base[4]; u8 offset[12]; } block10; |
| 491 | | |
| 492 | | /* master config register */ |
| 493 | | u8 config; |
| 494 | | |
| 495 | | /* VID1 & VID2 => register format, 6-bits, right justified */ |
| 496 | | u8 vid[2]; |
| 497 | | |
| 498 | | /* prochot1 - prochot2: limits */ |
| 499 | | u8 prochot_max[2]; |
| 500 | | |
| 501 | | /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */ |
| 502 | | u8 vccp_limits[2]; |
| 503 | | |
| 504 | | /* GPIO input state (register format, i.e. inverted) */ |
| 505 | | u8 gpi; |
| 506 | | |
| 507 | | /* #PROCHOT override (register format) */ |
| 508 | | u8 prochot_override; |
| 509 | | |
| 510 | | /* #PROCHOT intervals (register format) */ |
| 511 | | u8 prochot_interval; |
| 512 | | |
| 513 | | /* Fan Boost Temperatures (register format) */ |
| 514 | | u8 boost[4]; |
| 515 | | |
| 516 | | /* Fan Boost Hysteresis (register format) */ |
| 517 | | u8 boost_hyst[2]; |
| 518 | | |
| 519 | | /* Temperature Zone Min. PWM & Hysteresis (register format) */ |
| 520 | | u8 auto_pwm_min_hyst[2]; |
| 521 | | |
| 522 | | /* #PROCHOT & #VRDHOT PWM Ramp Control */ |
| 523 | | u8 pwm_ramp_ctl; |
| 524 | | |
| 525 | | /* miscellaneous setup regs */ |
| 526 | | u8 sfc1; |
| 527 | | u8 sfc2; |
| 528 | | u8 sf_tach_to_pwm; |
| 529 | | |
| 530 | | /* The two PWM CTL2 registers can read something other than what was |
| 531 | | last written for the OVR_DC field (duty cycle override). So, we |
| 532 | | save the user-commanded value here. */ |
| 533 | | u8 pwm_override[2]; |
| 534 | | }; |
| 535 | | |
| 536 | | |
| 537 | | static int lm93_attach_adapter(struct i2c_adapter *adapter); |
| 538 | | static int lm93_detect(struct i2c_adapter *adapter, int address, |
| 539 | | unsigned short flags, int kind); |
| 540 | | static int lm93_detach_client(struct i2c_client *client); |
| 541 | | |
| 542 | | static u8 lm93_read_byte(struct i2c_client *client, u8 register); |
| 543 | | static int lm93_write_byte(struct i2c_client *client, u8 register, u8 value); |
| 544 | | static u16 lm93_read_word(struct i2c_client *client, u8 register); |
| 545 | | static int lm93_write_word(struct i2c_client *client, u8 register, u16 value); |
| 546 | | static void lm93_update_client(struct i2c_client *client); |
| 547 | | static void lm93_update_client_full(struct lm93_data *data, |
| 548 | | struct i2c_client *client); |
| 549 | | static void lm93_update_client_min (struct lm93_data *data, |
| 550 | | struct i2c_client *client); |
| 551 | | |
| 552 | | static void lm93_init_client(struct i2c_client *client); |
| 553 | | |
| 554 | | |
| 555 | | static void lm93_in(struct i2c_client *client, int operation, int ctl_name, |
| 556 | | int *nrels_mag, long *results); |
| 557 | | static void lm93_temp(struct i2c_client *client, int operation, |
| 558 | | int ctl_name, int *nrels_mag, long *results); |
| 559 | | static void lm93_fan(struct i2c_client *client, int operation, |
| 560 | | int ctl_name, int *nrels_mag, long *results); |
| 561 | | static void lm93_pwm(struct i2c_client *client, int operation, |
| 562 | | int ctl_name, int *nrels_mag, long *results); |
| 563 | | static void lm93_pwm_freq(struct i2c_client *client, int operation, |
| 564 | | int ctl_name, int *nrels_mag, long *results); |
| 565 | | static void lm93_pwm_auto_chan(struct i2c_client *client, int operation, |
| 566 | | int ctl_name, int *nrels_mag, long *results); |
| 567 | | static void lm93_pwm_auto_spinup_min(struct i2c_client *client, int operation, |
| 568 | | int ctl_name, int *nrels_mag, long *results); |
| 569 | | static void lm93_pwm_auto_spinup_time(struct i2c_client *client, int operation, |
| 570 | | int ctl_name, int *nrels_mag, long *results); |
| 571 | | static void lm93_pwm_auto_ramp(struct i2c_client *client, int operation, |
| 572 | | int ctl_name, int *nrels_mag, long *results); |
| 573 | | static void lm93_temp_auto_base(struct i2c_client *client, int operation, |
| 574 | | int ctl_name, int *nrels_mag, long *results); |
| 575 | | static void lm93_temp_auto_offsets(struct i2c_client *client, int operation, |
| 576 | | int ctl_name, int *nrels_mag, long *results); |
| 577 | | static void lm93_temp_auto_boost(struct i2c_client *client, int operation, |
| 578 | | int ctl_name, int *nrels_mag, long *results); |
| 579 | | static void lm93_temp_auto_boost_hyst(struct i2c_client *client, int operation, |
| 580 | | int ctl_name, int *nrels_mag, long *results); |
| 581 | | static void lm93_temp_auto_pwm_min(struct i2c_client *client, int operation, |
| 582 | | int ctl_name, int *nrels_mag, long *results); |
| 583 | | static void lm93_temp_auto_offset_hyst(struct i2c_client *client, int operation, |
| 584 | | int ctl_name, int *nrels_mag, long *results); |
| 585 | | static void lm93_fan_smart_tach(struct i2c_client *client, int operation, |
| 586 | | int ctl_name, int *nrels_mag, long *results); |
| 587 | | static void lm93_vid(struct i2c_client *client, int operation, |
| 588 | | int ctl_name, int *nrels_mag, long *results); |
| 589 | | static void lm93_prochot(struct i2c_client *client, int operation, |
| 590 | | int ctl_name, int *nrels_mag, long *results); |
| 591 | | static void lm93_prochot_short(struct i2c_client *client, int operation, |
| 592 | | int ctl_name, int *nrels_mag, long *results); |
| 593 | | static void lm93_prochot_override(struct i2c_client *client, int operation, |
| 594 | | int ctl_name, int *nrels_mag, long *results); |
| 595 | | static void lm93_prochot_interval(struct i2c_client *client, int operation, |
| 596 | | int ctl_name, int *nrels_mag, long *results); |
| 597 | | static void lm93_vrdhot(struct i2c_client *client, int operation, |
| 598 | | int ctl_name, int *nrels_mag, long *results); |
| 599 | | static void lm93_gpio(struct i2c_client *client, int operation, |
| 600 | | int ctl_name, int *nrels_mag, long *results); |
| 601 | | static void lm93_alarms(struct i2c_client *client, int operation, |
| 602 | | int ctl_name, int *nrels_mag, long *results); |
| 603 | | |
| 604 | | static struct i2c_driver lm93_driver = { |
| 605 | | .owner = THIS_MODULE, |
| 606 | | .name = "LM93 sensor driver", |
| 607 | | .id = I2C_DRIVERID_LM93, |
| 608 | | .flags = I2C_DF_NOTIFY, |
| 609 | | .attach_adapter = lm93_attach_adapter, |
| 610 | | .detach_client = lm93_detach_client, |
| 611 | | }; |
| 612 | | |
| 613 | | /* unique ID for each LM93 detected */ |
| 614 | | static int lm93_id = 0; |
| 615 | | |
| | 230 | |
| | 231 | /* SMBus capabilities */ |
| | 232 | #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \ |
| | 233 | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA) |
| | 234 | #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \ |
| | 235 | I2C_FUNC_SMBUS_WORD_DATA) |
| | 236 | |
| | 237 | /* LM93 BLOCK READ COMMANDS */ |
| | 238 | static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = { |
| | 239 | { 0xf2, 8 }, |
| | 240 | { 0xf3, 8 }, |
| | 241 | { 0xf4, 6 }, |
| | 242 | { 0xf5, 16 }, |
| | 243 | { 0xf6, 4 }, |
| | 244 | { 0xf7, 8 }, |
| | 245 | { 0xf8, 12 }, |
| | 246 | { 0xf9, 32 }, |
| | 247 | { 0xfa, 8 }, |
| | 248 | { 0xfb, 8 }, |
| | 249 | { 0xfc, 16 }, |
| | 250 | { 0xfd, 9 }, |
| | 251 | }; |
| | 252 | |
| | 253 | /* ALARMS: SYSCTL format described further below |
| | 254 | REG: 64 bits in 8 registers, as immediately below */ |
| | 255 | struct block1_t { |
| | 256 | u8 host_status_1; |
| | 257 | u8 host_status_2; |
| | 258 | u8 host_status_3; |
| | 259 | u8 host_status_4; |
| | 260 | u8 p1_prochot_status; |
| | 261 | u8 p2_prochot_status; |
| | 262 | u8 gpi_status; |
| | 263 | u8 fan_status; |
| | 264 | }; |
| | 265 | |
| | 266 | /* unique ID for each LM93 detected */ |
| | 267 | static int lm93_id = 0; |
| | 268 | |
| | 269 | /* For each registered client, we need to keep some data in memory. That |
| | 270 | data is pointed to by client->data. The structure itself is dynamically |
| | 271 | allocated, at the same time the client itself is allocated. */ |
| | 272 | |
| | 273 | struct lm93_data { |
| | 274 | struct i2c_client client; |
| | 275 | struct semaphore lock; |
| | 276 | int sysctl_id; |
| | 277 | enum chips type; |
| | 278 | |
| | 279 | struct semaphore update_lock; |
| | 280 | unsigned long last_updated; /* In jiffies */ |
| | 281 | |
| | 282 | /* client update function */ |
| | 283 | void (*update)(struct lm93_data *, struct i2c_client *); |
| | 284 | |
| | 285 | char valid; /* !=0 if following fields are valid */ |
| | 286 | |
| | 287 | /* register values, arranged by block read groups */ |
| | 288 | struct block1_t block1; |
| | 289 | |
| | 290 | /* temp1 - temp4: unfiltered readings |
| | 291 | temp1 - temp2: filtered readings */ |
| | 292 | u8 block2[6]; |
| | 293 | |
| | 294 | /* vin1 - vin16: readings */ |
| | 295 | u8 block3[16]; |
| | 296 | |
| | 297 | /* prochot1 - prochot2: readings */ |
| | 298 | struct { u8 cur; u8 avg; } block4[2]; |
| | 299 | |
| | 300 | /* fan counts 1-4 => 14-bits, LE, *left* justified */ |
| | 301 | u16 block5[4]; |
| | 302 | |
| | 303 | /* block6 has a lot of data we don't need */ |
| | 304 | struct { u8 min; u8 max; } temp_lim[3]; |
| | 305 | |
| | 306 | /* vin1 - vin16: low and high limits */ |
| | 307 | struct { u8 min; u8 max; } block7[16]; |
| | 308 | |
| | 309 | /* fan count limits 1-4 => same format as block5 */ |
| | 310 | u16 block8[4]; |
| | 311 | |
| | 312 | /* pwm control registers (2 pwms, 4 regs) */ |
| | 313 | u8 block9[2][4]; |
| | 314 | |
| | 315 | /* auto/pwm base temp and offset temp registers */ |
| | 316 | struct { u8 base[4]; u8 offset[12]; } block10; |
| | 317 | |
| | 318 | /* master config register */ |
| | 319 | u8 config; |
| | 320 | |
| | 321 | /* VID1 & VID2 => register format, 6-bits, right justified */ |
| | 322 | u8 vid[2]; |
| | 323 | |
| | 324 | /* prochot1 - prochot2: limits */ |
| | 325 | u8 prochot_max[2]; |
| | 326 | |
| | 327 | /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */ |
| | 328 | u8 vccp_limits[2]; |
| | 329 | |
| | 330 | /* GPIO input state (register format, i.e. inverted) */ |
| | 331 | u8 gpi; |
| | 332 | |
| | 333 | /* #PROCHOT override (register format) */ |
| | 334 | u8 prochot_override; |
| | 335 | |
| | 336 | /* #PROCHOT intervals (register format) */ |
| | 337 | u8 prochot_interval; |
| | 338 | |
| | 339 | /* Fan Boost Temperatures (register format) */ |
| | 340 | u8 boost[4]; |
| | 341 | |
| | 342 | /* Fan Boost Hysteresis (register format) */ |
| | 343 | u8 boost_hyst[2]; |
| | 344 | |
| | 345 | /* Temperature Zone Min. PWM & Hysteresis (register format) */ |
| | 346 | u8 auto_pwm_min_hyst[2]; |
| | 347 | |
| | 348 | /* #PROCHOT & #VRDHOT PWM Ramp Control */ |
| | 349 | u8 pwm_ramp_ctl; |
| | 350 | |
| | 351 | /* miscellaneous setup regs */ |
| | 352 | u8 sfc1; |
| | 353 | u8 sfc2; |
| | 354 | u8 sf_tach_to_pwm; |
| | 355 | |
| | 356 | /* The two PWM CTL2 registers can read something other than what was |
| | 357 | last written for the OVR_DC field (duty cycle override). So, we |
| | 358 | save the user-commanded value here. */ |
| | 359 | u8 pwm_override[2]; |
| | 360 | }; |
| | 361 | |
| | 362 | #define MAX_RETRIES 5 |
| | 363 | |
| | 364 | static u8 lm93_read_byte(struct i2c_client *client, u8 reg) |
| | 365 | { |
| | 366 | int value, i; |
| | 367 | |
| | 368 | /* retry in case of read errors */ |
| | 369 | for (i=1; i<=MAX_RETRIES; i++) { |
| | 370 | if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) { |
| | 371 | return value; |
| | 372 | } else { |
| | 373 | printk(KERN_WARNING "lm93.o: read byte data failed, " |
| | 374 | "address 0x%02x.\n", reg); |
| | 375 | mdelay(i); |
| | 376 | } |
| | 377 | |
| | 378 | } |
| | 379 | |
| | 380 | /* <TODO> what to return in case of error? */ |
| | 381 | return 0; |
| | 382 | } |
| | 383 | |
| | 384 | static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value) |
| | 385 | { |
| | 386 | int result; |
| | 387 | |
| | 388 | /* <TODO> how to handle write errors? */ |
| | 389 | result = i2c_smbus_write_byte_data(client, reg, value); |
| | 390 | |
| | 391 | if (result < 0) |
| | 392 | printk(KERN_WARNING "lm93.o: write byte data failed, " |
| | 393 | "0x%02x at address 0x%02x.\n", value, reg); |
| | 394 | |
| | 395 | return result; |
| | 396 | } |
| | 397 | |
| | 398 | static u16 lm93_read_word(struct i2c_client *client, u8 reg) |
| | 399 | { |
| | 400 | int value, i; |
| | 401 | |
| | 402 | /* retry in case of read errors */ |
| | 403 | for (i=1; i<=MAX_RETRIES; i++) { |
| | 404 | if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) { |
| | 405 | return value; |
| | 406 | } else { |
| | 407 | printk(KERN_WARNING "lm93.o: read word data failed, " |
| | 408 | "address 0x%02x.\n", reg); |
| | 409 | mdelay(i); |
| | 410 | } |
| | 411 | |
| | 412 | } |
| | 413 | |
| | 414 | /* <TODO> what to return in case of error? */ |
| | 415 | return 0; |
| | 416 | } |
| | 417 | |
| | 418 | static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value) |
| | 419 | { |
| | 420 | int result; |
| | 421 | |
| | 422 | /* <TODO> how to handle write errors? */ |
| | 423 | result = i2c_smbus_write_word_data(client, reg, value); |
| | 424 | |
| | 425 | if (result < 0) |
| | 426 | printk(KERN_WARNING "lm93.o: write word data failed, " |
| | 427 | "0x%04x at address 0x%02x.\n", value, reg); |
| | 428 | |
| | 429 | return result; |
| | 430 | } |
| | 431 | |
| | 432 | static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX]; |
| | 433 | |
| | 434 | /* |
| | 435 | read block data into values, retry if not expected length |
| | 436 | fbn => index to lm93_block_read_cmds table |
| | 437 | (Fixed Block Number - section 14.5.2 of LM93 datasheet) |
| | 438 | */ |
| | 439 | static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) |
| | 440 | { |
| | 441 | int i, result; |
| | 442 | |
| | 443 | for (i = 1; i <= MAX_RETRIES; i++) { |
| | 444 | result = i2c_smbus_read_block_data(client, |
| | 445 | lm93_block_read_cmds[fbn].cmd, lm93_block_buffer); |
| | 446 | |
| | 447 | if (result != lm93_block_read_cmds[fbn].len) { |
| | 448 | printk(KERN_WARNING "lm93.o: block read data failed, " |
| | 449 | "command 0x%02x.\n", |
| | 450 | lm93_block_read_cmds[fbn].cmd); |
| | 451 | mdelay(1); |
| | 452 | } |
| | 453 | } |
| | 454 | |
| | 455 | if (result == lm93_block_read_cmds[fbn].len) { |
| | 456 | memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len); |
| | 457 | } else { |
| | 458 | /* <TODO> what to do in case of error? */ |
| | 459 | } |
| | 460 | } |
| | 461 | |
| | 462 | static void lm93_update_client(struct i2c_client *client) |
| | 463 | { |
| | 464 | struct lm93_data *data = client->data; |
| | 465 | |
| | 466 | down(&data->update_lock); |
| | 467 | |
| | 468 | if (time_after(jiffies - data->last_updated, HZ + HZ / 2) || |
| | 469 | time_before(jiffies, data->last_updated) || !data->valid) { |
| | 470 | |
| | 471 | data->update(data, client); |
| | 472 | data->last_updated = jiffies; |
| | 473 | data->valid = 1; |
| | 474 | } |
| | 475 | |
| | 476 | up(&data->update_lock); |
| | 477 | } |
| | 478 | |
| | 479 | /* update routine for data that has no corresponding SMBus block data command */ |
| | 480 | static void lm93_update_client_common(struct lm93_data *data, |
| | 481 | struct i2c_client *client) |
| | 482 | { |
| | 483 | int i; |
| | 484 | |
| | 485 | /* temp1 - temp4: limits */ |
| | 486 | for (i = 0; i < 4; i++) { |
| | 487 | data->temp_lim[i].min = |
| | 488 | lm93_read_byte(client, LM93_REG_TEMP_MIN(i)); |
| | 489 | data->temp_lim[i].max = |
| | 490 | lm93_read_byte(client, LM93_REG_TEMP_MAX(i)); |
| | 491 | } |
| | 492 | |
| | 493 | /* config register */ |
| | 494 | data->config = lm93_read_byte(client, LM93_REG_CONFIG); |
| | 495 | |
| | 496 | /* vid1 - vid2: values */ |
| | 497 | for (i = 0; i < 2; i++) |
| | 498 | data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i)); |
| | 499 | |
| | 500 | /* prochot1 - prochot2: limits */ |
| | 501 | for (i = 0; i < 2; i++) |
| | 502 | data->prochot_max[i] = lm93_read_byte(client, |
| | 503 | LM93_REG_PROCHOT_MAX(i)); |
| | 504 | |
| | 505 | /* vccp1 - vccp2: VID relative limits */ |
| | 506 | for (i = 0; i < 2; i++) |
| | 507 | data->vccp_limits[i] = lm93_read_byte(client, |
| | 508 | LM93_REG_VCCP_LIMIT_OFF(i)); |
| | 509 | |
| | 510 | /* GPIO input state */ |
| | 511 | data->gpi = lm93_read_byte(client, LM93_REG_GPI); |
| | 512 | |
| | 513 | /* #PROCHOT override state */ |
| | 514 | data->prochot_override = lm93_read_byte(client, |
| | 515 | LM93_REG_PROCHOT_OVERRIDE); |
| | 516 | |
| | 517 | /* #PROCHOT intervals */ |
| | 518 | data->prochot_interval = lm93_read_byte(client, |
| | 519 | LM93_REG_PROCHOT_INTERVAL); |
| | 520 | |
| | 521 | /* Fan Boost Termperature registers */ |
| | 522 | for (i = 0; i < 4; i++) |
| | 523 | data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); |
| | 524 | |
| | 525 | /* Fan Boost Temperature Hyst. registers */ |
| | 526 | data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12); |
| | 527 | data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34); |
| | 528 | |
| | 529 | /* Temperature Zone Min. PWM & Hysteresis registers */ |
| | 530 | data->auto_pwm_min_hyst[0] = |
| | 531 | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12); |
| | 532 | data->auto_pwm_min_hyst[1] = |
| | 533 | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34); |
| | 534 | |
| | 535 | /* #PROCHOT & #VRDHOT PWM Ramp Control register */ |
| | 536 | data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); |
| | 537 | |
| | 538 | /* misc setup registers */ |
| | 539 | data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1); |
| | 540 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| | 541 | data->sf_tach_to_pwm = lm93_read_byte(client, |
| | 542 | LM93_REG_SF_TACH_TO_PWM); |
| | 543 | } |
| | 544 | |
| | 545 | /* update routine which uses SMBus block data commands */ |
| | 546 | static void lm93_update_client_full(struct lm93_data *data, |
| | 547 | struct i2c_client *client) |
| | 548 | { |
| | 549 | pr_debug("lm93.o: starting device update (block data enabled)\n"); |
| | 550 | |
| | 551 | /* in1 - in16: values & limits */ |
| | 552 | lm93_read_block(client, 3, (u8 *)(data->block3)); |
| | 553 | lm93_read_block(client, 7, (u8 *)(data->block7)); |
| | 554 | |
| | 555 | /* temp1 - temp4: values */ |
| | 556 | lm93_read_block(client, 2, (u8 *)(data->block2)); |
| | 557 | |
| | 558 | /* prochot1 - prochot2: values */ |
| | 559 | lm93_read_block(client, 4, (u8 *)(data->block4)); |
| | 560 | |
| | 561 | /* fan1 - fan4: values & limits */ |
| | 562 | lm93_read_block(client, 5, (u8 *)(data->block5)); |
| | 563 | lm93_read_block(client, 8, (u8 *)(data->block8)); |
| | 564 | |
| | 565 | /* pmw control registers */ |
| | 566 | lm93_read_block(client, 9, (u8 *)(data->block9)); |
| | 567 | |
| | 568 | /* alarm values */ |
| | 569 | lm93_read_block(client, 1, (u8 *)(&data->block1)); |
| | 570 | |
| | 571 | /* auto/pwm registers */ |
| | 572 | lm93_read_block(client, 10, (u8 *)(&data->block10)); |
| | 573 | |
| | 574 | lm93_update_client_common(data, client); |
| | 575 | } |
| | 576 | |
| | 577 | /* update routine which uses SMBus byte/word data commands only */ |
| | 578 | static void lm93_update_client_min(struct lm93_data *data, |
| | 579 | struct i2c_client *client) |
| | 580 | { |
| | 581 | int i,j; |
| | 582 | u8 *ptr; |
| | 583 | |
| | 584 | pr_debug("lm93.o: starting device update (block data disabled)\n"); |
| | 585 | |
| | 586 | /* in1 - in16: values & limits */ |
| | 587 | for (i = 0; i < 16; i++) { |
| | 588 | data->block3[i] = |
| | 589 | lm93_read_byte(client, LM93_REG_IN(i)); |
| | 590 | data->block7[i].min = |
| | 591 | lm93_read_byte(client, LM93_REG_IN_MIN(i)); |
| | 592 | data->block7[i].max = |
| | 593 | lm93_read_byte(client, LM93_REG_IN_MAX(i)); |
| | 594 | } |
| | 595 | |
| | 596 | /* temp1 - temp4: values */ |
| | 597 | for (i = 0; i < 4; i++) { |
| | 598 | data->block2[i] = |
| | 599 | lm93_read_byte(client, LM93_REG_TEMP(i)); |
| | 600 | } |
| | 601 | |
| | 602 | /* prochot1 - prochot2: values */ |
| | 603 | for (i = 0; i < 2; i++) { |
| | 604 | data->block4[i].cur = |
| | 605 | lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i)); |
| | 606 | data->block4[i].avg = |
| | 607 | lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i)); |
| | 608 | } |
| | 609 | |
| | 610 | /* fan1 - fan4: values & limits */ |
| | 611 | for (i = 0; i < 4; i++) { |
| | 612 | data->block5[i] = |
| | 613 | lm93_read_word(client, LM93_REG_FAN(i)); |
| | 614 | data->block8[i] = |
| | 615 | lm93_read_word(client, LM93_REG_FAN_MIN(i)); |
| | 616 | } |
| | 617 | |
| | 618 | /* pwm control registers */ |
| | 619 | for (i = 0; i < 2; i++) { |
| | 620 | for (j = 0; j < 4; j++) { |
| | 621 | data->block9[i][j] = |
| | 622 | lm93_read_byte(client, LM93_REG_PWM_CTL(i,j)); |
| | 623 | } |
| | 624 | } |
| | 625 | |
| | 626 | /* alarm values */ |
| | 627 | for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) { |
| | 628 | *(ptr + i) = |
| | 629 | lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i); |
| | 630 | } |
| | 631 | |
| | 632 | /* auto/pwm (base temp) registers */ |
| | 633 | for (i = 0; i < 4; i++) { |
| | 634 | data->block10.base[i] = |
| | 635 | lm93_read_byte(client, LM93_REG_TEMP_BASE(i)); |
| | 636 | } |
| | 637 | |
| | 638 | /* auto/pwm (offset temp) registers */ |
| | 639 | for (i = 0; i < 12; i++) { |
| | 640 | data->block10.offset[i] = |
| | 641 | lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i)); |
| | 642 | } |
| | 643 | |
| | 644 | lm93_update_client_common(data, client); |
| | 645 | } |
| | 646 | |
| | 647 | /* VID: mV |
| | 648 | REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */ |
| | 649 | static int LM93_VID_FROM_REG(u8 reg) |
| | 650 | { |
| | 651 | return vid_from_reg((reg & 0x3f), 100); |
| | 652 | } |
| | 653 | |
| | 654 | static void lm93_vid(struct i2c_client *client, int operation, int ctl_name, |
| | 655 | int *nrels_mag, long *results) |
| | 656 | { |
| | 657 | struct lm93_data *data = client->data; |
| | 658 | int nr = ctl_name - LM93_SYSCTL_VID1; |
| | 659 | |
| | 660 | if (0 > nr || nr > 1) |
| | 661 | return; /* ERROR */ |
| | 662 | |
| | 663 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 664 | *nrels_mag = 2; |
| | 665 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 666 | lm93_update_client(client); |
| | 667 | results[0] = LM93_VID_FROM_REG(data->vid[nr]); |
| | 668 | *nrels_mag = 1; |
| | 669 | } |
| | 670 | } |
| | 671 | |
| | 672 | /* min, max, and nominal voltage readings, per channel (mV)*/ |
| | 673 | static const unsigned long lm93_vin_val_min[16] = { |
| | 674 | 0, 0, 0, 0, 0, 0, 0, 0, |
| | 675 | 0, 0, 0, 0, 0, 0, 0, 3000, |
| | 676 | }; |
| | 677 | static const unsigned long lm93_vin_val_max[16] = { |
| | 678 | 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600, |
| | 679 | 4400, 6667, 3333, 2625, 1312, 1312, 1236, 3600, |
| | 680 | }; |
| | 681 | /* |
| | 682 | static const unsigned long lm93_vin_val_nom[16] = { |
| | 683 | 927, 927, 927, 1200, 1500, 1500, 1200, 1200, |
| | 684 | 3300, 5000, 2500, 1969, 984, 984, 309, 3300, |
| | 685 | }; |
| | 686 | */ |
| | 687 | |
| | 688 | /* min, max, and nominal register values, per channel (u8) */ |
| | 689 | static const u8 lm93_vin_reg_min[16] = { |
| | 690 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| | 691 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, |
| | 692 | }; |
| | 693 | static const u8 lm93_vin_reg_max[16] = { |
| | 694 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| | 695 | 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1, |
| | 696 | }; |
| | 697 | /* |
| | 698 | static const u8 lm93_vin_reg_nom[16] = { |
| | 699 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, |
| | 700 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, |
| | 701 | }; |
| | 702 | */ |
| | 703 | |
| | 704 | /* IN: 1/100 V, limits determined by channel nr |
| | 705 | REG: scaling determined by channel nr */ |
| | 706 | static u8 LM93_IN_TO_REG(int nr, unsigned val) |
| | 707 | { |
| | 708 | /* range limit */ |
| | 709 | const long mV = SENSORS_LIMIT(val * 10, |
| | 710 | lm93_vin_val_min[nr], lm93_vin_val_max[nr]); |
| | 711 | |
| | 712 | /* try not to lose too much precision here */ |
| | 713 | const long uV = mV * 1000; |
| | 714 | const long uV_max = lm93_vin_val_max[nr] * 1000; |
| | 715 | const long uV_min = lm93_vin_val_min[nr] * 1000; |
| | 716 | |
| | 717 | /* convert */ |
| | 718 | const long slope = (uV_max - uV_min) / |
| | 719 | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); |
| | 720 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
| | 721 | |
| | 722 | u8 result = ((uV - intercept + (slope/2)) / slope); |
| | 723 | result = SENSORS_LIMIT(result, |
| | 724 | lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); |
| | 725 | return result; |
| | 726 | } |
| | 727 | |
| | 728 | static unsigned LM93_IN_FROM_REG(int nr, u8 reg) |
| | 729 | { |
| | 730 | const long uV_max = lm93_vin_val_max[nr] * 1000; |
| | 731 | const long uV_min = lm93_vin_val_min[nr] * 1000; |
| | 732 | |
| | 733 | const long slope = (uV_max - uV_min) / |
| | 734 | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); |
| | 735 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
| | 736 | |
| | 737 | return (slope * reg + intercept + 5000) / 10000; |
| | 738 | } |
| | 739 | |
| | 740 | /* vid in mV , upper == 0 indicates low limit, otherwise upper limit |
| | 741 | upper also determines which nibble of the register is returned |
| | 742 | (the other nibble will be 0x0) */ |
| | 743 | static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) |
| | 744 | { |
| | 745 | long uV_offset = vid * 1000 - val * 10000; |
| | 746 | if (upper) { |
| | 747 | uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000); |
| | 748 | return (u8)((uV_offset / 12500 - 1) << 4); |
| | 749 | } else { |
| | 750 | uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000); |
| | 751 | return (u8)((uV_offset / -25000 - 1) << 0); |
| | 752 | } |
| | 753 | } |
| | 754 | |
| | 755 | /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */ |
| | 756 | static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid) |
| | 757 | { |
| | 758 | const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) : |
| | 759 | (((reg >> 0 & 0x0f) + 1) * -25000); |
| | 760 | const long uV_vid = vid * 1000; |
| | 761 | return (uV_vid + uV_offset + 5000) / 10000; |
| | 762 | } |
| | 763 | |
| | 764 | static void lm93_in(struct i2c_client *client, int operation, int ctl_name, |
| | 765 | int *nrels_mag, long *results) |
| | 766 | { |
| | 767 | struct lm93_data *data = client->data; |
| | 768 | int nr = ctl_name - LM93_SYSCTL_IN1; /* 0 <= nr <= 15 */ |
| | 769 | int vccp = ctl_name - LM93_SYSCTL_IN7; /* 0 <= vccp <= 1 if relevant */ |
| | 770 | |
| | 771 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 772 | *nrels_mag = 2; |
| | 773 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 774 | |
| | 775 | lm93_update_client(client); |
| | 776 | |
| | 777 | /* for limits, check in7 and in8 for VID relative mode */ |
| | 778 | if ((ctl_name==LM93_SYSCTL_IN7 || ctl_name==LM93_SYSCTL_IN8) && |
| | 779 | (vccp_limit_type[vccp])) { |
| | 780 | long vid = LM93_VID_FROM_REG(data->vid[vccp]); |
| | 781 | results[0] = LM93_IN_REL_FROM_REG( |
| | 782 | data->vccp_limits[vccp], 0, vid); |
| | 783 | results[1] = LM93_IN_REL_FROM_REG( |
| | 784 | data->vccp_limits[vccp], 1, vid); |
| | 785 | |
| | 786 | /* otherwise, use absolute limits */ |
| | 787 | } else { |
| | 788 | results[0] = LM93_IN_FROM_REG(nr, |
| | 789 | data->block7[nr].min); |
| | 790 | results[1] = LM93_IN_FROM_REG(nr, |
| | 791 | data->block7[nr].max); |
| | 792 | } |
| | 793 | |
| | 794 | results[2] = LM93_IN_FROM_REG(nr, data->block3[nr]); |
| | 795 | *nrels_mag = 3; |
| | 796 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 797 | down(&data->update_lock); |
| | 798 | |
| | 799 | /* for limits, check in7 and in8 for VID relative mode */ |
| | 800 | if ((ctl_name==LM93_SYSCTL_IN7 || ctl_name==LM93_SYSCTL_IN8) && |
| | 801 | (vccp_limit_type[vccp])) { |
| | 802 | |
| | 803 | long vid = LM93_VID_FROM_REG(data->vid[vccp]); |
| | 804 | if (*nrels_mag >= 2) { |
| | 805 | data->vccp_limits[vccp] = |
| | 806 | (data->vccp_limits[vccp] & 0x0f) | |
| | 807 | LM93_IN_REL_TO_REG(results[1], 1, vid); |
| | 808 | } |
| | 809 | if (*nrels_mag >= 1) { |
| | 810 | data->vccp_limits[vccp] = |
| | 811 | (data->vccp_limits[vccp] & 0xf0) | |
| | 812 | LM93_IN_REL_TO_REG(results[0], 0, vid); |
| | 813 | lm93_write_byte(client, |
| | 814 | LM93_REG_VCCP_LIMIT_OFF(vccp), |
| | 815 | data->vccp_limits[vccp]); |
| | 816 | } |
| | 817 | |
| | 818 | /* otherwise, use absolute limits */ |
| | 819 | } else { |
| | 820 | if (*nrels_mag >= 1) { |
| | 821 | data->block7[nr].min = LM93_IN_TO_REG(nr, |
| | 822 | results[0]); |
| | 823 | lm93_write_byte(client, LM93_REG_IN_MIN(nr), |
| | 824 | data->block7[nr].min); |
| | 825 | } |
| | 826 | if (*nrels_mag >= 2) { |
| | 827 | data->block7[nr].max = LM93_IN_TO_REG(nr, |
| | 828 | results[1]); |
| | 829 | lm93_write_byte(client, LM93_REG_IN_MAX(nr), |
| | 830 | data->block7[nr].max); |
| | 831 | } |
| | 832 | } |
| | 833 | up(&data->update_lock); |
| | 834 | } |
| | 835 | } |
| | 836 | |
| | 837 | static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1) |
| | 838 | { |
| | 839 | unsigned result; |
| | 840 | result = b1.host_status_2; |
| | 841 | result |= b1.host_status_3 << 8; |
| | 842 | result |= (b1.fan_status & 0x04) << 16; |
| | 843 | result |= (b1.p1_prochot_status & 0x80) << 13; |
| | 844 | result |= (b1.p2_prochot_status & 0x80) << 14; |
| | 845 | result |= (b1.host_status_4 & 0xfc) << 20; |
| | 846 | result |= (b1.host_status_1 & 0x07) << 28; |
| | 847 | return result; |
| | 848 | } |
| | 849 | |
| | 850 | static void lm93_alarms(struct i2c_client *client, int operation, |
| | 851 | int ctl_name, int *nrels_mag, long *results) |
| | 852 | { |
| | 853 | struct lm93_data *data = client->data; |
| | 854 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 855 | *nrels_mag = 0; |
| | 856 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 857 | lm93_update_client(client); |
| | 858 | results[0] = LM93_ALARMS_FROM_REG(data->block1); |
| | 859 | *nrels_mag = 1; |
| | 860 | } |
| | 861 | } |
| | 862 | |
| | 863 | #define LM93_TEMP_MIN (-1280) |
| | 864 | #define LM93_TEMP_MAX ( 1270) |
| | 865 | |
| | 866 | /* TEMP: 1/10 degrees C (-128C to +127C) |
| | 867 | REG: 1C/bit, two's complement */ |
| | 868 | static u8 LM93_TEMP_TO_REG(int temp) |
| | 869 | { |
| | 870 | int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); |
| | 871 | ntemp += (ntemp<0 ? -5 : 5); |
| | 872 | return (u8)(ntemp / 10); |
| | 873 | } |
| | 874 | |
| | 875 | static int LM93_TEMP_FROM_REG(u8 reg) |
| | 876 | { |
| | 877 | return (s8)reg * 10; |
| | 878 | } |
| | 879 | |
| | 880 | static void lm93_temp(struct i2c_client *client, int operation, int ctl_name, |
| | 881 | int *nrels_mag, long *results) |
| | 882 | { |
| | 883 | struct lm93_data *data = client->data; |
| | 884 | int nr = ctl_name - LM93_SYSCTL_TEMP1; |
| | 885 | |
| | 886 | if (0 > nr || nr > 2) |
| | 887 | return; /* ERROR */ |
| | 888 | |
| | 889 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 890 | *nrels_mag = 1; |
| | 891 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 892 | lm93_update_client(client); |
| | 893 | results[0] = LM93_TEMP_FROM_REG(data->temp_lim[nr].max); |
| | 894 | results[1] = LM93_TEMP_FROM_REG(data->temp_lim[nr].min); |
| | 895 | results[2] = LM93_TEMP_FROM_REG(data->block2[nr]); |
| | 896 | *nrels_mag = 3; |
| | 897 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 898 | down(&data->update_lock); |
| | 899 | if (*nrels_mag >= 1) { |
| | 900 | data->temp_lim[nr].max = LM93_TEMP_TO_REG(results[0]); |
| | 901 | lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), |
| | 902 | data->temp_lim[nr].max); |
| | 903 | } |
| | 904 | if (*nrels_mag >= 2) { |
| | 905 | data->temp_lim[nr].min = LM93_TEMP_TO_REG(results[1]); |
| | 906 | lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), |
| | 907 | data->temp_lim[nr].min); |
| | 908 | } |
| | 909 | up(&data->update_lock); |
| | 910 | } |
| | 911 | } |
| | 912 | |
| | 913 | /* Determine 4-bit temperature offset resolution */ |
| | 914 | static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr) |
| | 915 | { |
| | 916 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| | 917 | return sfc2 & (nr < 2 ? 0x10 : 0x20); |
| | 918 | } |
| | 919 | |
| | 920 | #define LM93_TEMP_OFFSET_MIN ( 0) |
| | 921 | #define LM93_TEMP_OFFSET_MAX0 (150) |
| | 922 | #define LM93_TEMP_OFFSET_MAX1 ( 75) |
| | 923 | |
| | 924 | /* This function is common to all 4-bit temperature offsets |
| | 925 | returns 4 bits right justified |
| | 926 | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ |
| | 927 | static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) |
| | 928 | { |
| | 929 | int factor = mode ? 5 : 10; |
| | 930 | |
| | 931 | off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN, |
| | 932 | mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); |
| | 933 | return (u8)((off + factor/2) / factor); |
| | 934 | } |
| | 935 | |
| | 936 | /* This function is common to all 4-bit temperature offsets |
| | 937 | reg is 4 bits right justified |
| | 938 | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ |
| | 939 | static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode) |
| | 940 | { |
| | 941 | return (reg & 0x0f) * (mode ? 5 : 10); |
| | 942 | } |
| | 943 | |
| | 944 | /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero)) |
| | 945 | REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero) |
| | 946 | 0 <= nr <= 3 */ |
| | 947 | static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode) |
| | 948 | { |
| | 949 | u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode); |
| | 950 | |
| | 951 | /* temp1-temp2 (nr=0,1) use lower nibble */ |
| | 952 | if (nr < 2) |
| | 953 | return (old & 0xf0) | (new & 0x0f); |
| | 954 | |
| | 955 | /* temp3-temp4 (nr=2,3) use upper nibble */ |
| | 956 | else |
| | 957 | return (new << 4 & 0xf0) | (old & 0x0f); |
| | 958 | } |
| | 959 | |
| | 960 | /* 0 <= nr <= 3 */ |
| | 961 | static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode) |
| | 962 | { |
| | 963 | /* temp1-temp2 (nr=0,1) use lower nibble */ |
| | 964 | if (nr < 2) |
| | 965 | return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode); |
| | 966 | |
| | 967 | /* temp3-temp4 (nr=2,3) use upper nibble */ |
| | 968 | else |
| | 969 | return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode); |
| | 970 | } |
| | 971 | |
| | 972 | static void lm93_temp_auto_offsets(struct i2c_client *client, int operation, |
| | 973 | int ctl_name, int *nrels_mag, long *results) |
| | 974 | { |
| | 975 | struct lm93_data *data = client->data; |
| | 976 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_OFFSETS; |
| | 977 | int ii; |
| | 978 | |
| | 979 | if (0 > nr || nr > 2) |
| | 980 | return; /* ERROR */ |
| | 981 | |
| | 982 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 983 | *nrels_mag = 1; |
| | 984 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 985 | int mode; |
| | 986 | lm93_update_client(client); |
| | 987 | |
| | 988 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| | 989 | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
| | 990 | |
| | 991 | for (ii = 0; ii < 12; ii++) { |
| | 992 | results[ii] = LM93_TEMP_AUTO_OFFSET_FROM_REG( |
| | 993 | data->block10.offset[ii], nr, mode); |
| | 994 | } |
| | 995 | *nrels_mag = 12; |
| | 996 | } |
| | 997 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 998 | /* we only care about the first 12 values */ |
| | 999 | int nrels = *nrels_mag > 12 ? 12 : *nrels_mag; |
| | 1000 | |
| | 1001 | down(&data->update_lock); |
| | 1002 | |
| | 1003 | /* force 0.5C/bit mode */ |
| | 1004 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| | 1005 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
| | 1006 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| | 1007 | |
| | 1008 | for (ii = 0; ii < nrels; ii++) { |
| | 1009 | data->block10.offset[ii] = LM93_TEMP_AUTO_OFFSET_TO_REG( |
| | 1010 | data->block10.offset[ii], results[ii], nr, 1); |
| | 1011 | lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ii), |
| | 1012 | data->block10.offset[ii]); |
| | 1013 | } |
| | 1014 | up(&data->update_lock); |
| | 1015 | } |
| | 1016 | } |
| | 1017 | |
| | 1018 | /* RPM: (82.5 to 1350000) |
| | 1019 | REG: 14-bits, LE, *left* justified */ |
| | 1020 | static u16 LM93_FAN_TO_REG(long rpm) |
| | 1021 | { |
| | 1022 | u16 count, regs; |
| | 1023 | |
| | 1024 | if (rpm == 0) { |
| | 1025 | count = 0x3fff; |
| | 1026 | } else { |
| | 1027 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| | 1028 | count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe); |
| | 1029 | } |
| | 1030 | |
| | 1031 | regs = count << 2; |
| | 1032 | return cpu_to_le16(regs); |
| | 1033 | } |
| | 1034 | |
| | 1035 | static int LM93_FAN_FROM_REG(u16 regs) |
| | 1036 | { |
| | 1037 | const u16 count = le16_to_cpu(regs) >> 2; |
| | 1038 | return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count; |
| | 1039 | } |
| | 1040 | |
| | 1041 | static void lm93_fan(struct i2c_client *client, int operation, int ctl_name, |
| | 1042 | int *nrels_mag, long *results) |
| | 1043 | { |
| | 1044 | struct lm93_data *data = client->data; |
| | 1045 | int nr = ctl_name - LM93_SYSCTL_FAN1; |
| | 1046 | |
| | 1047 | if (0 > nr || nr > 3) |
| | 1048 | return; /* ERROR */ |
| | 1049 | |
| | 1050 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1051 | *nrels_mag = 0; |
| | 1052 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1053 | lm93_update_client(client); |
| | 1054 | results[0] = LM93_FAN_FROM_REG(data->block8[nr]); /* min */ |
| | 1055 | results[1] = LM93_FAN_FROM_REG(data->block5[nr]); /* val */ |
| | 1056 | *nrels_mag = 2; |
| | 1057 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1058 | if (*nrels_mag >= 1) { |
| | 1059 | down(&data->update_lock); |
| | 1060 | data->block8[nr] = LM93_FAN_TO_REG(results[0]); |
| | 1061 | lm93_write_word(client, LM93_REG_FAN_MIN(nr), |
| | 1062 | data->block8[nr]); |
| | 1063 | up(&data->update_lock); |
| | 1064 | } |
| | 1065 | } |
| | 1066 | } |
| | 1067 | |
| | 1068 | /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6% |
| | 1069 | * REG: (same) */ |
| | 1070 | static u8 LM93_PROCHOT_TO_REG(long prochot) |
| | 1071 | { |
| | 1072 | prochot = SENSORS_LIMIT(prochot, 0, 255); |
| | 1073 | return (u8)prochot; |
| | 1074 | } |
| | 1075 | |
| | 1076 | static void lm93_prochot(struct i2c_client *client, int operation, |
| | 1077 | int ctl_name, int *nrels_mag, long *results) |
| | 1078 | { |
| | 1079 | struct lm93_data *data = client->data; |
| | 1080 | int nr = ctl_name - LM93_SYSCTL_PROCHOT1; |
| | 1081 | |
| | 1082 | if (0 > nr || nr > 1) |
| | 1083 | return; /* ERROR */ |
| | 1084 | |
| | 1085 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1086 | *nrels_mag = 0; |
| | 1087 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1088 | lm93_update_client(client); |
| | 1089 | results[0] = data->prochot_max[nr]; |
| | 1090 | results[1] = data->block4[nr].avg; |
| | 1091 | results[2] = data->block4[nr].avg; |
| | 1092 | *nrels_mag = 3; |
| | 1093 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1094 | down(&data->update_lock); |
| | 1095 | if (*nrels_mag >= 1) { |
| | 1096 | data->prochot_max[nr] = LM93_PROCHOT_TO_REG(results[0]); |
| | 1097 | lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr), |
| | 1098 | data->prochot_max[nr]); |
| | 1099 | } |
| | 1100 | up(&data->update_lock); |
| | 1101 | } |
| | 1102 | } |
| | 1103 | |
| | 1104 | /* PROCHOT-OVERRIDE; 0-15, 0 is 6.25%, 15 is 99.88% |
| | 1105 | * REG: (same) */ |
| | 1106 | static u8 LM93_PROCHOT_OVERRIDE_TO_REG(int force1, int force2, long prochot) |
| | 1107 | { |
| | 1108 | u8 result = 0; |
| | 1109 | |
| | 1110 | result |= force1 ? 0x80 : 0x00; |
| | 1111 | result |= force2 ? 0x40 : 0x00; |
| | 1112 | prochot = SENSORS_LIMIT(prochot, 0, 15); |
| | 1113 | result |= prochot; |
| | 1114 | return result; |
| | 1115 | } |
| | 1116 | |
| | 1117 | static void lm93_prochot_override(struct i2c_client *client, int operation, |
| | 1118 | int ctl_name, int *nrels_mag, long *results) |
| | 1119 | { |
| | 1120 | struct lm93_data *data = client->data; |
| | 1121 | |
| | 1122 | if (ctl_name != LM93_SYSCTL_PROCHOT_OVERRIDE) |
| | 1123 | return; /* ERROR */ |
| | 1124 | |
| | 1125 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1126 | *nrels_mag = 0; |
| | 1127 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1128 | lm93_update_client(client); |
| | 1129 | results[0] = (data->prochot_override & 0x80) ? 1 : 0; |
| | 1130 | results[1] = (data->prochot_override & 0x40) ? 1 : 0; |
| | 1131 | results[2] = data->prochot_override & 0x0f; |
| | 1132 | *nrels_mag = 3; |
| | 1133 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1134 | |
| | 1135 | /* grab old values */ |
| | 1136 | int force2 = (data->prochot_override & 0x40) ? 1 : 0; |
| | 1137 | int prochot = data->prochot_override & 0x0f; |
| | 1138 | |
| | 1139 | down(&data->update_lock); |
| | 1140 | if (*nrels_mag >= 3) { |
| | 1141 | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
| | 1142 | results[0], results[1], results[2]); |
| | 1143 | } |
| | 1144 | if (*nrels_mag == 2) { |
| | 1145 | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
| | 1146 | results[0], results[1], prochot); |
| | 1147 | } |
| | 1148 | if (*nrels_mag == 1) { |
| | 1149 | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
| | 1150 | results[0], force2, prochot); |
| | 1151 | } |
| | 1152 | if (*nrels_mag >= 1) { |
| | 1153 | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, |
| | 1154 | data->prochot_override); |
| | 1155 | } |
| | 1156 | up(&data->update_lock); |
| | 1157 | } |
| | 1158 | } |
| | 1159 | |
| | 1160 | /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds) |
| | 1161 | * REG: 0-9 as mapped below */ |
| | 1162 | static int lm93_interval_map[10] = { |
| | 1163 | 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200, |
| | 1164 | }; |
| | 1165 | |
| | 1166 | static int LM93_INTERVAL_FROM_REG(u8 reg) |
| | 1167 | { |
| | 1168 | return lm93_interval_map[reg & 0x0f]; |
| | 1169 | } |
| | 1170 | |
| | 1171 | /* round up to nearest match */ |
| | 1172 | static u8 LM93_INTERVAL_TO_REG(long interval) |
| | 1173 | { |
| | 1174 | int i; |
| | 1175 | for (i = 0; i < 9; i++) |
| | 1176 | if (interval <= lm93_interval_map[i]) |
| | 1177 | break; |
| | 1178 | |
| | 1179 | /* can fall through with i==9 */ |
| | 1180 | return (u8)i; |
| | 1181 | } |
| | 1182 | |
| | 1183 | static void lm93_prochot_interval(struct i2c_client *client, int operation, |
| | 1184 | int ctl_name, int *nrels_mag, long *results) |
| | 1185 | { |
| | 1186 | struct lm93_data *data = client->data; |
| | 1187 | |
| | 1188 | if (ctl_name != LM93_SYSCTL_PROCHOT_INTERVAL) |
| | 1189 | return; /* ERROR */ |
| | 1190 | |
| | 1191 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1192 | *nrels_mag = 2; |
| | 1193 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1194 | lm93_update_client(client); |
| | 1195 | results[0] = LM93_INTERVAL_FROM_REG( |
| | 1196 | data->prochot_interval & 0x0f); |
| | 1197 | results[1] = LM93_INTERVAL_FROM_REG( |
| | 1198 | (data->prochot_interval & 0xf0) >> 4); |
| | 1199 | *nrels_mag = 2; |
| | 1200 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1201 | down(&data->update_lock); |
| | 1202 | data->prochot_interval = lm93_read_byte(client, |
| | 1203 | LM93_REG_PROCHOT_INTERVAL); |
| | 1204 | if (*nrels_mag >= 2) { |
| | 1205 | data->prochot_interval = |
| | 1206 | (LM93_INTERVAL_TO_REG(results[1]) << 4) | |
| | 1207 | (data->prochot_interval & 0x0f); |
| | 1208 | } |
| | 1209 | if (*nrels_mag >= 1) { |
| | 1210 | data->prochot_interval = |
| | 1211 | (data->prochot_interval & 0xf0) | |
| | 1212 | LM93_INTERVAL_TO_REG(results[0]); |
| | 1213 | lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, |
| | 1214 | data->prochot_interval); |
| | 1215 | } |
| | 1216 | up(&data->update_lock); |
| | 1217 | } |
| | 1218 | } |
| | 1219 | |
| | 1220 | /* PWM: 0-255 per sensors documentation |
| | 1221 | REG: 0-13 as mapped below... right justified */ |
| | 1222 | typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t; |
| | 1223 | static int lm93_pwm_map[2][14] = { |
| | 1224 | { |
| | 1225 | 0x00, /* 0.00% */ 0x40, /* 25.00% */ |
| | 1226 | 0x50, /* 31.25% */ 0x60, /* 37.50% */ |
| | 1227 | 0x70, /* 43.75% */ 0x80, /* 50.00% */ |
| | 1228 | 0x90, /* 56.25% */ 0xa0, /* 62.50% */ |
| | 1229 | 0xb0, /* 68.75% */ 0xc0, /* 75.00% */ |
| | 1230 | 0xd0, /* 81.25% */ 0xe0, /* 87.50% */ |
| | 1231 | 0xf0, /* 93.75% */ 0xff, /* 100.00% */ |
| | 1232 | }, |
| | 1233 | { |
| | 1234 | 0x00, /* 0.00% */ 0x40, /* 25.00% */ |
| | 1235 | 0x49, /* 28.57% */ 0x52, /* 32.14% */ |
| | 1236 | 0x5b, /* 35.71% */ 0x64, /* 39.29% */ |
| | 1237 | 0x6d, /* 42.86% */ 0x76, /* 46.43% */ |
| | 1238 | 0x80, /* 50.00% */ 0x89, /* 53.57% */ |
| | 1239 | 0x92, /* 57.14% */ 0xb6, /* 71.43% */ |
| | 1240 | 0xdb, /* 85.71% */ 0xff, /* 100.00% */ |
| | 1241 | }, |
| | 1242 | }; |
| | 1243 | |
| | 1244 | static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq) |
| | 1245 | { |
| | 1246 | return lm93_pwm_map[freq][reg & 0x0f]; |
| | 1247 | } |
| | 1248 | |
| | 1249 | /* round up to nearest match */ |
| | 1250 | static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq) |
| | 1251 | { |
| | 1252 | int i; |
| | 1253 | for (i = 0; i < 13; i++) |
| | 1254 | if (pwm <= lm93_pwm_map[freq][i]) |
| | 1255 | break; |
| | 1256 | |
| | 1257 | /* can fall through with i==13 */ |
| | 1258 | return (u8)i; |
| | 1259 | } |
| | 1260 | |
| | 1261 | static void lm93_pwm(struct i2c_client *client, int operation, int ctl_name, |
| | 1262 | int *nrels_mag, long *results) |
| | 1263 | { |
| | 1264 | struct lm93_data *data = client->data; |
| | 1265 | int nr = ctl_name - LM93_SYSCTL_PWM1; |
| | 1266 | u8 ctl2, ctl4; |
| | 1267 | |
| | 1268 | if (0 > nr || nr > 1) |
| | 1269 | return; /* ERROR */ |
| | 1270 | |
| | 1271 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1272 | *nrels_mag = 0; |
| | 1273 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1274 | lm93_update_client(client); |
| | 1275 | ctl2 = data->block9[nr][LM93_PWM_CTL2]; |
| | 1276 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| | 1277 | results[1] = (ctl2 & 0x01) ? 1 : 0; |
| | 1278 | ctl2 = ctl2 >> 4 & 0x0f; |
| | 1279 | if (results[1]) /* show user commanded value if enabled */ |
| | 1280 | results[0] = data->pwm_override[nr]; |
| | 1281 | else /* show present h/w value if manual pwm disabled */ |
| | 1282 | results[0] = LM93_PWM_FROM_REG(ctl2, (ctl4 & 0x07) ? |
| | 1283 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
| | 1284 | *nrels_mag = 2; |
| | 1285 | } |
| | 1286 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1287 | if (*nrels_mag >= 1) { |
| | 1288 | down(&data->update_lock); |
| | 1289 | ctl2 = lm93_read_byte( |
| | 1290 | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); |
| | 1291 | ctl4 = lm93_read_byte( |
| | 1292 | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
| | 1293 | ctl2 = (ctl2 & 0x0f) | |
| | 1294 | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
| | 1295 | LM93_PWM_MAP_LO_FREQ : |
| | 1296 | LM93_PWM_MAP_HI_FREQ) << 4; |
| | 1297 | if (*nrels_mag >= 2) { |
| | 1298 | if (results[1]) |
| | 1299 | ctl2 |= 0x01; |
| | 1300 | else |
| | 1301 | ctl2 &= ~0x01; |
| | 1302 | } |
| | 1303 | /* save user commanded value */ |
| | 1304 | data->pwm_override[nr] = |
| | 1305 | LM93_PWM_FROM_REG(ctl2 >> 4 & 0x0f, |
| | 1306 | (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : |
| | 1307 | LM93_PWM_MAP_HI_FREQ); |
| | 1308 | lm93_write_byte(client, |
| | 1309 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2), ctl2); |
| | 1310 | up(&data->update_lock); |
| | 1311 | } |
| | 1312 | } |
| | 1313 | } |
| | 1314 | |
| | 1315 | /* PWM FREQ: HZ |
| | 1316 | REG: 0-7 as mapped below */ |
| | 1317 | static int lm93_pwm_freq_map[8] = { |
| | 1318 | 22500, 96, 84, 72, 60, 48, 36, 12 |
| | 1319 | }; |
| | 1320 | |
| | 1321 | static int LM93_PWM_FREQ_FROM_REG(u8 reg) |
| | 1322 | { |
| | 1323 | return lm93_pwm_freq_map[reg & 0x07]; |
| | 1324 | } |
| | 1325 | |
| | 1326 | /* round up to nearest match */ |
| | 1327 | static u8 LM93_PWM_FREQ_TO_REG(int freq) |
| | 1328 | { |
| | 1329 | int i; |
| | 1330 | for (i = 7; i > 0; i--) |
| | 1331 | if (freq <= lm93_pwm_freq_map[i]) |
| | 1332 | break; |
| | 1333 | |
| | 1334 | /* can fall through with i==0 */ |
| | 1335 | return (u8)i; |
| | 1336 | } |
| | 1337 | |
| | 1338 | /* helper function - must grab data->update_lock before calling |
| | 1339 | fan is 0-3, indicating fan1-fan4 */ |
| | 1340 | static void lm93_write_fan_smart_tach(struct i2c_client *client, |
| | 1341 | struct lm93_data *data, int fan, long value) |
| | 1342 | { |
| | 1343 | /* insert the new mapping and write it out */ |
| | 1344 | data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); |
| | 1345 | data->sf_tach_to_pwm &= ~0x3 << fan * 2; |
| | 1346 | data->sf_tach_to_pwm |= value << fan * 2; |
| | 1347 | lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm); |
| | 1348 | |
| | 1349 | /* insert the enable bit and write it out */ |
| | 1350 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| | 1351 | if (value) |
| | 1352 | data->sfc2 |= 1 << fan; |
| | 1353 | else |
| | 1354 | data->sfc2 &= ~1 << fan; |
| | 1355 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| | 1356 | } |
| | 1357 | |
| | 1358 | /* helper function - must grab data->update_lock before calling |
| | 1359 | pwm is 0-1, indicating pwm1-pwm2 |
| | 1360 | this disables smart tach for all tach channels bound to the given pwm */ |
| | 1361 | static void lm93_disable_fan_smart_tach(struct i2c_client *client, |
| | 1362 | struct lm93_data *data, int pwm) |
| | 1363 | { |
| | 1364 | int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); |
| | 1365 | int mask; |
| | 1366 | |
| | 1367 | /* collapse the mapping into a mask of enable bits */ |
| | 1368 | mapping = (mapping >> pwm) & 0x55; |
| | 1369 | mask = mapping & 0x01; |
| | 1370 | mask |= (mapping & 0x04) >> 1; |
| | 1371 | mask |= (mapping & 0x10) >> 2; |
| | 1372 | mask |= (mapping & 0x40) >> 3; |
| | 1373 | |
| | 1374 | /* disable smart tach according to the mask */ |
| | 1375 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| | 1376 | data->sfc2 &= ~mask; |
| | 1377 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| | 1378 | } |
| | 1379 | |
| | 1380 | static void lm93_pwm_freq(struct i2c_client *client, int operation, |
| | 1381 | int ctl_name, int *nrels_mag, long *results) |
| | 1382 | { |
| | 1383 | struct lm93_data *data = client->data; |
| | 1384 | int nr = ctl_name - LM93_SYSCTL_PWM1_FREQ; |
| | 1385 | u8 ctl4; |
| | 1386 | |
| | 1387 | if (0 > nr || nr > 1) |
| | 1388 | return; /* ERROR */ |
| | 1389 | |
| | 1390 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1391 | *nrels_mag = 0; |
| | 1392 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1393 | lm93_update_client(client); |
| | 1394 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| | 1395 | results[0] = LM93_PWM_FREQ_FROM_REG(ctl4); |
| | 1396 | *nrels_mag = 1; |
| | 1397 | } |
| | 1398 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1399 | if (*nrels_mag >= 1) { |
| | 1400 | down(&data->update_lock); |
| | 1401 | ctl4 = lm93_read_byte( client, |
| | 1402 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
| | 1403 | ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(results[0]); |
| | 1404 | data->block9[nr][LM93_PWM_CTL4] = ctl4; |
| | 1405 | |
| | 1406 | /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ |
| | 1407 | if (!ctl4) |
| | 1408 | lm93_disable_fan_smart_tach(client, data, nr); |
| | 1409 | |
| | 1410 | lm93_write_byte(client, |
| | 1411 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4); |
| | 1412 | up(&data->update_lock); |
| | 1413 | } |
| | 1414 | } |
| | 1415 | } |
| | 1416 | |
| | 1417 | /* GPIO: 0-255, GPIO0 is LSB |
| | 1418 | * REG: inverted */ |
| | 1419 | static unsigned LM93_GPI_FROM_REG(u8 reg) |
| | 1420 | { |
| | 1421 | return ~reg & 0xff; |
| | 1422 | } |
| | 1423 | |
| | 1424 | static void lm93_gpio(struct i2c_client *client, int operation, int ctl_name, |
| | 1425 | int *nrels_mag, long *results) |
| | 1426 | { |
| | 1427 | struct lm93_data *data = client->data; |
| | 1428 | |
| | 1429 | if (ctl_name != LM93_SYSCTL_GPIO) |
| | 1430 | return; /* ERROR */ |
| | 1431 | |
| | 1432 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1433 | *nrels_mag = 0; |
| | 1434 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1435 | lm93_update_client(client); |
| | 1436 | results[0] = LM93_GPI_FROM_REG(data->gpi); |
| | 1437 | *nrels_mag = 1; |
| | 1438 | } |
| | 1439 | } |
| | 1440 | |
| | 1441 | static void lm93_temp_auto_base(struct i2c_client *client, int operation, |
| | 1442 | int ctl_name, int *nrels_mag, long *results) |
| | 1443 | { |
| | 1444 | struct lm93_data *data = client->data; |
| | 1445 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BASE; |
| | 1446 | |
| | 1447 | if (0 > nr || nr > 2) |
| | 1448 | return; /* ERROR */ |
| | 1449 | |
| | 1450 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1451 | *nrels_mag = 1; |
| | 1452 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1453 | lm93_update_client(client); |
| | 1454 | results[0] = LM93_TEMP_FROM_REG(data->block10.base[nr]); |
| | 1455 | *nrels_mag = 1; |
| | 1456 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1457 | down(&data->update_lock); |
| | 1458 | if (*nrels_mag >= 1) { |
| | 1459 | data->block10.base[nr] = LM93_TEMP_TO_REG(results[0]); |
| | 1460 | lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), |
| | 1461 | data->block10.base[nr]); |
| | 1462 | } |
| | 1463 | up(&data->update_lock); |
| | 1464 | } |
| | 1465 | } |
| | 1466 | |
| | 1467 | static void lm93_temp_auto_boost(struct i2c_client *client, int operation, |
| | 1468 | int ctl_name, int *nrels_mag, long *results) |
| | 1469 | { |
| | 1470 | struct lm93_data *data = client->data; |
| | 1471 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BOOST; |
| | 1472 | |
| | 1473 | if (0 > nr || nr > 2) |
| | 1474 | return; /* ERROR */ |
| | 1475 | |
| | 1476 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1477 | *nrels_mag = 1; |
| | 1478 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1479 | lm93_update_client(client); |
| | 1480 | results[0] = LM93_TEMP_FROM_REG(data->boost[nr]); |
| | 1481 | *nrels_mag = 1; |
| | 1482 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1483 | down(&data->update_lock); |
| | 1484 | if (*nrels_mag >= 1) { |
| | 1485 | data->boost[nr] = LM93_TEMP_TO_REG(results[0]); |
| | 1486 | lm93_write_byte(client, LM93_REG_BOOST(nr), |
| | 1487 | data->boost[nr]); |
| | 1488 | } |
| | 1489 | up(&data->update_lock); |
| | 1490 | } |
| | 1491 | |
| | 1492 | } |
| | 1493 | |
| | 1494 | static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst, |
| | 1495 | int nr, int mode) |
| | 1496 | { |
| | 1497 | u8 reg = LM93_TEMP_OFFSET_TO_REG( |
| | 1498 | (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode); |
| | 1499 | |
| | 1500 | switch (nr) { |
| | 1501 | case 0: |
| | 1502 | reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f); |
| | 1503 | break; |
| | 1504 | case 1: |
| | 1505 | reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f); |
| | 1506 | break; |
| | 1507 | case 2: |
| | 1508 | reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f); |
| | 1509 | break; |
| | 1510 | case 3: |
| | 1511 | default: |
| | 1512 | reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f); |
| | 1513 | break; |
| | 1514 | } |
| | 1515 | |
| | 1516 | return reg; |
| | 1517 | } |
| | 1518 | |
| | 1519 | static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr, |
| | 1520 | int mode) |
| | 1521 | { |
| | 1522 | u8 reg; |
| | 1523 | |
| | 1524 | switch (nr) { |
| | 1525 | case 0: |
| | 1526 | reg = data->boost_hyst[0] & 0x0f; |
| | 1527 | break; |
| | 1528 | case 1: |
| | 1529 | reg = data->boost_hyst[0] >> 4 & 0x0f; |
| | 1530 | break; |
| | 1531 | case 2: |
| | 1532 | reg = data->boost_hyst[1] & 0x0f; |
| | 1533 | break; |
| | 1534 | case 3: |
| | 1535 | default: |
| | 1536 | reg = data->boost_hyst[1] >> 4 & 0x0f; |
| | 1537 | break; |
| | 1538 | } |
| | 1539 | |
| | 1540 | return LM93_TEMP_FROM_REG(data->boost[nr]) - |
| | 1541 | LM93_TEMP_OFFSET_FROM_REG(reg, mode); |
| | 1542 | } |
| | 1543 | |
| | 1544 | static void lm93_temp_auto_boost_hyst(struct i2c_client *client, int operation, |
| | 1545 | int ctl_name, int *nrels_mag, long *results) |
| | 1546 | { |
| | 1547 | struct lm93_data *data = client->data; |
| | 1548 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BOOST_HYST; |
| | 1549 | |
| | 1550 | if (0 > nr || nr > 2) |
| | 1551 | return; /* ERROR */ |
| | 1552 | |
| | 1553 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1554 | *nrels_mag = 1; |
| | 1555 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1556 | int mode; |
| | 1557 | lm93_update_client(client); |
| | 1558 | |
| | 1559 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| | 1560 | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
| | 1561 | |
| | 1562 | results[0] = LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode); |
| | 1563 | *nrels_mag = 1; |
| | 1564 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1565 | if (*nrels_mag >= 1) { |
| | 1566 | down(&data->update_lock); |
| | 1567 | |
| | 1568 | /* force 0.5C/bit mode */ |
| | 1569 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| | 1570 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
| | 1571 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| | 1572 | |
| | 1573 | data->boost_hyst[nr/2] = |
| | 1574 | LM93_AUTO_BOOST_HYST_TO_REG(data, |
| | 1575 | results[0], nr, 1); |
| | 1576 | lm93_write_byte(client, LM93_REG_BOOST_HYST(nr), |
| | 1577 | data->boost_hyst[nr/2]); |
| | 1578 | up(&data->update_lock); |
| | 1579 | } |
| | 1580 | } |
| | 1581 | } |
| | 1582 | |
| | 1583 | static void lm93_temp_auto_pwm_min(struct i2c_client *client, int operation, |
| | 1584 | int ctl_name, int *nrels_mag, long *results) |
| | 1585 | { |
| | 1586 | struct lm93_data *data = client->data; |
| | 1587 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_PWM_MIN; |
| | 1588 | u8 reg, ctl4; |
| | 1589 | |
| | 1590 | if (0 > nr || nr > 2) |
| | 1591 | return; /* ERROR */ |
| | 1592 | |
| | 1593 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1594 | *nrels_mag = 0; |
| | 1595 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1596 | lm93_update_client(client); |
| | 1597 | reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; |
| | 1598 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| | 1599 | results[0] = LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? |
| | 1600 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
| | 1601 | *nrels_mag = 1; |
| | 1602 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1603 | if (*nrels_mag >= 1) { |
| | 1604 | down(&data->update_lock); |
| | 1605 | reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); |
| | 1606 | ctl4 = lm93_read_byte( |
| | 1607 | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
| | 1608 | reg = (reg & 0x0f) | |
| | 1609 | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
| | 1610 | LM93_PWM_MAP_LO_FREQ : |
| | 1611 | LM93_PWM_MAP_HI_FREQ) << 4; |
| | 1612 | |
| | 1613 | data->auto_pwm_min_hyst[nr/2] = reg; |
| | 1614 | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); |
| | 1615 | up(&data->update_lock); |
| | 1616 | } |
| | 1617 | } |
| | 1618 | } |
| | 1619 | |
| | 1620 | static void lm93_temp_auto_offset_hyst(struct i2c_client *client, int operation, |
| | 1621 | int ctl_name, int *nrels_mag, long *results) |
| | 1622 | { |
| | 1623 | struct lm93_data *data = client->data; |
| | 1624 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_OFFSET_HYST; |
| | 1625 | |
| | 1626 | if (0 > nr || nr > 2) |
| | 1627 | return; /* ERROR */ |
| | 1628 | |
| | 1629 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1630 | *nrels_mag = 1; |
| | 1631 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1632 | int mode; |
| | 1633 | lm93_update_client(client); |
| | 1634 | |
| | 1635 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| | 1636 | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
| | 1637 | |
| | 1638 | results[0] = LM93_TEMP_OFFSET_FROM_REG( |
| | 1639 | data->auto_pwm_min_hyst[nr/2], mode); |
| | 1640 | |
| | 1641 | *nrels_mag = 1; |
| | 1642 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1643 | if (*nrels_mag >= 1) { |
| | 1644 | u8 reg; |
| | 1645 | down(&data->update_lock); |
| | 1646 | |
| | 1647 | /* force 0.5C/bit mode */ |
| | 1648 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| | 1649 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
| | 1650 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| | 1651 | |
| | 1652 | reg = data->auto_pwm_min_hyst[nr/2]; |
| | 1653 | reg = (reg & 0xf0) | |
| | 1654 | (LM93_TEMP_OFFSET_TO_REG(results[0], 1) & 0x0f); |
| | 1655 | |
| | 1656 | data->auto_pwm_min_hyst[nr/2] = reg; |
| | 1657 | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); |
| | 1658 | up(&data->update_lock); |
| | 1659 | } |
| | 1660 | } |
| | 1661 | } |
| | 1662 | |
| | 1663 | /* some tedious bit-twiddling here to deal with the register format: |
| | 1664 | |
| | 1665 | data->sf_tach_to_pwm: (tach to pwm mapping bits) |
| | 1666 | |
| | 1667 | bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| | 1668 | T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1 |
| | 1669 | |
| | 1670 | data->sfc2: (enable bits) |
| | 1671 | |
| | 1672 | bit | 3 | 2 | 1 | 0 |
| | 1673 | T4 T3 T2 T1 |
| | 1674 | */ |
| | 1675 | |
| | 1676 | static void lm93_fan_smart_tach(struct i2c_client *client, int operation, |
| | 1677 | int ctl_name, int *nrels_mag, long *results) |
| | 1678 | { |
| | 1679 | struct lm93_data *data = client->data; |
| | 1680 | int nr = ctl_name - LM93_SYSCTL_FAN1_SMART_TACH; |
| | 1681 | |
| | 1682 | if (0 > nr || nr > 3) |
| | 1683 | return; /* ERROR */ |
| | 1684 | |
| | 1685 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1686 | *nrels_mag = 0; |
| | 1687 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1688 | lm93_update_client(client); |
| | 1689 | |
| | 1690 | /* extract the relevant mapping */ |
| | 1691 | int mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03; |
| | 1692 | |
| | 1693 | /* if there's a mapping and it's enabled */ |
| | 1694 | if (mapping && ((data->sfc2 >> nr) & 0x01)) |
| | 1695 | results[0] = mapping; |
| | 1696 | else |
| | 1697 | results[0] = 0; |
| | 1698 | |
| | 1699 | *nrels_mag = 1; |
| | 1700 | |
| | 1701 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1702 | if (*nrels_mag >= 1) { |
| | 1703 | down(&data->update_lock); |
| | 1704 | |
| | 1705 | /* sanity test, ignore the write otherwise */ |
| | 1706 | if (0 <= results[0] && results[0] <= 2) { |
| | 1707 | |
| | 1708 | /* can't enable if pwm freq is 22.5KHz */ |
| | 1709 | if (results[0]) { |
| | 1710 | u8 ctl4 = lm93_read_byte(client, |
| | 1711 | LM93_REG_PWM_CTL(results[0]-1, |
| | 1712 | LM93_PWM_CTL4)); |
| | 1713 | if ((ctl4 & 0x07) == 0) |
| | 1714 | results[0] = 0; |
| | 1715 | } |
| | 1716 | |
| | 1717 | lm93_write_fan_smart_tach(client, data, nr, |
| | 1718 | results[0]); |
| | 1719 | } |
| | 1720 | up(&data->update_lock); |
| | 1721 | } |
| | 1722 | } |
| | 1723 | } |
| | 1724 | |
| | 1725 | static void lm93_prochot_short(struct i2c_client *client, int operation, |
| | 1726 | int ctl_name, int *nrels_mag, long *results) |
| | 1727 | { |
| | 1728 | struct lm93_data *data = client->data; |
| | 1729 | |
| | 1730 | if (ctl_name != LM93_SYSCTL_PROCHOT_SHORT) |
| | 1731 | return; /* ERROR */ |
| | 1732 | |
| | 1733 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1734 | *nrels_mag = 0; |
| | 1735 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1736 | lm93_update_client(client); |
| | 1737 | results[0] = (data->config & 0x10) ? 1 : 0; |
| | 1738 | *nrels_mag = 1; |
| | 1739 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1740 | down(&data->update_lock); |
| | 1741 | if (*nrels_mag >= 1) { |
| | 1742 | if (results[0]) |
| | 1743 | data->config |= 0x10; |
| | 1744 | else |
| | 1745 | data->config &= ~0x10; |
| | 1746 | lm93_write_byte(client, LM93_REG_CONFIG, data->config); |
| | 1747 | } |
| | 1748 | up(&data->update_lock); |
| | 1749 | } |
| | 1750 | } |
| | 1751 | |
| | 1752 | static void lm93_vrdhot(struct i2c_client *client, int operation, |
| | 1753 | int ctl_name, int *nrels_mag, long *results) |
| | 1754 | { |
| | 1755 | struct lm93_data *data = client->data; |
| | 1756 | int nr = ctl_name - LM93_SYSCTL_VRDHOT1; |
| | 1757 | |
| | 1758 | if (0 > nr || nr > 1) |
| | 1759 | return; /* ERROR */ |
| | 1760 | |
| | 1761 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1762 | *nrels_mag = 0; |
| | 1763 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1764 | lm93_update_client(client); |
| | 1765 | results[0] = data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0; |
| | 1766 | *nrels_mag = 1; |
| | 1767 | } |
| | 1768 | } |
| | 1769 | |
| | 1770 | static void lm93_pwm_auto_chan(struct i2c_client *client, int operation, |
| | 1771 | int ctl_name, int *nrels_mag, long *results) |
| | 1772 | { |
| | 1773 | struct lm93_data *data = client->data; |
| | 1774 | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_CHANNELS; |
| | 1775 | |
| | 1776 | if (0 > nr || nr > 1) |
| | 1777 | return; /* ERROR */ |
| | 1778 | |
| | 1779 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1780 | *nrels_mag = 0; |
| | 1781 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1782 | lm93_update_client(client); |
| | 1783 | results[0] = data->block9[nr][LM93_PWM_CTL1]; |
| | 1784 | *nrels_mag = 1; |
| | 1785 | } |
| | 1786 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1787 | if (*nrels_mag >= 1) { |
| | 1788 | down(&data->update_lock); |
| | 1789 | data->block9[nr][LM93_PWM_CTL1] = |
| | 1790 | SENSORS_LIMIT(results[0], 0, 255); |
| | 1791 | lm93_write_byte(client, |
| | 1792 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1), |
| | 1793 | data->block9[nr][LM93_PWM_CTL1]); |
| | 1794 | up(&data->update_lock); |
| | 1795 | } |
| | 1796 | } |
| | 1797 | } |
| | 1798 | |
| | 1799 | static void lm93_pwm_auto_spinup_min(struct i2c_client *client, int operation, |
| | 1800 | int ctl_name, int *nrels_mag, long *results) |
| | 1801 | { |
| | 1802 | struct lm93_data *data = client->data; |
| | 1803 | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_SPINUP_MIN; |
| | 1804 | u8 ctl3, ctl4; |
| | 1805 | |
| | 1806 | if (0 > nr || nr > 1) |
| | 1807 | return; /* ERROR */ |
| | 1808 | |
| | 1809 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1810 | *nrels_mag = 0; |
| | 1811 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1812 | lm93_update_client(client); |
| | 1813 | ctl3 = data->block9[nr][LM93_PWM_CTL3]; |
| | 1814 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| | 1815 | results[0] = LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ? |
| | 1816 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
| | 1817 | *nrels_mag = 1; |
| | 1818 | } |
| | 1819 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1820 | if (*nrels_mag >= 1) { |
| | 1821 | down(&data->update_lock); |
| | 1822 | ctl3 = lm93_read_byte(client, |
| | 1823 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); |
| | 1824 | ctl4 = lm93_read_byte(client, |
| | 1825 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4)); |
| | 1826 | ctl3 = (ctl3 & 0xf0) | |
| | 1827 | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
| | 1828 | LM93_PWM_MAP_LO_FREQ : |
| | 1829 | LM93_PWM_MAP_HI_FREQ); |
| | 1830 | data->block9[nr][LM93_PWM_CTL3] = ctl3; |
| | 1831 | lm93_write_byte(client, |
| | 1832 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); |
| | 1833 | up(&data->update_lock); |
| | 1834 | } |
| | 1835 | } |
| | 1836 | } |
| | 1837 | |
| | 1838 | /* TIME: 1/100 seconds |
| | 1839 | * REG: 0-7 as mapped below */ |
| | 1840 | static int lm93_spinup_time_map[8] = { |
| | 1841 | 0, 10, 25, 40, 70, 100, 200, 400, |
| | 1842 | }; |
| | 1843 | |
| | 1844 | static int LM93_SPINUP_TIME_FROM_REG(u8 reg) |
| | 1845 | { |
| | 1846 | return lm93_spinup_time_map[reg >> 5 & 0x07]; |
| | 1847 | } |
| | 1848 | |
| | 1849 | /* round up to nearest match */ |
| | 1850 | static u8 LM93_SPINUP_TIME_TO_REG(int time) |
| | 1851 | { |
| | 1852 | int i; |
| | 1853 | for (i = 0; i < 7; i++) |
| | 1854 | if (time <= lm93_spinup_time_map[i]) |
| | 1855 | break; |
| | 1856 | |
| | 1857 | /* can fall through with i==8 */ |
| | 1858 | return (u8)i; |
| | 1859 | } |
| | 1860 | |
| | 1861 | static void lm93_pwm_auto_spinup_time(struct i2c_client *client, int operation, |
| | 1862 | int ctl_name, int *nrels_mag, long *results) |
| | 1863 | { |
| | 1864 | struct lm93_data *data = client->data; |
| | 1865 | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_SPINUP_TIME; |
| | 1866 | |
| | 1867 | if (0 > nr || nr > 1) |
| | 1868 | return; /* ERROR */ |
| | 1869 | |
| | 1870 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1871 | *nrels_mag = 2; |
| | 1872 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1873 | lm93_update_client(client); |
| | 1874 | results[0] = LM93_SPINUP_TIME_FROM_REG( |
| | 1875 | data->block9[nr][LM93_PWM_CTL3]); |
| | 1876 | *nrels_mag = 1; |
| | 1877 | } |
| | 1878 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1879 | if (*nrels_mag >= 1) { |
| | 1880 | u8 ctl3; |
| | 1881 | down(&data->update_lock); |
| | 1882 | ctl3 = lm93_read_byte(client, |
| | 1883 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); |
| | 1884 | ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG( |
| | 1885 | results[0]) << 5 & 0xe0); |
| | 1886 | data->block9[nr][LM93_PWM_CTL3] = ctl3; |
| | 1887 | lm93_write_byte(client, |
| | 1888 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); |
| | 1889 | up(&data->update_lock); |
| | 1890 | } |
| | 1891 | } |
| | 1892 | } |
| | 1893 | |
| | 1894 | #define LM93_RAMP_MIN 0 |
| | 1895 | #define LM93_RAMP_MAX 75 |
| | 1896 | |
| | 1897 | /* RAMP: 1/100 seconds |
| | 1898 | REG: 50mS/bit 4-bits right justified */ |
| | 1899 | static u8 LM93_RAMP_TO_REG(int ramp) |
| | 1900 | { |
| | 1901 | ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); |
| | 1902 | return (u8)((ramp + 2) / 5); |
| | 1903 | } |
| | 1904 | |
| | 1905 | static int LM93_RAMP_FROM_REG(u8 reg) |
| | 1906 | { |
| | 1907 | return (reg & 0x0f) * 5; |
| | 1908 | } |
| | 1909 | |
| | 1910 | static void lm93_pwm_auto_ramp(struct i2c_client *client, int operation, |
| | 1911 | int ctl_name, int *nrels_mag, long *results) |
| | 1912 | { |
| | 1913 | struct lm93_data *data = client->data; |
| | 1914 | |
| | 1915 | if (!(ctl_name == LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP || |
| | 1916 | ctl_name == LM93_SYSCTL_PWM_AUTO_VRDHOT_RAMP)) |
| | 1917 | return; /* ERROR */ |
| | 1918 | |
| | 1919 | if (operation == SENSORS_PROC_REAL_INFO) |
| | 1920 | *nrels_mag = 2; |
| | 1921 | else if (operation == SENSORS_PROC_REAL_READ) { |
| | 1922 | lm93_update_client(client); |
| | 1923 | if (ctl_name == LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP) |
| | 1924 | results[0] = LM93_RAMP_FROM_REG( |
| | 1925 | data->pwm_ramp_ctl >> 4 & 0x0f); |
| | 1926 | else |
| | 1927 | results[0] = LM93_RAMP_FROM_REG( |
| | 1928 | data->pwm_ramp_ctl & 0x0f); |
| | 1929 | *nrels_mag = 1; |
| | 1930 | } |
| | 1931 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| | 1932 | if (*nrels_mag >= 1) { |
| | 1933 | u8 ramp; |
| | 1934 | down(&data->update_lock); |
| | 1935 | ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); |
| | 1936 | if (ctl_name == LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP) |
| | 1937 | ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG( |
| | 1938 | results[0]) << 4 & 0xf0); |
| | 1939 | else |
| | 1940 | ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG( |
| | 1941 | results[0]) & 0x0f); |
| | 1942 | lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp); |
| | 1943 | up(&data->update_lock); |
| | 1944 | } |
| | 1945 | } |
| | 1946 | } |
| 1078 | | #define MAX_RETRIES 5 |
| 1079 | | |
| 1080 | | static u8 lm93_read_byte(struct i2c_client *client, u8 reg) |
| 1081 | | { |
| 1082 | | int value, i; |
| 1083 | | |
| 1084 | | /* retry in case of read errors */ |
| 1085 | | for (i=1; i<=MAX_RETRIES; i++) { |
| 1086 | | if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) { |
| 1087 | | return value; |
| 1088 | | } else { |
| 1089 | | printk(KERN_WARNING "lm93.o: read byte data failed, " |
| 1090 | | "address 0x%02x.\n", reg); |
| 1091 | | mdelay(i); |
| 1092 | | } |
| 1093 | | |
| 1094 | | } |
| 1095 | | |
| 1096 | | /* <TODO> what to return in case of error? */ |
| 1097 | | return 0; |
| 1098 | | } |
| 1099 | | |
| 1100 | | static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value) |
| 1101 | | { |
| 1102 | | int result; |
| 1103 | | |
| 1104 | | /* <TODO> how to handle write errors? */ |
| 1105 | | result = i2c_smbus_write_byte_data(client, reg, value); |
| 1106 | | |
| 1107 | | if (result < 0) |
| 1108 | | printk(KERN_WARNING "lm93.o: write byte data failed, " |
| 1109 | | "0x%02x at address 0x%02x.\n", value, reg); |
| 1110 | | |
| 1111 | | return result; |
| 1112 | | } |
| 1113 | | |
| 1114 | | static u16 lm93_read_word(struct i2c_client *client, u8 reg) |
| 1115 | | { |
| 1116 | | int value, i; |
| 1117 | | |
| 1118 | | /* retry in case of read errors */ |
| 1119 | | for (i=1; i<=MAX_RETRIES; i++) { |
| 1120 | | if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) { |
| 1121 | | return value; |
| 1122 | | } else { |
| 1123 | | printk(KERN_WARNING "lm93.o: read word data failed, " |
| 1124 | | "address 0x%02x.\n", reg); |
| 1125 | | mdelay(i); |
| 1126 | | } |
| 1127 | | |
| 1128 | | } |
| 1129 | | |
| 1130 | | /* <TODO> what to return in case of error? */ |
| 1131 | | return 0; |
| 1132 | | } |
| 1133 | | |
| 1134 | | static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value) |
| 1135 | | { |
| 1136 | | int result; |
| 1137 | | |
| 1138 | | /* <TODO> how to handle write errors? */ |
| 1139 | | result = i2c_smbus_write_word_data(client, reg, value); |
| 1140 | | |
| 1141 | | if (result < 0) |
| 1142 | | printk(KERN_WARNING "lm93.o: write word data failed, " |
| 1143 | | "0x%04x at address 0x%02x.\n", value, reg); |
| 1144 | | |
| 1145 | | return result; |
| 1146 | | } |
| 1147 | | |
| 1148 | | static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX]; |
| 1149 | | |
| 1150 | | /* |
| 1151 | | read block data into values, retry if not expected length |
| 1152 | | fbn => index to lm93_block_read_cmds table |
| 1153 | | (Fixed Block Number - section 14.5.2 of LM93 datasheet) |
| 1154 | | */ |
| 1155 | | static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) |
| 1156 | | { |
| 1157 | | int i, result; |
| 1158 | | |
| 1159 | | for (i = 1; i <= MAX_RETRIES; i++) { |
| 1160 | | result = i2c_smbus_read_block_data(client, |
| 1161 | | lm93_block_read_cmds[fbn].cmd, lm93_block_buffer); |
| 1162 | | |
| 1163 | | if (result != lm93_block_read_cmds[fbn].len) { |
| 1164 | | printk(KERN_WARNING "lm93.o: block read data failed, " |
| 1165 | | "command 0x%02x.\n", |
| 1166 | | lm93_block_read_cmds[fbn].cmd); |
| 1167 | | mdelay(1); |
| 1168 | | } |
| 1169 | | } |
| 1170 | | |
| 1171 | | if (result == lm93_block_read_cmds[fbn].len) { |
| 1172 | | memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len); |
| 1173 | | } else { |
| 1174 | | /* <TODO> what to do in case of error? */ |
| 1175 | | } |
| 1176 | | } |
| 1177 | | |
| 1178 | | static void lm93_init_client(struct i2c_client *client) |
| 1179 | | { |
| 1180 | | int i; |
| 1181 | | u8 reg = lm93_read_byte(client, LM93_REG_CONFIG); |
| 1182 | | |
| 1183 | | /* start monitoring */ |
| 1184 | | lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01); |
| 1185 | | |
| 1186 | | if (init) { |
| 1187 | | /* enable #ALERT pin */ |
| 1188 | | reg = lm93_read_byte(client, LM93_REG_CONFIG); |
| 1189 | | lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08); |
| 1190 | | |
| 1191 | | /* enable ASF mode for BMC status registers */ |
| 1192 | | reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL); |
| 1193 | | lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02); |
| 1194 | | |
| 1195 | | /* set sleep state to S0 */ |
| 1196 | | lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0); |
| 1197 | | } |
| 1198 | | |
| 1199 | | /* spin until ready */ |
| 1200 | | for (i=0; i<20; i++) { |
| 1201 | | mdelay(10); |
| 1202 | | if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80) |
| 1203 | | return; |
| 1204 | | } |
| 1205 | | |
| 1206 | | printk(KERN_WARNING "lm93.o: timed out waiting for sensor " |
| 1207 | | "chip to signal ready!\n"); |
| 1208 | | } |
| 1209 | | |
| 1210 | | static void lm93_update_client(struct i2c_client *client) |
| 1211 | | { |
| 1212 | | struct lm93_data *data = client->data; |
| 1213 | | |
| 1214 | | down(&data->update_lock); |
| 1215 | | |
| 1216 | | if (time_after(jiffies - data->last_updated, HZ + HZ / 2) || |
| 1217 | | time_before(jiffies, data->last_updated) || !data->valid) { |
| 1218 | | |
| 1219 | | data->update(data, client); |
| 1220 | | data->last_updated = jiffies; |
| 1221 | | data->valid = 1; |
| 1222 | | } |
| 1223 | | |
| 1224 | | up(&data->update_lock); |
| 1225 | | } |
| 1226 | | |
| 1227 | | /* update routine for data that has no corresponding SMBus block data command */ |
| 1228 | | static void lm93_update_client_common(struct lm93_data *data, |
| 1229 | | struct i2c_client *client) |
| 1230 | | { |
| 1231 | | int i; |
| 1232 | | |
| 1233 | | /* temp1 - temp4: limits */ |
| 1234 | | for (i = 0; i < 4; i++) { |
| 1235 | | data->temp_lim[i].min = |
| 1236 | | lm93_read_byte(client, LM93_REG_TEMP_MIN(i)); |
| 1237 | | data->temp_lim[i].max = |
| 1238 | | lm93_read_byte(client, LM93_REG_TEMP_MAX(i)); |
| 1239 | | } |
| 1240 | | |
| 1241 | | /* config register */ |
| 1242 | | data->config = lm93_read_byte(client, LM93_REG_CONFIG); |
| 1243 | | |
| 1244 | | /* vid1 - vid2: values */ |
| 1245 | | for (i = 0; i < 2; i++) |
| 1246 | | data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i)); |
| 1247 | | |
| 1248 | | /* prochot1 - prochot2: limits */ |
| 1249 | | for (i = 0; i < 2; i++) |
| 1250 | | data->prochot_max[i] = lm93_read_byte(client, |
| 1251 | | LM93_REG_PROCHOT_MAX(i)); |
| 1252 | | |
| 1253 | | /* vccp1 - vccp2: VID relative limits */ |
| 1254 | | for (i = 0; i < 2; i++) |
| 1255 | | data->vccp_limits[i] = lm93_read_byte(client, |
| 1256 | | LM93_REG_VCCP_LIMIT_OFF(i)); |
| 1257 | | |
| 1258 | | /* GPIO input state */ |
| 1259 | | data->gpi = lm93_read_byte(client, LM93_REG_GPI); |
| 1260 | | |
| 1261 | | /* #PROCHOT override state */ |
| 1262 | | data->prochot_override = lm93_read_byte(client, |
| 1263 | | LM93_REG_PROCHOT_OVERRIDE); |
| 1264 | | |
| 1265 | | /* #PROCHOT intervals */ |
| 1266 | | data->prochot_interval = lm93_read_byte(client, |
| 1267 | | LM93_REG_PROCHOT_INTERVAL); |
| 1268 | | |
| 1269 | | /* Fan Boost Termperature registers */ |
| 1270 | | for (i = 0; i < 4; i++) |
| 1271 | | data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); |
| 1272 | | |
| 1273 | | /* Fan Boost Temperature Hyst. registers */ |
| 1274 | | data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12); |
| 1275 | | data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34); |
| 1276 | | |
| 1277 | | /* Temperature Zone Min. PWM & Hysteresis registers */ |
| 1278 | | data->auto_pwm_min_hyst[0] = |
| 1279 | | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12); |
| 1280 | | data->auto_pwm_min_hyst[1] = |
| 1281 | | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34); |
| 1282 | | |
| 1283 | | /* #PROCHOT & #VRDHOT PWM Ramp Control register */ |
| 1284 | | data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); |
| 1285 | | |
| 1286 | | /* misc setup registers */ |
| 1287 | | data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1); |
| 1288 | | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| 1289 | | data->sf_tach_to_pwm = lm93_read_byte(client, |
| 1290 | | LM93_REG_SF_TACH_TO_PWM); |
| 1291 | | } |
| 1292 | | |
| 1293 | | /* update routine which uses SMBus block data commands */ |
| 1294 | | static void lm93_update_client_full(struct lm93_data *data, |
| 1295 | | struct i2c_client *client) |
| 1296 | | { |
| 1297 | | pr_debug("lm93.o: starting device update (block data enabled)\n"); |
| 1298 | | |
| 1299 | | /* in1 - in16: values & limits */ |
| 1300 | | lm93_read_block(client, 3, (u8 *)(data->block3)); |
| 1301 | | lm93_read_block(client, 7, (u8 *)(data->block7)); |
| 1302 | | |
| 1303 | | /* temp1 - temp4: values */ |
| 1304 | | lm93_read_block(client, 2, (u8 *)(data->block2)); |
| 1305 | | |
| 1306 | | /* prochot1 - prochot2: values */ |
| 1307 | | lm93_read_block(client, 4, (u8 *)(data->block4)); |
| 1308 | | |
| 1309 | | /* fan1 - fan4: values & limits */ |
| 1310 | | lm93_read_block(client, 5, (u8 *)(data->block5)); |
| 1311 | | lm93_read_block(client, 8, (u8 *)(data->block8)); |
| 1312 | | |
| 1313 | | /* pmw control registers */ |
| 1314 | | lm93_read_block(client, 9, (u8 *)(data->block9)); |
| 1315 | | |
| 1316 | | /* alarm values */ |
| 1317 | | lm93_read_block(client, 1, (u8 *)(&data->block1)); |
| 1318 | | |
| 1319 | | /* auto/pwm registers */ |
| 1320 | | lm93_read_block(client, 10, (u8 *)(&data->block10)); |
| 1321 | | |
| 1322 | | lm93_update_client_common(data, client); |
| 1323 | | } |
| 1324 | | |
| 1325 | | /* update routine which uses SMBus byte/word data commands only */ |
| 1326 | | static void lm93_update_client_min(struct lm93_data *data, |
| 1327 | | struct i2c_client *client) |
| 1328 | | { |
| 1329 | | int i,j; |
| 1330 | | u8 *ptr; |
| 1331 | | |
| 1332 | | pr_debug("lm93.o: starting device update (block data disabled)\n"); |
| 1333 | | |
| 1334 | | /* in1 - in16: values & limits */ |
| 1335 | | for (i = 0; i < 16; i++) { |
| 1336 | | data->block3[i] = |
| 1337 | | lm93_read_byte(client, LM93_REG_IN(i)); |
| 1338 | | data->block7[i].min = |
| 1339 | | lm93_read_byte(client, LM93_REG_IN_MIN(i)); |
| 1340 | | data->block7[i].max = |
| 1341 | | lm93_read_byte(client, LM93_REG_IN_MAX(i)); |
| 1342 | | } |
| 1343 | | |
| 1344 | | /* temp1 - temp4: values */ |
| 1345 | | for (i = 0; i < 4; i++) { |
| 1346 | | data->block2[i] = |
| 1347 | | lm93_read_byte(client, LM93_REG_TEMP(i)); |
| 1348 | | } |
| 1349 | | |
| 1350 | | /* prochot1 - prochot2: values */ |
| 1351 | | for (i = 0; i < 2; i++) { |
| 1352 | | data->block4[i].cur = |
| 1353 | | lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i)); |
| 1354 | | data->block4[i].avg = |
| 1355 | | lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i)); |
| 1356 | | } |
| 1357 | | |
| 1358 | | /* fan1 - fan4: values & limits */ |
| 1359 | | for (i = 0; i < 4; i++) { |
| 1360 | | data->block5[i] = |
| 1361 | | lm93_read_word(client, LM93_REG_FAN(i)); |
| 1362 | | data->block8[i] = |
| 1363 | | lm93_read_word(client, LM93_REG_FAN_MIN(i)); |
| 1364 | | } |
| 1365 | | |
| 1366 | | /* pwm control registers */ |
| 1367 | | for (i = 0; i < 2; i++) { |
| 1368 | | for (j = 0; j < 4; j++) { |
| 1369 | | data->block9[i][j] = |
| 1370 | | lm93_read_byte(client, LM93_REG_PWM_CTL(i,j)); |
| 1371 | | } |
| 1372 | | } |
| 1373 | | |
| 1374 | | /* alarm values */ |
| 1375 | | for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) { |
| 1376 | | *(ptr + i) = |
| 1377 | | lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i); |
| 1378 | | } |
| 1379 | | |
| 1380 | | /* auto/pwm (base temp) registers */ |
| 1381 | | for (i = 0; i < 4; i++) { |
| 1382 | | data->block10.base[i] = |
| 1383 | | lm93_read_byte(client, LM93_REG_TEMP_BASE(i)); |
| 1384 | | } |
| 1385 | | |
| 1386 | | /* auto/pwm (offset temp) registers */ |
| 1387 | | for (i = 0; i < 12; i++) { |
| 1388 | | data->block10.offset[i] = |
| 1389 | | lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i)); |
| 1390 | | } |
| 1391 | | |
| 1392 | | lm93_update_client_common(data, client); |
| 1393 | | } |
| 1394 | | |
| 1395 | | /* The next few functions are the call-back functions of the /proc/sys and |
| 1396 | | sysctl files. Which function is used is defined in the ctl_table in |
| 1397 | | the extra1 field. |
| 1398 | | Each function must return the magnitude (power of 10 to divide the date |
| 1399 | | with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must |
| 1400 | | put a maximum of *nrels elements in results reflecting the data of this |
| 1401 | | file, and set *nrels to the number it actually put in it, if operation== |
| 1402 | | SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from |
| 1403 | | results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. |
| 1404 | | Note that on SENSORS_PROC_REAL_READ, I do not check whether results is |
| 1405 | | large enough (by checking the incoming value of *nrels). This is not very |
| 1406 | | good practice, but as long as you put less than about 5 values in results, |
| 1407 | | you can assume it is large enough. */ |
| 1408 | | |
| 1409 | | static void lm93_in(struct i2c_client *client, int operation, int ctl_name, |
| 1410 | | int *nrels_mag, long *results) |
| 1411 | | { |
| 1412 | | struct lm93_data *data = client->data; |
| 1413 | | int nr = ctl_name - LM93_SYSCTL_IN1; /* 0 <= nr <= 15 */ |
| 1414 | | int vccp = ctl_name - LM93_SYSCTL_IN7; /* 0 <= vccp <= 1 if relevant */ |
| 1415 | | |
| 1416 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1417 | | *nrels_mag = 2; |
| 1418 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1419 | | |
| 1420 | | lm93_update_client(client); |
| 1421 | | |
| 1422 | | /* for limits, check in7 and in8 for VID relative mode */ |
| 1423 | | if ((ctl_name==LM93_SYSCTL_IN7 || ctl_name==LM93_SYSCTL_IN8) && |
| 1424 | | (vccp_limit_type[vccp])) { |
| 1425 | | long vid = LM93_VID_FROM_REG(data->vid[vccp]); |
| 1426 | | results[0] = LM93_IN_REL_FROM_REG( |
| 1427 | | data->vccp_limits[vccp], 0, vid); |
| 1428 | | results[1] = LM93_IN_REL_FROM_REG( |
| 1429 | | data->vccp_limits[vccp], 1, vid); |
| 1430 | | |
| 1431 | | /* otherwise, use absolute limits */ |
| 1432 | | } else { |
| 1433 | | results[0] = LM93_IN_FROM_REG(nr, |
| 1434 | | data->block7[nr].min); |
| 1435 | | results[1] = LM93_IN_FROM_REG(nr, |
| 1436 | | data->block7[nr].max); |
| 1437 | | } |
| 1438 | | |
| 1439 | | results[2] = LM93_IN_FROM_REG(nr, data->block3[nr]); |
| 1440 | | *nrels_mag = 3; |
| 1441 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1442 | | down(&data->update_lock); |
| 1443 | | |
| 1444 | | /* for limits, check in7 and in8 for VID relative mode */ |
| 1445 | | if ((ctl_name==LM93_SYSCTL_IN7 || ctl_name==LM93_SYSCTL_IN8) && |
| 1446 | | (vccp_limit_type[vccp])) { |
| 1447 | | |
| 1448 | | long vid = LM93_VID_FROM_REG(data->vid[vccp]); |
| 1449 | | if (*nrels_mag >= 2) { |
| 1450 | | data->vccp_limits[vccp] = |
| 1451 | | (data->vccp_limits[vccp] & 0x0f) | |
| 1452 | | LM93_IN_REL_TO_REG(results[1], 1, vid); |
| 1453 | | } |
| 1454 | | if (*nrels_mag >= 1) { |
| 1455 | | data->vccp_limits[vccp] = |
| 1456 | | (data->vccp_limits[vccp] & 0xf0) | |
| 1457 | | LM93_IN_REL_TO_REG(results[0], 0, vid); |
| 1458 | | lm93_write_byte(client, |
| 1459 | | LM93_REG_VCCP_LIMIT_OFF(vccp), |
| 1460 | | data->vccp_limits[vccp]); |
| 1461 | | } |
| 1462 | | |
| 1463 | | /* otherwise, use absolute limits */ |
| 1464 | | } else { |
| 1465 | | if (*nrels_mag >= 1) { |
| 1466 | | data->block7[nr].min = LM93_IN_TO_REG(nr, |
| 1467 | | results[0]); |
| 1468 | | lm93_write_byte(client, LM93_REG_IN_MIN(nr), |
| 1469 | | data->block7[nr].min); |
| 1470 | | } |
| 1471 | | if (*nrels_mag >= 2) { |
| 1472 | | data->block7[nr].max = LM93_IN_TO_REG(nr, |
| 1473 | | results[1]); |
| 1474 | | lm93_write_byte(client, LM93_REG_IN_MAX(nr), |
| 1475 | | data->block7[nr].max); |
| 1476 | | } |
| 1477 | | } |
| 1478 | | up(&data->update_lock); |
| 1479 | | } |
| 1480 | | } |
| 1481 | | |
| 1482 | | void lm93_temp(struct i2c_client *client, int operation, int ctl_name, |
| 1483 | | int *nrels_mag, long *results) |
| 1484 | | { |
| 1485 | | struct lm93_data *data = client->data; |
| 1486 | | int nr = ctl_name - LM93_SYSCTL_TEMP1; |
| 1487 | | |
| 1488 | | if (0 > nr || nr > 2) |
| 1489 | | return; /* ERROR */ |
| 1490 | | |
| 1491 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1492 | | *nrels_mag = 1; |
| 1493 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1494 | | lm93_update_client(client); |
| 1495 | | results[0] = LM93_TEMP_FROM_REG(data->temp_lim[nr].max); |
| 1496 | | results[1] = LM93_TEMP_FROM_REG(data->temp_lim[nr].min); |
| 1497 | | results[2] = LM93_TEMP_FROM_REG(data->block2[nr]); |
| 1498 | | *nrels_mag = 3; |
| 1499 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1500 | | down(&data->update_lock); |
| 1501 | | if (*nrels_mag >= 1) { |
| 1502 | | data->temp_lim[nr].max = LM93_TEMP_TO_REG(results[0]); |
| 1503 | | lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), |
| 1504 | | data->temp_lim[nr].max); |
| 1505 | | } |
| 1506 | | if (*nrels_mag >= 2) { |
| 1507 | | data->temp_lim[nr].min = LM93_TEMP_TO_REG(results[1]); |
| 1508 | | lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), |
| 1509 | | data->temp_lim[nr].min); |
| 1510 | | } |
| 1511 | | up(&data->update_lock); |
| 1512 | | } |
| 1513 | | } |
| 1514 | | |
| 1515 | | void lm93_temp_auto_base(struct i2c_client *client, int operation, |
| 1516 | | int ctl_name, int *nrels_mag, long *results) |
| 1517 | | { |
| 1518 | | struct lm93_data *data = client->data; |
| 1519 | | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BASE; |
| 1520 | | |
| 1521 | | if (0 > nr || nr > 2) |
| 1522 | | return; /* ERROR */ |
| 1523 | | |
| 1524 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1525 | | *nrels_mag = 1; |
| 1526 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1527 | | lm93_update_client(client); |
| 1528 | | results[0] = LM93_TEMP_FROM_REG(data->block10.base[nr]); |
| 1529 | | *nrels_mag = 1; |
| 1530 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1531 | | down(&data->update_lock); |
| 1532 | | if (*nrels_mag >= 1) { |
| 1533 | | data->block10.base[nr] = LM93_TEMP_TO_REG(results[0]); |
| 1534 | | lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), |
| 1535 | | data->block10.base[nr]); |
| 1536 | | } |
| 1537 | | up(&data->update_lock); |
| 1538 | | } |
| 1539 | | } |
| 1540 | | |
| 1541 | | void lm93_temp_auto_offsets(struct i2c_client *client, int operation, |
| 1542 | | int ctl_name, int *nrels_mag, long *results) |
| 1543 | | { |
| 1544 | | struct lm93_data *data = client->data; |
| 1545 | | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_OFFSETS; |
| 1546 | | int ii; |
| 1547 | | |
| 1548 | | if (0 > nr || nr > 2) |
| 1549 | | return; /* ERROR */ |
| 1550 | | |
| 1551 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1552 | | *nrels_mag = 1; |
| 1553 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1554 | | int mode; |
| 1555 | | lm93_update_client(client); |
| 1556 | | |
| 1557 | | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| 1558 | | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
| 1559 | | |
| 1560 | | for (ii = 0; ii < 12; ii++) { |
| 1561 | | results[ii] = LM93_TEMP_AUTO_OFFSET_FROM_REG( |
| 1562 | | data->block10.offset[ii], nr, mode); |
| 1563 | | } |
| 1564 | | *nrels_mag = 12; |
| 1565 | | } |
| 1566 | | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1567 | | /* we only care about the first 12 values */ |
| 1568 | | int nrels = *nrels_mag > 12 ? 12 : *nrels_mag; |
| 1569 | | |
| 1570 | | down(&data->update_lock); |
| 1571 | | |
| 1572 | | /* force 0.5C/bit mode */ |
| 1573 | | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| 1574 | | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
| 1575 | | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| 1576 | | |
| 1577 | | for (ii = 0; ii < nrels; ii++) { |
| 1578 | | data->block10.offset[ii] = LM93_TEMP_AUTO_OFFSET_TO_REG( |
| 1579 | | data->block10.offset[ii], results[ii], nr, 1); |
| 1580 | | lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ii), |
| 1581 | | data->block10.offset[ii]); |
| 1582 | | } |
| 1583 | | up(&data->update_lock); |
| 1584 | | } |
| 1585 | | } |
| 1586 | | |
| 1587 | | void lm93_temp_auto_boost(struct i2c_client *client, int operation, |
| 1588 | | int ctl_name, int *nrels_mag, long *results) |
| 1589 | | { |
| 1590 | | struct lm93_data *data = client->data; |
| 1591 | | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BOOST; |
| 1592 | | |
| 1593 | | if (0 > nr || nr > 2) |
| 1594 | | return; /* ERROR */ |
| 1595 | | |
| 1596 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1597 | | *nrels_mag = 1; |
| 1598 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1599 | | lm93_update_client(client); |
| 1600 | | results[0] = LM93_TEMP_FROM_REG(data->boost[nr]); |
| 1601 | | *nrels_mag = 1; |
| 1602 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1603 | | down(&data->update_lock); |
| 1604 | | if (*nrels_mag >= 1) { |
| 1605 | | data->boost[nr] = LM93_TEMP_TO_REG(results[0]); |
| 1606 | | lm93_write_byte(client, LM93_REG_BOOST(nr), |
| 1607 | | data->boost[nr]); |
| 1608 | | } |
| 1609 | | up(&data->update_lock); |
| 1610 | | } |
| 1611 | | |
| 1612 | | } |
| 1613 | | |
| 1614 | | static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst, |
| 1615 | | int nr, int mode) |
| 1616 | | { |
| 1617 | | u8 reg = LM93_TEMP_OFFSET_TO_REG( |
| 1618 | | (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode); |
| 1619 | | |
| 1620 | | switch (nr) { |
| 1621 | | case 0: |
| 1622 | | reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f); |
| 1623 | | break; |
| 1624 | | case 1: |
| 1625 | | reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f); |
| 1626 | | break; |
| 1627 | | case 2: |
| 1628 | | reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f); |
| 1629 | | break; |
| 1630 | | case 3: |
| 1631 | | default: |
| 1632 | | reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f); |
| 1633 | | break; |
| 1634 | | } |
| 1635 | | |
| 1636 | | return reg; |
| 1637 | | } |
| 1638 | | |
| 1639 | | static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr, |
| 1640 | | int mode) |
| 1641 | | { |
| 1642 | | u8 reg; |
| 1643 | | |
| 1644 | | switch (nr) { |
| 1645 | | case 0: |
| 1646 | | reg = data->boost_hyst[0] & 0x0f; |
| 1647 | | break; |
| 1648 | | case 1: |
| 1649 | | reg = data->boost_hyst[0] >> 4 & 0x0f; |
| 1650 | | break; |
| 1651 | | case 2: |
| 1652 | | reg = data->boost_hyst[1] & 0x0f; |
| 1653 | | break; |
| 1654 | | case 3: |
| 1655 | | default: |
| 1656 | | reg = data->boost_hyst[1] >> 4 & 0x0f; |
| 1657 | | break; |
| 1658 | | } |
| 1659 | | |
| 1660 | | return LM93_TEMP_FROM_REG(data->boost[nr]) - |
| 1661 | | LM93_TEMP_OFFSET_FROM_REG(reg, mode); |
| 1662 | | } |
| 1663 | | |
| 1664 | | void lm93_temp_auto_boost_hyst(struct i2c_client *client, int operation, |
| 1665 | | int ctl_name, int *nrels_mag, long *results) |
| 1666 | | { |
| 1667 | | struct lm93_data *data = client->data; |
| 1668 | | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BOOST_HYST; |
| 1669 | | |
| 1670 | | if (0 > nr || nr > 2) |
| 1671 | | return; /* ERROR */ |
| 1672 | | |
| 1673 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1674 | | *nrels_mag = 1; |
| 1675 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1676 | | int mode; |
| 1677 | | lm93_update_client(client); |
| 1678 | | |
| 1679 | | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| 1680 | | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
| 1681 | | |
| 1682 | | results[0] = LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode); |
| 1683 | | *nrels_mag = 1; |
| 1684 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1685 | | if (*nrels_mag >= 1) { |
| 1686 | | down(&data->update_lock); |
| 1687 | | |
| 1688 | | /* force 0.5C/bit mode */ |
| 1689 | | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| 1690 | | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
| 1691 | | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| 1692 | | |
| 1693 | | data->boost_hyst[nr/2] = |
| 1694 | | LM93_AUTO_BOOST_HYST_TO_REG(data, |
| 1695 | | results[0], nr, 1); |
| 1696 | | lm93_write_byte(client, LM93_REG_BOOST_HYST(nr), |
| 1697 | | data->boost_hyst[nr/2]); |
| 1698 | | up(&data->update_lock); |
| 1699 | | } |
| 1700 | | } |
| 1701 | | } |
| 1702 | | |
| 1703 | | void lm93_temp_auto_pwm_min(struct i2c_client *client, int operation, |
| 1704 | | int ctl_name, int *nrels_mag, long *results) |
| 1705 | | { |
| 1706 | | struct lm93_data *data = client->data; |
| 1707 | | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_PWM_MIN; |
| 1708 | | u8 reg, ctl4; |
| 1709 | | |
| 1710 | | if (0 > nr || nr > 2) |
| 1711 | | return; /* ERROR */ |
| 1712 | | |
| 1713 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1714 | | *nrels_mag = 0; |
| 1715 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1716 | | lm93_update_client(client); |
| 1717 | | reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; |
| 1718 | | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| 1719 | | results[0] = LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? |
| 1720 | | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
| 1721 | | *nrels_mag = 1; |
| 1722 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1723 | | if (*nrels_mag >= 1) { |
| 1724 | | down(&data->update_lock); |
| 1725 | | reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); |
| 1726 | | ctl4 = lm93_read_byte( |
| 1727 | | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
| 1728 | | reg = (reg & 0x0f) | |
| 1729 | | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
| 1730 | | LM93_PWM_MAP_LO_FREQ : |
| 1731 | | LM93_PWM_MAP_HI_FREQ) << 4; |
| 1732 | | |
| 1733 | | data->auto_pwm_min_hyst[nr/2] = reg; |
| 1734 | | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); |
| 1735 | | up(&data->update_lock); |
| 1736 | | } |
| 1737 | | } |
| 1738 | | } |
| 1739 | | |
| 1740 | | void lm93_temp_auto_offset_hyst(struct i2c_client *client, int operation, |
| 1741 | | int ctl_name, int *nrels_mag, long *results) |
| 1742 | | { |
| 1743 | | struct lm93_data *data = client->data; |
| 1744 | | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_OFFSET_HYST; |
| 1745 | | |
| 1746 | | if (0 > nr || nr > 2) |
| 1747 | | return; /* ERROR */ |
| 1748 | | |
| 1749 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1750 | | *nrels_mag = 1; |
| 1751 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1752 | | int mode; |
| 1753 | | lm93_update_client(client); |
| 1754 | | |
| 1755 | | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
| 1756 | | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
| 1757 | | |
| 1758 | | results[0] = LM93_TEMP_OFFSET_FROM_REG( |
| 1759 | | data->auto_pwm_min_hyst[nr/2], mode); |
| 1760 | | |
| 1761 | | *nrels_mag = 1; |
| 1762 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1763 | | if (*nrels_mag >= 1) { |
| 1764 | | u8 reg; |
| 1765 | | down(&data->update_lock); |
| 1766 | | |
| 1767 | | /* force 0.5C/bit mode */ |
| 1768 | | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| 1769 | | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
| 1770 | | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| 1771 | | |
| 1772 | | reg = data->auto_pwm_min_hyst[nr/2]; |
| 1773 | | reg = (reg & 0xf0) | |
| 1774 | | (LM93_TEMP_OFFSET_TO_REG(results[0], 1) & 0x0f); |
| 1775 | | |
| 1776 | | data->auto_pwm_min_hyst[nr/2] = reg; |
| 1777 | | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); |
| 1778 | | up(&data->update_lock); |
| 1779 | | } |
| 1780 | | } |
| 1781 | | } |
| 1782 | | |
| 1783 | | void lm93_fan(struct i2c_client *client, int operation, int ctl_name, |
| 1784 | | int *nrels_mag, long *results) |
| 1785 | | { |
| 1786 | | struct lm93_data *data = client->data; |
| 1787 | | int nr = ctl_name - LM93_SYSCTL_FAN1; |
| 1788 | | |
| 1789 | | if (0 > nr || nr > 3) |
| 1790 | | return; /* ERROR */ |
| 1791 | | |
| 1792 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1793 | | *nrels_mag = 0; |
| 1794 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1795 | | lm93_update_client(client); |
| 1796 | | results[0] = LM93_FAN_FROM_REG(data->block8[nr]); /* min */ |
| 1797 | | results[1] = LM93_FAN_FROM_REG(data->block5[nr]); /* val */ |
| 1798 | | *nrels_mag = 2; |
| 1799 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1800 | | if (*nrels_mag >= 1) { |
| 1801 | | down(&data->update_lock); |
| 1802 | | data->block8[nr] = LM93_FAN_TO_REG(results[0]); |
| 1803 | | lm93_write_word(client, LM93_REG_FAN_MIN(nr), |
| 1804 | | data->block8[nr]); |
| 1805 | | up(&data->update_lock); |
| 1806 | | } |
| 1807 | | } |
| 1808 | | } |
| 1809 | | |
| 1810 | | void lm93_vid(struct i2c_client *client, int operation, int ctl_name, |
| 1811 | | int *nrels_mag, long *results) |
| 1812 | | { |
| 1813 | | struct lm93_data *data = client->data; |
| 1814 | | int nr = ctl_name - LM93_SYSCTL_VID1; |
| 1815 | | |
| 1816 | | if (0 > nr || nr > 1) |
| 1817 | | return; /* ERROR */ |
| 1818 | | |
| 1819 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1820 | | *nrels_mag = 2; |
| 1821 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1822 | | lm93_update_client(client); |
| 1823 | | results[0] = LM93_VID_FROM_REG(data->vid[nr]); |
| 1824 | | *nrels_mag = 1; |
| 1825 | | } |
| 1826 | | } |
| 1827 | | |
| 1828 | | /* some tedious bit-twiddling here to deal with the register format: |
| 1829 | | |
| 1830 | | data->sf_tach_to_pwm: (tach to pwm mapping bits) |
| 1831 | | |
| 1832 | | bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1833 | | T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1 |
| 1834 | | |
| 1835 | | data->sfc2: (enable bits) |
| 1836 | | |
| 1837 | | bit | 3 | 2 | 1 | 0 |
| 1838 | | T4 T3 T2 T1 |
| 1839 | | */ |
| 1840 | | |
| 1841 | | /* helper function - must grab data->update_lock before calling |
| 1842 | | fan is 0-3, indicating fan1-fan4 */ |
| 1843 | | static void lm93_write_fan_smart_tach(struct i2c_client *client, |
| 1844 | | struct lm93_data *data, int fan, long value) |
| 1845 | | { |
| 1846 | | /* insert the new mapping and write it out */ |
| 1847 | | data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); |
| 1848 | | data->sf_tach_to_pwm &= ~0x3 << fan * 2; |
| 1849 | | data->sf_tach_to_pwm |= value << fan * 2; |
| 1850 | | lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm); |
| 1851 | | |
| 1852 | | /* insert the enable bit and write it out */ |
| 1853 | | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| 1854 | | if (value) |
| 1855 | | data->sfc2 |= 1 << fan; |
| 1856 | | else |
| 1857 | | data->sfc2 &= ~1 << fan; |
| 1858 | | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| 1859 | | } |
| 1860 | | |
| 1861 | | /* helper function - must grab data->update_lock before calling |
| 1862 | | pwm is 0-1, indicating pwm1-pwm2 |
| 1863 | | this disables smart tach for all tach channels bound to the given pwm */ |
| 1864 | | static void lm93_disable_fan_smart_tach(struct i2c_client *client, |
| 1865 | | struct lm93_data *data, int pwm) |
| 1866 | | { |
| 1867 | | int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); |
| 1868 | | int mask; |
| 1869 | | |
| 1870 | | /* collapse the mapping into a mask of enable bits */ |
| 1871 | | mapping = (mapping >> pwm) & 0x55; |
| 1872 | | mask = mapping & 0x01; |
| 1873 | | mask |= (mapping & 0x04) >> 1; |
| 1874 | | mask |= (mapping & 0x10) >> 2; |
| 1875 | | mask |= (mapping & 0x40) >> 3; |
| 1876 | | |
| 1877 | | /* disable smart tach according to the mask */ |
| 1878 | | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
| 1879 | | data->sfc2 &= ~mask; |
| 1880 | | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
| 1881 | | } |
| 1882 | | |
| 1883 | | void lm93_fan_smart_tach(struct i2c_client *client, int operation, int ctl_name, |
| 1884 | | int *nrels_mag, long *results) |
| 1885 | | { |
| 1886 | | struct lm93_data *data = client->data; |
| 1887 | | int nr = ctl_name - LM93_SYSCTL_FAN1_SMART_TACH; |
| 1888 | | |
| 1889 | | if (0 > nr || nr > 3) |
| 1890 | | return; /* ERROR */ |
| 1891 | | |
| 1892 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1893 | | *nrels_mag = 0; |
| 1894 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1895 | | lm93_update_client(client); |
| 1896 | | |
| 1897 | | /* extract the relevant mapping */ |
| 1898 | | int mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03; |
| 1899 | | |
| 1900 | | /* if there's a mapping and it's enabled */ |
| 1901 | | if (mapping && ((data->sfc2 >> nr) & 0x01)) |
| 1902 | | results[0] = mapping; |
| 1903 | | else |
| 1904 | | results[0] = 0; |
| 1905 | | |
| 1906 | | *nrels_mag = 1; |
| 1907 | | |
| 1908 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1909 | | if (*nrels_mag >= 1) { |
| 1910 | | down(&data->update_lock); |
| 1911 | | |
| 1912 | | /* sanity test, ignore the write otherwise */ |
| 1913 | | if (0 <= results[0] && results[0] <= 2) { |
| 1914 | | |
| 1915 | | /* can't enable if pwm freq is 22.5KHz */ |
| 1916 | | if (results[0]) { |
| 1917 | | u8 ctl4 = lm93_read_byte(client, |
| 1918 | | LM93_REG_PWM_CTL(results[0]-1, |
| 1919 | | LM93_PWM_CTL4)); |
| 1920 | | if ((ctl4 & 0x07) == 0) |
| 1921 | | results[0] = 0; |
| 1922 | | } |
| 1923 | | |
| 1924 | | lm93_write_fan_smart_tach(client, data, nr, |
| 1925 | | results[0]); |
| 1926 | | } |
| 1927 | | up(&data->update_lock); |
| 1928 | | } |
| 1929 | | } |
| 1930 | | } |
| 1931 | | |
| 1932 | | void lm93_prochot(struct i2c_client *client, int operation, int ctl_name, |
| 1933 | | int *nrels_mag, long *results) |
| 1934 | | { |
| 1935 | | struct lm93_data *data = client->data; |
| 1936 | | int nr = ctl_name - LM93_SYSCTL_PROCHOT1; |
| 1937 | | |
| 1938 | | if (0 > nr || nr > 1) |
| 1939 | | return; /* ERROR */ |
| 1940 | | |
| 1941 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1942 | | *nrels_mag = 0; |
| 1943 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1944 | | lm93_update_client(client); |
| 1945 | | results[0] = data->prochot_max[nr]; |
| 1946 | | results[1] = data->block4[nr].avg; |
| 1947 | | results[2] = data->block4[nr].avg; |
| 1948 | | *nrels_mag = 3; |
| 1949 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1950 | | down(&data->update_lock); |
| 1951 | | if (*nrels_mag >= 1) { |
| 1952 | | data->prochot_max[nr] = LM93_PROCHOT_TO_REG(results[0]); |
| 1953 | | lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr), |
| 1954 | | data->prochot_max[nr]); |
| 1955 | | } |
| 1956 | | up(&data->update_lock); |
| 1957 | | } |
| 1958 | | } |
| 1959 | | |
| 1960 | | void lm93_prochot_short(struct i2c_client *client, int operation, int ctl_name, |
| 1961 | | int *nrels_mag, long *results) |
| 1962 | | { |
| 1963 | | struct lm93_data *data = client->data; |
| 1964 | | |
| 1965 | | if (ctl_name != LM93_SYSCTL_PROCHOT_SHORT) |
| 1966 | | return; /* ERROR */ |
| 1967 | | |
| 1968 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1969 | | *nrels_mag = 0; |
| 1970 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1971 | | lm93_update_client(client); |
| 1972 | | results[0] = (data->config & 0x10) ? 1 : 0; |
| 1973 | | *nrels_mag = 1; |
| 1974 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 1975 | | down(&data->update_lock); |
| 1976 | | if (*nrels_mag >= 1) { |
| 1977 | | if (results[0]) |
| 1978 | | data->config |= 0x10; |
| 1979 | | else |
| 1980 | | data->config &= ~0x10; |
| 1981 | | lm93_write_byte(client, LM93_REG_CONFIG, data->config); |
| 1982 | | } |
| 1983 | | up(&data->update_lock); |
| 1984 | | } |
| 1985 | | } |
| 1986 | | |
| 1987 | | void lm93_prochot_override(struct i2c_client *client, int operation, |
| 1988 | | int ctl_name, int *nrels_mag, long *results) |
| 1989 | | { |
| 1990 | | struct lm93_data *data = client->data; |
| 1991 | | |
| 1992 | | if (ctl_name != LM93_SYSCTL_PROCHOT_OVERRIDE) |
| 1993 | | return; /* ERROR */ |
| 1994 | | |
| 1995 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 1996 | | *nrels_mag = 0; |
| 1997 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 1998 | | lm93_update_client(client); |
| 1999 | | results[0] = (data->prochot_override & 0x80) ? 1 : 0; |
| 2000 | | results[1] = (data->prochot_override & 0x40) ? 1 : 0; |
| 2001 | | results[2] = data->prochot_override & 0x0f; |
| 2002 | | *nrels_mag = 3; |
| 2003 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 2004 | | |
| 2005 | | /* grab old values */ |
| 2006 | | int force2 = (data->prochot_override & 0x40) ? 1 : 0; |
| 2007 | | int prochot = data->prochot_override & 0x0f; |
| 2008 | | |
| 2009 | | down(&data->update_lock); |
| 2010 | | if (*nrels_mag >= 3) { |
| 2011 | | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
| 2012 | | results[0], results[1], results[2]); |
| 2013 | | } |
| 2014 | | if (*nrels_mag == 2) { |
| 2015 | | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
| 2016 | | results[0], results[1], prochot); |
| 2017 | | } |
| 2018 | | if (*nrels_mag == 1) { |
| 2019 | | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
| 2020 | | results[0], force2, prochot); |
| 2021 | | } |
| 2022 | | if (*nrels_mag >= 1) { |
| 2023 | | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, |
| 2024 | | data->prochot_override); |
| 2025 | | } |
| 2026 | | up(&data->update_lock); |
| 2027 | | } |
| 2028 | | } |
| 2029 | | |
| 2030 | | void lm93_prochot_interval(struct i2c_client *client, int operation, |
| 2031 | | int ctl_name, int *nrels_mag, long *results) |
| 2032 | | { |
| 2033 | | struct lm93_data *data = client->data; |
| 2034 | | |
| 2035 | | if (ctl_name != LM93_SYSCTL_PROCHOT_INTERVAL) |
| 2036 | | return; /* ERROR */ |
| 2037 | | |
| 2038 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2039 | | *nrels_mag = 2; |
| 2040 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2041 | | lm93_update_client(client); |
| 2042 | | results[0] = LM93_INTERVAL_FROM_REG( |
| 2043 | | data->prochot_interval & 0x0f); |
| 2044 | | results[1] = LM93_INTERVAL_FROM_REG( |
| 2045 | | (data->prochot_interval & 0xf0) >> 4); |
| 2046 | | *nrels_mag = 2; |
| 2047 | | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 2048 | | down(&data->update_lock); |
| 2049 | | data->prochot_interval = lm93_read_byte(client, |
| 2050 | | LM93_REG_PROCHOT_INTERVAL); |
| 2051 | | if (*nrels_mag >= 2) { |
| 2052 | | data->prochot_interval = |
| 2053 | | (LM93_INTERVAL_TO_REG(results[1]) << 4) | |
| 2054 | | (data->prochot_interval & 0x0f); |
| 2055 | | } |
| 2056 | | if (*nrels_mag >= 1) { |
| 2057 | | data->prochot_interval = |
| 2058 | | (data->prochot_interval & 0xf0) | |
| 2059 | | LM93_INTERVAL_TO_REG(results[0]); |
| 2060 | | lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, |
| 2061 | | data->prochot_interval); |
| 2062 | | } |
| 2063 | | up(&data->update_lock); |
| 2064 | | } |
| 2065 | | } |
| 2066 | | |
| 2067 | | void lm93_vrdhot(struct i2c_client *client, int operation, int ctl_name, |
| 2068 | | int *nrels_mag, long *results) |
| 2069 | | { |
| 2070 | | struct lm93_data *data = client->data; |
| 2071 | | int nr = ctl_name - LM93_SYSCTL_VRDHOT1; |
| 2072 | | |
| 2073 | | if (0 > nr || nr > 1) |
| 2074 | | return; /* ERROR */ |
| 2075 | | |
| 2076 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2077 | | *nrels_mag = 0; |
| 2078 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2079 | | lm93_update_client(client); |
| 2080 | | results[0] = data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0; |
| 2081 | | *nrels_mag = 1; |
| 2082 | | } |
| 2083 | | } |
| 2084 | | |
| 2085 | | void lm93_gpio(struct i2c_client *client, int operation, int ctl_name, |
| 2086 | | int *nrels_mag, long *results) |
| 2087 | | { |
| 2088 | | struct lm93_data *data = client->data; |
| 2089 | | |
| 2090 | | if (ctl_name != LM93_SYSCTL_GPIO) |
| 2091 | | return; /* ERROR */ |
| 2092 | | |
| 2093 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2094 | | *nrels_mag = 0; |
| 2095 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2096 | | lm93_update_client(client); |
| 2097 | | results[0] = LM93_GPI_FROM_REG(data->gpi); |
| 2098 | | *nrels_mag = 1; |
| 2099 | | } |
| 2100 | | } |
| 2101 | | |
| 2102 | | void lm93_pwm(struct i2c_client *client, int operation, int ctl_name, |
| 2103 | | int *nrels_mag, long *results) |
| 2104 | | { |
| 2105 | | struct lm93_data *data = client->data; |
| 2106 | | int nr = ctl_name - LM93_SYSCTL_PWM1; |
| 2107 | | u8 ctl2, ctl4; |
| 2108 | | |
| 2109 | | if (0 > nr || nr > 1) |
| 2110 | | return; /* ERROR */ |
| 2111 | | |
| 2112 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2113 | | *nrels_mag = 0; |
| 2114 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2115 | | lm93_update_client(client); |
| 2116 | | ctl2 = data->block9[nr][LM93_PWM_CTL2]; |
| 2117 | | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| 2118 | | results[1] = (ctl2 & 0x01) ? 1 : 0; |
| 2119 | | ctl2 = ctl2 >> 4 & 0x0f; |
| 2120 | | if (results[1]) /* show user commanded value if enabled */ |
| 2121 | | results[0] = data->pwm_override[nr]; |
| 2122 | | else /* show present h/w value if manual pwm disabled */ |
| 2123 | | results[0] = LM93_PWM_FROM_REG(ctl2, (ctl4 & 0x07) ? |
| 2124 | | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
| 2125 | | *nrels_mag = 2; |
| 2126 | | } |
| 2127 | | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 2128 | | if (*nrels_mag >= 1) { |
| 2129 | | down(&data->update_lock); |
| 2130 | | ctl2 = lm93_read_byte( |
| 2131 | | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); |
| 2132 | | ctl4 = lm93_read_byte( |
| 2133 | | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
| 2134 | | ctl2 = (ctl2 & 0x0f) | |
| 2135 | | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
| 2136 | | LM93_PWM_MAP_LO_FREQ : |
| 2137 | | LM93_PWM_MAP_HI_FREQ) << 4; |
| 2138 | | if (*nrels_mag >= 2) { |
| 2139 | | if (results[1]) |
| 2140 | | ctl2 |= 0x01; |
| 2141 | | else |
| 2142 | | ctl2 &= ~0x01; |
| 2143 | | } |
| 2144 | | /* save user commanded value */ |
| 2145 | | data->pwm_override[nr] = |
| 2146 | | LM93_PWM_FROM_REG(ctl2 >> 4 & 0x0f, |
| 2147 | | (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : |
| 2148 | | LM93_PWM_MAP_HI_FREQ); |
| 2149 | | lm93_write_byte(client, |
| 2150 | | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2), ctl2); |
| 2151 | | up(&data->update_lock); |
| 2152 | | } |
| 2153 | | } |
| 2154 | | } |
| 2155 | | |
| 2156 | | void lm93_pwm_freq(struct i2c_client *client, int operation, int ctl_name, |
| 2157 | | int *nrels_mag, long *results) |
| 2158 | | { |
| 2159 | | struct lm93_data *data = client->data; |
| 2160 | | int nr = ctl_name - LM93_SYSCTL_PWM1_FREQ; |
| 2161 | | u8 ctl4; |
| 2162 | | |
| 2163 | | if (0 > nr || nr > 1) |
| 2164 | | return; /* ERROR */ |
| 2165 | | |
| 2166 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2167 | | *nrels_mag = 0; |
| 2168 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2169 | | lm93_update_client(client); |
| 2170 | | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| 2171 | | results[0] = LM93_PWM_FREQ_FROM_REG(ctl4); |
| 2172 | | *nrels_mag = 1; |
| 2173 | | } |
| 2174 | | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 2175 | | if (*nrels_mag >= 1) { |
| 2176 | | down(&data->update_lock); |
| 2177 | | ctl4 = lm93_read_byte( client, |
| 2178 | | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
| 2179 | | ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(results[0]); |
| 2180 | | data->block9[nr][LM93_PWM_CTL4] = ctl4; |
| 2181 | | |
| 2182 | | /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ |
| 2183 | | if (!ctl4) |
| 2184 | | lm93_disable_fan_smart_tach(client, data, nr); |
| 2185 | | |
| 2186 | | lm93_write_byte(client, |
| 2187 | | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4); |
| 2188 | | up(&data->update_lock); |
| 2189 | | } |
| 2190 | | } |
| 2191 | | } |
| 2192 | | |
| 2193 | | void lm93_pwm_auto_chan(struct i2c_client *client, int operation, int ctl_name, |
| 2194 | | int *nrels_mag, long *results) |
| 2195 | | { |
| 2196 | | struct lm93_data *data = client->data; |
| 2197 | | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_CHANNELS; |
| 2198 | | |
| 2199 | | if (0 > nr || nr > 1) |
| 2200 | | return; /* ERROR */ |
| 2201 | | |
| 2202 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2203 | | *nrels_mag = 0; |
| 2204 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2205 | | lm93_update_client(client); |
| 2206 | | results[0] = data->block9[nr][LM93_PWM_CTL1]; |
| 2207 | | *nrels_mag = 1; |
| 2208 | | } |
| 2209 | | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 2210 | | if (*nrels_mag >= 1) { |
| 2211 | | down(&data->update_lock); |
| 2212 | | data->block9[nr][LM93_PWM_CTL1] = |
| 2213 | | SENSORS_LIMIT(results[0], 0, 255); |
| 2214 | | lm93_write_byte(client, |
| 2215 | | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1), |
| 2216 | | data->block9[nr][LM93_PWM_CTL1]); |
| 2217 | | up(&data->update_lock); |
| 2218 | | } |
| 2219 | | } |
| 2220 | | } |
| 2221 | | |
| 2222 | | void lm93_pwm_auto_spinup_min(struct i2c_client *client, int operation, |
| 2223 | | int ctl_name, int *nrels_mag, long *results) |
| 2224 | | { |
| 2225 | | struct lm93_data *data = client->data; |
| 2226 | | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_SPINUP_MIN; |
| 2227 | | u8 ctl3, ctl4; |
| 2228 | | |
| 2229 | | if (0 > nr || nr > 1) |
| 2230 | | return; /* ERROR */ |
| 2231 | | |
| 2232 | | if (operation == SENSORS_PROC_REAL_INFO) |
| 2233 | | *nrels_mag = 0; |
| 2234 | | else if (operation == SENSORS_PROC_REAL_READ) { |
| 2235 | | lm93_update_client(client); |
| 2236 | | ctl3 = data->block9[nr][LM93_PWM_CTL3]; |
| 2237 | | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
| 2238 | | results[0] = LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ? |
| 2239 | | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
| 2240 | | *nrels_mag = 1; |
| 2241 | | } |
| 2242 | | else if (operation == SENSORS_PROC_REAL_WRITE) { |
| 2243 | | if (*nrels_mag >= 1) { |
| 2244 | | down(&data->update_lock); |
| 2245 | | ctl3 = lm93_read_byte(client, |
| 2246 | | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); |
| 2247 | | ctl4 = lm93_read_byte(client, |
| 2248 | | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4)); |
| 2249 | | ctl3 = (ctl3 & 0xf0) | |
| 2250 | | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
| 2251 | | LM93_PWM_MAP_LO_FREQ : |
| 2252 | | LM93_PWM_MAP_HI_FREQ); |
| 2253 | | data->block9[nr][LM93_PWM_CTL3] = ctl3; |
| 2254 | | lm93_write_byte(client, |
| 2255 | | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); |
| 2256 | | up(&data->update_lock); |
| 2257 | | } |
| 2258 | | } |
| 2259 | | } |
| 2260 | | |
| 2261 | | /* TIME: 1/100 seconds |
| 2262 | | * REG: 0-7 as mapped below */ |
| 2263 | | static int lm93_spinup_time_map[8] = { |
| 2264 | | 0, 10, 25, 40, 70, 100, 200, 400, |
| | 2288 | static struct i2c_driver lm93_driver = { |
| | 2289 | .owner = THIS_MODULE, |
| | 2290 | .name = "LM93 sensor driver", |
| | 2291 | .id = I2C_DRIVERID_LM93, |
| | 2292 | .flags = I2C_DF_NOTIFY, |
| | 2293 | .attach_adapter = lm93_attach_adapter, |
| | 2294 | .detach_client = lm93_detach_client, |