Commit graph

2881 commits

Author SHA1 Message Date
Linus Torvalds 0df241385b power supply and reset changes for the 6.5 series
* Add new Qualcomm PMI8998/PM660 SMB2 charger
 * bq256xx: support systems without thermistors
 * cros_pchg: fix peripheral device status after system resume
 * axp20x_usb_power: add support for AXP192
 * qcom-pon: add support for pm8941
 * at91-reset: prepare to expose reset reason to sysfs
 * switch all I2C drivers back to use .probe instead of .probe_new
 * convert some more DT bindings to YAML
 * misc. cleanups
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmSjPRsACgkQ2O7X88g7
 +ppEgw//SzE/6dgc5e2OG+qtHb2vnjUrmoz9w0/sGZuTVFhnvZ4ofpEyOrRR8/kV
 rUT6dqEPh3p/tHIyiLdcAG2JyA3QZ3G8rekdIUOj++vWn4S97FQsqBxwL/46D0om
 c7S+SDrCo/XKnJvRIiC8a+0HzAsjVUdaWdvzkEovrF5MRS1HeX4GXadaW/c6pdxN
 NfOZBR2F+JXHlC/nmBtpmQCJvikooz6DPvZd6Tiv9dlywOHNO7NSlcueuuhSofYp
 /j7BAXq/V+jEynNTPnaBwnO5aA1XPMpC/nOo4HuHjJbrHoXCt5bMhabA9bIlaplN
 9bilfxmqqfaMkpWQOhF8qmz+s496WELcmGqGBZXvNBgn/85qYTPxue4JVe1D7ldh
 TjvGUBZkVUwkce052BZrPZCUTYhlrTBJ/6xpuGeUrPa3C9ib8e9Wm6C13zI2vsJV
 EeVxgt79cNkdioZ0GfibQTg+bJ7oa8BtwWEk0UaC9jfaPQGfNum05FHRik1a+A7R
 vehaoIYiCCMaXuHSZoqqjEocdnxXQCNkViMuYNqhN5Bcb0YdlMF6r0T2fa4HND0Y
 CU8uCofqTc67/RazqCsIRHNXDi6cJOYmdnSc1q7pYCO9/KmoMdP0xIFPB2Mca7uI
 2rMooSE77ssYGc1gOW9GWuMNEdvJXNufJJzr5LLdMbhIh0ecy04=
 =9vtE
 -----END PGP SIGNATURE-----

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

Pull power supply and reset updates from Sebastian Reichel:

 - Add new Qualcomm PMI8998/PM660 SMB2 charger

 - bq256xx: support systems without thermistors

 - cros_pchg: fix peripheral device status after system resume

 - axp20x_usb_power: add support for AXP192

 - qcom-pon: add support for pm8941

 - at91-reset: prepare to expose reset reason to sysfs

 - switch all I2C drivers back to use .probe instead of .probe_new

 - convert some more DT bindings to YAML

 - misc cleanups

* tag 'for-v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (28 commits)
  MAINTAINERS: add documentation file for Microchip SAMA5D2 shutdown controller
  dt-bindings: power: reset: atmel,sama5d2-shdwc: convert to yaml
  dt-bindings: power: reset: atmel,at91sam9260-shdwc: convert to yaml
  power: reset: at91-reset: change the power on reason prototype
  power: reset: qcom-pon: add support for pm8941-pon
  dt-bindings: power: reset: qcom-pon: define pm8941-pon
  power: supply: add Qualcomm PMI8998 SMB2 Charger driver
  dt-bindings: power: supply: qcom,pmi8998-charger: add bindings for smb2 driver
  power: supply: rt9467: Make charger-enable control as logic level
  power: supply: Switch i2c drivers back to use .probe()
  power: reset: add HAS_IOPORT dependencies
  dt-bindings: power: supply: axp20x: Add AXP192 compatible
  power: supply: axp20x_usb_power: Add support for AXP192
  power: supply: axp20x_usb_power: Remove variant IDs from VBUS polling check
  power: supply: axp20x_usb_power: Use regmap field for VBUS disabling
  power: supply: axp20x_usb_power: Use regmap fields for USB BC feature
  power: supply: axp20x_usb_power: Use regmap fields for VBUS monitor feature
  power: supply: axp20x_usb_power: Simplify USB current limit handling
  power: supply: hwmon: constify pointers to hwmon_channel_info
  power: supply: twl4030_madc_battery: Refactor twl4030_madc_bat_ext_changed()
  ...
2023-07-03 17:23:16 -07:00
Linus Torvalds c156d4af43 - New Drivers
- Add support for Intel Cherry Trail Whiskey Cove PMIC LEDs
    - Add support for Awinic AW20036/AW20054/AW20072 LEDs
 
  - New Device Support
    - Add support for PMI632 LPG to QCom LPG
    - Add support for PMI8998 to QCom Flash
    - Add support for MT6331, WLEDs and MT6332 to Mediatek MT6323 PMIC
 
  - New Functionality
    - Implement the LP55xx Charge Pump
    - Add support for suspend / resume to Intel Cherry Trail Whiskey Cove PMIC
    - Add support for breathing mode to Intel Cherry Trail Whiskey Cove PMIC
    - Enable per-pin resolution Pinctrl in LEDs GPIO
 
  - Fix-ups
    - Allow thread to sleep by switching from spinlock to mutex
    - Add lots of Device Tree bindings / support
    - Adapt relationships / dependencies driven by Kconfig
    - Switch I2C drivers from .probe_new() to .probe()
    - Remove superfluous / duplicate code
    - Replace strlcpy() with strscpy() for efficiency and overflow prevention
    - Staticify various functions
    - Trivial: Fixing coding style
    - Simplify / reduce code
 
  - Bug Fixes
    - Prevent NETDEV_LED_MODE_LINKUP from being cleared on rename
    - Repair race between led_set_brightness(LED_{OFF,FULL})
    - Fix Oops relating to sleeping in critical sections
    - Clear LED_INIT_DEFAULT_TRIGGER flag when clearing the current trigger
    - Do not leak resources in error handling paths
    - Fix unsigned comparison which can never be negative
    - Provide missing NULL terminating entries in tables
    - Fix misnaming issues
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEdrbJNaO+IJqU8IdIUa+KL4f8d2EFAmSinb0ACgkQUa+KL4f8
 d2FYfg//WWLVfXRuRpY9ueOxvWj65WVPQSQ+wzF/vRTweogR+lN0qxNPH6yT943z
 ap2EBxpWf84zCifYG4yhTEYDHQT+nH1fIz6xaK29DK8sCQi4WdRpHuE2pE30R/tf
 Q7SyZi9DlWyoqNiqgNNCl7vkTaHpO3trxoxfEfN2YIB0npLf8yyWRz4feVXXsYtg
 41S4Mo7oTxphd7OLvw9PKogdTbT29vBMXen8jzv5g8FObj1Gheg0frq2t2W+bfAl
 27cJJJS7he4/WLCDzXVQfB46Nva5NpqHiANbgOAApDGx3hFCzZFTCg6K7+VucpjY
 bNz3pqmslT5uJxMjqNz8fCSzwWTjyKLHBeGsIT/4HBXD4DnfFbWz9HYkorfNgsu2
 lKEp0SYhSmmuS8IVzJvqDqXg6k21hGpuR9P+dI7teoClh0qLTMCz2L2c9p2zNfth
 0W+WeLYQ67QTRH9EcHo3dlZH/mP/J1jGmUDbF+DFI6bHsg2iahZUA6ixD18E7sWE
 RwtCnb3xyn7eoDe3LwJdKtJMyrX59MbFWqozij2NNhvduXc+m1kH/DX5CSaBUVwf
 RtfDZwWHf4qK4CipuuqOLd5fiUArJ3TSHBxXkoo0Wz7NYXK9k86eIZgWrgdEbvuA
 oHmSousS19Eiscjtzxl7OjvDJMRc0rTJfD7LzYoHQBL4Vpnd8VI=
 =9kd5
 -----END PGP SIGNATURE-----

Merge tag 'leds-next-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds

Pull LED updates from Lee Jones:
 "New Drivers:
   - Add support for Intel Cherry Trail Whiskey Cove PMIC LEDs
   - Add support for Awinic AW20036/AW20054/AW20072 LEDs

  New Device Support:
   - Add support for PMI632 LPG to QCom LPG
   - Add support for PMI8998 to QCom Flash
   - Add support for MT6331, WLEDs and MT6332 to Mediatek MT6323 PMIC

  New Functionality:
   - Implement the LP55xx Charge Pump
   - Add support for suspend / resume to Intel Cherry Trail Whiskey Cove PMIC
   - Add support for breathing mode to Intel Cherry Trail Whiskey Cove PMIC
   - Enable per-pin resolution Pinctrl in LEDs GPIO

  Fix-ups:
   - Allow thread to sleep by switching from spinlock to mutex
   - Add lots of Device Tree bindings / support
   - Adapt relationships / dependencies driven by Kconfig
   - Switch I2C drivers from .probe_new() to .probe()
   - Remove superfluous / duplicate code
   - Replace strlcpy() with strscpy() for efficiency and overflow prevention
   - Staticify various functions
   - Trivial: Fixing coding style
   - Simplify / reduce code

  Bug Fixes:
   - Prevent NETDEV_LED_MODE_LINKUP from being cleared on rename
   - Repair race between led_set_brightness(LED_{OFF,FULL})
   - Fix Oops relating to sleeping in critical sections
   - Clear LED_INIT_DEFAULT_TRIGGER flag when clearing the current trigger
   - Do not leak resources in error handling paths
   - Fix unsigned comparison which can never be negative
   - Provide missing NULL terminating entries in tables
   - Fix misnaming issues"

* tag 'leds-next-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds: (53 commits)
  leds: leds-mt6323: Adjust return/parameter types in wled get/set callbacks
  leds: sgm3140: Add richtek,rt5033-led compatible
  dt-bindings: leds: sgm3140: Document richtek,rt5033 compatible
  dt-bindings: backlight: kinetic,ktz8866: Add missing type for "current-num-sinks"
  dt-bindings: leds: Drop unneeded quotes
  leds: Fix config reference for AW200xx driver
  leds: leds-mt6323: Add support for WLEDs and MT6332
  leds: leds-mt6323: Add support for MT6331 leds
  leds: leds-mt6323: Open code and drop MT6323_CAL_HW_DUTY macro
  leds: leds-mt6323: Drop MT6323_ prefix from macros and defines
  leds: leds-mt6323: Specify registers and specs in platform data
  dt-bindings: leds: leds-mt6323: Document mt6332 compatible
  dt-bindings: leds: leds-mt6323: Document mt6331 compatible
  leds: simatic-ipc-leds-gpio: Introduce more Kconfig switches
  leds: simatic-ipc-leds-gpio: Split up into multiple drivers
  leds: simatic-ipc-leds-gpio: Move two extra gpio pins into another table
  leds: simatic-ipc-leds-gpio: Add terminating entries to gpio tables
  leds: flash: leds-qcom-flash: Fix an unsigned comparison which can never be negative
  leds: cht-wcove: Remove unneeded semicolon
  leds: cht-wcove: Fix an unsigned comparison which can never be negative
  ...
