dt-bindings: thermal: Add support for Airoha EN7581 thermal sensor
Subsystems (2)
PATCH v3 1/3 dt-bindings: thermal: Add support for Airoha EN7581 thermal sensor
Add support for Airoha EN7581 thermal sensor and monitor. This is a simple sensor for the CPU or SoC Package that provide thermal sensor and trip point for hot low and critical condition to fire interrupt and react on the abnormal state.
---
Changes v2:
- Add Reviewed-by tag
.../thermal/airoha,en7581-thermal.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/airoha,en7581-thermal.yaml
Documentation/devicetree/bindings/thermal/airoha,en7581-thermal.yaml new file +48 -0
@@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/airoha,en7581-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha EN7581 Thermal Sensor and Monitor + +maintainers: + - Christian Marangi <[email protected]> + +properties: + compatible: + const: airoha,en7581-thermal + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + airoha,chip-scu: + description: phandle to the chip SCU syscon + $ref: /schemas/types.yaml#/definitions/phandle + + '#thermal-sensor-cells': + const: 0 + +required: + - compatible + - reg + - interrupts + - airoha,chip-scu + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + thermal-sensor@1efbd800 { + compatible = "airoha,en7581-thermal"; + reg = <0x1efbd000 0xd5c>; + interrupts = <GIC_SPI 23 IRQ_TYPE_LEVEL_HIGH>; + airoha,chip-scu = <&chip_scu>; + + #thermal-sensor-cells = <0>; + };
Signature · 1 line
2.45.2
PATCH v3 2/3 thermal: of: Add devm_thermal_of_zone_register_with_params() variant
Commit b1ae92dcfa8e ("thermal: core: Make struct thermal_zone_device definition internal") moved the thermal_zone_device struct from global thermal.h to internal thermal_core.h making the internal variables of the struct not accessible from the user drivers (without inclusing thermal_core.h).
One case where the internal variables might be needed is for the thermal_zone_params in the context of OF probe.
In such case a thermal driver might have default params that can only be parsed at runtime (example present in EFUSE or derived from other values) and wants to update the values in the thermal_zone_params for the thermal device. (to use the helper like get_slope() or get_offset())
To account for this scenario, introduce a variant of devm_thermal_of_zone_register(), devm_thermal_of_zone_register_with_params(), that takes and additional variable and permits to register the thermal device with default thermal_zone_params.
To follow OF implementation, these params are only treated as default params and are ignored if a related one is defined in DT. (example a slope or offset value defined in DT have priority to the default one passed in a thermal_device_params struct)
This permits to support both implementation, use the helpers and expose these values in sysfs.
---
Changes v3:
- Add this patch
drivers/thermal/thermal_of.c | 67 +++++++++++++++++++++++++++++------- include/linux/thermal.h | 13 +++++++ 2 files changed, 68 insertions(+), 12 deletions(-)
drivers/thermal/thermal_of.c +55 -12
@@ -250,7 +250,7 @@ static void thermal_of_parameters_init(struct device_node *np, {int coef[2 ];int ncoef =ARRAY_SIZE (coef); -int prop, ret; +int prop; tzp->no_hwmon = true;
@@ -262,14 +262,11 @@ static void thermal_of_parameters_init(struct device_node *np,* thermal zone. Thus, we are considering only the first two * values as slope and offset. */ - ret =of_property_read_u32_array (np,"coefficients" , coef, ncoef); -if (ret) { - coef[0 ] =1 ; - coef[1 ] =0 ; +if (!of_property_read_u32_array (np,"coefficients" , coef, ncoef)) { + tzp->slope = coef[0 ]; + tzp->offset = coef[1 ]; } - tzp->slope = coef[0 ]; - tzp->offset = coef[1 ]; }static struct device_node *thermal_of_zone_get_by_name (struct thermal_zone_device *tz)
@@ -458,10 +455,15 @@ static void thermal_of_zone_unregister(struct thermal_zone_device *tz)* zone properties and registers new thermal zone with those * properties. * +* The passed thermal zone params are treated as default values and ignored if +* the related property is found in DT. (DT params have priority to +* default values) +* * @sensor: A device node pointer corresponding to the sensor in the device tree * @id: An integer as sensor identifier * @data: A private data to be stored in the thermal zone dedicated private area * @ops: A set of thermal sensor ops +* @tzp: a pointer to the default thermal zone params structure associated with the sensor * * Return: a valid thermal zone structure pointer on success. * - EINVAL: if the device tree thermal description is malformed
@@ -469,12 +471,12 @@ static void thermal_of_zone_unregister(struct thermal_zone_device *tz)* - Other negative errors are returned by the underlying called functions */ static struct thermal_zone_device *thermal_of_zone_register (struct device_node *sensor,int id,void *data, -const struct thermal_zone_device_ops *ops) +const struct thermal_zone_device_ops *ops, +struct thermal_zone_params *tzp) {struct thermal_zone_device_ops of_ops = *ops;struct thermal_zone_device *tz;struct thermal_trip *trips; -struct thermal_zone_params tzp = {};struct device_node *np;const char *action;int delay, pdelay;
@@ -500,7 +502,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * goto out_kfree_trips; } -thermal_of_parameters_init (np, &tzp); +thermal_of_parameters_init (np, tzp); of_ops.bind = thermal_of_bind; of_ops.unbind = thermal_of_unbind;
@@ -511,7 +513,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * of_ops.critical = thermal_zone_device_critical_reboot; tz =thermal_zone_device_register_with_trips (np->name, trips, ntrips, - data, &of_ops, &tzp, + data, &of_ops, tzp, pdelay, delay);if (IS_ERR (tz)) { ret =PTR_ERR (tz);
@@ -566,6 +568,7 @@ static int devm_thermal_of_zone_match(struct device *dev, void *res,struct thermal_zone_device *devm_thermal_of_zone_register (struct device *dev,int sensor_id,void *data,const struct thermal_zone_device_ops *ops) { +struct thermal_zone_params tzp = { .slope =1 };struct thermal_zone_device **ptr, *tzd; ptr = devres_alloc(devm_thermal_of_zone_release, sizeof(*ptr),
@@ -573,7 +576,7 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, inif (!ptr)return ERR_PTR (-ENOMEM ); - tzd =thermal_of_zone_register (dev->of_node, sensor_id, data, ops); + tzd =thermal_of_zone_register (dev->of_node, sensor_id, data, ops, &tzp);if (IS_ERR (tzd)) {devres_free (ptr);return tzd;
@@ -586,6 +589,46 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, in }EXPORT_SYMBOL_GPL (devm_thermal_of_zone_register); +/** +* devm_thermal_of_zone_register_with_params - register a thermal tied with the sensor life cycle +* with default params +* +* This function is the device version of the thermal_of_zone_register() function. +* +* @dev: a device structure pointer to sensor to be tied with the thermal zone OF life cycle +* @sensor_id: the sensor identifier +* @data: a pointer to a private data to be stored in the thermal zone 'devdata' field +* @ops: a pointer to the ops structure associated with the sensor +* @tzp: a pointer to the default thermal zone params structure associated with the sensor +* +* The thermal zone params are treated as default values and ignored if the related property is +* found in DT. (DT params have priority to default values) +*/ +struct thermal_zone_device *devm_thermal_of_zone_register_with_params (struct device *dev,int sensor_id, +void *data, +const struct thermal_zone_device_ops *ops, +struct thermal_zone_params *tzp) +{ +struct thermal_zone_device **ptr, *tzd; + + ptr =devres_alloc (devm_thermal_of_zone_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + tzd =thermal_of_zone_register (dev->of_node, sensor_id, data, ops, tzp); +if (IS_ERR (tzd)) { +devres_free (ptr); +return tzd; + } + + *ptr = tzd; +devres_add (dev, ptr); + +return tzd; +} +EXPORT_SYMBOL_GPL (devm_thermal_of_zone_register_with_params); +/** * devm_thermal_of_zone_unregister - Resource managed version of * thermal_of_zone_unregister().
include/linux/thermal.h +13 -0
@@ -180,6 +180,10 @@ struct thermal_zone_params {#ifdef CONFIG_THERMAL_OF struct thermal_zone_device *devm_thermal_of_zone_register (struct device *dev,int id,void *data,const struct thermal_zone_device_ops *ops); +struct thermal_zone_device *devm_thermal_of_zone_register_with_params (struct device *dev,int id, +void *data, +const struct thermal_zone_device_ops *ops, +struct thermal_zone_params *tzp);void devm_thermal_of_zone_unregister (struct device *dev,struct thermal_zone_device *tz);
@@ -192,6 +196,15 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, inreturn ERR_PTR (-ENOTSUPP ); } +static inline +struct thermal_zone_device *devm_thermal_of_zone_register_with_params (struct device *dev,int id, +void *data, +const struct thermal_zone_device_ops *ops, +struct thermal_zone_params *tzp) +{ +return ERR_PTR (-ENOTSUPP ); +} +static inline void devm_thermal_of_zone_unregister (struct device *dev,struct thermal_zone_device *tz) {
Signature · 1 line
2.45.2
PATCH v3 3/3 thermal: Add support for Airoha EN7581 thermal sensor
In reply to Christian MarangiAdd support for Airoha EN7581 thermal sensor. This provide support for reading the CPU or SoC Package sensor and to setup trip points for hot and critical condition. An interrupt is fired to react on this and doesn't require passive poll to read the temperature.
The thermal regs provide a way to read the ADC value from an external register placed in the Chip SCU regs. Monitor will read this value and fire an interrupt if the trip condition configured is reached.
---
Changes v3:
- Handle thermal_zone_device moved in different header
- Enable interrupt after thermal register
- Use new way to provide slope and offset
Changes v2:
- Add missing Makefile and Kconfig entry (somehow not included in v1)
- Sort include header
- Add missing bitfield.h
drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 1 + drivers/thermal/airoha_thermal.c | 482 +++++++++++++++++++++++++++++++ 3 files changed, 492 insertions(+) create mode 100644 drivers/thermal/airoha_thermal.c
drivers/thermal/Kconfig +9 -0
@@ -309,6 +309,15 @@ config QORIQ_THERMAL cpufreq is used as the cooling device to throttle CPUs when the passive trip is crossed. +config AIROHA_THERMAL + tristate "Airoha thermal sensor driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on MFD_SYSCON + depends on OF + help + Enable this to plug the Airoha thermal sensor driver into the Linux + thermal framework. + config SPEAR_THERMAL tristate "SPEAr thermal sensor driver" depends on PLAT_SPEAR || COMPILE_TEST
drivers/thermal/Makefile +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_K3_THERMAL) += k3_bandgap.o k3_j72xx_bandgap.o # platform thermal drivers obj-y += broadcom/ obj-$(CONFIG_THERMAL_MMIO) += thermal_mmio.o +obj-$(CONFIG_AIROHA_THERMAL) += airoha_thermal.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_SUN8I_THERMAL) += sun8i_thermal.o obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o
drivers/thermal/airoha_thermal.c new file +482 -0
482 lines not on this page · raw message
Signature · 1 line
2.45.2
Quoted 7 lines · Christian Marangi
Add support for Airoha EN7581 thermal sensor and monitor. This is a simple sensor for the CPU or SoC Package that provide thermal sensor and trip point for hot low and critical condition to fire interrupt and react on the abnormal state.
Signed-off-by Christian Marangi <[email protected]>Reviewed-by Rob Herring (Arm) <[email protected]>
Any news with this series? Everything wrong with the thermal core small patch?
Ansuel
Hi Ansuel,
Quoted 11 lines · Christian Marangi
Quoted 7 lines · Christian Marangi
Add support for Airoha EN7581 thermal sensor and monitor. This is a simple sensor for the CPU or SoC Package that provide thermal sensor and trip point for hot low and critical condition to fire interrupt and react on the abnormal state.
Signed-off-by Christian Marangi <[email protected]>Reviewed-by Rob Herring (Arm) <[email protected]>Any news with this series? Everything wrong with the thermal core small patch?
I understand why you are trying to achieve this but usually it is the kernel which overloads the firmware description, not the opposite, no?
Either way, we ignore the offset/slope from tzp and use a couple of private variables offset/slope in the driver (iow do not call thermal_zone_get_offset() thermal_zone_get_slope()). Or add the thermal_zone_set_offset() and thermal_zone_set_slope() helpers.
I would prefer the first solution as for today I can not see any DT for ARM64 with the coefficients set. So may be we can consider the slope and the offset as a legacy which should be removed from sysfs and the thermal zone device parameters in a near future.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 24 lines · Daniel Lezcano
Hi Ansuel,
Quoted 11 lines · Christian Marangi
Quoted 7 lines · Christian Marangi
Add support for Airoha EN7581 thermal sensor and monitor. This is a simple sensor for the CPU or SoC Package that provide thermal sensor and trip point for hot low and critical condition to fire interrupt and react on the abnormal state.
Signed-off-by Christian Marangi <[email protected]>Reviewed-by Rob Herring (Arm) <[email protected]>Any news with this series? Everything wrong with the thermal core small patch?
I understand why you are trying to achieve this but usually it is the kernel which overloads the firmware description, not the opposite, no?
Either way, we ignore the offset/slope from tzp and use a couple of private variables offset/slope in the driver (iow do not call
thermal_zone_get_offset()thermal_zone_get_slope()). Or add thethermal_zone_set_offset()andthermal_zone_set_slope()helpers.
Quoted 5 lines
I would prefer the first solution as for today I can not see any DT for ARM64 with the coefficients set. So may be we can consider the slope and the offset as a legacy which should be removed from sysfs and the thermal zone device parameters in a near future.
Hi Daniel,
Having set OPs is problematic as that would diverge from what is set in DT that should always have priority.
Well yes my idea was trying to make use of them as currently there are many driver that set these values but have the slope and offset in thermal core always set to 0 and 1.
Thing is that reading temp with ADC is very common and in some way or another you always have a slope and an offset so it makese sense to permit to have those values preallocated instead of handling them in priv struct.
Anyway if the idea is to drop that, I will happly move those values handling back in the driver. Just need a confirm on that.
Also thanks for the feedback!
Signature · 1 line
Ansuel
Quoted 36 lines · Christian Marangi
Quoted 24 lines · Daniel Lezcano
Hi Ansuel,
Quoted 11 lines · Christian Marangi
Quoted 7 lines · Christian Marangi
Add support for Airoha EN7581 thermal sensor and monitor. This is a simple sensor for the CPU or SoC Package that provide thermal sensor and trip point for hot low and critical condition to fire interrupt and react on the abnormal state.
Signed-off-by Christian Marangi <[email protected]>Reviewed-by Rob Herring (Arm) <[email protected]>Any news with this series? Everything wrong with the thermal core small patch?
I understand why you are trying to achieve this but usually it is the kernel which overloads the firmware description, not the opposite, no?
Either way, we ignore the offset/slope from tzp and use a couple of private variables offset/slope in the driver (iow do not call
thermal_zone_get_offset()thermal_zone_get_slope()). Or add thethermal_zone_set_offset()andthermal_zone_set_slope()helpers.Quoted 5 lines
I would prefer the first solution as for today I can not see any DT for ARM64 with the coefficients set. So may be we can consider the slope and the offset as a legacy which should be removed from sysfs and the thermal zone device parameters in a near future.
Hi Daniel,
Having set OPs is problematic as that would diverge from what is set in DT that should always have priority.
Quoted 8 lines
Well yes my idea was trying to make use of them as currently there are many driver that set these values but have the slope and offset in thermal core always set to 0 and 1.
Thing is that reading temp with ADC is very common and in some way or another you always have a slope and an offset so it makese sense to permit to have those values preallocated instead of handling them in priv struct.
Right but if we look at the coefficients description, it is a bit fuzzy how they are used today.
Quoted 2 lines
Anyway if the idea is to drop that, I will happly move those values handling back in the driver. Just need a confirm on that.
Yes, it is probably better to put them private to the driver while we sort out how to deal with the coefficients properly. Especially that we want to introduce thermal zones with multiple sensors support.
Thanks
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog