How to calculate the constant value used by the imx_init_calib () function in imx_thermal.c?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to calculate the constant value used by the imx_init_calib () function in imx_thermal.c?

1,450 Views
takayuki_ishii
Contributor IV

Hello community,

 

In source code drivers/thermal/imx_thermal.c, to calculate temperature from TEMPMON count value,

it is used following formula in function imx_get_temp()

/* See imx_init_calib() for formula derivation */
if (data->socdata->version == TEMPMON_IMX7D)
*temp = (n_meas - data->c1 + 25) * 1000;
else
*temp = data->c2 - n_meas * data->c1;

 

In this formula, it is use data->c1, data->c2 constant values.

It is calculate in function imx_init_calib().

In this time, 3 fixed value (15423, 4148468, 28581) are used.

How to calculate this values?

 

OCOTP_ANA1 value of my imx6qp SABRE-SD board is 0x5724cd7d

So,

ROOM_COUNT=1394 [0x572]

HOT_COUNT=1229 [0x4cd]

HOT_TEMP=125 [0x7d]

I can't calculate c1, c2 value because I can't calculate 15423 and 4148468 from OCOTP_ANA1 value.

 

The other hand, where come from T1' = 28.580661 °C used in the kernel source code?

https://source.codeaurora.org/external/imxsupport/linux-imx/tree/drivers/thermal/imx_thermal.c?h=kor...

 

Best regards,

Ishii.

0 Kudos
7 Replies

1,204 Views
b36401
NXP Employee
NXP Employee

As noted in i.MX6QP Reference Manual calculation formula of Tmeas is:
T2 - (Nmeas - N2) * ((T2 - T1) / (N1 - N2))
The temperature calibration point fuse values are available in the OCOTP_ANA1 register.

0 Kudos

1,239 Views
josephzhou1
Contributor V

do

Best Regards,
Joseph Zhou Jianhui / Senior Embedded Software Engineer, Singapore
0 Kudos

1,230 Views
takayuki_ishii
Contributor IV

Hello Joseph and NXP support members,

 

Thank you for your reply.

I found a reason of this change in "i.MX 6 Temperature Sensor Module"

Application Note AN5215 at following community thread.

https://www.nxp.com/docs/en/application-note/AN5215.pdf

https://community.nxp.com/t5/i-MX-Processors/Can-someone-point-me-to-the-cpu-temperature-sensor-cali...

 

Best regards,

Ishii.

 

 

0 Kudos

1,247 Views
b36401
NXP Employee
NXP Employee

As noted in i.MX6QP Reference Manual calculation formula of Tmeas is:
T2 - (Nmeas - N2) * ((T2 - T1) / (N1 - N2))
The temperature calibration point fuse values are available in the OCOTP_ANA1 register.

0 Kudos

1,442 Views
b36401
NXP Employee
NXP Employee

There is 2 points approximation:
temp= ( n_meas - n1) + 25
where n1 is the fuse value for 25C (factory provided).

0 Kudos

1,435 Views
takayuki_ishii
Contributor IV

Hello NXP tech support member,

 

I understand what are you saying.

And sorry for my less information.

 

I use i.MX6QuadPlus.

Your answer is for i.MX7.

It would be grateful if you could let me know a method for i.MX6QP..

 

Best regards,

Ishii.

0 Kudos

1,439 Views
takayuki_ishii
Contributor IV

Hello  support member,

 

Sorry but I can't understand what are you saying.

I hope to know why is it use fixed value 15423 and 4148468 in imx_thermal.c?

I think that it must calculate from the fuse value for 25C and HOT_TEMP (factory provided).

 

I add following dev_info message to output OCOTP_ANA1 and TEMPMON_TEMPSENSE0 register value to imx_thermal.c.

In function imx_init_calib()

n1 = ocotp_ana1 >> 20;

temp64 = 10000000; /* use 10^7 as fixed point constant for values in formula */
temp64 *= 1000; /* to get result in °mC */
do_div(temp64, 15423 * n1 - 4148468);
data->c1 = temp64;
data->c2 = n1 * data->c1 + 28581;

#ifdef TEMPMON_DEBUGOUT
dev_info(&pdev->dev, " ocotp_ana1=0x%08x data C1=%d, C2=%d\n", ocotp_ana1, data->c1, data->c2);
#endif

In function imx_get_temp()

/* See imx_init_calib() for formula derivation */
if (data->socdata->version == TEMPMON_IMX7D)
*temp = (n_meas - data->c1 + 25) * 1000;
else
*temp = data->c2 - n_meas * data->c1;

dev_info(&tz->device, "TEMPMON0=0x%08x TEMP_CNT=0x%04x TEMP=%d\n", val, n_meas, *temp);

And OCOTP_ANA1 message log as following.

[ 3.719692] imx_thermal 20c8000.anatop:tempmon: ocotp_ana1=0x5724cd7d data C1=576, C2=831525

thermal_zone0/temp value as following.

$ cat /sys/class/thermal/thermal_zone0/temp

[ 29.159066] thermal thermal_zone0: TEMPMON0=0x4db56106 TEMP_CNT=0x0561 TEMP=38373

38373

In this time,

TEMPMON_TEMPSENSE0 = 0x4db56106

n_meas=0x0561=1377

OCOTP_ANA1 = 0x5724cd7d

n1 = 0x572 = 1394

 

Best regards,

Ishii.