--- acpi-2.6.8-rc/drivers/acpi/thermal.c.orig 2004-07-15 13:28:40.678388104 +0800 +++ acpi-2.6.8-rc/drivers/acpi/thermal.c 2004-07-15 14:26:35.697104960 +0800 @@ -60,6 +60,7 @@ #define ACPI_THERMAL_NOTIFY_HOT 0xF1 #define ACPI_THERMAL_MODE_ACTIVE 0x00 #define ACPI_THERMAL_MODE_PASSIVE 0x01 +#define ACPI_THERMAL_MODE_CRT 0xff #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff" #define ACPI_THERMAL_MAX_ACTIVE 10 @@ -289,13 +290,6 @@ acpi_thermal_set_cooling_mode ( status = acpi_get_handle(tz->handle, "_SCP", &handle); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); - status = acpi_get_handle(tz->handle, "_PSV", &handle); - if(!ACPI_FAILURE(status)) { - tz->cooling_mode = 1; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n", - mode?"passive":"active")); - return_VALUE(0); - } return_VALUE(-ENODEV); } @@ -315,6 +309,43 @@ acpi_thermal_set_cooling_mode ( static int +acpi_thermal_check_cooling_mode ( + struct acpi_thermal *tz) +{ + int i,l = -1; + + if (!tz) + return -1; + + for (i = 0; i< ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!(tz->trips.active[i].flags.valid)) + break; + l = i; + } + + if ((l < 0) && !tz->trips.passive.flags.valid) { + tz->cooling_mode = ACPI_THERMAL_MODE_CRT; + goto out; + } + if ((l >= 0) && tz->trips.passive.flags.valid) { + if (tz->trips.passive.temperature > tz->trips.active[l].temperature) + tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE; + else + tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE; + goto out; + } + if ((l < 0) && tz->trips.passive.flags.valid) { + tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE; + goto out; + } + if ((l >=0) && !tz->trips.passive.flags.valid) + tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE; + +out: + return 0; +} + +static int acpi_thermal_get_trip_points ( struct acpi_thermal *tz) { @@ -851,10 +882,14 @@ static int acpi_thermal_trip_seq_show(st if (tz->trips.critical.flags.valid) seq_printf(seq, "critical (S5): %ld C\n", KELVIN_TO_CELSIUS(tz->trips.critical.temperature)); + else + seq_printf(seq, "critical (S5): \n"); if (tz->trips.hot.flags.valid) seq_printf(seq, "hot (S4): %ld C\n", KELVIN_TO_CELSIUS(tz->trips.hot.temperature)); + else + seq_printf(seq, "hot (S4): \n"); if (tz->trips.passive.flags.valid) { seq_printf(seq, "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", @@ -867,6 +902,8 @@ static int acpi_thermal_trip_seq_show(st seq_printf(seq, "0x%p ", tz->trips.passive.devices.handles[j]); } seq_puts(seq, "\n"); + } else { + seq_printf(seq, "passive: \n"); } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { @@ -880,6 +917,9 @@ static int acpi_thermal_trip_seq_show(st seq_puts(seq, "\n"); } + if (i == 0) + seq_printf(seq, "active: \n"); + end: return 0; } @@ -927,15 +967,27 @@ acpi_thermal_write_trip_points ( return_VALUE(-EINVAL); } - tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical); - tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot); - tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive); + if ( tz->trips.critical.flags.valid ) + tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical); + if ( tz->trips.hot.flags.valid ) + tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot); + if ( tz->trips.passive.flags.valid ) + tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive); for (i = 0; i < num - 3; i++) { if (!(tz->trips.active[i].flags.valid)) break; tz->trips.active[i].temperature = CELSIUS_TO_KELVIN(active[i]); } + acpi_thermal_check_cooling_mode(tz); + if ( tz->flags.cooling_mode && (tz->cooling_mode != ACPI_THERMAL_MODE_CRT)) { + i = acpi_thermal_set_cooling_mode(tz,tz->cooling_mode); + if (i) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Set cooling mode failed!\n")); + return_VALUE(-EFAULT); + } + } + return_VALUE(count); } @@ -950,12 +1002,14 @@ static int acpi_thermal_cooling_seq_show goto end; if (!tz->flags.cooling_mode) { - seq_puts(seq, "\n"); - goto end; + seq_puts(seq, "\n"); } - seq_printf(seq, "cooling mode: %s\n", - tz->cooling_mode?"passive":"active"); + if ( tz->cooling_mode == ACPI_THERMAL_MODE_CRT ) + seq_printf(seq, "cooling mode: critical\n"); + else + seq_printf(seq, "cooling mode: %s\n", + tz->cooling_mode?"passive":"active"); end: return 0; @@ -997,6 +1051,8 @@ acpi_thermal_write_cooling_mode ( if (result) return_VALUE(result); + acpi_thermal_check(tz); + return_VALUE(count); } @@ -1201,6 +1257,7 @@ acpi_thermal_notify ( case ACPI_THERMAL_NOTIFY_THRESHOLDS: acpi_thermal_get_trip_points(tz); acpi_thermal_check(tz); + acpi_thermal_check_cooling_mode(tz); acpi_bus_generate_event(device, event, 0); break; case ACPI_THERMAL_NOTIFY_DEVICES: @@ -1234,16 +1291,22 @@ acpi_thermal_get_info ( if (result) return_VALUE(result); - /* Set the cooling mode [_SCP] to active cooling (default) */ - result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); - if (!result) - tz->flags.cooling_mode = 1; - /* Get trip points [_CRT, _PSV, etc.] (required) */ result = acpi_thermal_get_trip_points(tz); if (result) return_VALUE(result); + /* Set the cooling mode [_SCP] to active cooling (default) */ + result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); + if (!result) + tz->flags.cooling_mode = 1; + else { + /* Oh,we have not _SCP method. + Generally check cooling_mode by _ACx, _PSV,spec 12.2*/ + tz->flags.cooling_mode = 0; + acpi_thermal_check_cooling_mode(tz); + } + /* Get default polling frequency [_TZP] (optional) */ if (tzp) tz->polling_frequency = tzp;