2023-07-03 11:26:05 -07:00
Linus Torvalds b8ec70ab66 - New Drivers
- Add support for TI TPS6594/TPS6593/LP8764 PMICs
    - Add support for Samsung RT5033 Battery Charger
    - Add support for Analog Devices MAX77540 and MAX77541 PMICs
 
  - New Device Support
    - Add support for SPI to Rockchip RK808 (and friends)
    - Add support for AXP192 PMIC to X-Powers AXP20X
    - Add support for AXP313a PMIC to X-Powers AXP20X
    - Add support for RK806 to Rockchip RK8XX
 
  - Removed Device Support
    - Removed MFD support for Richtek RT5033 Battery
 
  - Fix-ups
    - Remove superfluous code
    - Switch I2C drivers from .probe_new() to .probe()
    - Convert over to managed resources (devm_*(), etc)
    - Use dev_err_probe() for returning errors from .probe()
    - Add lots of Device Tree bindings / support
    - Improve cache efficiency by switching to Maple
    - Use own exported namespaces (NS)
    - Include missing and remove superfluous headers
    - Start using / convert to the new shutdown sys-off API
    - Trivial: variable / define renaming
    - Make use of of_property_read_reg() when requesting DT 'reg's
 
  - Bug Fixes
    - Fix chip revision readout due to incorrect data masking
    - Amend incorrect register and mask values used for charger state
    - Hide unused functionality at compile time
    - Fix resource leaks following error handling routines
    - Return correct error values and fix error handling in general
    - Repair incorrect device names - used for device matching
    - Remedy broken module auto-loading
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEdrbJNaO+IJqU8IdIUa+KL4f8d2EFAmSinHkACgkQUa+KL4f8
 d2Gj3A/9EimIwZKau8OeHCVue1mNrEVkVsCiWIZF1eHliufNbH0g3+9gzTB1yQfL
 PmE2tN+vxdHNPJKzPnrmEEdJpm+rV6RikUD3I1mVN0wPSXDmZPx9kYuJD8SmMtZo
 aDLQIMwqY0ZijGgAoVWmRtYo5praWSFvyutiD1yYEI4yAz/QcLoNvWjt3qb0H+fq
 Un1LYErrLxLar0GllzQa5lzoNEAoSBvO1TmS8z4Cm5uiU6Orahh2DlsE/Do40GSc
 5YYntAEsuJ1Bkg7JB+bxdU4BJnJskqzaasLIe3Fc4rXf6zdh/21EpmhpFGY+BS8s
 51f+NjViMwi+3uiBe5g8f/pIy6dIpkfvdukzbqDhDwqXnexftpy3+i99PJiWludR
 Xpr6s+g6zpxLAoKzHNA1jm5B3I0IPJEBoWe8jAalIcGIQBdjiF9UAkas3z9NTEoa
 8TrjW1Abxow1TB9ouT0kE7hvQk2UpYLEbNdDAByE4mM33d5AF7UpcEBrhmbFDA/E
 12q5EMoV9uXIzf+LS2TdYroo8SVYHufiIoiwU6QPJzWVVFJ3lrU3pA1Oe+aICMNu
 90EVDI1Ve37WTJfN9+FAlncaWF99AEqZwrES25QrKhMQO4w6LS35shlzTzpUcB4k
 q+upr81cWLz0t7fmjgn4yVa1CWzaQ19nylqXF/Nb4RP/6ZiP2Dw=
 =EmOj
 -----END PGP SIGNATURE-----

Merge tag 'mfd-next-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd

Pull MFD updates from Lee Jones:
 "New Drivers:
   - Add support for TI TPS6594/TPS6593/LP8764 PMICs
   - Add support for Samsung RT5033 Battery Charger
   - Add support for Analog Devices MAX77540 and MAX77541 PMICs

  New Device Support:
   - Add support for SPI to Rockchip RK808 (and friends)
   - Add support for AXP192 PMIC to X-Powers AXP20X
   - Add support for AXP313a PMIC to X-Powers AXP20X
   - Add support for RK806 to Rockchip RK8XX

  Removed Device Support:
   - Removed MFD support for Richtek RT5033 Battery

  Fix-ups:
   - Remove superfluous code
   - Switch I2C drivers from .probe_new() to .probe()
   - Convert over to managed resources (devm_*(), etc)
   - Use dev_err_probe() for returning errors from .probe()
   - Add lots of Device Tree bindings / support
   - Improve cache efficiency by switching to Maple
   - Use own exported namespaces (NS)
   - Include missing and remove superfluous headers
   - Start using / convert to the new shutdown sys-off API
   - Trivial: variable / define renaming
   - Make use of of_property_read_reg() when requesting DT 'reg's

  Bug Fixes:
   - Fix chip revision readout due to incorrect data masking
   - Amend incorrect register and mask values used for charger state
   - Hide unused functionality at compile time
   - Fix resource leaks following error handling routines
   - Return correct error values and fix error handling in general
   - Repair incorrect device names - used for device matching
   - Remedy broken module auto-loading"

* tag 'mfd-next-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (51 commits)
  dt-bindings: mfd: max77541: Add ADI MAX77541/MAX77540
  iio: adc: max77541: Add ADI MAX77541 ADC Support
  regulator: max77541: Add ADI MAX77541/MAX77540 Regulator Support
  dt-bindings: regulator: max77541: Add ADI MAX77541/MAX77540 Regulator
  mfd: Switch two more drivers back to use struct i2c_driver::probe
  dt-bindings: mfd: samsung,s5m8767: Simplify excluding properties
  mfd: stmpe: Only disable the regulators if they are enabled
  mfd: max77541: Add ADI MAX77541/MAX77540 PMIC Support
  dt-bindings: mfd: gateworks-gsc: Remove unnecessary fan-controller nodes
  mfd: core: Use of_property_read_reg() to parse "reg"
  mfd: stmfx: Nullify stmfx->vdd in case of error
  mfd: stmfx: Fix error path in stmfx_chip_init
  mfd: intel-lpss: Add missing check for platform_get_resource
  mfd: stpmic1: Add PMIC poweroff via sys-off handler
  mfd: stpmic1: Fixup main control register and bits naming
  dt-bindings: mfd: qcom,tcsr: Add the compatible for IPQ8074
  mfd: tps65219: Add support for soft shutdown via sys-off API
  mfd: pm8008: Drop bogus i2c module alias
  mfd: pm8008: Fix module autoloading
  mfd: tps65219: Add GPIO cell instance
  ...
2023-07-03 10:55:04 -07:00
Miquel Raynal cba266a4f6 power: reset: at91-reset: change the power on reason prototype
It is quite uncommon to use a driver helper with parameters like *pdev
and __iomem *base. It is much cleaner and close to today's standards to
provide the per-device driver structure and then access its
internals. Let's do this with the helper which returns the power on
reason. While we change the parameters, we can as well rename the
function from at91_reset_status() to at91_reset_reason() to be more
accurate with what the helper actually does, and finally because we don't
really need the pdev argument in this helper besides for printing the
reset reason, we can move the dev_info() call into the probe.

All these modifications prepare the introduction of a sysfs entry to
access this information. This way the diff will be much smaller. Thus,
there is no intended functional change.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-06-19 23:33:14 +02:00
Lee Jones 425f6a4576 Merge branches 'tb-mfd-clk-input-pinctrl-power-rtc-sound-6.5', 'ib-mfd-tps6594-core-6.5', 'ib-mfd-regulator-max5970-6.5', 'ib-mfd-regulator-6.5' and 'ib-mfd-power-6.5' into ibs-for-mfd-merged 2023-06-15 09:18:54 +01:00
Dmitry Baryshkov 4dea2fd6e8 power: reset: qcom-pon: add support for pm8941-pon
For PM8941 we don't have a defined field to store the reset reason.
Support wrapping pwrkey and resin, but without writing the reset
reason.

Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-06-09 21:18:17 +02:00
Caleb Connolly 8648aeb5d7 power: supply: add Qualcomm PMI8998 SMB2 Charger driver
Add a driver for the SMB2 charger block found in the Qualcomm PMI8998
and PM660.

This driver is capable of utilising Qualcomm's Automatic Power Source
Detection (APSD) BC1.2 implementation, as well as Automatic Input
Current Limiting (AICL) to configure the maximum input current
limit of DCP (wall) chargers.

Quick Charge is not currently supported.

Most devices using the smb2 charger have a secondary dedicated charger
chip which is used in parallel to enable faster charger without
overheating. However, not all do, as a result to ensure safety until
these are supported, the maximum current is limited to ~1A via the
FAST_CHARGE_CURRENT_CFG register.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
Tested-by: Joel Selvaraj <joelselvaraj.oss@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-06-09 01:20:14 +02:00
Jakob Hauser 4ed21f06a9 power: supply: rt5033_battery: Adopt status property from charger
The rt5033-battery fuelgauge can't get a status by itself. The rt5033-charger
can, let's get this value.

To get the charger as a "supplier" from the devicetree, the "of_node" needs
to be initiated.

Additionally, in the probe function replace dev_err() with dev_err_probe(),
this will avoid printing an error for -EPROBE_DEFER when the battery driver
probes before the charger driver.

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/a2015d257b145108a3ecdf107a3040362c887fc5.1684182964.git.jahau@rocketmail.com
2023-06-08 18:17:50 +01:00
Jakob Hauser 49b435908b power: supply: rt5033_battery: Move struct rt5033_battery to battery driver
Move struct rt5033_battery from the mfd header into the battery driver because
it's not used by others.

Within struct rt5033_battery, remove the line "struct rt5033_dev *rt5033;"
because it doesn't get used.

In rt5033.h, remove #include <linux/power_supply.h>, it's not necessary
anymore.

In rt5033_battery.c, remove #include <linux/mfd/rt5033.h>, it's not necessary
anymore either. Instead add #include <linux/regmap.h> and

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/736e1cbee257853cb3d1da6f05c184e9a053263b.1684182964.git.jahau@rocketmail.com
2023-06-08 18:17:38 +01:00
Jakob Hauser b7653853d5 power: supply: rt5033_charger: Add RT5033 charger device driver
This patch adds device driver of Richtek RT5033 PMIC. The driver supports
switching charger. rt5033 charger provides three charging modes. The charging
modes are pre-charge mode, fast charge mode and constant voltage mode. They
vary in charge rate, the charge parameters can be controlled by i2c interface.

Tested-by: Raymond Hackley <raymondhackley@protonmail.com>
Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/9556d4ebb30fd321e37aa0eb343554122e4720c9.1684182964.git.jahau@rocketmail.com
2023-06-08 18:17:14 +01:00
ChiYuan Huang 5d80a86a99 power: supply: rt9467: Make charger-enable control as logic level
The current coding make 'charger-enable-gpio' control as real hardware
level. This conflicts with the default binding example. For driver
behavior, no need to use real hardware level, just logic level is
enough. This change can make this flexibility keep in dts gpio active
level about this pin.

Fixes: 6f7f70e3a8 ("power: supply: rt9467: Add Richtek RT9467 charger driver")
Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-06-08 01:50:26 +02:00
Mark Brown 30e15cb0fb
spi-geni-qcom: Add new interfaces and utilise them
Merge series from Vijaya Krishna Nivarthi <quic_vnivarth@quicinc.com>:

A "known issue" during implementation of SE DMA for spi geni driver was
that it does DMA map/unmap internally instead of in spi framework.
Current patches remove this hiccup and also clean up code a bit.

