Commit graph

2750 commits

Author SHA1 Message Date
Mark Brown
4c678b7a64 power: supply: Use an rbtree rather than flat register cache
The smb347 has a very sparse register map (the maximum register is 0x3f but
less than 10% of the possible registers appear to be defined) and doesn't
have any hardware defaults specified so the sparser data structure of an
rbtree is a better fit for it's needs than a flat cache. Since it uses I2C
for the control interface there is no performance concern with the slightly
more involved code so let's convert it.

This will mean we avoid any issues created by assuming that any previously
unaccessed registers hold a value that doesn't match what's in the hardware
(eg, an _update_bits() suppressing a write).

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-24 11:47:55 +01:00
Hans de Goede
5ac121b81b power: supply: axp288-charger: Set Vhold to 4.4V
The AXP288's recommended and factory default Vhold value (minimum
input voltage below which the input current draw will be reduced)
is 4.4V. This lines up with other charger IC's such as the TI
bq2419x/bq2429x series which use 4.36V or 4.44V.

For some reason some BIOS-es initialize Vhold to 4.6V or even 4.7V
which combined with the typical voltage drop over typically low
wire gauge micro-USB cables leads to the input-current getting
capped below 1A (with a 2A capable dedicated charger) based on Vhold.

This leads to slow charging, or even to the device slowly discharging
if the device is in heavy use.

As the Linux AXP288 drivers use the builtin BC1.2 charger detection
and send the input-current-limit according to the detected charger
there really is no reason not to use the recommended 4.4V Vhold.

Set Vhold to 4.4V to fix the slow charging issue on various devices.

There is one exception, the special-case of the HP X2 2-in-1s which
combine this BC1.2 capable PMIC with a Type-C port and a 5V/3A factory
provided charger with a Type-C plug which does not do BC1.2. These
have their input-current-limit hardcoded to 3A (like under Windows)
and use a higher Vhold on purpose to limit the current when used
with other chargers. To avoid touching Vhold on these HP X2 laptops
the code setting Vhold is added to an else branch of the if checking
for these models.

Note this also fixes the sofar unused VBUS_ISPOUT_VHOLD_SET_MASK
define, which was wrong.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:21:42 +01:00
Changcheng Deng
cd4c7b2725 power: supply: ab8500: Remove unneeded variable
Remove unneeded variable used to store return value.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:21:42 +01:00
Michał Mirosław
513e3b53c1 power: supply: ltc2941: clean up error messages
Replace dev_err() with dev_err_probe() in probe() and extend register
access failure messages. dev_err()s in _reset() are removed as they
are redundant: register access wrappers already log the error.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:21:42 +01:00
Michał Mirosław
cf215c37f5 power: supply: ltc2941: simplify Qlsb calculation
Replace two divisions with a subtraction+shift for a small code size
improvement and less brackets.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:21:42 +01:00
Hong Peng
8f5b373960 power: supply: ab8500_charger: Fix spelling typo
fix the comment typo: "interrupts", "structcure"

Signed-off-by: Hong Peng <elicec@foxmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:21:42 +01:00
Miaoqian Lin
6a4760463d power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init
kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix memory leak by calling kobject_put().

Fixes: 8c0984e5a7 ("power: move power supply drivers to power/supply")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:21:41 +01:00
Daisuke Nojiri
8453010013 power: supply: PCHG: Use MKBP for device event handling
This change makes the PCHG driver receive device events through
MKBP protocol since CrOS EC switched to deliver all peripheral
charge events to the MKBP protocol. This will unify PCHG event
handling on X86 and ARM.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-13 22:20:12 +01:00
Linus Walleij
f444578d72 power: supply: bq256xx: Handle OOM correctly
Since we now return a pointer to an allocated object we need
to account for memory allocation failure in a separate
error path.

Fixes: 25fd330370 ("power: supply_core: Pass pointer to battery info")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 21:19:51 +01:00
Linus Walleij
21ad180d0f power: supply: ab8500_charger: Fix VBAT interval check
When using USB charging, the AB8500 charger is periodically
checking VBAT for a threshold at 3.8V.

This crashes badly, as the class_for_each_device() was passed
the wrong argument. I think this has maybe worked by chance
in the past because of how the structs were arranged but it
is leading to crashes now.

Fix this up and also switch to using microvolts for the
voltages like the rest of the code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:54 +01:00
Linus Walleij
0f6dad11fd power: supply: ab8500_charger: Restrict ADC retrieveal
The AB8505 only has two ADC channels: the voltage and current
provided from VBUS (USB). It does not support AC charging at all.
Make sure we don't try to retrieve the non-existing channels.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
75ee3f6f0c power: supply: ab8500_chargalg: Drop enable/disable sysfs
There is a sysfs ABI to enable/disable charging of different
types (AC/USB).

Since we don't have any userspace for this code, this sits
unused and it is not used on production products either.

Drop this code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
05906f58c8 power: supply: ab8500_chargalg: Drop charging step
There is a sysfs ABI to change the "charging step" of the
charger i.e. limit how much we charge from userspace.

Since we don't have any userspace for this code, this sits
unused and it is not used on production products either.

Drop this code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
3bab736363 power: supply: ab8500_fg: Drop useless parameter
All calls to ab8500_fg_calc_cap_discharge_voltage() require
compensation and pass true as the second argument so just drop
this argument.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
965a990427 power: supply: ab8500_fg: Safeguard compensated voltage
In some cases when the platform is dissapating more than
500mA the voltage measurements and compensation will become
instable. Add a parameter to bail out of the voltage
measurement if this happens.

This code was found in a Samsung vendor tree.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
673b50322b power: supply: ab8500_fg: Break out load compensated voltage
Break out the part of the function providing the load compensated
capacity that provides the load compensated voltage and use
that to get the load compensated capacity.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
edc400e163 power: supply: ab8500_fg: Break loop for measurement
In the Samsung code tree we find that it can happen that this
measurement loop goes on for a long time, and it seems like a
good idea to break it after 70 iterations if it goes on for
too long.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
2b0e7ac084 power: supply: ab8500: Integrate thermal zone
Instead of providing our own homebrewn thermal measurement
code for an NTC and passing tables, we put the NTC thermistor
into the device tree, create a passive thermal zone, and poll
this thermal zone for the temperature.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
d662a7df36 power: supply: ab8500: Swap max and overvoltage
We should terminate charging when we reach the voltage_max_design_uv
not overvoltage_limit_uv, this is an abuse of that struct member.

The overvoltage limit is actually not configurable on the AB8500,
it is fixed to 4.75 V so drop a comment about that in the code.

Fixes: 2a5f41830a ("power: supply: ab8500: Standardize voltages")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Linus Walleij
d58964be64 power: supply: ab8500: Drop BATCTRL thermal mode
The BATCTRL mode reads the temperature of the battery by
enabling a certain probing current (7-20 mA) and then measure
the voltage of the NTC mounted inside the battery.

None of the AB8500 product or the reference designs use this
mode. What we use is the so-called BATTEMP mode which enables
an internal 230 kOhm pull-up to 1.8 V to the external NTC on
pin BatTemp (N16) and then measures the voltage over the NTC
using the ADC:

        1.8V (VTVOUT)
         |
        [ ] 230 kOhm
         |
BatTemp  +---------------- ADC
Pin N16  | _
         |/
        [/] NTC
       _/|
         |
        GND

Cut out the BATCTRL code to clear the forest and stop
maintaining code we can never test.

The current inducing method is still used to probe for the
battery type using the internal BTI (battery type indicator)
on the BatCtrl (C3) pin in a separate code path.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 20:24:53 +01:00
Andy Shevchenko
1c97db1747 power: supply: core: Use device_property_string_array_count()
Use device_property_string_array_count() to get number of strings
in a string array property.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:54:21 +01:00
Uwe Kleine-König
e83c7204f1 power: supply: rt9455: Don't pass an error code in remove callback
When ret is not zero there were already one or two error messages emitted
about a problem (because rt9455_register_reset() emits a message in most
cases then). Passing on that error code to the i2c core only results in
another error message. Suppress that by returning zero unconditionally.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:52:56 +01:00
Christophe JAILLET
a942f913a9 power: supply: core: Simplify hwmon memory allocation
Use devm_bitmap_zalloc() instead of hand writing it.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:45:52 +01:00
Hans de Goede
f059b46e6f power: supply: ug3105_battery: Add driver for uPI uG3105 battery monitor
Add a new battery driver for the uPI uG3105 battery monitor.

Note the uG3105 is not a full-featured autonomous fuel-gauge. Instead it
is expected to be use in combination with some always on microcontroller
reading its coulomb-counter before it can wrap (must be read every 400
seconds!).

Since Linux does not monitor coulomb-counter changes while the device is
off or suspended, the coulomb counter is not used atm.

So far this driver is only used on x86/ACPI (non devicetree) devs
(also note there is no of_match table). Therefor there is no devicetree
bindings documentation for this driver's "upisemi,rsns-microohm" property
since this is not used in actual devicetree files and the dt bindings
maintainers have requested properties with no actual dt users to
_not_ be added to the dt bindings.

The property's name has been chosen so that it should not need to be
changed if/when devicetree enumeration support gets added later, as it
mirrors "maxim,rsns-microohm" from the "maxim,max17042" bindings.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:35 +01:00
Hans de Goede
4e456230f1 power: supply: bq24190_charger: Disallow ccc_ireg and cvc_vreg to be higher then the fwnode values
If the fwnode data as parsed by power_supply_get_battery_info() provides
max values for ccc_ireg and cvc_vreg then do not allow the user to later
set these to higher values then those specified by the firmware,
otherwise the battery might get damaged.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Hans de Goede
445c21d208 power: supply: bq24190_charger: Program charger with fwnode supplied ccc_ireg and cvc_vreg
So far the bq24190_charger driver has been relying on either the chips
default constant_charge_current_max_ua and constant_charge_voltage_max_uv
values, or on the BIOS or bootloader to program these for us.

This does not happen on all boards, causing e.g. the wrong (too low)
values to be used on Lenovo Yoga Tablet 2 830F/L and 1050F/L tablets.

If power_supply_get_battery_info() provides us with values for these
settings, then program the charger accordingly.

And if the user later overrides these values then save the user-values
so that these will be restored after a suspend/resume.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Hans de Goede
73633ccbba power: supply: bq24190_charger: Store ichg-max and vreg-max in bq24190_dev_info
Store ichg-max and vreg-max in bq24190_dev_info once from
bq24190_get_config() and drop the bq24190_charger_get_current_max() and
bq24190_charger_get_voltage_max() helpers.

This is a preparation patch for honoring the
constant_charge_current_max_ua and constant_charge_voltage_max_uv
values from power_supply_get_battery_info().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Hans de Goede
a314fae312 power: supply: bq24190_charger: Always call power_supply_get_battery_info()
power_supply_get_battery_info() now also supports getting battery_info
on boards not using dt/of. Remove the of_node check. If neither of nor
other battery-info is present the function will fail making this change
a no-op in that case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Hans de Goede
5e8c1dc78c power: supply: bq24190_charger: Turn off 5V boost regulator on shutdown
Turn off the 5V boost regulator on shutdown, there are 3 reasons for
doing this:

1. It drains he battery if left on
2. If left on the device will not charge when plugged into a charger
3. If left on and the powered peripheral attached to a Type-C port is
   removed before the next boot, then the Type-C port-controller will
   see VBus being present while nothing is attached confusing the
   TCPM state-machine.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Hans de Goede
c76787b0d8 power: supply: core: Add support for generic fwnodes to power_supply_get_battery_info()
Add support to power_supply_get_battery_info() to read the properties from
other fwnode types such as swnodes added by platform code on x86 devices.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Hans de Goede
7562ccd85f power: supply: core: Use fwnode_property_*() in power_supply_get_battery_info()
Switch power_supply_get_battery_info() over to use the generic
fwnode_property_*() property read functions. This is a preparation patch
for adding support for reading properties from other fwnode types such
as swnode properties added by platform code on x86 devices.

Note the parsing of the 2d matrix "ocv-capacity-table-%d" and
"resistance-temp-table" properties is not converted since this depends on
the raw of_get_property() accessor function of which there is no
fwnode_property_*() equivalent AFAICT. This means that these properties
will not be supported in swnodes for now.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11 19:08:34 +01:00
Colin Ian King
784056d36f power: supply: axp288_fuel_gauge: Fix spelling mistake "resisitor" -> "resistor"
There is a spelling mistake in a MODULE_PARM_DESC description. Fix it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-02 20:05:20 +01:00
Sebastian Reichel
28e54414a8 Immutable branch between power-supply, mfd, i2c and extcon for for 5.18
This immutable branch fixes the charger setup on Xiaomi Mi Pad 2 and
 Lenovo Yogabook, which requires updates to multiple drivers throughout
 the tree.
 
 Signed-off-by: Sebastian Reichel <sre@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmH5RA0ACgkQ2O7X88g7
 +poTPxAAg6RQaD5YjwnkE/IXtzhArkGgmAwKFwD0dSsiuiyEiUm1NvLSftQWuq0a
 nnC3LVP1AwAmm3i8Upg5MSNiylARh5TmCN3/QqlIj+ifiw2UMcSGHdFRy6dme/ZV
 5o1TXicH/eFWoWsqtBpupUkl1lCdhkCtQTRcvrcE3LhZ/HGtSKcAu6Gg1fJMuTfK
 Y+6oOI2h+yFZ3anaeLEuRY83VWFXMxZecyhvDDm+2dH7jh+pk13mzBfVwjjQdJew
 n/wHjB0LST8z4LLlPrFSKyNjERRdk5HEZw2vFicG9IEIsX1klfhEtpMlt2SL/ul2
 ttgsalMijBJPbl7XA01Qi72IRUVj0cnUZQbPjeWE0E3il2+3z276C1Ei3HGJkuSl
 KRIn1ZP5/GNu+wVTeRvfnIOw3qYGLfJT3AdW6lsxVEFGCZ0aGEf6Z5FbeoFaCs0P
 id32IJhxuWi35zaSU+5WwmLnbXlVrVp6Y+ZinS0hYUbesEuRcPYzo2ma7FHQ+kvi
 SW/Yn/xSI1kQTpd1ZjQSdpIP2jk4l43h/RKKjvewXFAtj5foRCsZi6oS6enrMm/d
 0brzIhqjSaczaBP86eSTvsMvqxG91oNbLF4YT5kvX4xGR81V7valiJ/KUWFTdOfv
 O5eI4z9oJmQJPLUSLAcfDEMQJQjLvar6AjolH4f4OTKp4YHdJUQ=
 =8iWn
 -----END PGP SIGNATURE-----

Merge tag 'psy-extcon-i2c-mfd-for-v5.18-signed' into psy-next

Immutable branch between power-supply, mfd, i2c and extcon for for 5.18

This immutable branch fixes the charger setup on Xiaomi Mi Pad 2 and
Lenovo Yogabook, which requires updates to multiple drivers throughout
the tree.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
2022-02-01 15:33:24 +01:00
Hans de Goede
c1ae3a4efb power: supply: bq25890: Use the devm_regmap_field_bulk_alloc() helper
Use the devm_regmap_field_bulk_alloc() helper function instead of
open-coding this ourselves.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:12 +01:00
Yauhen Kharuzhy
48f45b094d power: supply: bq25890: Support higher charging voltages through Pump Express+ protocol
Add a "linux,pump-express-vbus-max" property which indicates if the Pump
Express+ protocol should be used to increase the charging protocol.

If this new property is set and a DCP charger is detected then request
a higher charging voltage through the Pump Express+ protocol.

So far this new property is only used on x86/ACPI (non devicetree) devs,
IOW it is not used in actual devicetree files. The devicetree-bindings
maintainers have requested properties like these to not be added to the
devicetree-bindings, so the new property is deliberately not added
to the existing devicetree-bindings.

Changes by Hans de Goede:
- Port to my bq25890 patch-series + various cleanups
- Make behavior configurable through a new "linux,pump-express-vbus-max"
  device-property
- Sleep 1 second before re-checking the Vbus voltage after requesting
  it to be raised, to ensure that the ADC has time to sampled the new Vbus
- Add VBUSV bq25890_tables[] entry and use it in bq25890_get_vbus_voltage()
- Tweak commit message

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Co-developed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:12 +01:00
Hans de Goede
eab25b4f93 power: supply: bq25890: On the bq25892 set the IINLIM based on external charger detection
The bq25892 does not have builtin charger-type detection like the bq25980,
there might be some external charger detection capability, which will be
modelled as a power_supply class-device supplying the bq25892.

Use the usb_type property value from the supplier psy-device to set the
input-current-limit (when available).

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:12 +01:00
Hans de Goede
79d35365a5 power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator
The bq25890_charger code supports enabling/disabling the boost converter
based on usb-phy notifications. But the usb-phy framework is not used on
all boards/platforms. At support for registering the Vbus boost converter
as a standard regulator when there is no usb-phy on the board.

Also add support for providing regulator_init_data through platform_data
for use on boards where device-tree is not used and the platform code must
thus provide the regulator_init_data.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:12 +01:00
Hans de Goede
5575802d78 power: supply: bq25890: Add bq25890_set_otg_cfg() helper
Add a bq25890_set_otg_cfg() helper function, this is a preparation
patch for adding regulator support.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
f481d5b80b power: supply: bq25890: Drop dev->platform_data == NULL check
Drop the "if (!dev->platform_data)" check, this seems to be an attempt
for allowing loading the driver on devices without devicetree stemming
from the initial commit of the driver (with the presumed intention being
the "return -ENODEV" else branch getting replaced with something else).

With the new "linux,skip-init" and "linux,read-back-settings" properties
the driver can actually supports devices without devicetree and this
check no longer makes sense.

While at it, also switch to dev_err_probe(), which is already used in
various other places in the driver.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
06c75095e8 power: supply: bq25890: Enable charging on boards where we skip reset
On boards where the "linux,skip-reset" boolean property is set we don't
reset the charger; and on some boards where the fw takes care of
initalizition F_CHG_CFG is set to 0 before handing control over to the OS.

Explicitly set F_CHG_CFG to 1 on boards where we don't reset the charger,
so that charging is always enabled on these boards, like it is always
enabled on boards where we do reset the charger.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
40428bd467 power: supply: bq25890: Add support to read back the settings from the chip
On most x86/ACPI devices there is no devicetree to supply the necessary
init-data. Instead the firmware already fully initializes the bq25890
charger at boot. To support this, add support for reading back the
settings from the chip through a new "linux,read-back-settings" boolean.

So far this new property is only used on x86/ACPI (non devicetree) devs,
IOW it is not used in actual devicetree files. The devicetree-bindings
maintainers have requested properties like these to not be added to the
devicetree-bindings, so the new property is deliberately not added
to the existing devicetree-bindings.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
7e3b8e357f power: supply: bq25890: Add support to skip reset at probe() / remove()
On most x86/ACPI devices the firmware already fully initializes
the bq25890 charger at boot, in this case it is best to not reset
it at probe() time.

At support for a new "linux,skip-reset" boolean property to support this.
So far this new property is only used on x86/ACPI (non devicetree) devs,
IOW it is not used in actual devicetree files. The devicetree-bindings
maintainers have requested properties like these to not be added to the
devicetree-bindings, so the new property is deliberately not added
to the existing devicetree-bindings.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
7b22a97464 power: supply: bq25890: Add a bq25890_rw_init_data() helper
On most x86/ACPI devices there is no devicetree to supply the necessary
init-data. Instead the firmware already fully initializes the bq25890
charger at boot.

Factor out the current code to write all the init_data from devicetree
into a new bq25890_rw_init_data() helper which can both write the data
to the charger (the current behavior) as well as read it back from
the charger into the init_data struct.

This is a preparation patch for adding support for x86/ACPI device's
where the init_data must be read back from the bq25890 charger.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Yauhen Kharuzhy
c562a43a46 power: supply: bq25890: Reduce reported CONSTANT_CHARGE_CURRENT_MAX for low temperatures
Take into account possible current reduction due to low-temperature when
reading POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX. As described in
the datasheet in cool (0-20° Celcius) conditions the current limit is
decreased to 20% or 50% of ICHG field value depended on JEITA_ISET field.

Also add NTC_FAULT field value to the debug message in
bq25890_get_chip_state().

Changed by Hans de Goede:
- Fix reading F_CHG_FAULT instead of F_NTC_FIELD for state->ntc_fault
- Only read JEITA_ISET field if necessary
- Tweak commit message a bit

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Co-developed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Yauhen Kharuzhy
766873c139 power: supply: bq25890: Rename IILIM field to IINLIM
Rename the Input Current Limit field in the REG00 from IILIM to IINLIM
accordingly with the bq2589x datasheet. This is just cosmetical change
to reduce confusion.

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
2220af8ca6 power: supply: core: Refactor power_supply_set_input_current_limit_from_supplier()
Some (USB) charger ICs have variants with USB D+ and D- pins to do their
own builtin charger-type detection, like e.g. the bq24190 and bq25890 and
also variants which lack this functionality, e.g. the bq24192 and bq25892.

In case the charger-type; and thus the input-current-limit detection is
done outside the charger IC then we need some way to communicate this to
the charger IC. In the past extcon was used for this, but if the external
detection does e.g. full USB PD negotiation then the extcon cable-types do
not convey enough information.

For these setups it was decided to model the external charging "brick"
and the parameters negotiated with it as a power_supply class-device
itself; and power_supply_set_input_current_limit_from_supplier() was
introduced to allow drivers to get the input-current-limit this way.

But in some cases psy drivers may want to know other properties, e.g. the
bq25892 can do "quick-charge" negotiation by pulsing its current draw,
but this should only be done if the usb_type psy-property of its supplier
is set to DCP (and device-properties indicate the board allows higher
voltages).

Instead of adding extra helper functions for each property which
a psy-driver wants to query from its supplier, refactor
power_supply_set_input_current_limit_from_supplier() into a
more generic power_supply_get_property_from_supplier() function.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:55:11 +01:00
Hans de Goede
210bc22c5d power: supply: axp288_fuel_gauge: Add a no_current_sense_res module_param
Some boards with an AXP288 fuel-gauge appear to have a broken (approx.
2 milli-ohm instead of 10) current sense resistor.

This makes the coulomb-counter part of the fuel-gauge useless, but the
OCV based capacity reporting is still working. Add a no_current_sense_res
module_param to disable use of the coulomb-counter using parts of the
fuel-gauge to allow users to work around this.

Note this is a module parameter and not done through DMI quirks, since
this seems to be a defect on some boards, not something which all boards
of the same model share.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:34 +01:00
Hans de Goede
30abb3d079 power: supply: axp288_fuel_gauge: Take lock before updating the valid flag
The valid flag is protected by the mutex, so code clearing it
should take the mutex before cleating the valid flag.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:34 +01:00
Hans de Goede
05972f53a1 power: supply: axp288_fuel_gauge: Refactor IRQ initialization
Refactor the IRQ initialization code:

* Move the looking up of the vIRQs to the beginning of probe(), failing
  probe early if this fails
* Do the actual requesting of IRQs inline in probe() and properly abort
  probe() on errors
* Use devm_request_threaded_irq(), completing the conversion of probe() to
  only use devm managed resources and remove the remove() driver function.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:34 +01:00
Hans de Goede
f1b7e0881f power: supply: axp288_fuel_gauge: Use devm_power_supply_register()
Use devm_power_supply_register() instead of
power_supply_register().

Note as a side-effect this changes the release order so that now
first the IRQs get free-ed and then the psy gets unregistered.
This is actually a bug-fix since this fixes the IRQ possibly trying
to reference the unregistered psy.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:34 +01:00
Hans de Goede
3601086612 power: supply: axp288_fuel_gauge: Use devm_add_action_or_reset() for iio chan release
An existing comment already mentions we: "cannot use devm_iio_channel_get
because x86 systems lack the device<->channel maps which iio_channel_get
will try to use when passed a non NULL device pointer".

