From de4dbca70de6809b3681a36a8ac5c4c19244ebca Mon Sep 17 00:00:00 2001 From: Hyungwoo Yang Date: Thu, 3 Jan 2013 16:33:36 -0800 Subject: drivers: misc: therm_est: add get_trend using dT/dt Added get_trend to use dTemp/dTime in trend calculation. Bug 1158323 Change-Id: I7a3e80a768e3ebd72f657222eb0d3b546a3fabba Signed-off-by: Hyungwoo Yang Reviewed-on: http://git-master/r/188582 --- drivers/misc/therm_est.c | 27 +++++++++++++++++++++++++++ include/linux/therm_est.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/drivers/misc/therm_est.c b/drivers/misc/therm_est.c index 553764d66..81270480f 100644 --- a/drivers/misc/therm_est.c +++ b/drivers/misc/therm_est.c @@ -45,6 +45,8 @@ struct therm_estimator { struct thermal_zone_device *thz; char *cdev_type; long trip_temp; + int tc1; + int tc2; #ifdef CONFIG_PM struct notifier_block pm_nb; #endif @@ -148,6 +150,28 @@ static int therm_est_get_temp(struct thermal_zone_device *thz, return 0; } +static int therm_est_get_trend(struct thermal_zone_device *thz, + int trip, + enum thermal_trend *trend) +{ + struct therm_estimator *est = thz->devdata; + int new_trend; + int cur_temp; + + cur_temp = thz->temperature; + new_trend = (est->tc1 * (cur_temp - thz->last_temperature)) + + (est->tc2 * (cur_temp - est->trip_temp)); + + if (new_trend > 0) + *trend = THERMAL_TREND_RAISING; + else if (new_trend < 0) + *trend = THERMAL_TREND_DROPPING; + else + *trend = THERMAL_TREND_STABLE; + + return 0; +} + static struct thermal_zone_device_ops therm_est_ops = { .bind = therm_est_bind, .unbind = therm_est_unbind, @@ -155,6 +179,7 @@ static struct thermal_zone_device_ops therm_est_ops = { .get_trip_temp = therm_est_get_trip_temp, .set_trip_temp = therm_est_set_trip_temp, .get_temp = therm_est_get_temp, + .get_trend = therm_est_get_trend, }; static ssize_t show_coeff(struct device *dev, @@ -341,6 +366,8 @@ static int __devinit therm_est_probe(struct platform_device *pdev) est->ndevs = data->ndevs; est->toffset = data->toffset; est->polling_period = data->polling_period; + est->tc1 = data->tc1; + est->tc2 = data->tc2; /* initialize history */ therm_est_init_history(est); diff --git a/include/linux/therm_est.h b/include/linux/therm_est.h index 8d48ed1db..514c5aeac 100644 --- a/include/linux/therm_est.h +++ b/include/linux/therm_est.h @@ -40,6 +40,8 @@ struct therm_est_data { long polling_period; int passive_delay; int ndevs; + int tc1; + int tc2; struct therm_est_subdevice devs[]; }; -- cgit v1.2.2