Skip to content

Commit

Permalink
Merge pull request #30 from plundstr/master
Browse files Browse the repository at this point in the history
Added thermal sensor re-enable
  • Loading branch information
Pekka Lundstrom committed Oct 14, 2013
2 parents ad6f534 + 93cdd88 commit 96fb420
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 48 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,5 +1,5 @@
# Package name and version
AC_INIT(dsme, 0.62.23)
AC_INIT(dsme, 0.62.24)

AM_INIT_AUTOMAKE

Expand Down
38 changes: 19 additions & 19 deletions modules/thermalmanager.c
Expand Up @@ -126,7 +126,7 @@ static void send_thermal_indication(void)
thermalmanager_state_change_ind);
dsme_dbus_message_append_string(sig, current_status_name());
dsme_dbus_signal_emit(sig);
dsme_log(LOG_NOTICE, "thermal status: %s", current_status_name());
dsme_log(LOG_NOTICE, "thermalmanager: Device thermal status: %s", current_status_name());
}

/* then broadcast an indication internally */
Expand All @@ -136,11 +136,11 @@ static void send_thermal_indication(void)
if (current_status == THERMAL_STATUS_FATAL) {
send_overheat_status(true);
overheated = true;
dsme_log(LOG_CRIT, "Device overheated");
dsme_log(LOG_CRIT, "thermalmanager: Device overheated");
} else if (overheated) {
send_overheat_status(false);
overheated = false;
dsme_log(LOG_NOTICE, "Device no longer overheated");
dsme_log(LOG_NOTICE, "thermalmanager: Device no longer overheated");
}
}
}
Expand All @@ -149,7 +149,7 @@ static void send_temperature_request(thermal_object_t* thermal_object)
{
if (!thermal_object->request_pending) {
dsme_log(LOG_DEBUG,
"requesting %s temperature",
"thermalmanager: requesting %s temperature",
thermal_object->conf->name);
thermal_object->request_pending = true;
if (!thermal_object->conf->request_temperature(
Expand All @@ -158,12 +158,12 @@ static void send_temperature_request(thermal_object_t* thermal_object)
{
thermal_object->request_pending = false;
dsme_log(LOG_DEBUG,
"error requesting %s temperature",
"thermalmanager: error requesting %s temperature",
thermal_object->conf->name);
}
} else {
dsme_log(LOG_DEBUG,
"still waiting for %s temperature",
"thermalmanager: still waiting for %s temperature",
thermal_object->conf->name);
}
}
Expand All @@ -175,7 +175,7 @@ static void receive_temperature_response(thermal_object_t* thermal_object,

if (temperature == -1) {
dsme_log(LOG_DEBUG,
"%s temperature request failed",
"thermalmanager: %s temperature request failed",
thermal_object->conf->name);
return;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ static void receive_temperature_response(thermal_object_t* thermal_object,

#ifndef DSME_THERMAL_LOGGING
dsme_log(LOG_DEBUG,
"%s temperature: %d %s",
"thermalmanager: %s temperature: %d %s",
thermal_object->conf->name,
temperature,
thermal_status_name[thermal_object->status]);
Expand Down Expand Up @@ -264,7 +264,7 @@ static void thermal_object_polling_interval_expired(void* object)
void dsme_register_thermal_object(thermal_object_t* thermal_object)
{
dsme_log(LOG_DEBUG,
"%s (%s)", __FUNCTION__,
"thermalmanager: %s (%s)", __FUNCTION__,
thermal_object->conf->name);

enter_module(this_module);
Expand All @@ -284,7 +284,7 @@ void dsme_register_thermal_object(thermal_object_t* thermal_object)

void dsme_unregister_thermal_object(thermal_object_t* thermal_object)
{
dsme_log(LOG_DEBUG, "%s(%s)", __FUNCTION__, thermal_object->conf->name);
dsme_log(LOG_DEBUG, "thermalmanager: %s(%s)", __FUNCTION__, thermal_object->conf->name);
// TODO
}

Expand All @@ -309,7 +309,7 @@ DSME_HANDLER(DSM_MSGTYPE_WAKEUP, client, msg)
thermal_object_t* thermal_object = (thermal_object_t*)(msg->data);

dsme_log(LOG_DEBUG,
"check thermal object '%s'",
"thermalmanager: check thermal object '%s'",
thermal_object->conf->name);
thermal_object_polling_interval_expired(thermal_object);
}
Expand All @@ -331,7 +331,7 @@ DSME_HANDLER(DSM_MSGTYPE_DBUS_DISCONNECT, client, msg)
DSME_HANDLER(DSM_MSGTYPE_SET_TA_TEST_MODE, client, msg)
{
is_in_ta_test = true;
dsme_log(LOG_NOTICE, "thermal manager: set TA test mode");
dsme_log(LOG_NOTICE, "thermalmanager: set TA test mode");
}
#endif

Expand Down Expand Up @@ -380,7 +380,7 @@ static FILE* thermal_tuning_file(const char* thermal_object_name)
DSME_THERMAL_TUNING_CONF_PATH,
thermal_object_name);

dsme_log(LOG_DEBUG, "trying to open %s for thermal tuning values", name);
dsme_log(LOG_DEBUG, "thermalmanager: trying to open %s for thermal tuning values", name);

return fopen(name, "r");
}
Expand Down Expand Up @@ -429,7 +429,7 @@ static bool thermal_object_config_read(
*/
new_config.state[i].mintime = new_config.state[i].maxtime/2;
} else {
dsme_log(LOG_ERR, "syntax error in thermal tuning on line %d", i+1);
dsme_log(LOG_ERR, "thermalmanager: syntax error in thermal tuning on line %d", i+1);
break;
}
}
Expand All @@ -448,18 +448,18 @@ static void thermal_object_try_to_read_config(thermal_object_t* thermal_object)

if (thermal_object_config_read(thermal_object->conf, f)) {
dsme_log(LOG_NOTICE,
"Read thermal tuning file for %s",
"thermalmanager: Read thermal tuning file for %s",
thermal_object->conf->name);
} else {
dsme_log(LOG_NOTICE,
"Thermal tuning file for %s discarded. Using default values",
"thermalmanager: Thermal tuning file for %s discarded. Using default values",
thermal_object->conf->name);
}

fclose(f);
} else {
dsme_log(LOG_NOTICE,
"No thermal tuning file for %s. Using default values",
"thermalmanager: No thermal tuning file for %s. Using default values",
thermal_object->conf->name);
}
}
Expand Down Expand Up @@ -513,7 +513,7 @@ static void log_temperature(int temperature, const thermal_object_t* thermal_obj
if (!log_file) {
if (!(log_file = fopen(DSME_THERMAL_LOG_PATH, "a"))) {
dsme_log(LOG_ERR,
"Error opening thermal log " DSME_THERMAL_LOG_PATH ": %s",
"thermalmanager: Error opening thermal log " DSME_THERMAL_LOG_PATH ": %s",
strerror(errno));
return;
}
Expand All @@ -536,7 +536,7 @@ static void log_temperature(int temperature, const thermal_object_t* thermal_obj
temperature,
status_string(thermal_object->status));
fflush(log_file);
dsme_log(LOG_DEBUG,"%s %d C %s", thermal_object->conf->name,
dsme_log(LOG_DEBUG,"thermalmanager: %s %d C %s", thermal_object->conf->name,
temperature, status_string(thermal_object->status));
}
#endif
69 changes: 43 additions & 26 deletions modules/thermalsensor_hw.c
Expand Up @@ -31,6 +31,10 @@
#include <stdio.h>
#include <stdlib.h>

/* TODO: These should be changed to use statefs once we have it */
#define CORE_SENSOR_MODE "/sys/devices/virtual/thermal/thermal_zone9/mode"
#define CORE_SENSOR_TEMP "/sys/devices/virtual/thermal/thermal_zone9/temp"
#define BATTERY_TEMP "/sys/class/power_supply/battery/temp"

static bool read_temperature(const char *path, int *temperature)
{
Expand All @@ -45,33 +49,13 @@ static bool read_temperature(const char *path, int *temperature)
ret = true;
}
fclose(f);
} else {
}
if (!ret) {
dsme_log(LOG_DEBUG, "thermal: read of %s FAILED", path);
}
return ret;
}

/* Get temp from sensor 9 */
/* TODO: This should be changed to use statefs once we have it */

#define CORE_SENSOR_MODE "/sys/devices/virtual/thermal/thermal_zone9/mode"
#define CORE_SENSOR_TEMP "/sys/devices/virtual/thermal/thermal_zone9/temp"

extern bool dsme_hw_get_core_temperature(thermal_object_t* thermal_object,
temperature_handler_fn_t* callback)
{
int temperature;

// dsme_log(LOG_DEBUG, "thermal: %s", __FUNCTION__);

if (read_temperature(CORE_SENSOR_TEMP, &temperature)) {
if (callback)
callback(thermal_object, temperature);
return true;
}
return false;
}

static bool enable_hw_core_temp_sensor(void)
{
FILE* f;
Expand All @@ -85,12 +69,45 @@ static bool enable_hw_core_temp_sensor(void)
ret = true;
}
fclose(f);
} else {
}
if (!ret) {
dsme_log(LOG_ERR, "FAILED enabling thermal sensor %s", CORE_SENSOR_MODE);
}
return ret;
}

extern bool dsme_hw_get_core_temperature(thermal_object_t* thermal_object,
temperature_handler_fn_t* callback)
{
int temperature;
bool got_temperature = false;

// dsme_log(LOG_DEBUG, "thermal: %s", __FUNCTION__);


if (read_temperature(CORE_SENSOR_TEMP, &temperature)) {
got_temperature = true;
} else {
/* Read failed, that could be because after deep sleep or transfer
* between actdead/user state, sensor is disabled and we need to re-enabe it.
* Try one more time
*/
dsme_log(LOG_DEBUG, "thermal: First read failed, trying to (re)enable");
if (enable_hw_core_temp_sensor() &&
read_temperature(CORE_SENSOR_TEMP, &temperature)) {
dsme_log(LOG_DEBUG, "thermal: On second try it was ok");
got_temperature = true;
}
}
if (got_temperature) {
if (callback)
callback(thermal_object, temperature);
} else {
dsme_log(LOG_WARNING, "thermal: Can't get core temperature readings");
}
return got_temperature;
}

