1
0
Fork 0
Commit Graph

888152 Commits (zero-colors)

Author SHA1 Message Date
Steinar Bakkemo 1710080e80 max77818-charger: add check for OTG mode when returning status_ex property
Ignore POGO connection state when in OTG mode, as the charger driver
always reports CHGIN OK (aka. connected) when charger_mode = OTG Supply
2021-03-19 23:32:29 +01:00
Steinar Bakkemo 02de15907a max77818-charger: add support for new POWER_SUPPLY_PROP_STATUS_EX property
Add support for reading connection state through new status_ex sysfs property.
2021-03-19 23:32:29 +01:00
Steinar Bakkemo d0422f8316 power-supply: add POWER_SUPPLY_PROP_STATUS_EX property with enumarated values 2021-03-19 23:32:29 +01:00
Shawn Guo ab0959c659 max77818_battery: add SOC alert event support
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>
2021-03-19 23:32:29 +01:00
Shawn Guo dbfdf27955 max77818_battery: drop some unhelpful properties
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>
2021-03-19 23:32:28 +01:00
Lars Ivar Miljeteig aa64f1bd2e max77818: Don't disable charging when unplugged
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.
2021-03-19 23:32:28 +01:00
Shawn Guo eeb719990c max77818-charger: fix bug on CHG_CNFG registers setting
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>
2021-03-19 23:32:28 +01:00
Steinar Bakkemo d6f51d15fe max77818-charger: fix issue causing charging mode 0 (off) to be retained
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.
2021-03-19 23:32:28 +01:00
Shawn Guo 58f1167d8f max77818-charger: remove POWER_SUPPLY_PROP_CURRENT_NOW property
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>
2021-03-19 23:32:28 +01:00
Lars Ivar Miljeteig 8403aea184 zero-sugar: Removed zero-sugar-charger.c
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.
2021-03-19 23:32:28 +01:00
Shawn Guo d9be5ac150 max77818-charger: add POWER_SUPPLY_MODE_ALL_OFF for charger_mode property
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>
2021-03-19 23:32:27 +01:00
Shawn Guo 52969b3767 max77818-charger: make ONLINE property non-writeable
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>
2021-03-19 23:32:27 +01:00
Shawn Guo dd420ff4fe max77818-charger: improve max77818_charger_set_enable() call
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>
2021-03-19 23:32:27 +01:00
Shawn Guo 1773d63e3d max77818-charger: drop 'present' from struct max77818_charger
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>
2021-03-19 23:32:27 +01:00
Shawn Guo b453f21543 max77818-charger: fix UVLO charging check
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>
2021-03-19 23:32:27 +01:00
Shawn Guo ea323d2b81 max77818-charger: fix dtls[] data type
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>
2021-03-19 23:32:27 +01:00
Shawn Guo 63dc817199 max77818-charger: drop max77818_charger_init_dev and max77818_charger_exit_dev
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>
2021-03-19 23:32:26 +01:00
Shawn Guo 4d2654c562 max77818-charger: drop max77818_charger_set_charge_current() function
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>
2021-03-19 23:32:26 +01:00
Shawn Guo cc0ec1cfc8 max77818-charger: report online per charging state
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>
2021-03-19 23:32:26 +01:00
Shawn Guo 6307efa835 max77818-charger: change MODE_OTG_BUCK_BOOST to 0x0F
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>
2021-03-19 23:32:26 +01:00
Shawn Guo 1540986928 max77818-charger: update default settings to match hardware reset ones
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>
2021-03-19 23:32:26 +01:00
Shawn Guo 73536c0299 max77818-charger: make current properties non-writeable
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>
2021-03-19 23:32:26 +01:00
Shawn Guo f78e528c27 max77818-charger: enable low battery prequalification support
It enables Low Battery Prequalification Mode support for charger.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
2021-03-19 23:32:26 +01:00
Shawn Guo 01a9899b9f battery: improve the comment in max77818_resume()
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>
2021-03-19 23:32:25 +01:00
Shawn Guo f27d6f599d mfd: max77818: remove unused headers
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>
2021-03-19 23:32:25 +01:00
Shawn Guo b475c3f41c mfd: clean up max77818 driver code
- 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>
2021-03-19 23:32:25 +01:00
Shawn Guo d8197936ef regulator: clean up max77818 reglator code
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>
2021-03-19 23:32:25 +01:00
Shawn Guo a08067a94e power: supply: clean up max77818 charger driver
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>
2021-03-19 23:32:25 +01:00
Shawn Guo 3031597699 power: supply: add max77818 battery driver
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>
2021-03-19 23:32:25 +01:00
Shawn Guo d3a5e39df5 power: supply: remove max77818_battery driver
The driver is buggy and not functional at all.  Let's remove it and
start over again.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
2021-03-19 23:32:25 +01:00
Steinar Bakkemo b2256ef769 max77818-charger: add support for charger_mode/other cleanup 2021-03-19 23:32:24 +01:00
Steinar Bakkemo 7e80b60245 power-supply: add POWER_SUPPLY_PROP_CHARGER_MODE
Add new charger_mode sysfs property to standard power supply sysfs props.
2021-03-19 23:32:24 +01:00
Steinar Bakkemo eea77dfda3 max77818-charger: add support for setting charger mode (charging/OTG) 2021-03-19 23:32:24 +01:00
Steinar Bakkemo 32e70aeb70 max77818: fix power supply reg. issue causing kernal panic/add sep. max cur. adj
Extract powersupply config to static data structure.
Add support for setting max current separately for chgin/wcin.
2021-03-19 23:32:24 +01:00
Steinar Bakkemo 5b8b0a3d01 max77818: add max77818 driver (driver received from Maxim, ported to 4.14.79 kernel) 2021-03-19 23:32:24 +01:00
Shawn Xiao 16c00949c7 MGS-1087: ARM: dts: Add CMA setting to 7d dtsi
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>
2021-03-19 23:32:23 +01:00
Shawn Guo efdf50dcef mmc: pwrseq_simple: select pinctrl state during suspend/resume
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>
2021-03-19 23:32:23 +01:00
Lars Ivar Miljeteig 2721255786 brcm80211: Select WIRELESS_EXT automatically 2021-03-19 23:32:23 +01:00
Lars Ivar Miljeteig 9e79dc4981 bd71815: Enable 32k out in cmos mode 2021-03-19 23:32:23 +01:00
Shawn Guo 839a1c3686 mfd: bd7181x: turn off power rails for SUSPEND mode
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>
2021-03-19 23:32:23 +01:00
Shawn Guo 1b8238725d mfd: bd7181x: keep LDO_DVREF on for LPSR sleep
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>
2021-03-19 23:32:23 +01:00
Shawn Guo c109551951 mfd: bd7181x: set LPSR_MODE bit only when system sleeps
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>
2021-03-19 23:32:22 +01:00
Shawn Guo c0af344867 mfd: bd7181x: disable unused functions to save power
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>
2021-03-19 23:32:22 +01:00
Shawn Guo fa2738c624 mfd: bd7181x: select pinctrl state during suspend/resume
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>
2021-03-19 23:32:22 +01:00
Shawn Guo 5d25aefe3a bd7181x: configure bd71815 for LPSR sleep support
It configures BD71815 to have BUCKs and LDOs on/off as needed in LPSR
mode.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
2021-03-19 23:32:22 +01:00
Steinar Bakkemo 4b9b70b520 rtc-bd7181x: disable debug output 2021-03-19 23:32:22 +01:00
Shawn Guo 7a6fe91413 regulator: bd7181x: skip DVS buck setup if it's not enabled
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>
2021-03-19 23:32:22 +01:00
Shawn Guo c3ba2bbbdd regulator: bd7181x: drop unneeded register initialization
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>
2021-03-19 23:32:22 +01:00
Shawn Guo 60e343b370 regulator: bd7181x: fix section mismatch warning
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>
2021-03-19 23:32:21 +01:00
Steinar Bakkemo 544faf9ce5 bd7181x: turn off extensive debug output 2021-03-19 23:32:21 +01:00