From: "Pali Rohár" <pali.rohar@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Steven Honeyman <stevenhoneyman@gmail.com>,
Jean Delvare <jdelvare@suse.de>,
Gabriele Mazzotta <gabriele.mzt@gmail.com>,
Jochen Eisinger <jochen@penguin-breeder.org>,
Valdis.Kletnieks@vt.edu, linux-kernel@vger.kernel.org
Subject: [PATCH 4/9] i8k: Rework error retries
Date: Mon, 12 Jan 2015 14:32:00 +0100 [thread overview]
Message-ID: <1421069525-12875-5-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1421069525-12875-1-git-send-email-pali.rohar@gmail.com>
From: Guenter Roeck <linux@roeck-us.net>
Instead of returning a previous value if the SMM code returns
an error when trying to read a temperature, retry once.
If that fails again, return -ENODATA. Also return -ENODATA if an
attempt is made to read the GPU temperature but the GPU is
currently turned off.
Drop the I8K_TEMPERATURE_BUG definition and handle the related bug
unconditionally.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Pali Rohár <pali.rohar@gmail.com>
---
drivers/char/i8k.c | 47 ++++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 1854fab..0e332fc 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -5,7 +5,7 @@
*
* Hwmon integration:
* Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
- * Copyright (C) 2013 Guenter Roeck <linux@roeck-us.net>
+ * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -20,6 +20,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/delay.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
@@ -59,8 +60,6 @@
#define I8K_POWER_AC 0x05
#define I8K_POWER_BATTERY 0x01
-#define I8K_TEMPERATURE_BUG 1
-
static DEFINE_MUTEX(i8k_mutex);
static char bios_version[4];
static struct device *i8k_hwmon_dev;
@@ -300,39 +299,41 @@ static int i8k_get_temp_type(int sensor)
/*
* Read the cpu temperature.
*/
-static int i8k_get_temp(int sensor)
+static int _i8k_get_temp(int sensor)
{
- struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
- int rc;
- int temp;
+ struct smm_regs regs = {
+ .eax = I8K_SMM_GET_TEMP,
+ .ebx = sensor & 0xff,
+ };
-#ifdef I8K_TEMPERATURE_BUG
- static int prev[4] = { I8K_MAX_TEMP+1, I8K_MAX_TEMP+1, I8K_MAX_TEMP+1, I8K_MAX_TEMP+1 };
-#endif
- regs.ebx = sensor & 0xff;
- rc = i8k_smm(®s);
- if (rc < 0)
- return rc;
+ return i8k_smm(®s) ? : regs.eax & 0xff;
+}
- temp = regs.eax & 0xff;
+static int i8k_get_temp(int sensor)
+{
+ int temp = _i8k_get_temp(sensor);
-#ifdef I8K_TEMPERATURE_BUG
/*
* Sometimes the temperature sensor returns 0x99, which is out of range.
- * In this case we return (once) the previous cached value. For example:
+ * In this case we retry (once) before returning an error.
# 1003655137 00000058 00005a4b
# 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
# 1003655139 00000054 00005c52
*/
- if (temp > I8K_MAX_TEMP) {
- temp = prev[sensor];
- prev[sensor] = I8K_MAX_TEMP+1;
- } else {
- prev[sensor] = temp;
+ if (temp == 0x99) {
+ msleep(100);
+ temp = _i8k_get_temp(sensor);
}
+ /*
+ * Return -ENODATA for all invalid temperatures.
+ *
+ * Known instances are the 0x99 value as seen above as well as
+ * 0xc1 (193), which may be returned when trying to read the GPU
+ * temperature if the system supports a GPU and it is currently
+ * turned off.
+ */
if (temp > I8K_MAX_TEMP)
return -ENODATA;
-#endif
return temp;
}
--
1.7.9.5
next prev parent reply other threads:[~2015-01-12 13:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 13:31 [PATCH 0/9] i8k patches Pali Rohár
2015-01-12 13:31 ` [PATCH 1/9] i8k: Add support for temperature sensor labels Pali Rohár
2015-01-12 13:31 ` [PATCH 2/9] i8k: Register only temperature sensors which have labels Pali Rohár
2015-01-12 13:31 ` [PATCH 3/9] i8k: Return -ENODATA for invalid temperature Pali Rohár
2015-01-12 13:32 ` Pali Rohár [this message]
2015-01-12 13:32 ` [PATCH 5/9] i8k: Add support for Dell XPS 13 Pali Rohár
2015-01-12 13:32 ` [PATCH 6/9] i8k: Make fan module parameters an unsigned Pali Rohár
2015-01-12 13:32 ` [PATCH 7/9] i8k: Autodetect fan RPM multiplier Pali Rohár
2015-01-12 14:19 ` Guenter Roeck
2015-01-12 14:37 ` Greg Kroah-Hartman
2015-01-12 14:51 ` Guenter Roeck
2015-01-12 13:32 ` [PATCH 8/9] i8k: Remove DMI config data for Latitude E6440 and E6540 Pali Rohár
2015-01-12 13:32 ` [PATCH 9/9] i8k: Add support for fan labels Pali Rohár
2015-01-12 14:50 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1421069525-12875-5-git-send-email-pali.rohar@gmail.com \
--to=pali.rohar@gmail.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=arnd@arndb.de \
--cc=gabriele.mzt@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jdelvare@suse.de \
--cc=jochen@penguin-breeder.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=stevenhoneyman@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox