62
62
63
63
#define TSC_MAX_NUM 5
64
64
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
-
74
65
/* Structure for thermal temperature calculation */
75
66
struct equation_coefs {
76
67
int a1 ;
@@ -84,13 +75,14 @@ struct rcar_gen3_thermal_tsc {
84
75
struct thermal_zone_device * zone ;
85
76
struct equation_coefs coef ;
86
77
int tj_t ;
87
- unsigned int id ; /* thermal channel id */
78
+ int thcode [ 3 ];
88
79
};
89
80
90
81
struct rcar_gen3_thermal_priv {
91
82
struct rcar_gen3_thermal_tsc * tscs [TSC_MAX_NUM ];
92
83
unsigned int num_tscs ;
93
84
void (* thermal_init )(struct rcar_gen3_thermal_tsc * tsc );
85
+ int ptat [3 ];
94
86
};
95
87
96
88
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,
133
125
/* no idea where these constants come from */
134
126
#define TJ_3 -41
135
127
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 ,
138
130
int ths_tj_1 )
139
131
{
140
132
/* 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,
143
135
* Division is not scaled in BSP and if scaled it might overflow
144
136
* the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled
145
137
*/
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 );
148
140
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 ]),
150
142
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 ;
152
144
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 ]),
154
146
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 ;
156
148
}
157
149
158
150
static int rcar_gen3_thermal_round (int temp )
@@ -174,7 +166,7 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp)
174
166
/* Read register and convert to mili Celsius */
175
167
reg = rcar_gen3_thermal_read (tsc , REG_GEN3_TEMP ) & CTEMP_MASK ;
176
168
177
- if (reg <= thcodes [ tsc -> id ] [1 ])
169
+ if (reg <= tsc -> thcode [1 ])
178
170
val = FIXPT_DIV (FIXPT_INT (reg ) - tsc -> coef .b1 ,
179
171
tsc -> coef .a1 );
180
172
else
@@ -401,9 +393,15 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
401
393
unsigned int i ;
402
394
int ret ;
403
395
404
- /* default values if FUSEs are missing */
396
+ /* Default THCODE values in case FUSEs are not set. */
405
397
/* 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
+ };
407
405
408
406
priv = devm_kzalloc (dev , sizeof (* priv ), GFP_KERNEL );
409
407
if (!priv )
@@ -413,6 +411,10 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
413
411
if (soc_device_match (r8a7795es1 ))
414
412
priv -> thermal_init = rcar_gen3_thermal_init_r8a7795es1 ;
415
413
414
+ priv -> ptat [0 ] = 2631 ;
415
+ priv -> ptat [1 ] = 1509 ;
416
+ priv -> ptat [2 ] = 435 ;
417
+
416
418
platform_set_drvdata (pdev , priv );
417
419
418
420
if (rcar_gen3_thermal_request_irqs (priv , pdev ))
@@ -439,7 +441,10 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
439
441
ret = PTR_ERR (tsc -> base );
440
442
goto error_unregister ;
441
443
}
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 ];
443
448
444
449
priv -> tscs [i ] = tsc ;
445
450
@@ -453,7 +458,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
453
458
tsc -> zone = zone ;
454
459
455
460
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 );
457
462
458
463
tsc -> zone -> tzp -> no_hwmon = false;
459
464
ret = thermal_add_hwmon_sysfs (tsc -> zone );
0 commit comments