Add a generic virtual thermal sensor
Subsystems (2)
v3 cover Add a generic virtual thermal sensor
This series add a virtual thermal sensor.
It could be used to get a temperature using some thermal sensors. Currently, the supported operations are max, min and avg.
The virtual sensor could be easily extended to support others operations.
Changes in v2:
- Fix some warnings / errors reported by kernel test robot
- rename some struct and functions with a more accurate name
- update the dt bindings: rename type attribute to aggregation-function
- factorize a little bit the aggregation functions
Changes in v3:
- Aggregate thermal zone instead of thermal sensors
- Use try_get_module / put_module to prevent thermal providers to be removed
- Update the bindings, to be more accurate
Alexandre Bailon (2):
dt-bindings: Add DT bindings for the DT-based virtual sensor driver
thermal: add a virtual sensor to aggregate temperatures
.../thermal/virtual,thermal-sensor.yaml | 80 +++++++ drivers/thermal/Kconfig | 8 + drivers/thermal/Makefile | 1 + drivers/thermal/virtual_thermal_sensor.c | 219 ++++++++++++++++++ include/dt-bindings/thermal/virtual-sensor.h | 15 ++ 5 files changed, 323 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/virtual,thermal-sensor.yaml create mode 100644 drivers/thermal/virtual_thermal_sensor.c create mode 100644 include/dt-bindings/thermal/virtual-sensor.h
Signature · 1 line
2.32.0
PATCH v3 1/2 dt-bindings: Add DT bindings for the DT-based virtual sensor driver
This adds the DT bindings for the DT-based virtual sensor driver. This driver provides a way, using DT, to aggregate the temperature of multiple thermal zones and get some useful data from it.
--- .../thermal/virtual,thermal-sensor.yaml | 86 +++++++++++++++++++ include/dt-bindings/thermal/virtual-sensor.h | 15 ++++ 2 files changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/virtual,thermal-sensor.yaml create mode 100644 include/dt-bindings/thermal/virtual-sensor.h
Documentation/devicetree/bindings/thermal/virtual,thermal-sensor.yaml new file +86 -0
@@ -0,0 +1,86 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2021 BayLibre +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/virtual,thermal-sensor.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Virtual thermal sensor binding + +maintainers: + - Alexandre Bailon <[email protected]> + +description: | + The virtual thermal sensor device provides a way to aggregate the temperature + from multiple thermal zones. Basically, this could be used to get the + maximum, minimum or average temperature. + +allOf: + - $ref: thermal-sensor.yaml# + +properties: + compatible: + const: virtual,thermal-sensor + + aggregation-function: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Used to select the operations to perform on the sensors to get the virtual + sensor temperature. + enum: + - VIRTUAL_THERMAL_SENSOR_MIN_VAL + - VIRTUAL_THERMAL_SENSOR_MAX_VAL + - VIRTUAL_THERMAL_SENSOR_AVG_VAL + + thermal-sensors: + $ref: /schemas/types.yaml#/definitions/string-array + description: + The names of the thermal zone to aggregate. + +required: + - aggregation-function + - thermal-sensors + +additionalProperties: true + +examples: + - | + #include <dt-bindings/thermal/thermal.h> + #include <dt-bindings/thermal/virtual-sensor.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/mt8192-clk.h> + + lvts: lvts@1100b000 { + compatible = "mediatek,mt6873-lvts"; + reg = <0x1100b000 0x1000>; + clocks = <&infracfg CLK_INFRA_THERM>; + clock-names = "lvts_clk"; + #thermal-sensor-cells = <1>; + interrupts = <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>; + }; + + cpu_max_sensor: cpu_max_sensor { + compatible = "virtual,thermal-sensor"; + #thermal-sensor-cells = <1>; + aggregation-function = <VIRTUAL_THERMAL_SENSOR_MAX_VAL>; + thermal-sensors = "cpu1", "cpu2"; + }; + + thermal_zones: thermal-zones { + cpu1 { + polling-delay = <0>; /* milliseconds */ + polling-delay-passive = <0>; /* milliseconds */ + thermal-sensors = <&lvts 0>; + }; + cpu2 { + polling-delay = <0>; /* milliseconds */ + polling-delay-passive = <0>; /* milliseconds */ + thermal-sensors = <&lvts 1>; + }; + cpu_max { + polling-delay = <0>; /* milliseconds */ + polling-delay-passive = <0>; /* milliseconds */ + thermal-sensors = <&cpu_max_sensor 0>; + }; + }; +...
include/dt-bindings/thermal/virtual-sensor.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* This header provides constants for virtual thermal sensor bindings. +* +* Copyright (C) 2021 BayLibre +*/ + +#ifndef _DT_BINDINGS_THERMAL_VIRTUAL_SENSOR_H +#define _DT_BINDINGS_THERMAL_VIRTUAL_SENSOR_H + +#define VIRTUAL_THERMAL_SENSOR_MIN_VAL 0 +#define VIRTUAL_THERMAL_SENSOR_MAX_VAL 1 +#define VIRTUAL_THERMAL_SENSOR_AVG_VAL 2 + +#endif /* _DT_BINDINGS_THERMAL_VIRTUAL_SENSOR_H */
Signature · 1 line
2.32.0
PATCH v3 2/2 thermal: add a virtual sensor to aggregate temperatures
In reply to Alexandre BailonThis adds a virtual thermal sensor driver that reads temperature from multiple hardware sensors and returns an aggregated temperature. Currently, this supports three aggregations:
the minimum, maximum and average temperature.
--- drivers/thermal/Kconfig | 8 + drivers/thermal/Makefile | 1 + drivers/thermal/virtual_thermal_sensor.c | 218 +++++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 drivers/thermal/virtual_thermal_sensor.c
drivers/thermal/Kconfig +8 -0
@@ -228,6 +228,14 @@ config THERMAL_MMIO register or shared memory, is a potential candidate to work with this driver. +config VIRTUAL_THERMAL + tristate "DT-based virtual thermal sensor driver" + depends on THERMAL_OF || COMPILE_TEST + help + This option enables the generic DT-based thermal sensor aggregator. + This driver creates a thermal sensor that reads multiple hardware + sensors and aggregates their output. + config HISI_THERMAL tristate "Hisilicon thermal driver" depends on ARCH_HISI || COMPILE_TEST
drivers/thermal/Makefile +1 -0
@@ -60,3 +60,4 @@ obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o obj-$(CONFIG_AMLOGIC_THERMAL) += amlogic_thermal.o obj-$(CONFIG_SPRD_THERMAL) += sprd_thermal.o obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL) += khadas_mcu_fan.o +obj-$(CONFIG_VIRTUAL_THERMAL) += virtual_thermal_sensor.o
drivers/thermal/virtual_thermal_sensor.c new file +218 -0
218 lines not on this page · raw message
Signature · 1 line
2.32.0
kernel test robot
build botRe: [PATCH v3 2/2] thermal: add a virtual sensor to aggregate temperatures
Thank you for the patch! Yet something to improve:
Hi Alexandre,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on rafael-pm/thermal]
[also build test ERROR on v5.15-rc7 next-20211029]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Alexandre-Bailon/Add-a-generic-virtual-thermal-sensor/20211029-231137 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal config: arc-allyesconfig (attached as .config) compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/be0e058f9a82f32140e4e96cf67a3e0842da9f70
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alexandre-Bailon/Add-a-generic-virtual-thermal-sensor/20211029-231137 git checkout be0e058f9a82f32140e4e96cf67a3e0842da9f70
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=arc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/thermal/virtual_thermal_sensor.c:73:5: error: no previous prototype for 'virtual_thermal_sensor_get_module' [-Werror=missing-prototypes]
73 | int virtual_thermal_sensor_get_module(struct virtual_thermal_zone_device *zone,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/thermal/virtual_thermal_sensor.c:102:6: error: no previous prototype for 'virtual_thermal_sensor_put_modules' [-Werror=missing-prototypes] 102 | void virtual_thermal_sensor_put_modules(struct virtual_thermal_sensor *sensor)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
vim +/virtual_thermal_sensor_get_module +73 drivers/thermal/virtual_thermal_sensor.c
72
> 73 int virtual_thermal_sensor_get_module(struct virtual_thermal_zone_device *zone,
74 const char *name)
75 {
76 struct platform_device *sensor_pdev;
77 struct device_node *node;
78
79 node = of_find_node_by_name(NULL, name);
80 if (!node)
81 return -ENODEV;
82
83 node = of_parse_phandle(node, "thermal-sensors", 0);
84 if (!node)
85 return -ENODEV;
86
87 sensor_pdev = of_find_device_by_node(node);
88 if (!sensor_pdev)
89 return -ENODEV;
90
91 if (!sensor_pdev->dev.driver)
92 return -EPROBE_DEFER;
93
94 if (!try_module_get(sensor_pdev->dev.driver->owner))
95 return -ENODEV;
96
97 zone->owner = sensor_pdev->dev.driver->owner;
98
99 return 0;
100 }
101
> 102 void virtual_thermal_sensor_put_modules(struct virtual_thermal_sensor *sensor) 103 {
104 int i;
105
106 for (i = 0; i < sensor->count; i++) {
107 if (sensor->zones[i].zone)
108 module_put(sensor->zones[i].owner);
109 }
110 }
111
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v3 2/2] thermal: add a virtual sensor to aggregate temperatures
In reply to Alexandre BailonThank you for the patch! Perhaps something to improve:
Hi Alexandre,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/thermal]
[also build test WARNING on v5.15 next-20211108]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Alexandre-Bailon/Add-a-generic-virtual-thermal-sensor/20211029-231137 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal config: i386-allmodconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/be0e058f9a82f32140e4e96cf67a3e0842da9f70 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Alexandre-Bailon/Add-a-generic-virtual-thermal-sensor/20211029-231137 git checkout be0e058f9a82f32140e4e96cf67a3e0842da9f70 # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/thermal/virtual_thermal_sensor.c:73:5: warning: no previous prototype for 'virtual_thermal_sensor_get_module' [-Wmissing-prototypes]
73 | int virtual_thermal_sensor_get_module(struct virtual_thermal_zone_device *zone,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/thermal/virtual_thermal_sensor.c:102:6: warning: no previous prototype for 'virtual_thermal_sensor_put_modules' [-Wmissing-prototypes] 102 | void virtual_thermal_sensor_put_modules(struct virtual_thermal_sensor *sensor)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/virtual_thermal_sensor_get_module +73 drivers/thermal/virtual_thermal_sensor.c
72
> 73 int virtual_thermal_sensor_get_module(struct virtual_thermal_zone_device *zone,
74 const char *name)
75 {
76 struct platform_device *sensor_pdev;
77 struct device_node *node;
78
79 node = of_find_node_by_name(NULL, name);
80 if (!node)
81 return -ENODEV;
82
83 node = of_parse_phandle(node, "thermal-sensors", 0);
84 if (!node)
85 return -ENODEV;
86
87 sensor_pdev = of_find_device_by_node(node);
88 if (!sensor_pdev)
89 return -ENODEV;
90
91 if (!sensor_pdev->dev.driver)
92 return -EPROBE_DEFER;
93
94 if (!try_module_get(sensor_pdev->dev.driver->owner))
95 return -ENODEV;
96
97 zone->owner = sensor_pdev->dev.driver->owner;
98
99 return 0;
100 }
101
> 102 void virtual_thermal_sensor_put_modules(struct virtual_thermal_sensor *sensor) 103 {
104 int i;
105
106 for (i = 0; i < sensor->count; i++) {
107 if (sensor->zones[i].zone)
108 module_put(sensor->zones[i].owner);
109 }
110 }
111
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org