The code doing the initial setting of the F_CONV_RATE field based
on the bq->state.online flag. In order for this to work properly,
this must be done after the initial bq25890_get_chip_state() call.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Before this commit the driver was registering its interrupt handler before
it registered the power_supply, causing bq->charger to potentially be NULL
when the interrupt handler runs, triggering a NULL pointer exception in
the interrupt handler:
[ 21.213531] BUG: kernel NULL pointer dereference, address: 0000000000000680
...
[ 21.213573] Hardware name: Xiaomi Inc Mipad2/Mipad, BIOS MIPad-P4.X64.0043.R03.1603071414 03/07/2016
[ 21.213576] RIP: 0010:__lock_acquire+0x5c5/0x1de0
...
[ 21.213629] Call Trace:
[ 21.213636] ? disable_irq_nosync+0x10/0x10
[ 21.213644] ? __mutex_unlock_slowpath+0x35/0x260
[ 21.213655] lock_acquire+0xb5/0x2b0
[ 21.213661] ? power_supply_changed+0x23/0x90
[ 21.213670] ? disable_irq_nosync+0x10/0x10
[ 21.213676] _raw_spin_lock_irqsave+0x48/0x60
[ 21.213682] ? power_supply_changed+0x23/0x90
[ 21.213687] power_supply_changed+0x23/0x90
[ 21.213697] __bq25890_handle_irq+0x5e/0xe0 [bq25890_charger]
[ 21.213709] bq25890_irq_handler_thread+0x26/0x40 [bq25890_charger]
[ 21.213718] irq_thread_fn+0x20/0x60
...
Fix this by moving the power_supply_register() call to above the
request_threaded_irq() call.
Note this fix includes making the following 2 (necessary) changes:
1. Switch to the devm version of power_supply_register() to avoid the
need to make the error-handling in probe() more complicated.
2. Rename the "irq_fail" label to "err_unregister_usb_notifier" since
the old name no longer makes sense after this fix.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
When registering the IRQ handler fails, do not just return the error code,
this will free the devm_kzalloc()-ed data struct while leaving the queued
work queued and the registered power_supply registered with both of them
now pointing to free-ed memory, resulting in various kernel crashes
soon afterwards.
Instead properly tear-down things on IRQ handler register errors.
Fixes: 703df6c097 ("power: bq27xxx_battery: Reorganize I2C into a module")
Cc: Andrew F. Davis <afd@ti.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Add more details to the error messages that indicate what went wrong
and use dev_err_probe() at a few places in the probe() path in order
to avoid error messages for deferred probe after which the driver probes
correctly.
Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Now that axp288_charger_usb_update_property() reads and caches all
relevant registers, axp288_get_charger_health() can be simplified
by directly returning the health.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Now that axp288_charger_usb_update_property() reads and caches all
relevant registers, the axp288_charger_is_present() and
axp288_charger_is_online() helpers are not necessary anymore.
Directly check the cached input_status instead, allowing the removal
of these 2 helpers.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Add "depends on IOSF_MBI" to CONFIG_AXP288_CHARGER as the changes from
commit ed22945485 ("power: supply: axp288-charger: Optimize register
reading method") use symbols which are only defined when IOSF_MBI support
is enabled.
Depending on this is ok since IOSF_MBI support should always be enabled
on devices which use the AXP288 PMIC.
Fixes: ed22945485 ("power: supply: axp288-charger: Optimize register reading method")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Look up the battery using the "monitored-battery" phandle
as is nowadays a standard DT binding. The actual bindings
for these charger elements are not upstream so let's sort
out this mess by conforming to the standard.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The driver allocates the mutex but not initialize it.
Use mutex_init() on it to initialize it correctly.
Fixes: ed22945485 ("power: supply: axp288-charger: Optimize register reading method")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
max17042_set_soc_threshold gets called with offset set to 1, which means
that minimum threshold value would underflow once SOC got down to 0,
causing invalid alerts from the gauge.
Fixes: e5f3872d20 ("max17042: Add support for signalling change in SOC")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The gauge requires us to clear the status bits manually for some alerts
to be properly dismissed. Previously the IRQ was configured to react only
on falling edge, which wasn't technically correct (the ALRT line is active
low), but it had a happy side-effect of preventing interrupt storms
on uncleared alerts from happening.
Fixes: 7fbf6b731b ("power: supply: max17042: Do not enforce (incorrect) interrupt trigger type")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Currently the rt5033_battery driver provides voltage values in mV. It
should be µV as stated in Documentation/power/power_supply_class.rst.
Fixes: b847dd96e6 ("power: rt5033_battery: Add RT5033 Fuel gauge device driver")
Cc: Beomho Seo <beomho.seo@samsung.com>
Cc: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The original implementation access the charger the same register value
several times to get the charger status, such as online, enabled, and
bus limits. It takes a long time and bandwidth for every "status get"
operation.
To reduce the access of the register and save bandwidth, this commit
integrated every read operation into only one "register value get"
operation and cache them in the variables. Once the "get properties"
is requested from the user space, the cached information can be returned
immediately.
I2C access between Linux kernel and P-Unit is improved by explicitly taking
semaphore once for the entire set of register accesses in the new
axp288_charger_usb_update_property() function. The I2C-Bus to the XPower
AXP288 is shared between the Linux kernel and SoCs P-Unit. The P-Unit
has a semaphore which the kernel must "lock" before it may use the bus.
If not explicitly taken by the I2C-Driver, then this semaphore is
automatically taken by the I2C-bus-driver for each I2C-transfer. In
other words, the semaphore will be locked and released several times for
entire set of register accesses.
Signed-off-by: Kate Hsuan <hpa@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
In the function cpcap_battery_probe(), the driver only needs the
data object, so use device_get_match_data() instead, to make the
code cleaner.
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Datasheet gives the name IAvg_empty, not LAvg_empty.
Signed-off-by: Henrik Grimler <henrik@grimler.se>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no
current sense resistor (rsns), the RepSOC register does not provide an
accurate state of charge value. The reported value is wrong, and does
not change over time. VFSOC however, which uses the voltage fuel gauge
to determine the state of charge, always shows an accurate value.
For devices without current sense, VFSOC is already used for the
soc-alert (0x0003 is written to MiscCFG register), so with this change
the source of the alert and the PROP_CAPACITY value match.
Fixes: 359ab9f5b1 ("power_supply: Add MAX17042 Fuel Gauge Driver")
Cc: <stable@vger.kernel.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Suggested-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
Signed-off-by: Henrik Grimler <henrik@grimler.se>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
There is a spelling mistake in the name wm831x_battey_apply_config,
fix it.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
If CONFIG_THERMAL=n:
drivers/power/supply/power_supply_core.c: In function ‘__power_supply_register’:
drivers/power/supply/power_supply_core.c:1137:6: error: implicit declaration of function ‘psy_has_property’ [-Werror=implicit-function-declaration]
1137 | if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) &&
| ^~~~~~~~~~~~~~~~
Fix this by moving psy_has_property() outside the section protected by
CONFIG_THERMAL.
Fixes: 9ba533eb99 ("power: supply: core: Add psy_has_property()")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Add the helper psy_has_property() to check whether a power supply
has a given property and use it instead of ad hoc iterations over
the property list in multiple locations.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
hrtimer_forward_now() provides the same functionality as the open coded
hrtimer_forward() invocation. Prepares for removal of hrtimer_forward()
from the public interfaces.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reorganize the Kconfig driver description and mention all supported
models. This helps when choosing drivers for given system.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reorganize the Kconfig driver description and mention all supported
models. This helps when choosing drivers for given system.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The power_supply_get_battery_info() fails if device-chemistry property
is missing in a device-tree because error variable is propagated to the
final return of the function, fix it.
Fixes: 4eef766b7d ("power: supply: core: Parse battery chemistry/technology")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
There's no need to print a message on every change in battery percentage
on regular log levels.
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Prepared by checking the datasheets of max17042, max17047/50
and max170455 for differences in register maps.
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This register is same as in MAX17047 and MAX17050, so there's no need
for custom casing it.
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
SMB347 can supply power to USB VBUS, implement the USB VBUS regulator.
USB VBUS needs to be powered for switching OTG-cable USB port into host
mode.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Pin control needs to be activated by setting the enable bit, otherwise
hardware rejects all pin changes. Previously this stayed unnoticed on
Nexus 7 because pin control was enabled by default after rebooting from
downstream kernel, which uses driver that enables the bit and charger
registers are non-volatile until power supply (battery) is disconnected.
Configure the pin control enable bit. This fixes the potentially
never-enabled charging on devices that use pin control.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Utilize generic regmap caching in order to avoid unnecessary slow I2C
accesses to all constant registers each time the supply status updated
and remove local caching of charger state to make code cleaner.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The smb347_set_writable() is used by interrupt handler and outside of it.
The interrupt should be disabled when the function is used outside of
interrupt handler in order to prevent racing with the interrupt context.
Add new parameter to smb347_set_writable() that allows to disable IRQ.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The only way to reset the BeagleV Starlight v0.9 board[1] properly is to
tell the PMIC to reset itself which will then assert the external reset
lines of the SoC, USB hub and ethernet phy.
This adds a driver to register a reset handler to do just that.
[1] https://github.com/beagleboard/beaglev-starlight
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
All bits of STATUS register are already defined (see STATUS_SMN_BIT and
further) so there is no need to define status SoC threshold min/max
values one more time.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reading status register can fail in the interrupt handler. In such
case, the regmap_read() will not store anything useful under passed
'val' variable and random stack value will be used to determine type of
interrupt.
Handle the regmap_read() failure to avoid handling interrupt type and
triggering changed power supply event based on random stack value.
Fixes: 39e7213edc ("max17042_battery: Support regmap to access device's registers")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This extends the struct power_supply_battery_info with a
"technology" field makes the core DT parser optionally obtain
this from the device tree.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit introduces support for NETGEAR ReadyNAS Duo v2.
This device use bit 4 of LED[2:0] Polarity Control Register to indicate
AC Power loss.
For more details about AC loss detection in NETGEAR ReadyNAS Duo v2,
please look at the file:
RND_5.3.13_WW.src/u-boot/board/mv_feroceon/mv_hal/usibootup/usibootup.c
from Netgear GPL sources.
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit prepare driver for another device support.
New power_off_cfg structure describes two most important things: name of
mdio bus and pointer to register setting function. It allow to add new
device with different mdio bus node and other phy register config.
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This immutable branch introduces the MT6360 charger driver,
which requires a new linear range helper.
Signed-off-by: Sebastian Reichel <sre@kernel.org>
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmEWoK4ACgkQ2O7X88g7
+poicBAAoSC7gnCdcmk7+OtZBT6UXSz6z5ftdIJ+Pi+HRuPDucZL+MJvRlenabZH
u4iyK8hx6iuZOmhTnRNhhmQjta7cIn0kQ55UQ/Va7B1Faqi7ZBDhwlr/TzveBOfo
bgfjQhrKWR0HBCYCzmoEfTQf5ew/eZmFd9oCvEVo1G9BqHKT1f+G6sJioAqz+Fq9
Z0w2ep2eFiRJlwSIvLd8tN2YcZOvAjbxSZFZ00QEFeFBzVDCbKan3Mj5aB85PkT0
0Fi09wYlIeQP5uqoiJq/X2/K4L+QCZ2OcjzwNnzfJQO1u2W37crm9mJBIKe2UNtK
9rKRJXMNVxf6eRCK0Tdr+AYBRI71AyByTKK5VlUDPzZpfRCA9KNMnDsbC59RxZbT
/5AlarAhlaGqtIVoNxOw7U0aiqLEJhryNr0D2CT2y7zoU/VHlaPZIzT815QhMubj
m7wh+bTnZXvV2VpMB6faoG4lwcqBklNlAFtYWX+OhqpS1z5/+LzeUoKd53rKnfn4
32SjIOKevEDe0nVXVKv9Y3M2/fie7ZHIbv3bU9gbIRWZ2oqG/DgeK6cUNNn9ALjT
xjkW15SUh9eAk+Aey20lMOqPo2T+YKlXH6r+LFXpnJJa1+JFEHfZbM49rcvdNF5Z
SpLpmuP8+P1oc1aqmBgY1LY7qTtlKsMGDnIRQuzXKLJ30NLSxe4=
=60NT
-----END PGP SIGNATURE-----
Merge tag 'ib-mt6360-for-5.15-signed' into psy-next
Immutable branch between regulator and power-supply for for 5.15
This immutable branch introduces the MT6360 charger driver,
which requires a new linear range helper.
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Rename ChargeOption macros to match the others for ChargeCurrent and
ChargeVoltage and also separate the command & masks macros from the bits of
interest macros for each command. This macro doesn't introduce any
functional change, only code re-org.
Signed-off-by: Bruno Meneguele <bruno.meneguele@smartgreen.net>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Read voltage_now via IIO and provide the property.
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Reported-by: kernel test robot <lkp@intel.com> # missing depends on IIO
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Add basic support for the battery charger for MT6360 PMIC
Signed-off-by: Gene Chen <gene_chen@richtek.com>
Reviewed-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Clean up a handful of checkpatch warnings:
- static const char * array should probably be static const char * const
- function arguments should have identifier names
- else should follow close brace '}'
- suspect code indent for conditional statements
- unnecessary parentheses in an if condition
- avoid multiple line dereference
- remove debug showing function execution, ftrace can trace these better
- prefer 'long' over 'long int' as the int is unnecessary
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Use the defined variable "dev" to make the code cleaner.
Co-developed-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
As defined by the Smart Battery Data Specification.
An _AVG suffix is added to the enum values REG_TIME_TO_EMPTY and
REG_TIME_TO_FULL to make the distinction clear.
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
The Smart Battery Data Specification allows for values 0..65535 mV,
there is no reason to limit the value to 20000.
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
In the probe function, when get irq failed, the function
platform_get_irq_byname() logs an error message, so remove
redundant message here.
Co-developed-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
MAX77849 is a combined fuel-gauge, charger and MUIC IC. Notably,
fuel-gauge has dedicated i2c lines and seems to be fully compatible
with max17047. Add new compatible for it reusing max17047 code paths.
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>