Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: rcar: enable to use thermal-zone on DT

This patch enables to use thermal-zone on DT if it was calles as
"renesas,rcar-thermal-gen2".
Previous style (= non thermal-zone) is still supported by
"renesas,rcar-thermal" to keep compatibility for "git bisect".

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>

authored by

Kuninori Morimoto and committed by
Eduardo Valentin
8b477ea5 42bbe400

+75 -7
+35 -2
Documentation/devicetree/bindings/thermal/rcar-thermal.txt
··· 1 1 * Renesas R-Car Thermal 2 2 3 3 Required properties: 4 - - compatible : "renesas,thermal-<soctype>", "renesas,rcar-thermal" 5 - as fallback. 4 + - compatible : "renesas,thermal-<soctype>", 5 + "renesas,rcar-gen2-thermal" (with thermal-zone) or 6 + "renesas,rcar-thermal" (without thermal-zone) as fallback. 6 7 Examples with soctypes are: 7 8 - "renesas,thermal-r8a73a4" (R-Mobile APE6) 8 9 - "renesas,thermal-r8a7779" (R-Car H1) ··· 36 35 0xe61f0200 0x38 37 36 0xe61f0300 0x38>; 38 37 interrupts = <0 69 IRQ_TYPE_LEVEL_HIGH>; 38 + }; 39 + 40 + Example (with thermal-zone): 41 + 42 + thermal-zones { 43 + cpu_thermal: cpu-thermal { 44 + polling-delay-passive = <1000>; 45 + polling-delay = <5000>; 46 + 47 + thermal-sensors = <&thermal>; 48 + 49 + trips { 50 + cpu-crit { 51 + temperature = <115000>; 52 + hysteresis = <0>; 53 + type = "critical"; 54 + }; 55 + }; 56 + cooling-maps { 57 + }; 58 + }; 59 + }; 60 + 61 + thermal: thermal@e61f0000 { 62 + compatible = "renesas,thermal-r8a7790", 63 + "renesas,rcar-gen2-thermal", 64 + "renesas,rcar-thermal"; 65 + reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>; 66 + interrupts = <0 69 IRQ_TYPE_LEVEL_HIGH>; 67 + clocks = <&mstp5_clks R8A7790_CLK_THERMAL>; 68 + power-domains = <&cpg_clocks>; 69 + #thermal-sensor-cells = <0>; 39 70 };
+40 -5
drivers/thermal/rcar_thermal.c
··· 23 23 #include <linux/interrupt.h> 24 24 #include <linux/io.h> 25 25 #include <linux/module.h> 26 + #include <linux/of_device.h> 26 27 #include <linux/platform_device.h> 27 28 #include <linux/pm_runtime.h> 28 29 #include <linux/reboot.h> ··· 76 75 #define rcar_has_irq_support(priv) ((priv)->common->base) 77 76 #define rcar_id_to_shift(priv) ((priv)->id * 8) 78 77 78 + #define USE_OF_THERMAL 1 79 79 static const struct of_device_id rcar_thermal_dt_ids[] = { 80 80 { .compatible = "renesas,rcar-thermal", }, 81 + { .compatible = "renesas,rcar-gen2-thermal", .data = (void *)USE_OF_THERMAL }, 81 82 {}, 82 83 }; 83 84 MODULE_DEVICE_TABLE(of, rcar_thermal_dt_ids); ··· 203 200 return ret; 204 201 } 205 202 206 - static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp) 203 + static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv, 204 + int *temp) 207 205 { 208 - struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone); 209 206 int tmp; 210 207 int ret; 211 208 ··· 227 224 *temp = tmp; 228 225 229 226 return 0; 227 + } 228 + 229 + static int rcar_thermal_of_get_temp(void *data, int *temp) 230 + { 231 + struct rcar_thermal_priv *priv = data; 232 + 233 + return rcar_thermal_get_current_temp(priv, temp); 234 + } 235 + 236 + static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp) 237 + { 238 + struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone); 239 + 240 + return rcar_thermal_get_current_temp(priv, temp); 230 241 } 231 242 232 243 static int rcar_thermal_get_trip_type(struct thermal_zone_device *zone, ··· 299 282 return 0; 300 283 } 301 284 285 + static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = { 286 + .get_temp = rcar_thermal_of_get_temp, 287 + }; 288 + 302 289 static struct thermal_zone_device_ops rcar_thermal_zone_ops = { 303 290 .get_temp = rcar_thermal_get_temp, 304 291 .get_trip_type = rcar_thermal_get_trip_type, ··· 339 318 340 319 priv = container_of(work, struct rcar_thermal_priv, work.work); 341 320 342 - rcar_thermal_get_temp(priv->zone, &cctemp); 321 + ret = rcar_thermal_get_current_temp(priv, &cctemp); 322 + if (ret < 0) 323 + return; 324 + 343 325 ret = rcar_thermal_update_temp(priv); 344 326 if (ret < 0) 345 327 return; 346 328 347 329 rcar_thermal_irq_enable(priv); 348 330 349 - rcar_thermal_get_temp(priv->zone, &nctemp); 331 + ret = rcar_thermal_get_current_temp(priv, &nctemp); 332 + if (ret < 0) 333 + return; 334 + 350 335 if (nctemp != cctemp) 351 336 thermal_zone_device_update(priv->zone); 352 337 } ··· 430 403 struct rcar_thermal_priv *priv; 431 404 struct device *dev = &pdev->dev; 432 405 struct resource *res, *irq; 406 + const struct of_device_id *of_id = of_match_device(rcar_thermal_dt_ids, dev); 407 + unsigned long of_data = (unsigned long)of_id->data; 433 408 int mres = 0; 434 409 int i; 435 410 int ret = -ENODEV; ··· 492 463 if (ret < 0) 493 464 goto error_unregister; 494 465 495 - priv->zone = thermal_zone_device_register("rcar_thermal", 466 + if (of_data == USE_OF_THERMAL) 467 + priv->zone = thermal_zone_of_sensor_register( 468 + dev, i, priv, 469 + &rcar_thermal_zone_of_ops); 470 + else 471 + priv->zone = thermal_zone_device_register( 472 + "rcar_thermal", 496 473 1, 0, priv, 497 474 &rcar_thermal_zone_ops, NULL, 0, 498 475 idle);