Linux-fslc temperature calibration in kernel driver imx_thermal.c

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

Linux-fslc temperature calibration in kernel driver imx_thermal.c

435 Views
ennebi
Contributor II

Hi,

I'm using Linux-fslc with imx6ull.

I observed that the "i.MX 6ULL Applications Processor Reference Manual", at "Chapter 52 Temperature Monitor" specifies that temperature calibration is defined with 2 points:

- (N1, T1) = (ROOM_COUNT, 25.0)

- (N2, T2) = (HOT_COUNT, HOT_TEMP)

While the kernel driver imx_thermal.c (5.15 and 6.12 are the same), in imx_init_calib() considers only one calibration point: the OCOTP_ANA1[ROOM_COUNT] at 25°C as in the following code extract:

 

static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1)
{
	struct imx_thermal_data *data = platform_get_drvdata(pdev);
	int n1;
	u64 temp64;

	if (ocotp_ana1 == 0 || ocotp_ana1 == ~0) {
		dev_err(&pdev->dev, "invalid sensor calibration data\n");
		return -EINVAL;
	}

	/*
	 * On i.MX7D, we only use the calibration data at 25C to get the temp,
	 * Tmeas = ( Nmeas - n1) + 25; n1 is the fuse value for 25C.
	 */
	if (data->socdata->version == TEMPMON_IMX7D) {
		data->c1 = (ocotp_ana1 >> 9) & 0x1ff;
		return 0;
	}

	/*
	 * The sensor is calibrated at 25 °C (aka T1) and the value measured
	 * (aka N1) at this temperature is provided in bits [31:20] in the
	 * i.MX's OCOTP value ANA1.
	 * To find the actual temperature T, the following formula has to be used
	 * when reading value n from the sensor:
	 *
	 * T = T1 + (N - N1) / (0.4148468 - 0.0015423 * N1) °C + 3.580661 °C
	 *   = [T1' - N1 / (0.4148468 - 0.0015423 * N1) °C] + N / (0.4148468 - 0.0015423 * N1) °C
	 *   = [T1' + N1 / (0.0015423 * N1 - 0.4148468) °C] - N / (0.0015423 * N1 - 0.4148468) °C
	 *   = c2 - c1 * N
	 *
	 * with
	 *
	 *  T1' = 28.580661 °C
	 *   c1 = 1 / (0.0015423 * N1 - 0.4297157) °C
	 *   c2 = T1' + N1 / (0.0015423 * N1 - 0.4148468) °C
	 *      = T1' + N1 * c1
	 */
	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;

	return 0;
}

 

This line 'n1 = ocotp_ana1 >> 20', drops OCOTP_ANA1[HOT_COUNT] and OCOTP_ANA1[HOT_TEMP] and this leads to temperature inconsistencies.

 

To confirm this, I did some verifications on a board, by reading registers and calculating trip temperatures:

  • Calibration register OCOTP_ANA1=0x50F4A269
    • ROOM_COUNT=0x50F = 1295
    • HOT_COUNT=0x4A2 = 1186
    • HOT_TEMP(°C)=0x69=105
  • TEMPMON_TEMPSENSE0=0x4A551206
    • ALARM_VALUE=0x4A5=1189
  • TEMPMON_TEMPSENSE2= 0x049D0FFF
    • PANIC_ALARM_VALUE=49D=1181

than I converted [ALARM_VALUE] and  [PANIC_ALARM_VALUE] to celsius temperature according to reference manual indication:

  • Tmeas = HOT_TEMP - (Nmeas - HOT_COUNT) * ((HOT_TEMP - 25.0) /
    (ROOM_COUNT – HOT_COUNT))

so I got:

  • Alarm/Passive temperature = 102,8°C
  • Panic temperature = 108.7°C

those temperatures are greater than default trip temperature:

 

  • Alarm/passive temperature = 95°C (10°c less than max temperature of 105°C)
  • Panic temperature = 100°C (5°C less than max temperature of 105°C)

This looks like a potentially critical issue in the driver where the panic temperature is already above the maximum operating temperature from datasheet.

Can you confirm the issue?

Labels (1)
0 Kudos
Reply
3 Replies

351 Views
JorgeCas
NXP TechSupport
NXP TechSupport

Hello,

Have you encountered any temperature measurement inaccuracies or trip temperature points are incorrect?

