mbox series

[v5,0/2] thermal: mediatek: add support for MT7986 and MT7981

Message ID cover.1674055882.git.daniel@makrotopia.org
Headers show
Series thermal: mediatek: add support for MT7986 and MT7981 | expand

Message

Daniel Golle Jan. 18, 2023, 3:40 p.m. UTC
As requested in a previous review, first convert the if-else selection
of the raw_to_mcelsius_* function to instead use a function pointer
added to struct mtk_thermal. Then add thermal support for the MT7986
SoC which can also be used on MT7981.

Device Tree bindings have already been merged[1].

Changes since v4: Only use switch statement where requested[2] and keep
if-else logic in other places.

When submitting v3, it looked like the patch series submitted by Amjad
Ouled-Ameur ("thermal: mediatek: Add support for MT8365 SoC"[3]) which
also adds this function pointer would be merged first. However, a
re-spin of this series addressing the comments it has received has not
yet been submitted. The change introducing the raw_to_mcelsius function
pointer is hence being applied independently.

Changes since v2: Rebase on top of pending patch introducing
raw_to_mcelsius function pointer.
Drop left-over macro extracting the unused adc_oe field.
Use switch (...) instead of if-else-if-else-... statements.
For now, return -EINVAL as default in case of unknown version. Imho
this should be BUG(), as this version is only defined within this
driver.

Changes since v1: Drop use of adc_oe field in efuse, Henry Yen
confirmed its use has been dropped intentionally in MTK SDK as well.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/commit/?h=thermal/bleeding-edge&id=071e99848ccc1fbe238c4c9c7cfffd83f1dfe156
[2]: https://lore.kernel.org/lkml/0b72a12c-286f-79d0-09e9-b1761530850a@collabora.com/
[3]: https://lore.kernel.org/linux-arm-kernel/4121bb6b-30db-7a23-f4c8-40afdda7a0b5@linaro.org/T/

Daniel Golle (2):
  thermal/drivers/mtk: use function pointer for raw_to_mcelsius
  thermal: mediatek: add support for MT7986 and MT7981

 drivers/thermal/mtk_thermal.c | 143 +++++++++++++++++++++++++++++++---
 1 file changed, 133 insertions(+), 10 deletions(-)


base-commit: 9ce08dd7ea24253aac5fd2519f9aea27dfb390c9

Comments

Matthias Brugger Jan. 19, 2023, 4:44 p.m. UTC | #1
On 18/01/2023 16:40, Daniel Golle wrote:
> Instead of having if-else logic selecting either raw_to_mcelsius_v1 or
> raw_to_mcelsius_v2 in mtk_thermal_bank_temperature introduce a function
> pointer raw_to_mcelsius to struct mtk_thermal which is initialized in the
> probe function.
> 
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
>   drivers/thermal/mtk_thermal.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index 0084b76493d9a..992750ee09e62 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -292,6 +292,8 @@ struct mtk_thermal {
>   
>   	const struct mtk_thermal_data *conf;
>   	struct mtk_thermal_bank banks[MAX_NUM_ZONES];
> +
> +	int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
>   };
>   
>   /* MT8183 thermal sensor data */
> @@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
>   	for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
>   		raw = readl(mt->thermal_base + conf->msr[i]);
>   
> -		if (mt->conf->version == MTK_THERMAL_V1) {
> -			temp = raw_to_mcelsius_v1(
> -				mt, conf->bank_data[bank->id].sensors[i], raw);
> -		} else {
> -			temp = raw_to_mcelsius_v2(
> -				mt, conf->bank_data[bank->id].sensors[i], raw);
> -		}
> +		temp = mt->raw_to_mcelsius(
> +			mt, conf->bank_data[bank->id].sensors[i], raw);
> +
>   
>   		/*
>   		 * The first read of a sensor often contains very high bogus
> @@ -1075,6 +1073,11 @@ static int mtk_thermal_probe(struct platform_device *pdev)
>   		mtk_thermal_release_periodic_ts(mt, auxadc_base);
>   	}
>   
> +	if (mt->conf->version == MTK_THERMAL_V1)
> +		mt->raw_to_mcelsius = raw_to_mcelsius_v1;
> +	else
> +		mt->raw_to_mcelsius = raw_to_mcelsius_v2;
> +
>   	for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
>   		for (i = 0; i < mt->conf->num_banks; i++)
>   			mtk_thermal_init_bank(mt, i, apmixed_phys_base,