Work around this by registering a devm action to free the iio-channels.
This is a step on the way to fully converting the probe() function to
only use devm managed resources.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:34 +01:00
Hans de Goede
0b80eb6c38 power: supply: axp288_fuel_gauge: Add axp288_fuel_gauge_read_initial_regs()
Refactor probe a bit, introducing a new
axp288_fuel_gauge_read_initial_regs() helper. This replaces a whole
bunch of gotos and removes the unblock_punit_i2c_access label.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:34 +01:00
Hans de Goede
b265716744 power: supply: axp288_fuel_gauge: Add dev helper var to probe()
Add a dev local variable to probe() as shortcut for &pdev->dev, this is
a preparation change for making more use of devm managed resources.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 14:29:33 +01:00
Yang Li
2b56a9a28a power: supply: core: fix application of sizeof to pointer
The coccinelle check report:
./drivers/power/supply/cw2015_battery.c:692:12-18: ERROR: application of
sizeof to pointer

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Fixes: 25fd330370 ("power: supply_core: Pass pointer to battery info")
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 13:13:44 +01:00
Carl Philipp Klemm
fd46821e85 power: supply: cpcap-battery: Add battery type auto detection for mapphone devices
This allows cpcap-battery to detect whitch battery is inserted, HW4X or
BW8X for xt875 and EB41 for xt894 by examining the battery nvmem. If no
known battery is detected sane defaults are used.

Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 12:47:11 +01:00
Evgeny Boger
d4f408cdcd power: supply: axp20x_battery: properly report current when discharging
As stated in [1], negative current values are used for discharging
batteries.

AXP PMICs internally have two different ADC channels for shunt current
measurement: one used during charging and one during discharging.
The values reported by these ADCs are unsigned.
While the driver properly selects ADC channel to get the data from,
it doesn't apply negative sign when reporting discharging current.

[1] Documentation/ABI/testing/sysfs-class-power

Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Acked-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 11:18:47 +01:00
Miaoqian Lin
ba18dad0fb power: reset: gemini-poweroff: Fix IRQ check in gemini_poweroff_probe
platform_get_irq() returns negative error number instead 0 on failure.
And the doc of platform_get_irq() provides a usage example:

    int irq = platform_get_irq(pdev, 0);
    if (irq < 0)
        return irq;

Fix the check of return value to catch errors correctly.

Fixes: f7a388d6cd ("power: reset: Add a driver for the Gemini poweroff")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 11:07:59 +01:00
Sergey Shtylyov
2b7950c7ac power: supply: mp2629_charger: use platform_get_irq()
Calling platform_get_irq_optional() doesn't make sense if you then bail out
on any error it returns.  Switch to calling platform_get_irq() instead and
remove dev_err() call as platform_get_irq() already curses loudly on error.

Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01 10:32:35 +01:00
Gustavo A. R. Silva
441d38c60f power: supply: cros_usbpd: Use struct_size() helper in kzalloc()
Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Also, address the following sparse warnings:
drivers/power/supply/cros_usbpd-charger.c:107:23: warning: using sizeof on a flexible structure

Link: https://github.com/KSPP/linux/issues/174
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-01-31 22:42:25 +01:00
Greg Kroah-Hartman
a8e223094c power_supply: ab8500: use default_groups in kobj_type
There are currently 2 ways to create a set of sysfs files for a
kobj_type, through the default_attrs field, and the default_groups
field.  Move the ab8500 power supply sysfs code to use default_groups
field which has been the preferred way since aa30f47cf6 ("kobject: Add
support for default attribute groups to kobj_type") so that we can soon
get rid of the obsolete default_attrs field.

Cc: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org
Link: https://lore.kernel.org/r/20211229140908.2523513-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-01-26 15:55:39 +01:00
Linus Torvalds
347708875a platform-drivers-x86 for v5.17-1
Highlights:
  - new drivers:
    - asus-tf103c-dock
    - intel_crystal_cove_charger
    - lenovo-yogabook-wmi
    - simatic-ipc platform-code + led driver + watchdog driver
    - x86-android-tablets (kernel module to workaround DSDT bugs on these)
  - amd-pmc:
    - bug-fixes
    - smar trace buffer support
  - asus-wmi: support for custom fan curves
  - int3472 (camera info ACPI object for Intel IPU3/SkyCam cameras):
    - ACPI core + int3472 changes to delay enumeration of camera sensor I2C
      clients until the PMIC for the sensor has been fully probed
    - Add support for board data (DSDT info is incomplete) for setting up
      the tps68470 PMIC used on some boards with these cameras
    - Add board data for the Microsoft Surface Go (original, v2 and v3)
  - thinkpad_acpi:
    - various cleanups
    - support for forced battery discharging (for battery calibration)
    - support to inhibit battery charging
    - this includes power_supply core changes to add new APIs for this
  - think_lmi: enhanced BIOS password support
  - various other small fixes and hardware-id additions
 
 The following is an automated git shortlog grouped by driver:
 
 ACPI:
  -  delay enumeration of devices with a _DEP pointing to an INT3472 device
 
 Add Asus TF103C dock driver:
  - Add Asus TF103C dock driver
 
 Add intel_crystal_cove_charger driver:
  - Add intel_crystal_cove_charger driver
 
 Documentation:
  -  syfs-class-firmware-attributes: Lenovo Opcode support
 
 Merge tag 'platform-drivers-x86-int3472-1' into review-hans:
  - Merge tag 'platform-drivers-x86-int3472-1' into review-hans
 
 amd-pmc:
  -  only use callbacks for suspend
  -  Add support for AMD Smart Trace Buffer
  -  Simplify error handling and store the pci_dev in amd_pmc_dev structure
  -  Fix s2idle failures on certain AMD laptops
  -  Make CONFIG_AMD_PMC depend on RTC_CLASS
 
 apple-gmux:
  -  use resource_size() with res
 
 asus-wmi:
  -  Reshuffle headers for better maintenance
  -  Split MODULE_AUTHOR() on per author basis
  -  Join string literals back
  -  remove unneeded semicolon
  -  Add support for custom fan curves
 
 dell-wmi-descriptor:
  -  disable by default
 
 hp_accel:
  -  Use SIMPLE_DEV_PM_OPS() for PM ops
  -  Fix an error handling path in 'lis3lv02d_probe()'
 
 i2c:
  -  acpi: Add i2c_acpi_new_device_by_fwnode() function
  -  acpi: Use acpi_dev_ready_for_enumeration() helper
 
 int3472:
  -  Add board data for Surface Go 3
  -  Deal with probe ordering issues
  -  Pass tps68470_regulator_platform_data to the tps68470-regulator MFD-cell
  -  Pass tps68470_clk_platform_data to the tps68470-regulator MFD-cell
  -  Add get_sensor_adev_and_name() helper
  -  Split into 2 drivers
 
 intel-uncore-frequency:
  -  use default_groups in kobj_type
 
 intel_pmc_core:
  -  fix memleak on registration failure
 
 leds:
  -  simatic-ipc-leds: add new driver for Siemens Industial PCs
 
 lenovo-yogabook-wmi:
  -  Add support for hall sensor on the back
  -  Add driver for Lenovo Yoga Book
 
 lg-laptop:
  -  Recognize more models
 
 platform:
  -  surface: Propagate ACPI Dependency
 
 platform/mellanox:
  -  mlxbf-pmc: Fix an IS_ERR() vs NULL bug in mlxbf_pmc_map_counters
  -  mlxreg-lc: fix error code in mlxreg_lc_create_static_devices()
 
 platform/surface:
  -  aggregator_registry: Rename device registration function
  -  aggregator_registry: Use generic client removal function
  -  aggregator: Make client device removal more generic
 
 platform/x86/intel:
  -  Remove X86_PLATFORM_DRIVERS_INTEL
  -  hid: add quirk to support Surface Go 3
 
 platform_data:
  -  Add linux/platform_data/tps68470.h file
 
 pmc_atom:
  -  improve critclk_systems matching for Siemens PCs
 
 power:
  -  supply: Provide stubs for charge_behaviour helpers
  -  supply: fix charge_behaviour attribute initialization
  -  supply: add helpers for charge_behaviour sysfs
  -  supply: add charge_behaviour attributes
 
 samsung-laptop:
  -  Fix typo in a comment
 
 simatic-ipc:
  -  add main driver for Siemens devices
 
 system76_acpi:
  -  Guard System76 EC specific functionality
 
 think-lmi:
  -  Prevent underflow in index_store()
  -  Simplify tlmi_analyze() error handling a bit
  -  Move kobject_init() call into tlmi_create_auth()
  -  Opcode support
  -  Abort probe on analyze failure
 
 thinkpad_acpi:
  -  support inhibit-charge
  -  support force-discharge
  -  Add lid_logo_dot to the list of safe LEDs
  -  Add LED_RETAIN_AT_SHUTDOWN to led_class_devs
  -  Remove unused sensors_pdev_attrs_registered flag
  -  Fix the hwmon sysfs-attr showing up in the wrong place
  -  tpacpi_attr_group contains driver attributes not device attrs
  -  Register tpacpi_pdriver after subdriver init
  -  Restore missing hotkey_tablet_mode and hotkey_radio_sw sysfs-attr
  -  Fix thermal_temp_input_attr sorting
  -  Remove "goto err_exit" from hotkey_init()
  -  Properly indent code in tpacpi_dytc_profile_init()
  -  Cleanup dytc_profile_available
  -  Simplify dytc_version handling
  -  Make *_init() functions return -ENODEV instead of 1
  -  Accept ibm_init_struct.init() returning -ENODEV
  -  Convert platform driver to use dev_groups
  -  fix documentation for adaptive keyboard
  -  Fix WWAN device disabled issue after S3 deep
  -  Add support for dual fan control
 
 tools/power/x86/intel-speed-select:
  -  v1.11 release
  -  Update max frequency
 
 touchscreen_dmi:
  -  Remove the Glavey TM800A550L entry
  -  Enable pen support on the Chuwi Hi10 Plus and Pro
  -  Correct min/max values for Chuwi Hi10 Pro (CWI529) tablet
  -  Add TrekStor SurfTab duo W1 touchscreen info
 
 watchdog:
  -  simatic-ipc-wdt: add new driver for Siemens Industrial PCs
 
 wmi:
  -  Add no_notify_data flag to struct wmi_driver
  -  Fix driver->notify() vs ->probe() race
  -  Replace read_takes_no_args with a flags field
 
 x86-android-tablets:
  -  Fix GPIO lookup leak on error-exit
  -  Add TM800A550L data
  -  Add Asus MeMO Pad 7 ME176C data
  -  Add Asus TF103C data
  -  Add support for preloading modules
  -  Add support for registering GPIO lookup tables
  -  Add support for instantiating serdevs
  -  Add support for instantiating platform-devs
  -  Add support for PMIC interrupts
  -  Don't return -EPROBE_DEFER from a non probe() function
  -  New driver for x86 Android tablets
 
 x86/platform/uv:
  -  use default_groups in kobj_type
 -----BEGIN PGP SIGNATURE-----
 
 iQFIBAABCAAyFiEEuvA7XScYQRpenhd+kuxHeUQDJ9wFAmHcCbkUHGhkZWdvZWRl
 QHJlZGhhdC5jb20ACgkQkuxHeUQDJ9y3yAf/Xo8TWsnF7XoS3pNCqRcObIulHy6u
 9AOD4gTb0p9LiAd8WN75UsQDew0Rib+UDTS3s6g9l71fMzpTFOD4IaBPrVAmIxpu
 Qs9raFTH67CFid/V3DCwAjPQYxxp5LBGvYJ4oy3OmaYHieV9jdsvNLISlpi/V8wR
 PmbmYtiK5TPZwRT+mknq89D+LynP2NYkvoqRitmB7MrAvxY3c0ssrex6dXMrdgqK
 ehRtfz/ER8xQ03APIzHG+ec73LZsHCMDDG7teas4tiMlMaWGgRO2I8GAudjuPEoy
 mBTSb3ABuEud8LTMgjB+trM2w9IAoFE0L6/OrKE5dK1tPdaLxvCuuSVheQ==
 =tmPR
 -----END PGP SIGNATURE-----

Merge tag 'platform-drivers-x86-v5.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86

Pull x86 platform driver updates from Hans de Goede:
 "Highlights:

  New drivers:
   - asus-tf103c-dock
   - intel_crystal_cove_charger
   - lenovo-yogabook-wmi
   - simatic-ipc platform-code + led driver + watchdog driver
   - x86-android-tablets (kernel module to workaround DSDT bugs on
     these)

  amd-pmc:
   - bug-fixes
   - smar trace buffer support

  asus-wmi:
   - support for custom fan curves

  int3472 (camera info ACPI object for Intel IPU3/SkyCam cameras):
   - ACPI core + int3472 changes to delay enumeration of camera sensor
     I2C clients until the PMIC for the sensor has been fully probed
   - Add support for board data (DSDT info is incomplete) for setting up
     the tps68470 PMIC used on some boards with these cameras
   - Add board data for the Microsoft Surface Go (original, v2 and v3)

  thinkpad_acpi:
   - various cleanups
   - support for forced battery discharging (for battery calibration)
   - support to inhibit battery charging
   - this includes power_supply core changes to add new APIs for this

  think_lmi:
   - enhanced BIOS password support

  various other small fixes and hardware-id additions"

* tag 'platform-drivers-x86-v5.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86: (78 commits)
  power: supply: Provide stubs for charge_behaviour helpers
  platform/x86: x86-android-tablets: Fix GPIO lookup leak on error-exit
  platform/x86: int3472: Add board data for Surface Go 3
  platform/x86: Add Asus TF103C dock driver
  platform/x86: x86-android-tablets: Add TM800A550L data
  platform/x86: x86-android-tablets: Add Asus MeMO Pad 7 ME176C data
  platform/x86: x86-android-tablets: Add Asus TF103C data
  platform/x86: x86-android-tablets: Add support for preloading modules
  platform/x86: x86-android-tablets: Add support for registering GPIO lookup tables
  platform/x86: x86-android-tablets: Add support for instantiating serdevs
  platform/x86: x86-android-tablets: Add support for instantiating platform-devs
  platform/x86: x86-android-tablets: Add support for PMIC interrupts
  platform/x86: x86-android-tablets: Don't return -EPROBE_DEFER from a non probe() function
  platform/x86: touchscreen_dmi: Remove the Glavey TM800A550L entry
  platform/x86: touchscreen_dmi: Enable pen support on the Chuwi Hi10 Plus and Pro
  platform/x86: touchscreen_dmi: Correct min/max values for Chuwi Hi10 Pro (CWI529) tablet
  platform/x86: Add intel_crystal_cove_charger driver
  power: supply: fix charge_behaviour attribute initialization
  platform/x86: intel-uncore-frequency: use default_groups in kobj_type
  x86/platform/uv: use default_groups in kobj_type
  ...
2022-01-11 11:26:57 -08:00
Linus Torvalds
039053c119 power supply and reset changes for the v5.17 series
power-supply core:
  - introduce "No Battery" health status
  - use library interpolation
  - add power_supply_battery_info documentation
  - migrate power_supply_battery_info to be fully heap allocated
    making it more obvious that it needs to be free'd manually
 
 Drivers:
  - max77976-charger: new driver
  - qcom-smbb: add pm8226 charger support
  - bq25890-charger: support battery temperature readings
  - ab8500: continue migrating towards using standard core APIs
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmHb+9YACgkQ2O7X88g7
 +pqhGw/+NyqnkSIsU4udxYJY47ooaZ7f2rApFueJSre0Xzwi37SQFFvstBb196YP
 B1mr2H16Slni0kRItu+B1H04mI1y1o7zT4E84s1DoMQjILLtxh+LiT8tefhhWtBs
 5a6IiUKtxo2HZZgreTqyAAjqPYkdRGDkChK87zBZdxIGcaGHXkRlyuTSR2P406r/
 qvA5uCkVg7CMqXf0RemcIlEOvSxaPXZz+PVJjn6qbjSioQHtOekoxoMBziy31Nhm
 Qp0sEYYlW6ZRpaP/IFU21sZb8zaH+isOrg2U/LttgfABdwtEVUz/nygZwSD0ncBi
 zSUrc4Mu/goh7m5oY91HUsis3fzgABMd/xdaDDzJoh91LvguE9lA2vP5r7hEDLVD
 S7v9RNNEfALce5sHGAEXQX0IztD0xZhSRe6jpeAYLVB0OG1Tae3q/6dlEHQsz2rb
 oANYsxrAU0hf2MnsXa6FnR1cnVJNm7z/bQpTFbU7guSX8Vi5n8jzmghoi3piCjyk
 9YXMROuivXuaBz1wXNk2IXzdYwtOTeateo2yYdSQol3UnYgUtIrn+qBVeuElbC3C
 qkb21yTpEIk3aoZOjbKFze7ks6L8c5Nip+66s4WkcAucK3Uxii1QpTR9f1+TdxN0
 vjybsIRHqPnCh6yl1JR/0NNvFPGQWkJt6sveQXas/LAZ77MOMro=
 =9cda
 -----END PGP SIGNATURE-----

Merge tag 'for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:
 "Power-supply core:

   - introduce "No Battery" health status

   - use library interpolation

   - add power_supply_battery_info documentation

   - migrate power_supply_battery_info to be fully heap allocated making
     it more obvious that it needs to be free'd manually

  Drivers:

   - max77976-charger: new driver

   - qcom-smbb: add pm8226 charger support

   - bq25890-charger: support battery temperature readings

   - ab8500: continue migrating towards using standard core APIs"

* tag 'for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (28 commits)
  power: supply_core: Pass pointer to battery info
  power: supply: ab8500: Fix the error handling path of ab8500_charger_probe()
  power: reset: mt6397: Check for null res pointer
  power: bq25890: add POWER_SUPPLY_PROP_TEMP
  power: supply: qcom_smbb: support pm8226
  dt-bindings: power: supply: pm8941-charger: add pm8226
  power: supply: ab8500: Standardize capacity lookup
  power: supply: ab8500: Standardize temp res lookup
  power: supply: ab8500: Standardize CV voltage
  power: supply: ab8500: Standardize CC current
  power: supply: ab8500: Make recharge capacity a constant
  power: supply: ab8500: Standardize termination current
  power: supply: ab8500: Standardize internal resistance
  power: supply: ab8500_fg: Init battery data in bind()
  power: supply: ab8500: Standardize voltages
  power: supply: ab8500: Standardize technology
  power: supply: ab8500: Standardize design capacity
  power: supply: ab8500: Use only one battery type
  power: supply: ab8500: Drop unused battery types
  power: supply: ab8500: Standardize operating temperature
  ...
2022-01-11 11:20:27 -08:00
Thomas Weißschuh
c8e2d921aa power: supply: fix charge_behaviour attribute initialization
All properties have to be added to power_supply_attrs which was missed
before.

Fixes: 1b0b6cc803 ("power: supply: add charge_behaviour attributes")
Reported-by: Heiner Kallweit <hkallweit1@gmail.com>
Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20220105064239.2689-1-linux@weissschuh.net
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2022-01-05 11:31:18 +01:00
Linus Walleij
25fd330370 power: supply_core: Pass pointer to battery info
The function to retrieve battery info (from the device tree) assumes
we have a static info struct that gets populated by calling into
power_supply_get_battery_info().

This is awkward since I want to support tables of static battery
info by just assigning a pointer to all info based on e.g. a
compatible value in the device tree.

We also have a mixture of static and dynamically allocated
variables here.

Bite the bullet and let power_supply_get_battery_info() allocate
also the memory used for the very top level
struct power_supply_battery_info container. Pass pointers
around and lifecycle this with the psy device just like the
stuff we allocate inside it.

Change all current users over.

As part of the change, initializers need to be added to some
previously uninitialized fields in struct
power_supply_battery_info.

Reviewed-By: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-01-03 18:53:10 +01:00
Christophe JAILLET
be2c0d5418 power: supply: ab8500: Fix the error handling path of ab8500_charger_probe()
Since the commit below, ab8500_bm_of_remove() needs to be called after a
successful ab8500_bm_of_probe() call.
This commit has only updated the remove function.

Fix the error handling path of the probe the same way.

Fixes: 6252c706cd ("power: supply: ab8500: Standardize operating temperature")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-01-03 18:33:29 +01:00
Jiasheng Jiang
1c1348bf05 power: reset: mt6397: Check for null res pointer
The return value of platform_get_resource() needs to be checked.
To avoid use of error pointer in case that there is no suitable
resource.

Fixes: d28c74c107 ("power: reset: add driver for mt6323 poweroff")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-01-03 18:30:21 +01:00
Thomas Weißschuh
539b9c94ac power: supply: add helpers for charge_behaviour sysfs
These helper functions can be used by drivers to implement their own
sysfs-attributes.
This is useful for ACPI-drivers extending the default ACPI-battery with
their own charge_behaviour attributes.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Link: https://lore.kernel.org/r/20211123232704.25394-3-linux@weissschuh.net
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2021-12-21 16:27:42 +01:00
Angus Ainslie
9652c02428 power: bq25890: add POWER_SUPPLY_PROP_TEMP
Add the POWER_SUPPLY_PROP_TEMP and a NTC 10K percent VREGN to degrees LUT.

Make sure that a conversion is forced when the power supply is offline so
the temperature is valid.

Signed-off-by: Angus Ainslie <angus@akkea.ca>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-12-02 18:27:06 +01:00
Luca Weiss
0838a3bfcd power: supply: qcom_smbb: support pm8226
PM8226 (used in MSM8226) has v1 smbb hardware and works fine with the
current driver.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-30 11:34:27 +01:00
Linus Walleij
0525f34d02 power: supply: ab8500: Standardize capacity lookup
The AB8500 charger only has one capacity table with
unspecified temperature, so we assume this capacity is given
for 20 degrees Celsius.

Convert this table to use the OCV (open circuit voltage)
tables in struct power_supply_battery_ocv_table.

In the process, convert the fuel gauge driver to use
microvolts and microamperes so we can use the same internals
as the power supply subsystem without having to multiply
and divide with 1000 in a few places.

Also convert high_curr_threshold and lowbat_threshold to
use microamperes and microvolts as these are closely
related to these changes.

Drop the unused overbat_threshold member in the custom
struct ab8500_fg_parameters.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:26 +01:00
Linus Walleij
67acb291f3 power: supply: ab8500: Standardize temp res lookup
The lookup from battery temperature to internal resistance was
using its own format. Rewrite this to use the table inside
struct power_supply_battery_info:s resist_table.

The supplied resistance table has to be rewritten to express
the resistance in percent of the factory resistance as a
side effect.

We can then rely on the library function
power_supply_temp2resist_simple() to interpolate the internal
resistance percent from the temperature.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:26 +01:00
Linus Walleij
bc6e028714 power: supply: ab8500: Standardize CV voltage
The voltage used in the constant voltage phase of the charging
exist in struct power_supply_battery_info as
constant_charge_voltage_max_uv.

Switch the custom property normal_vol_lvl to this and
consequentially change everything that relates to this value
over to using microvolts rather than millivolts so
we align internal representation of current with the
power core. Prefix every variable we change with *_uv
to indicate the unit everywhere but also to make sure
we do not miss any outlier.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:26 +01:00
Linus Walleij
83e5aa77d1 power: supply: ab8500: Standardize CC current
The current used in the constant current phase of the charging
exist in struct power_supply_battery_info as
constant_charge_current_max_ua.

Switch the custom property max_out_curr to this and
consequentally change everything that relates to this value
over to using microamperes rather than milliamperes so
we align internal representation of current with the
power core. Prefix every variable we change with *_ua
to indicate the unit everywhere but also to make sure
we do not miss any outlier.

Drop some duplicate unused defines in a header.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
1091ed7db0 power: supply: ab8500: Make recharge capacity a constant
The recharge capacity is the hysteresis level for a charger to
restart when a battery does not support maintenance charging.

All products using the AB8500 have batteries supporting
maintenace charging and all code has always set this to 95%.

Turn it into a constant.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
9c20899da4 power: supply: ab8500: Standardize termination current
The AB8500 custom termination current can be replaced by the
corresponding struct power_supply_battery_info field.

Remove the struct member and amend the code to use the
standard property.

Add *_ua suffix for clarity and to make sure we have
changed all code sites using this member.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
50425ccf24 power: supply: ab8500: Standardize internal resistance
The nominal internal resistance isn't used by the AB8500
charging code, instead this resistance is measured continuously,
but we anyways migrate this to the standard property in
struct power_supply_battery_info.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
fc81c435a8 power: supply: ab8500_fg: Init battery data in bind()
We were assigning some battery data state in probe() but
this is insecure as it depends on the proper probe order
between the components: the charger must probe first so
that the battery data is populated. Move the init to
the bind() call which is certain to happen after the
probe of the master and all components has happened.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
2a5f41830a power: supply: ab8500: Standardize voltages
The nominal voltage in this charge driver corresponds to
both the voltage_min_design_uv and voltage_max_design_uv
of struct power_supply_battery_info so assign both if this
is undefined.

The overcharge max voltage (when the charger should cut off)
is migrated at the same time so we move both voltages to
struct power_supply_battery_info.

Adjust the code to deal directly with the microvolt values
instead of converting them to millivolts.

Add *_uv suffixes for clarity and to make sure we have
changed all code sites using this member.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
2d3559a50a power: supply: ab8500: Standardize technology
The AB8500 custom battery type can be replaced by the
corresponding struct power_supply_battery_info field.

Remove the struct member and amend the code to use the
standard property.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
22be8d77c8 power: supply: ab8500: Standardize design capacity
Now that we know that we have only one battery type to
deal with we can proceed to transfer properties to
struct power_supply_battery_info.

The designed capacity for the battery was in a custom field
of the custom battery type in mAh, transfer this to the
standard charge_full_design_uah property in
struct power_supply_battery_info and augment the code
accordingly.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
e5dff305ab power: supply: ab8500: Use only one battery type
The code was going through hoops and loops to detect what
battery is connected and check the resistance for this battery
etc.

Skip this trouble: we will support one battery (currently
"unknown") then we will find the connected battery in the
device tree using a compatible string. The battery resistance
may be used to double-check that the right battery is
connected.

Convert the array of battery types into one battery type so
we can next move over the properties of this one type into
the standard struct power_supply_battery_info.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
d8d26ac12e power: supply: ab8500: Drop unused battery types
The code tries to detect a lot of battery variants on the reference
designs, but we are not using the reference designs in practice, we
are using real products such as Samsung Phones.

The reference design with no battery plugged in will be detected as
a LIPO battery with a thermistor on the batctrl pin so we will
assume this and later on we can support other types through the
device tree if we want, just like the products do.

Drop the tables for external thermistor, only keep the internal
thermistor tables that we will use as default.

We can delete the assignment of the temperature to resistance table
since the default will be the only and correct option.

Also get rid of some unused variables and unused exports.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
6252c706cd power: supply: ab8500: Standardize operating temperature
Instead of storing the temperature limits in our custom
struct struct ab8500_bm_data, make struct power_supply_battery_info
a member of this and store the min and max temperatures inside
that struct as the temp_min/temp_max and
temp_alert_min/temp_alert_max respectively.

The values can be assigned from the device tree, but if
not present will be set to the same defaults as are currently
in the code.

This way we start to move over to using
struct power_supply_battery_info and make it possible to move
the data over to the device tree and we will move piece by
piece toward using the standard info struct.

Temperature hysteresis is currently not supported by the
standard struct but we move the assignment here as well so
that we have all parameterization in one spot.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
3aca6ecdab power: supply: ab8500: Sink current tables into charger code
The two tables for input and output current translation from
register values does not need to be passed around from the
battery manager data. Just push it down into the charger code
where it is used, like other tables in that code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
59f1b85470 power: supply: ab8500: Use core battery parser
This deploys the core battery DT parser to read the basic properties
of the battery. We only use very little of it as we start out, but
we will improve as we go along.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-22 17:16:25 +01:00
Linus Walleij
a4585ba205 power: supply: core: Use library interpolation
The power supply core appears to contain two open coded
linear interpolations. Use the kernel fixpoint arithmetic
interpolation library function instead.

Cc: Chunyan Zhang <chunyan.zhang@unisoc.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-17 17:44:41 +01:00
Luca Ceresoli
715ecbc10d power: supply: max77976: add Maxim MAX77976 charger driver
Add support for the MAX77976 3.5/5.5A 1-Cell Li+ Battery Charger.

This is a simple implementation enough to be used as a simple battery
charger without OTG and boost.

Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-16 16:10:07 +01:00
Luca Ceresoli
77d641baa3 power: supply: core: add POWER_SUPPLY_HEALTH_NO_BATTERY
Some chargers can keep the system powered from the mains even when no
battery is present. It this case none of the currently defined health
statuses applies. Add a new status to report that no battery is present.

Suggested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-16 16:10:07 +01:00
Nathan Chancellor
644106cdb8 power: reset: ltc2952: Fix use of floating point literals
A new commit in LLVM causes an error on the use of 'long double' when
'-mno-x87' is used, which the kernel does through an alias,
'-mno-80387' (see the LLVM commit below for more details around why it
does this).

drivers/power/reset/ltc2952-poweroff.c:162:28: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
        data->wde_interval = 300L * 1E6L;
                                  ^
drivers/power/reset/ltc2952-poweroff.c:162:21: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
        data->wde_interval = 300L * 1E6L;
                           ^
drivers/power/reset/ltc2952-poweroff.c:163:41: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
        data->trigger_delay = ktime_set(2, 500L*1E6L);
                                               ^
3 errors generated.

This happens due to the use of a 'long double' literal. The 'E6' part of
'1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
it to 'long double'.

There is no visible reason for floating point values in this driver, as
the values are only assigned to integer types. Use NSEC_PER_MSEC, which
is the same integer value as '1E6L', to avoid changing functionality but
fix the error.

Fixes: 6647156c00 ("power: reset: add LTC2952 poweroff driver")
Link: https://github.com/ClangBuiltLinux/linux/issues/1497
Link: a8083d42b1
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-16 15:22:39 +01:00
Yauhen Kharuzhy
80211be1b9 power: bq25890: Enable continuous conversion for ADC at charging
Instead of one shot run of ADC at beginning of charging, run continuous
conversion to ensure that all charging-related values are monitored
properly (input voltage, input current, themperature etc.).

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-15 15:09:54 +01:00
Linus Walleij
51c7b6a039 power: supply: core: Break capacity loop
We should not go on looking for more capacity tables after
we realize we have looked at the last one in
power_supply_find_ocv2cap_table().

Fixes: 3afb50d712 ("power: supply: core: Add some helpers to use the battery OCV capacity table")
Cc: Chunyan Zhang <chunyan.zhang@unisoc.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-11-15 14:20:11 +01:00
Hans de Goede
22ad4f99f6 power: supply: bq25890: Fix initial setting of the F_CONV_RATE field
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>
2021-11-02 16:48:47 +01:00
Hans de Goede
d01363da53 power: supply: bq25890: Fix race causing oops at boot
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>
2021-11-02 16:48:47 +01:00
Hans de Goede
cdf10ffe8f power: supply: bq27xxx: Fix kernel crash on IRQ handler register error
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>
2021-11-02 13:47:19 +01:00
Martin Kepplinger
172d0ccea5 power: bq25890: add return values to error messages
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>
2021-10-18 18:27:40 +02:00
Hans de Goede
5b5100c569 power: supply: axp288-charger: Simplify axp288_get_charger_health()
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>
2021-10-18 18:18:56 +02:00
Hans de Goede
9052ff9b03 power: supply: axp288-charger: Remove unnecessary is_present and is_online helpers
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>
2021-10-18 18:18:56 +02:00
Hans de Goede
0b5a9135d5 power: supply: axp288-charger: Add depends on IOSF_MBIO to Kconfig
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>
2021-10-18 18:18:56 +02:00
Linus Walleij
1a67843595 power: supply: ab8500_bmdata: Use standard phandle
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>
2021-10-13 18:15:57 +02:00
Wei Yongjun
db6e436264 power: supply: axp288_charger: Fix missing mutex_init()
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>
2021-10-13 14:04:20 +02:00
Sebastian Krzyszkowiak
e660dbb68c power: supply: max17042_battery: Prevent int underflow in set_soc_threshold
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>
2021-10-12 17:59:10 +02:00
Sebastian Krzyszkowiak
0cf48167b8 power: supply: max17042_battery: Clear status bits in interrupt handler
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>
2021-10-12 17:59:05 +02:00
Yang Yingliang
1d422ecfc4 power: supply: max17040: fix null-ptr-deref in max17040_probe()
Add check the return value of devm_regmap_init_i2c(), otherwise
later access may cause null-ptr-deref as follows:

KASAN: null-ptr-deref in range [0x0000000000000360-0x0000000000000367]
RIP: 0010:regmap_read+0x33/0x170
Call Trace:
  max17040_probe+0x61b/0xff0 [max17040_battery]
 ? write_comp_data+0x2a/0x90
 ? max17040_set_property+0x1d0/0x1d0 [max17040_battery]
 ? tracer_hardirqs_on+0x33/0x520
 ? __sanitizer_cov_trace_pc+0x1d/0x50
 ? _raw_spin_unlock_irqrestore+0x4b/0x60
 ? trace_hardirqs_on+0x63/0x2d0
 ? write_comp_data+0x2a/0x90
 ? __sanitizer_cov_trace_pc+0x1d/0x50
 ? max17040_set_property+0x1d0/0x1d0 [max17040_battery]
 i2c_device_probe+0xa31/0xbe0

Fixes: 6455a8a84b ("power: supply: max17040: Use regmap i2c")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-10-12 17:18:46 +02:00
Jakob Hauser
bf895295e9 power: supply: rt5033_battery: Change voltage values to µV
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>
2021-10-12 17:12:23 +02:00
Kate Hsuan
ed22945485 power: supply: axp288-charger: Optimize register reading method
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>
2021-10-12 15:21:15 +02:00
Tang Bin
0668281d32 power: supply: cpcap-battery: use device_get_match_data() to simplify code
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>
2021-10-02 17:58:38 +02:00
Henrik Grimler
d0c27c9211 power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty
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>
2021-10-02 17:49:11 +02:00
Henrik Grimler
223a3b8283 power: supply: max17042_battery: use VFSOC for capacity when no rsns
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>
2021-10-02 17:49:08 +02:00
Claudiu Beznea
f558c8072c power: reset: at91-reset: check properly the return value of devm_of_iomap
devm_of_iomap() returns error code or valid pointer. Check its return
value with IS_ERR().

Fixes: bd3127733f ("power: reset: at91-reset: use devm_of_iomap")
Reported-by: Cristian Birsan <cristian.birsan@microchip.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-10-02 17:40:34 +02:00
Colin Ian King
73d59c9263 power: supply: wm831x_power: fix spelling mistake on function name
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>
2021-10-02 17:31:15 +02:00
Geert Uytterhoeven
5ce39985c6 power: supply: core: Move psy_has_property() to fix build
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>
2021-09-30 12:48:36 +02:00
Matthias Kaehlcke
9ba533eb99 power: supply: core: Add psy_has_property()
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>
2021-09-27 16:21:40 +02:00
Thomas Gleixner
067930724e power: reset: ltc2952: Use hrtimer_forward_now()
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>
2021-09-24 23:35:11 +02:00
Krzysztof Kozlowski
40a2d98c97 power: supply: max17042: extend help/description
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>
2021-09-24 23:33:24 +02:00
Krzysztof Kozlowski
82ab575eb8 power: supply: max17040: extend help/description
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>
2021-09-24 23:33:05 +02:00
Linus Torvalds
4520dcbe0d power supply and reset changes for the v5.15 series
battery/charger related changes:
  - cros-peripheral-charger: new driver
  - mt6360-charger: new driver
  - simple-battery: support reading chemistry info
  - max17042-battery: add max77849 support
  - sbs-battery: add time_to_empty_now support
  - smb347-charger: prepare USB OTG support
  - rn5t618: add voltage_now support
  - axp288: cleanup & optimizations
  - max17042_battery: cleanups
  - ab8500: cleanups
  - misc minor cleanups and DT binding fixes
 
 reset related changes:
  - tps65086-restart: new driver
  - linkstation-poweroff: support NETGEAR ReadyNAS Duo v2
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmEmUVwACgkQ2O7X88g7
 +poFbA//XimqwjO0MR7xqmm2905l78L3L1cNn7vRPzfdPbcf/kKPg8Jrx8kTn1EK
 wKdbP4ZQJOIyCLIFcI6oURUaNHh485KXj4DFvT13AsbkPw+2xUv0Ha5p8J698QAG
 RPmkTNHk+0M/K+/Z7/GPb6t0B7uQi3cg7/aIZeFo26FYpIP5XekoxP1xoLfE9lO2
 aSrSbDh8oIjOLFPc4nuzm0x4Bcg/MpbUG1nhTBdP8OD8xjuMSmDUnbEvLgQYv4oP
 9PLbi4jxm0VSfFhdECCSZ+x7CO0+wqxLXWCoOGlzDQ1Y2OYp9nG+Xgsj46HGh38c
 11WER/16J7AfzUg1zqfu7NKDOKWad+TsTvQgXVK4GAxDOxpOS8Hz7GuP0/nnZBLx
 PoDAb7ZBtb6QXJDEvCDWoo+yMcZRaULbefQCgR/ys6bWoL+B6wdowxfV/daFGpmx
 fAMDGoSGrmYJhbPkcfAVJrN196zd5EQzbB6pyOfAPu3lJiDz+M/DyPNYwkljagAx
 JzSK80cwtXk07lgZZvC8Z3MJruN5pqqvWX/TA8l7dHpReoguCM3hAPUJ9pdVoIa7
 haavL0UzLwya9C2sK9hcys8EBim5thkXI6GsnpRxiztkXZh0LtsUP9Dydt2srGA6
 Hl4BD/g23W9+zmjkAIAvgMwbBoZ2/SHkD7l3ZqG2N2j6LrQxpwc=
 =UcdD
 -----END PGP SIGNATURE-----

Merge tag 'for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:
 "Battery/charger related:
   - cros-peripheral-charger: new driver
   - mt6360-charger: new driver
   - simple-battery: support reading chemistry info
   - max17042-battery: add max77849 support
   - sbs-battery: add time_to_empty_now support
   - smb347-charger: prepare USB OTG support
   - rn5t618: add voltage_now support
   - axp288: cleanup & optimizations
   - max17042_battery: cleanups
   - ab8500: cleanups
   - misc minor cleanups and DT binding fixes

  reset related:
   - tps65086-restart: new driver
   - linkstation-poweroff: support NETGEAR ReadyNAS Duo v2"

* tag 'for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (51 commits)
  power: supply: core: Fix parsing of battery chemistry/technology
  power: supply: max17042_battery: log SOC threshold using debug log level
  power: supply: max17042_battery: more robust chip type checks
  power: supply: max17042_battery: fix typo in MAx17042_TOFF
  power: supply: max17042_battery: clean up MAX17055_V_empty
  power: supply: smb347-charger: Implement USB VBUS regulator
  power: supply: smb347-charger: Add missing pin control activation
  power: supply: smb347-charger: Utilize generic regmap caching
  power: supply: smb347-charger: Make smb347_set_writable() IRQ-safe
  dt-bindings: power: supply: smb347-charger: Document USB VBUS regulator
  power: reset: Add TPS65086 restart driver
  dt-bindings: power: supply: max17042: describe interrupt
  power: supply: max17042: remove duplicated STATUS bit defines
  power: supply: max17042: handle fails of reading status register
  power: supply: core: Parse battery chemistry/technology
  dt-bindings: power: Extend battery bindings with chemistry
  power: reset: linkstation-poweroff: add new device
  power: reset: linkstation-poweroff: prepare for new devices
  power: supply: bq24735: reorganize ChargeOption command macros
  power: supply: rn5t618: Add voltage_now property
  ...
2021-08-30 11:47:32 -07:00
Dmitry Osipenko
c9398455b0 power: supply: core: Fix parsing of battery chemistry/technology
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>
2021-08-20 18:57:56 +02:00
Sebastian Krzyszkowiak
eaa2c49051 power: supply: max17042_battery: log SOC threshold using debug log level
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>
2021-08-17 15:33:52 +02:00
Sebastian Krzyszkowiak
4bf00434a6 power: supply: max17042_battery: more robust chip type checks
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>
2021-08-17 15:33:52 +02:00
Sebastian Krzyszkowiak
ed0d0a0506 power: supply: max17042_battery: fix typo in MAx17042_TOFF
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-17 15:33:52 +02:00
Sebastian Krzyszkowiak
1e4f30eaf4 power: supply: max17042_battery: clean up MAX17055_V_empty
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>
2021-08-17 15:33:52 +02:00
Dmitry Osipenko
565efae96c power: supply: smb347-charger: Implement USB VBUS regulator
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>
2021-08-16 17:57:10 +02:00
Dmitry Osipenko
efe2175478 power: supply: smb347-charger: Add missing pin control activation
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>
2021-08-16 17:57:02 +02:00
Dmitry Osipenko
17e7bc532c power: supply: smb347-charger: Utilize generic regmap caching
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>
2021-08-16 17:56:58 +02:00
Dmitry Osipenko
4ac59d85a2 power: supply: smb347-charger: Make smb347_set_writable() IRQ-safe
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>
2021-08-16 17:56:50 +02:00
Emil Renner Berthing
80698507e0 power: reset: Add TPS65086 restart driver
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>
2021-08-16 14:48:51 +02:00
Krzysztof Kozlowski
22b6907caf power: supply: max17042: remove duplicated STATUS bit defines
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>
2021-08-16 13:05:32 +02:00
Krzysztof Kozlowski
54784ffa5b power: supply: max17042: handle fails of reading status register
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>
2021-08-16 13:05:06 +02:00
Linus Walleij
4eef766b7d power: supply: core: Parse battery chemistry/technology
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>
2021-08-14 12:48:07 +02:00
Pawel Dembicki
0c77ec3da8 power: reset: linkstation-poweroff: add new device
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>
2021-08-13 19:16:41 +02:00
Pawel Dembicki
e2f471efe1 power: reset: linkstation-poweroff: prepare for new devices
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>
2021-08-13 19:12:26 +02:00
Sebastian Reichel
ecdf7e7a1d 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>
 -----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>
2021-08-13 18:50:16 +02:00
Bruno Meneguele
27a8ff4648 power: supply: bq24735: reorganize ChargeOption command macros
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>
2021-08-13 18:38:17 +02:00
Andreas Kemnade
2f5caa26a0 power: supply: rn5t618: Add voltage_now property
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>
2021-08-13 18:38:17 +02:00
Gene Chen
0402e8ebb8 power: supply: mt6360_charger: add MT6360 charger support
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>
2021-08-13 18:37:49 +02:00
Colin Ian King
3833423196 power: supply: ab8500: clean up warnings found by checkpatch
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>
2021-08-13 17:21:57 +02:00
Tang Bin
c02aa89b74 power: supply: axp288_charger: Use the defined variable to clean code
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>
2021-08-13 16:31:02 +02:00
Matthias Schiffer
6ea0126631 power: supply: sbs-battery: add support for time_to_empty_now attribute
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>
2021-08-06 23:48:51 +02:00
Matthias Schiffer
e11544d0cd power: supply: sbs-battery: relax voltage limit
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>
2021-08-06 23:48:51 +02:00
Tang Bin
391719dce5 power: supply: qcom_smbb: Remove superfluous error message
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>
2021-08-06 23:36:12 +02:00
Nikita Travkin
4415e4cea4 power: supply: max17042_battery: Add support for MAX77849 Fuel-Gauge
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>
2021-08-06 23:23:49 +02:00
Hans de Goede
213e19d659 power: supply: axp288_fuel_gauge: Take the P-Unit semaphore only once during probe()
The I2C-bus to the XPower AXP288 is shared between the Linux kernel and
the 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 and this is a quite expensive operation.

Explicitly take the semaphore in probe() around the register-accesses
done during probe, so that this only needs to be done once, rather then
once per register-access.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
964b3e9b02 power: supply: axp288_fuel_gauge: Move the AXP20X_CC_CTRL check together with the other checks
The I2C-bus to the XPower AXP288 is shared between the Linux kernel and
the 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.

Move the AXP20X_CC_CTRL check done in probe() together with the other
register-accesses done in probe, so that we can take the semaphore once
for the entire set of register-accesses.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Andrejus Basovas
394088f0b0 power: supply: axp288_fuel_gauge: Refresh all registers in one go
The I2C-bus to the XPower AXP288 is shared between the Linux kernel and
the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock"
before it may use the bus and while the kernel holds the semaphore the CPU
and GPU power-states must not be changed otherwise the system will freeze.

This is a complex process, which is quite expensive. This is all done by
iosf_mbi_block_punit_i2c_access(). To ensure that no unguarded I2C-bus
accesses happen, iosf_mbi_block_punit_i2c_access() gets called by the
I2C-bus-driver for every I2C transfer. Because this is so expensive it
is allowed to call iosf_mbi_block_punit_i2c_access() in a nested
fashion, so that higher-level code which does multiple I2C-transfers can
call it once for a group of transfers, turning the calls done by the
I2C-bus-driver into no-ops.

Userspace power-supply API users typically will read all provided
properties in one go, refreshing the last read values when
power_supply_changed() is called by the driver and/or periodically
(e.g. every 2 minutes).

The reading of all properties in one go causes the P-Unit semaphore
to quickly be taken and released multiple times in a row. Certain
PMIC registers like AXP20X_FG_RES are even used in multiple properties
so they get read multiple times, leading to a P-Unit take + release
each time the register is read.

As already mentioned the taking of the P-Unit semaphore is a quite
expensive operation and it has also been reported that the
"hammering" of the P-Unit semaphore done by the axp288_fuel_gauge
driver can even cause stability issues with the system as a whole.

Switch over to a scheme where the axp288_fuel_gauge driver keeps
a local copy of all the registers which it uses for properties
and make it only refresh its copy of the registers if the values
are older then 1 minute; or when a fuel-gauge interrupt has
triggered since the last read.

This not only reduces the amount of reads, it also makes the code
do all the reads in one go, rather then reading specific registers
based on which property is being queried. This allows calling
iosf_mbi_block_punit_i2c_access() once before doing all the reads,
so that we now only take the P-Unit semaphore once per update.

Tested-by: Andrejus Basovas <cpp@gcc.lt>
Signed-off-by: Andrejus Basovas <cpp@gcc.lt>
Co-developed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
c371d4491b power: supply: axp288_fuel_gauge: Only read PWR_OP_MODE, FG_LOW_CAP_REG regs once
Accessing registers on the AXP288 is quite expensive, so we should avoid
doing unnecessary accesses.

The FG_LOW_CAP_REG never changes underneath us, so we only need to read
it once. Devices with an AXP288 do not have user-replace (let alone
hot-swappable) batteries and the only bit we care about in the
PWR_OP_MODE register is the CHRG_STAT_BAT_PRESENT bit, so we can get
away with only reading the PWR_OP_MODE register once too.

Note that the FG_LOW_CAP_REG is not marked volatile in the regmap, so we
were effectively already reading it once. This change makes this explicit,
this is done as preparation of a further patch which moves all remaining
register accesses in fuel_gauge_get_property() out of that function.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
7eef3e6638 power: supply: axp288_fuel_gauge: Store struct device pointer in axp288_fg_info
Directly store the struct device pointer in axp288_fg_info, rather then
storing a pointer to the struct platform_device there and then using
"&info->pdev->dev" everywhere.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
f17bda7f65 power: supply: axp288_fuel_gauge: Drop retry logic from fuel_gauge_reg_readb()
The I2C-bus to the XPower AXP288 is shared between the Linux kernel and
the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock"
before it may use the bus. This semaphore is automatically taken by the
I2C-bus-driver.

The retry on -EBUSY logic in fuel_gauge_reg_readb() likely was added to
deal with the I2C-bus-drive returning -EBUSY when it failed to take the
semaphore, but this really should never happen. The semaphore code even
has a WARN_ON(ret) to log a kernel backtrace if this does somehow happen,
when this happens something is seriously wrong and the system typically
freezes soon afterwards.

TL;DR: the regmap_read() should never fail with -EBUSY so the retries
are unnecessary.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
caa534c3ba power: supply: axp288_fuel_gauge: Report register-address on readb / writeb errors
When fuel_gauge_reg_readb()/_writeb() fails, report which register we
were trying to read / write when the error happened.

Also reword the message a bit:
- Drop the axp288 prefix, dev_err() already prints this
- Switch from telegram / abbreviated style to a normal sentence, aligning
  the message with those from fuel_gauge_read_*bit_word()

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
8f6cc48e1a power: supply: axp288_fuel_gauge: Silence the chatty IRQ mapping code
Drop the IRQ mapping messages, because they are really not
interesting at all.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
fc0db6556c power: supply: axp288_fuel_gauge: Remove debugfs support
The debugfs code is simply just dumping a bunch of registers, the same
information can also easily be gotten through the regmap debugfs
interface or through the i2cdump utility.

I've not used the debugfs interface once in all these years that I've
been working on the axp288_fuel_gauge driver, so lets just remove it.

Note this also removes the temperature-channels from the list of
IIO ADC channels used by the driver, since these were only used in the
debugfs interface.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Hans de Goede
f9ac97307b power: supply: axp288_fuel_gauge: Fix define alignment
The values of various defines used in the driver are not aligned
properly when tabsize is set to 8 (I guess they were created with
a different tabsize).

Properly align the defines to make the code easier to read.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 18:54:52 +02:00
Tang Bin
daaca3156d power: supply: sc27xx: Delete superfluous error message
In the function sc27xx_fgu_probe(), when get irq failed,
platform_get_irq() logs an error message, so remove
redundant message here.

Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05 17:57:25 +02:00
Peter Robinson
ad1abe4769 power: supply: cw2015: use dev_err_probe to allow deferred probe
Deal with deferred probe using dev_err_probe so the error is handled
and avoid logging lots probe defer information like the following:

[    9.125121] cw2015 4-0062: Failed to register power supply
[    9.211131] cw2015 4-0062: Failed to register power supply

Fixes: b4c7715c10 ("power: supply: add CellWise cw2015 fuel gauge driver")
Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 16:00:35 +02:00
Daisuke Nojiri
56d629af09 power: supply: PCHG: Peripheral device charger
This patch adds a driver for PCHG (Peripheral CHarGer). PCHG is a
framework managing power supplies for peripheral devices.

This driver creates a sysfs node for each peripheral charge port:

	/sys/class/power_supply/peripheral<n>

where <n> is the index of a charge port.

For example, when a stylus is connected to a NFC/WLC port, the node
returns:

	/sys/class/power_supply/peripheral0/
		capacity=50
		charge_type=Standard
		scope=Device
		status=Charging
		type=Battery

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 15:54:34 +02:00
Linus Walleij
5176a18bb5 power: supply: ab8500: Drop some includes from bmdata
This file isn't using any AB8500 symbols so drop these includes.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 15:14:30 +02:00
Linus Walleij
661d10ee0f power: supply: ab8500: Rename charging algorithm psy
If we rename the "abx500_chargalg" supply to "ab8500_chargalg"
as it should be named, the existing supplies are supplying that
supply but that was obviously not working since it had the
wrong name.

Now that the dependency kicks in we get a bunch
of NULL references from ab8500_chargalg_external_power_changed()
so check that the workqueue is allocated before we try to
queue work on it.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 15:14:30 +02:00
Linus Walleij
484a9cc3dc power: supply: ab8500: Drop abx500 concept
Drop the entire idea with abx500 being abstract and different from ab8500
in the AB8500 charging drivers. This rids the two identical definitions
of a slew of structs in ab8500-bm.h and makes things less confusion and
easier to understand.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 15:14:30 +02:00
Linus Walleij
c5b64a990e power: supply: ab8500: Rename charging algorithm symbols
The "abx500" name on the charging algorithm stems from the ambition
to produce a series of these analog basebands, re-using the same
charging algorithm driver. No ASICs beside AB8500 and AB8505 were
ever produced so this terminology is confusing. Rename the
algorithm file and symbols to reflect the more narrow scope.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 15:14:30 +02:00
Linus Walleij
f820547446 power: supply: ab8500: Use library interpolation
The kernel already has a static inline for linear interpolation
so use that instead of rolling our own.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16 15:14:30 +02:00
Gustavo A. R. Silva
b51883d47d power: supply: Fix fall-through warnings for Clang
Fix the following fallthrough warnings:

drivers/power/supply/ab8500_fg.c:1730:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
drivers/power/supply/abx500_chargalg.c:1155:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]

Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2021-07-13 14:50:47 -05:00
Linus Torvalds
c6e8c51f69 power supply and reset changes for the v5.14 series
battery/charger driver changes:
  * convert charger-manager binding to YAML
  * drop bd70528-charger driver
  * drop pm2301-charger driver
  * introduce rt5033-battery driver
  * misc. improvements and fixes
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmDdZH0ACgkQ2O7X88g7
 +pqLpxAAixSqw2UrKCipLUaWWH1vanwPeU78z8XEzpHdNayrTR9PujBMhWH+ps+R
 IgHNjsQuJsnvbedWfmzkgjrZe5amAuN6Va8OkVDSVzEY+RZvLmXfj9POC5d4LmNK
 wpIBM/Okjie097j3ZWz7CJp47rsQnkS9EvRY4FevNjz1zt1VSpQNyDHAjemsn+j9
 1F9BnBMr2gzgTMxLDIloa71VMEaA8cZlAWulIKwxaN5FaSwoacK0NfestjM1R/Bc
 Z50pfqzAXBrofm14WKQRIgSEkf9zM6S1AjHG/y4b/C69XbzmBJxn+FK1F+yukWfN
 Kiq1kGvE9zWqOrDYPd7LxYDetTJ9JgNDxMreLIP7N+syurFYizl7v0JU9TL6BKsh
 EXCklOx/xaCs0Y3a3kBH8dJ72MBppW1loE0XbAqhkMDkzQybTxg9xUI1gnhVTIlb
 5b6KbU5kUo4AghJ279zSNxYNHABKxyu/WCZKNafsLT9pC41muGIPT8ZNgAs2Z3fG
 V60RSiAFpRrHU7efuizbXYchLEv+vWJG7kfdWmHWawMIqE11cUHgMIjFvkv/41t/
 zD3ZnlvvQe/ZZFO16aasvpj99BsZkI5tmNjmVnfPc2cOsLw/HFHIObSe+7x2PpVe
 7peflSz6DHL48NAsoq71WxeoPVPm3YYMMA9kr4tt9ZnVBbLJaCM=
 =EFOr
 -----END PGP SIGNATURE-----

Merge tag 'for-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:
 "Battery/charger driver changes:

   - convert charger-manager binding to YAML

   - drop bd70528-charger driver

   - drop pm2301-charger driver

   - introduce rt5033-battery driver

   - misc improvements and fixes"

* tag 'for-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (42 commits)
  power: supply: ab8500: Fix an old bug
  power: supply: axp288_fuel_gauge: remove redundant continue statement
  power: supply: axp288_fuel_gauge: Make "T3 MRD" no_battery_list DMI entry more generic
  power: supply: axp288_fuel_gauge: Rename fuel_gauge_blacklist to no_battery_list
  power: supply: bq24190_charger: drop of_match_ptr() from device ID table
  drivers: power: add missing MODULE_DEVICE_TABLE in keystone-reset.c
  power: supply: ab8500: add missing MODULE_DEVICE_TABLE
  power: supply: charger-manager: add missing MODULE_DEVICE_TABLE
  power: reset: regulator-poweroff: add missing MODULE_DEVICE_TABLE
  power: supply: cpcap-charger: get the battery inserted infomation from cpcap-battery
  power: supply: cpcap-battery: invalidate config when incompatible measurements are read
  power: supply: axp20x_battery: allow disabling battery charging
  power: supply: max17040: drop unused platform data support
  power: supply: max17040: simplify POWER_SUPPLY_PROP_ONLINE
  power: supply: max17040: remove non-working POWER_SUPPLY_PROP_STATUS
  power: reset: at91-sama5d2_shdwc: Remove redundant error printing in at91_shdwc_probe()
  power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE
  power: supply: rt5033_battery: Fix device tree enumeration
  dt-bindings: power: supply: Add DT schema for richtek,rt5033-battery
  power: supply: Drop BD70528 support
  ...
2021-07-07 13:17:48 -07:00
Andy Shevchenko
f39650de68 kernel.h: split out panic and oops helpers
kernel.h is being used as a dump for all kinds of stuff for a long time.
Here is the attempt to start cleaning it up by splitting out panic and
oops helpers.

There are several purposes of doing this:
- dropping dependency in bug.h
- dropping a loop by moving out panic_notifier.h
- unload kernel.h from something which has its own domain

At the same time convert users tree-wide to use new headers, although for
the time being include new header back to kernel.h to avoid twisted
indirected includes for existing users.

[akpm@linux-foundation.org: thread_info.h needs limits.h]
[andriy.shevchenko@linux.intel.com: ia64 fix]
  Link: https://lkml.kernel.org/r/20210520130557.55277-1-andriy.shevchenko@linux.intel.com

Link: https://lkml.kernel.org/r/20210511074137.33666-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Co-developed-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Wei Liu <wei.liu@kernel.org>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Sebastian Reichel <sre@kernel.org>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Stephen Boyd <sboyd@kernel.org>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-07-01 11:06:04 -07:00
Linus Walleij
f1c74a6c07 power: supply: ab8500: Fix an old bug
Trying to get the AB8500 charging driver working I ran into a bit
of bitrot: we haven't used the driver for a while so errors in
refactorings won't be noticed.

This one is pretty self evident: use argument to the macro or we
end up with a random pointer to something else.

Cc: stable@vger.kernel.org
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Marcus Cooper <codekipper@gmail.com>
Fixes: 297d716f62 ("power_supply: Change ownership from driver to core")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:14:55 +02:00
Colin Ian King
f390e4bd79 power: supply: axp288_fuel_gauge: remove redundant continue statement
The continue statement at the end of a for-loop has no effect,
invert the if expression and remove the continue.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:10:26 +02:00
Hans de Goede
3a06b912a5 power: supply: axp288_fuel_gauge: Make "T3 MRD" no_battery_list DMI entry more generic
It turns out that the "T3 MRD" DMI_BOARD_NAME value is used in a lot of
different Cherry Trail x5-z8300 / x5-z8350 based Mini-PC / HDMI-stick
models from Ace PC / Meegopad / MinisForum / Wintel (and likely also
other vendors).

Most of the other DMI strings on these boxes unfortunately contain various
generic values like "Default string" or "$(DEFAULT_STRING)", so we cannot
match on them. These devices do have their chassis-type correctly set to a
value of "3" (desktop) which is a pleasant surprise, so also match on that.

This should avoid the quirk accidentally also getting applied to laptops /
tablets (which do actually have a battery). Although in my quite large
database of Bay and Cherry Trail based devices DMIdecode dumps I don't
have any laptops / tables with a board-name of "T3 MRD", so this should
not be an issue.

BugLink: https://askubuntu.com/questions/1206714/how-can-a-mini-pc-be-stopped-from-being-detected-as-a-laptop-with-a-battery/
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:08:52 +02:00
Hans de Goede
0973e96b4b power: supply: axp288_fuel_gauge: Rename fuel_gauge_blacklist to no_battery_list
As documented in the updated "Naming" chapter of
Documentation/process/coding-style.rst, usage of the work blacklist
should be avoided where possible.

Rename the list of devices which have no battery to the
axp288_no_battery_list, which also more accurately describes the
contents of the list.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:08:52 +02:00
Andy Shevchenko
df6f3f7eb7 power: supply: bq24190_charger: drop of_match_ptr() from device ID table
The driver can match only via the DT table so the table should be always
used and the of_match_ptr() does not have any sense (this also allows ACPI
matching via PRP0001, even though it might be not relevant here). This
fixes compile warning (!CONFIG_OF):

  drivers/power/supply/bq24190_charger.c:1972:34: warning: ‘bq24190_of_match’ defined but not used [-Wunused-const-variable=]

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:07:34 +02:00
Yu Jiahua
30e677a2ba drivers: power: add missing MODULE_DEVICE_TABLE in keystone-reset.c
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Signed-off-by: Yu Jiahua <yujiahua1@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:06:37 +02:00
Zou Wei
dfe52db13a power: supply: ab8500: add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30 00:00:01 +02:00
Zou Wei
073b5d5b1f power: supply: charger-manager: add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-29 23:57:10 +02:00
Zou Wei
4465b3a621 power: reset: regulator-poweroff: add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-29 23:55:12 +02:00
Sebastian Reichel
2fc6d0ec54 Merge branch 'psy-fixes' into psy-next 2021-06-29 22:38:37 +02:00
Carl Philipp Klemm
eab4e6d953 power: supply: cpcap-charger: get the battery inserted infomation from cpcap-battery
This avoids reimplementing the detection logic twice and removes the
possibility of activating charging with 500mA even if a battery is not
detected.

Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 14:36:17 +02:00
Carl Philipp Klemm
aecd127b45 power: supply: cpcap-battery: invalidate config when incompatible measurements are read
This invalidates empty->counter_uah and charge_full when charge_now
indicates that they are grossly wrong and adds some tolerance to
POWER_SUPPLY_PROP_CHARGE_FULL to allow for inaccuracies in the charge
counter and manufacturing tolerances in the battery.

Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 14:28:31 +02:00
Hermann Lauer
6a0fcc87c9 power: supply: axp20x_battery: allow disabling battery charging
Allow disabling and re-enabling battery charging of an axp209 PMIC
through a writable status property. With the current driver code
charging is always on.

This works on the axp209 of Banana {Pi M1+,Pro} and should work on all
AXP chips.

Signed-off-by: Hermann.Lauer@uni-heidelberg.de
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 14:12:42 +02:00
Krzysztof Kozlowski
cd70c85c57 power: supply: max17040: drop unused platform data support
There are no platforms using the driver with platform data (no board
files with the driver), so the dead code can be dropped.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 13:11:37 +02:00
Krzysztof Kozlowski
ce0ae8324e power: supply: max17040: simplify POWER_SUPPLY_PROP_ONLINE
The driver was reporting POWER_SUPPLY_PROP_ONLINE via platform data
functions or '1' if no platform data was provided.  Since there are no
platforms using the driver with platform data (no board files with the
driver), the online property can be simplified to always return '1'.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 13:11:37 +02:00
Krzysztof Kozlowski
c603bec359 power: supply: max17040: remove non-working POWER_SUPPLY_PROP_STATUS
The driver was reporting POWER_SUPPLY_PROP_STATUS via platform data
functions.  Without platform data, the max17040_get_status() functions
returns early with POWER_SUPPLY_STATUS_UNKNOWN.  Since there are no
platforms using the driver with platform data (no board files with the
driver), the status property was always unknown.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 13:11:37 +02:00
Zhen Lei
8ef9f687ab power: reset: at91-sama5d2_shdwc: Remove redundant error printing in at91_shdwc_probe()
When devm_ioremap_resource() fails, a clear enough error message will be
printed by its subfunction __devm_ioremap_resource(). The error
information contains the device name, failure cause, and possibly resource
information.

Therefore, remove the error printing here to simplify code and reduce the
binary size.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 13:04:01 +02:00
Bixuan Cui
ed3443fb4d power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Bixuan Cui <cuibixuan@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 12:58:30 +02:00
Stephan Gerhold
f3076cd8d1 power: supply: rt5033_battery: Fix device tree enumeration
The fuel gauge in the RT5033 PMIC has its own I2C bus and interrupt
line. Therefore, it is not actually part of the RT5033 MFD and needs
its own of_match_table to probe properly.

Also, given that it's independent of the MFD, there is actually
no need to make the Kconfig depend on MFD_RT5033. Although the driver
uses the shared <linux/mfd/rt5033.h> header, there is no compile
or runtime dependency on the RT5033 MFD driver.

Cc: Beomho Seo <beomho.seo@samsung.com>
Cc: Chanwoo Choi <cw00.choi@samsung.com>
Fixes: b847dd96e6 ("power: rt5033_battery: Add RT5033 Fuel gauge device driver")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 12:30:50 +02:00
Matti Vaittinen
4b53bdd53a power: supply: Drop BD70528 support
The only known BD70528 use-cases are such that the PMIC is controlled
from separate MCU which is not running Linux. I am not aware of
any Linux driver users. Furthermore, it seems there is no demand for
this IC. Let's ease the maintenance burden and drop the driver. We can
always add it back if there is sudden need for it.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 12:02:12 +02:00
Krzysztof Kozlowski
8bb2314fc2 power: supply: max17040: Do not enforce (incorrect) interrupt trigger type
Interrupt line can be configured on different hardware in different way,
even inverted.  Therefore driver should not enforce specific trigger
type - edge falling - but instead rely on Devicetree to configure it.

The Maxim 14577/77836 datasheets describe the interrupt line as active
low with a requirement of acknowledge from the CPU therefore the edge
falling is not correct.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Acked-by: Iskren Chernev <iskren.chernev@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 11:58:22 +02:00
Krzysztof Kozlowski
7fbf6b731b power: supply: max17042: Do not enforce (incorrect) interrupt trigger type
Interrupt line can be configured on different hardware in different way,
even inverted.  Therefore driver should not enforce specific trigger
type - edge falling - but instead rely on Devicetree to configure it.

The Maxim 17047/77693 datasheets describe the interrupt line as active
low with a requirement of acknowledge from the CPU therefore the edge
falling is not correct.

The interrupt line is shared between PMIC and RTC driver, so using level
sensitive interrupt is here especially important to avoid races.  With
an edge configuration in case if first PMIC signals interrupt followed
shortly after by the RTC, the interrupt might not be yet cleared/acked
thus the second one would not be noticed.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-04 11:58:22 +02:00
Maximilian Luz
601423bc0c power: supply: surface-charger: Fix type of integer variable
The ac->state field is __le32, not u32. So change the variable we're
temporarily storing it in to __le32 as well.

Reported-by: kernel test robot <lkp@intel.com>
Fixes: e61ffb3445 ("power: supply: Add AC driver for Surface Aggregator Module")
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 20:53:54 +02:00
Ikjoon Jang
b49a81d0fd power: supply: sbs-battery: cache constant string properties
Currently sbs-battery supports three string properties -
manufacturer, model_name, and chemistry. Buffers for those
properties are currently defined as global variables.

This patch moves those global variables into struct sbs_info
and cache/reuse them as they are all constant values.

Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 19:49:58 +02:00
Andreas Kemnade
20a3c8b57b power: supply: rn5t618: Add input current limit
Adds properties for setting the maximum current to USB, ADP and Battery
supplies. USB and ADP limits are reset to OTP values upon replugging.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 19:31:23 +02:00
Andreas Kemnade
7d76367774 power: supply: rn5t618: Add charger type detection
The RC5T619 can detect SDP, CDP and DCP chargers, so let's add support
for it.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 19:31:23 +02:00
Linus Walleij
3ee236296a power: supply: smb347-charger: Drop unused include
This driver is including the legacy GPIO header <linux/gpio.h>
but not using any symbols from it. Delete the include.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Acked-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 19:01:44 +02:00
Linus Walleij
aa8c8bf64b power: supply: pm2301_charger: Delete driver
The PM2301 was only used in tandem with AB9540, part of U9540,
a platform that was cancelled and never deployed in products.
Delete it.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 19:01:40 +02:00
Guenter Roeck
e2bfc28afa power: supply: ab8500: Drop unnecessary NULL check after container_of
The result of container_of() operations is never NULL unless the element
is the first element of the embedded structure, which is not the case here.
The NULL check is therefore unnecessary and misleading. Remove it.

This change was made automatically with the following Coccinelle script.

@@
type t;
identifier v;
statement s;
@@

<+...
(
  t v = container_of(...);
|
  v = container_of(...);
)
  ...
  when != v
- if (\( !v \| v == NULL \) ) s
...+>

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:50:45 +02:00
Linus Walleij
9c2b682610 power: supply: ab8500: Drop unused member
This setting is read directly from the device tree in
the ab8500_charger.c code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:40:15 +02:00
Linus Walleij
f9184a228d power: supply: ab8500: Enable USB and AC
The vendor code tree supplies platform data to enable he
USB charging for AB8500 and AB8500 and disable the AC
charging on the AB8505. This was missed when the driver
was submitted to the mainline kernel.

Fix this by doing what the vendor kernel does: always
register the USB charger, do not register the AC charger
on the AB8505.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:40:15 +02:00
Linus Walleij
5bcb5087c9 power: supply: ab8500: Avoid NULL pointers
Sometimes the code will crash because we haven't enabled
AC or USB charging and thus not created the corresponding
psy device. Fix it by checking that it is there before
notifying.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:40:15 +02:00
Linus Walleij
7e2bb83c61 power: supply: ab8500: Call battery population once
The code was calling ab8500_bm_of_probe() in four different
spots effectively overwriting the same configuration three
times. This was done because probe order was uncertain.

Since we now used componentized probe, call it only once
while probing the main charging component.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:40:15 +02:00
Linus Walleij
1c1f13a006 power: supply: ab8500: Move to componentized binding
The driver has problems with the different components of
the charging code racing with each other to probe().

This results in all four subdrivers populating battery
information to ascertain that it is populated for their
own needs for example.

Fix this by using component probing and thus expressing
to the kernel that these are dependent components.
The probes can happen in any order and will only acquire
resources such as state container, regulators and
interrupts and initialize the data structures, but no
execution happens until the .bind() callback is called.

The charging driver is the main component and binds
first, then bind in order the three subcomponents:
ab8500-fg, ab8500-btemp and ab8500-chargalg.

Do some housekeeping while we are moving the code around.
Like use devm_* for IRQs so as to cut down on some
boilerplate.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:40:15 +02:00
Jian Xin
94233f11f8 power: supply: ab8500: Fix typo
fix misspelled 'interrupts'

Signed-off-by: Jian Xin <xinjian@yulong.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-03 18:40:10 +02:00
Maximilian Luz
e633f33d26 power: supply: surface_battery: Fix battery event handling
The battery subsystem of the Surface Aggregator Module EC requires us to
register the battery notifier with instance ID 0. However, battery
events are actually sent with the instance ID corresponding to the
device, which is nonzero. Thus, the strict-matching approach doesn't
work here and will discard events that the driver is expected to handle.

To fix this we have to fall back on notifier matching by target-category
only and have to manually check the instance ID in the notifier
callback.

Fixes: 167f77f7d0 ("power: supply: Add battery driver for Surface Aggregator Module")
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-05-13 18:26:07 +02:00
Zou Wei
2aac79d14d power: supply: sc2731_charger: Add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-05-13 18:24:22 +02:00
Zou Wei
603fcfb9d4 power: supply: sc27xx: Add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-05-13 18:24:22 +02:00