I have discussed the code with owner. It's an very old code and he though the algorithm should be okay.

Best regards.

0 Kudos
Reply

303 Views
ennebi
Contributor II

Hi Jorge,

as I reported in my initial post, I confirm you that trip temperature points are incorrect:

  • actual Alarm/Passive temperature is 102,8°C instead of 95°C
  • actual Panic temperature is 108.7°C instead of 100°C

This is a potentially critical issue, the panic temperature is above the maximum operating temperature of 105°C.

0 Kudos
Reply

163 Views
JorgeCas
NXP TechSupport
NXP TechSupport

Hello,

The coefficients used for single-point calibration and two-point calibration differ significantly. Regarding your question—have you compared the temperature derived from single-point calibration against actual ambient conditions to assess error margins?

On iMX6, single-point calibration is applied with calculations referenced in imx_init_calib, incorporating additional coefficients c1 and c2. Notably, even imx_set_alarm_temp utilizes single-point calibration coefficients when configuring alarm thresholds.

Crucially, attempting to inversely convert single-point calibration results using two-point calibration methodology is fundamentally incorrect—the calibration frameworks are not interchangeable or reversible in this manner.

Best regards.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2189166%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELinux-fslc%20temperature%20calibration%20in%20kernel%20driver%20imx_thermal.c%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2189166%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI'm%20using%20Linux-fslc%20with%20imx6ull.%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20observed%20that%20the%20%22i.MX%206ULL%20Applications%20Processor%20Reference%20Manual%22%2C%20at%20%22Chapter%2052%20Temperature%20Monitor%22%20specifies%20that%20temperature%20calibration%20is%20defined%20with%202%20points%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E-%26nbsp%3B(N1%2C%20T1)%20%3D%20(ROOM_COUNT%2C%2025.0)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E-%26nbsp%3B(N2%2C%20T2)%20%3D%20(HOT_COUNT%2C%20HOT_TEMP)%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EWhile%20the%20kernel%20driver%20imx_thermal.c%20(5.15%20and%206.12%20are%20the%20same)%2C%20in%26nbsp%3B%3CSPAN%3Eimx_init_calib()%20considers%20only%20one%20calibration%20point%3A%20the%26nbsp%3BOCOTP_ANA1%5BROOM_COUNT%5D%20at%2025%C2%B0C%20as%20in%20the%20following%20code%20extract%3A%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3Estatic%20int%20imx_init_calib(struct%20platform_device%20*pdev%2C%20u32%20ocotp_ana1)%0A%7B%0A%09struct%20imx_thermal_data%20*data%20%3D%20platform_get_drvdata(pdev)%3B%0A%09int%20n1%3B%0A%09u64%20temp64%3B%0A%0A%09if%20(ocotp_ana1%20%3D%3D%200%20%7C%7C%20ocotp_ana1%20%3D%3D%20~0)%20%7B%0A%09%09dev_err(%26amp%3Bpdev-%26gt%3Bdev%2C%20%22invalid%20sensor%20calibration%20data%5Cn%22)%3B%0A%09%09return%20-EINVAL%3B%0A%09%7D%0A%0A%09%2F*%0A%09%20*%20On%20i.MX7D%2C%20we%20only%20use%20the%20calibration%20data%20at%2025C%20to%20get%20the%20temp%2C%0A%09%20*%20Tmeas%20%3D%20(%20Nmeas%20-%20n1)%20%2B%2025%3B%20n1%20is%20the%20fuse%20value%20for%2025C.%0A%09%20*%2F%0A%09if%20(data-%26gt%3Bsocdata-%26gt%3Bversion%20%3D%3D%20TEMPMON_IMX7D)%20%7B%0A%09%09data-%26gt%3Bc1%20%3D%20(ocotp_ana1%20%26gt%3B%26gt%3B%209)%20%26amp%3B%200x1ff%3B%0A%09%09return%200%3B%0A%09%7D%0A%0A%09%2F*%0A%09%20*%20The%20sensor%20is%20calibrated%20at%2025%20%C2%B0C%20(aka%20T1)%20and%20the%20value%20measured%0A%09%20*%20(aka%20N1)%20at%20this%20temperature%20is%20provided%20in%20bits%20%5B31%3A20%5D%20in%20the%0A%09%20*%20i.MX's%20OCOTP%20value%20ANA1.%0A%09%20*%20To%20find%20the%20actual%20temperature%20T%2C%20the%20following%20formula%20has%20to%20be%20used%0A%09%20*%20when%20reading%20value%20n%20from%20the%20sensor%3A%0A%09%20*%0A%09%20*%20T%20%3D%20T1%20%2B%20(N%20-%20N1)%20%2F%20(0.4148468%20-%200.0015423%20*%20N1)%20%C2%B0C%20%2B%203.580661%20%C2%B0C%0A%09%20*%20%20%20%3D%20%5BT1'%20-%20N1%20%2F%20(0.4148468%20-%200.0015423%20*%20N1)%20%C2%B0C%5D%20%2B%20N%20%2F%20(0.4148468%20-%200.0015423%20*%20N1)%20%C2%B0C%0A%09%20*%20%20%20%3D%20%5BT1'%20%2B%20N1%20%2F%20(0.0015423%20*%20N1%20-%200.4148468)%20%C2%B0C%5D%20-%20N%20%2F%20(0.0015423%20*%20N1%20-%200.4148468)%20%C2%B0C%0A%09%20*%20%20%20%3D%20c2%20-%20c1%20*%20N%0A%09%20*%0A%09%20*%20with%0A%09%20*%0A%09%20*%20%20T1'%20%3D%2028.580661%20%C2%B0C%0A%09%20*%20%20%20c1%20%3D%201%20%2F%20(0.0015423%20*%20N1%20-%200.4297157)%20%C2%B0C%0A%09%20*%20%20%20c2%20%3D%20T1'%20%2B%20N1%20%2F%20(0.0015423%20*%20N1%20-%200.4148468)%20%C2%B0C%0A%09%20*%20%20%20%20%20%20%3D%20T1'%20%2B%20N1%20*%20c1%0A%09%20*%2F%0A%09n1%20%3D%20ocotp_ana1%20%26gt%3B%26gt%3B%2020%3B%0A%0A%09temp64%20%3D%2010000000%3B%20%2F*%20use%2010%5E7%20as%20fixed%20point%20constant%20for%20values%20in%20formula%20*%2F%0A%09temp64%20*%3D%201000%3B%20%2F*%20to%20get%20result%20in%20%C2%B0mC%20*%2F%0A%09do_div(temp64%2C%2015423%20*%20n1%20-%204148468)%3B%0A%09data-%26gt%3Bc1%20%3D%20temp64%3B%0A%09data-%26gt%3Bc2%20%3D%20n1%20*%20data-%26gt%3Bc1%20%2B%2028581%3B%0A%0A%09return%200%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3EThis%20line%20'%3C%2FSPAN%3E%3CSPAN%3En1%20%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%20ocotp_ana1%20%3C%2FSPAN%3E%3CSPAN%3E%26gt%3B%26gt%3B%3C%2FSPAN%3E%20%3CSPAN%3E20'%2C%26nbsp%3Bdrops%26nbsp%3BOCOTP_ANA1%5BHOT_COUNT%5D%20and%26nbsp%3BOCOTP_ANA1%5BHOT_TEMP%5D%20and%20this%20leads%20to%20temperature%26nbsp%3Binconsistencies.%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3ETo%20confirm%20this%2C%20I%20did%20some%20verifications%20on%20a%20board%2C%20by%20reading%20registers%20and%20calculating%20trip%20temperatures%3A%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%3ECalibration%20register%26nbsp%3BOCOTP_ANA1%3D0x50F4A269%3CBR%20%2F%3E%3C%2FSPAN%3E%3CUL%3E%3CLI%3E%3CSPAN%3EROOM_COUNT%3D0x50F%20%3D%201295%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EHOT_COUNT%3D0x4A2%20%3D%201186%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EHOT_TEMP(%C2%B0C)%3D0x69%3D105%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3ETEMPMON_TEMPSENSE0%3D0x4A551206%3C%2FSPAN%3E%3CUL%3E%3CLI%3E%3CSPAN%3EALARM_VALUE%3D0x4A5%3D1189%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3ETEMPMON_TEMPSENSE2%3D%26nbsp%3B0x049D0FFF%3C%2FSPAN%3E%3CUL%3E%3CLI%3E%3CSPAN%3EPANIC_ALARM_VALUE%3D49D%3D1181%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%3Ethan%20I%20converted%20%5BALARM_VALUE%5D%20and%26nbsp%3B%20%5BPANIC_ALARM_VALUE%5D%20to%20celsius%20temperature%20according%20to%20reference%20manual%20indication%3A%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%3ETmeas%20%3D%20HOT_TEMP%20-%20(Nmeas%20-%20HOT_COUNT)%20*%20((HOT_TEMP%20-%2025.0)%20%2F%3CBR%20%2F%3E(ROOM_COUNT%20%E2%80%93%20HOT_COUNT))%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3Eso%20I%20got%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CUL%3E%3CLI%3EAlarm%2FPassive%20temperature%20%3D%20102%2C8%C2%B0C%3C%2FLI%3E%3CLI%3EPanic%20temperature%20%3D%20108.7%C2%B0C%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%3Ethose%20temperatures%20are%20greater%20than%20default%20trip%20temperature%3A%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CUL%3E%3CLI%3E%3CSPAN%3EAlarm%2Fpassive%20temperature%20%3D%2095%C2%B0C%20(10%C2%B0c%20less%20than%20max%20temperature%20of%20105%C2%B0C)%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EPanic%20temperature%20%3D%20100%C2%B0C%20(5%C2%B0C%20less%20than%20max%20temperature%20of%20105%C2%B0C)%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%3EThis%20looks%20like%20a%20potentially%20critical%20issue%20in%20the%20driver%20where%20the%20panic%20temperature%20is%20already%20above%20the%20maximum%20operating%20temperature%20from%20datasheet.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ECan%20you%20confirm%20the%20issue%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2189166%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MX6%20All%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2207009%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Linux-fslc%20temperature%20calibration%20in%20kernel%20driver%20imx_thermal.c%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2207009%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EThe%20coefficients%20used%20for%20single-point%20calibration%20and%20two-point%20calibration%20differ%20significantly.%20Regarding%20your%20question%E2%80%94have%20you%20compared%20the%20temperature%20derived%20from%20single-point%20calibration%20against%20actual%20ambient%20conditions%20to%20assess%20error%20margins%3F%3C%2FP%3E%0A%3CP%3EOn%20iMX6%2C%20single-point%20calibration%20is%20applied%20with%20calculations%20referenced%20in%20imx_init_calib%2C%20incorporating%20additional%20coefficients%20c1%20and%20c2.%20Notably%2C%20even%20imx_set_alarm_temp%20utilizes%20single-point%20calibration%20coefficients%20when%20configuring%20alarm%20thresholds.%3C%2FP%3E%0A%3CP%3ECrucially%2C%20attempting%20to%20inversely%20convert%20single-point%20calibration%20results%20using%20two-point%20calibration%20methodology%20is%20fundamentally%20incorrect%E2%80%94the%20calibration%20frameworks%20are%20not%20interchangeable%20or%20reversible%20in%20this%20manner.%3C%2FP%3E%0A%3CP%3EBest%20regards.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2195167%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Linux-fslc%20temperature%20calibration%20in%20kernel%20driver%20imx_thermal.c%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2195167%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Jorge%2C%3C%2FP%3E%3CP%3Eas%20I%20reported%20in%20my%20initial%20post%2C%20I%20confirm%20you%20that%26nbsp%3B%3CSPAN%3Etrip%20temperature%20points%20are%20incorrect%3A%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3Eactual%20Alarm%2FPassive%20temperature%20is%20102%2C8%C2%B0C%20instead%20of%2095%C2%B0C%3C%2FLI%3E%3CLI%3Eactual%20Panic%20temperature%20is%20108.7%C2%B0C%20instead%20of%20100%C2%B0C%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%3EThis%20is%20a%20potentially%20critical%20issue%2C%20the%20panic%20temperature%20is%20above%20the%20maximum%20operating%20temperature%20of%20105%C2%B0C.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2193655%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Linux-fslc%20temperature%20calibration%20in%20kernel%20driver%20imx_thermal.c%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2193655%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EHave%20you%20encountered%20any%20temperature%20measurement%20inaccuracies%20or%20trip%20temperature%20points%20are%20incorrect%3F%3C%2FP%3E%0A%3CP%3EI%20have%20discussed%20the%20code%20with%20owner.%20It's%20an%20very%20old%20code%20and%20he%20though%20the%20algorithm%20should%20be%20okay.%3C%2FP%3E%0A%3CP%3EBest%20regards.%3C%2FP%3E%3C%2FLINGO-BODY%3E