Skip to content

Commit

Permalink
Merge pull request #18 from plundstr/master
Browse files Browse the repository at this point in the history
Added thermal sensors for battery and core
  • Loading branch information
Pekka Lundstrom committed Sep 24, 2013
2 parents b9bde7e + b943c0c commit 7e0744b
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 19 deletions.
17 changes: 15 additions & 2 deletions configure.ac
@@ -1,5 +1,5 @@
# Package name and version
AC_INIT(dsme, 0.62.16)
AC_INIT(dsme, 0.62.17)

AM_INIT_AUTOMAKE

Expand Down Expand Up @@ -104,6 +104,19 @@ AS_IF([test "x$enable_memory_thermal_mgmt" != xno],
[AC_DEFINE([DSME_MEMORY_THERMAL_MGMT], [1])])
AM_CONDITIONAL([WANT_MEMORY_THERMAL_MGMT], [test x$enable_memory_thermal_mgmt != xno])

#
# HW thermal mgmt
#
AC_ARG_ENABLE([hw-thermal-mgmt],
[AS_HELP_STRING([--disable-hw-thermal-mgmt],
[disable hw thermal management (libthermalobject_hw)])],
[],
[enable_hw_thermal_mgmt=yes])

AS_IF([test "x$enable_hw_thermal_mgmt" != xno],
[AC_DEFINE([DSME_HW_THERMAL_MGMT], [1])])
AM_CONDITIONAL([WANT_HW_THERMAL_MGMT], [test x$enable_hw_thermal_mgmt != xno])

#
# pwrkeymonitor
#
Expand Down Expand Up @@ -168,7 +181,7 @@ AC_CHECK_LIB([dsme], [dsmesock_init], [AC_MSG_NOTICE([got libdsme])], AC_MSG_FAI

# Check headers
AC_CHECK_HEADERS([arpa/inet.h fcntl.h ftw.h inttypes.h limits.h stdint.h stdlib.h \
string.h strings.h sys/ioctl.h sys/socket.h sys/time.h \
string.h strings.h sys/ioctl.h sys/socket.h sys/time.h time.h \
syslog.h unistd.h utmpx.h])

# Checks for typedefs, structures, and compiler characteristics.
Expand Down
12 changes: 12 additions & 0 deletions modules/Makefile.am
Expand Up @@ -43,6 +43,10 @@ if WANT_MEMORY_THERMAL_MGMT
pkglib_LTLIBRARIES += thermalobject_memory.la
endif

if WANT_HW_THERMAL_MGMT
pkglib_LTLIBRARIES += thermalobject_hw.la
endif

if WANT_POWERON_TIMER
pkglib_LTLIBRARIES += powerontimer.la
endif
Expand Down Expand Up @@ -135,6 +139,14 @@ thermalobject_memory_la_SOURCES = thermalobject_memory.c \
thermalsensor_omap.h
endif

if WANT_HW_THERMAL_MGMT
thermalobject_hw_la_SOURCES = thermalobject_hw.c \
thermalsensor_hw.c \
thermalsensor_hw.h
thermalobject_hw_la_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
thermalobject_hw_la_LIBADD = $(GLIB_LIBS)
endif


if WANT_POWERON_TIMER
powerontimer_la_SOURCES = powerontimer.c \
Expand Down
3 changes: 3 additions & 0 deletions modules/startup.c
Expand Up @@ -84,6 +84,9 @@ const char *modules[] = {
"alarmtracker.so",
"thermalflagger.so",
"thermalmanager.so",
#ifdef DSME_HW_THERMAL_MGMT
"thermalobject_hw.so",
#endif
#ifdef DSME_MEMORY_THERMAL_MGMT
"thermalobject_memory.so",
#endif
Expand Down
33 changes: 20 additions & 13 deletions modules/thermalmanager.c
Expand Up @@ -31,6 +31,9 @@
* - use a single timer for all thermal objects
* i.e. use the shortest interval of all thermal objects
*/

#define _GNU_SOURCE

#include "thermalmanager.h"

#include <iphbd/iphb_internal.h>
Expand Down Expand Up @@ -259,10 +262,15 @@ 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__,
thermal_object->conf->name);

enter_module(this_module);

#ifdef DSME_THERMAL_TUNING
thermal_object = thermal_object_copy(thermal_object);
thermal_object_try_to_read_config(thermal_object);
#endif

// add the thermal object to the list of know thermal objects
Expand All @@ -275,6 +283,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);
// TODO
}

