Skip to content

Commit 2c37aa4

Browse files
hmhlenb
authored andcommitted
ACPI: thinkpad-acpi: add sysfs support to the thermal subdriver
Export thinkpad thermal sensors to sysfs, following the hwmon specification for thermal monitoring sensors. ThinkPad thermal monitoring is done by the EC. Sensors can show up or disappear at runtime when they are inside hotswappable hardware, such as batteries. Sensors that are not available return -ENXIO when accessed. Up to 16 thermal sensors are supported on new firmware (but nobody has reported a ThinkPad with more than 12 sensors so far), and 8 sensors are supported on older firmware. Thermal sensor mapping is model-specific. Precision varies, it is 1 degree Celcius on new ThinkPads, but higher on some older models. Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 40ca9fd commit 2c37aa4

3 files changed

Lines changed: 143 additions & 7 deletions

File tree

‎Documentation/thinkpad-acpi.txt‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,17 @@ X40:
458458
16 - one medium-pitched beep repeating constantly, stop with 17
459459
17 - stop 16
460460

461-
Temperature sensors -- /proc/acpi/ibm/thermal
462-
---------------------------------------------
461+
Temperature sensors
462+
-------------------
463+
464+
procfs: /proc/acpi/ibm/thermal
465+
sysfs device attributes: (hwmon) temp*_input
463466

464467
Most ThinkPads include six or more separate temperature sensors but
465468
only expose the CPU temperature through the standard ACPI methods.
466469
This feature shows readings from up to eight different sensors on older
467470
ThinkPads, and it has experimental support for up to sixteen different
468-
sensors on newer ThinkPads. Readings from sensors that are not available
469-
return -128.
470-
471-
No commands can be written to this file.
471+
sensors on newer ThinkPads.
472472

473473
EXPERIMENTAL: The 16-sensors feature is marked EXPERIMENTAL because the
474474
implementation directly accesses hardware registers and may not work as
@@ -525,6 +525,20 @@ The A31 has a very atypical layout for the thermal sensors
525525
8: Bay Battery: secondary sensor
526526

527527

528+
Procfs notes:
529+
Readings from sensors that are not available return -128.
530+
No commands can be written to this file.
531+
532+
Sysfs notes:
533+
Sensors that are not available return the ENXIO error. This
534+
status may change at runtime, as there are hotplug thermal
535+
sensors, like those inside the batteries and docks.
536+
537+
thinkpad-acpi thermal sensors are reported through the hwmon
538+
subsystem, and follow all of the hwmon guidelines at
539+
Documentation/hwmon.
540+
541+
528542
EXPERIMENTAL: Embedded controller register dump -- /proc/acpi/ibm/ecdump
529543
------------------------------------------------------------------------
530544

