Skip to content

Commit 566e0ea

Browse files
Niklas Söderlunddlezcano
authored andcommitted
thermal/drivers/rcar_gen3: Move Tj_T storage to shared private data
The calculated Tj_T constant is calculated from the PTAT data either read from the first TSC zone on the device if calibration data is fused, or from fallback values in the driver itself. The value calculated is shared among all TSC zones. Move the Tj_T constant to the shared private data structure instead of duplicating it in each TSC private data. This requires adding a pointer to the shared data to the TSC private data structure. This back pointer make it easier to further rework the temperature conversion logic. Signed-off-by: Niklas Söderlund <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7fcd7df commit 566e0ea

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

drivers/thermal/rcar_gen3_thermal.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ struct rcar_thermal_info {
8181
};
8282

8383
struct rcar_gen3_thermal_tsc {
84+
struct rcar_gen3_thermal_priv *priv;
8485
void __iomem *base;
8586
struct thermal_zone_device *zone;
8687
struct equation_coefs coef;
87-
int tj_t;
8888
int thcode[3];
8989
};
9090

@@ -93,6 +93,7 @@ struct rcar_gen3_thermal_priv {
9393
struct thermal_zone_device_ops ops;
9494
unsigned int num_tscs;
9595
int ptat[3];
96+
int tj_t;
9697
const struct rcar_thermal_info *info;
9798
};
9899

@@ -136,26 +137,32 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc,
136137
/* no idea where these constants come from */
137138
#define TJ_3 -41
138139

139-
static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_priv *priv,
140-
struct rcar_gen3_thermal_tsc *tsc,
141-
int ths_tj_1)
140+
static void rcar_gen3_thermal_shared_coefs(struct rcar_gen3_thermal_priv *priv)
141+
{
142+
int tj1 = priv->info->ths_tj_1;
143+
144+
priv->tj_t = (FIXPT_INT((priv->ptat[1] - priv->ptat[2]) * (tj1 - TJ_3))
145+
/ (priv->ptat[0] - priv->ptat[2])) + FIXPT_INT(TJ_3);
146+
}
147+
148+
static void rcar_gen3_thermal_tsc_coefs(struct rcar_gen3_thermal_priv *priv,
149+
struct rcar_gen3_thermal_tsc *tsc)
142150
{
151+
int tj1 = priv->info->ths_tj_1;
152+
143153
/* TODO: Find documentation and document constant calculation formula */
144154

145155
/*
146156
* Division is not scaled in BSP and if scaled it might overflow
147157
* the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled
148158
*/
149-
tsc->tj_t = (FIXPT_INT((priv->ptat[1] - priv->ptat[2]) * (ths_tj_1 - TJ_3))
150-
/ (priv->ptat[0] - priv->ptat[2])) + FIXPT_INT(TJ_3);
151-
152159
tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[2]),
153-
tsc->tj_t - FIXPT_INT(TJ_3));
160+
priv->tj_t - FIXPT_INT(TJ_3));
154161
tsc->coef.b1 = FIXPT_INT(tsc->thcode[2]) - tsc->coef.a1 * TJ_3;
155162

156163
tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[0]),
157-
tsc->tj_t - FIXPT_INT(ths_tj_1));
158-
tsc->coef.b2 = FIXPT_INT(tsc->thcode[0]) - tsc->coef.a2 * ths_tj_1;
164+
priv->tj_t - FIXPT_INT(tj1));
165+
tsc->coef.b2 = FIXPT_INT(tsc->thcode[0]) - tsc->coef.a2 * tj1;
159166
}
160167

161168
static int rcar_gen3_thermal_round(int temp)
@@ -196,10 +203,11 @@ static int rcar_gen3_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
196203
static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc,
197204
int mcelsius)
198205
{
206+
struct rcar_gen3_thermal_priv *priv = tsc->priv;
199207
int celsius, val;
200208

201209
celsius = DIV_ROUND_CLOSEST(mcelsius, 1000);
202-
if (celsius <= INT_FIXPT(tsc->tj_t))
210+
if (celsius <= INT_FIXPT(priv->tj_t))
203211
val = celsius * tsc->coef.a1 + tsc->coef.b1;
204212
else
205213
val = celsius * tsc->coef.a2 + tsc->coef.b2;
@@ -516,6 +524,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
516524
goto error_unregister;
517525
}
518526

527+
tsc->priv = priv;
519528
tsc->base = devm_ioremap_resource(dev, res);
520529
if (IS_ERR(tsc->base)) {
521530
ret = PTR_ERR(tsc->base);
@@ -530,11 +539,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
530539
if (!rcar_gen3_thermal_read_fuses(priv))
531540
dev_info(dev, "No calibration values fused, fallback to driver values\n");
532541

542+
rcar_gen3_thermal_shared_coefs(priv);
543+
533544
for (i = 0; i < priv->num_tscs; i++) {
534545
struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
535546

536547
rcar_gen3_thermal_init(priv, tsc);
537-
rcar_gen3_thermal_calc_coefs(priv, tsc, priv->info->ths_tj_1);
548+
rcar_gen3_thermal_tsc_coefs(priv, tsc);
538549

539550
zone = devm_thermal_of_zone_register(dev, i, tsc, &priv->ops);
540551
if (IS_ERR(zone)) {

0 commit comments

Comments
 (0)