Testing revealed no regressions and results with 1000 iterations of
reading from EC showed no loss of performance.
Results
=======
Before - Iteration 999, min=5.10, max=5.17, avg=5.14, ints=25129
After  - Iteration 999, min=5.10, max=5.20, avg=5.15, ints=25153
2023-06-07 13:28:09 +01:00
Uwe Kleine-König fe20b1dcd2 power: supply: Switch i2c drivers back to use .probe()
After commit b8a1a4cd5a ("i2c: Provide a temporary .probe_new()
call-back type"), all drivers being converted to .probe_new() and then
03c835f498 ("i2c: Switch .probe() to not take an id parameter") convert
back to (the new) .probe() to be able to eventually drop .probe_new() from
struct i2c_driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-06-04 22:33:22 +02:00
Hans de Goede e298d8a38b leds: Change led_trigger_blink[_oneshot]() delay parameters to pass-by-value
led_blink_set[_oneshot]()'s delay_on and delay_off function parameters
are pass by reference, so that hw-blink implementations can report
back the actual achieved delays when the values have been rounded
to something the hw supports.

This is really only interesting for the sysfs API / the timer trigger.
Other triggers don't really care about this and none of the callers of
led_trigger_blink[_oneshot]() do anything with the returned delay values.

Change the led_trigger_blink[_oneshot]() delay parameters to pass-by-value,
there are 2 reasons for this:

1. led_cdev->blink_set() may sleep, while led_trigger_blink() may not.
So on hw where led_cdev->blink_set() sleeps the call needs to be deferred
to a workqueue, in which case the actual achieved delays are unknown
(this is a preparation patch for the deferring).

2. Since the callers don't care about the actual achieved delays, allowing
callers to directly pass a value leads to simpler code for most callers.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Tested-by: Yauhen Kharuzhy <jekhor@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Acked-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20230510162234.291439-2-hdegoede@redhat.com
Signed-off-by: Lee Jones <lee@kernel.org>
2023-05-25 12:16:27 +01:00
Mario Limonciello 95339f40a8 power: supply: Fix logic checking if system is running from battery
The logic used for power_supply_is_system_supplied() counts all power
supplies and assumes that the system is running from AC if there is
either a non-battery power-supply reporting to be online or if no
power-supplies exist at all.

The second rule is for desktop systems, that don't have any
battery/charger devices. These systems will incorrectly report to be
powered from battery once a device scope power-supply is registered
(e.g. a HID device), since these power-supplies increase the counter.

Apart from HID devices, recent dGPUs provide UCSI power supplies on a
desktop systems. The dGPU by default doesn't have anything plugged in so
it's 'offline'. This makes power_supply_is_system_supplied() return 0
with a count of 1 meaning all drivers that use this get a wrong judgement.

To fix this case adjust the logic to also examine the scope of the power
supply. If the power supply is deemed a device power supply, then don't
count it.

Cc: Evan Quan <Evan.Quan@amd.com>
Suggested-by: Lijo Lazar <Lijo.Lazar@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-16 23:02:56 +02:00
Niklas Schnelle eae36cb824 power: reset: add HAS_IOPORT dependencies
In a future patch HAS_IOPORT=n will result in inb()/outb() and friends
not being declared. We thus need to add HAS_IOPORT as dependency for
those drivers using them.

Co-developed-by: Arnd Bergmann <arnd@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@kernel.org>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-16 21:58:57 +02:00
Kang Chen 4cbb0d3588 power: supply: mt6360: add a check of devm_work_autocancel in mt6360_charger_probe
devm_work_autocancel may fail, add a check and return early.

Fixes: 0402e8ebb8 ("power: supply: mt6360_charger: add MT6360 charger support")
Signed-off-by: Kang Chen <void0red@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-16 00:46:53 +02:00
Daisuke Nojiri b2f2a3c980 power: supply: sbs-charger: Fix INHIBITED bit for Status reg
CHARGE_INHIBITED bit position of the ChargerStatus register is actually
0 not 1. This patch corrects it.

Fixes: feb583e37f ("power: supply: add sbs-charger driver")
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-16 00:06:10 +02:00
Aidan MacDonald af1dcd3d2d power: supply: axp20x_usb_power: Add support for AXP192
Add support for the AXP192. It is most similar to the AXP202 but
the current limits are different and the USB OTG status register
has a different address (0x04 instead of 0x02).

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 23:19:52 +02:00
Aidan MacDonald 830087b11e power: supply: axp20x_usb_power: Remove variant IDs from VBUS polling check
Use an explicit boolean flag instead of a check based on the
variant ID. Since this is the last use of variant IDs in the
driver, also remove the IDs.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 23:19:52 +02:00
Aidan MacDonald 305398bfce power: supply: axp20x_usb_power: Use regmap field for VBUS disabling
The POWER_SUPPLY_PROP_ONLINE property allows controlling the VBUS
enable state on supported PMICs. Switch to regmap fields to reduce
dependence on variant IDs.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 23:19:52 +02:00
Aidan MacDonald 70b3b6d9a8 power: supply: axp20x_usb_power: Use regmap fields for USB BC feature
Replace the use of variant IDs with a regmap field, to reduce
dependence on variant IDs.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 23:19:52 +02:00
Aidan MacDonald 05c14ac245 power: supply: axp20x_usb_power: Use regmap fields for VBUS monitor feature
Use regmap fields to describe the VBUS valid bit and VBUS monitor
enable bit. This allows the driver to easily support other chips,
eg. the AXP192, that have the VBUS valid bit in a different register.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 23:19:52 +02:00
Aidan MacDonald 28ca77c9bb power: supply: axp20x_usb_power: Simplify USB current limit handling
Handle the USB current limit with a lookup table and regmap field,
which minimizes code duplication. Invalid or unlimited values are
denoted by -1 entries, and can't be selected from userspace.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 23:19:52 +02:00
Sebastian Reichel c20e8c5b12 mfd: rk808: Split into core and i2c
Split rk808 into a core and an i2c part in preparation for
SPI support.

Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> # for RTC
Tested-by: Diederik de Haas <didi.debian@cknow.org> # Rock64, Quartz64 Model A + B
Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # Pine64 QuartzPro64
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Link: https://lore.kernel.org/r/20230504173618.142075-6-sebastian.reichel@collabora.com
Signed-off-by: Lee Jones <lee@kernel.org>
2023-05-15 16:19:03 +01:00
ChiaEn Wu bc97139ff1 power: supply: rt9467: Fix passing zero to 'dev_err_probe'
Fix passing zero to 'dev_err_probe()' in 'rt9467_request_interrupt()'

Fixes: 6f7f70e3a8 ("power: supply: rt9467: Add Richtek RT9467 charger driver")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/r/202305111228.bHLWU6bq-lkp@intel.com/
Signed-off-by: ChiaEn Wu <chiaen_wu@richtek.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-15 00:51:54 +02:00
Marek Vasut 155c45a256 power: supply: Ratelimit no data debug output
Reduce the amount of output this dev_dbg() statement emits into logs,
otherwise if system software polls the sysfs entry for data and keeps
getting -ENODATA, it could end up filling the logs up.

This does in fact make systemd journald choke, since during boot the
sysfs power supply entries are polled and if journald starts at the
same time, the journal is just being repeatedly filled up, and the
system stops on trying to start journald without booting any further.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-11 20:45:50 +02:00
Huacai Chen 44c524b642 power: supply: Fix power_supply_get_battery_info() if parent is NULL
After commit 27a2195efa ("power: supply: core: auto-exposure
of simple-battery data") we call power_supply_get_battery_info() in
__power_supply_register(), but it causes test_battery crash with NULL
pointer:

[    7.524846] __power_supply_register: Expected proper parent device for 'test_battery'
[    7.524856] CPU 3 Unable to handle kernel paging request at virtual address 0000000000000278, era == 9000000002fb279c, ra == 9000000003173434
[    7.524862] Oops[#1]:
[    7.524866] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 6.3.0+ #524
[    7.524870] Hardware name: Loongson Loongson-3A5000-7A1000-1w-CRB/Loongson-LS3A5000-7A1000-1w-CRB, BIOS vUDK2018-LoongArch-V2.0.0-prebeta9 10/21/2022
[    7.524872] pc 9000000002fb279c ra 9000000003173434 tp 90000001001f0000 sp 90000001001f3c00
[    7.524875] a0 0000000000000000 a1 0000000000000000 a2 0000000000000000 a3 9000000004553e13
[    7.524878] a4 9000000004553e16 a5 ffffffffffffffff a6 9000000003fd0948 a7 0000000000000030
[    7.524881] t0 9000000003173434 t1 90000000035e2c00 t2 0000000000000001 t3 00000000fffff2b0
[    7.524883] t4 0000000000000007 t5 fffffffffffffffe t6 0000000000000000 t7 0000000000000010
[    7.524886] t8 00000000000000b4 u0 00000001c0840c76 s9 0000000000000000 s0 0000000000000000
[    7.524889] s1 900000000370c458 s2 0000000000000001 s3 9000000101f81000 s4 9000000101f81038
[    7.524891] s5 9000000101f813a0 s6 900000000370c398 s7 9000000003eebd18 s8 90000000037c0070
[    7.524894]    ra: 9000000003173434 power_supply_get_battery_info+0xe4/0x710
[    7.591224]   ERA: 9000000002fb279c __dev_fwnode+0x8/0x20
[    7.853583]  CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE)
[    7.859740]  PRMD: 00000004 (PPLV0 +PIE -PWE)
[    7.864073]  EUEN: 00000000 (-FPE -SXE -ASXE -BTE)
[    7.868839]  ECFG: 00071c1c (LIE=2-4,10-12 VS=7)
[    7.873430] ESTAT: 00010000 [PIL] (IS= ECode=1 EsubCode=0)
[    7.878884]  BADV: 0000000000000278
[    7.882346]  PRID: 0014c010 (Loongson-64bit, Loongson-3A5000)
[    7.888056] Modules linked in:
[    7.891088] Process swapper/0 (pid: 1, threadinfo=0000000091357ee8, task=00000000313d98cb)
[    7.899307] Stack : 00000000000000b4 900000000279aca8 0000000000000001 0000000000000000
[    7.907274]         0000000000000049 0000000000000408 9000000100008c00 90000000035b6370
[    7.915238]         900000000b801080 90000000029a440c 9000000003eb4680 9000000003eb4680
[    7.923202]         9000000101f81038 900000000357cdcc 0000000000000001 900000000370c458
[    7.931166]         9000000101f81000 90000000037c0070 9000000003eebd18 900000000370c398
[    7.939131]         90000000045f4530 9000000101f81038 0000000000000000 0000000000000001
[    7.947095]         900000000370c458 9000000101f81000 0000000000000000 9000000003173e64
[    7.955059]         0000000000000026 9000000003de3880 9000000100562040 900000000357e07c
[    7.963023]         000000000000026f 0000000000000001 90000001001f3d68 fffffffffffffff5
[    7.970987]         90000000036d2ca8 90000000027429d8 90000000037c0030 0000000000000001
[    7.978951]         ...
[    7.981379] Call Trace:
[    7.981382] [<9000000002fb279c>] __dev_fwnode+0x8/0x20
[    7.988916] [<9000000003173434>] power_supply_get_battery_info+0xe4/0x710
[    7.995666] [<9000000003173e64>] __power_supply_register+0x404/0x580
[    8.001984] [<900000000379d368>] test_power_init+0x6c/0x124
[    8.007527] [<90000000026e08f8>] do_one_initcall+0x58/0x1ec
[    8.013066] [<9000000003761614>] kernel_init_freeable+0x290/0x310
[    8.019127] [<90000000035b40e8>] kernel_init+0x24/0x11c
[    8.024324] [<90000000026e2048>] ret_from_kernel_thread+0xc/0xa4
[    8.030295]
[    8.031769] Code: 4c000020  0015002c  03400000 <28c9e08c> 40000d80  02c06184  4c000020  28ca0084  4c000020

Root cause: psy->dev.parent is NULL in power_supply_get_battery_info(),
so change the else branch to be 'else if (psy->dev.parent)' and return
-ENOENT if psy->dev.parent is NULL.

Fixes: 27a2195efa ("power: supply: core: auto-exposure of simple-battery data")
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-09 09:32:22 +02:00
Krzysztof Kozlowski 67fce5963b power: supply: hwmon: constify pointers to hwmon_channel_info
Statically allocated array of pointed to hwmon_channel_info can be made
const for safety.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:33:16 +02:00
Hans de Goede 77c2a3097d power: supply: bq24190: Call power_supply_changed() after updating input current
The bq24192 model relies on external charger-type detection and once
that is done the bq24190_charger code will update the input current.

In this case, when the initial power_supply_changed() call is made
from the interrupt handler, the input settings are 5V/0.5A which
on many devices is not enough power to charge (while the device is on).

On many devices the fuel-gauge relies in its external_power_changed
callback to timely signal userspace about charging <-> discharging
status changes. Add a power_supply_changed() call after updating
the input current. This allows the fuel-gauge driver to timely recheck
if the battery is charging after the new input current has been applied
and then it can immediately notify userspace about this.

Fixes: 18f8e6f695 ("power: supply: bq24190_charger: Get input_current_limit from our supplier")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede ad3d9c779b power: supply: bq25890: Call power_supply_changed() after updating input current or voltage
The bq25892 model relies on external charger-type detection and once
that is done the bq25890_charger code will update the input current
and if pumpexpress is used also the input voltage.

In this case, when the initial power_supply_changed() call is made
from the interrupt handler, the input settings are 5V/0.5A which
on many devices is not enough power to charge (while the device is on).

On many devices the fuel-gauge relies in its external_power_changed
callback to timely signal userspace about charging <-> discharging
status changes. Add a power_supply_changed() call after updating
the input current or voltage. This allows the fuel-gauge driver
to timely recheck if the battery is charging after the new input
settings have been applied and then it can immediately notify
userspace about this.

Fixes: 48f45b094d ("power: supply: bq25890: Support higher charging voltages through Pump Express+ protocol")
Fixes: eab25b4f93 ("power: supply: bq25890: On the bq25892 set the IINLIM based on external charger detection")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede 59dddea987 power: supply: bq27xxx: Use mod_delayed_work() instead of cancel() + schedule()
Use mod_delayed_work() instead of separate cancel_delayed_work_sync() +
schedule_delayed_work() calls.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede 59a99cd462 power: supply: bq27xxx: After charger plug in/out wait 0.5s for things to stabilize
bq27xxx_external_power_changed() gets called when the charger is plugged
in or out. Rather then immediately scheduling an update wait 0.5 seconds
for things to stabilize, so that e.g. the (dis)charge current is stable
when bq27xxx_battery_update() runs.

Fixes: 740b755a3b ("bq27x00: Poll battery state")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede 939a116142 power: supply: bq27xxx: Ensure power_supply_changed() is called on current sign changes
On gauges where the current register is signed, there is no charging
flag in the flags register. So only checking flags will not result
in power_supply_changed() getting called when e.g. a charger is plugged
in and the current sign changes from negative (discharging) to
positive (charging).

This causes userspace's notion of the status to lag until userspace
does a poll.

And when a power_supply_leds.c LED trigger is used to indicate charging
status with a LED, this LED will lag until the capacity percentage
changes, which may take many minutes (because the LED trigger only is
updated on power_supply_changed() calls).

Fix this by calling bq27xxx_battery_current_and_status() on gauges with
a signed current register and checking if the status has changed.

Fixes: 297a533b3e ("bq27x00: Cache battery registers")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede ff4c4a2a44 power: supply: bq27xxx: Move bq27xxx_battery_update() down
Move the bq27xxx_battery_update() functions to below
the bq27xxx_battery_current_and_status() function.

This is just moving a block of text, no functional changes.

This is a preparation patch for making bq27xxx_battery_update() check
the status and have it call power_supply_changed() on status changes.

Fixes: 297a533b3e ("bq27x00: Cache battery registers")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede 35092c5819 power: supply: bq27xxx: Add cache parameter to bq27xxx_battery_current_and_status()
Add a cache parameter to bq27xxx_battery_current_and_status() so that
it can optionally use cached flags instead of re-reading them itself.

This is a preparation patch for making bq27xxx_battery_update() check
the status and have it call power_supply_changed() on status changes.

Fixes: 297a533b3e ("bq27x00: Cache battery registers")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:12 +02:00
Hans de Goede c00bc80462 power: supply: bq27xxx: Fix poll_interval handling and races on remove
Before this patch bq27xxx_battery_teardown() was setting poll_interval = 0
to avoid bq27xxx_battery_update() requeuing the delayed_work item.

There are 2 problems with this:

1. If the driver is unbound through sysfs, rather then the module being
   rmmod-ed, this changes poll_interval unexpectedly

2. This is racy, after it being set poll_interval could be changed
   before bq27xxx_battery_update() checks it through
   /sys/module/bq27xxx_battery/parameters/poll_interval

Fix this by added a removed attribute to struct bq27xxx_device_info and
using that instead of setting poll_interval to 0.

There also is another poll_interval related race on remove(), writing
/sys/module/bq27xxx_battery/parameters/poll_interval will requeue
the delayed_work item for all devices on the bq27xxx_battery_devices
list and the device being removed was only removed from that list
after cancelling the delayed_work item.

Fix this by moving the removal from the bq27xxx_battery_devices list
to before cancelling the delayed_work item.

Fixes: 8cfaaa8118 ("bq27x00_battery: Fix OOPS caused by unregistring bq27x00 driver")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:11 +02:00
Hans de Goede 444ff00734 power: supply: bq27xxx: Fix I2C IRQ race on remove
devm_request_threaded_irq() requested IRQs are only free-ed after
the driver's remove function has ran. So the IRQ could trigger and
call bq27xxx_battery_update() after bq27xxx_battery_teardown() has
already run.

Switch to explicitly free-ing the IRQ in bq27xxx_battery_i2c_remove()
to fix this.

Fixes: 8807feb91b ("power: bq27xxx_battery: Add interrupt handling support")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:11 +02:00
Hans de Goede 5c34c0aef1 power: supply: bq27xxx: Fix bq27xxx_battery_update() race condition
bq27xxx_battery_update() assumes / requires that it is only run once,
not multiple times at the same time. But there are 3 possible callers:

1. bq27xxx_battery_poll() delayed_work item handler
2. bq27xxx_battery_irq_handler_thread() I2C IRQ handler
3. bq27xxx_battery_setup()

And there is no protection against these racing with each other,
fix this race condition by making all callers take di->lock:

- Rename bq27xxx_battery_update() to bq27xxx_battery_update_unlocked()

- Add new bq27xxx_battery_update() which takes di->lock and then calls
  bq27xxx_battery_update_unlocked()

- Make stale cache check code in bq27xxx_battery_get_property(), which
  already takes di->lock directly to check the jiffies, call
  bq27xxx_battery_update_unlocked() instead of messing with
  the delayed_work item

- Make bq27xxx_battery_update_unlocked() mod the delayed-work item
  so that the next poll is delayed to poll_interval milliseconds after
  the last update independent of the source of the update

Fixes: 740b755a3b ("bq27x00: Poll battery state")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:11 +02:00
Hans de Goede e448464399 power: supply: leds: Fix blink to LED on transition
When a battery's status changes from charging to full then
the charging-blink-full-solid trigger tries to change
the LED from blinking to solid/on.

As is documented in include/linux/leds.h to deactivate blinking /
to make the LED solid a LED_OFF must be send:

"""
         * Deactivate blinking again when the brightness is set to LED_OFF
         * via the brightness_set() callback.
"""

led_set_brighness() calls with a brightness value other then 0 / LED_OFF
merely change the brightness of the LED in its on state while it is
blinking.

So power_supply_update_bat_leds() must first send a LED_OFF event
before the LED_FULL to disable blinking.

Fixes: 6501f728c5 ("power_supply: Add new LED trigger charging-blink-solid-full")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:13:19 +02:00
Hans de Goede 32fe18d034 power: supply: twl4030_madc_battery: Refactor twl4030_madc_bat_ext_changed()
twl4030_madc_bat_ext_changed() is a wrapper around
"power_supply_changed(psy);" and it has the same prototype.

Remove it, replacing it with making the external_power_changed
callback directly point to power_supply_changed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:07:56 +02:00
Hans de Goede 1269774ac3 power: supply: max17042_battery: Refactor max17042_external_power_changed()
max17042_external_power_changed() is a wrapper around
"power_supply_changed(psy);" and it has the same prototype.

Remove it, replacing it with making the external_power_changed
callback directly point to power_supply_changed.

Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Cc: Purism Kernel Team <kernel@puri.sm>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:07:34 +02:00
Hans de Goede 4d5c129d6c power: supply: sc27xx: Fix external_power_changed race
sc27xx_fgu_external_power_changed() dereferences data->battery,
which gets sets in ab8500_btemp_probe() like this:

	data->battery = devm_power_supply_register(dev, &sc27xx_fgu_desc,
                                                   &fgu_cfg);

As soon as devm_power_supply_register() has called device_add()
the external_power_changed callback can get called. So there is a window
where sc27xx_fgu_external_power_changed() may get called while
data->battery has not been set yet leading to a NULL pointer dereference.

Fixing this is easy. The external_power_changed callback gets passed
the power_supply which will eventually get stored in data->battery,
so sc27xx_fgu_external_power_changed() can simply directly use
the passed in psy argument which is always valid.

After this change sc27xx_fgu_external_power_changed() is reduced to just
"power_supply_changed(psy);" and it has the same prototype. While at it
simply replace it with making the external_power_changed callback
directly point to power_supply_changed.

Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:06:12 +02:00
Hans de Goede 029a443b9b power: supply: bq25890: Fix external_power_changed race
bq25890_charger_external_power_changed() dereferences bq->charger,
which gets sets in bq25890_power_supply_init() like this:

  bq->charger = devm_power_supply_register(bq->dev, &bq->desc, &psy_cfg);

As soon as devm_power_supply_register() has called device_add()
the external_power_changed callback can get called. So there is a window
where bq25890_charger_external_power_changed() may get called while
bq->charger has not been set yet leading to a NULL pointer dereference.

This race hits during boot sometimes on a Lenovo Yoga Book 1 yb1-x90f
when the cht_wcove_pwrsrc (extcon) power_supply is done with detecting
the connected charger-type which happens to exactly hit the small window:

  BUG: kernel NULL pointer dereference, address: 0000000000000018
  <snip>
  RIP: 0010:__power_supply_is_supplied_by+0xb/0xb0
  <snip>
  Call Trace:
   <TASK>
   __power_supply_get_supplier_property+0x19/0x50
   class_for_each_device+0xb1/0xe0
   power_supply_get_property_from_supplier+0x2e/0x50
   bq25890_charger_external_power_changed+0x38/0x1b0 [bq25890_charger]
   __power_supply_changed_work+0x30/0x40
   class_for_each_device+0xb1/0xe0
   power_supply_changed_work+0x5f/0xe0
  <snip>

Fixing this is easy. The external_power_changed callback gets passed
the power_supply which will eventually get stored in bq->charger,
so bq25890_charger_external_power_changed() can simply directly use
the passed in psy argument which is always valid.

Fixes: eab25b4f93 ("power: supply: bq25890: On the bq25892 set the IINLIM based on external charger detection")
Cc: stable@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:05:23 +02:00
Hans de Goede f8319774d6 power: supply: axp288_fuel_gauge: Fix external_power_changed race
fuel_gauge_external_power_changed() dereferences info->bat,
which gets sets in axp288_fuel_gauge_probe() like this:

  info->bat = devm_power_supply_register(dev, &fuel_gauge_desc, &psy_cfg);

As soon as devm_power_supply_register() has called device_add()
the external_power_changed callback can get called. So there is a window
where fuel_gauge_external_power_changed() may get called while
info->bat has not been set yet leading to a NULL pointer dereference.

Fixing this is easy. The external_power_changed callback gets passed
the power_supply which will eventually get stored in info->bat,
so fuel_gauge_external_power_changed() can simply directly use
the passed in psy argument which is always valid.

Fixes: 30abb3d079 ("power: supply: axp288_fuel_gauge: Take lock before updating the valid flag")
Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:04:53 +02:00
Hans de Goede a5299ce4e9 power: supply: ab8500: Fix external_power_changed race
ab8500_btemp_external_power_changed() dereferences di->btemp_psy,
which gets sets in ab8500_btemp_probe() like this:

        di->btemp_psy = devm_power_supply_register(dev, &ab8500_btemp_desc,
                                                   &psy_cfg);

As soon as devm_power_supply_register() has called device_add()
the external_power_changed callback can get called. So there is a window
where ab8500_btemp_external_power_changed() may get called while
di->btemp_psy has not been set yet leading to a NULL pointer dereference.

Fixing this is easy. The external_power_changed callback gets passed
the power_supply which will eventually get stored in di->btemp_psy,
so ab8500_btemp_external_power_changed() can simply directly use
the passed in psy argument which is always valid.

And the same applies to ab8500_fg_external_power_changed().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:03:50 +02:00
Christophe JAILLET 3cc52437d9 power: supply: rk817: Simplify an error message
dev_err_probe() already display the error code. There is no need to
duplicate it explicitly in the error message.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 14:43:19 +02:00
Uwe Kleine-König aafbf04f95 power: reset: gpio-restart: Convert to platform remove callback returning void
Returning an error code from a remove callback makes the driver core
emit a generic (and so little helpful) error message and after that the
error code is ignored and the device unbound.

As gpio_restart_remove() already emits an error message, suppressing the
generic error is no loss.

Then convert to .remove_new() which is equivalent to returning 0
unconditionally in .remove(). See commit 5c5a7680e6 ("platform:
Provide a remove callback that returns no value") for its rational.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 14:41:00 +02:00
Daisuke Nojiri 97dd69b1ad power: supply: cros_pchg: Sync port status on resume
When a stylus is removed (or attached) during suspend, the device detach
(or attach) events can be lost. This patch makes the peripheral device
charge driver retrieve the latest status from the EC on resume.

BUG=b:276414488
TEST=Redrix

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 14:31:24 +02:00
Hermes Zhang 131c0c7682 power: supply: bq256xx: Apply TS_IGNORE from devicetree
TS_IGNORE is default off in bq256xx chip. For some HW which doesn't have
the NTC, we need to set TS_IGNORE to 1 to make the charge work. The new
"ti,no-thermistor" is introduced to toggle it.

Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 14:14:07 +02:00