1 From a26f878abcd0491906b5bbac8dd174f27019e907 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Fri, 24 Nov 2006 11:47:08 -0200
4 Subject: [PATCH 5/28] ACPI: ibm-acpi: Use a enum to select the thermal sensor reading strategy
6 This patch consolidades all decisions regarding the strategy to be used to
7 read thinkpad thermal sensors into a single enum, and refactors the
8 thermal sensor reading code to use a much more readable (and easier to
9 extend) switch() construct, in a separate function.
11 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
13 drivers/acpi/ibm_acpi.c | 90 ++++++++++++++++++++++++++++++++++-------------
14 1 files changed, 65 insertions(+), 25 deletions(-)
16 diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
17 index b81a95d..baf9492 100644
18 --- a/drivers/acpi/ibm_acpi.c
19 +++ b/drivers/acpi/ibm_acpi.c
20 @@ -217,6 +217,17 @@ IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
21 #define IBM_HKEY_HID "IBM0068"
22 #define IBM_PCI_HID "PNP0A03"
24 +enum thermal_access_mode {
25 + IBMACPI_THERMAL_NONE = 0, /* No thermal support */
26 + IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
27 + IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
30 +#define IBMACPI_MAX_THERMAL_SENSORS 8 /* Max thermal sensors supported */
31 +struct ibm_thermal_sensors_struct {
32 + s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
38 @@ -1275,50 +1286,79 @@ static int acpi_ec_write(int i, u8 v)
42 -static int thermal_tmp_supported;
43 -static int thermal_updt_supported;
44 +static enum thermal_access_mode thermal_read_mode;
46 static int thermal_init(void)
48 - /* temperatures not supported on 570, G4x, R30, R31, R32 */
49 - thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
51 - /* 600e/x, 770e, 770x */
52 - thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv");
53 + if (acpi_evalf(ec_handle, NULL, "TMP7", "qv")) {
54 + if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
55 + /* 600e/x, 770e, 770x */
56 + thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
58 + /* Standard ACPI TMPx access, max 8 sensors */
59 + thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
62 + /* temperatures not supported on 570, G4x, R30, R31, R32 */
63 + thermal_read_mode = IBMACPI_THERMAL_NONE;
69 -static int thermal_read(char *p)
70 +static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
74 + char tmpi[] = "TMPi";
76 - if (!thermal_tmp_supported)
77 - len += sprintf(p + len, "temperatures:\tnot supported\n");
80 - char tmpi[] = "TMPi";
85 - if (thermal_updt_supported)
86 - if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
87 + switch (thermal_read_mode) {
88 + case IBMACPI_THERMAL_ACPI_UPDT:
89 + if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
91 + for (i = 0; i < 8; i++) {
93 + if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
95 + s->temp[i] = (t - 2732) * 100;
99 + case IBMACPI_THERMAL_ACPI_TMP07:
100 for (i = 0; i < 8; i++) {
102 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
104 - if (thermal_updt_supported)
105 - tmp[i] = (t - 2732 + 5) / 10;
108 + s->temp[i] = t * 1000;
112 - len += sprintf(p + len,
113 - "temperatures:\t%d %d %d %d %d %d %d %d\n",
114 - tmp[0], tmp[1], tmp[2], tmp[3],
115 - tmp[4], tmp[5], tmp[6], tmp[7]);
116 + case IBMACPI_THERMAL_NONE:
122 +static int thermal_read(char *p)
126 + struct ibm_thermal_sensors_struct t;
128 + n = thermal_get_sensors(&t);
129 + if (unlikely(n < 0))
132 + len += sprintf(p + len, "temperatures:\t");
135 + for (i = 0; i < (n - 1); i++)
136 + len += sprintf(p + len, "%d ", t.temp[i] / 1000);
137 + len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
139 + len += sprintf(p + len, "not supported\n");