- Handle return code for regmap_write & regmap_read
- Rename some functions with misleading names
i.e "verify" when it actually writes, differentiate
between reading params from chip or device tree, etc
- Don't clear POR bit if writing data failed
- Set init complete even if "write custom params" fail,
as it will eventually time out and continue init anyhow
In order to be able to synchronize initial register write with other
drivers possibly accessing the same registers during init, an option
to apply a mutex lock (defined at the mfd level) is introduced.
The config register is also given a requirement to be locked, as this
register holds the FGCC bit which is the main cause of this option.
Due to uncertainty related to how safe it is to verify each custom
param during every boot, set the skip_verify flag for every custom param except
for the config register which is verified against current DT and reset if changed
for some reason since last boot.
This ensures that if an operation performed through the max77818 charger driver
was aborted by a reboot for instance, and the FGCC bit remained 0, it will be
restored to 1 after a reboot.
Due to the normal FG driver init configuring FGCC to be enabled during its normal
run, where all custom params configured in DT are verified and restored to the
original value if changed since last boot, charger driver sync has to be done
after completion of normal init.
This is now done in a separate worker which waits for the other init to complete
using a simple completion obj.
Also, unlock mutex at early return errors.
The status_ex is read during driver initiation, but the local shadow
variable was not updated, causing the status_ex to be "not connected"
even if the device was powered on with USB-C charger connected.max77818-battery: fix initial status_ex read bug
Operations done during FG driver initiation which address the charger driver is
collected in new init routine, which now reads initial status information required
to be shadowed in the FG driver (status_ex) and disables the chgin interface by
default.
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.
- 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)
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.
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
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.
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.
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.
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.
- 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.
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.
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.
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.
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
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.
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.
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).
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>
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.
The MAX77818 SOC max/min alert is being used to report 1% SOC change.
It's not such an useful event. We need to use the alert to report low
battery event to user space. This patch drops 1% SOC reporting and uses
the max/min alert to report battery SOC event to user space by calling
sysfs_notify() on corresponding sysfs entry.
It disables max SOC alert and set min SOC alert as 10% by default, but
the value can be updated by writing desired value into
/sys/class/power_supply/max77818_battery/capacity_alert_min
/sys/class/power_supply/max77818_battery/capacity_alert_max
Saying we have capacity_alert_min be 10, once SOC goes to 9, INTR_SOCMIN
will be triggered, and the user space program polling capacity_alert_min
sysfs entry will return successfully.
While dropping max77818_set_soc_threshold(), .suspend/.resume hooks are
removed altogether, as enable_irq_wake() has been handled by MAX77818
mfd driver, and disable_irq() has been handled by PM core anyway.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Right now, max77818_battery driver already has 31 sysfs entries
(and thus uevents for power_supply class), which is reaching the
maximum number 32 (see UEVENT_NUM_ENVP in include/linux/kobject.h).
So when trying to add more properties, we will get the following
kernel WARNING in calling power_supply_uevent() -> add_uevent_var().
WARNING: CPU: 1 PID: 93 at lib/kobject_uevent.c:568 add_uevent_var+0xa4/0xcc
add_uevent_var: too many keys
Let's drop some unhelpful properties which do not reflect any hardware
states to leave room for other new useful properties.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Improve the comment on max77818_set_soc_threshold() call in
max77818_resume(), to make it clear why we need to reprogram SOC
threshold when we are back from suspend/sleep state.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The max77818 battery block is simillar to max17042_battery, so we choose
to create max77818_battery by reusing majority of max17042_battery
driver code.
The max77818_battery reuses header max17042_battery.h directly and adds
max77818 specific defines in there. But we do not reuse max17042_battery.c
directly, because it supports I2C device probing while we need platform
device probing. Also the startup sequence and initialization is quite
different between max17042 and max77818. So we end up creating a new
max77818_battery driver with max77818 specific custom parameter parsing
from DT and startup sequence implementation. The majority of
.get_property/.set_property code are copied from max17042 driver, and
we support two more properties, TIME_TO_EMPTY_NOW and TIME_TO_FULL_NOW,
with max77818 driver though.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>