1
0
Fork 0
Commit Graph

888152 Commits (zero-colors)

Author SHA1 Message Date
Steinar Bakkemo 63923b297f max77818-battery/charger: disable chgin (CHGINSEL=0) when max current=0
When charger driver receives a request to set max current for the chgin
interface to 0, the CHGINSEL bit is set to 0 to disable the interface.

When it receives a request to set a non-zero max current for the chgin
interface, the CHGINSEL bit is reset to 1 to re-enable the interface.

When the FG driver receives a notification about a connection change
for the chgin interface, it set the max current for the chgin interface
to 0 (i.e turning it off) through the charger driver.
2021-03-19 23:32:36 +01:00
Steinar Bakkemo ae775ba9bc max77818-charger: add support for default_current_limit DT param
During driver init, the default safe value is set rather than the max possible
input current, which might draw too much from a normal USB host not capable of
supplying extended charge current.
2021-03-19 23:32:36 +01:00
Steinar Bakkemo e15906a2fa max77818-battery: fix usb1/usb2 references => chgin/wcin 2021-03-19 23:32:36 +01:00
Steinar Bakkemo 758234fe1b max77818-battery: limit max current to 100 mA for chgin interface
As a protection against pirate accessory charger equipment, the max
charge current is always limited to 100 mA for the chgin interface.
2021-03-19 23:32:36 +01:00
Steinar Bakkemo 4752993f20 max77818-battery: add errorhandling/deallocation before exiting probe with error 2021-03-19 23:32:36 +01:00
Steinar Bakkemo 99945913ba max77818-battery: aplit up probe to clarify initiation process 2021-03-19 23:32:35 +01:00
Steinar Bakkemo ec03fc992b max77818-battery-utils: add dyn debug indicating lock/unlock during FGCC ops 2021-03-19 23:32:35 +01:00
Steinar Bakkemo 7eeea007da max77818-battery: add support for new usb_safe_max_current DT param
Use new usb_safe_max_current DT param to set default max current during init,
and not hard-coded value of 500 mA.
2021-03-19 23:32:35 +01:00
Steinar Bakkemo 8efe8fd2c1 max77818-mfd/battery-utils: fix possible kernel panic on missing ptr 2021-03-19 23:32:35 +01:00
Steinar Bakkemo ce33bb06f4 max77818-battery: minor debug comment fixup 2021-03-19 23:32:35 +01:00
Steinar Bakkemo 6dc5cd6235 max77818-battery: fix what seems to be a bug that might cause race during probe
Clear and not set the init_complete flag at the start of probe, before
power supply device is registered.
2021-03-19 23:32:35 +01:00
Steinar Bakkemo 8e8c8d6b0f max77818-mfd/battery/charger: move charger IRQ handling to battery driver
- Do initiation of the charger irq regmap in the MFD driver while disabling FGCC
- Initiate charger interrupts in battery driver while disabling FGCC
- Add new charger irq handler in battery driver requesting status_ex
  property from charger driver while disabling FGCC
  (enabling separate status for chgin/wcin)
2021-03-19 23:32:35 +01:00
Steinar Bakkemo a5ade446a1 power-supply: add changing and unknown to POWER_SUPPLY_PROP_STATUS_EX
POWER_SUPPLY_PROP_STATUS_EX_CHANGING and POWER_SUPPLY_PROP_STATUS_EX_UNKNOWN
is added to the set of defined values for the power supply status_ex property.

This is required to indicate to userspace that an interrupt has occured,
and that the connection state is changing, and if the new connection state
could not be read, the status is unknown.
2021-03-19 23:32:34 +01:00
Steinar Bakkemo 75d97406c8 max77818-utils: add MAX77818_START_NON_FGCC_OP/MAX77818_FINISH_NON_FGCC_OP
In order to do a set of operations in sequence while disabling FGCC,
two macros are defined to start by disabling FGCC mode end finish by
re-enabling FGCC mode, while ensuring that the operation is not interrupted
by another similar sequence by applying the same lock as used in the
MAX77818_DO_NON_FGCC_OP macro  when starting the operation and releasing
the lock when finishin the opration.
2021-03-19 23:32:34 +01:00
Steinar Bakkemo 9a0e9b6f96 max77818-battery/battery-utils: move FGCC handling to new max77818-utils module
In order for the FGCC flag to be flipped from modules/drivers external to the
max77818-battery driver, the FGCC enable/disable routine and corresponding
macro doing a non-FGCC operation by flipping the FGCC bit to disable FGCC,
do the operation and re-enable FGCC is moved to an external module max77818-utils.
2021-03-19 23:32:34 +01:00
Steinar Bakkemo e64ad81dfb max77818-battery: add MAX77818_DO_NON_FGCC_OP macro to standardize FGCC flip ops
All operations performed by charger driver which require FGCC mode to be disabled
in order for the driver to be able to communicate with the charger device
basically do the following which now are done with the MAX77818_DO_NON_FGCC_OP
macro:

Disable FGCC
Do required operation
Re-enable FGCC
2021-03-19 23:32:34 +01:00
Steinar Bakkemo 1facbee627 max77818-battery/charger: replace POGO/USB-C refs with chgin/wcin 2021-03-19 23:32:34 +01:00
Steinar Bakkemo 086bcf9191 max77818-charger: add support for setting max current draw for CHGIN/WCIN
The POWER_SUPPLY_PROP_CURRENT_MAX is used to set max current draw on CHGIN,
and the new POWER_SUPPLY_PROP_CURRENT_MAX2 (added to power-supply core for
this purpose) is used to set max current draw on WCIN.
2021-03-19 23:32:34 +01:00
Steinar Bakkemo 0cc7d7ed62 power-supply: add support for setting max current for USB1/USB2 separately
In order for the MAX77818 driver to be able to set the max current separately
for the two VBUS lines, a new property was added (POWER_SUPPLY_PROP_CURRENT_MAX2),
enabling POWER_SUPPLY_PROP_CURRENT_MAX to configure USB1 max current draw and
POWER_SUPPLY_PROP_CURRENT_MAX2 to configure USB2 max current respectively.
2021-03-19 23:32:34 +01:00
Steinar Bakkemo dd36ed4e4e max77818-battery: add usb-phy notification handling for dynamic max current adj.
The max77818-charger driver is used to set updated max current on given
interface, flipping the FGCC bit appropriately to enable charger device config
temporarily.
2021-03-19 23:32:33 +01:00
Lars Ivar Miljeteig a9045f0ee5 max77818-charger: Fix warning on debug output 2021-03-19 23:32:33 +01:00
Steinar Bakkemo 1d5f270f79 max77818-charger: add dynamic debug to output read raw charge state GPIOs 2021-03-19 23:32:33 +01:00
Steinar Bakkemo efb50e5123 max77818-charger: add pm_ops in order to switch/reset pinctrl state after LPSR
When going into LPSR sleep, the power is taken from the GPIO bank used for the
charge state GPIOs.

When returning from LPSR sleep, the GPIO pinctrl state has to be re-initialized
in order to enable the internal pull-up.

As the GPIOs are used as inputs and no other initialization is done during the
initial probe/init of the driver, no further action is required.

[Grzegorz: Fix compilation by including <linux/pinctrl/consumer.h> which
	   is required after porting this patch from kernel v4.14 to v5.4.]
Signed-off-by: Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org>
2021-03-19 23:32:33 +01:00
Steinar Bakkemo 8f744cd5fb max77818-charger: fix related to reading charger_mode in FGCC mode
Add support for recognizing all expected read back charger_mode values.

Remove unwanted side-effect causing charger_mode to be written when
unrecognized value is read back.

When reading back charger_mode and the batery is (nearly) full,
the read back charger_mode from the charger device is not necessarily the same
as the written value due to internal states being triggered by current state
if charge. A mode 0x05 (Charger) written might yield a read back value of 0x04,
which is ok when the capacity is 100% but still an indication that the charger_mode
is set to "Charger".

Also when writing mode 0x00 (Off), the read back value might yield 0x01..0x03,
which has to be accepted as "Off".
2021-03-19 23:32:33 +01:00
Steinar Bakkemo e8fc755391 max77818-battery: improve FGCC enable/disable (configurable delay)
Add post_fgcc_change_delay_us module parameter with default value
100000 us.

