Add patches accepted for 2.6.22-rc1 (not released yet)
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.22-rc1 / 0031-ACPI-thinkpad-acpi-cleanup-thermal-subdriver-for-s.patch
blobe7fb948be66f536035f581b11293c2a0f92ec142
1 From 04cc862c1893a055ab1117fa6f3aa0886c0ba032 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Sat, 21 Apr 2007 11:08:43 -0300
4 Subject: ACPI: thinkpad-acpi: cleanup thermal subdriver for sysfs conversion
6 Clean-up the thermal subdriver for sysfs conversion. Make thermal_get_*
7 reentrancy-safe while at it, and add the missing thermal_read_mode variable
8 to the header file.
10 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
11 Signed-off-by: Len Brown <len.brown@intel.com>
12 ---
13 drivers/misc/thinkpad_acpi.c | 79 ++++++++++++++++++++++++++++--------------
14 drivers/misc/thinkpad_acpi.h | 8 ++++
15 2 files changed, 61 insertions(+), 26 deletions(-)
17 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
18 index 8829d3c..e9aec87 100644
19 --- a/drivers/misc/thinkpad_acpi.c
20 +++ b/drivers/misc/thinkpad_acpi.c
21 @@ -1818,13 +1818,13 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
23 ta1 = ta2 = 0;
24 for (i = 0; i < 8; i++) {
25 - if (likely(acpi_ec_read(0x78 + i, &t))) {
26 + if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
27 ta1 |= t;
28 } else {
29 ta1 = 0;
30 break;
32 - if (likely(acpi_ec_read(0xC0 + i, &t))) {
33 + if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
34 ta2 |= t;
35 } else {
36 ta1 = 0;
37 @@ -1869,57 +1869,84 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
38 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
41 -static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
42 +/* idx is zero-based */
43 +static int thermal_get_sensor(int idx, s32 *value)
45 - int i, t;
46 + int t;
47 s8 tmp;
48 - char tmpi[] = "TMPi";
49 + char tmpi[5];
51 - if (!s)
52 - return -EINVAL;
53 + t = TP_EC_THERMAL_TMP0;
55 switch (thermal_read_mode) {
56 #if TPACPI_MAX_THERMAL_SENSORS >= 16
57 case TPACPI_THERMAL_TPEC_16:
58 - for (i = 0; i < 8; i++) {
59 - if (!acpi_ec_read(0xC0 + i, &tmp))
60 - return -EIO;
61 - s->temp[i + 8] = tmp * 1000;
62 + if (idx >= 8 && idx <= 15) {
63 + t = TP_EC_THERMAL_TMP8;
64 + idx -= 8;
66 /* fallthrough */
67 #endif
68 case TPACPI_THERMAL_TPEC_8:
69 - for (i = 0; i < 8; i++) {
70 - if (!acpi_ec_read(0x78 + i, &tmp))
71 + if (idx <= 7) {
72 + if (!acpi_ec_read(t + idx, &tmp))
73 return -EIO;
74 - s->temp[i] = tmp * 1000;
75 + *value = tmp * 1000;
76 + return 0;
78 - return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8;
79 + break;
81 case TPACPI_THERMAL_ACPI_UPDT:
82 - if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
83 - return -EIO;
84 - for (i = 0; i < 8; i++) {
85 - tmpi[3] = '0' + i;
86 + if (idx <= 7) {
87 + snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
88 + if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
89 + return -EIO;
90 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
91 return -EIO;
92 - s->temp[i] = (t - 2732) * 100;
93 + *value = (t - 2732) * 100;
94 + return 0;
96 - return 8;
97 + break;
99 case TPACPI_THERMAL_ACPI_TMP07:
100 - for (i = 0; i < 8; i++) {
101 - tmpi[3] = '0' + i;
102 + if (idx <= 7) {
103 + snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
104 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
105 return -EIO;
106 - s->temp[i] = t * 1000;
107 + *value = t * 1000;
108 + return 0;
110 - return 8;
111 + break;
113 case TPACPI_THERMAL_NONE:
114 default:
115 - return 0;
116 + return -ENOSYS;
119 + return -EINVAL;
122 +static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
124 + int res, i;
125 + int n;
127 + n = 8;
128 + i = 0;
130 + if (!s)
131 + return -EINVAL;
133 + if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
134 + n = 16;
136 + for(i = 0 ; i < n; i++) {
137 + res = thermal_get_sensor(i, &s->temp[i]);
138 + if (res)
139 + return res;
142 + return n;
145 static int thermal_read(char *p)
146 diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
147 index fb0abb0..6432b28 100644
148 --- a/drivers/misc/thinkpad_acpi.h
149 +++ b/drivers/misc/thinkpad_acpi.h
150 @@ -427,12 +427,20 @@ enum thermal_access_mode {
151 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
154 +enum { /* TPACPI_THERMAL_TPEC_* */
155 + TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
156 + TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
159 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
160 struct ibm_thermal_sensors_struct {
161 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
164 +static enum thermal_access_mode thermal_read_mode;
166 static int thermal_init(struct ibm_init_struct *iibm);
167 +static int thermal_get_sensor(int idx, s32 *value);
168 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
169 static int thermal_read(char *p);
172 1.5.1