This series fixed some issues for Tegra soctherm,
and add get_trend().
Main changes from v5:
1. Move the get_trend() patch https://lkml.org/lkml/2018/11/20/643
into this serial.
Main changes from v4:
1. fixed for the parsing sensor id.
2. keep warning for missing critical trips.
Main changes from v3:
1. updated codes for parsing sensor id, per Thierry's comments
Main changes from v2:
1. add codes to parse sensor id to avoid registration
failure.
Main changes from v1:
1. Acked by Thierry Reding <[email protected]> for the patch
"thermal: tegra: fix memory allocation".
2. Print out the sensor name when register failed.
2. Remove patch "thermal: tegra: fix coverity defect"
Wei Ni (4):
thermal: tegra: remove unnecessary warnings
thermal: tegra: fix memory allocation
thermal: tegra: parse sensor id before sensor register
thermal: tegra: add get_trend ops
drivers/thermal/tegra/soctherm.c | 85 +++++++++++++++++++++++++++++++++++++---
1 file changed, 80 insertions(+), 5 deletions(-)
--
2.7.4
Convert warnings to info as not all platforms may
have all the thresholds and sensors enabled.
Signed-off-by: Wei Ni <[email protected]>
---
drivers/thermal/tegra/soctherm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index ed28110a3535..f07de8258e93 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -569,7 +569,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
set_throttle:
ret = get_hot_temp(tz, &trip, &temperature);
if (ret) {
- dev_warn(dev, "throttrip: %s: missing hot temperature\n",
+ dev_info(dev, "throttrip: %s: missing hot temperature\n",
sg->name);
return 0;
}
@@ -600,7 +600,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
}
if (i == THROTTLE_SIZE)
- dev_warn(dev, "throttrip: %s: missing throttle cdev\n",
+ dev_info(dev, "throttrip: %s: missing throttle cdev\n",
sg->name);
return 0;
--
2.7.4
Fix memory allocation to store the pointers to
thermal_zone_device.
Signed-off-by: Wei Ni <[email protected]>
Acked-by: Thierry Reding <[email protected]>
---
drivers/thermal/tegra/soctherm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index f07de8258e93..fd2703c0cfc5 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -1339,7 +1339,7 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
}
tegra->thermctl_tzs = devm_kcalloc(&pdev->dev,
- soc->num_ttgs, sizeof(*z),
+ soc->num_ttgs, sizeof(z),
GFP_KERNEL);
if (!tegra->thermctl_tzs)
return -ENOMEM;
--
2.7.4
Add support for get_trend ops that allows soctherm
sensors to be used with the step-wise governor.
Signed-off-by: Wei Ni <[email protected]>
---
drivers/thermal/tegra/soctherm.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index 6bee31cd4621..330bffd38fdd 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -488,9 +488,43 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp)
return 0;
}
+static int tegra_thermctl_get_trend(void *data, int trip,
+ enum thermal_trend *trend)
+{
+ struct tegra_thermctl_zone *zone = data;
+ struct thermal_zone_device *tz = zone->tz;
+ int trip_temp, temp, last_temp, ret;
+
+ if (!tz)
+ return -EINVAL;
+
+ ret = tz->ops->get_trip_temp(zone->tz, trip, &trip_temp);
+ if (ret)
+ return ret;
+
+ mutex_lock(&tz->lock);
+ temp = tz->temperature;
+ last_temp = tz->last_temperature;
+ mutex_unlock(&tz->lock);
+
+ if (temp > trip_temp) {
+ if (temp >= last_temp)
+ *trend = THERMAL_TREND_RAISING;
+ else
+ *trend = THERMAL_TREND_STABLE;
+ } else if (temp < trip_temp) {
+ *trend = THERMAL_TREND_DROPPING;
+ } else {
+ *trend = THERMAL_TREND_STABLE;
+ }
+
+ return 0;
+}
+
static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = {
.get_temp = tegra_thermctl_get_temp,
.set_trip_temp = tegra_thermctl_set_trip_temp,
+ .get_trend = tegra_thermctl_get_trend,
};
static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp)
--
2.7.4
Since different platforms may not support all 4
sensors, so the sensor registration may be failed.
Add codes to parse dt to find sensor id which
need to be registered. So that the registration
can be successful on all platform.
Signed-off-by: Wei Ni <[email protected]>
---
drivers/thermal/tegra/soctherm.c | 45 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index fd2703c0cfc5..6bee31cd4621 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -1224,6 +1224,41 @@ static void soctherm_init(struct platform_device *pdev)
tegra_soctherm_throttle(&pdev->dev);
}
+static bool tegra_soctherm_find_sensor_id(unsigned int sensor_id)
+{
+ bool ret = false;
+ struct of_phandle_args sensor_specs;
+ struct device_node *np, *sensor_np;
+
+ np = of_find_node_by_name(NULL, "thermal-zones");
+ if (!np)
+ return ret;
+
+ for_each_available_child_of_node(np, sensor_np) {
+ if (of_parse_phandle_with_args(sensor_np, "thermal-sensors",
+ "#thermal-sensor-cells",
+ 0, &sensor_specs))
+ continue;
+
+ if (sensor_specs.args_count != 1) {
+ WARN(sensor_specs.args_count != 1,
+ "%s: wrong cells in sensor specifier %d\n",
+ sensor_specs.np->name, sensor_specs.args_count);
+ continue;
+ }
+
+ if (sensor_specs.args[0] == sensor_id) {
+ of_node_put(sensor_np);
+ ret = true;
+ break;
+ }
+ }
+
+ of_node_put(np);
+
+ return ret;
+}
+
static const struct of_device_id tegra_soctherm_of_match[] = {
#ifdef CONFIG_ARCH_TEGRA_124_SOC
{
@@ -1365,13 +1400,16 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
zone->sg = soc->ttgs[i];
zone->ts = tegra;
+ if (!tegra_soctherm_find_sensor_id(soc->ttgs[i]->id))
+ continue;
+
z = devm_thermal_zone_of_sensor_register(&pdev->dev,
soc->ttgs[i]->id, zone,
&tegra_of_thermal_ops);
if (IS_ERR(z)) {
err = PTR_ERR(z);
- dev_err(&pdev->dev, "failed to register sensor: %d\n",
- err);
+ dev_err(&pdev->dev, "failed to register sensor %s: %d\n",
+ soc->ttgs[i]->name, err);
goto disable_clocks;
}
@@ -1434,6 +1472,9 @@ static int __maybe_unused soctherm_resume(struct device *dev)
struct thermal_zone_device *tz;
tz = tegra->thermctl_tzs[soc->ttgs[i]->id];
+ if (!tz)
+ continue;
+
err = tegra_soctherm_set_hwtrips(dev, soc->ttgs[i], tz);
if (err) {
dev_err(&pdev->dev,
--
2.7.4
Hi Rui,
I moved get_trend() patch https://lkml.org/lkml/2018/11/20/643 in this
serial.
Since no more comments on these patches, will you take them?
Thanks.
Wei.
On 14/12/2018 5:49 PM, Wei Ni wrote:
> This series fixed some issues for Tegra soctherm,
> and add get_trend().
>
> Main changes from v5:
> 1. Move the get_trend() patch https://lkml.org/lkml/2018/11/20/643
> into this serial.
>
> Main changes from v4:
> 1. fixed for the parsing sensor id.
> 2. keep warning for missing critical trips.
>
> Main changes from v3:
> 1. updated codes for parsing sensor id, per Thierry's comments
>
> Main changes from v2:
> 1. add codes to parse sensor id to avoid registration
> failure.
>
> Main changes from v1:
> 1. Acked by Thierry Reding <[email protected]> for the patch
> "thermal: tegra: fix memory allocation".
> 2. Print out the sensor name when register failed.
> 2. Remove patch "thermal: tegra: fix coverity defect"
>
> Wei Ni (4):
> thermal: tegra: remove unnecessary warnings
> thermal: tegra: fix memory allocation
> thermal: tegra: parse sensor id before sensor register
> thermal: tegra: add get_trend ops
>
> drivers/thermal/tegra/soctherm.c | 85 +++++++++++++++++++++++++++++++++++++---
> 1 file changed, 80 insertions(+), 5 deletions(-)
>
On Fri, Dec 14, 2018 at 05:49:52PM +0800, Wei Ni wrote:
> Since different platforms may not support all 4
> sensors, so the sensor registration may be failed.
> Add codes to parse dt to find sensor id which
> need to be registered. So that the registration
> can be successful on all platform.
>
> Signed-off-by: Wei Ni <[email protected]>
> ---
> drivers/thermal/tegra/soctherm.c | 45 ++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 43 insertions(+), 2 deletions(-)
Acked-by: Thierry Reding <[email protected]>
On Fri, Dec 14, 2018 at 05:49:50PM +0800, Wei Ni wrote:
> Convert warnings to info as not all platforms may
> have all the thresholds and sensors enabled.
>
> Signed-off-by: Wei Ni <[email protected]>
> ---
> drivers/thermal/tegra/soctherm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Acked-by: Thierry Reding <[email protected]>
On Fri, Dec 14, 2018 at 05:49:53PM +0800, Wei Ni wrote:
> Add support for get_trend ops that allows soctherm
> sensors to be used with the step-wise governor.
>
> Signed-off-by: Wei Ni <[email protected]>
> ---
> drivers/thermal/tegra/soctherm.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
Acked-by: Thierry Reding <[email protected]>
On 五, 2018-12-14 at 17:54 +0800, Wei Ni wrote:
> Hi Rui,
> I moved get_trend() patch https://lkml.org/lkml/2018/11/20/643 in
> this
> serial.
> Since no more comments on these patches, will you take them?
>
I think Eduardo will take care of this patch series.
thanks,
rui
> Thanks.
> Wei.
>
> On 14/12/2018 5:49 PM, Wei Ni wrote:
> >
> > This series fixed some issues for Tegra soctherm,
> > and add get_trend().
> >
> > Main changes from v5:
> > 1. Move the get_trend() patch https://lkml.org/lkml/2018/11/20/643
> > into this serial.
> >
> > Main changes from v4:
> > 1. fixed for the parsing sensor id.
> > 2. keep warning for missing critical trips.
> >
> > Main changes from v3:
> > 1. updated codes for parsing sensor id, per Thierry's comments
> >
> > Main changes from v2:
> > 1. add codes to parse sensor id to avoid registration
> > failure.
> >
> > Main changes from v1:
> > 1. Acked by Thierry Reding <[email protected]> for the patch
> > "thermal: tegra: fix memory allocation".
> > 2. Print out the sensor name when register failed.
> > 2. Remove patch "thermal: tegra: fix coverity defect"
> >
> > Wei Ni (4):
> > thermal: tegra: remove unnecessary warnings
> > thermal: tegra: fix memory allocation
> > thermal: tegra: parse sensor id before sensor register
> > thermal: tegra: add get_trend ops
> >
> > drivers/thermal/tegra/soctherm.c | 85
> > +++++++++++++++++++++++++++++++++++++---
> > 1 file changed, 80 insertions(+), 5 deletions(-)
> >
On Tue, Dec 18, 2018 at 11:35:54AM +0800, Zhang Rui wrote:
> On 五, 2018-12-14 at 17:54 +0800, Wei Ni wrote:
> > Hi Rui,
> > I moved get_trend() patch https://lkml.org/lkml/2018/11/20/643 in
> > this
> > serial.
> > Since no more comments on these patches, will you take them?
> >
> I think Eduardo will take care of this patch series.
Yes, I will take a look on this series.
But, please, next time you send a series of patches on thermal, copy the
[email protected] mailing list. This way we can track your
patches on patchwork.
>
> thanks,
> rui
> > Thanks.
> > Wei.
> >
> > On 14/12/2018 5:49 PM, Wei Ni wrote:
> > >
> > > This series fixed some issues for Tegra soctherm,
> > > and add get_trend().
> > >
> > > Main changes from v5:
> > > 1. Move the get_trend() patch https://lkml.org/lkml/2018/11/20/643
> > > into this serial.
> > >
> > > Main changes from v4:
> > > 1. fixed for the parsing sensor id.
> > > 2. keep warning for missing critical trips.
> > >
> > > Main changes from v3:
> > > 1. updated codes for parsing sensor id, per Thierry's comments
> > >
> > > Main changes from v2:
> > > 1. add codes to parse sensor id to avoid registration
> > > failure.
> > >
> > > Main changes from v1:
> > > 1. Acked by Thierry Reding <[email protected]> for the patch
> > > "thermal: tegra: fix memory allocation".
> > > 2. Print out the sensor name when register failed.
> > > 2. Remove patch "thermal: tegra: fix coverity defect"
> > >
> > > Wei Ni (4):
> > > thermal: tegra: remove unnecessary warnings
> > > thermal: tegra: fix memory allocation
> > > thermal: tegra: parse sensor id before sensor register
> > > thermal: tegra: add get_trend ops
> > >
> > > drivers/thermal/tegra/soctherm.c | 85
> > > +++++++++++++++++++++++++++++++++++++---
> > > 1 file changed, 80 insertions(+), 5 deletions(-)
> > >
On Fri, Dec 14, 2018 at 05:49:52PM +0800, Wei Ni wrote:
> Since different platforms may not support all 4
> sensors, so the sensor registration may be failed.
> Add codes to parse dt to find sensor id which
> need to be registered. So that the registration
> can be successful on all platform.
>
> Signed-off-by: Wei Ni <[email protected]>
> ---
> drivers/thermal/tegra/soctherm.c | 45 ++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> index fd2703c0cfc5..6bee31cd4621 100644
> --- a/drivers/thermal/tegra/soctherm.c
> +++ b/drivers/thermal/tegra/soctherm.c
> @@ -1224,6 +1224,41 @@ static void soctherm_init(struct platform_device *pdev)
> tegra_soctherm_throttle(&pdev->dev);
> }
>
> +static bool tegra_soctherm_find_sensor_id(unsigned int sensor_id)
> +{
> + bool ret = false;
> + struct of_phandle_args sensor_specs;
> + struct device_node *np, *sensor_np;
> +
> + np = of_find_node_by_name(NULL, "thermal-zones");
> + if (!np)
> + return ret;
> +
> + for_each_available_child_of_node(np, sensor_np) {
> + if (of_parse_phandle_with_args(sensor_np, "thermal-sensors",
> + "#thermal-sensor-cells",
> + 0, &sensor_specs))
> + continue;
> +
> + if (sensor_specs.args_count != 1) {
> + WARN(sensor_specs.args_count != 1,
> + "%s: wrong cells in sensor specifier %d\n",
> + sensor_specs.np->name, sensor_specs.args_count);
> + continue;
> + }
> +
> + if (sensor_specs.args[0] == sensor_id) {
> + of_node_put(sensor_np);
> + ret = true;
> + break;
> + }
> + }
> +
> + of_node_put(np);
> +
> + return ret;
> +}
So, I am still failing to see why this is really needed.
Why can't you simply resolve this with different compatibles?
If the sensor is not present or disabled, the compatible is not, well,
compatible anymore.
> +
> static const struct of_device_id tegra_soctherm_of_match[] = {
> #ifdef CONFIG_ARCH_TEGRA_124_SOC
> {
> @@ -1365,13 +1400,16 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
> zone->sg = soc->ttgs[i];
> zone->ts = tegra;
>
> + if (!tegra_soctherm_find_sensor_id(soc->ttgs[i]->id))
> + continue;
> +
> z = devm_thermal_zone_of_sensor_register(&pdev->dev,
> soc->ttgs[i]->id, zone,
> &tegra_of_thermal_ops);
> if (IS_ERR(z)) {
> err = PTR_ERR(z);
> - dev_err(&pdev->dev, "failed to register sensor: %d\n",
> - err);
> + dev_err(&pdev->dev, "failed to register sensor %s: %d\n",
> + soc->ttgs[i]->name, err);
> goto disable_clocks;
> }
>
> @@ -1434,6 +1472,9 @@ static int __maybe_unused soctherm_resume(struct device *dev)
> struct thermal_zone_device *tz;
>
> tz = tegra->thermctl_tzs[soc->ttgs[i]->id];
> + if (!tz)
> + continue;
> +
> err = tegra_soctherm_set_hwtrips(dev, soc->ttgs[i], tz);
> if (err) {
> dev_err(&pdev->dev,
> --
> 2.7.4
>
On 19/12/2018 9:24 AM, Eduardo Valentin wrote:
> On Fri, Dec 14, 2018 at 05:49:52PM +0800, Wei Ni wrote:
>> Since different platforms may not support all 4
>> sensors, so the sensor registration may be failed.
>> Add codes to parse dt to find sensor id which
>> need to be registered. So that the registration
>> can be successful on all platform.
>>
>> Signed-off-by: Wei Ni <[email protected]>
>> ---
>> drivers/thermal/tegra/soctherm.c | 45 ++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 43 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
>> index fd2703c0cfc5..6bee31cd4621 100644
>> --- a/drivers/thermal/tegra/soctherm.c
>> +++ b/drivers/thermal/tegra/soctherm.c
>> @@ -1224,6 +1224,41 @@ static void soctherm_init(struct platform_device *pdev)
>> tegra_soctherm_throttle(&pdev->dev);
>> }
>>
>> +static bool tegra_soctherm_find_sensor_id(unsigned int sensor_id)
>> +{
>> + bool ret = false;
>> + struct of_phandle_args sensor_specs;
>> + struct device_node *np, *sensor_np;
>> +
>> + np = of_find_node_by_name(NULL, "thermal-zones");
>> + if (!np)
>> + return ret;
>> +
>> + for_each_available_child_of_node(np, sensor_np) {
>> + if (of_parse_phandle_with_args(sensor_np, "thermal-sensors",
>> + "#thermal-sensor-cells",
>> + 0, &sensor_specs))
>> + continue;
>> +
>> + if (sensor_specs.args_count != 1) {
>> + WARN(sensor_specs.args_count != 1,
>> + "%s: wrong cells in sensor specifier %d\n",
>> + sensor_specs.np->name, sensor_specs.args_count);
>> + continue;
>> + }
>> +
>> + if (sensor_specs.args[0] == sensor_id) {
>> + of_node_put(sensor_np);
>> + ret = true;
>> + break;
>> + }
>> + }
>> +
>> + of_node_put(np);
>> +
>> + return ret;
>> +}
>
> So, I am still failing to see why this is really needed.
>
> Why can't you simply resolve this with different compatibles?
> If the sensor is not present or disabled, the compatible is not, well,
> compatible anymore.
This driver can support three Tegra chip t124, t132 and t210. And we
also support some platforms for every chips. As the description in the
commit, different platforms may not support all 4 sensors, so I
upstreamed this patch.
If we use different compatibles, I think we can't resolve it simply,
because we also need to add codes to configure which platform support
which sensors, and may add more in the future. If use this patch, we
doesn't need to do any more in the future.
Actually in my original change, I just ignore the registration failure
to fix this issue, it will not affect loading driver, but as Daniel's
comment, it's not better to ignore, so I followed his comment to refer
the QORIQ thermal driver to get the sensor id.
Thanks.
Wei.
>
>> +
>> static const struct of_device_id tegra_soctherm_of_match[] = {
>> #ifdef CONFIG_ARCH_TEGRA_124_SOC
>> {
>> @@ -1365,13 +1400,16 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
>> zone->sg = soc->ttgs[i];
>> zone->ts = tegra;
>>
>> + if (!tegra_soctherm_find_sensor_id(soc->ttgs[i]->id))
>> + continue;
>> +
>> z = devm_thermal_zone_of_sensor_register(&pdev->dev,
>> soc->ttgs[i]->id, zone,
>> &tegra_of_thermal_ops);
>> if (IS_ERR(z)) {
>> err = PTR_ERR(z);
>> - dev_err(&pdev->dev, "failed to register sensor: %d\n",
>> - err);
>> + dev_err(&pdev->dev, "failed to register sensor %s: %d\n",
>> + soc->ttgs[i]->name, err);
>> goto disable_clocks;
>> }
>>
>> @@ -1434,6 +1472,9 @@ static int __maybe_unused soctherm_resume(struct device *dev)
>> struct thermal_zone_device *tz;
>>
>> tz = tegra->thermctl_tzs[soc->ttgs[i]->id];
>> + if (!tz)
>> + continue;
>> +
>> err = tegra_soctherm_set_hwtrips(dev, soc->ttgs[i], tz);
>> if (err) {
>> dev_err(&pdev->dev,
>> --
>> 2.7.4
>>
On 19/12/2018 5:31 AM, Eduardo Valentin wrote:
> On Tue, Dec 18, 2018 at 11:35:54AM +0800, Zhang Rui wrote:
>> On 五, 2018-12-14 at 17:54 +0800, Wei Ni wrote:
>>> Hi Rui,
>>> I moved get_trend() patch https://lkml.org/lkml/2018/11/20/643 in
>>> this
>>> serial.
>>> Since no more comments on these patches, will you take them?
>>>
>> I think Eduardo will take care of this patch series.
>
> Yes, I will take a look on this series.
>
> But, please, next time you send a series of patches on thermal, copy the
> [email protected] mailing list. This way we can track your
> patches on patchwork.
Sure, will do it.
Thanks.
Wei.
>
>>
>> thanks,
>> rui
>>> Thanks.
>>> Wei.
>>>
>>> On 14/12/2018 5:49 PM, Wei Ni wrote:
>>>>
>>>> This series fixed some issues for Tegra soctherm,
>>>> and add get_trend().
>>>>
>>>> Main changes from v5:
>>>> 1. Move the get_trend() patch https://lkml.org/lkml/2018/11/20/643
>>>> into this serial.
>>>>
>>>> Main changes from v4:
>>>> 1. fixed for the parsing sensor id.
>>>> 2. keep warning for missing critical trips.
>>>>
>>>> Main changes from v3:
>>>> 1. updated codes for parsing sensor id, per Thierry's comments
>>>>
>>>> Main changes from v2:
>>>> 1. add codes to parse sensor id to avoid registration
>>>> failure.
>>>>
>>>> Main changes from v1:
>>>> 1. Acked by Thierry Reding <[email protected]> for the patch
>>>> "thermal: tegra: fix memory allocation".
>>>> 2. Print out the sensor name when register failed.
>>>> 2. Remove patch "thermal: tegra: fix coverity defect"
>>>>
>>>> Wei Ni (4):
>>>> thermal: tegra: remove unnecessary warnings
>>>> thermal: tegra: fix memory allocation
>>>> thermal: tegra: parse sensor id before sensor register
>>>> thermal: tegra: add get_trend ops
>>>>
>>>> drivers/thermal/tegra/soctherm.c | 85
>>>> +++++++++++++++++++++++++++++++++++++---
>>>> 1 file changed, 80 insertions(+), 5 deletions(-)
>>>>
On Wed, Dec 19, 2018 at 11:00:10AM +0800, Wei Ni wrote:
>
>
> On 19/12/2018 9:24 AM, Eduardo Valentin wrote:
> > On Fri, Dec 14, 2018 at 05:49:52PM +0800, Wei Ni wrote:
> >> Since different platforms may not support all 4
> >> sensors, so the sensor registration may be failed.
> >> Add codes to parse dt to find sensor id which
> >> need to be registered. So that the registration
> >> can be successful on all platform.
> >>
> >> Signed-off-by: Wei Ni <[email protected]>
> >> ---
> >> drivers/thermal/tegra/soctherm.c | 45 ++++++++++++++++++++++++++++++++++++++--
> >> 1 file changed, 43 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> >> index fd2703c0cfc5..6bee31cd4621 100644
> >> --- a/drivers/thermal/tegra/soctherm.c
> >> +++ b/drivers/thermal/tegra/soctherm.c
> >> @@ -1224,6 +1224,41 @@ static void soctherm_init(struct platform_device *pdev)
> >> tegra_soctherm_throttle(&pdev->dev);
> >> }
> >>
> >> +static bool tegra_soctherm_find_sensor_id(unsigned int sensor_id)
> >> +{
> >> + bool ret = false;
> >> + struct of_phandle_args sensor_specs;
> >> + struct device_node *np, *sensor_np;
> >> +
> >> + np = of_find_node_by_name(NULL, "thermal-zones");
> >> + if (!np)
> >> + return ret;
> >> +
> >> + for_each_available_child_of_node(np, sensor_np) {
> >> + if (of_parse_phandle_with_args(sensor_np, "thermal-sensors",
> >> + "#thermal-sensor-cells",
> >> + 0, &sensor_specs))
> >> + continue;
> >> +
> >> + if (sensor_specs.args_count != 1) {
> >> + WARN(sensor_specs.args_count != 1,
> >> + "%s: wrong cells in sensor specifier %d\n",
> >> + sensor_specs.np->name, sensor_specs.args_count);
> >> + continue;
> >> + }
> >> +
> >> + if (sensor_specs.args[0] == sensor_id) {
> >> + of_node_put(sensor_np);
> >> + ret = true;
> >> + break;
> >> + }
> >> + }
> >> +
> >> + of_node_put(np);
> >> +
> >> + return ret;
> >> +}
> >
> > So, I am still failing to see why this is really needed.
> >
> > Why can't you simply resolve this with different compatibles?
> > If the sensor is not present or disabled, the compatible is not, well,
> > compatible anymore.
>
> This driver can support three Tegra chip t124, t132 and t210. And we
> also support some platforms for every chips. As the description in the
> commit, different platforms may not support all 4 sensors, so I
> upstreamed this patch.
ok.. Which means, all platforms need to have a proper DT that describes
the correct amount of sensors.
> If we use different compatibles, I think we can't resolve it simply,
> because we also need to add codes to configure which platform support
> which sensors, and may add more in the future. If use this patch, we
There is a very common way of solving this, you can pass .data and grab
after calling of_node_match(), just like the tegra soc thermal driver
already does.
> doesn't need to do any more in the future.
Well, if the patch is needed to add support for different versions of
your sensor block, then there is no reason why not patching.
> Actually in my original change, I just ignore the registration failure
> to fix this issue, it will not affect loading driver, but as Daniel's
> comment, it's not better to ignore, so I followed his comment to refer
It is not good to ignore. The correct thing to do here is for tegra to
have correct DT entries for each sensor block version, to correctly
represent the amount of sensors present in the RTL, then you reflect
that in device driver using compatible. This way you wont need to ignore
failures, and you will support the correct amount of sensors for each
block version.
> the QORIQ thermal driver to get the sensor id.
>
I am not sure that is a good example to follow.
> Thanks.
> Wei.
>
> >
> >> +
> >> static const struct of_device_id tegra_soctherm_of_match[] = {
> >> #ifdef CONFIG_ARCH_TEGRA_124_SOC
> >> {
> >> @@ -1365,13 +1400,16 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
> >> zone->sg = soc->ttgs[i];
> >> zone->ts = tegra;
> >>
> >> + if (!tegra_soctherm_find_sensor_id(soc->ttgs[i]->id))
> >> + continue;
> >> +
> >> z = devm_thermal_zone_of_sensor_register(&pdev->dev,
> >> soc->ttgs[i]->id, zone,
> >> &tegra_of_thermal_ops);
> >> if (IS_ERR(z)) {
> >> err = PTR_ERR(z);
> >> - dev_err(&pdev->dev, "failed to register sensor: %d\n",
> >> - err);
> >> + dev_err(&pdev->dev, "failed to register sensor %s: %d\n",
> >> + soc->ttgs[i]->name, err);
> >> goto disable_clocks;
> >> }
> >>
> >> @@ -1434,6 +1472,9 @@ static int __maybe_unused soctherm_resume(struct device *dev)
> >> struct thermal_zone_device *tz;
> >>
> >> tz = tegra->thermctl_tzs[soc->ttgs[i]->id];
> >> + if (!tz)
> >> + continue;
> >> +
> >> err = tegra_soctherm_set_hwtrips(dev, soc->ttgs[i], tz);
> >> if (err) {
> >> dev_err(&pdev->dev,
> >> --
> >> 2.7.4
> >>
On 19/12/2018 10:57 PM, Eduardo Valentin wrote:
> On Wed, Dec 19, 2018 at 11:00:10AM +0800, Wei Ni wrote:
>>
>>
>> On 19/12/2018 9:24 AM, Eduardo Valentin wrote:
>>> On Fri, Dec 14, 2018 at 05:49:52PM +0800, Wei Ni wrote:
>>>> Since different platforms may not support all 4
>>>> sensors, so the sensor registration may be failed.
>>>> Add codes to parse dt to find sensor id which
>>>> need to be registered. So that the registration
>>>> can be successful on all platform.
>>>>
>>>> Signed-off-by: Wei Ni <[email protected]>
>>>> ---
>>>> drivers/thermal/tegra/soctherm.c | 45 ++++++++++++++++++++++++++++++++++++++--
>>>> 1 file changed, 43 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
>>>> index fd2703c0cfc5..6bee31cd4621 100644
>>>> --- a/drivers/thermal/tegra/soctherm.c
>>>> +++ b/drivers/thermal/tegra/soctherm.c
>>>> @@ -1224,6 +1224,41 @@ static void soctherm_init(struct platform_device *pdev)
>>>> tegra_soctherm_throttle(&pdev->dev);
>>>> }
>>>>
>>>> +static bool tegra_soctherm_find_sensor_id(unsigned int sensor_id)
>>>> +{
>>>> + bool ret = false;
>>>> + struct of_phandle_args sensor_specs;
>>>> + struct device_node *np, *sensor_np;
>>>> +
>>>> + np = of_find_node_by_name(NULL, "thermal-zones");
>>>> + if (!np)
>>>> + return ret;
>>>> +
>>>> + for_each_available_child_of_node(np, sensor_np) {
>>>> + if (of_parse_phandle_with_args(sensor_np, "thermal-sensors",
>>>> + "#thermal-sensor-cells",
>>>> + 0, &sensor_specs))
>>>> + continue;
>>>> +
>>>> + if (sensor_specs.args_count != 1) {
>>>> + WARN(sensor_specs.args_count != 1,
>>>> + "%s: wrong cells in sensor specifier %d\n",
>>>> + sensor_specs.np->name, sensor_specs.args_count);
>>>> + continue;
>>>> + }
>>>> +
>>>> + if (sensor_specs.args[0] == sensor_id) {
>>>> + of_node_put(sensor_np);
>>>> + ret = true;
>>>> + break;
>>>> + }
>>>> + }
>>>> +
>>>> + of_node_put(np);
>>>> +
>>>> + return ret;
>>>> +}
>>>
>>> So, I am still failing to see why this is really needed.
>>>
>>> Why can't you simply resolve this with different compatibles?
>>> If the sensor is not present or disabled, the compatible is not, well,
>>> compatible anymore.
>>
>> This driver can support three Tegra chip t124, t132 and t210. And we
>> also support some platforms for every chips. As the description in the
>> commit, different platforms may not support all 4 sensors, so I
>> upstreamed this patch.
>
> ok.. Which means, all platforms need to have a proper DT that describes
> the correct amount of sensors.
Thanks for your comments.
I thought about it carefully again, and found we doesn't need to change
any codes for this issue.
In the DT, actually the node "thermal-zones{} already describes the
correct sensors, so we doesn't need to add more changes in DT.
>
>> If we use different compatibles, I think we can't resolve it simply,
>> because we also need to add codes to configure which platform support
>> which sensors, and may add more in the future. If use this patch, we
>
> There is a very common way of solving this, you can pass .data and grab
> after calling of_node_match(), just like the tegra soc thermal driver
> already does.
Yes, for the driver, we just need to add a new file, something like
tegra210-soctherm.c, to configure a new platform, which can remove the
configuration for the disabled sensor, so that the soctherm driver will
not try to register that sensors anymore.
>
>> doesn't need to do any more in the future.
>
> Well, if the patch is needed to add support for different versions of
> your sensor block, then there is no reason why not patching.
Since in current released platforms, they support all 4 sensors, so I
will not send new patches by now.
So please ignore this change.
And will you take other 3 changes?
Thanks.
Wei.
>
>> Actually in my original change, I just ignore the registration failure
>> to fix this issue, it will not affect loading driver, but as Daniel's
>> comment, it's not better to ignore, so I followed his comment to refer
>
> It is not good to ignore. The correct thing to do here is for tegra to
> have correct DT entries for each sensor block version, to correctly
> represent the amount of sensors present in the RTL, then you reflect
> that in device driver using compatible. This way you wont need to ignore
> failures, and you will support the correct amount of sensors for each
> block version.
>
>> the QORIQ thermal driver to get the sensor id.
>>
>
> I am not sure that is a good example to follow.
>
>> Thanks.
>> Wei.
>>
>>>
>>>> +
>>>> static const struct of_device_id tegra_soctherm_of_match[] = {
>>>> #ifdef CONFIG_ARCH_TEGRA_124_SOC
>>>> {
>>>> @@ -1365,13 +1400,16 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
>>>> zone->sg = soc->ttgs[i];
>>>> zone->ts = tegra;
>>>>
>>>> + if (!tegra_soctherm_find_sensor_id(soc->ttgs[i]->id))
>>>> + continue;
>>>> +
>>>> z = devm_thermal_zone_of_sensor_register(&pdev->dev,
>>>> soc->ttgs[i]->id, zone,
>>>> &tegra_of_thermal_ops);
>>>> if (IS_ERR(z)) {
>>>> err = PTR_ERR(z);
>>>> - dev_err(&pdev->dev, "failed to register sensor: %d\n",
>>>> - err);
>>>> + dev_err(&pdev->dev, "failed to register sensor %s: %d\n",
>>>> + soc->ttgs[i]->name, err);
>>>> goto disable_clocks;
>>>> }
>>>>
>>>> @@ -1434,6 +1472,9 @@ static int __maybe_unused soctherm_resume(struct device *dev)
>>>> struct thermal_zone_device *tz;
>>>>
>>>> tz = tegra->thermctl_tzs[soc->ttgs[i]->id];
>>>> + if (!tz)
>>>> + continue;
>>>> +
>>>> err = tegra_soctherm_set_hwtrips(dev, soc->ttgs[i], tz);
>>>> if (err) {
>>>> dev_err(&pdev->dev,
>>>> --
>>>> 2.7.4
>>>>