/* Does our HW support this temp reading ? */
extern bool dsme_hw_supports_core_temp(void)
{
Expand All @@ -114,9 +131,9 @@ extern bool dsme_hw_get_battery_temperature(thermal_object_t* thermal_ob

// dsme_log(LOG_DEBUG, "thermal: %s", __FUNCTION__);

if (read_temperature("/sys/class/power_supply/battery/temp", &temperature)) {
/* We get the temp in one tens */
temperature = (temperature + 5 ) / 10;
if (read_temperature(BATTERY_TEMP, &temperature)) {
/* We get the temp in one tens */
temperature = (temperature + 5 ) / 10;
if (callback)
callback(thermal_object, temperature);
return true;
Expand Down
2 changes: 1 addition & 1 deletion rpm/dsme.spec
Expand Up @@ -13,7 +13,7 @@ Name: dsme
# << macros

Summary: Device State Management Entity
Version: 0.62.23
Version: 0.62.24
Release: 0
Group: System/System Control
License: LGPLv2+
Expand Down
2 changes: 1 addition & 1 deletion rpm/dsme.yaml
@@ -1,6 +1,6 @@
Name: dsme
Summary: Device State Management Entity
Version: 0.62.23
Version: 0.62.24
Release: 0
Group: System/System Control
License: LGPLv2+
Expand Down

0 comments on commit 96fb420

Please sign in to comment.