mirror of
https://github.com/adulau/aha.git
synced 2025-01-04 23:23:18 +00:00
ACPI: thinkpad-acpi: cleanup thermal subdriver for sysfs conversion
Clean-up the thermal subdriver for sysfs conversion. Make thermal_get_* reentrancy-safe while at it, and add the missing thermal_read_mode variable to the header file. Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
c9bea99c1a
commit
04cc862c18
2 changed files with 61 additions and 26 deletions
|
@ -1818,13 +1818,13 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
|
||||||
|
|
||||||
ta1 = ta2 = 0;
|
ta1 = ta2 = 0;
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
if (likely(acpi_ec_read(0x78 + i, &t))) {
|
if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
|
||||||
ta1 |= t;
|
ta1 |= t;
|
||||||
} else {
|
} else {
|
||||||
ta1 = 0;
|
ta1 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (likely(acpi_ec_read(0xC0 + i, &t))) {
|
if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
|
||||||
ta2 |= t;
|
ta2 |= t;
|
||||||
} else {
|
} else {
|
||||||
ta1 = 0;
|
ta1 = 0;
|
||||||
|
@ -1869,57 +1869,84 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
|
||||||
return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
|
return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
|
/* idx is zero-based */
|
||||||
|
static int thermal_get_sensor(int idx, s32 *value)
|
||||||
{
|
{
|
||||||
int i, t;
|
int t;
|
||||||
s8 tmp;
|
s8 tmp;
|
||||||
char tmpi[] = "TMPi";
|
char tmpi[5];
|
||||||
|
|
||||||
if (!s)
|
t = TP_EC_THERMAL_TMP0;
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
switch (thermal_read_mode) {
|
switch (thermal_read_mode) {
|
||||||
#if TPACPI_MAX_THERMAL_SENSORS >= 16
|
#if TPACPI_MAX_THERMAL_SENSORS >= 16
|
||||||
case TPACPI_THERMAL_TPEC_16:
|
case TPACPI_THERMAL_TPEC_16:
|
||||||
for (i = 0; i < 8; i++) {
|
if (idx >= 8 && idx <= 15) {
|
||||||
if (!acpi_ec_read(0xC0 + i, &tmp))
|
t = TP_EC_THERMAL_TMP8;
|
||||||
return -EIO;
|
idx -= 8;
|
||||||
s->temp[i + 8] = tmp * 1000;
|
|
||||||
}
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
#endif
|
#endif
|
||||||
case TPACPI_THERMAL_TPEC_8:
|
case TPACPI_THERMAL_TPEC_8:
|
||||||
for (i = 0; i < 8; i++) {
|
if (idx <= 7) {
|
||||||
if (!acpi_ec_read(0x78 + i, &tmp))
|
if (!acpi_ec_read(t + idx, &tmp))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
s->temp[i] = tmp * 1000;
|
*value = tmp * 1000;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8;
|
break;
|
||||||
|
|
||||||
case TPACPI_THERMAL_ACPI_UPDT:
|
case TPACPI_THERMAL_ACPI_UPDT:
|
||||||
|
if (idx <= 7) {
|
||||||
|
snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
|
||||||
if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
|
if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
for (i = 0; i < 8; i++) {
|
|
||||||
tmpi[3] = '0' + i;
|
|
||||||
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
|
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
s->temp[i] = (t - 2732) * 100;
|
*value = (t - 2732) * 100;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return 8;
|
break;
|
||||||
|
|
||||||
case TPACPI_THERMAL_ACPI_TMP07:
|
case TPACPI_THERMAL_ACPI_TMP07:
|
||||||
for (i = 0; i < 8; i++) {
|
if (idx <= 7) {
|
||||||
tmpi[3] = '0' + i;
|
snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
|
||||||
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
|
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
s->temp[i] = t * 1000;
|
*value = t * 1000;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return 8;
|
break;
|
||||||
|
|
||||||
case TPACPI_THERMAL_NONE:
|
case TPACPI_THERMAL_NONE:
|
||||||
default:
|
default:
|
||||||
return 0;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
|
||||||
|
{
|
||||||
|
int res, i;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = 8;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
|
||||||
|
n = 16;
|
||||||
|
|
||||||
|
for(i = 0 ; i < n; i++) {
|
||||||
|
res = thermal_get_sensor(i, &s->temp[i]);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int thermal_read(char *p)
|
static int thermal_read(char *p)
|
||||||
|
|
|
@ -427,12 +427,20 @@ enum thermal_access_mode {
|
||||||
TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
|
TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum { /* TPACPI_THERMAL_TPEC_* */
|
||||||
|
TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
|
||||||
|
TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
|
||||||
|
};
|
||||||
|
|
||||||
#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
|
#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
|
||||||
struct ibm_thermal_sensors_struct {
|
struct ibm_thermal_sensors_struct {
|
||||||
s32 temp[TPACPI_MAX_THERMAL_SENSORS];
|
s32 temp[TPACPI_MAX_THERMAL_SENSORS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static enum thermal_access_mode thermal_read_mode;
|
||||||
|
|
||||||
static int thermal_init(struct ibm_init_struct *iibm);
|
static int thermal_init(struct ibm_init_struct *iibm);
|
||||||
|
static int thermal_get_sensor(int idx, s32 *value);
|
||||||
static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
|
static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
|
||||||
static int thermal_read(char *p);
|
static int thermal_read(char *p);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue