Commit 2510aa56 authored by Wei Ni's avatar Wei Ni Committed by Eduardo Valentin

thermal: tegra: support hw and sw shutdown

Currently the critical trip points in thermal framework are the only
way to specify a temperature at which HW should shutdown. This is
insufficient for certain platforms which would want an orderly
software shutdown in addition to HW shutdown.

This change support to parse "nvidia, thermtrips" property,
it allows soctherm DT to specify thermtrip temperatures so that
critical trip points framework can be used for doing software
shutdown.
Signed-off-by: default avatarWei Ni <wni@nvidia.com>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent 9967a1bc
...@@ -446,6 +446,24 @@ find_throttle_cfg_by_name(struct tegra_soctherm *ts, const char *name) ...@@ -446,6 +446,24 @@ find_throttle_cfg_by_name(struct tegra_soctherm *ts, const char *name)
return NULL; return NULL;
} }
static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)
{
int i, temp = min_low_temp;
struct tsensor_group_thermtrips *tt = ts->soc->thermtrips;
if (id >= TEGRA124_SOCTHERM_SENSOR_NUM)
return temp;
if (tt) {
for (i = 0; i < ts->soc->num_ttgs; i++) {
if (tt[i].id == id)
return tt[i].temp;
}
}
return temp;
}
static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp) static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp)
{ {
struct tegra_thermctl_zone *zone = data; struct tegra_thermctl_zone *zone = data;
...@@ -464,7 +482,16 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp) ...@@ -464,7 +482,16 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp)
return ret; return ret;
if (type == THERMAL_TRIP_CRITICAL) { if (type == THERMAL_TRIP_CRITICAL) {
/*
* If thermtrips property is set in DT,
* doesn't need to program critical type trip to HW,
* if not, program critical trip to HW.
*/
if (min_low_temp == tsensor_group_thermtrip_get(ts, sg->id))
return thermtrip_program(dev, sg, temp); return thermtrip_program(dev, sg, temp);
else
return 0;
} else if (type == THERMAL_TRIP_HOT) { } else if (type == THERMAL_TRIP_HOT) {
int i; int i;
...@@ -555,7 +582,8 @@ static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp) ...@@ -555,7 +582,8 @@ static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp)
* @dev: struct device * of the SOC_THERM instance * @dev: struct device * of the SOC_THERM instance
* *
* Configure the SOC_THERM HW trip points, setting "THERMTRIP" * Configure the SOC_THERM HW trip points, setting "THERMTRIP"
* "THROTTLE" trip points , using "critical" or "hot" type trip_temp * "THROTTLE" trip points , using "thermtrips", "critical" or "hot"
* type trip_temp
* from thermal zone. * from thermal zone.
* After they have been configured, THERMTRIP or THROTTLE will take * After they have been configured, THERMTRIP or THROTTLE will take
* action when the configured SoC thermal sensor group reaches a * action when the configured SoC thermal sensor group reaches a
...@@ -577,28 +605,23 @@ static int tegra_soctherm_set_hwtrips(struct device *dev, ...@@ -577,28 +605,23 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
{ {
struct tegra_soctherm *ts = dev_get_drvdata(dev); struct tegra_soctherm *ts = dev_get_drvdata(dev);
struct soctherm_throt_cfg *stc; struct soctherm_throt_cfg *stc;
int i, trip, temperature; int i, trip, temperature, ret;
int ret;
ret = tz->ops->get_crit_temp(tz, &temperature); /* Get thermtrips. If missing, try to get critical trips. */
if (ret) { temperature = tsensor_group_thermtrip_get(ts, sg->id);
dev_warn(dev, "thermtrip: %s: missing critical temperature\n", if (min_low_temp == temperature)
sg->name); if (tz->ops->get_crit_temp(tz, &temperature))
goto set_throttle; temperature = max_high_temp;
}
ret = thermtrip_program(dev, sg, temperature); ret = thermtrip_program(dev, sg, temperature);
if (ret) { if (ret) {
dev_err(dev, "thermtrip: %s: error during enable\n", dev_err(dev, "thermtrip: %s: error during enable\n", sg->name);
sg->name);
return ret; return ret;
} }
dev_info(dev, dev_info(dev, "thermtrip: will shut down when %s reaches %d mC\n",
"thermtrip: will shut down when %s reaches %d mC\n",
sg->name, temperature); sg->name, temperature);
set_throttle:
ret = get_hot_temp(tz, &trip, &temperature); ret = get_hot_temp(tz, &trip, &temperature);
if (ret) { if (ret) {
dev_info(dev, "throttrip: %s: missing hot temperature\n", dev_info(dev, "throttrip: %s: missing hot temperature\n",
...@@ -929,6 +952,50 @@ static const struct thermal_cooling_device_ops throt_cooling_ops = { ...@@ -929,6 +952,50 @@ static const struct thermal_cooling_device_ops throt_cooling_ops = {
.set_cur_state = throt_set_cdev_state, .set_cur_state = throt_set_cdev_state,
}; };
static int soctherm_thermtrips_parse(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct tegra_soctherm *ts = dev_get_drvdata(dev);
struct tsensor_group_thermtrips *tt = ts->soc->thermtrips;
const int max_num_prop = ts->soc->num_ttgs * 2;
u32 *tlb;
int i, j, n, ret;
if (!tt)
return -ENOMEM;
n = of_property_count_u32_elems(dev->of_node, "nvidia,thermtrips");
if (n <= 0) {
dev_info(dev,
"missing thermtrips, will use critical trips as shut down temp\n");
return n;
}
n = min(max_num_prop, n);
tlb = devm_kcalloc(&pdev->dev, max_num_prop, sizeof(u32), GFP_KERNEL);
if (!tlb)
return -ENOMEM;
ret = of_property_read_u32_array(dev->of_node, "nvidia,thermtrips",
tlb, n);
if (ret) {
dev_err(dev, "invalid num ele: thermtrips:%d\n", ret);
return ret;
}
i = 0;
for (j = 0; j < n; j = j + 2) {
if (tlb[j] >= TEGRA124_SOCTHERM_SENSOR_NUM)
continue;
tt[i].id = tlb[j];
tt[i].temp = tlb[j + 1];
i++;
}
return 0;
}
/** /**
* soctherm_init_hw_throt_cdev() - Parse the HW throttle configurations * soctherm_init_hw_throt_cdev() - Parse the HW throttle configurations
* and register them as cooling devices. * and register them as cooling devices.
...@@ -1370,6 +1437,8 @@ static int tegra_soctherm_probe(struct platform_device *pdev) ...@@ -1370,6 +1437,8 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
if (err) if (err)
return err; return err;
soctherm_thermtrips_parse(pdev);
soctherm_init_hw_throt_cdev(pdev); soctherm_init_hw_throt_cdev(pdev);
soctherm_init(pdev); soctherm_init(pdev);
......
...@@ -92,6 +92,11 @@ struct tegra_tsensor { ...@@ -92,6 +92,11 @@ struct tegra_tsensor {
const struct tegra_tsensor_group *group; const struct tegra_tsensor_group *group;
}; };
struct tsensor_group_thermtrips {
u8 id;
u32 temp;
};
struct tegra_soctherm_fuse { struct tegra_soctherm_fuse {
u32 fuse_base_cp_mask, fuse_base_cp_shift; u32 fuse_base_cp_mask, fuse_base_cp_shift;
u32 fuse_base_ft_mask, fuse_base_ft_shift; u32 fuse_base_ft_mask, fuse_base_ft_shift;
...@@ -113,6 +118,7 @@ struct tegra_soctherm_soc { ...@@ -113,6 +118,7 @@ struct tegra_soctherm_soc {
const int thresh_grain; const int thresh_grain;
const unsigned int bptt; const unsigned int bptt;
const bool use_ccroc; const bool use_ccroc;
struct tsensor_group_thermtrips *thermtrips;
}; };
int tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse, int tegra_calc_shared_calib(const struct tegra_soctherm_fuse *tfuse,
......
...@@ -203,6 +203,13 @@ static const struct tegra_soctherm_fuse tegra210_soctherm_fuse = { ...@@ -203,6 +203,13 @@ static const struct tegra_soctherm_fuse tegra210_soctherm_fuse = {
.fuse_spare_realignment = 0, .fuse_spare_realignment = 0,
}; };
struct tsensor_group_thermtrips tegra210_tsensor_thermtrips[] = {
{.id = TEGRA124_SOCTHERM_SENSOR_NUM},
{.id = TEGRA124_SOCTHERM_SENSOR_NUM},
{.id = TEGRA124_SOCTHERM_SENSOR_NUM},
{.id = TEGRA124_SOCTHERM_SENSOR_NUM},
};
const struct tegra_soctherm_soc tegra210_soctherm = { const struct tegra_soctherm_soc tegra210_soctherm = {
.tsensors = tegra210_tsensors, .tsensors = tegra210_tsensors,
.num_tsensors = ARRAY_SIZE(tegra210_tsensors), .num_tsensors = ARRAY_SIZE(tegra210_tsensors),
...@@ -212,4 +219,5 @@ const struct tegra_soctherm_soc tegra210_soctherm = { ...@@ -212,4 +219,5 @@ const struct tegra_soctherm_soc tegra210_soctherm = {
.thresh_grain = TEGRA210_THRESH_GRAIN, .thresh_grain = TEGRA210_THRESH_GRAIN,
.bptt = TEGRA210_BPTT, .bptt = TEGRA210_BPTT,
.use_ccroc = false, .use_ccroc = false,
.thermtrips = tegra210_tsensor_thermtrips,
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment