Skip to content

fix: axp2202: reject invalid TDIE ADC readings - #19

Draft
xzl01 wants to merge 1 commit into
radxa:cubie-aiot-v1.5.0from
xzl01:fix-axp2202-temp
Draft

fix: axp2202: reject invalid TDIE ADC readings#19
xzl01 wants to merge 1 commit into
radxa:cubie-aiot-v1.5.0from
xzl01:fix-axp2202-temp

Conversation

@xzl01

@xzl01 xzl01 commented Aug 6, 2026

Copy link
Copy Markdown

The USB power driver reported a bogus 435.2 degC temperature when the ADC returned all-zero data (raw=0 -> (753-0)*1000/173 = 4352). Add a high-byte mask, reject raw==0 with -ENODATA, and sanity-check the result to the -50..150 C range so the thermal zone does not show a fake temperature.

ℹ️ 依赖顺序: 本 PR 是 radxa-pkg/linux-aw2607#1 的前置依赖。

The USB power driver reported a bogus 435.2 degC temperature when the
ADC returned all-zero data (raw=0 -> (753-0)*1000/173 = 4352). Add a
high-byte mask, reject raw==0 with -ENODATA, and sanity-check the result
to the -50..150 C range so the thermal zone does not show a fake
temperature.
int temp, old_temp, raw;
int ret = 0;

ret = regmap_update_bits(regmap, AXP2202_ADC_DATA_SEL, 0x03, AXP2202_ADC_TDIE_SEL); /* ADC channel select */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥移除注释呢……

if (ret < 0)
return ret;
old_temp = (753 - ((data[0] << 8) + data[1])) * 1000 / 173;
raw = ((data[0] & 0x3F) << 8) + data[1];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么只保留data[0]最后6位数据,数据手册说精度是14位么

}

/* Reject faulty/uninitialized ADC readings (-50..150 C). */
if (temp < -500 || temp > 1500)

@RadxaYuntian RadxaYuntian Aug 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

芯片手册有说温度区间么
这个-50到150的区间感觉太arbitrary了,实际使用的时候会除了0以外还会回报这区间之外的数据么?没有的话我感觉没必要限制

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants