ACPI: ibm-acpi: Use a enum to select the thermal sensor reading strategy

This patch consolidades all decisions regarding the strategy to be used to
read thinkpad thermal sensors into a single enum, and refactors the
thermal sensor reading code to use a much more readable (and easier to
extend) switch() construct, in a separate function.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
This commit is contained in:
Henrique de Moraes Holschuh 2006-11-24 11:47:08 -02:00 committed by Len Brown
parent 8d29726434
commit a26f878abc

View File

@ -217,6 +217,17 @@ IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
#define IBM_HKEY_HID "IBM0068" #define IBM_HKEY_HID "IBM0068"
#define IBM_PCI_HID "PNP0A03" #define IBM_PCI_HID "PNP0A03"
enum thermal_access_mode {
IBMACPI_THERMAL_NONE = 0, /* No thermal support */
IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
};
#define IBMACPI_MAX_THERMAL_SENSORS 8 /* Max thermal sensors supported */
struct ibm_thermal_sensors_struct {
s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
};
struct ibm_struct { struct ibm_struct {
char *name; char *name;
char param[32]; char param[32];
@ -1275,50 +1286,79 @@ static int acpi_ec_write(int i, u8 v)
return 1; return 1;
} }
static int thermal_tmp_supported; static enum thermal_access_mode thermal_read_mode;
static int thermal_updt_supported;
static int thermal_init(void) static int thermal_init(void)
{ {
/* temperatures not supported on 570, G4x, R30, R31, R32 */ if (acpi_evalf(ec_handle, NULL, "TMP7", "qv")) {
thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
/* 600e/x, 770e, 770x */ /* 600e/x, 770e, 770x */
thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv"); thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
} else {
/* Standard ACPI TMPx access, max 8 sensors */
thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
}
} else {
/* temperatures not supported on 570, G4x, R30, R31, R32 */
thermal_read_mode = IBMACPI_THERMAL_NONE;
}
return 0; return 0;
} }
static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
{
int i, t;
char tmpi[] = "TMPi";
if (!s)
return -EINVAL;
switch (thermal_read_mode) {
case IBMACPI_THERMAL_ACPI_UPDT:
if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
return -EIO;
for (i = 0; i < 8; i++) {
tmpi[3] = '0' + i;
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
return -EIO;
s->temp[i] = (t - 2732) * 100;
}
return 8;
case IBMACPI_THERMAL_ACPI_TMP07:
for (i = 0; i < 8; i++) {
tmpi[3] = '0' + i;
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
return -EIO;
s->temp[i] = t * 1000;
}
return 8;
case IBMACPI_THERMAL_NONE:
default:
return 0;
}
}
static int thermal_read(char *p) static int thermal_read(char *p)
{ {
int len = 0; int len = 0;
int n, i;
struct ibm_thermal_sensors_struct t;
if (!thermal_tmp_supported) n = thermal_get_sensors(&t);
len += sprintf(p + len, "temperatures:\tnot supported\n"); if (unlikely(n < 0))
else { return n;
int i, t;
char tmpi[] = "TMPi";
s8 tmp[8];
if (thermal_updt_supported) len += sprintf(p + len, "temperatures:\t");
if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
return -EIO;
for (i = 0; i < 8; i++) { if (n > 0) {
tmpi[3] = '0' + i; for (i = 0; i < (n - 1); i++)
if (!acpi_evalf(ec_handle, &t, tmpi, "d")) len += sprintf(p + len, "%d ", t.temp[i] / 1000);
return -EIO; len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
if (thermal_updt_supported) } else
tmp[i] = (t - 2732 + 5) / 10; len += sprintf(p + len, "not supported\n");
else
tmp[i] = t;
}
len += sprintf(p + len,
"temperatures:\t%d %d %d %d %d %d %d %d\n",
tmp[0], tmp[1], tmp[2], tmp[3],
tmp[4], tmp[5], tmp[6], tmp[7]);
}
return len; return len;
} }