fix: axp2202: reject invalid TDIE ADC readings - #19
Draft
xzl01 wants to merge 1 commit into
Draft
Conversation
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.
RadxaYuntian
reviewed
Aug 6, 2026
| 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 */ |
| if (ret < 0) | ||
| return ret; | ||
| old_temp = (753 - ((data[0] << 8) + data[1])) * 1000 / 173; | ||
| raw = ((data[0] & 0x3F) << 8) + data[1]; |
Member
There was a problem hiding this comment.
为什么只保留data[0]最后6位数据,数据手册说精度是14位么
| } | ||
|
|
||
| /* Reject faulty/uninitialized ADC readings (-50..150 C). */ | ||
| if (temp < -500 || temp > 1500) |
Member
There was a problem hiding this comment.
芯片手册有说温度区间么
这个-50到150的区间感觉太arbitrary了,实际使用的时候会除了0以外还会回报这区间之外的数据么?没有的话我感觉没必要限制
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.