lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <trinity-fc45afb4-bb5a-42f0-aa8d-94a5189cd1f2-1694626814181@3c-app-gmx-bs38>
Date:   Wed, 13 Sep 2023 19:40:14 +0200
From:   Frank Wunderlich <frank-w@...lic-files.de>
To:     AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>
Cc:     Frank Wunderlich <linux@...web.de>,
        linux-mediatek@...ts.infradead.org,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Daniel Lezcano <daniel.lezcano@...aro.org>,
        Amit Kucheria <amitk@...nel.org>,
        Zhang Rui <rui.zhang@...el.com>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Conor Dooley <conor+dt@...nel.org>,
        Matthias Brugger <matthias.bgg@...il.com>,
        linux-pm@...r.kernel.org, devicetree@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        Daniel Golle <daniel@...rotopia.org>
Subject: Aw: Re: [RFC v1 2/3] thermal/drivers/mediatek/lvts_thermal: make
 coeff configurable

Hi

> Gesendet: Mittwoch, 13. September 2023 um 10:03 Uhr
> Von: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@...labora.com>
> Il 11/09/23 20:33, Frank Wunderlich ha scritto:
> > From: Frank Wunderlich <frank-w@...lic-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@...lic-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

makes sense...imho very good idea.
originally i took the naming based on the Constants which maybe should be changed too?

> >   };
> >
> >   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`.

right and passing an int (instead of struct) is easier and more readable too.

> Cheers,
> Angelo
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