platform/x86: thinkpad_acpi: Correct thermal sensor allocation

On recent Thinkpad platforms it was reported that temp sensor 11 was
always incorrectly displaying 66C. It turns out the reason for this is
that this location in EC RAM is not a temperature sensor but is the
power supply ID (offset 0xC2).

Based on feedback from the Lenovo firmware team the EC RAM version can
be determined and for the current version (3) only the 0x78 to 0x7F
range is used for temp sensors. I don't have any details for earlier
versions so I have left the implementation unaltered there.

Note - in this block only 0x78 and 0x79 are officially designated (CPU &
GPU sensors). The use of the other locations in the block will vary from
platform to platform; but the existing logic to detect a sensor presence
holds.

Signed-off-by: Mark Pearson <markpearson@lenovo.com>
Link: https://lore.kernel.org/r/20210407212015.298222-1-markpearson@lenovo.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Mark Pearson 2021-04-07 17:20:15 -04:00 коммит произвёл Hans de Goede
Родитель 507cf5a2f1
Коммит 6759e18e5c
1 изменённых файлов: 22 добавлений и 9 удалений

Просмотреть файл

@ -6283,6 +6283,7 @@ enum thermal_access_mode {
enum { /* TPACPI_THERMAL_TPEC_* */ enum { /* TPACPI_THERMAL_TPEC_* */
TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
TP_EC_FUNCREV = 0xEF, /* ACPI EC Functional revision */
TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */
@ -6481,7 +6482,7 @@ static const struct attribute_group thermal_temp_input8_group = {
static int __init thermal_init(struct ibm_init_struct *iibm) static int __init thermal_init(struct ibm_init_struct *iibm)
{ {
u8 t, ta1, ta2; u8 t, ta1, ta2, ver = 0;
int i; int i;
int acpi_tmp7; int acpi_tmp7;
int res; int res;
@ -6496,7 +6497,14 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
* 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
* non-implemented, thermal sensors return 0x80 when * non-implemented, thermal sensors return 0x80 when
* not available * not available
* The above rule is unfortunately flawed. This has been seen with
* 0xC2 (power supply ID) causing thermal control problems.
* The EC version can be determined by offset 0xEF and at least for
* version 3 the Lenovo firmware team confirmed that registers 0xC0-0xC7
* are not thermal registers.
*/ */
if (!acpi_ec_read(TP_EC_FUNCREV, &ver))
pr_warn("Thinkpad ACPI EC unable to access EC version\n");
ta1 = ta2 = 0; ta1 = ta2 = 0;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
@ -6506,11 +6514,13 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
ta1 = 0; ta1 = 0;
break; break;
} }
if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { if (ver < 3) {
ta2 |= t; if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
} else { ta2 |= t;
ta1 = 0; } else {
break; ta1 = 0;
break;
}
} }
} }
if (ta1 == 0) { if (ta1 == 0) {
@ -6523,9 +6533,12 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
thermal_read_mode = TPACPI_THERMAL_NONE; thermal_read_mode = TPACPI_THERMAL_NONE;
} }
} else { } else {
thermal_read_mode = if (ver >= 3)
(ta2 != 0) ? thermal_read_mode = TPACPI_THERMAL_TPEC_8;
TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; else
thermal_read_mode =
(ta2 != 0) ?
TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
} }
} else if (acpi_tmp7) { } else if (acpi_tmp7) {
if (tpacpi_is_ibm() && if (tpacpi_is_ibm() &&