67
67
68
68
struct rcar_gen3_thermal_priv ;
69
69
70
+ struct rcar_gen3_thermal_fuse_info {
71
+ u32 ptat [3 ];
72
+ u32 thcode [3 ];
73
+ u32 mask ;
74
+ };
75
+
70
76
struct rcar_thermal_info {
71
77
int scale ;
72
78
int adj_below ;
73
79
int adj_above ;
74
- void ( * read_fuses )( struct rcar_gen3_thermal_priv * priv ) ;
80
+ const struct rcar_gen3_thermal_fuse_info * fuses ;
75
81
};
76
82
77
83
struct equation_set_coef {
@@ -253,59 +259,31 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data)
253
259
return IRQ_HANDLED ;
254
260
}
255
261
256
- static void rcar_gen3_thermal_read_fuses_gen3 (struct rcar_gen3_thermal_priv * priv )
262
+ static void rcar_gen3_thermal_fetch_fuses (struct rcar_gen3_thermal_priv * priv )
257
263
{
258
- unsigned int i ;
264
+ const struct rcar_gen3_thermal_fuse_info * fuses = priv -> info -> fuses ;
259
265
260
266
/*
261
267
* Set the pseudo calibration points with fused values.
262
268
* PTAT is shared between all TSCs but only fused for the first
263
269
* TSC while THCODEs are fused for each TSC.
264
270
*/
265
- priv -> ptat [0 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_PTAT1 ) &
266
- GEN3_FUSE_MASK ;
267
- priv -> ptat [1 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_PTAT2 ) &
268
- GEN3_FUSE_MASK ;
269
- priv -> ptat [2 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_PTAT3 ) &
270
- GEN3_FUSE_MASK ;
271
-
272
- for (i = 0 ; i < priv -> num_tscs ; i ++ ) {
271
+ priv -> ptat [0 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], fuses -> ptat [ 0 ])
272
+ & fuses -> mask ;
273
+ priv -> ptat [1 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], fuses -> ptat [ 1 ])
274
+ & fuses -> mask ;
275
+ priv -> ptat [2 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], fuses -> ptat [ 2 ])
276
+ & fuses -> mask ;
277
+
278
+ for (unsigned int i = 0 ; i < priv -> num_tscs ; i ++ ) {
273
279
struct rcar_gen3_thermal_tsc * tsc = priv -> tscs [i ];
274
280
275
- tsc -> thcode [0 ] = rcar_gen3_thermal_read (tsc , REG_GEN3_THCODE1 ) &
276
- GEN3_FUSE_MASK ;
277
- tsc -> thcode [1 ] = rcar_gen3_thermal_read (tsc , REG_GEN3_THCODE2 ) &
278
- GEN3_FUSE_MASK ;
279
- tsc -> thcode [2 ] = rcar_gen3_thermal_read (tsc , REG_GEN3_THCODE3 ) &
280
- GEN3_FUSE_MASK ;
281
- }
282
- }
283
-
284
- static void rcar_gen3_thermal_read_fuses_gen4 (struct rcar_gen3_thermal_priv * priv )
285
- {
286
- unsigned int i ;
287
-
288
- /*
289
- * Set the pseudo calibration points with fused values.
290
- * PTAT is shared between all TSCs but only fused for the first
291
- * TSC while THCODEs are fused for each TSC.
292
- */
293
- priv -> ptat [0 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN4_THSFMON16 ) &
294
- GEN4_FUSE_MASK ;
295
- priv -> ptat [1 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN4_THSFMON17 ) &
296
- GEN4_FUSE_MASK ;
297
- priv -> ptat [2 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN4_THSFMON15 ) &
298
- GEN4_FUSE_MASK ;
299
-
300
- for (i = 0 ; i < priv -> num_tscs ; i ++ ) {
301
- struct rcar_gen3_thermal_tsc * tsc = priv -> tscs [i ];
302
-
303
- tsc -> thcode [0 ] = rcar_gen3_thermal_read (tsc , REG_GEN4_THSFMON01 ) &
304
- GEN4_FUSE_MASK ;
305
- tsc -> thcode [1 ] = rcar_gen3_thermal_read (tsc , REG_GEN4_THSFMON02 ) &
306
- GEN4_FUSE_MASK ;
307
- tsc -> thcode [2 ] = rcar_gen3_thermal_read (tsc , REG_GEN4_THSFMON00 ) &
308
- GEN4_FUSE_MASK ;
281
+ tsc -> thcode [0 ] = rcar_gen3_thermal_read (tsc , fuses -> thcode [0 ])
282
+ & fuses -> mask ;
283
+ tsc -> thcode [1 ] = rcar_gen3_thermal_read (tsc , fuses -> thcode [1 ])
284
+ & fuses -> mask ;
285
+ tsc -> thcode [2 ] = rcar_gen3_thermal_read (tsc , fuses -> thcode [2 ])
286
+ & fuses -> mask ;
309
287
}
310
288
}
311
289
@@ -316,7 +294,7 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv)
316
294
317
295
/* If fuses are not set, fallback to pseudo values. */
318
296
thscp = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_THSCP );
319
- if (!priv -> info -> read_fuses ||
297
+ if (!priv -> info -> fuses ||
320
298
(thscp & THSCP_COR_PARA_VLD ) != THSCP_COR_PARA_VLD ) {
321
299
/* Default THCODE values in case FUSEs are not set. */
322
300
static const int thcodes [TSC_MAX_NUM ][3 ] = {
@@ -342,7 +320,8 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv)
342
320
return false;
343
321
}
344
322
345
- priv -> info -> read_fuses (priv );
323
+ rcar_gen3_thermal_fetch_fuses (priv );
324
+
346
325
return true;
347
326
}
348
327
@@ -370,25 +349,37 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv,
370
349
usleep_range (1000 , 2000 );
371
350
}
372
351
352
+ static const struct rcar_gen3_thermal_fuse_info rcar_gen3_thermal_fuse_info_gen3 = {
353
+ .ptat = { REG_GEN3_PTAT1 , REG_GEN3_PTAT2 , REG_GEN3_PTAT3 },
354
+ .thcode = { REG_GEN3_THCODE1 , REG_GEN3_THCODE2 , REG_GEN3_THCODE3 },
355
+ .mask = GEN3_FUSE_MASK ,
356
+ };
357
+
358
+ static const struct rcar_gen3_thermal_fuse_info rcar_gen3_thermal_fuse_info_gen4 = {
359
+ .ptat = { REG_GEN4_THSFMON16 , REG_GEN4_THSFMON17 , REG_GEN4_THSFMON15 },
360
+ .thcode = { REG_GEN4_THSFMON01 , REG_GEN4_THSFMON02 , REG_GEN4_THSFMON00 },
361
+ .mask = GEN4_FUSE_MASK ,
362
+ };
363
+
373
364
static const struct rcar_thermal_info rcar_m3w_thermal_info = {
374
365
.scale = 157 ,
375
366
.adj_below = -41 ,
376
367
.adj_above = 116 ,
377
- .read_fuses = rcar_gen3_thermal_read_fuses_gen3 ,
368
+ .fuses = & rcar_gen3_thermal_fuse_info_gen3 ,
378
369
};
379
370
380
371
static const struct rcar_thermal_info rcar_gen3_thermal_info = {
381
372
.scale = 167 ,
382
373
.adj_below = -41 ,
383
374
.adj_above = 126 ,
384
- .read_fuses = rcar_gen3_thermal_read_fuses_gen3 ,
375
+ .fuses = & rcar_gen3_thermal_fuse_info_gen3 ,
385
376
};
386
377
387
378
static const struct rcar_thermal_info rcar_gen4_thermal_info = {
388
379
.scale = 167 ,
389
380
.adj_below = -41 ,
390
381
.adj_above = 126 ,
391
- .read_fuses = rcar_gen3_thermal_read_fuses_gen4 ,
382
+ .fuses = & rcar_gen3_thermal_fuse_info_gen4 ,
392
383
};
393
384
394
385
static const struct of_device_id rcar_gen3_thermal_dt_ids [] = {
0 commit comments