From: Kuninori Morimoto <kuninori.morimoto...@renesas.com>

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 <kuninori.morimoto...@renesas.com>
---
  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

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to