aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/abituguru.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/abituguru.c')
-rw-r--r--drivers/hwmon/abituguru.c120
1 files changed, 80 insertions, 40 deletions
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 59122cc0a50a..35ad1b032726 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -26,6 +26,7 @@
26#include <linux/jiffies.h> 26#include <linux/jiffies.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/delay.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/hwmon.h> 31#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h> 32#include <linux/hwmon-sysfs.h>
@@ -64,17 +65,17 @@
64#define ABIT_UGURU_IN_SENSOR 0 65#define ABIT_UGURU_IN_SENSOR 0
65#define ABIT_UGURU_TEMP_SENSOR 1 66#define ABIT_UGURU_TEMP_SENSOR 1
66#define ABIT_UGURU_NC 2 67#define ABIT_UGURU_NC 2
67/* Timeouts / Retries, if these turn out to need a lot of fiddling we could 68/* In many cases we need to wait for the uGuru to reach a certain status, most
68 convert them to params. */ 69 of the time it will reach this status within 30 - 90 ISA reads, and thus we
69/* 250 was determined by trial and error, 200 works most of the time, but not 70 can best busy wait. This define gives the total amount of reads to try. */
70 always. I assume this is cpu-speed independent, since the ISA-bus and not 71#define ABIT_UGURU_WAIT_TIMEOUT 125
71 the CPU should be the bottleneck. Note that 250 sometimes is still not 72/* However sometimes older versions of the uGuru seem to be distracted and they
72 enough (only reported on AN7 mb) this is handled by a higher layer. */ 73 do not respond for a long time. To handle this we sleep before each of the
73#define ABIT_UGURU_WAIT_TIMEOUT 250 74 last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */
75#define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5
74/* Normally all expected status in abituguru_ready, are reported after the 76/* Normally all expected status in abituguru_ready, are reported after the
75 first read, but sometimes not and we need to poll, 5 polls was not enough 77 first read, but sometimes not and we need to poll. */
76 50 sofar is. */ 78#define ABIT_UGURU_READY_TIMEOUT 5
77#define ABIT_UGURU_READY_TIMEOUT 50
78/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ 79/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */
79#define ABIT_UGURU_MAX_RETRIES 3 80#define ABIT_UGURU_MAX_RETRIES 3
80#define ABIT_UGURU_RETRY_DELAY (HZ/5) 81#define ABIT_UGURU_RETRY_DELAY (HZ/5)
@@ -142,6 +143,14 @@ static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 };
142static int force; 143static int force;
143module_param(force, bool, 0); 144module_param(force, bool, 0);
144MODULE_PARM_DESC(force, "Set to one to force detection."); 145MODULE_PARM_DESC(force, "Set to one to force detection.");
146static int bank1_types[ABIT_UGURU_MAX_BANK1_SENSORS] = { -1, -1, -1, -1, -1,
147 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
148module_param_array(bank1_types, int, NULL, 0);
149MODULE_PARM_DESC(bank1_types, "Bank1 sensortype autodetection override:\n"
150 " -1 autodetect\n"
151 " 0 volt sensor\n"
152 " 1 temp sensor\n"
153 " 2 not connected");
145static int fan_sensors; 154static int fan_sensors;
146module_param(fan_sensors, int, 0); 155module_param(fan_sensors, int, 0);
147MODULE_PARM_DESC(fan_sensors, "Number of fan sensors on the uGuru " 156MODULE_PARM_DESC(fan_sensors, "Number of fan sensors on the uGuru "
@@ -218,6 +227,10 @@ static int abituguru_wait(struct abituguru_data *data, u8 state)
218 timeout--; 227 timeout--;
219 if (timeout == 0) 228 if (timeout == 0)
220 return -EBUSY; 229 return -EBUSY;
230 /* sleep a bit before our last few tries, see the comment on
231 this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */
232 if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP)
233 msleep(0);
221 } 234 }
222 return 0; 235 return 0;
223} 236}
@@ -248,6 +261,7 @@ static int abituguru_ready(struct abituguru_data *data)
248 "CMD reg does not hold 0xAC after ready command\n"); 261 "CMD reg does not hold 0xAC after ready command\n");
249 return -EIO; 262 return -EIO;
250 } 263 }
264 msleep(0);
251 } 265 }
252 266
253 /* After this the ABIT_UGURU_DATA port should contain 267 /* After this the ABIT_UGURU_DATA port should contain
@@ -260,6 +274,7 @@ static int abituguru_ready(struct abituguru_data *data)
260 "state != more input after ready command\n"); 274 "state != more input after ready command\n");
261 return -EIO; 275 return -EIO;
262 } 276 }
277 msleep(0);
263 } 278 }
264 279
265 data->uguru_ready = 1; 280 data->uguru_ready = 1;
@@ -323,7 +338,8 @@ static int abituguru_read(struct abituguru_data *data,
323 /* And read the data */ 338 /* And read the data */
324 for (i = 0; i < count; i++) { 339 for (i = 0; i < count; i++) {
325 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 340 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
326 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for " 341 ABIT_UGURU_DEBUG(retries ? 1 : 3,
342 "timeout exceeded waiting for "
327 "read state (bank: %d, sensor: %d)\n", 343 "read state (bank: %d, sensor: %d)\n",
328 (int)bank_addr, (int)sensor_addr); 344 (int)bank_addr, (int)sensor_addr);
329 break; 345 break;
@@ -342,7 +358,9 @@ static int abituguru_read(struct abituguru_data *data,
342static int abituguru_write(struct abituguru_data *data, 358static int abituguru_write(struct abituguru_data *data,
343 u8 bank_addr, u8 sensor_addr, u8 *buf, int count) 359 u8 bank_addr, u8 sensor_addr, u8 *buf, int count)
344{ 360{
345 int i; 361 /* We use the ready timeout as we have to wait for 0xAC just like the
362 ready function */
363 int i, timeout = ABIT_UGURU_READY_TIMEOUT;
346 364
347 /* Send the address */ 365 /* Send the address */
348 i = abituguru_send_address(data, bank_addr, sensor_addr, 366 i = abituguru_send_address(data, bank_addr, sensor_addr,
@@ -362,7 +380,8 @@ static int abituguru_write(struct abituguru_data *data,
362 } 380 }
363 381
364 /* Now we need to wait till the chip is ready to be read again, 382 /* Now we need to wait till the chip is ready to be read again,
365 don't ask why */ 383 so that we can read 0xAC as confirmation that our write has
384 succeeded. */
366 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 385 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
367 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " 386 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state "
368 "after write (bank: %d, sensor: %d)\n", (int)bank_addr, 387 "after write (bank: %d, sensor: %d)\n", (int)bank_addr,
@@ -371,11 +390,15 @@ static int abituguru_write(struct abituguru_data *data,
371 } 390 }
372 391
373 /* Cmd port MUST be read now and should contain 0xAC */ 392 /* Cmd port MUST be read now and should contain 0xAC */
374 if (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) { 393 while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) {
375 ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after write " 394 timeout--;
376 "(bank: %d, sensor: %d)\n", (int)bank_addr, 395 if (timeout == 0) {
377 (int)sensor_addr); 396 ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after "
378 return -EIO; 397 "write (bank: %d, sensor: %d)\n",
398 (int)bank_addr, (int)sensor_addr);
399 return -EIO;
400 }
401 msleep(0);
379 } 402 }
380 403
381 /* Last put the chip back in ready state */ 404 /* Last put the chip back in ready state */
@@ -395,7 +418,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
395 u8 sensor_addr) 418 u8 sensor_addr)
396{ 419{
397 u8 val, buf[3]; 420 u8 val, buf[3];
398 int ret = ABIT_UGURU_NC; 421 int i, ret = -ENODEV; /* error is the most common used retval :| */
422
423 /* If overriden by the user return the user selected type */
424 if (bank1_types[sensor_addr] >= ABIT_UGURU_IN_SENSOR &&
425 bank1_types[sensor_addr] <= ABIT_UGURU_NC) {
426 ABIT_UGURU_DEBUG(2, "assuming sensor type %d for bank1 sensor "
427 "%d because of \"bank1_types\" module param\n",
428 bank1_types[sensor_addr], (int)sensor_addr);
429 return bank1_types[sensor_addr];
430 }
399 431
400 /* First read the sensor and the current settings */ 432 /* First read the sensor and the current settings */
401 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val, 433 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val,
@@ -422,7 +454,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
422 buf[2] = 250; 454 buf[2] = 250;
423 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 455 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
424 buf, 3) != 3) 456 buf, 3) != 3)
425 return -ENODEV; 457 goto abituguru_detect_bank1_sensor_type_exit;
426 /* Now we need 20 ms to give the uguru time to read the sensors 458 /* Now we need 20 ms to give the uguru time to read the sensors
427 and raise a voltage alarm */ 459 and raise a voltage alarm */
428 set_current_state(TASK_UNINTERRUPTIBLE); 460 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -430,21 +462,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
430 /* Check for alarm and check the alarm is a volt low alarm. */ 462 /* Check for alarm and check the alarm is a volt low alarm. */
431 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 463 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
432 ABIT_UGURU_MAX_RETRIES) != 3) 464 ABIT_UGURU_MAX_RETRIES) != 3)
433 return -ENODEV; 465 goto abituguru_detect_bank1_sensor_type_exit;
434 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 466 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
435 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 467 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
436 sensor_addr, buf, 3, 468 sensor_addr, buf, 3,
437 ABIT_UGURU_MAX_RETRIES) != 3) 469 ABIT_UGURU_MAX_RETRIES) != 3)
438 return -ENODEV; 470 goto abituguru_detect_bank1_sensor_type_exit;
439 if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { 471 if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) {
440 /* Restore original settings */
441 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
442 sensor_addr,
443 data->bank1_settings[sensor_addr],
444 3) != 3)
445 return -ENODEV;
446 ABIT_UGURU_DEBUG(2, " found volt sensor\n"); 472 ABIT_UGURU_DEBUG(2, " found volt sensor\n");
447 return ABIT_UGURU_IN_SENSOR; 473 ret = ABIT_UGURU_IN_SENSOR;
474 goto abituguru_detect_bank1_sensor_type_exit;
448 } else 475 } else
449 ABIT_UGURU_DEBUG(2, " alarm raised during volt " 476 ABIT_UGURU_DEBUG(2, " alarm raised during volt "
450 "sensor test, but volt low flag not set\n"); 477 "sensor test, but volt low flag not set\n");
@@ -460,7 +487,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
460 buf[2] = 10; 487 buf[2] = 10;
461 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 488 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
462 buf, 3) != 3) 489 buf, 3) != 3)
463 return -ENODEV; 490 goto abituguru_detect_bank1_sensor_type_exit;
464 /* Now we need 50 ms to give the uguru time to read the sensors 491 /* Now we need 50 ms to give the uguru time to read the sensors
465 and raise a temp alarm */ 492 and raise a temp alarm */
466 set_current_state(TASK_UNINTERRUPTIBLE); 493 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -468,15 +495,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
468 /* Check for alarm and check the alarm is a temp high alarm. */ 495 /* Check for alarm and check the alarm is a temp high alarm. */
469 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 496 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
470 ABIT_UGURU_MAX_RETRIES) != 3) 497 ABIT_UGURU_MAX_RETRIES) != 3)
471 return -ENODEV; 498 goto abituguru_detect_bank1_sensor_type_exit;
472 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 499 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
473 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 500 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
474 sensor_addr, buf, 3, 501 sensor_addr, buf, 3,
475 ABIT_UGURU_MAX_RETRIES) != 3) 502 ABIT_UGURU_MAX_RETRIES) != 3)
476 return -ENODEV; 503 goto abituguru_detect_bank1_sensor_type_exit;
477 if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) { 504 if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) {
478 ret = ABIT_UGURU_TEMP_SENSOR;
479 ABIT_UGURU_DEBUG(2, " found temp sensor\n"); 505 ABIT_UGURU_DEBUG(2, " found temp sensor\n");
506 ret = ABIT_UGURU_TEMP_SENSOR;
507 goto abituguru_detect_bank1_sensor_type_exit;
480 } else 508 } else
481 ABIT_UGURU_DEBUG(2, " alarm raised during temp " 509 ABIT_UGURU_DEBUG(2, " alarm raised during temp "
482 "sensor test, but temp high flag not set\n"); 510 "sensor test, but temp high flag not set\n");
@@ -484,11 +512,23 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
484 ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor " 512 ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor "
485 "test\n"); 513 "test\n");
486 514
487 /* Restore original settings */ 515 ret = ABIT_UGURU_NC;
488 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 516abituguru_detect_bank1_sensor_type_exit:
489 data->bank1_settings[sensor_addr], 3) != 3) 517 /* Restore original settings, failing here is really BAD, it has been
518 reported that some BIOS-es hang when entering the uGuru menu with
519 invalid settings present in the uGuru, so we try this 3 times. */
520 for (i = 0; i < 3; i++)
521 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
522 sensor_addr, data->bank1_settings[sensor_addr],
523 3) == 3)
524 break;
525 if (i == 3) {
526 printk(KERN_ERR ABIT_UGURU_NAME
527 ": Fatal error could not restore original settings. "
528 "This should never happen please report this to the "
529 "abituguru maintainer (see MAINTAINERS)\n");
490 return -ENODEV; 530 return -ENODEV;
491 531 }
492 return ret; 532 return ret;
493} 533}
494 534
@@ -514,7 +554,7 @@ abituguru_detect_no_bank2_sensors(struct abituguru_data *data)
514{ 554{
515 int i; 555 int i;
516 556
517 if (fan_sensors) { 557 if (fan_sensors > 0 && fan_sensors <= ABIT_UGURU_MAX_BANK2_SENSORS) {
518 data->bank2_sensors = fan_sensors; 558 data->bank2_sensors = fan_sensors;
519 ABIT_UGURU_DEBUG(2, "assuming %d fan sensors because of " 559 ABIT_UGURU_DEBUG(2, "assuming %d fan sensors because of "
520 "\"fan_sensors\" module param\n", 560 "\"fan_sensors\" module param\n",
@@ -568,7 +608,7 @@ abituguru_detect_no_pwms(struct abituguru_data *data)
568{ 608{
569 int i, j; 609 int i, j;
570 610
571 if (pwms) { 611 if (pwms > 0 && pwms <= ABIT_UGURU_MAX_PWMS) {
572 data->pwms = pwms; 612 data->pwms = pwms;
573 ABIT_UGURU_DEBUG(2, "assuming %d PWM outputs because of " 613 ABIT_UGURU_DEBUG(2, "assuming %d PWM outputs because of "
574 "\"pwms\" module param\n", (int)data->pwms); 614 "\"pwms\" module param\n", (int)data->pwms);
@@ -1288,7 +1328,7 @@ static struct abituguru_data *abituguru_update_device(struct device *dev)
1288 data->update_timeouts = 0; 1328 data->update_timeouts = 0;
1289LEAVE_UPDATE: 1329LEAVE_UPDATE:
1290 /* handle timeout condition */ 1330 /* handle timeout condition */
1291 if (err == -EBUSY) { 1331 if (!success && (err == -EBUSY || err >= 0)) {
1292 /* No overflow please */ 1332 /* No overflow please */
1293 if (data->update_timeouts < 255u) 1333 if (data->update_timeouts < 255u)
1294 data->update_timeouts++; 1334 data->update_timeouts++;