2015-11-25 05:42:38

by Kuninori Morimoto

[permalink] [raw]
Subject: [PATCH] thermal: rcar: add .set_trip_temp support


From: Kuninori Morimoto <[email protected]>

You can set trip temp if your kernel has CONFIG_THERMAL_WRITABLE_TRIPS

echo $temp > /sys/class/thermal/thermal_zone0/trip_point_0_temp

-45000 < $temp < 125000 is supported
Default is 90000

Signed-off-by: Kuninori Morimoto <[email protected]>
---
This patch is v2 of "[PATCH] thermal: rcar: enable to set tripN-temp via DT"
I think it will be full-DT feature if it uses of-thermal, but this driver is used
from non-DT SoC too. We would like to keep non-DT support.
And we would like to do is only exchange trip temp.
.set_trip_temp is very enouth for it at this point.
But, it can use of-thermal feature in the future.

drivers/thermal/rcar_thermal.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 5d4ae7d..1eaa1be 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -63,6 +63,7 @@ struct rcar_thermal_priv {
struct mutex lock;
struct list_head list;
int id;
+ int trip_temp;
u32 ctemp;
};

@@ -222,7 +223,7 @@ static int rcar_thermal_get_trip_type(struct thermal_zone_device *zone,

/* see rcar_thermal_get_temp() */
switch (trip) {
- case 0: /* +90 <= temp */
+ case 0:
*type = THERMAL_TRIP_CRITICAL;
break;
default:
@@ -241,8 +242,8 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,

/* see rcar_thermal_get_temp() */
switch (trip) {
- case 0: /* +90 <= temp */
- *temp = MCELSIUS(90);
+ case 0:
+ *temp = priv->trip_temp;
break;
default:
dev_err(dev, "rcar driver trip error\n");
@@ -270,10 +271,27 @@ static int rcar_thermal_notify(struct thermal_zone_device *zone,
return 0;
}

+static int rcar_thermal_set_trip_temp(struct thermal_zone_device *zone,
+ int trip, int temp)
+{
+ struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
+
+ if (trip != 0)
+ return -EINVAL;
+
+ if (temp < -45000 || temp > 125000)
+ return -EINVAL;
+
+ priv->trip_temp = temp;
+
+ return 0;
+}
+
static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
.get_temp = rcar_thermal_get_temp,
.get_trip_type = rcar_thermal_get_trip_type,
.get_trip_temp = rcar_thermal_get_trip_temp,
+ .set_trip_temp = rcar_thermal_set_trip_temp,
.notify = rcar_thermal_notify,
};

@@ -418,13 +436,14 @@ static int rcar_thermal_probe(struct platform_device *pdev)

priv->common = common;
priv->id = i;
+ priv->trip_temp = MCELSIUS(90); /* default*/
mutex_init(&priv->lock);
INIT_LIST_HEAD(&priv->list);
INIT_DELAYED_WORK(&priv->work, rcar_thermal_work);
rcar_thermal_update_temp(priv);

priv->zone = thermal_zone_device_register("rcar_thermal",
- 1, 0, priv,
+ 1, 1, priv,
&rcar_thermal_zone_ops, NULL, 0,
idle);
if (IS_ERR(priv->zone)) {
--
1.9.1


2015-11-30 18:51:07

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH] thermal: rcar: add .set_trip_temp support

On Wed, Nov 25, 2015 at 05:42:27AM +0000, Kuninori Morimoto wrote:
>
> From: Kuninori Morimoto <[email protected]>
>
> You can set trip temp if your kernel has CONFIG_THERMAL_WRITABLE_TRIPS
>
> echo $temp > /sys/class/thermal/thermal_zone0/trip_point_0_temp
>
> -45000 < $temp < 125000 is supported
> Default is 90000
>
> Signed-off-by: Kuninori Morimoto <[email protected]>
> ---
> This patch is v2 of "[PATCH] thermal: rcar: enable to set tripN-temp via DT"
> I think it will be full-DT feature if it uses of-thermal, but this driver is used
> from non-DT SoC too. We would like to keep non-DT support.
> And we would like to do is only exchange trip temp.
> .set_trip_temp is very enouth for it at this point.
> But, it can use of-thermal feature in the future.

Kuninori,


According to discussion on your first version [1], this patch is not needed
anymore, right?

If you want to add the support for writable trip points, please, add the
support to of-thermal, as this driver supports only DT booting boards.


[1] - https://lkml.org/lkml/2015/11/25/888
>

2015-12-01 03:00:29

by Kuninori Morimoto

[permalink] [raw]
Subject: Re: [PATCH] thermal: rcar: add .set_trip_temp support


Hi Eduardo

> According to discussion on your first version [1], this patch is not needed
> anymore, right?
>
> If you want to add the support for writable trip points, please, add the
> support to of-thermal, as this driver supports only DT booting boards.

Thanks. I will investigate it.