aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ibm_acpi.c
diff options
context:
space:
mode:
authorHenrique de Moraes Holschuh <hmh@hmh.eng.br>2006-11-24 08:47:08 -0500
committerLen Brown <len.brown@intel.com>2006-12-07 01:38:38 -0500
commita26f878abcd0491906b5bbac8dd174f27019e907 (patch)
tree0453e9e9cd51bb35f049a8cd87bfaeb7a30ecce3 /drivers/acpi/ibm_acpi.c
parent8d29726434697a5ed08d4e0dfba9399a098922f4 (diff)
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>
Diffstat (limited to 'drivers/acpi/ibm_acpi.c')
-rw-r--r--drivers/acpi/ibm_acpi.c90
1 files changed, 65 insertions, 25 deletions
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index b81a95d2067c..baf9492f0a79 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -217,6 +217,17 @@ IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
217#define IBM_HKEY_HID "IBM0068" 217#define IBM_HKEY_HID "IBM0068"
218#define IBM_PCI_HID "PNP0A03" 218#define IBM_PCI_HID "PNP0A03"
219 219
220enum thermal_access_mode {
221 IBMACPI_THERMAL_NONE = 0, /* No thermal support */
222 IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
223 IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
224};
225
226#define IBMACPI_MAX_THERMAL_SENSORS 8 /* Max thermal sensors supported */
227struct ibm_thermal_sensors_struct {
228 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
229};
230
220struct ibm_struct { 231struct ibm_struct {
221 char *name; 232 char *name;
222 char param[32]; 233 char param[32];
@@ -1275,50 +1286,79 @@ static int acpi_ec_write(int i, u8 v)
1275 return 1; 1286 return 1;
1276} 1287}
1277 1288
1278static int thermal_tmp_supported; 1289static enum thermal_access_mode thermal_read_mode;
1279static int thermal_updt_supported;
1280 1290
1281static int thermal_init(void) 1291static int thermal_init(void)
1282{ 1292{
1283 /* temperatures not supported on 570, G4x, R30, R31, R32 */ 1293 if (acpi_evalf(ec_handle, NULL, "TMP7", "qv")) {
1284 thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); 1294 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1285 1295 /* 600e/x, 770e, 770x */
1286 /* 600e/x, 770e, 770x */ 1296 thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
1287 thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv"); 1297 } else {
1298 /* Standard ACPI TMPx access, max 8 sensors */
1299 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1300 }
1301 } else {
1302 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1303 thermal_read_mode = IBMACPI_THERMAL_NONE;
1304 }
1288 1305
1289 return 0; 1306 return 0;
1290} 1307}
1291 1308
1292static int thermal_read(char *p) 1309static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1293{ 1310{
1294 int len = 0; 1311 int i, t;
1312 char tmpi[] = "TMPi";
1295 1313
1296 if (!thermal_tmp_supported) 1314 if (!s)
1297 len += sprintf(p + len, "temperatures:\tnot supported\n"); 1315 return -EINVAL;
1298 else {
1299 int i, t;
1300 char tmpi[] = "TMPi";
1301 s8 tmp[8];
1302 1316
1303 if (thermal_updt_supported) 1317 switch (thermal_read_mode) {
1304 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) 1318 case IBMACPI_THERMAL_ACPI_UPDT:
1319 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1320 return -EIO;
1321 for (i = 0; i < 8; i++) {
1322 tmpi[3] = '0' + i;
1323 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1305 return -EIO; 1324 return -EIO;
1325 s->temp[i] = (t - 2732) * 100;
1326 }
1327 return 8;
1306 1328
1329 case IBMACPI_THERMAL_ACPI_TMP07:
1307 for (i = 0; i < 8; i++) { 1330 for (i = 0; i < 8; i++) {
1308 tmpi[3] = '0' + i; 1331 tmpi[3] = '0' + i;
1309 if (!acpi_evalf(ec_handle, &t, tmpi, "d")) 1332 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1310 return -EIO; 1333 return -EIO;
1311 if (thermal_updt_supported) 1334 s->temp[i] = t * 1000;
1312 tmp[i] = (t - 2732 + 5) / 10;
1313 else
1314 tmp[i] = t;
1315 } 1335 }
1336 return 8;
1316 1337
1317 len += sprintf(p + len, 1338 case IBMACPI_THERMAL_NONE:
1318 "temperatures:\t%d %d %d %d %d %d %d %d\n", 1339 default:
1319 tmp[0], tmp[1], tmp[2], tmp[3], 1340 return 0;
1320 tmp[4], tmp[5], tmp[6], tmp[7]);
1321 } 1341 }
1342}
1343
1344static int thermal_read(char *p)
1345{
1346 int len = 0;
1347 int n, i;
1348 struct ibm_thermal_sensors_struct t;
1349
1350 n = thermal_get_sensors(&t);
1351 if (unlikely(n < 0))
1352 return n;
1353
1354 len += sprintf(p + len, "temperatures:\t");
1355
1356 if (n > 0) {
1357 for (i = 0; i < (n - 1); i++)
1358 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1359 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1360 } else
1361 len += sprintf(p + len, "not supported\n");
1322 1362
1323 return len; 1363 return len;
1324} 1364}