Use dev_info() instead of pr_info().
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The function sc27xx_poweroff_shutdown is local to the source and does
not need to be in global scope, so make it static.
Cleans up sparse warning:
drivers/power/reset/sc27xx-poweroff.c:28:6: warning: symbol
'sc27xx_poweroff_shutdown' was not declared. Should it be static?
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
In preparation to enabling -Wvla, remove VLA usage and replace it
with fixed-length arrays.
DA9150_QIF_LONG_SIZE (4 bytes) is the biggest size of an attribute which can
be accessed [1].
Fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621
[1] https://marc.info/?l=kernel-hardening&m=152059600524753&w=2
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Acked-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
power_supply_am_i_supplied() can return negative error
codes. In this case we should assume, that no charger
is connected and the battery should be marked as
DISCHARGING instead of NOT_CHARGING.
Reported-by: Merlijn Wajer <merlijn@wizzup.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
max17042_get_status uses the core power_supply_am_i_supplied. That
function relies on DT properties to figure out the power supply
topology, and will error out without DT.
Fixes max17042 battery status being reported as "unknown".
Signed-off-by: Pierre Bourdon <delroth@google.com>
Signed-off-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Commit 2b5a4b4bf2 ("power: supply: axp288_fuel_gauge: Rework
get_status()"), switched from 0A current detection to using the capacity
register for full detection.
It turns out this fixes full reporting on some devices which keep trickle
charging long after the capacity register reach 100%, but breaks it on
some other devices where the charger stops charging before the capacity
register reaches 100%. This commit fixes this by also checking for
0A current when the reported capacity is above 90%.
Fixes: 2b5a4b4bf2 ("psy: axp288_fuel_gauge: Rework get_status()")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The ECS EF20EA laptop ships an AXP288 but it is actually using a
different, separate FG chip for AC and battery monitoring. On this
laptop we need to keep using the regular ACPI driver and disable the
AXP288 FG to avoid reporting two batteries to userspace.
Signed-off-by: Carlo Caione <carlo@endlessm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Add support for reading a timeout value from device property.
Fall back to previous default of 3s if nothing is specified.
Signed-off-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
On Spreadtrum platform, we need power off system through external SC27xx
series PMICs including the SC2720, SC2721, SC2723, SC2730 and SC2731 chips.
Thus this patch adds SC27xx series PMICs power-off support.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The X-Powers AXP813 PMIC has got some slight differences from
AXP20X/AXP22X PMICs:
- the maximum voltage supplied by the PMIC is 4.35 instead of 4.36/4.24
for AXP20X/AXP22X,
- the constant charge current formula is different,
It also has a bit to tell whether the battery percentage returned by the
PMIC is valid.
Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
We used to use IDs to select a function or a feature depending on the
variant. It's easier to maintain the code by adding data structure
storing the few differences between variants so that we don't add a pile
of if conditions.
Let's use this data structure and update the code to use it.
Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
[updated POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN write property to use
the introduced set_max_voltage() callback]
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Platform data are now used only during probe time, so remove
them from gpio_charger structure and consolidate probing
function accordingly.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
[Replace of_property_read_string with dev_property_read_string]
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Setting GPIOF_ACTIVE_LOW flag based on platform data gpio_active_low
makes return value of gpiod_get_value_cansleep directly usable.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
There is an error message within devm_kzalloc already.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
On the D-Link DIR-685 we get spurious poweroff from
infrared. Since that block (CIR) doesn't even have a
driver this can be safely ignored, we can revisit this
code once we have a device supporting CIR.
On the D-Link DNS-313 we get spurious poweroff from
the power button. This appears to be an initialization
issue: we need to enable the block (start the state
machine) before we clear any dangling IRQ.
This patch fixes both issues.
Fixes: f7a388d6cd ("power: reset: Add a driver for the Gemini poweroff")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Temperature is measured in tenths of degree Celsius.
Fixes: 085bc24d15 ("Add LTC2941/LTC2943 Battery Gauge Driver")
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Using explicit struct device variable makes code a bit more readable.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Simplify error unwinding using devm_* allocators. This also
makes driver remove function empty, so remove it.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Add properties for charge empty and charge full thresholds.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The Microsemi Ocelot SoC has a register allowing to reset the MIPS core.
Unfortunately, the syscon-reboot driver can't be used directly (but almost)
as the reset control may be disabled using another register.
Cc: linux-pm@vger.kernel.org
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
* bq27xxx: add bq27521 support
* drop unused imx-snvs-poweroff driver
* improve axp288 driver
* misc. fixes
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAlpx13wACgkQ2O7X88g7
+pp6QBAAlYcyFR1s/NrQA42zbMdFSHhzTzjQOoOXrik9ajRQNo5XuOyOYoS1LztW
aaIzZm/GSgZ00wMNv/NoUkUU+CVhj2mhlIj/uintLmK8jryEcnLYAnrRiV38qkQQ
JwQEet4IPhHQ4ljw6jexnhiieSLhl5HqufF1jDpV+b959sG0WyH1skeHbMM033c9
giIgSn8lrgjG5of/bnoTIAnbsH+hummURQ7yox4Dqa+dqJ0oJK3U0uorbeyQtCuB
57aPEiDfoxBBohkPcwpCCMOxkreShST2caNRrmyKHif3dj+80ZBIsHOme1rVaP0c
XG5z3qu1lHkvxthLcNKEXAZ9+PD9kCKFIi3YUA8FLBwDyeYvJi+4uQ7VkzFXxK0H
hYt4nYA5vO9i0rNaRdFPK/RYr6esTW9aVw3IASi9ic3oHncaW1Q/kpU7hglkND+w
8MOPARgLR6G86D3FTsI8bxmkLuKr1k7Vae2MnhnX3jgPDKFF35yTh21LrLJQXDzX
nQQ4YoLwdbU0dvhDc1vQMNc2t3wOwpZjfg5a8f2nd7xqFRM4uE4batN8MkefNkxv
W0Dd+0H4n1Gy+Z9vvSmlwt1iGWWa9QqhNeLDrrtqpN43AJUfP3ucd4nFlDUNS921
Ilt4e34OoXJoDNDsm00iCPduTtme7QChSnkiGY+cFiwA0CSgs3A=
=XIx5
-----END PGP SIGNATURE-----
Merge tag 'for-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply
Pull power supply and reset updates from Sebastian Reichel:
- bq27xxx: add bq27521 support
- drop unused imx-snvs-poweroff driver
- improve axp288 driver
- misc fixes
* tag 'for-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (32 commits)
power: supply: max17042_battery: Always fall back to default platform-data
power: supply: max17042_battery: Check battery current for status when supplied
MAINTAINERS: Add AXP288 PMIC entry
power: supply: axp288_fuel_gauge: Do not register our psy on (some) HDMI sticks
power: supply: axp288_fuel_gauge: Optimize get_current()
power: supply: axp288_fuel_gauge: Rework get_status()
power: reset: account for const type of of_device_id.data
power: supply: account for const type of of_device_id.data
bq24190: Simplify code in property_is_writeable
power: supply: axp288_fuel_gauge: Get iio-channels once during boot
power: supply: axp288_charger: Properly stop work on probe-error / remove
power: supply: axp288_charger: Simplify extcon cable handling
power: supply: axp288_charger: Use the right property for the input current limit
power: supply: axp288_charger: Pick lower input current limit not higher
power: supply: axp288_charger: Do not cache input current limit value
power: supply: axp288_charger: Remove no longer needed locking
power: supply: axp288_charger: Use regmap_update_bits to set the input limits
power: supply: axp288_charger: Cleanup some double empty lines
power: supply: axp288_charger: Remove charger-enabled state tracking
power: supply: axp288_charger: Add missing newlines to some messages
...
It is possible to have CONFIG_OF enabled on x86 builds, where we have no
firmware provided max17042_platform_data. The CONFIG_OF implementation of
max17042_get_pdata would return NULL in this case, causing the probe to
fail.
Instead always fallback to the default platform-data, as used on x86 sofar,
when there is no firmware provided pdata, independent of CONFIG_OF.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Even though the system is supplied, it may still be discharging if the
supply is e.g. only delivering 5V 0.5A. Check the avg battery current if
available for more accurate status reporting.
Cc: James <kernel@madingley.org>
Suggested-by: James <kernel@madingley.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The Intel Compute Stick (Cherry Trail version) and the Meegopad T08 HDMI
stick, both use an axp288 PMIC. They also both have this wired up in such
a way that the detection logic in the PMIC claims that a valid battery is
present, resuling in GNOME and KDE showing a full-battery in their status
bar and power-settings, while these devices do not have a battery.
For lack of a better fix add a DMI blacklist and do not register the
axp288_fuel_gauge psy on devices on the blacklist.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
First check the discharge current, and when that is non 0 use that without
also checking the charge current (which will be 0 then). This makes
get_current() do only 1 i2c read instead of 2 when on battery.
This is esp. important given the pmic i2c bus mutex stuff used on boards
with an axp288 because the SoC's own punit also may access the axp288,
which makes i2c accesses more expensive then normal.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Relying on the (dis)charge current reporting for reporting FULL back to
userspace does not work really well and often leads to the reported status
getting stuck at e.g. 98/99% (the fuelgauge is not perfect) for hours.
What happens is that when the battery is full the axp288 keeps charging it
with a very low current. Until it is really really full and once really
really full, some inaccuracies in the adc lead to it then sometimes
reporting a small discharging rate, even though an external pwr source is
used. So we end up with a status of "charging" for hours after the battery
is actually already full and sometimes this then flip-flops to discharging.
This commit fixes this by first checking if a valid Vbus is present and if
it is present using the fuel-gauge's reported percentage to check for a
full battery.
This commit also changes how get_status() determines if the battery is
charging or discharging when not reporting it as full. We still use the
current direction for this, but instead of reading 4 extra registers for
this (2 16 bit regs), simplify things by using the current-direction bit
in the power-status register, which already gets read anyways.
This also reduces the amount of i2c reads to 1 when on battery and 2
when a valid Vbus is present.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
This driver creates a const structure that it stores in the data
field of an of_device_id array.
Add const to the declaration of the location that receives a value
from the data field to ensure that the compiler will continue to check
that the value is not modified and remove the const-dropping cast on
the access to the data field.
Done using Coccinelle.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
This driver creates two const structures that it stores in the data
field of an of_device_id array.
The data field of an of_device_id structure has type const void *, so
there is no need for a const-discarding cast when putting const values
into such a structure.
Furthermore, adding const to the declaration of the location that
receives a const value from such a field ensures that the compiler
will continue to check that the value is not modified. The
const-discarding cast on the extraction from the data field is thus
no longer needed.
Done using Coccinelle.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Simplify function that should be trivial.
Signed-off-by: Pavel machek <pavel@ucw.cz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Get iio-channels once during boot, delaying the probe if the axp288_adc
drivers has not loaded yet, instead of getting them on demand each time
we need them.
This fixes the following errors in dmesg:
axp288_fuel_gauge axp288_fuel_gauge: ADC charge current read failed:-19
Which were caused by the ondemand iio-channel read code not finding the
channel when the axp288_adc driver had not loaded yet.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Properly stop any work we may have queued on probe-errors / remove.
Rather then adding a remove driver callback for this, and goto style
error handling to probe, use a devm_action for this.
The devm_action gets registered before we register any of the extcon
notifiers which may queue the work, devm does cleanup in reverse order,
so this ensures that the notifiers are removed before we cancel the work.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Simplify extcon cable handling using the new
devm_extcon_register_notifier_all function to listen to all cables
in one go.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Use the right property for the input current limit and make it writable.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The code before this commit would pick 900 mA when asking for an input
current limit of 600mA, rather then 500 mA, not good.
While touching almost all code using the silly xxxMA defines anyways,
also get rid of these simply typing out the numbers and switch the
unit to uA as that is the psy class standard unit for currents.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The hardware may change this underneath us.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Now that we use regmap to do read-modify-write ops everywhere, we can
rely on the regmap lock and no longer need our own lock.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Use regmap_update_bits in axp288_charger_set_vbus_inlmt, instead of DIY
code.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
While we are doing cleanups, also remove some double blank lines.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The extcon code is the only one to trigger our worker (outside of the
initial run) and we can rely on it to only call us if things have
changed, so there is no need to track the charger-enabled state.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Add missing (terminating) "\n"-s to some dev_dbg messages.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Before this commit we were relying solely on the extcon interface for
cable detection, including to determine if a cable providing vbus is
connected at all. This caused us to turn off charging at boot, because
when we run the initial state processing the axp288-extcon driver is still
running charger-type detection most of the time, so all charger cable
types read as disconnected when we run the initial state processing.
This commit reworks the axp288_charger_extcon_evt_worker flow to use the
VBUS_VALID bit from the PWR_INPUT_STATUS register to determine if we
should turn charging on/off. Note this is the same bit as we use for the
online property.
If VBUS_VALID is set, but the extcon code has not completed the charger
type detection yet, we now simply bail leaving things as configured by
the BIOS (we will get a notifier call when the extcon code is done and
reschedule the axp288_charger_extcon_evt_worker).
The extcon code is the only one to trigger the worker (outside of the
initial run) and we can rely on it to only call us if things have changed,
so while we are completely refactoring axp288_charger_extcon_evt_worker,
also remove the code to check if the state has changed.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
There's no user of it in kernel now and it basically functions the same
as the generic syscon-poweroff.c to which we have already switched.
So let's remove it.
Cc: Robin Gong <yibin.gong@nxp.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Acked-by: Rob Herring <robh@kernel.org>
Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
When PSHOLD in a Qualcomm platform is deasserted the PMIC will perform
either a power off or a restart of the system. The action to take is
configured in the PON block, which is controlled by a separate driver.
As the configuration logic was added to the pm8941-pwrkey driver the
comment in do_msm_poweroff() is no longer valid and the name
do_msm_restart() is misleading. Update the naming and drop the comment.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
This driver creates a number of const structures that it stores in the
data field of an of_device_id array.
The data field of an of_device_id structure has type const void *, so
there is no need for a const-discarding cast when putting const values
into such a structure.
Furthermore, adding const to the declaration of the location that
receives a const value from such a field ensures that the compiler
will continue to check that the value is not modified. The
const-discarding cast on the extraction from the data field is
thus no longer needed.
Done using Coccinelle.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This adds basic support for BQ27521 battery monitor, used in Nokia N9
and N950. In particular, battery voltage is important to be able to
tell when the battery is almost empty. Emptying battery on N950 is
pretty painful, as flasher needs to be used to recover phone in such case.
Signed-off-by: Pavel Machek <pavel@ucw.cz>
Acked-by: Andrew F. Davis <afd@ti.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Now that drivers/i2c/busses/i2c-cht-wc.c uses
"input-current-limit-from-supplier" instead of "extcon-name" the last
user of the bq24190 extcon code is gone, remove it.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The driver sets the fuel gauge to continuous monitoring on startup, for
the models that support this. When the board shuts down, the chip remains
in that mode, causing a few mA drain on the battery every 2 or 10 seconds.
This patch registers a shutdown handler that turns off the monitoring to
prevent this battery drain.
Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
The platform_get_irq_byname() function returns -1 if an error occurs.
zero or positive number on success. platform_get_irq_byname() error
checking for zero is not correct.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>