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 <quic_manafm@quicinc.com>
This commit is contained in:
Manaf Meethalavalappu Pallikunhi 2022-05-27 22:58:25 +05:30 committed by Rashid Zafar
parent b28c171a2a
commit c4de850798

View File

@ -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);