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>
It updates charger parameters per zero-sugar and battery pack
characteristics. Among of these, input_current_limit_chgin and
input_current_limit_wcin are still in discussion and may be updated
later. But input_current_limit_chgin shouldn't exceed fast_charge_current
so much, so let's match it with fast_charge_current for now.
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>
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>
We do not really want to disable fast-charge and top-off timer, as the
former prevents charger from staying in fast-charge stage for too long,
and the latter triggers the entering to top-off stage. So before we
get best settings for our battery pack from vendor, let's drop the
settings from device tree and let driver use the default.
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>
It mixes quite a few max77818 related changes:
- Update fuelgauge device node with all those parameters required by
max77818-fuelgauge driver for initialization.
- SAFEOUT1 regulator shouldn't be boot-on and always-on. Instead, it
supplies OTG1 VBUS which can be turn on/off as needed by USB driver.
As a result, reg_usb_otg1_vbus can be dropped.
- Drop buggy "restart_threshold" property from charger node and let
driver use default setting.
- Add pinctrl for GPIO6_22 which is used as max77818 interrupt line.
- Drop "max77818,int-gpio" which is not needed.
- Drop "okay" status which is only needed to flip device status from
"disabled" from "okay".
- Fix coding style and indentation.
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>
Add prevent-frying-pan property in device tree
to prevent the pan function from looping bad
data to the display. Without this fix, a SW
crash can potentially fry the eInk display.
This is only relevant for the zero-sugar
plattform by reMarkable AS.
The reset sequence via GPIO makes digitizer non-functional. This was not
an issue when we have GPIO1_0 pad configured as WDOG function, because
the reset sequence setting on the GPIO doesn't take any effect. But now
pad configuration is gone and the pad works in GPIO mode by default, so
the reset sequence is taking effect. Let drop this problematic reset
and get digitizer back to work.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Removed CAN, bluetooth, SATA
Removed some PMICs: MAX17135, PFUZE100, PF1550, MC13xxx
Removed video support (webcams etc)
Removed console output to framebuffer
Removed DRM framebuffer support
Those buck1 dvs properties and gpo node are not used by us, and those
regulator-virtuals are only for testing and unneeded here. Let's clean
them up.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
We use CONFIG_CPUFREQ_DT driver on imx7d. The driver looks for
regulator using 'cpu-supply' property rather than 'arm-supply'. Let's
fix it so that cpufreq-dt driver can actually scale voltage along with
frequency.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Right now, only BD7181X PMIC driver is used. Charger, RTC and GPIO are
not used. Let's disable them for now, and re-enable them with proper
testing when needed.
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>