34
34
#define REG_GEN3_THCODE1 0x50
35
35
#define REG_GEN3_THCODE2 0x54
36
36
#define REG_GEN3_THCODE3 0x58
37
+ #define REG_GEN3_PTAT1 0x5c
38
+ #define REG_GEN3_PTAT2 0x60
39
+ #define REG_GEN3_PTAT3 0x64
40
+ #define REG_GEN3_THSCP 0x68
37
41
38
42
/* IRQ{STR,MSK,EN} bits */
39
43
#define IRQ_TEMP1 BIT(0)
55
59
#define THCTR_PONM BIT(6)
56
60
#define THCTR_THSST BIT(0)
57
61
62
+ /* THSCP bits */
63
+ #define THSCP_COR_PARA_VLD (BIT(15) | BIT(14))
64
+
58
65
#define CTEMP_MASK 0xFFF
59
66
60
67
#define MCELSIUS (temp ) ((temp) * 1000)
@@ -245,6 +252,64 @@ static const struct soc_device_attribute r8a7795es1[] = {
245
252
{ /* sentinel */ }
246
253
};
247
254
255
+ static bool rcar_gen3_thermal_read_fuses (struct rcar_gen3_thermal_priv * priv )
256
+ {
257
+ unsigned int i ;
258
+ u32 thscp ;
259
+
260
+ /* If fuses are not set, fallback to pseudo values. */
261
+ thscp = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_THSCP );
262
+ if ((thscp & THSCP_COR_PARA_VLD ) != THSCP_COR_PARA_VLD ) {
263
+ /* Default THCODE values in case FUSEs are not set. */
264
+ static const int thcodes [TSC_MAX_NUM ][3 ] = {
265
+ { 3397 , 2800 , 2221 },
266
+ { 3393 , 2795 , 2216 },
267
+ { 3389 , 2805 , 2237 },
268
+ { 3415 , 2694 , 2195 },
269
+ { 3356 , 2724 , 2244 },
270
+ };
271
+
272
+ priv -> ptat [0 ] = 2631 ;
273
+ priv -> ptat [1 ] = 1509 ;
274
+ priv -> ptat [2 ] = 435 ;
275
+
276
+ for (i = 0 ; i < priv -> num_tscs ; i ++ ) {
277
+ struct rcar_gen3_thermal_tsc * tsc = priv -> tscs [i ];
278
+
279
+ tsc -> thcode [0 ] = thcodes [i ][0 ];
280
+ tsc -> thcode [1 ] = thcodes [i ][1 ];
281
+ tsc -> thcode [2 ] = thcodes [i ][2 ];
282
+ }
283
+
284
+ return false;
285
+ }
286
+
287
+ /*
288
+ * Set the pseudo calibration points with fused values.
289
+ * PTAT is shared between all TSCs but only fused for the first
290
+ * TSC while THCODEs are fused for each TSC.
291
+ */
292
+ priv -> ptat [0 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_PTAT1 ) &
293
+ GEN3_FUSE_MASK ;
294
+ priv -> ptat [1 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_PTAT2 ) &
295
+ GEN3_FUSE_MASK ;
296
+ priv -> ptat [2 ] = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_PTAT3 ) &
297
+ GEN3_FUSE_MASK ;
298
+
299
+ for (i = 0 ; i < priv -> num_tscs ; i ++ ) {
300
+ struct rcar_gen3_thermal_tsc * tsc = priv -> tscs [i ];
301
+
302
+ tsc -> thcode [0 ] = rcar_gen3_thermal_read (tsc , REG_GEN3_THCODE1 ) &
303
+ GEN3_FUSE_MASK ;
304
+ tsc -> thcode [1 ] = rcar_gen3_thermal_read (tsc , REG_GEN3_THCODE2 ) &
305
+ GEN3_FUSE_MASK ;
306
+ tsc -> thcode [2 ] = rcar_gen3_thermal_read (tsc , REG_GEN3_THCODE3 ) &
307
+ GEN3_FUSE_MASK ;
308
+ }
309
+
310
+ return true;
311
+ }
312
+
248
313
static void rcar_gen3_thermal_init_r8a7795es1 (struct rcar_gen3_thermal_tsc * tsc )
249
314
{
250
315
rcar_gen3_thermal_write (tsc , REG_GEN3_CTSR , CTSR_THBGR );
@@ -393,16 +458,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
393
458
unsigned int i ;
394
459
int ret ;
395
460
396
- /* Default THCODE values in case FUSEs are not set. */
397
- /* TODO: Read values from hardware on supported platforms */
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
- };
405
-
406
461
priv = devm_kzalloc (dev , sizeof (* priv ), GFP_KERNEL );
407
462
if (!priv )
408
463
return - ENOMEM ;
@@ -411,10 +466,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
411
466
if (soc_device_match (r8a7795es1 ))
412
467
priv -> thermal_init = rcar_gen3_thermal_init_r8a7795es1 ;
413
468
414
- priv -> ptat [0 ] = 2631 ;
415
- priv -> ptat [1 ] = 1509 ;
416
- priv -> ptat [2 ] = 435 ;
417
-
418
469
platform_set_drvdata (pdev , priv );
419
470
420
471
if (rcar_gen3_thermal_request_irqs (priv , pdev ))
@@ -442,11 +493,16 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
442
493
goto error_unregister ;
443
494
}
444
495
445
- tsc -> thcode [0 ] = thcodes [i ][0 ];
446
- tsc -> thcode [1 ] = thcodes [i ][1 ];
447
- tsc -> thcode [2 ] = thcodes [i ][2 ];
448
-
449
496
priv -> tscs [i ] = tsc ;
497
+ }
498
+
499
+ priv -> num_tscs = i ;
500
+
501
+ if (!rcar_gen3_thermal_read_fuses (priv ))
502
+ dev_info (dev , "No calibration values fused, fallback to driver values\n" );
503
+
504
+ for (i = 0 ; i < priv -> num_tscs ; i ++ ) {
505
+ struct rcar_gen3_thermal_tsc * tsc = priv -> tscs [i ];
450
506
451
507
zone = devm_thermal_zone_of_sensor_register (dev , i , tsc ,
452
508
& rcar_gen3_tz_of_ops );
@@ -476,8 +532,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
476
532
dev_info (dev , "TSC%u: Loaded %d trip points\n" , i , ret );
477
533
}
478
534
479
- priv -> num_tscs = i ;
480
-
481
535
if (!priv -> num_tscs ) {
482
536
ret = - ENODEV ;
483
537
goto error_unregister ;
0 commit comments