Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: rcar_gen3_thermal: Update temperature conversion method

Update the formula to calculate temperature:
Currently, current TEMP is calculated as
average of val1 (is calculated by formula 1)
and val2 (is calculated by formula 2). But,
as description in HWM (chapter 10A.3.1.2 Normal Mode.)

If (TEMP_CODE < THCODE2[11:0]) CTEMP value should be val1.
If (TEMP_CODE > THCODE2[11:0]) CTEMP value should be val2.

Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>

authored by

Yoshihiro Kaneko and committed by
Eduardo Valentin
6a310f8f bdc4480a

+18 -10
+18 -10
drivers/thermal/rcar_gen3_thermal.c
··· 62 62 63 63 #define TSC_MAX_NUM 3 64 64 65 + /* default THCODE values if FUSEs are missing */ 66 + static const int thcode[TSC_MAX_NUM][3] = { 67 + { 3397, 2800, 2221 }, 68 + { 3393, 2795, 2216 }, 69 + { 3389, 2805, 2237 }, 70 + }; 71 + 65 72 /* Structure for thermal temperature calculation */ 66 73 struct equation_coefs { 67 74 int a1; ··· 84 77 int low; 85 78 int high; 86 79 int tj_t; 80 + int id; /* thermal channel id */ 87 81 }; 88 82 89 83 struct rcar_gen3_thermal_priv { ··· 134 126 #define TJ_3 -41 135 127 136 128 static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, 137 - int *ptat, int *thcode, 129 + int *ptat, const int *thcode, 138 130 int ths_tj_1) 139 131 { 140 132 /* TODO: Find documentation and document constant calculation formula */ ··· 168 160 static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) 169 161 { 170 162 struct rcar_gen3_thermal_tsc *tsc = devdata; 171 - int mcelsius, val1, val2; 163 + int mcelsius, val; 172 164 u32 reg; 173 165 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 - val1 = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, tsc->coef.a1); 178 - val2 = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, tsc->coef.a2); 179 - mcelsius = FIXPT_TO_MCELSIUS((val1 + val2) / 2); 169 + if (reg <= thcode[tsc->id][1]) 170 + val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, 171 + tsc->coef.a1); 172 + else 173 + val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, 174 + tsc->coef.a2); 175 + mcelsius = FIXPT_TO_MCELSIUS(val); 180 176 181 177 /* Make sure we are inside specifications */ 182 178 if ((mcelsius < MCELSIUS(-40)) || (mcelsius > MCELSIUS(125))) ··· 367 355 /* default values if FUSEs are missing */ 368 356 /* TODO: Read values from hardware on supported platforms */ 369 357 int ptat[3] = { 2631, 1509, 435 }; 370 - int thcode[TSC_MAX_NUM][3] = { 371 - { 3397, 2800, 2221 }, 372 - { 3393, 2795, 2216 }, 373 - { 3389, 2805, 2237 }, 374 - }; 375 358 376 359 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 377 360 if (!priv) ··· 421 414 ret = PTR_ERR(tsc->base); 422 415 goto error_unregister; 423 416 } 417 + tsc->id = i; 424 418 425 419 priv->tscs[i] = tsc; 426 420