thermal: qcom: Add support to update tsens trip based on nvmem data
Add support to detect higher thermal profile parts and update thermal zone trips dynamically based on nvmem cell data for tsens. Change-Id: I792c4f2736d10d68b45cc9b64c0ec08d185cf007 Signed-off-by: Manaf Meethalavalappu Pallikunhi <quic_manafm@quicinc.com>
This commit is contained in:
parent
2325103d69
commit
3f7ba8359f
@ -1256,11 +1256,77 @@ int tsens_v2_tsens_resume(struct tsens_priv *priv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tsens_thermal_zone_trip_update(struct thermal_zone_device *tz,
|
||||
int trip_id)
|
||||
{
|
||||
u32 trip_delta = 0;
|
||||
|
||||
if (!of_thermal_is_trip_valid(tz, trip_id) || !tz->trips)
|
||||
return;
|
||||
|
||||
if (tz->trips[trip_id].type == THERMAL_TRIP_CRITICAL)
|
||||
return;
|
||||
|
||||
if (tz->trips[trip_id].type == THERMAL_TRIP_HOT)
|
||||
trip_delta = TSENS_ELEVATE_HOT_DELTA;
|
||||
else if (strnstr(tz->type, "cpu", sizeof(tz->type)))
|
||||
trip_delta = TSENS_ELEVATE_CPU_DELTA;
|
||||
else
|
||||
trip_delta = TSENS_ELEVATE_DELTA;
|
||||
|
||||
mutex_lock(&tz->lock);
|
||||
tz->trips[trip_id].temperature += trip_delta;
|
||||
mutex_unlock(&tz->lock);
|
||||
|
||||
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
|
||||
}
|
||||
|
||||
static int tsens_nvmem_trip_update(struct thermal_zone_device *tz)
|
||||
{
|
||||
int i, num_trips = 0;
|
||||
|
||||
if (strnstr(tz->type, "mdmss", sizeof(tz->type)))
|
||||
return 0;
|
||||
|
||||
num_trips = of_thermal_get_ntrips(tz);
|
||||
/* First trip is for userspace, update all other trips. */
|
||||
for (i = 1; i < num_trips; i++)
|
||||
tsens_thermal_zone_trip_update(tz, i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool tsens_is_nvmem_trip_update_needed(struct tsens_priv *priv)
|
||||
{
|
||||
int ret;
|
||||
u32 itemp = 0;
|
||||
|
||||
if (!of_property_read_bool(priv->dev->of_node, "nvmem-cells"))
|
||||
return false;
|
||||
|
||||
ret = nvmem_cell_read_variable_le_u32(priv->dev,
|
||||
"tsens_itemp", &itemp);
|
||||
if (ret) {
|
||||
dev_err(priv->dev,
|
||||
"%s: Not able to read tsens_chipinfo nvmem, ret:%d\n",
|
||||
__func__, ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
TSENS_DBG_2(priv, "itemp fuse:0x%x", itemp);
|
||||
if (itemp)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int tsens_register(struct tsens_priv *priv)
|
||||
{
|
||||
int i, temp, ret;
|
||||
struct thermal_zone_device *tzd;
|
||||
|
||||
priv->need_trip_update = tsens_is_nvmem_trip_update_needed(priv);
|
||||
|
||||
for (i = 0; i < priv->num_sensors; i++) {
|
||||
priv->sensor[i].priv = priv;
|
||||
tzd = devm_thermal_of_zone_register(priv->dev, priv->sensor[i].hw_id,
|
||||
@ -1287,6 +1353,9 @@ static int tsens_register(struct tsens_priv *priv)
|
||||
if (devm_thermal_add_hwmon_sysfs(tzd))
|
||||
dev_warn(priv->dev,
|
||||
"Failed to add hwmon sysfs attributes\n");
|
||||
/* update tsens trip based on fuse register */
|
||||
if (priv->need_trip_update)
|
||||
ret = tsens_nvmem_trip_update(tzd);
|
||||
qti_update_tz_ops(tzd, true);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,10 @@
|
||||
#define THRESHOLD_MIN_ADC_CODE 0x0
|
||||
#define COLD_SENSOR_HW_ID 128
|
||||
|
||||
#define TSENS_ELEVATE_DELTA 10000
|
||||
#define TSENS_ELEVATE_CPU_DELTA 5000
|
||||
#define TSENS_ELEVATE_HOT_DELTA 3000
|
||||
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/thermal.h>
|
||||
#include <linux/regmap.h>
|
||||
@ -615,7 +619,8 @@ struct tsens_priv {
|
||||
int crit_irq;
|
||||
int cold_irq;
|
||||
|
||||
bool tm_disable_on_suspend;
|
||||
bool need_trip_update;
|
||||
bool tm_disable_on_suspend;
|
||||
|
||||
struct dentry *debug_root;
|
||||
struct dentry *debug;
|
||||
|
Loading…
Reference in New Issue
Block a user