mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: Neil Armstrong <neil.armstrong@linaro.org>
To: linux-amlogic@lists.infradead.org
Subject: Re: [PATCH v4 4/8] thermal: amlogic: Add support for secure monitor calibration readout
Date: Fri, 24 Apr 2026 11:52:07 +0200	[thread overview]
Message-ID: <8757d21d-9208-43f9-a36d-5955b008948a@linaro.org> (raw)
In-Reply-To: <20260423-add-thermal-t7-vim4-v4-4-d4c1528d5044@aliel.fr>

On 4/23/26 18:07, Ronald Claveau via B4 Relay wrote:
> From: Ronald Claveau <linux-kernel-dev@aliel.fr>
> 
> Some SoCs (e.g. T7) expose thermal calibration data through the secure
> monitor rather than a directly accessible eFuse register. Add a use_sm
> flag to amlogic_thermal_data to select this path, and retrieve the
> firmware handle and tsensor_id from the "amlogic,secure-monitor" DT
> phandle with one fixed argument.
> 
> Also introduce the amlogic,t7-thermal compatible using this new path.
> 
> While refactoring, fix a pre-existing bug where
> amlogic_thermal_initialize() was called after
> devm_thermal_of_zone_register(), causing the thermal framework to
> read an uninitialized trim_info on zone registration.
> 
> Signed-off-by: Ronald Claveau <linux-kernel-dev@aliel.fr>
> ---
>   drivers/thermal/amlogic_thermal.c | 115 ++++++++++++++++++++++++++++----------
>   1 file changed, 85 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/thermal/amlogic_thermal.c b/drivers/thermal/amlogic_thermal.c
> index 5448d772db12a..0d0c01e57b85e 100644
> --- a/drivers/thermal/amlogic_thermal.c
> +++ b/drivers/thermal/amlogic_thermal.c
> @@ -25,6 +25,7 @@
>   #include <linux/platform_device.h>
>   #include <linux/regmap.h>
>   #include <linux/thermal.h>
> +#include <linux/firmware/meson/meson_sm.h>
>   
>   #include "thermal_hwmon.h"
>   
> @@ -84,12 +85,14 @@ struct amlogic_thermal_soc_calib_data {
>    * @u_efuse_off: register offset to read fused calibration value
>    * @calibration_parameters: calibration parameters structure pointer
>    * @regmap_config: regmap config for the device
> + * @use_sm: read data from secure monitor instead of efuse
>    * This structure is required for configuration of amlogic thermal driver.
>    */
>   struct amlogic_thermal_data {
>   	int u_efuse_off;
>   	const struct amlogic_thermal_soc_calib_data *calibration_parameters;
>   	const struct regmap_config *regmap_config;
> +	bool use_sm;
>   };
>   
>   struct amlogic_thermal {
> @@ -100,6 +103,8 @@ struct amlogic_thermal {
>   	struct clk *clk;
>   	struct thermal_zone_device *tzd;
>   	u32 trim_info;
> +	struct meson_sm_firmware *sm_fw;
> +	u32 tsensor_id;
>   };
>   
>   /*
> @@ -133,26 +138,6 @@ static int amlogic_thermal_code_to_millicelsius(struct amlogic_thermal *pdata,
>   	return temp;
>   }
>   
> -static int amlogic_thermal_initialize(struct amlogic_thermal *pdata)
> -{
> -	int ret = 0;
> -	int ver;
> -
> -	regmap_read(pdata->sec_ao_map, pdata->data->u_efuse_off,
> -		    &pdata->trim_info);
> -
> -	ver = TSENSOR_TRIM_VERSION(pdata->trim_info);
> -
> -	if ((ver & TSENSOR_TRIM_CALIB_VALID_MASK) == 0) {
> -		ret = -EINVAL;
> -		dev_err(&pdata->pdev->dev,
> -			"tsensor thermal calibration not supported: 0x%x!\n",
> -			ver);
> -	}
> -
> -	return ret;
> -}
> -
>   static int amlogic_thermal_enable(struct amlogic_thermal *data)
>   {
>   	int ret;
> @@ -190,6 +175,70 @@ static int amlogic_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>   	return 0;
>   }
>   
> +static int amlogic_thermal_probe_sm(struct platform_device *pdev,
> +				    struct amlogic_thermal *pdata)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct device_node *sm_np;
> +	struct of_phandle_args ph_args;
> +	int ret;
> +
> +	ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
> +					       "amlogic,secure-monitor",
> +					       1, 0, &ph_args);
> +	if (ret)
> +		return ret;
> +
> +	sm_np = ph_args.np;

Drop this sm_np variable and use ph_args.np

> +	if (!sm_np) {
> +		dev_err(dev,
> +			"Failed to parse secure monitor phandle\n");

Single line

> +		return -ENODEV;
> +	}
> +
> +	pdata->sm_fw = meson_sm_get(sm_np);
> +	of_node_put(sm_np);
> +	if (!pdata->sm_fw) {
> +		dev_err(dev, "Failed to get secure monitor firmware\n");
> +		return -EPROBE_DEFER;
> +	}
> +
> +	pdata->tsensor_id = ph_args.args[0];
> +
> +	return meson_sm_get_thermal_calib(pdata->sm_fw,
> +					  &pdata->trim_info,
> +					  pdata->tsensor_id);
> +}
> +
> +static int amlogic_thermal_probe_syscon(struct platform_device *pdev,
> +					struct amlogic_thermal *pdata)
> +{
> +	struct device *dev = &pdev->dev;
> +	int ret = 0;
> +	int ver;
> +
> +	pdata->sec_ao_map = syscon_regmap_lookup_by_phandle
> +		(pdev->dev.of_node, "amlogic,ao-secure");

Rewrite as:
	pdata->sec_ao_map =
		syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
						"amlogic,ao-secure");

> +	if (IS_ERR(pdata->sec_ao_map)) {
> +		dev_err(dev, "syscon regmap lookup failed.\n");
> +		return PTR_ERR(pdata->sec_ao_map);
> +	}
> +
> +	regmap_read(pdata->sec_ao_map, pdata->data->u_efuse_off,
> +		    &pdata->trim_info);
> +
> +	ver = TSENSOR_TRIM_VERSION(pdata->trim_info);
> +
> +	if ((ver & TSENSOR_TRIM_CALIB_VALID_MASK) == 0) {
> +		ret = -EINVAL;
> +		dev_err(&pdata->pdev->dev,
> +			"tsensor thermal calibration not supported: 0x%x!\n",
> +			ver);

Just return -EINVAL here

> +	}
> +
> +	return ret;

return 0

> +}
> +
>   static const struct thermal_zone_device_ops amlogic_thermal_ops = {
>   	.get_temp	= amlogic_thermal_get_temp,
>   };
> @@ -226,6 +275,12 @@ static const struct amlogic_thermal_data amlogic_thermal_a1_cpu_param = {
>   	.regmap_config = &amlogic_thermal_regmap_config_g12a,
>   };
>   
> +static const struct amlogic_thermal_data amlogic_thermal_t7_param = {
> +	.use_sm			= true,
> +	.calibration_parameters	= &amlogic_thermal_g12a,
> +	.regmap_config		= &amlogic_thermal_regmap_config_g12a,
> +};
> +
>   static const struct of_device_id of_amlogic_thermal_match[] = {
>   	{
>   		.compatible = "amlogic,g12a-ddr-thermal",
> @@ -239,6 +294,10 @@ static const struct of_device_id of_amlogic_thermal_match[] = {
>   		.compatible = "amlogic,a1-cpu-thermal",
>   		.data = &amlogic_thermal_a1_cpu_param,
>   	},
> +	{
> +		.compatible = "amlogic,t7-thermal",
> +		.data = &amlogic_thermal_t7_param,
> +	},
>   	{ /* sentinel */ }
>   };
>   MODULE_DEVICE_TABLE(of, of_amlogic_thermal_match);
> @@ -271,12 +330,12 @@ static int amlogic_thermal_probe(struct platform_device *pdev)
>   	if (IS_ERR(pdata->clk))
>   		return dev_err_probe(dev, PTR_ERR(pdata->clk), "failed to get clock\n");
>   
> -	pdata->sec_ao_map = syscon_regmap_lookup_by_phandle
> -		(pdev->dev.of_node, "amlogic,ao-secure");
> -	if (IS_ERR(pdata->sec_ao_map)) {
> -		dev_err(dev, "syscon regmap lookup failed.\n");
> -		return PTR_ERR(pdata->sec_ao_map);
> -	}
> +	if (pdata->data->use_sm)
> +		ret = amlogic_thermal_probe_sm(pdev, pdata);
> +	else
> +		ret = amlogic_thermal_probe_syscon(pdev, pdata);
> +	if (ret)
> +		return ret;
>   
>   	pdata->tzd = devm_thermal_of_zone_register(&pdev->dev,
>   						   0,
> @@ -290,10 +349,6 @@ static int amlogic_thermal_probe(struct platform_device *pdev)
>   
>   	devm_thermal_add_hwmon_sysfs(&pdev->dev, pdata->tzd);
>   
> -	ret = amlogic_thermal_initialize(pdata);
> -	if (ret)
> -		return ret;
> -
>   	ret = amlogic_thermal_enable(pdata);
>   
>   	return ret;
> 

With that fixed:
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

Thanks,
Neil


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-04-24  9:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 16:07 [PATCH v4 0/8] arm64: amlogic: T7 thermal support Ronald Claveau via B4 Relay
2026-04-23 16:07 ` [PATCH v4 1/8] dt-bindings: thermal: amlogic: Add support for T7 Ronald Claveau via B4 Relay
2026-04-23 16:07 ` [PATCH v4 2/8] firmware: meson: sm: Thermal calibration read via secure monitor Ronald Claveau via B4 Relay
2026-04-24  9:47   ` Neil Armstrong
2026-04-23 16:07 ` [PATCH v4 3/8] firmware: meson: sm: Add thermal calibration SMC call Ronald Claveau via B4 Relay
2026-04-24  9:47   ` Neil Armstrong
2026-04-23 16:07 ` [PATCH v4 4/8] thermal: amlogic: Add support for secure monitor calibration readout Ronald Claveau via B4 Relay
2026-04-24  9:52   ` Neil Armstrong [this message]
2026-04-24 15:13     ` Ronald Claveau
2026-04-23 16:07 ` [PATCH v4 5/8] arm64: dts: amlogic: t7: Add cooling cells to all CPUs Ronald Claveau via B4 Relay
2026-04-24  9:52   ` Neil Armstrong
2026-04-23 16:07 ` [PATCH v4 6/8] arm64: dts: amlogic: t7: Add thermal sensor nodes Ronald Claveau via B4 Relay
2026-04-24  9:52   ` Neil Armstrong
2026-04-23 16:07 ` [PATCH v4 7/8] arm64: dts: amlogic: t7: Add thermal zones Ronald Claveau via B4 Relay
2026-04-24  9:53   ` Neil Armstrong
2026-04-23 16:07 ` [PATCH v4 8/8] arm64: dts: amlogic: t7: khadas-vim4: Add fan cooling to " Ronald Claveau via B4 Relay
2026-04-24  9:53   ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8757d21d-9208-43f9-a36d-5955b008948a@linaro.org \
    --to=neil.armstrong@linaro.org \
    --cc=linux-amlogic@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®