linux icon indicating copy to clipboard operation
linux copied to clipboard

Max8998 charger

Open PabloPL opened this issue 6 years ago • 2 comments

Without this it's impossible to charge batter, when using mainline kernel.

Prepared v2 version of patchset and send to LKML.

PabloPL avatar Jul 14 '18 12:07 PabloPL

Charger-manager support created at https://github.com/PabloPL/linux/tree/for-upstream/charger-manager

Appears to work just fine on Fascinate4G. i9000 has slightly different thermal values.

xc-racer99 avatar Oct 18 '19 23:10 xc-racer99

Alright, I've spent a lot of work on this lately trying to figure out how best to implement charging. The best documentation I've found is:

  • https://github.com/xc-racer99/blastoff_kernel_samsung_galaxys4g/blob/gingerbread/include/linux/mfd/max8998-private.h which contains all the register definitions
  • http://www.ti.com/lit/ds/symlink/lp3974.pdf which is a product brief for the lp3974 (mostly register compatible with the max8998, just some differences in charging currents and RTC quirks from what I can tell)
  • https://datasheets.maximintegrated.com/en/ds/MAX8939-MAX8939B.pdf - datasheet for a similar chip from maxim that has a good description of what the eoc, restart, temp, etc parameters do.

Edit: There's also the low bat alarms, two are supported. Config is in the older kernel header max8998_function.h Important struct is

// LBCNFG
typedef enum {
    LBHYST_100mV,
    LBHYST_200mV,
    LBHYST_300mV,
    LBHYST_400mV,
    LBTH_2p9V,
    LBTH_3p0V,
    LBTH_3p1V,
    LBTH_3p2V,
    LBTH_3p3V,
    LBTH_3p4V,
    LBTH_3p5V,
    LBTH_3p57V
} lbcnfg_type;

I've noticed a few things:

  • There's an output proportional to the current output (BATTMON), but this appears to only be connected on some variants (no on the i9000, yes on the T959P)
  • The Nexus S actually uses the lp3974 (seen in middle-right of ifixit's teardown image at https://d3nevzfk7ii3be.cloudfront.net/igi/yWH3LRykFuC3YgYf.huge)
  • There's 2 programmable max voltage levels, 4.2V and 4.35V - we used 4.2V
  • There's 4 possible max temperature values, we use 105 (see max8998-private.h linked above, this info isn't present in most versions of this file)
    • However, we actually have an external temperature monitoring system that it is used instead (via ADC + thermistor)
  • The in-kernel max8998_charger.c is designed for an external regulator for charger on/off + current control, but this was never merged (see https://lore.kernel.org/lkml/[email protected]/)

I've submitted a few things to mainline (none of which are currently merged):

  • Fixes for the ONLINE and STATUS props in max8998_charger.c
  • An initial version of the CHARGER regulator (but this was before I found the old patch and didn't have the different values for lp3974)
  • Fixes for charger-manager so that it works properly in all situations

It might be worthwhile to create a proper max8998 charging function if the CHARGER regulator patches are denied. We would lose the custom temperature shutoff value, but otherwise I think everything would work.

Edit: BATTMON doesn't appear to be providing the temperature as it can be disabled and temperature still read (ie we have an external resistor). ENVICHG is related to the charge current, disabling it makes ADC channel 2 read 0, plus goes to 0 when not charging.

Edit 2: TOPOFF values are percentage of fast charging current, RESTART values are voltage drops (in mV) before restarting charging.

xc-racer99 avatar May 18 '20 15:05 xc-racer99