Add linux v2.6.20-rc2, as most patches were merged in
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.20-rc2 / 0005-ACPI-ibm-acpi-Use-a-enum-to-select-the-thermal-sensor-reading-strategy.txt
blob9886880836783ef3bb07acd0a8b6bdac3b7c10b5
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>
12 ---
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 */
28 +};
30 +#define IBMACPI_MAX_THERMAL_SENSORS 8  /* Max thermal sensors supported */
31 +struct ibm_thermal_sensors_struct {
32 +       s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
33 +};
35  struct ibm_struct {
36         char *name;
37         char param[32];
38 @@ -1275,50 +1286,79 @@ static int acpi_ec_write(int i, u8 v)
39         return 1;
40  }
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)
47  {
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;
57 +               } else {
58 +                       /* Standard ACPI TMPx access, max 8 sensors */
59 +                       thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
60 +               }
61 +       } else {
62 +               /* temperatures not supported on 570, G4x, R30, R31, R32 */
63 +               thermal_read_mode = IBMACPI_THERMAL_NONE;
64 +       }
66         return 0;
67  }
69 -static int thermal_read(char *p)
70 +static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
71  {
72 -       int len = 0;
73 +       int i, t;
74 +       char tmpi[] = "TMPi";
76 -       if (!thermal_tmp_supported)
77 -               len += sprintf(p + len, "temperatures:\tnot supported\n");
78 -       else {
79 -               int i, t;
80 -               char tmpi[] = "TMPi";
81 -               s8 tmp[8];
82 +       if (!s)
83 +               return -EINVAL;
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"))
90 +                       return -EIO;
91 +               for (i = 0; i < 8; i++) {
92 +                       tmpi[3] = '0' + i;
93 +                       if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
94                                 return -EIO;
95 +                       s->temp[i] = (t - 2732) * 100;
96 +               }
97 +               return 8;
99 +       case IBMACPI_THERMAL_ACPI_TMP07:
100                 for (i = 0; i < 8; i++) {
101                         tmpi[3] = '0' + i;
102                         if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
103                                 return -EIO;
104 -                       if (thermal_updt_supported)
105 -                               tmp[i] = (t - 2732 + 5) / 10;
106 -                       else
107 -                               tmp[i] = t;
108 +                       s->temp[i] = t * 1000;
109                 }
110 +               return 8;
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:
117 +       default:
118 +               return 0;
119         }
122 +static int thermal_read(char *p)
124 +       int len = 0;
125 +       int n, i;
126 +       struct ibm_thermal_sensors_struct t;
128 +       n = thermal_get_sensors(&t);
129 +       if (unlikely(n < 0))
130 +               return n;
132 +       len += sprintf(p + len, "temperatures:\t");
134 +       if (n > 0) {
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);
138 +       } else
139 +               len += sprintf(p + len, "not supported\n");
141         return len;
143 -- 
144 1.4.4.2