max170xx: Battery gauge configuration
According to docs, max17055 requires some inputs to correctly configure its algorithm:
- battery label capacity (DesignCap)
- empty voltage (VEmpty)
- charge voltage (VChg)
- charge termination current (ICHGTerm)
It can also be configured in a more advanced way by providing it a full set of data about battery characteristics, but that's optional. The driver currently implements that full configuration path, but only when using platform data - there's no way to set it from device tree.
When setting the new config values, the gauge model has to be refreshed (Refresh
bit in ModelCfg
register). It shouldn't happen at every boot though since that doesn't allow the gauge to calibrate itself over time. It should only happen once after the gauge configuration has been reset (by taking the battery off). This can be done by checking the STATUS_POR_BIT
in MAX17042_STATUS
register, which is initially set after a gauge reset, and by unsetting it once the initial configuration is applied.
This should allow the gauge to start with a reasonable values and then actually learn to make the outputs more accurate over time.
TODO:
- split into multiple commits
- make sure other chips than max17055 aren't broken by this
- recheck the termination current values
- I guess the new device tree properties should be put into a new node representing the battery itself, since currently they specify behavior instead of describing hardware
Merge request reports
Activity
added 35089 commits
-
b71307e2...c9a41478 - 35088 commits from branch
Librem5:imx8-next-librem5
- 5370ba4a - WIP: max17042: Battery gauge configuration
-
b71307e2...c9a41478 - 35088 commits from branch
added 9 commits
- 65295c1a - max17042_battery: Don't allow to set charge_full property
- d961b38d - max17042_battery: Export charge termination current property
- 0e69fa92 - max17042_battery: Improve accuracy of current_now and current_avg readings
- b1dec0cf - max17042_battery: Take r_sns value into account in charge_counter reading
- 3342aa66 - max17042_battery: Trigger model refresh when setting charge_full_design
- bde53a8f - XXX: max17042_battery: Move enable_por_init check into max17042_init_chip
- 121153a5 - max17042_battery: Move vchg-4V2 handling to POR initialization
- 9fcece2d - max17042_battery: Allow to set termination current via device tree
- 2680ced2 - max17042_battery: Allow to set battery design capacity via device tree
Toggle commit listadded 1 commit
- 4c0e6e2f - imx8mq-librem5: Set battery parameters for each batch
Except of the one commit marked by
XXX
that I have to do differently, this should be ready for initial review now. I intend to send some of these commits upstream (but some of them apply only to our tree at this moment).Edited by Sebastian Krzyszkowiakadded 184 commits
-
4c0e6e2f...66a3d4ad - 174 commits from branch
Librem5:imx8-next-librem5
- dcab1e32 - max17042_battery: Don't allow to set charge_full property
- 33e81dbd - max17042_battery: Export charge termination current property
- 59f87a77 - max17042_battery: Improve accuracy of current_now and current_avg readings
- f06fd7d3 - max17042_battery: Take r_sns value into account in charge_counter reading
- a38db438 - max17042_battery: Trigger model refresh when setting charge_full_design
- 391b67bb - XXX: max17042_battery: Move enable_por_init check into max17042_init_chip
- 94002390 - max17042_battery: Move vchg-4V2 handling to POR initialization
- 2812b6bc - max17042_battery: Allow to set termination current via device tree
- d86ce4a8 - max17042_battery: Allow to set battery design capacity via device tree
- 8fe9536f - imx8mq-librem5: Set battery parameters for each batch
Toggle commit list-
4c0e6e2f...66a3d4ad - 174 commits from branch
mentioned in merge request !259 (merged)
added 21 commits
- 9fa3d2b9 - MLK-24608: drm/imx/dcss: disallow certain modes
- 9b9aabd3 - LF-1512: drm: cdns mhdp: avoid potentially overflowing
- d6423557 - usb: typec: tps6598x: Add more register definitions
- 26da8d02 - usb: typec: tps6598x: Add debugfs
- 9050e30a - usb: typec: tps6589x: Handle DP alt mode changes via extcon
- 7e2a5a9d - drm: cadence/mhdp: Add runtime pm stubs
- 970806d6 - drm: cadence/mhdp: Wire up extcon
- 57012b36 - drm: cadence/mhdp: Don't power on phy before alt mode got negotiated
- 6eb651dd - arm64: dtbs: librem5: Connect extcon
- 25c600f6 - arm64: dts: librem5: Drop separte DP device tree
- 881a096f - arm64: dts: librem5r4: Set sense resistor value
- 5b2cefb9 - max17042_battery: Don't allow to set charge_full property
- 51582c55 - max17042_battery: Export charge termination current property
- 64b20e42 - max17042_battery: Improve accuracy of current_now and current_avg readings
- 227dd6cf - max17042_battery: Take r_sns value into account in charge_counter reading
- e52f9192 - max17042_battery: Trigger model refresh when setting charge_full_design
- 2affc853 - XXX: max17042_battery: Move enable_por_init check into max17042_init_chip
- c8b59755 - max17042_battery: Move vchg-4V2 handling to POR initialization
- 3124aa16 - max17042_battery: Allow to set termination current via device tree
- 4403d4c3 - max17042_battery: Allow to set battery design capacity via device tree
- 23db78e9 - imx8mq-librem5: Set battery parameters for each batch
Toggle commit listadded 1 commit
- 7b6346f2 - max17042_battery: Fix current_{avg,now} hiding with no current sense
added 11 commits
- f0b2eb96 - power: max17042_battery: Fix current_{avg,now} hiding with no current sense
- 5da3b63e - power: max17042_battery: Improve accuracy of current_now and current_avg readings
- ce76438d - power: max17042_battery: Take r_sns value into account in charge_counter
- 0527067b - power: max17042_battery: Export charge termination current property
- 9f9d69f7 - max17042_battery: Don't allow to set charge_full property
- f7ae921c - max17042_battery: Trigger model refresh when setting charge_full_design
- 2a9a796b - XXX: max17042_battery: Move enable_por_init check into max17042_init_chip
- 1490bc8b - max17042_battery: Move vchg-4V2 handling to POR initialization
- 7fcfdaaa - max17042_battery: Allow to set termination current via device tree
- 419e5d81 - max17042_battery: Allow to set battery design capacity via device tree
- fd5fa883 - imx8mq-librem5: Set battery parameters for each batch
Toggle commit listFirst four patches now submitted upstream: https://lore.kernel.org/linux-pm/2264396.HPVdm0XNkV@pliszka/T/
added 56 commits
-
fd5fa883...d3d7d61e - 45 commits from branch
Librem5:imx8-current-librem5
- a2e01c25 - power: max17042_battery: Fix current_{avg,now} hiding with no current sense
- 8cc16c02 - power: max17042_battery: Improve accuracy of current_now and current_avg readings
- c27bc366 - power: max17042_battery: Take r_sns value into account in charge_counter
- df26616a - power: max17042_battery: Export charge termination current property
- f99b2901 - max17042_battery: Don't allow to set charge_full property
- acf7bde7 - max17042_battery: Trigger model refresh when setting charge_full_design
- 9cdf4f17 - XXX: max17042_battery: Move enable_por_init check into max17042_init_chip
- 5f23d8ef - max17042_battery: Move vchg-4V2 handling to POR initialization
- 0feb56cb - max17042_battery: Allow to set termination current via device tree
- 84b7f3a4 - max17042_battery: Allow to set battery design capacity via device tree
- 150edbfd - imx8mq-librem5: Set battery parameters for each batch
Toggle commit list-
fd5fa883...d3d7d61e - 45 commits from branch
- Resolved by Sebastian Krzyszkowiak
@martin.kepplinger @guido.gunther @angus.ainslie I think we should merge this since without it the Evergreen's battery meter is pretty much useless. The first four patches went already into 5.11, the rest are either specific to our fork (since they modify Angus' patches that aren't upstream) or need to be reworked a bit before submitting upstream (which I plan to do in January) but should be fine to go downstream already.
added 943 commits
-
150edbfd...868f3eb8 - 932 commits from branch
Librem5:imx8-current-librem5
- 116b1a72 - power: max17042_battery: Fix current_{avg,now} hiding with no current sense
- d524bf96 - power: max17042_battery: Improve accuracy of current_now and current_avg readings
- 4628191e - power: max17042_battery: Take r_sns value into account in charge_counter
- 71d12ace - power: max17042_battery: Export charge termination current property
- efcd6025 - max17042_battery: Don't allow to set charge_full property
- 41f616c8 - max17042_battery: Trigger model refresh when setting charge_full_design
- cc5ff90c - XXX: max17042_battery: Move enable_por_init check into max17042_init_chip
- 1428e122 - max17042_battery: Move vchg-4V2 handling to POR initialization
- 64c4bf75 - max17042_battery: Allow to set termination current via device tree
- b56ffa72 - max17042_battery: Allow to set battery design capacity via device tree
- 7f7e0a22 - imx8mq-librem5: Set battery parameters for each batch
Toggle commit list-
150edbfd...868f3eb8 - 932 commits from branch