Skip to content

Commit b8aaf14

Browse files
Niklas Söderlunddlezcano
authored andcommitted
thermal: rcar_gen3_thermal: Store thcode and ptat in priv data
Prepare for reading the THCODE and PTAT values from hardware fuses by storing the values used during calculations in the drivers private data structures. As the values are now stored directly in the private data structures there is no need to keep track of the TSC channel id as its only usage was to lookup the THCODE row, drop it. Signed-off-by: Niklas Söderlund <[email protected]> Tested-by: Kuninori Morimoto <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent f6c8367 commit b8aaf14

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

drivers/thermal/rcar_gen3_thermal.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@
6262

6363
#define TSC_MAX_NUM 5
6464

65-
/* default THCODE values if FUSEs are missing */
66-
static const int thcodes[TSC_MAX_NUM][3] = {
67-
{ 3397, 2800, 2221 },
68-
{ 3393, 2795, 2216 },
69-
{ 3389, 2805, 2237 },
70-
{ 3415, 2694, 2195 },
71-
{ 3356, 2724, 2244 },
72-
};
73-
7465
/* Structure for thermal temperature calculation */
7566
struct equation_coefs {
7667
int a1;
@@ -84,13 +75,14 @@ struct rcar_gen3_thermal_tsc {
8475
struct thermal_zone_device *zone;
8576
struct equation_coefs coef;
8677
int tj_t;
87-
unsigned int id; /* thermal channel id */
78+
int thcode[3];
8879
};
8980

9081
struct rcar_gen3_thermal_priv {
9182
struct rcar_gen3_thermal_tsc *tscs[TSC_MAX_NUM];
9283
unsigned int num_tscs;
9384
void (*thermal_init)(struct rcar_gen3_thermal_tsc *tsc);
85+
int ptat[3];
9486
};
9587

9688
static inline u32 rcar_gen3_thermal_read(struct rcar_gen3_thermal_tsc *tsc,
@@ -133,8 +125,8 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc,
133125
/* no idea where these constants come from */
134126
#define TJ_3 -41
135127

136-
static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc,
137-
int *ptat, const int *thcode,
128+
static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_priv *priv,
129+
struct rcar_gen3_thermal_tsc *tsc,
138130
int ths_tj_1)
139131
{
140132
/* TODO: Find documentation and document constant calculation formula */
@@ -143,16 +135,16 @@ static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc,
143135
* Division is not scaled in BSP and if scaled it might overflow
144136
* the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled
145137
*/
146-
tsc->tj_t = (FIXPT_INT((ptat[1] - ptat[2]) * (ths_tj_1 - TJ_3))
147-
/ (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3);
138+
tsc->tj_t = (FIXPT_INT((priv->ptat[1] - priv->ptat[2]) * (ths_tj_1 - TJ_3))
139+
/ (priv->ptat[0] - priv->ptat[2])) + FIXPT_INT(TJ_3);
148140

149-
tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]),
141+
tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[2]),
150142
tsc->tj_t - FIXPT_INT(TJ_3));
151-
tsc->coef.b1 = FIXPT_INT(thcode[2]) - tsc->coef.a1 * TJ_3;
143+
tsc->coef.b1 = FIXPT_INT(tsc->thcode[2]) - tsc->coef.a1 * TJ_3;
152144

153-
tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]),
145+
tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[0]),
154146
tsc->tj_t - FIXPT_INT(ths_tj_1));
155-
tsc->coef.b2 = FIXPT_INT(thcode[0]) - tsc->coef.a2 * ths_tj_1;
147+
tsc->coef.b2 = FIXPT_INT(tsc->thcode[0]) - tsc->coef.a2 * ths_tj_1;
156148
}
157149

158150
static int rcar_gen3_thermal_round(int temp)
@@ -174,7 +166,7 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp)
174166
/* Read register and convert to mili Celsius */
175167
reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK;
176168

177-
if (reg <= thcodes[tsc->id][1])
169+
if (reg <= tsc->thcode[1])
178170
val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1,
179171
tsc->coef.a1);
180172
else
@@ -401,9 +393,15 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
401393
unsigned int i;
402394
int ret;
403395

404-
/* default values if FUSEs are missing */
396+
/* Default THCODE values in case FUSEs are not set. */
405397
/* TODO: Read values from hardware on supported platforms */
406-
int ptat[3] = { 2631, 1509, 435 };
398+
static const int thcodes[TSC_MAX_NUM][3] = {
399+
{ 3397, 2800, 2221 },
400+
{ 3393, 2795, 2216 },
401+
{ 3389, 2805, 2237 },
402+
{ 3415, 2694, 2195 },
403+
{ 3356, 2724, 2244 },
404+
};
407405

408406
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
409407
if (!priv)
@@ -413,6 +411,10 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
413411
if (soc_device_match(r8a7795es1))
414412
priv->thermal_init = rcar_gen3_thermal_init_r8a7795es1;
415413

414+
priv->ptat[0] = 2631;
415+
priv->ptat[1] = 1509;
416+
priv->ptat[2] = 435;
417+
416418
platform_set_drvdata(pdev, priv);
417419

418420
if (rcar_gen3_thermal_request_irqs(priv, pdev))
@@ -439,7 +441,10 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
439441
ret = PTR_ERR(tsc->base);
440442
goto error_unregister;
441443
}
442-
tsc->id = i;
444+
445+
tsc->thcode[0] = thcodes[i][0];
446+
tsc->thcode[1] = thcodes[i][1];
447+
tsc->thcode[2] = thcodes[i][2];
443448

444449
priv->tscs[i] = tsc;
445450

@@ -453,7 +458,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
453458
tsc->zone = zone;
454459

455460
priv->thermal_init(tsc);
456-
rcar_gen3_thermal_calc_coefs(tsc, ptat, thcodes[i], *ths_tj_1);
461+
rcar_gen3_thermal_calc_coefs(priv, tsc, *ths_tj_1);
457462

458463
tsc->zone->tzp->no_hwmon = false;
459464
ret = thermal_add_hwmon_sysfs(tsc->zone);

0 commit comments

Comments
 (0)