* [PATCH 1/3] i8k: Add support for temperature sensor labels
@ 2014-11-30 20:26 Pali Rohár
2014-11-30 20:26 ` [PATCH 2/3] i8k: Register only temperature sensors which have labels Pali Rohár
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Pali Rohár @ 2014-11-30 20:26 UTC (permalink / raw)
To: Guenter Roeck, Arnd Bergmann, Greg Kroah-Hartman
Cc: Steven Honeyman, linux-kernel, Gabriele Mazzotta, Pali Rohár
This patch adds labels for temperature sensors if SMM function with EAX register
0x11a3 reports it. This information was taken from DOS binary NBSVC.MDM.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
drivers/char/i8k.c | 74 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 61 insertions(+), 13 deletions(-)
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index e34a019..4be72a4 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -42,6 +42,7 @@
#define I8K_SMM_GET_FAN 0x00a3
#define I8K_SMM_GET_SPEED 0x02a3
#define I8K_SMM_GET_TEMP 0x10a3
+#define I8K_SMM_GET_TEMP_TYPE 0x11a3
#define I8K_SMM_GET_DELL_SIG1 0xfea3
#define I8K_SMM_GET_DELL_SIG2 0xffa3
@@ -288,6 +289,14 @@ static int i8k_set_fan(int fan, int speed)
return i8k_smm(®s) ? : i8k_get_fan_status(fan);
}
+static int i8k_get_temp_type(int sensor)
+{
+ struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
+
+ regs.ebx = sensor & 0xff;
+ return i8k_smm(®s) ? : regs.eax & 0xff;
+}
+
/*
* Read the cpu temperature.
*/
@@ -493,6 +502,29 @@ static int i8k_open_fs(struct inode *inode, struct file *file)
* Hwmon interface
*/
+static ssize_t i8k_hwmon_show_temp_label(struct device *dev,
+ struct device_attribute *devattr,
+ char *buf)
+{
+ static const char * const labels[] = {
+ "CPU",
+ "GPU",
+ "SODIMM",
+ "Other",
+ "Ambient",
+ "Other",
+ };
+ int index = to_sensor_dev_attr(devattr)->index;
+ int type;
+
+ type = i8k_get_temp_type(index);
+ if (type < 0)
+ return type;
+ if (type >= ARRAY_SIZE(labels))
+ type = ARRAY_SIZE(labels) - 1;
+ return sprintf(buf, "%s\n", labels[type]);
+}
+
static ssize_t i8k_hwmon_show_temp(struct device *dev,
struct device_attribute *devattr,
char *buf)
@@ -555,9 +587,17 @@ static ssize_t i8k_hwmon_set_pwm(struct device *dev,
}
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
+ 0);
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
+ 1);
static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
+ 2);
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
+ 3);
static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
I8K_FAN_LEFT);
static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
@@ -569,31 +609,39 @@ static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
static struct attribute *i8k_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
- &sensor_dev_attr_temp2_input.dev_attr.attr, /* 1 */
- &sensor_dev_attr_temp3_input.dev_attr.attr, /* 2 */
- &sensor_dev_attr_temp4_input.dev_attr.attr, /* 3 */
- &sensor_dev_attr_fan1_input.dev_attr.attr, /* 4 */
- &sensor_dev_attr_pwm1.dev_attr.attr, /* 5 */
- &sensor_dev_attr_fan2_input.dev_attr.attr, /* 6 */
- &sensor_dev_attr_pwm2.dev_attr.attr, /* 7 */
+ &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
+ &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
+ &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
+ &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
+ &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
+ &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
+ &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
+ &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */
+ &sensor_dev_attr_pwm1.dev_attr.attr, /* 9 */
+ &sensor_dev_attr_fan2_input.dev_attr.attr, /* 10 */
+ &sensor_dev_attr_pwm2.dev_attr.attr, /* 11 */
NULL
};
static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
int index)
{
- if (index == 0 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
+ if (index >= 0 && index <= 1 &&
+ !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
return 0;
- if (index == 1 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
+ if (index >= 2 && index <= 3 &&
+ !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
return 0;
- if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
+ if (index >= 4 && index <= 5 &&
+ !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
return 0;
- if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
+ if (index >= 6 && index <= 7 &&
+ !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
return 0;
- if (index >= 4 && index <= 5 &&
+ if (index >= 8 && index <= 9 &&
!(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
return 0;
- if (index >= 6 && index <= 7 &&
+ if (index >= 10 && index <= 11 &&
!(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
return 0;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] i8k: Register only temperature sensors which have labels
2014-11-30 20:26 [PATCH 1/3] i8k: Add support for temperature sensor labels Pali Rohár
@ 2014-11-30 20:26 ` Pali Rohár
2014-11-30 20:49 ` Guenter Roeck
2014-11-30 20:26 ` [PATCH 3/3] i8k: Return -ENODATA for invalid temperature Pali Rohár
2014-11-30 20:48 ` [PATCH 1/3] i8k: Add support for temperature sensor labels Guenter Roeck
2 siblings, 1 reply; 6+ messages in thread
From: Pali Rohár @ 2014-11-30 20:26 UTC (permalink / raw)
To: Guenter Roeck, Arnd Bergmann, Greg Kroah-Hartman
Cc: Steven Honeyman, linux-kernel, Gabriele Mazzotta, Pali Rohár
Detect presense of sensor by calling type function instead trying to read
temperature value. Type function is working also for sensors which are temporary
turned off (e.g on GPU which is turned off). Dell DOS binary NBSVC.MDM is doing
similar checks, so we should do that too.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
drivers/char/i8k.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 4be72a4..7b56ede 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -660,19 +660,19 @@ static int __init i8k_init_hwmon(void)
i8k_hwmon_flags = 0;
- /* CPU temperature attributes, if temperature reading is OK */
- err = i8k_get_temp(0);
- if (err >= 0 || err == -ERANGE)
+ /* CPU temperature attributes, if temperature type is OK */
+ err = i8k_get_temp_type(0);
+ if (err >= 0)
i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
/* check for additional temperature sensors */
- err = i8k_get_temp(1);
- if (err >= 0 || err == -ERANGE)
+ err = i8k_get_temp_type(1);
+ if (err >= 0)
i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
- err = i8k_get_temp(2);
- if (err >= 0 || err == -ERANGE)
+ err = i8k_get_temp_type(2);
+ if (err >= 0)
i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
- err = i8k_get_temp(3);
- if (err >= 0 || err == -ERANGE)
+ err = i8k_get_temp_type(3);
+ if (err >= 0)
i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
/* Left fan attributes, if left fan is present */
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] i8k: Register only temperature sensors which have labels
2014-11-30 20:26 ` [PATCH 2/3] i8k: Register only temperature sensors which have labels Pali Rohár
@ 2014-11-30 20:49 ` Guenter Roeck
0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2014-11-30 20:49 UTC (permalink / raw)
To: Pali Rohár, Arnd Bergmann, Greg Kroah-Hartman
Cc: Steven Honeyman, linux-kernel, Gabriele Mazzotta
On 11/30/2014 12:26 PM, Pali Rohár wrote:
> Detect presense of sensor by calling type function instead trying to read
> temperature value. Type function is working also for sensors which are temporary
> turned off (e.g on GPU which is turned off). Dell DOS binary NBSVC.MDM is doing
> similar checks, so we should do that too.
>
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Thanks,
Guenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] i8k: Return -ENODATA for invalid temperature
2014-11-30 20:26 [PATCH 1/3] i8k: Add support for temperature sensor labels Pali Rohár
2014-11-30 20:26 ` [PATCH 2/3] i8k: Register only temperature sensors which have labels Pali Rohár
@ 2014-11-30 20:26 ` Pali Rohár
2014-11-30 20:50 ` Guenter Roeck
2014-11-30 20:48 ` [PATCH 1/3] i8k: Add support for temperature sensor labels Guenter Roeck
2 siblings, 1 reply; 6+ messages in thread
From: Pali Rohár @ 2014-11-30 20:26 UTC (permalink / raw)
To: Guenter Roeck, Arnd Bergmann, Greg Kroah-Hartman
Cc: Steven Honeyman, linux-kernel, Gabriele Mazzotta, Pali Rohár
Guenter Roeck suggested to return -ENODATA instead -ERANGE or -EINVAL when BIOS
reports invalid temperature value.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
drivers/char/i8k.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 7b56ede..8c7c642 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -331,7 +331,7 @@ static int i8k_get_temp(int sensor)
prev[sensor] = temp;
}
if (temp > I8K_MAX_TEMP)
- return -ERANGE;
+ return -ENODATA;
#endif
return temp;
@@ -533,8 +533,6 @@ static ssize_t i8k_hwmon_show_temp(struct device *dev,
int temp;
temp = i8k_get_temp(index);
- if (temp == -ERANGE)
- return -EINVAL;
if (temp < 0)
return temp;
return sprintf(buf, "%d\n", temp * 1000);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] i8k: Add support for temperature sensor labels
2014-11-30 20:26 [PATCH 1/3] i8k: Add support for temperature sensor labels Pali Rohár
2014-11-30 20:26 ` [PATCH 2/3] i8k: Register only temperature sensors which have labels Pali Rohár
2014-11-30 20:26 ` [PATCH 3/3] i8k: Return -ENODATA for invalid temperature Pali Rohár
@ 2014-11-30 20:48 ` Guenter Roeck
2 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2014-11-30 20:48 UTC (permalink / raw)
To: Pali Rohár, Arnd Bergmann, Greg Kroah-Hartman
Cc: Steven Honeyman, linux-kernel, Gabriele Mazzotta
On 11/30/2014 12:26 PM, Pali Rohár wrote:
> This patch adds labels for temperature sensors if SMM function with EAX register
> 0x11a3 reports it. This information was taken from DOS binary NBSVC.MDM.
>
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Nitpick below, otherwise
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Thanks,
Guenter
> ---
> drivers/char/i8k.c | 74 +++++++++++++++++++++++++++++++++++++++++++---------
> 1 file changed, 61 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
> index e34a019..4be72a4 100644
> --- a/drivers/char/i8k.c
> +++ b/drivers/char/i8k.c
> @@ -42,6 +42,7 @@
> #define I8K_SMM_GET_FAN 0x00a3
> #define I8K_SMM_GET_SPEED 0x02a3
> #define I8K_SMM_GET_TEMP 0x10a3
> +#define I8K_SMM_GET_TEMP_TYPE 0x11a3
> #define I8K_SMM_GET_DELL_SIG1 0xfea3
> #define I8K_SMM_GET_DELL_SIG2 0xffa3
>
> @@ -288,6 +289,14 @@ static int i8k_set_fan(int fan, int speed)
> return i8k_smm(®s) ? : i8k_get_fan_status(fan);
> }
>
> +static int i8k_get_temp_type(int sensor)
> +{
> + struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
> +
> + regs.ebx = sensor & 0xff;
> + return i8k_smm(®s) ? : regs.eax & 0xff;
> +}
> +
> /*
> * Read the cpu temperature.
> */
> @@ -493,6 +502,29 @@ static int i8k_open_fs(struct inode *inode, struct file *file)
> * Hwmon interface
> */
>
> +static ssize_t i8k_hwmon_show_temp_label(struct device *dev,
> + struct device_attribute *devattr,
> + char *buf)
Continuation lines should be aligned with '('.
> +{
> + static const char * const labels[] = {
> + "CPU",
> + "GPU",
> + "SODIMM",
> + "Other",
> + "Ambient",
> + "Other",
> + };
> + int index = to_sensor_dev_attr(devattr)->index;
> + int type;
> +
> + type = i8k_get_temp_type(index);
> + if (type < 0)
> + return type;
> + if (type >= ARRAY_SIZE(labels))
> + type = ARRAY_SIZE(labels) - 1;
> + return sprintf(buf, "%s\n", labels[type]);
> +}
> +
> static ssize_t i8k_hwmon_show_temp(struct device *dev,
> struct device_attribute *devattr,
> char *buf)
> @@ -555,9 +587,17 @@ static ssize_t i8k_hwmon_set_pwm(struct device *dev,
> }
>
> static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
> +static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
> + 0);
> static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
> +static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
> + 1);
> static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
> +static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
> + 2);
> static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
> +static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
> + 3);
> static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
> I8K_FAN_LEFT);
> static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
> @@ -569,31 +609,39 @@ static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
>
> static struct attribute *i8k_attrs[] = {
> &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
> - &sensor_dev_attr_temp2_input.dev_attr.attr, /* 1 */
> - &sensor_dev_attr_temp3_input.dev_attr.attr, /* 2 */
> - &sensor_dev_attr_temp4_input.dev_attr.attr, /* 3 */
> - &sensor_dev_attr_fan1_input.dev_attr.attr, /* 4 */
> - &sensor_dev_attr_pwm1.dev_attr.attr, /* 5 */
> - &sensor_dev_attr_fan2_input.dev_attr.attr, /* 6 */
> - &sensor_dev_attr_pwm2.dev_attr.attr, /* 7 */
> + &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
> + &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
> + &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
> + &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
> + &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
> + &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
> + &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
> + &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */
> + &sensor_dev_attr_pwm1.dev_attr.attr, /* 9 */
> + &sensor_dev_attr_fan2_input.dev_attr.attr, /* 10 */
> + &sensor_dev_attr_pwm2.dev_attr.attr, /* 11 */
> NULL
> };
>
> static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
> int index)
> {
> - if (index == 0 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
> + if (index >= 0 && index <= 1 &&
> + !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
> return 0;
> - if (index == 1 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
> + if (index >= 2 && index <= 3 &&
> + !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
> return 0;
> - if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
> + if (index >= 4 && index <= 5 &&
> + !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
> return 0;
> - if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
> + if (index >= 6 && index <= 7 &&
> + !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
> return 0;
> - if (index >= 4 && index <= 5 &&
> + if (index >= 8 && index <= 9 &&
> !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
> return 0;
> - if (index >= 6 && index <= 7 &&
> + if (index >= 10 && index <= 11 &&
> !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
> return 0;
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-11-30 20:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-30 20:26 [PATCH 1/3] i8k: Add support for temperature sensor labels Pali Rohár
2014-11-30 20:26 ` [PATCH 2/3] i8k: Register only temperature sensors which have labels Pali Rohár
2014-11-30 20:49 ` Guenter Roeck
2014-11-30 20:26 ` [PATCH 3/3] i8k: Return -ENODATA for invalid temperature Pali Rohár
2014-11-30 20:50 ` Guenter Roeck
2014-11-30 20:48 ` [PATCH 1/3] i8k: Add support for temperature sensor labels Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox