Skip to content

Save battery thresholds to flash - #498

Merged
crawfxrd merged 2 commits into
masterfrom
save-bct
Nov 26, 2024
Merged

Save battery thresholds to flash#498
crawfxrd merged 2 commits into
masterfrom
save-bct

Conversation

@crawfxrd

@crawfxrd crawfxrd commented Aug 22, 2024

Copy link
Copy Markdown
Member

Make battery thresholds persistent by saving them in flash space. This allows configuring them after EC reset (system powered-off, unplugged) but before any system firmware or OS policy can be applied.

As part of this, the dynamic keymap is moved from the hard-coded address of 0x1FC00 to "the last sector"; Models with 256 KiB flash (CONFIG_EC_FLASH_SIZE_256K=y) will lose their layout and need to reconfigure it.

Test

  • When not configured, default values (90, 100) are used across multiple EC resets
  • When configured, the profile/custom values are used across multiple EC resets
    • If flash is dumped, the values are present in the ROM image

Check values with:

  • system76-power charge-thresholds
  • cat /sys/class/power_supply/BAT0/charge_control_{start,end}_threshold

Comment thread src/board/system76/common/battery.c Outdated
Comment thread src/board/system76/common/battery.c
Comment thread src/board/system76/common/acpi.c
With the use of 256 KiB flash chips, the hard-coded address of 0x1FC00
may no longer be "the last sector".

Signed-off-by: Tim Crawford <tcrawford@system76.com>
jackpot51
jackpot51 previously approved these changes Nov 22, 2024
@crawfxrd

crawfxrd commented Nov 25, 2024

Copy link
Copy Markdown
Member Author

Writing to flash works.

0003f800: 54 42 56 5a ff ff ff ff ff ff ff ff ff ff ff ff  TBVZ............

Reading it back does not.

$ cat /sys/class/power_supply/BAT0/charge_control_{start,end}_threshold
1
1

And I don't know why. And now that I've said it, it's very obvious.

Make battery thresholds persistent by saving them in flash space. This
allows configuring them after EC reset (system powered-off, unplugged)
but before any system firmware or OS policy can be applied.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
@crawfxrd
crawfxrd marked this pull request as ready for review November 25, 2024 23:22
@crawfxrd
crawfxrd requested review from a team and jackpot51 November 25, 2024 23:23
@leviport leviport self-assigned this Nov 26, 2024

@leviport leviport left a comment

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.

Tested on darp10-b, and this seems to be working great. The thresholds I set persist through multiple EC resets. Very nice!

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.

Charging thresholds don't persist through an EC reset

3 participants