thermal/drivers/airoha: Fix AN7583 mux mapping and expose all sensors
Subsystems (2)
v3 cover thermal/drivers/airoha: Fix AN7583 mux mapping and expose all sensors
The AN7583 support merged for 7.3-rc1 reads the wrong mux positions: the mux field names are swapped, and v5 of the series swapped the call arguments to match them. Patch 1 fixes the field definitions.
Patch 2 serialises mux selection and ADC sampling.
Patches 3 and 4 add one thermal sensor cell for AN7583 and a zone per sensor.
Tested on a Nokia XG-040G-MF (AN7583) with this driver on a 6.18 kernel in OpenWrt. Without the series the board powers off 2.6 s into boot. With it the three zones match direct ADC reads, and concurrent readers during CPU frequency changes gave no failed read and no shutdown. EN7581 was tested with equivalent changes on a Nokia XG-040G-MD. Build-tested on arm64 with W=1; the binding passes dt_binding_check.
Changes in v3:
- Patch 2: say in the commit message that the race needs the zones added by patch 4
- Patch 3: add Reviewed-by
- Patch 4: shorten a comment
- Rebased on thermal/linux-next
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Vitaliy Sochnev (4):
thermal/drivers/airoha: Fix AN7583 ADC mux field mapping thermal/drivers/airoha: Serialise access to the shared ADC
dt-bindings: arm: airoha: Use one thermal sensor cell for AN7583 thermal/drivers/airoha: Register a thermal zone per AN7583 sensor
.../bindings/arm/airoha,en7581-chip-scu.yaml | 3 +- drivers/thermal/airoha_thermal.c | 159 ++++++++++++++---- 2 files changed, 126 insertions(+), 36 deletions(-)
base-commit: e856ca3013b3074fd07cb81c90b1de332f69153c
Signature · 1 line
2.55.0
PATCH v3 1/4 thermal/drivers/airoha: Fix AN7583 ADC mux field mapping
On AN7583, bits 3:1 of 0x2e4 select the sensor (0 bandgap, 5 GbE, 6 CPU) and bits 3:2 of 0x2a0 select the diode (0 D0, 1 ZERO, 2 D1). The driver names them the other way round: MUX_TADC is 0x2e4, MUX_SENSOR is 0x2a0.
v5 of the AN7583 series swapped the airoha_set_thermal_mux() arguments to match these names. The diode index now goes to the sensor selector, so the zone reads mux positions 1, 0 and 2 (PAD_AVS, bandgap, core voltage) instead of the bandgap diodes. On a Nokia XG-040G-MF the result crosses the critical trip and the board powers off during boot.
Swap the field definitions. MUX_TADC then selects the diode, as on EN7581, and the existing call order is correct.
--- drivers/thermal/airoha_thermal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/thermal/airoha_thermal.c +5 -5
@@ -18,10 +18,10 @@#define EN7581_DOUT_TADC 0x2f8#define EN7581_DOUT_TADC_MASK GENMASK(15, 0) -#define AN7583_MUX_SENSOR 0x2a0 +#define AN7583_MUX_TADC 0x2a0#define AN7583_LOAD_ADJ GENMASK(3, 2) -#define AN7583_MUX_TADC 0x2e4 -#define AN7583_MUX_TADC_MASK GENMASK(3, 1) +#define AN7583_MUX_SENSOR 0x2e4 +#define AN7583_MUX_SENSOR_MASK GENMASK(3, 1)#define AN7583_DOUT_TADC 0x2f0/* PTP_THERMAL regs */
@@ -636,8 +636,8 @@ static const struct thermal_zone_device_ops an7583_tz_ops = {static const struct reg_field an7583_chip_scu_fields[AIROHA_THERMAL_FIELD_MAX ] = { [AIROHA_THERMAL_DOUT_TADC ] =REG_FIELD (AN7583_DOUT_TADC ,0 ,31 ), - [AIROHA_THERMAL_MUX_TADC ] =REG_FIELD (AN7583_MUX_TADC ,1 ,3 ), - [AIROHA_THERMAL_MUX_SENSOR ] =REG_FIELD (AN7583_MUX_SENSOR ,2 ,3 ), + [AIROHA_THERMAL_MUX_TADC ] =REG_FIELD (AN7583_MUX_TADC ,2 ,3 ), + [AIROHA_THERMAL_MUX_SENSOR ] =REG_FIELD (AN7583_MUX_SENSOR ,1 ,3 ), }; static int an7583_thermal_probe(struct platform_device *pdev,
Signature · 1 line
2.55.0
[thermal: thermal/linux-next] thermal/drivers/airoha: Fix AN7583 ADC mux field mapping
The following commit has been merged into the thermal/linux-next branch of thermal:
The following commit has been merged into the thermal/linux-next branch of thermal:
Commit-ID: 4a0f3193c68eb41882ccf7c298f5cd0b17efb8ab Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//4a0f3193c68eb41882ccf7c298f5cd0b17efb8ab Author: Vitaliy Sochnev <[email protected]> AuthorDate: Tue, 29 Sep 2026 19:52:06 +03:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Wed, 14 Oct 2026 09:45:40 +02:00
thermal/drivers/airoha: Fix AN7583 ADC mux field mapping
On AN7583, bits 3:1 of 0x2e4 select the sensor (0 bandgap, 5 GbE, 6 CPU) and bits 3:2 of 0x2a0 select the diode (0 D0, 1 ZERO, 2 D1). The driver names them the other way round: MUX_TADC is 0x2e4, MUX_SENSOR is 0x2a0.
v5 of the AN7583 series swapped the airoha_set_thermal_mux() arguments to match these names. The diode index now goes to the sensor selector, so the zone reads mux positions 1, 0 and 2 (PAD_AVS, bandgap, core voltage) instead of the bandgap diodes. On a Nokia XG-040G-MF the result crosses the critical trip and the board powers off during boot.
Swap the field definitions. MUX_TADC then selects the diode, as on EN7581, and the existing call order is correct.
--- drivers/thermal/airoha_thermal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/thermal/airoha_thermal.c +5 -5
@@ -18,10 +18,10 @@#define EN7581_DOUT_TADC 0x2f8#define EN7581_DOUT_TADC_MASK GENMASK(15, 0) -#define AN7583_MUX_SENSOR 0x2a0 +#define AN7583_MUX_TADC 0x2a0#define AN7583_LOAD_ADJ GENMASK(3, 2) -#define AN7583_MUX_TADC 0x2e4 -#define AN7583_MUX_TADC_MASK GENMASK(3, 1) +#define AN7583_MUX_SENSOR 0x2e4 +#define AN7583_MUX_SENSOR_MASK GENMASK(3, 1)#define AN7583_DOUT_TADC 0x2f0/* PTP_THERMAL regs */
@@ -636,8 +636,8 @@ static const struct thermal_zone_device_ops an7583_tz_ops = {static const struct reg_field an7583_chip_scu_fields[AIROHA_THERMAL_FIELD_MAX ] = { [AIROHA_THERMAL_DOUT_TADC ] =REG_FIELD (AN7583_DOUT_TADC ,0 ,31 ), - [AIROHA_THERMAL_MUX_TADC ] =REG_FIELD (AN7583_MUX_TADC ,1 ,3 ), - [AIROHA_THERMAL_MUX_SENSOR ] =REG_FIELD (AN7583_MUX_SENSOR ,2 ,3 ), + [AIROHA_THERMAL_MUX_TADC ] =REG_FIELD (AN7583_MUX_TADC ,2 ,3 ), + [AIROHA_THERMAL_MUX_SENSOR ] =REG_FIELD (AN7583_MUX_SENSOR ,1 ,3 ), }; static int an7583_thermal_probe(struct platform_device *pdev,
PATCH v3 2/4 thermal/drivers/airoha: Serialise access to the shared ADC
In reply to Vitaliy SochnevA read selects the sensor and walks three diodes with a 10 ms settle on each. The zone lock serialises reads of one zone. With a zone per AN7583 sensor, added later in this series, reads of different zones interleave and convert samples taken at another mux position.
Mux writes are dropped silently unless PLLRG_PROTECT is lifted, and its save and restore do not nest. The cached TADC value also skips a write after another reader has moved the mux.
With the AN7583 sensors read as parallel zones during CPU frequency changes, a zone crossed its critical trip on a chip at 55 C and the board shut down.
Serialise the sequence, drop the cache, check the selection after writing and after sampling, and return -EAGAIN if it does not hold.
--- drivers/thermal/airoha_thermal.c | 85 +++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 17 deletions(-)
drivers/thermal/airoha_thermal.c +68 -17
@@ -5,6 +5,7 @@#include <linux/delay.h> #include <linux/interrupt.h> #include <linux/mfd/syscon.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/platform_device.h>
@@ -191,6 +192,7 @@#define AN7583_NUM_SENSOR 3#define AIROHA_THERMAL_NO_MUX_SENSOR -1 +#define AIROHA_THERMAL_MUX_TRIES 3/* Convert temp to raw value as read from ADC ((((temp / 100) - init) * slope) / 1000) + offset */ #define TEMP_TO_RAW (priv, temp) ((((((temp) / 100) - (priv)->init_temp) * \
@@ -250,7 +252,8 @@ struct airoha_thermal_priv {struct resource scu_adc_res;u32 pllrg_protect; -int current_adc; +/* Serialises mux selection and ADC sampling */ +struct mutex lock;struct thermal_zone_device *tz;int init_temp;
@@ -294,9 +297,26 @@ static int airoha_get_thermal_ADC(struct airoha_thermal_priv *priv)return val; } +static bool airoha_thermal_mux_holds (struct airoha_thermal_priv *priv, +int tdac_idx,int sensor_idx) +{ +unsigned int val; + +if (regmap_field_read (priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC ], &val) || + val != tdac_idx) +return false; + +if (sensor_idx ==AIROHA_THERMAL_NO_MUX_SENSOR ) +return true; + +return !regmap_field_read (priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR ], &val) && + val == sensor_idx; +} +static void airoha_set_thermal_mux (struct airoha_thermal_priv *priv,int tdac_idx,int sensor_idx) { +int tries =AIROHA_THERMAL_MUX_TRIES ;u32 pllrg;/* Save PLLRG current value */
@@ -307,19 +327,17 @@ static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, priv->pllrg_protect);/* -* Configure Thermal Sensor mux to sensor_idx. +* Configure Thermal Sensor mux to sensor_idx and Thermal ADC mux to +* tdac_idx. Writes can be dropped silently, so read them back. * (if not supported, sensor_idx is AIROHA_THERMAL_NO_MUX_SENSOR) */ -if (sensor_idx !=AIROHA_THERMAL_NO_MUX_SENSOR ) -regmap_field_write (priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR ], - sensor_idx); - -/* Configure Thermal ADC mux to tdac_idx */ -if (priv->current_adc != tdac_idx) { +do { +if (sensor_idx !=AIROHA_THERMAL_NO_MUX_SENSOR ) +regmap_field_write (priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR ], + sensor_idx);regmap_field_write (priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC ], tdac_idx); - priv->current_adc = tdac_idx; - } + }while (!airoha_thermal_mux_holds (priv, tdac_idx, sensor_idx) && --tries);/* Restore PLLRG value on exit */ regmap_write (priv->chip_scu,EN7581_PLLRG_PROTECT , pllrg);
@@ -596,12 +614,40 @@ static int en7581_thermal_post_probe(struct platform_device *pdev)return 0 ; } +static int an7583_thermal_read_diode (struct airoha_thermal_priv *priv, +int diode,int sensor_idx,int *val) +{ +airoha_set_thermal_mux (priv, diode, sensor_idx); + *val =airoha_get_thermal_ADC (priv); + +return airoha_thermal_mux_holds (priv, diode, sensor_idx) ?0 : -EAGAIN ; +} + +static int an7583_thermal_read_diodes (struct airoha_thermal_priv *priv, +int sensor_idx,int *zero,int *d0, +int *d1) +{ +int ret; + + ret =an7583_thermal_read_diode (priv,AN7583_ZERO_TADC , sensor_idx, zero); +if (ret) +return ret; + + ret =an7583_thermal_read_diode (priv,AN7583_D0_TADC , sensor_idx, d0); +if (ret) +return ret; + +return an7583_thermal_read_diode (priv,AN7583_D1_TADC , sensor_idx, d1); +} +static int an7583_thermal_get_temp (struct thermal_zone_device *tz,int *temp) {struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz);int sensor_idx;int delta_diode, delta_gain;int coeff, slope, offset; +int tries =AIROHA_THERMAL_MUX_TRIES ; +int ret;int diode_zero, diode_d0, diode_d1;
@@ -612,12 +658,14 @@ static int an7583_thermal_get_temp(struct thermal_zone_device *tz, int *temp) slope = an7583_thermal_slope[sensor_idx]; offset = an7583_thermal_offset[sensor_idx]; -airoha_set_thermal_mux (priv,AN7583_ZERO_TADC , sensor_idx); - diode_zero =airoha_get_thermal_ADC (priv); -airoha_set_thermal_mux (priv,AN7583_D0_TADC , sensor_idx); - diode_d0 =airoha_get_thermal_ADC (priv); -airoha_set_thermal_mux (priv,AN7583_D1_TADC , sensor_idx); - diode_d1 =airoha_get_thermal_ADC (priv); +mutex_lock (&priv->lock); +do { + ret =an7583_thermal_read_diodes (priv, sensor_idx, &diode_zero, + &diode_d0, &diode_d1); + }while (ret == -EAGAIN && --tries); +mutex_unlock (&priv->lock); +if (ret) +return ret; delta_diode = diode_d1 - diode_d0; delta_gain = (delta_diode * coeff) /100 + (diode_zero - diode_d1);
@@ -678,7 +726,10 @@ static int airoha_thermal_probe(struct platform_device *pdev)return -ENOMEM ; priv->pllrg_protect = soc_data->pllrg_protect; - priv->current_adc =-1 ; + + ret =devm_mutex_init (dev, &priv->lock); +if (ret) +return ret;if (!soc_data->probe)return -EINVAL ;
Signature · 1 line
2.55.0
[thermal: thermal/linux-next] thermal/drivers/airoha: Serialise access to the shared ADC
The following commit has been merged into the thermal/linux-next branch of thermal:
The following commit has been merged into the thermal/linux-next branch of thermal:
Commit-ID: b1bf55053abed0d72738bcc12297bfa09f45eeb4 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//b1bf55053abed0d72738bcc12297bfa09f45eeb4 Author: Vitaliy Sochnev <[email protected]> AuthorDate: Tue, 29 Sep 2026 19:52:07 +03:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Wed, 14 Oct 2026 09:45:40 +02:00
thermal/drivers/airoha: Serialise access to the shared ADC
A read selects the sensor and walks three diodes with a 10 ms settle on each. The zone lock serialises reads of one zone. With a zone per AN7583 sensor, added later in this series, reads of different zones interleave and convert samples taken at another mux position.
Mux writes are dropped silently unless PLLRG_PROTECT is lifted, and its save and restore do not nest. The cached TADC value also skips a write after another reader has moved the mux.
With the AN7583 sensors read as parallel zones during CPU frequency changes, a zone crossed its critical trip on a chip at 55 C and the board shut down.
Serialise the sequence, drop the cache, check the selection after writing and after sampling, and return -EAGAIN if it does not hold.
--- drivers/thermal/airoha_thermal.c | 85 ++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 17 deletions(-)
drivers/thermal/airoha_thermal.c +68 -17
@@ -5,6 +5,7 @@#include <linux/delay.h> #include <linux/interrupt.h> #include <linux/mfd/syscon.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/platform_device.h>
@@ -191,6 +192,7 @@#define AN7583_NUM_SENSOR 3#define AIROHA_THERMAL_NO_MUX_SENSOR -1 +#define AIROHA_THERMAL_MUX_TRIES 3/* Convert temp to raw value as read from ADC ((((temp / 100) - init) * slope) / 1000) + offset */ #define TEMP_TO_RAW (priv, temp) ((((((temp) / 100) - (priv)->init_temp) * \
@@ -250,7 +252,8 @@ struct airoha_thermal_priv {struct resource scu_adc_res;u32 pllrg_protect; -int current_adc; +/* Serialises mux selection and ADC sampling */ +struct mutex lock;struct thermal_zone_device *tz;int init_temp;
@@ -294,9 +297,26 @@ static int airoha_get_thermal_ADC(struct airoha_thermal_priv *priv)return val; } +static bool airoha_thermal_mux_holds (struct airoha_thermal_priv *priv, +int tdac_idx,int sensor_idx) +{ +unsigned int val; + +if (regmap_field_read (priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC ], &val) || + val != tdac_idx) +return false; + +if (sensor_idx ==AIROHA_THERMAL_NO_MUX_SENSOR ) +return true; + +return !regmap_field_read (priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR ], &val) && + val == sensor_idx; +} +static void airoha_set_thermal_mux (struct airoha_thermal_priv *priv,int tdac_idx,int sensor_idx) { +int tries =AIROHA_THERMAL_MUX_TRIES ;u32 pllrg;/* Save PLLRG current value */
@@ -307,19 +327,17 @@ static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, priv->pllrg_protect);/* -* Configure Thermal Sensor mux to sensor_idx. +* Configure Thermal Sensor mux to sensor_idx and Thermal ADC mux to +* tdac_idx. Writes can be dropped silently, so read them back. * (if not supported, sensor_idx is AIROHA_THERMAL_NO_MUX_SENSOR) */ -if (sensor_idx !=AIROHA_THERMAL_NO_MUX_SENSOR ) -regmap_field_write (priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR ], - sensor_idx); - -/* Configure Thermal ADC mux to tdac_idx */ -if (priv->current_adc != tdac_idx) { +do { +if (sensor_idx !=AIROHA_THERMAL_NO_MUX_SENSOR ) +regmap_field_write (priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR ], + sensor_idx);regmap_field_write (priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC ], tdac_idx); - priv->current_adc = tdac_idx; - } + }while (!airoha_thermal_mux_holds (priv, tdac_idx, sensor_idx) && --tries);/* Restore PLLRG value on exit */ regmap_write (priv->chip_scu,EN7581_PLLRG_PROTECT , pllrg);
@@ -596,12 +614,40 @@ static int en7581_thermal_post_probe(struct platform_device *pdev)return 0 ; } +static int an7583_thermal_read_diode (struct airoha_thermal_priv *priv, +int diode,int sensor_idx,int *val) +{ +airoha_set_thermal_mux (priv, diode, sensor_idx); + *val =airoha_get_thermal_ADC (priv); + +return airoha_thermal_mux_holds (priv, diode, sensor_idx) ?0 : -EAGAIN ; +} + +static int an7583_thermal_read_diodes (struct airoha_thermal_priv *priv, +int sensor_idx,int *zero,int *d0, +int *d1) +{ +int ret; + + ret =an7583_thermal_read_diode (priv,AN7583_ZERO_TADC , sensor_idx, zero); +if (ret) +return ret; + + ret =an7583_thermal_read_diode (priv,AN7583_D0_TADC , sensor_idx, d0); +if (ret) +return ret; + +return an7583_thermal_read_diode (priv,AN7583_D1_TADC , sensor_idx, d1); +} +static int an7583_thermal_get_temp (struct thermal_zone_device *tz,int *temp) {struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz);int sensor_idx;int delta_diode, delta_gain;int coeff, slope, offset; +int tries =AIROHA_THERMAL_MUX_TRIES ; +int ret;int diode_zero, diode_d0, diode_d1;
@@ -612,12 +658,14 @@ static int an7583_thermal_get_temp(struct thermal_zone_device *tz, int *temp) slope = an7583_thermal_slope[sensor_idx]; offset = an7583_thermal_offset[sensor_idx]; -airoha_set_thermal_mux (priv,AN7583_ZERO_TADC , sensor_idx); - diode_zero =airoha_get_thermal_ADC (priv); -airoha_set_thermal_mux (priv,AN7583_D0_TADC , sensor_idx); - diode_d0 =airoha_get_thermal_ADC (priv); -airoha_set_thermal_mux (priv,AN7583_D1_TADC , sensor_idx); - diode_d1 =airoha_get_thermal_ADC (priv); +mutex_lock (&priv->lock); +do { + ret =an7583_thermal_read_diodes (priv, sensor_idx, &diode_zero, + &diode_d0, &diode_d1); + }while (ret == -EAGAIN && --tries); +mutex_unlock (&priv->lock); +if (ret) +return ret; delta_diode = diode_d1 - diode_d0; delta_gain = (delta_diode * coeff) /100 + (diode_zero - diode_d1);
@@ -678,7 +726,10 @@ static int airoha_thermal_probe(struct platform_device *pdev)return -ENOMEM ; priv->pllrg_protect = soc_data->pllrg_protect; - priv->current_adc =-1 ; + + ret =devm_mutex_init (dev, &priv->lock); +if (ret) +return ret;if (!soc_data->probe)return -EINVAL ;
PATCH v3 3/4 dt-bindings: arm: airoha: Use one thermal sensor cell for AN7583
In reply to Vitaliy SochnevAN7583 has three temperature sensors behind the chip SCU: bandgap, GbE and CPU. With no cells a thermal zone can only refer to the bandgap sensor.
Use one cell to select the sensor. The AN7583 compatible is new in 7.3-rc1 and no device tree uses the property yet.
--- .../devicetree/bindings/arm/airoha,en7581-chip-scu.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.yaml +2 -1
@@ -26,7 +26,8 @@ properties: maxItems: 1 '#thermal-sensor-cells': - const: 0 + description: Sensor index, 0 bandgap, 1 GbE, 2 CPU. + const: 1 required: - compatible
Signature · 1 line
2.55.0
[thermal: thermal/linux-next] dt-bindings: arm: airoha: Use one thermal sensor cell for AN7583
The following commit has been merged into the thermal/linux-next branch of thermal:
The following commit has been merged into the thermal/linux-next branch of thermal:
Commit-ID: 0cc14454eb4a1478ad23644668f8fb19075fd46f Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//0cc14454eb4a1478ad23644668f8fb19075fd46f Author: Vitaliy Sochnev <[email protected]> AuthorDate: Tue, 29 Sep 2026 19:52:08 +03:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Wed, 14 Oct 2026 09:45:40 +02:00
dt-bindings: arm: airoha: Use one thermal sensor cell for AN7583
AN7583 has three temperature sensors behind the chip SCU: bandgap, GbE and CPU. With no cells a thermal zone can only refer to the bandgap sensor.
Use one cell to select the sensor. The AN7583 compatible is new in 7.3-rc1 and no device tree uses the property yet.
--- Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.yaml +2 -1
@@ -26,7 +26,8 @@ properties: maxItems: 1 '#thermal-sensor-cells': - const: 0 + description: Sensor index, 0 bandgap, 1 GbE, 2 CPU. + const: 1 required: - compatible
PATCH v3 4/4 thermal/drivers/airoha: Register a thermal zone per AN7583 sensor
In reply to Vitaliy SochnevAN7583 has three temperature sensors and the driver has constants for all of them, but it registers one zone and reads only the bandgap sensor.
Register a zone per sensor; the thermal sensor cell selects it. A device tree may describe fewer zones than sensors. EN7581 still registers one zone.
Idle and with both cores loaded on a Nokia XG-040G-MF:
bandgap 56.9 C -> 59.3 C GbE 58.7 C -> 61.5 C CPU 57.0 C -> 61.1 C
--- drivers/thermal/airoha_thermal.c | 64 +++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 13 deletions(-)
drivers/thermal/airoha_thermal.c +51 -13
@@ -245,6 +245,11 @@ enum airoha_thermal_chip_scu_field { AIROHA_THERMAL_FIELD_MAX, }; +struct airoha_thermal_zone { +struct airoha_thermal_priv *priv; +int sensor; +}; +struct airoha_thermal_priv {struct regmap *map;struct regmap *chip_scu;
@@ -263,6 +268,9 @@ struct airoha_thermal_priv {struct airoha_thermal_soc_data {u32 pllrg_protect; +/* Sensor mux value per zone, NULL without a sensor mux */ +const int *sensors; +int num_sensors;const struct thermal_zone_device_ops *thdev_ops; int (*probe)(struct platform_device *pdev,
@@ -348,7 +356,8 @@ static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv,static int en7581_thermal_get_temp (struct thermal_zone_device *tz,int *temp) { -struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz); +struct airoha_thermal_zone *zone =thermal_zone_device_priv (tz); +struct airoha_thermal_priv *priv = zone->priv;int min_value, max_value, avg_value, value;int i;
@@ -374,7 +383,8 @@ static int en7581_thermal_get_temp(struct thermal_zone_device *tz, int *temp)static int en7581_thermal_set_trips (struct thermal_zone_device *tz,int low,int high) { -struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz); +struct airoha_thermal_zone *zone =thermal_zone_device_priv (tz); +struct airoha_thermal_priv *priv = zone->priv;bool enable_monitor = false;if (high !=INT_MAX ) {
@@ -642,8 +652,9 @@ static int an7583_thermal_read_diodes(struct airoha_thermal_priv *priv,static int an7583_thermal_get_temp (struct thermal_zone_device *tz,int *temp) { -struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz); -int sensor_idx; +struct airoha_thermal_zone *zone =thermal_zone_device_priv (tz); +struct airoha_thermal_priv *priv = zone->priv; +int sensor_idx = zone->sensor;int delta_diode, delta_gain;int coeff, slope, offset;int tries =AIROHA_THERMAL_MUX_TRIES ;
@@ -651,9 +662,6 @@ static int an7583_thermal_get_temp(struct thermal_zone_device *tz, int *temp)int diode_zero, diode_d0, diode_d1; -/* Always read sensor AN7583_BGP_TEMP_SENSOR */ - sensor_idx =AN7583_BGP_TEMP_SENSOR ; - coeff = an7583_thermal_coeff[sensor_idx]; slope = an7583_thermal_slope[sensor_idx]; offset = an7583_thermal_offset[sensor_idx];
@@ -717,7 +725,7 @@ static int airoha_thermal_probe(struct platform_device *pdev)const struct airoha_thermal_soc_data *soc_data;struct airoha_thermal_priv *priv;struct device *dev = &pdev->dev; -int ret; +int ret, i; soc_data =device_get_match_data (dev);
@@ -739,11 +747,31 @@ static int airoha_thermal_probe(struct platform_device *pdev)return ret;/* register of thermal sensor and get info from DT */ - priv->tz =devm_thermal_of_zone_register (dev,0 , priv, - soc_data->thdev_ops); -if (IS_ERR (priv->tz)) { -dev_err (dev,"register thermal zone sensor failed\n" ); -return PTR_ERR (priv->tz); +for (i =0 ; i < soc_data->num_sensors; i++) { +struct airoha_thermal_zone *zone; +struct thermal_zone_device *tz; + + zone =devm_kzalloc (dev,sizeof (*zone),GFP_KERNEL ); +if (!zone) +return -ENOMEM ; + + zone->priv = priv; + zone->sensor = soc_data->sensors ? soc_data->sensors[i] : +AIROHA_THERMAL_NO_MUX_SENSOR ; + + tz =devm_thermal_of_zone_register (dev, i, zone, + soc_data->thdev_ops); +if (IS_ERR (tz)) { +/* A DT may describe fewer zones than sensors */ +if (i &&PTR_ERR (tz) == -ENODEV ) +continue ; + +dev_err (dev,"register thermal zone %d failed\n" , i); +return PTR_ERR (tz); + } + +if (!i) + priv->tz = tz; }platform_set_drvdata (pdev, priv);
@@ -751,7 +779,15 @@ static int airoha_thermal_probe(struct platform_device *pdev)return soc_data->post_probe ? soc_data->post_probe (pdev) :0 ; } +/* The bandgap sensor stays zone 0 */ +static const int an7583_zone_sensors[AN7583_NUM_SENSOR ] = { +AN7583_BGP_TEMP_SENSOR , +AN7583_GBE_TEMP_SENSOR , +AN7583_CPU_TEMP_SENSOR , +}; +static const struct airoha_thermal_soc_data en7581_data = { + .num_sensors =1 , .pllrg_protect =EN7581_SCU_THERMAL_PROTECT_KEY , .thdev_ops = &en7581_thdev_ops, .probe = &en7581_thermal_probe,
@@ -759,6 +795,8 @@ static const struct airoha_thermal_soc_data en7581_data = { };static const struct airoha_thermal_soc_data an7583_data = { + .sensors = an7583_zone_sensors, + .num_sensors =AN7583_NUM_SENSOR , .pllrg_protect =AN7583_SCU_THERMAL_PROTECT_KEY , .thdev_ops = &an7583_tz_ops, .probe = &an7583_thermal_probe,
Signature · 1 line
2.55.0
[thermal: thermal/linux-next] thermal/drivers/airoha: Register a thermal zone per AN7583 sensor
The following commit has been merged into the thermal/linux-next branch of thermal:
The following commit has been merged into the thermal/linux-next branch of thermal:
Commit-ID: 06a169d840a0d6ce03c230b115cef7d7cebcc2d4 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//06a169d840a0d6ce03c230b115cef7d7cebcc2d4 Author: Vitaliy Sochnev <[email protected]> AuthorDate: Tue, 29 Sep 2026 19:52:09 +03:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Wed, 14 Oct 2026 09:45:40 +02:00
thermal/drivers/airoha: Register a thermal zone per AN7583 sensor
AN7583 has three temperature sensors and the driver has constants for all of them, but it registers one zone and reads only the bandgap sensor.
Register a zone per sensor; the thermal sensor cell selects it. A device tree may describe fewer zones than sensors. EN7581 still registers one zone.
Idle and with both cores loaded on a Nokia XG-040G-MF:
bandgap 56.9 C -> 59.3 C GbE 58.7 C -> 61.5 C CPU 57.0 C -> 61.1 C
--- drivers/thermal/airoha_thermal.c | 64 ++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 13 deletions(-)
drivers/thermal/airoha_thermal.c +51 -13
@@ -245,6 +245,11 @@ enum airoha_thermal_chip_scu_field { AIROHA_THERMAL_FIELD_MAX, }; +struct airoha_thermal_zone { +struct airoha_thermal_priv *priv; +int sensor; +}; +struct airoha_thermal_priv {struct regmap *map;struct regmap *chip_scu;
@@ -263,6 +268,9 @@ struct airoha_thermal_priv {struct airoha_thermal_soc_data {u32 pllrg_protect; +/* Sensor mux value per zone, NULL without a sensor mux */ +const int *sensors; +int num_sensors;const struct thermal_zone_device_ops *thdev_ops; int (*probe)(struct platform_device *pdev,
@@ -348,7 +356,8 @@ static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv,static int en7581_thermal_get_temp (struct thermal_zone_device *tz,int *temp) { -struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz); +struct airoha_thermal_zone *zone =thermal_zone_device_priv (tz); +struct airoha_thermal_priv *priv = zone->priv;int min_value, max_value, avg_value, value;int i;
@@ -374,7 +383,8 @@ static int en7581_thermal_get_temp(struct thermal_zone_device *tz, int *temp)static int en7581_thermal_set_trips (struct thermal_zone_device *tz,int low,int high) { -struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz); +struct airoha_thermal_zone *zone =thermal_zone_device_priv (tz); +struct airoha_thermal_priv *priv = zone->priv;bool enable_monitor = false;if (high !=INT_MAX ) {
@@ -642,8 +652,9 @@ static int an7583_thermal_read_diodes(struct airoha_thermal_priv *priv,static int an7583_thermal_get_temp (struct thermal_zone_device *tz,int *temp) { -struct airoha_thermal_priv *priv =thermal_zone_device_priv (tz); -int sensor_idx; +struct airoha_thermal_zone *zone =thermal_zone_device_priv (tz); +struct airoha_thermal_priv *priv = zone->priv; +int sensor_idx = zone->sensor;int delta_diode, delta_gain;int coeff, slope, offset;int tries =AIROHA_THERMAL_MUX_TRIES ;
@@ -651,9 +662,6 @@ static int an7583_thermal_get_temp(struct thermal_zone_device *tz, int *temp)int diode_zero, diode_d0, diode_d1; -/* Always read sensor AN7583_BGP_TEMP_SENSOR */ - sensor_idx =AN7583_BGP_TEMP_SENSOR ; - coeff = an7583_thermal_coeff[sensor_idx]; slope = an7583_thermal_slope[sensor_idx]; offset = an7583_thermal_offset[sensor_idx];
@@ -717,7 +725,7 @@ static int airoha_thermal_probe(struct platform_device *pdev)const struct airoha_thermal_soc_data *soc_data;struct airoha_thermal_priv *priv;struct device *dev = &pdev->dev; -int ret; +int ret, i; soc_data =device_get_match_data (dev);
@@ -739,11 +747,31 @@ static int airoha_thermal_probe(struct platform_device *pdev)return ret;/* register of thermal sensor and get info from DT */ - priv->tz =devm_thermal_of_zone_register (dev,0 , priv, - soc_data->thdev_ops); -if (IS_ERR (priv->tz)) { -dev_err (dev,"register thermal zone sensor failed\n" ); -return PTR_ERR (priv->tz); +for (i =0 ; i < soc_data->num_sensors; i++) { +struct airoha_thermal_zone *zone; +struct thermal_zone_device *tz; + + zone =devm_kzalloc (dev,sizeof (*zone),GFP_KERNEL ); +if (!zone) +return -ENOMEM ; + + zone->priv = priv; + zone->sensor = soc_data->sensors ? soc_data->sensors[i] : +AIROHA_THERMAL_NO_MUX_SENSOR ; + + tz =devm_thermal_of_zone_register (dev, i, zone, + soc_data->thdev_ops); +if (IS_ERR (tz)) { +/* A DT may describe fewer zones than sensors */ +if (i &&PTR_ERR (tz) == -ENODEV ) +continue ; + +dev_err (dev,"register thermal zone %d failed\n" , i); +return PTR_ERR (tz); + } + +if (!i) + priv->tz = tz; }platform_set_drvdata (pdev, priv);
@@ -751,7 +779,15 @@ static int airoha_thermal_probe(struct platform_device *pdev)return soc_data->post_probe ? soc_data->post_probe (pdev) :0 ; } +/* The bandgap sensor stays zone 0 */ +static const int an7583_zone_sensors[AN7583_NUM_SENSOR ] = { +AN7583_BGP_TEMP_SENSOR , +AN7583_GBE_TEMP_SENSOR , +AN7583_CPU_TEMP_SENSOR , +}; +static const struct airoha_thermal_soc_data en7581_data = { + .num_sensors =1 , .pllrg_protect =EN7581_SCU_THERMAL_PROTECT_KEY , .thdev_ops = &en7581_thdev_ops, .probe = &en7581_thermal_probe,
@@ -759,6 +795,8 @@ static const struct airoha_thermal_soc_data en7581_data = { };static const struct airoha_thermal_soc_data an7583_data = { + .sensors = an7583_zone_sensors, + .num_sensors =AN7583_NUM_SENSOR , .pllrg_protect =AN7583_SCU_THERMAL_PROTECT_KEY , .thdev_ops = &an7583_tz_ops, .probe = &an7583_thermal_probe,