Merge "thermal: qcom: Add support to update tsens trip based on nvmem data"

This commit is contained in:
QCTECMDR Service 2024-08-27 11:39:45 -07:00 committed by Gerrit - the friendly Code Review server
commit 76c1fe285b
3 changed files with 81 additions and 6 deletions

View file

@ -837,7 +837,6 @@ static const struct regmap_config tsens_srot_config = {
static int init_cold_interrupt(struct tsens_priv *priv,
struct platform_device *op, u32 ver_minor)
{
struct device *dev = priv->dev;
int ret = 0;
@ -850,16 +849,17 @@ static int init_cold_interrupt(struct tsens_priv *priv,
priv->fields[COLD_STATUS]);
if (IS_ERR(priv->rf[COLD_STATUS])) {
ret = PTR_ERR(priv->rf[COLD_STATUS]);
goto err_put_device;
}
}
err_put_device:
put_device(&op->dev);
return ret;
}
#if IS_MODULE(CONFIG_QCOM_TSENS)
int init_common(struct tsens_priv *priv)
#else
int __init init_common(struct tsens_priv *priv)
#endif
{
void __iomem *tm_base, *srot_base;
struct device *dev = priv->dev;
@ -1032,7 +1032,7 @@ int __init init_common(struct tsens_priv *priv)
regmap_field_write(priv->rf[CC_MON_MASK], 1);
}
ret = init_cold_interrupt(priv, op, ver_minor);
init_cold_interrupt(priv, op, ver_minor);
spin_lock_init(&priv->ul_lock);
@ -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);
}

View file

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

View file

@ -7,6 +7,7 @@ qcom_scmi_client.ko
cmd-db.ko
qcom_rpmh.ko
qcom-pdc.ko
nvmem_qfprom.ko
thermal_minidump.ko
qcom_tsens.ko
qcom_iommu_util.ko