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>
Keep charging on at all times, to avoid brick faults
If a device has low battery, and you:
1. Unplugg chargers
2. Set mode to "Charger" in sysfs
3. Shutdown the device
It is bricked until the battery is plugged in and out.
This should fix that.
The ffs() is for finding the first set bit, not what we want - the last
set bit of a bit mask. Actually, the whole ffs/fls can go wrong very
easily depending on what the bit mask is. Let's explicitly define the
needed bit shift and kill ffs/fls use completely, so that we fix
incorrect setting on register CNFG_01, CNFG_03 and CNFG_04.
While at it, simply the writing to CNFG_04 by using regmap_write()
rather than regmap_update_bits(), since we need to update all fields
of the register, i.e. CHG_CV_PRM and MINVSYS.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
If the charging mode 0 is retained during device reset,
this will possibly cause a "deadlock" requiring complete battery
drain before device may be re-charged.
The property POWER_SUPPLY_PROP_CURRENT_NOW is expected to be the
real-time charging current, while what we have in charger driver for
this property is just a static configuration we set into CHG_CC bits
of register CHG_CNFG_02, which is Fast-Charge Current Selection.
Rather than /sys/class/power_supply/max77818-charger/current_now,
battery driver sysfs entry /sys/class/power_supply/max77818_battery/current_now
should be used for checking real-time charging current. So let's
remove the property from charger driver, so that users are not confused
by it's current_now sysfs entry.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
This file has nothing to do with zero-sugar, and
nothing to do with charging. It also has nothing
to do with the commit it was added in. Thus, I'm
deleting it.
Besides "Charger" and "OTG Supply", it supports the third state "Off"
for charger_mode property. To set the propety to "Off" state, either of
the following command should work.
1. $ echo 2 > /sys/class/power_supply/max77818-charger/charger_mode
2. $ echo Off > /sys/class/power_supply/max77818-charger/charger_mode
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Now charger driver can automatically turn on/off charger for as needed,
so we do not want to allow ONLINE property writeable from outside.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
It improves max77818_charger_set_enable() function call and usage in
the following aspects.
- Print MODE value to be set with dev_info().
- Add error messages for possible failures, so that we do not have to
check return for every single calling.
- Always set MODE_OTG_BUCK_BOOST as long as we set enabling for OTG
mode, because we do not want implicit disabling but explicit disabling
by calling max77818_charger_set_enable(0).
- When we set charger_mode property, we should enable or disable charger
according to charger availability, rather than always disabling.
- Change dev_info() to dev_dbg() in max77818_do_irq(), as we are already
printing MODE value, which is more important.
- Ignore interrupt in OTG mode, as we do not want to actively manage
charger on/off for OTG mode, but only when charger_mode property is
set.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The field 'present' is only used once in max77818_charger_update()
function. It doesn't really need to be defined in struct
max77818_charger. Let's drop it. In the meantime, move around the
code a little bit and save the xxx_UNKNOWN assignments, as they have
been done just above.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Charging in FASTCHARGE_CC/CV could be because of that the other charger
rather than the one being checked is present. So we need to add one
more condition to ensure the other charger is not present.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The dtls[] data type should be u8, so that regmap_buck_read() can read
correct DTLS_00 ~ DTLS02 values into dtls[3].
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
These two functions now only enable/disable charger and are called by
max77818_do_irq(). Let's simplify the code a little bit by drop the
functions and call max77818_charger_set_enable() from max77818_do_irq()
directly.
While at it, flip the order of dev_info() message output and
max77818_charger_set_enable() call, as it's more natural to print the
event message and then take action on the event.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
As charge current can not be set by .set_property hook any more, the
only place we need to set charge current is from max77818_charger_initialize().
So let's drop max77818_charger_set_charge_current() function and write
register directly in max77818_charger_initialize().
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
There could be situation where charger is present but it's not charging,
like charger is in timer fault, suspend, input invalid, junction
temperature (see register DETAILS_01, bits CHG_DTLS for details).
As battery driver reports its charging status by looking at online
property of charger device, this causes confusion that charger reports
Not Charging while in the meantime battery reports Charging status.
It's more accurate to report charger online status by looking at
CHARGING state, so that charger and battery stay consistent on charging
status.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
In OTG supply mode, we should allow WCIN to power system and charge
battery. So mode 0x0F should be better than 0x0E.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
In case there is no corresponding properties found in device tree, the
charger settings should be using values coming out of hardware reset,
which are most sensible ones.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The fast charge current and input current limit property shouldn't be
changed by user space. Let's make them non-writeable.
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>
With max77818 mfd, charger, battery and regulator drivers being
cleaned up, these headers are now unneeded. Remove them.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
- Fix kernel WARNING below, which is caused by irq_set_status_flags()
with argument IRQ_NOAUTOEN and enable_irq().
WARNING: CPU: 1 PID: 1 at kernel/irq/manage.c:1390 __setup_irq+0x6d0/0x71c
- Improve coding style of the driver to make it a classic Linux style
driver.
- Clean up unused and unnecessary codes, like IO accessors, IRQ helpers,
as sub-device driver can handle these on their own needs.
- Drop unnecessary mutex locking.
- Save functions max77818_pmic_irq_int(), max77818_pmic_setup() and
max77818_destroy() by putting related code into .probe/.remove to
simplify calling sequence.
- Drop max77818_pmic_get_platdata() since we do not need to parse
"max77818,int-gpio" property to get IRQ number on our (recent) kernel
version.
- Add .of_compatible field into max77818_devices[], so that sub-device
driver doesn't need to find and attach their of_node.
- Use module_i2c_driver() to save max77818_init() and max77818_exit().
- Clean up include/linux/mfd/max77818/max77818.h to drop unused stuff.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The regulator driver is much overloaded on our (recent) kernel version.
Let's clean up the code only needed for old version kernel, and also
remove the code parsing regulator init data from device tree, as
regulator core code is able to handle it, as long as we pass required
info via .of_match and .regulators_node in struct regulator_desc.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Starting with the task to have a thorough review on the driver, I ended
up with fixing a couple of issues and cleaning up the code quite a lot.
- The termination_time is written to the wrong register. It should be
CNFG_03 instead of CNFG_09.
- A reasonable default topoff_timer should be 30 minutes according to
the reset value in data sheet.
- Fix broken interrupt code and CHGIN/WCIN insert/remove event can now
be triggered.
- Remove those verbose debugging message output.
- Improve coding style of the driver to make it a classic Linux style
driver.
- Rather than calling helpers provided max77818 mfd driver, call into
regmap functions directly, as those helpers are not so helpful, and
we may want to drop them from max77818 mfd driver later.
- Drop max77818_charger_pm_ops as the functions do nothing there.
- Use module_platform_driver() to save some code.
There are quite many function shifting and code tweaking with the
cleanup, which makes the reviewing code a lot harder (sorry about that).
So it might be easier to review the driver file rather than diff. At
end of the day, the commit shouldn't introduce any regression but only
fix issues and enable interrupt support.
But there are still a few things worth discussion and possibly further
works.
- The driver currently allows user to change charger current setting.
Should we really allow this? I quote the following from max77818
data sheet:
"Maxim recommends that CHG_CC be set to the maximum acceptable charge
rate for your battery – there is typically no need to actively adjust
the CHG_CC setting based on the capabilities of the source at CHGIN,
system load, or thermal limitations of the PCB"
- MAX77818 data sheet stats that for a particular battery/system, the
following parameters should be set properly.
Determine the following registers bit settings by considering the
characteristics of the battery:
. Charger Restart Threshold - CHG_RSTRT
Default (reset) is 150mV below CHG_CV_PRM (0x01), and we set it
3400mV, which is wrong (I'm fixing it).
. Fast-Charge Timer (tFC) - FCHGTIME
Default is 4 hours (0x01), and we set it disabled (0x00). Is this
really what we want?
. Fast-Charge Current - CHG_CC
Default is 450mA (0x09), and we set it 2800mA (0x38).
. Top-Off Time - TO_TIME
Default is 30 minutes, and we set it 0 minutes (0x00). Is this
really what we want? I'm not even sure what 0x00 means here.
. Top-Off Current - TO_ITH
Default is 150mA (0x01), we set it 200mA (0x04).
. Battery Regulation Voltage - CHG_CV_PRM
Default is 4.2V (0x16), and we set it 4.3V (0x1A).
Determine the following register bit settings by considering the
characteristics of the system:
. Low Battery Prequalification Enable: PQEN
Default is disabled, we use default.
. Minimum System Regulation Voltage: MINVSYS
Default is 3.6V (0x02), and we set it 3.4V (0x00).
. Junction Temperature Thermal Regulation Loop Setpoint: REGTEMP
Default is 115C (0x02), and we use default.
- Do we need to enable watchdog timer?
- Do we need to detect and handle over-current condition by setting
bit DISIBS in CNFG_00 to force MBATT-SYS FET off?
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>
Since the cma setting has been moved to dts file. Add this partation to
7d dtsi to make cma pool building successful on 7d soc.
Signed-off-by: Shawn Xiao <b49994@freescale.com>
To support suspend/resume from LPSR mode, we need to select default
pinctrl state in resume, so that IOMUXC settings can be restored from
power losing.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
[Grzegorz: fix compilation by including <linux/pinctrl/consumer.h> which
is needed after porting this patch from v4.14 to v5.4]
Signed-off-by: Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org>
In standby sleep, system PMIC BD71815 will go into SUSPEND mode. Let's
turn off those power rails unneeded in SUSPEND mode to save power.
Note: VDD_3V3, LDO1_3V3 and LDO5_1V8 need to be retained, as we want
to wake up system from standby via touch, digitizer and wifi.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
LDO_DVREF should be on during LPSR sleep, as it provides the reference
voltage to LPDDR3. So let's keep it on for LPSR state.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Bit LPSR_MODE should be cleared only when system is going to sleep in
LPSR state. Other than that, the bit should be set for system to get
powered off in SNVS state.
All BUCKs and LDOs will be turned off in SNVS state, only except LDO3.
So we need to change the default setting to turn off LDO3 in SNVS state.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
As suggested by Bent, it disables unused/unneeded BD71815 functions,
like RTC, charger, battery, LED and so on, to save a bit more power.
Since we are now doing more BD71815 hardware initialization than LPSR
related configuration, function bd7181x_lpsr_init() gets renamed to
bd7181x_hw_init().
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
To support suspend/resume from LPSR mode, we need to select default
pinctrl state in resume, so that IOMUXC settings can be restored from
power losing.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The DVS buck setup should only be done in case that i2c_dvs_enable is
true. Otherwise, we should skip it to avoid the following noisy
messages.
bd7181x-pmic bd7181x-pmic: Buck0: DVS High-Low[0 - 0].
bd7181x-pmic bd7181x-pmic: bd7181x_buck12_dvs_init(): not found selector for voltage [0]
bd7181x-pmic bd7181x-pmic: bd7181x_buck12_dvs_init(): not found selector for voltage [0]
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
The initial register settings on PWRCTRL, GPO and CHG_SET1 are not
really necessary.
1. RESTARTEN is the mask of Bit0, which is for ROHM factory only in
PWRCTRL.
2. We do not use GPIO of BD7181X so far, and there is no need for
initial setting.
3. We do not use BD7181X charger but a separate charger MAX77818, so
it shouldn't be enabled at all.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
There is a section mismatch warning seen at the kernel image link stage.
LD vmlinux.o
MODPOST vmlinux.o
WARNING: modpost: Found 1 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
Build kernel with CONFIG_DEBUG_SECTION_MISMATCH=y, and turns out the
warning comes from bd7181x regulator driver.
WARNING: vmlinux.o(.data+0x1fd3c): Section mismatch in reference from
the variable bd7181x_driver to the function .init.text:bd7181x_probe()
The variable bd7181x_driver references
the function __init bd7181x_probe()
Fix it by dropping __init and __exit annotation which shouldn't be
there.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>