mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno  <angelogioacchino.delregno@collabora.com>
To: Frank Wunderlich <linux@fw-web.de>, linux-mediatek@lists.infradead.org
Cc: Frank Wunderlich <frank-w@public-files.de>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Daniel Golle <daniel@makrotopia.org>
Subject: Re: [RFC v1 2/3] thermal/drivers/mediatek/lvts_thermal: make coeff configurable
Date: Wed, 13 Sep 2023 10:03:49 +0200	[thread overview]
Message-ID: <99ef1b62-0676-a912-20fb-c04c427c4d01@collabora.com> (raw)
In-Reply-To: <20230911183354.11487-3-linux@fw-web.de>

Il 11/09/23 20:33, Frank Wunderlich ha scritto:
> From: Frank Wunderlich <frank-w@public-files.de>
> 
> The upcoming mt7988 has different temperature coefficients so we
> cannot use constants in the functions lvts_golden_temp_init,
> lvts_golden_temp_init and lvts_raw_to_temp anymore.
> 
> Add a field in the lvts_ctrl pointing to the lvts_data which now
> contains the soc-specific temperature coefficents.
> 
> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> ---
>   drivers/thermal/mediatek/lvts_thermal.c | 56 ++++++++++++++++++-------
>   1 file changed, 41 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index effd9b00a424..c1004b4da3b6 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -80,8 +80,8 @@
>   #define LVTS_SENSOR_MAX				4
>   #define LVTS_GOLDEN_TEMP_MAX		62
>   #define LVTS_GOLDEN_TEMP_DEFAULT	50
> -#define LVTS_COEFF_A				-250460
> -#define LVTS_COEFF_B				250460
> +#define LVTS_COEFF_A_MT8195			-250460
> +#define LVTS_COEFF_B_MT8195			250460
>   
>   #define LVTS_MSR_IMMEDIATE_MODE		0
>   #define LVTS_MSR_FILTERED_MODE		1
> @@ -94,7 +94,7 @@
>   #define LVTS_MINIMUM_THRESHOLD		20000
>   
>   static int golden_temp = LVTS_GOLDEN_TEMP_DEFAULT;
> -static int coeff_b = LVTS_COEFF_B;
> +static int coeff_b;

This could be renamed to `golden_temp_offset`

>   
>   struct lvts_sensor_data {
>   	int dt_id;
> @@ -109,9 +109,15 @@ struct lvts_ctrl_data {
>   	int mode;
>   };
>   
> +struct formula_coeff {
> +	int a;
> +	int b;
> +};
> +
>   struct lvts_data {
>   	const struct lvts_ctrl_data *lvts_ctrl;
>   	int num_lvts_ctrl;
> +	struct formula_coeff coeff;

You can just add the coefficients here directly... and while at it you can
also make it self explanatory, because the "A" coefficient is a factor while
the "B" coefficient is just an offset.

	int temp_factor; <--- coeff_a
	int temp_offset; <--- coeff_b

>   };
>   
>   struct lvts_sensor {
> @@ -126,6 +132,7 @@ struct lvts_sensor {
>   
>   struct lvts_ctrl {
>   	struct lvts_sensor sensors[LVTS_SENSOR_MAX];
> +	const struct lvts_data *lvts_data;
>   	u32 calibration[LVTS_SENSOR_MAX];
>   	u32 hw_tshut_raw_temp;
>   	int num_lvts_sensor;
> @@ -247,21 +254,21 @@ static void lvts_debugfs_exit(struct lvts_domain *lvts_td) { }
>   
>   #endif
>   
> -static int lvts_raw_to_temp(u32 raw_temp)
> +static int lvts_raw_to_temp(u32 raw_temp, struct formula_coeff coeff)
>   {
>   	int temperature;
>   
> -	temperature = ((s64)(raw_temp & 0xFFFF) * LVTS_COEFF_A) >> 14;
> +	temperature = ((s64)(raw_temp & 0xFFFF) * coeff.a) >> 14;

so that this also becomes more readable:

static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
{
	int temperature;

	temperature = ((s64)(raw_temp & 0xFFFF) * temp_factor) >> 14;
	temperature += golden_temp_offset;

	return temperature;
}

where temp_factor is lvts_data.temp_factor, and golden_temp_offset is a
rename of `static int coeff_b`.

Cheers,
Angelo


  reply	other threads:[~2023-09-13  8:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 18:33 [RFC v1 0/3] add LVTS support for mt7988 Frank Wunderlich
2023-09-11 18:33 ` [RFC v1 1/3] dt-bindings: thermal: mediatek: add mt7988 compatible Frank Wunderlich
2023-09-12 15:58   ` Rob Herring
2023-09-13  7:49   ` AngeloGioacchino Del Regno
2023-09-13 10:57     ` Frank Wunderlich
2023-09-13 11:23       ` AngeloGioacchino Del Regno
2023-09-11 18:33 ` [RFC v1 2/3] thermal/drivers/mediatek/lvts_thermal: make coeff configurable Frank Wunderlich
2023-09-13  8:03   ` AngeloGioacchino Del Regno [this message]
2023-09-13 17:40     ` Aw: " Frank Wunderlich
2023-09-11 18:33 ` [RFC v1 3/3] thermal/drivers/mediatek/lvts_thermal: add mt7988 support Frank Wunderlich
2023-09-13  8:16   ` AngeloGioacchino Del Regno
2023-09-13 10:52     ` Frank Wunderlich
2023-09-13 11:43       ` AngeloGioacchino Del Regno
2023-09-13 17:16         ` Aw: " Frank Wunderlich

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=99ef1b62-0676-a912-20fb-c04c427c4d01@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=amitk@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=daniel@makrotopia.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frank-w@public-files.de \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@fw-web.de \
    --cc=matthias.bgg@gmail.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=rui.zhang@intel.com \
    /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®