6767
6868struct rcar_gen3_thermal_priv ;
6969
70+ struct rcar_gen3_thermal_fuse_info {
71+ u32 ptat [3 ];
72+ u32 thcode [3 ];
73+ u32 mask ;
74+ };
75+
7076struct rcar_thermal_info {
7177 int scale ;
7278 int adj_below ;
7379 int adj_above ;
74- void ( * read_fuses )( struct rcar_gen3_thermal_priv * priv ) ;
80+ const struct rcar_gen3_thermal_fuse_info * fuses ;
7581};
7682
7783struct equation_set_coef {
@@ -253,59 +259,31 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data)
253259 return IRQ_HANDLED ;
254260}
255261
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 )
257263{
258- unsigned int i ;
264+ const struct rcar_gen3_thermal_fuse_info * fuses = priv -> info -> fuses ;
259265
260266 /*
261267 * Set the pseudo calibration points with fused values.
262268 * PTAT is shared between all TSCs but only fused for the first
263269 * TSC while THCODEs are fused for each TSC.
264270 */
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 ++ ) {
273279 struct rcar_gen3_thermal_tsc * tsc = priv -> tscs [i ];
274280
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 ;
309287 }
310288}
311289
@@ -316,7 +294,7 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv)
316294
317295 /* If fuses are not set, fallback to pseudo values. */
318296 thscp = rcar_gen3_thermal_read (priv -> tscs [0 ], REG_GEN3_THSCP );
319- if (!priv -> info -> read_fuses ||
297+ if (!priv -> info -> fuses ||
320298 (thscp & THSCP_COR_PARA_VLD ) != THSCP_COR_PARA_VLD ) {
321299 /* Default THCODE values in case FUSEs are not set. */
322300 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)
342320 return false;
343321 }
344322
345- priv -> info -> read_fuses (priv );
323+ rcar_gen3_thermal_fetch_fuses (priv );
324+
346325 return true;
347326}
348327
@@ -370,25 +349,37 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv,
370349 usleep_range (1000 , 2000 );
371350}
372351
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+
373364static const struct rcar_thermal_info rcar_m3w_thermal_info = {
374365 .scale = 157 ,
375366 .adj_below = -41 ,
376367 .adj_above = 116 ,
377- .read_fuses = rcar_gen3_thermal_read_fuses_gen3 ,
368+ .fuses = & rcar_gen3_thermal_fuse_info_gen3 ,
378369};
379370
380371static const struct rcar_thermal_info rcar_gen3_thermal_info = {
381372 .scale = 167 ,
382373 .adj_below = -41 ,
383374 .adj_above = 126 ,
384- .read_fuses = rcar_gen3_thermal_read_fuses_gen3 ,
375+ .fuses = & rcar_gen3_thermal_fuse_info_gen3 ,
385376};
386377
387378static const struct rcar_thermal_info rcar_gen4_thermal_info = {
388379 .scale = 167 ,
389380 .adj_below = -41 ,
390381 .adj_above = 126 ,
391- .read_fuses = rcar_gen3_thermal_read_fuses_gen4 ,
382+ .fuses = & rcar_gen3_thermal_fuse_info_gen4 ,
392383};
393384
394385static const struct of_device_id rcar_gen3_thermal_dt_ids [] = {
0 commit comments