Move delay into FGCC enable/disable function.
Add delay both after FGCC enable and disable.
2021-03-19 23:32:33 +01:00
Steinar Bakkemo c75b3d92f4 max77818-battery: fix mixed up lock/write/unlock => unlock/write/lock 2021-03-19 23:32:33 +01:00
Steinar Bakkemo ca7e308d84 max77818-battery: set 'is_learn_value' for iavg-min register 2021-03-19 23:32:32 +01:00
Steinar Bakkemo 7d8c0e22d8 max77818-battery: set 'is_learn_value' flag for dpacc and dqacc registers
As the dpacc and dqacc registers change over time, these are skipped in addition
to other learned values to prevent them from being overwritten on every boot.
2021-03-19 23:32:32 +01:00
Steinar Bakkemo 4c55834a1c max77818-battery: add unlocking of extra config registers in verify_custom_patems
Unlock and re-lock of extra config registers were separated into common
functions to be used both in initial write_custom_params and new verify/write
routine.

Verification of the RelaxCfg register was also added to the new verify/write routine.
2021-03-19 23:32:32 +01:00
Steinar Bakkemo 5f23b45362 max77818-battery: enable default config-update mode (verify)
- Set 'verify' as the default config-update mode
- Add flag in max77818_of_property (is_learned_value) in order to prevent config
  values given in DT as initial values that is expected to change from being
  reset when device reboots and params are synced to curent DT.
2021-03-19 23:32:32 +01:00
Steinar Bakkemo 03d95da0b4 max77818-battery: add synchronized access to init_done flag
The power_supply get_property handler is protected by a flag indicating
when the config init/update thread is complete, but this flag was not
synchronized.

In addition to this, the flag is now cleared before the driver is registered
as a power_supply device to properly tell the power_supply initiation to wait.
2021-03-19 23:32:32 +01:00
Steinar Bakkemo 9d3734237d max77818-battery: add config_update type 'verify'
If max77818.config_update=verify, and POR is not set, all custom params will
be verified against current DT configuration and updated if required.
2021-03-19 23:32:32 +01:00
Steinar Bakkemo 393931791a max77818-battery: add FG config update params
Add module parameter enabling complete FG config rewrite from DT or
only custom params update from DT depending on what is required.

The driver may be given either "max77818_battery.config_update=complete" or
"max77818_battery.config_update=partial" respectively through the kernel commandline
from u-boot.

Versioning scheme may then be implemented outside of the kernel if required,
and which update to apply to a given device will then be chosen by update scripts.
2021-03-19 23:32:32 +01:00
Steinar Bakkemo 3c5f71a787 max77818-battery: bugfix that was missed before merge (FGCC support) 2021-03-19 23:32:31 +01:00
Steinar Bakkemo 4f5cf60f67 max77818-battery/charger: fix IRQ init issue (charger)
Fix flaw in probe causing IRQ init to be performed in FGCC mode and not when
FGCC is disabled (which is the intension).

Simplify FGCC re-enable code during FG driver init.
2021-03-19 23:32:31 +01:00
Steinar Bakkemo 979c2ca6c3 max77818-charger: added errorhandling to CURRENT_MAX property
The current_max property was not read correctly in FGCC mode,
due to missing errorhandling when charger device is not accessible
over the I2C bus.

An error message is now returned instead of a false value when FGCC
mode is active.
2021-03-19 23:32:31 +01:00
Steinar Bakkemo a2a45cc079 max77818-charger: do actual read from device when getting charger_mode
To make sure the actual charger_mode is returned, an actual read is
done refreshing the shadow value when charger_mode property is read.
2021-03-19 23:32:31 +01:00
Steinar Bakkemo 742d35430f max77818-mfd/charger: add charger regmap ERR_OR_NULL check + 'property get' bugfix
The charger regmap should not be NULL, but to be sure that the regmap is never used
if NULL or ERR_PTR, a check for this has been introduced wherever this is used in
the charger driver.

A check is also done in the MFD driver before trying to initialize the charger irq.

In addition to this, a bug causing a stack dump during boot was found, causing
the powersupply subsystem's initial calls to get_property to fail due to the
mutex was created too late in the probe routine.
2021-03-19 23:32:31 +01:00
Steinar Bakkemo aa059bb115 max77818-battery: add missing mutex init 2021-03-19 23:32:31 +01:00
Steinar Bakkemo 94534ab13c max77818-battery/charger: changes as requested in PR
MAX77818 MFD driver:
- Let drvdata->regmap_chg remain NULL if not initialized,
  for simple validity check
- Remove no longer used label

MAX77818 charger driver:
- Indicate error if chgin_stat_gpio state/wcin_stat_gpio states cannot be read
- Let chgin_stat_gpio/wcin_stat_gpio remain NULL if not initialized,
  for simple validity check
- Define MODE_ALL_OFF = 0x00 (POWER_SUPPLY_MODE_ALL_OFF)
- Add initial charger_mode read from device during initialization,
  and set to Charger if unknown mode is read
  (not corresponding to defined power supply charger modes)
- charger_update routine no longer returns a value

MAX77818 battery/FG driver:
- Define CONFIG_FGCC_BIT
- Add mutex to drvdata
- Improve variable naming
- Add mutex locking to charger_mode get/set functions
- Add proper FGCC mode restoration check in charger_mode get function
- Add warnings if regmap read/writes fails during custom param init
2021-03-19 23:32:31 +01:00
Steinar Bakkemo a4aaa9458c max77818-battery/charger: add support for charger_mode readback through FG drv 2021-03-19 23:32:30 +01:00
Steinar Bakkemo 0b040cc7cf max77818-battery: add charger_mode property to be forwarded to charger
charger_mode property was added to FG driver in order to disable
FGCC mode before forwarding the property change request to the charger driver,
before turning the FGCC mode back on after successfully changing the charger mode.
2021-03-19 23:32:30 +01:00
Steinar Bakkemo d8c5f24f34 max77818-mfd/charger: add support for 'zombie' max77818 charger driver
Add support for "zombie" max77818-charger driver with GPIO based con-stat
- The max77818-battery and the max77818-charger drivers are now loaded regardless
of the failed communication with the charger device over I2C.

Adapt status_ex property to use GPIO based connection status when charger
device is offline from the I2C bus.
2021-03-19 23:32:30 +01:00
Steinar Bakkemo 8e192ca744 max77818-battery: fix "comma+space" issue in custom_param_list (PR comment) 2021-03-19 23:32:30 +01:00
Steinar Bakkemo 68da196c74 max77818-battery: improve custom property retrieval from DT
Parameters are verified, and not-given parameters now results in
a warning and default values are kept instead of writing 0 for all
properties not found in DT.
2021-03-19 23:32:30 +01:00
Steinar Bakkemo 0e80e22a4f max77818-battery: fix ordering of new smart charge register definitions
Correct FG parameter ordering (by register offset)
2021-03-19 23:32:30 +01:00
Steinar Bakkemo 3a1f40614d max77818-battery: add debug output/warnings in DT parameter parsing
Optional debug output when parameter is written.
Warning if parameter is not given.
Warning if paraeter is given, but value is not expected format (not u16).
2021-03-19 23:32:30 +01:00
Steinar Bakkemo 96cb69de41 max77818-battery: add support for DT params related to smart charging/FGCC
Add support for new params defined in DT (register definitions/driver init):
    TAlrtTh
    TAlrtTh2
    JEITA_Curr
    JEITA_Volt
    ChargeState0..7
2021-03-19 23:32:29 +01:00
Shawn Guo 6fa52f4728 max77818_battery: work around battery presence issue
MAX77818 battery presence STATUS bit is not working on our device for
some reason unknown yet. We are working around the issue here by reading
temperature register, in which a negative value indicates absence of
battery.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
2021-03-19 23:32:29 +01:00
Steinar Bakkemo d512eb3577 max77818-battery: add support for tGain/tOFF/tCurve FG params
Read tGain/tOFF/tCurve from DT during driver init.

Note:
FG/battery driver has to re-init the device for changes to occur on
already configured devices, and this is normally only done right after
initial power-on with un-configured device.

A solution for this is however under development, which will make sure
that selected FG parameters are validated during each boot.
2021-03-19 23:32:29 +01:00