From c4de8507982e294e6e25a2812c913096153e76cb Mon Sep 17 00:00:00 2001 From: Manaf Meethalavalappu Pallikunhi Date: Fri, 27 May 2022 22:58:25 +0530 Subject: [PATCH] driver: thermal: bcl-soc: Add support for trend estimation Add support for trend estimation callback. Since BCL soc update is happening in software worker thread and soc stays longer duration in same state compared to thermal sensor. It leads to a case where before handling thermal zone update completely on threshold update, there is a chance that another thermal zone update context can happen in parallel due to userspace clients update or due to polling thread context. This causes the trend stays stable for longer duration. This will not help in mitigating using step wise algorithm. Adding this trend estimation callback will return a raising trend during bcl soc trip high violation, a dropping trend during trip low vilation and fallback to default core trend estimation for otherwise. This will help step wise algorithm to determine the next mitigation actions. Change-Id: Ib59eadbb497cf5775bda4888e0d93b3378d46798 Signed-off-by: Manaf Meethalavalappu Pallikunhi --- drivers/thermal/qcom/bcl_soc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/thermal/qcom/bcl_soc.c b/drivers/thermal/qcom/bcl_soc.c index d3caa67f7808..eeab5b29776e 100644 --- a/drivers/thermal/qcom/bcl_soc.c +++ b/drivers/thermal/qcom/bcl_soc.c @@ -34,6 +34,39 @@ struct bcl_device { static struct bcl_device *bcl_perph; +static int bcl_soc_get_trend(void *data, int trip, + enum thermal_trend *trend) +{ + struct bcl_device *bcl_perph = data; + struct thermal_zone_device *tz = bcl_perph->tz_dev; + int trip_temp = 0, trip_hyst = 0, temp, ret; + + if (!tz) + return -EINVAL; + + ret = tz->ops->get_trip_temp(tz, trip, &trip_temp); + if (ret) + return ret; + + if (tz->ops->get_trip_hyst) { + ret = tz->ops->get_trip_hyst(tz, trip, &trip_hyst); + if (ret) + return ret; + } + temp = READ_ONCE(tz->temperature); + + if (temp >= trip_temp) + *trend = THERMAL_TREND_RAISING; + else if (!trip_hyst && temp < trip_temp) + *trend = THERMAL_TREND_DROPPING; + else if (temp <= (trip_temp - trip_hyst)) + *trend = THERMAL_TREND_DROPPING; + else + *trend = THERMAL_TREND_STABLE; + + return 0; +} + static int bcl_set_soc(void *data, int low, int high) { if (high == bcl_perph->trip_temp) @@ -141,6 +174,7 @@ static int bcl_soc_probe(struct platform_device *pdev) bcl_perph->dev = &pdev->dev; bcl_perph->ops.get_temp = bcl_read_soc; bcl_perph->ops.set_trips = bcl_set_soc; + bcl_perph->ops.get_trend = bcl_soc_get_trend; INIT_WORK(&bcl_perph->soc_eval_work, bcl_evaluate_soc); bcl_perph->psy_nb.notifier_call = battery_supply_callback; ret = power_supply_reg_notifier(&bcl_perph->psy_nb);