Skip to content

Commit a216261

Browse files
Wolfram Sangdlezcano
authored andcommitted
drivers/thermal/rcar_gen3_thermal: refactor reading fuses into seprarate function
Gen4 will be very different, so refactor Gen3 access into separate call first. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20230511192220.7523-3-wsa+renesas@sang-engineering.com
1 parent fe3bfa7 commit a216261

1 file changed

Lines changed: 36 additions & 24 deletions

File tree

drivers/thermal/rcar_gen3_thermal.c

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ struct equation_coefs {
6666
int b2;
6767
};
6868

69+
struct rcar_gen3_thermal_priv;
70+
6971
struct rcar_thermal_info {
7072
int ths_tj_1;
73+
void (*read_fuses)(struct rcar_gen3_thermal_priv *priv);
7174
};
7275

7376
struct rcar_gen3_thermal_tsc {
@@ -241,14 +244,43 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data)
241244
return IRQ_HANDLED;
242245
}
243246

247+
static void rcar_gen3_thermal_read_fuses_gen3(struct rcar_gen3_thermal_priv *priv)
248+
{
249+
unsigned int i;
250+
251+
/*
252+
* Set the pseudo calibration points with fused values.
253+
* PTAT is shared between all TSCs but only fused for the first
254+
* TSC while THCODEs are fused for each TSC.
255+
*/
256+
priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) &
257+
GEN3_FUSE_MASK;
258+
priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) &
259+
GEN3_FUSE_MASK;
260+
priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) &
261+
GEN3_FUSE_MASK;
262+
263+
for (i = 0; i < priv->num_tscs; i++) {
264+
struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
265+
266+
tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) &
267+
GEN3_FUSE_MASK;
268+
tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) &
269+
GEN3_FUSE_MASK;
270+
tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) &
271+
GEN3_FUSE_MASK;
272+
}
273+
}
274+
244275
static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv)
245276
{
246277
unsigned int i;
247278
u32 thscp;
248279

249280
/* If fuses are not set, fallback to pseudo values. */
250281
thscp = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_THSCP);
251-
if ((thscp & THSCP_COR_PARA_VLD) != THSCP_COR_PARA_VLD) {
282+
if (!priv->info->read_fuses ||
283+
(thscp & THSCP_COR_PARA_VLD) != THSCP_COR_PARA_VLD) {
252284
/* Default THCODE values in case FUSEs are not set. */
253285
static const int thcodes[TSC_MAX_NUM][3] = {
254286
{ 3397, 2800, 2221 },
@@ -273,29 +305,7 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv)
273305
return false;
274306
}
275307

276-
/*
277-
* Set the pseudo calibration points with fused values.
278-
* PTAT is shared between all TSCs but only fused for the first
279-
* TSC while THCODEs are fused for each TSC.
280-
*/
281-
priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) &
282-
GEN3_FUSE_MASK;
283-
priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) &
284-
GEN3_FUSE_MASK;
285-
priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) &
286-
GEN3_FUSE_MASK;
287-
288-
for (i = 0; i < priv->num_tscs; i++) {
289-
struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
290-
291-
tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) &
292-
GEN3_FUSE_MASK;
293-
tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) &
294-
GEN3_FUSE_MASK;
295-
tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) &
296-
GEN3_FUSE_MASK;
297-
}
298-
308+
priv->info->read_fuses(priv);
299309
return true;
300310
}
301311

@@ -325,10 +335,12 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv,
325335

326336
static const struct rcar_thermal_info rcar_m3w_thermal_info = {
327337
.ths_tj_1 = 116,
338+
.read_fuses = rcar_gen3_thermal_read_fuses_gen3,
328339
};
329340

330341
static const struct rcar_thermal_info rcar_gen3_thermal_info = {
331342
.ths_tj_1 = 126,
343+
.read_fuses = rcar_gen3_thermal_read_fuses_gen3,
332344
};
333345

334346
static const struct of_device_id rcar_gen3_thermal_dt_ids[] = {

0 commit comments

Comments
 (0)