‎drivers/misc/thinkpad_acpi.c‎

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,11 +1992,91 @@ static struct ibm_struct beep_driver_data = {
19921992

19931993
static enum thermal_access_mode thermal_read_mode;
19941994

1995+
/* sysfs temp##_input -------------------------------------------------- */
1996+
1997+
static ssize_t thermal_temp_input_show(struct device *dev,
1998+
struct device_attribute *attr,
1999+
char *buf)
2000+
{
2001+
struct sensor_device_attribute *sensor_attr =
2002+
to_sensor_dev_attr(attr);
2003+
int idx = sensor_attr->index;
2004+
s32 value;
2005+
int res;
2006+
2007+
res = thermal_get_sensor(idx, &value);
2008+
if (res)
2009+
return res;
2010+
if (value == TP_EC_THERMAL_TMP_NA * 1000)
2011+
return -ENXIO;
2012+
2013+
return snprintf(buf, PAGE_SIZE, "%d\n", value);
2014+
}
2015+
2016+
#define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2017+
SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2018+
2019+
static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
2020+
THERMAL_SENSOR_ATTR_TEMP(1, 0),
2021+
THERMAL_SENSOR_ATTR_TEMP(2, 1),
2022+
THERMAL_SENSOR_ATTR_TEMP(3, 2),
2023+
THERMAL_SENSOR_ATTR_TEMP(4, 3),
2024+
THERMAL_SENSOR_ATTR_TEMP(5, 4),
2025+
THERMAL_SENSOR_ATTR_TEMP(6, 5),
2026+
THERMAL_SENSOR_ATTR_TEMP(7, 6),
2027+
THERMAL_SENSOR_ATTR_TEMP(8, 7),
2028+
THERMAL_SENSOR_ATTR_TEMP(9, 8),
2029+
THERMAL_SENSOR_ATTR_TEMP(10, 9),
2030+
THERMAL_SENSOR_ATTR_TEMP(11, 10),
2031+
THERMAL_SENSOR_ATTR_TEMP(12, 11),
2032+
THERMAL_SENSOR_ATTR_TEMP(13, 12),
2033+
THERMAL_SENSOR_ATTR_TEMP(14, 13),
2034+
THERMAL_SENSOR_ATTR_TEMP(15, 14),
2035+
THERMAL_SENSOR_ATTR_TEMP(16, 15),
2036+
};
2037+
2038+
#define THERMAL_ATTRS(X) \
2039+
&sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2040+
2041+
static struct attribute *thermal_temp_input_attr[] = {
2042+
THERMAL_ATTRS(8),
2043+
THERMAL_ATTRS(9),
2044+
THERMAL_ATTRS(10),
2045+
THERMAL_ATTRS(11),
2046+
THERMAL_ATTRS(12),
2047+
THERMAL_ATTRS(13),
2048+
THERMAL_ATTRS(14),
2049+
THERMAL_ATTRS(15),
2050+
THERMAL_ATTRS(0),
2051+
THERMAL_ATTRS(1),
2052+
THERMAL_ATTRS(2),
2053+
THERMAL_ATTRS(3),
2054+
THERMAL_ATTRS(4),
2055+
THERMAL_ATTRS(5),
2056+
THERMAL_ATTRS(6),
2057+
THERMAL_ATTRS(7),
2058+
NULL
2059+
};
2060+
2061+
static const struct attribute_group thermal_temp_input16_group = {
2062+
.attrs = thermal_temp_input_attr
2063+
};
2064+
2065+
static const struct attribute_group thermal_temp_input8_group = {
2066+
.attrs = &thermal_temp_input_attr[8]
2067+
};
2068+
2069+
#undef THERMAL_SENSOR_ATTR_TEMP
2070+
#undef THERMAL_ATTRS
2071+
2072+
/* --------------------------------------------------------------------- */
2073+
19952074
static int __init thermal_init(struct ibm_init_struct *iibm)
19962075
{
19972076
u8 t, ta1, ta2;
19982077
int i;
19992078
int acpi_tmp7;
2079+
int res;
20002080

20012081
vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
20022082

@@ -2060,7 +2140,46 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
20602140
str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
20612141
thermal_read_mode);
20622142

2063-
return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
2143+
switch(thermal_read_mode) {
2144+
case TPACPI_THERMAL_TPEC_16:
2145+
res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2146+
&thermal_temp_input16_group);
2147+
if (res)
2148+
return res;
2149+
break;
2150+
case TPACPI_THERMAL_TPEC_8:
2151+
case TPACPI_THERMAL_ACPI_TMP07:
2152+
case TPACPI_THERMAL_ACPI_UPDT:
2153+
res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2154+
&thermal_temp_input8_group);
2155+
if (res)
2156+
return res;
2157+
break;
2158+
case TPACPI_THERMAL_NONE:
2159+
default:
2160+
return 1;
2161+
}
2162+
2163+
return 0;
2164+
}
2165+
2166+
static void thermal_exit(void)
2167+
{
2168+
switch(thermal_read_mode) {
2169+
case TPACPI_THERMAL_TPEC_16:
2170+
sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2171+
&thermal_temp_input16_group);
2172+
break;
2173+
case TPACPI_THERMAL_TPEC_8:
2174+
case TPACPI_THERMAL_ACPI_TMP07:
2175+
case TPACPI_THERMAL_ACPI_UPDT:
2176+
sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2177+
&thermal_temp_input16_group);
2178+
break;
2179+
case TPACPI_THERMAL_NONE:
2180+
default:
2181+
break;
2182+
}
20642183
}
20652184

20662185
/* idx is zero-based */
@@ -2168,6 +2287,7 @@ static int thermal_read(char *p)
21682287
static struct ibm_struct thermal_driver_data = {
21692288
.name = "thermal",
21702289
.read = thermal_read,
2290+
.exit = thermal_exit,
21712291
};
21722292

21732293
/*************************************************************************

‎drivers/misc/thinkpad_acpi.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/fb.h>
3939
#include <linux/platform_device.h>
4040
#include <linux/hwmon.h>
41+
#include <linux/hwmon-sysfs.h>
4142
#include <asm/uaccess.h>
4243

4344
#include <linux/dmi.h>
@@ -467,6 +468,7 @@ enum thermal_access_mode {
467468
enum { /* TPACPI_THERMAL_TPEC_* */
468469
TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
469470
TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
471+
TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
470472
};
471473

472474
#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */

0 commit comments

Comments
 (0)