Expand Down Expand Up @@ -386,16 +395,16 @@ static bool thermal_object_config_read(

for (i = 0; i < THERMAL_STATUS_COUNT; ++i) {
if (fscanf(f,
"%d, %d, %d",
"%d, %d, %d, %d",
&new_config.state[i].min,
&new_config.state[i].max,
&new_config.state[i].mintime) != 3)
&new_config.state[i].mintime,
&new_config.state[i].maxtime) != 4)
{
dsme_log(LOG_ERR, "syntax error in thermal tuning on line %d", i+1);
success = false;
break;
}
new_config.state[i].maxtime = new_config.state[i].mintime + 10;
}

if (success) {
Expand All @@ -413,23 +422,19 @@ 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,
"(re)read thermal tuning file for %s;"
" thermal values may have changed",
"Read thermal tuning file for %s",
thermal_object->conf->name);
} else {
dsme_log(LOG_NOTICE,
"thermal tuning file for %s discarded;"
" no change in thermal values",
"Thermal tuning file for %s discarded. Using default values",
thermal_object->conf->name);
}

fclose(f);
#ifndef DSME_THERMAL_LOGGING
} else {
dsme_log(LOG_DEBUG,
"no thermal tuning file for %s; no change in thermal values",
dsme_log(LOG_NOTICE,
"No thermal tuning file for %s. Using default values",
thermal_object->conf->name);
#endif
}
}

Expand Down Expand Up @@ -499,11 +504,13 @@ static void log_temperature(int temperature, const thermal_object_t* thermal_obj
}

fprintf(log_file,
"%d %d %d %s\n",
(int)time(0),
"%d %s %d C %s\n",
now - start_time,
thermal_object->conf->name,
temperature,
status_string(thermal_object->status));
fflush(log_file);
dsme_log(LOG_DEBUG,"%s %d C %s", thermal_object->conf->name,
temperature, status_string(thermal_object->status));
}
#endif
108 changes: 108 additions & 0 deletions modules/thermalobject_hw.c
@@ -0,0 +1,108 @@
/**
@file thermalobject_hw.c
This file implements a thermal object for tracking HW temperatures.
Battery and SOC core temperatures
<p>
Copyright (C) 2013 Jolla ltd
@author Pekka Lundstrom <pekka.lundstrom@jolla.com>
This file is part of Dsme.
Dsme is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License
version 2.1 as published by the Free Software Foundation.
Dsme is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Dsme. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE

#include "thermalmanager.h"
#include "thermalsensor_hw.h"

#include "dsme/modules.h"
#include "dsme/logging.h"

static bool core_registered = false;
static bool battery_registered = false;


/* These are default values that can be overridden by
HW adaptation file /etc/dsme/temp_hw_core
*/
static thermal_object_configuration_t core_thermal_conf = {
"hw_core",
{
/* (min, max], [mintime, maxtime] */
{ -99, 70, 110, 120 }, /* NORMAL */
{ 68, 90, 55, 60 }, /* WARNING */
{ 88, 115, 5, 10 }, /* ALERT */
{ 115, 999, 5, 10 } /* FATAL */
},
dsme_hw_get_core_temperature
};

static thermal_object_t core_thermal_object = {
&core_thermal_conf,
THERMAL_STATUS_NORMAL,
0
};

/* These are default values that can be overridden by
HW adaptation file /etc/dsme/temp_hw_battery
*/
static thermal_object_configuration_t battery_thermal_conf = {
"hw_battery",
{
/* (min, max], [mintime, maxtime] */
{ -99, 57, 110, 120 }, /* NORMAL */
{ 56, 60, 55, 60 }, /* WARNING */
{ 59, 65, 5, 10 }, /* ALERT */
{ 65, 99, 5, 10 }, /* FATAL */
},
dsme_hw_get_battery_temperature
};

static thermal_object_t battery_thermal_object = {
&battery_thermal_conf,
THERMAL_STATUS_NORMAL,
0
};


void module_init(module_t* handle)
{
dsme_log(LOG_DEBUG, "thermalobject_hw.so loaded");
if (dsme_hw_supports_core_temp()) {
dsme_register_thermal_object(&core_thermal_object);
core_registered = true;
} else {
dsme_log(LOG_NOTICE, "thermalobject_hw_core: No HW support, going to sleep only mode");
}
if (dsme_hw_supports_battery_temp()) {
dsme_register_thermal_object(&battery_thermal_object);
battery_registered = true;
} else {
dsme_log(LOG_NOTICE, "thermalobject_hw_battery: No HW support, going to sleep only mode");
}
}

void module_fini(void)
{
if (core_registered) {
dsme_unregister_thermal_object(&core_thermal_object);
core_registered = false;
}
if (battery_registered) {
dsme_unregister_thermal_object(&battery_thermal_object);
battery_registered = false;
}
dsme_log(LOG_DEBUG, "thermalobject_hw.so unloaded");
}

0 comments on commit 7e0744b

Please sign in to comment.