Repository navigation
fwk: lotus: clamp typec_safety_level in update_safety_power_limit() (CPU stuck at ~600 MHz) - #95
Open
mkornreich wants to merge 1 commit into
Conversation
In LEVEL_TYPEC_1_5A the Type-C safety sub-level was incremented and decremented without bounds, while the ladder only stepped down when the counter was exactly TYPEC_SAFETY_LEVEL_0 (and only stepped up when it was exactly TYPEC_SAFETY_LEVEL_3). The hard throttle applied in LEVEL_PROCHOT cuts the battery discharge current, so the first tick after entering LEVEL_TYPEC_1_5A is usually a decrease tick: the counter goes 0 -> -1 -> -2 ... and never equals TYPEC_SAFETY_LEVEL_0 again. safety_level then never returns to LEVEL_PROCHOT, so throttle_ap(THROTTLE_OFF, THROTTLE_HARD, THROTTLE_SRC_BAT_DISCHG_CURRENT) is never called and the APU stays hard throttled (~600 MHz) until the EC resets, on AC as well as battery. Every tick, cypd_update_safety_table() also indexes the 4-entry safety_table[] with the out-of-range level and passes the result to cypd_select_pdo(); the PD controllers reject it and the EC logs "SET CCG_SELECT_REG failed" about once a second. Clamp the counter to [TYPEC_SAFETY_LEVEL_0, TYPEC_SAFETY_LEVEL_3]. Fixes: 9ff6a96 ("fwk: 16-inch: Reduce the Type-C current once the battery exceed discharge current limit") BRANCH=fwk-tulip-29169 BUG=FrameworkComputer/SoftwareFirmwareIssueTracker#243 TEST=Host simulation of the LEVEL_PROCHOT..LEVEL_COUNT cases. Without this change, PROCHOT followed by 20 decrease ticks leaves the ladder at LEVEL_TYPEC_1_5A with the counter at -20 and the throttle on; with it, the ladder returns to LEVEL_NORMAL and releases the throttle. 1,000,000 random ticks keep the counter within [0, 3]. Not yet built or run on hardware. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
I did use AI for this but it does solve THE CLAMP. It resolves https://community.frame.work/t/cpu-frequency-stuck-at-600-mhz/79713 |
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.
Problem
On the Laptop 16, heavy load that drains the battery can leave every CPU core hard-throttled at ~600 MHz until the EC loses power. Both boards are affected, since tulip and lotus both build
lotus/src/cpu_power.c.Unplugging or replugging the charger, OS reboots and power-profile changes don't clear it. While it's stuck, the EC console logs this for every PD port about once a second:
Reports of this:
Cause
In
update_safety_power_limit(),LEVEL_TYPEC_1_5Aincrements and decrementstypec_safety_levelwithout bounds, but only steps down when the counter equals exactlyTYPEC_SAFETY_LEVEL_0:LEVEL_PROCHOT. That assertsTHROTTLE_SRC_BAT_DISCHG_CURRENTand moves toLEVEL_TYPEC_1_5A, with the counter at 0.LEVEL_PROCHOT, soTHROTTLE_OFFfor that source is never sent.cypd_update_safety_table()indexes the 4-entrysafety_table[]with the negative value and passes the result tocypd_select_pdo(). The PD controllers reject it, which produces the console loop above.Where the code is:
It's unrelated to the PROCHOT pin fix in c6575ef.
Fix
Clamp
typec_safety_levelto[TYPEC_SAFETY_LEVEL_0, TYPEC_SAFETY_LEVEL_3]:LEVEL_PROCHOT, which releases the throttle on the next decrease.Testing
Host simulation of the
LEVEL_PROCHOT..LEVEL_COUNTcases, with the switch block copied verbatim:LEVEL_NORMAL, throttle releasedNot yet built or run on hardware. It should be reproducible on a unit with the existing console hooks:
Seen in the field on a Laptop 16 AI 300 (HX 370, BIOS 04.01): the CPU locked at 603–610 MHz after heavy CPU+GPU load on battery, with the console loop above. Only an EC power cycle cleared it.
🤖 Generated with Claude Code