* FAILED: patch "[PATCH] power: supply: generic-adc-battery: fix status with no supplier" failed to apply to 5.15-stable tree
@ 2026-11-07 11:08 Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
0 siblings, 1 reply; 8+ messages in thread
From: Sasha Levin @ 2026-11-07 11:08 UTC (permalink / raw)
To: me, sebastian.reichel; +Cc: stable
The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 8ae5a3f40045ff486826ed6b6a83e39a0f380073
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '20261107060802-failed-5.15-8ae5a3f40045@kernel.org' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 8ae5a3f40045ff486826ed6b6a83e39a0f380073 Mon Sep 17 00:00:00 2001
From: Tim Douglas <me@timdoug.com>
Date: Mon, 12 Oct 2026 22:21:53 -0400
Subject: [PATCH] power: supply: generic-adc-battery: fix status with no
supplier
power_supply_am_i_supplied() returns -ENODEV when no registered power
supply supplies the battery. generic-adc-battery's gab_work() tests this
return value as a boolean, so -ENODEV takes the supplied branch and
reports CHARGING, or NOT_CHARGING if the charge-finished GPIO is asserted,
instead of DISCHARGING.
This was noticed while bringing up an out-of-tree Linux port to the
WikiReader: the driver reported CHARGING on a device powered by two AAA
batteries with no charging hardware.
Only a positive return value indicates an online supplier, so treat zero
and negative returns as discharging.
Fixes: 46cecd130d55 ("power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate")
Cc: stable@vger.kernel.org
Signed-off-by: Tim Douglas <me@timdoug.com>
Link: https://patch.msgid.link/20261013022153.6707-1-me@timdoug.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
drivers/power/supply/generic-adc-battery.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index f3ca3ebb25333..c8ad3f11e8081 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -130,7 +130,7 @@ static void gab_work(struct work_struct *work)
adc_bat = container_of(delayed_work, struct gab, bat_work);
status = adc_bat->status;
- if (!power_supply_am_i_supplied(adc_bat->psy))
+ if (power_supply_am_i_supplied(adc_bat->psy) <= 0)
adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
else if (gab_charge_finished(adc_bat))
adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources
2026-11-07 11:08 FAILED: patch "[PATCH] power: supply: generic-adc-battery: fix status with no supplier" failed to apply to 5.15-stable tree Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 2/7] power: supply: generic-adc-battery: drop jitter delay support Sasha Levin
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Sebastian Reichel, Linus Walleij, Matti Vaittinen, Sasha Levin
From: Sebastian Reichel <sre@kernel.org>
[ Upstream commit 93297ef6920f071ed109cbdcf640edfc693d0456 ]
Convert driver to use managed resources to simplify driver code.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Stable-dep-of: 8ae5a3f40045 ("power: supply: generic-adc-battery: fix status with no supplier")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 81 ++++++----------------
1 file changed, 23 insertions(+), 58 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 0af536f4932f1..535972a332b32 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -23,6 +23,7 @@
#include <linux/iio/consumer.h>
#include <linux/iio/types.h>
#include <linux/power/generic-adc-battery.h>
+#include <linux/devm-helpers.h>
#define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -269,14 +270,13 @@ static int gab_probe(struct platform_device *pdev)
* copying the static properties and allocating extra memory for holding
* the extra configurable properties received from platform data.
*/
- properties = kcalloc(ARRAY_SIZE(gab_props) +
- ARRAY_SIZE(gab_chan_name),
- sizeof(*properties),
- GFP_KERNEL);
- if (!properties) {
- ret = -ENOMEM;
- goto first_mem_fail;
- }
+ properties = devm_kcalloc(&pdev->dev,
+ ARRAY_SIZE(gab_props) +
+ ARRAY_SIZE(gab_chan_name),
+ sizeof(*properties),
+ GFP_KERNEL);
+ if (!properties)
+ return -ENOMEM;
memcpy(properties, gab_props, sizeof(gab_props));
@@ -285,12 +285,13 @@ static int gab_probe(struct platform_device *pdev)
* based on the channel supported by consumer device.
*/
for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
- adc_bat->channel[chan] = iio_channel_get(&pdev->dev,
- gab_chan_name[chan]);
+ adc_bat->channel[chan] = devm_iio_channel_get(&pdev->dev, gab_chan_name[chan]);
if (IS_ERR(adc_bat->channel[chan])) {
ret = PTR_ERR(adc_bat->channel[chan]);
+ if (ret != -ENODEV)
+ return dev_err_probe(&pdev->dev, ret, "Failed to get ADC channel %s\n", gab_chan_name[chan]);
adc_bat->channel[chan] = NULL;
- } else {
+ } else if (adc_bat->channel[chan]) {
/* copying properties for supported channels only */
int index2;
@@ -305,10 +306,8 @@ static int gab_probe(struct platform_device *pdev)
}
/* none of the channels are supported so let's bail out */
- if (!any) {
- ret = -ENODEV;
- goto second_mem_fail;
- }
+ if (!any)
+ return dev_err_probe(&pdev->dev, -ENODEV, "Failed to get any ADC channel\n");
/*
* Total number of properties is equal to static properties
@@ -319,25 +318,24 @@ static int gab_probe(struct platform_device *pdev)
psy_desc->properties = properties;
psy_desc->num_properties = index;
- adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
- if (IS_ERR(adc_bat->psy)) {
- ret = PTR_ERR(adc_bat->psy);
- goto err_reg_fail;
- }
+ adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
+ if (IS_ERR(adc_bat->psy))
+ return dev_err_probe(&pdev->dev, PTR_ERR(adc_bat->psy), "Failed to register power-supply device\n");
- INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work);
+ ret = devm_delayed_work_autocancel(&pdev->dev, &adc_bat->bat_work, gab_work);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to register delayed work\n");
- adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev,
- "charged", GPIOD_IN);
+ adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, "charged", GPIOD_IN);
if (adc_bat->charge_finished) {
int irq;
irq = gpiod_to_irq(adc_bat->charge_finished);
- ret = request_any_context_irq(irq, gab_charged,
+ ret = devm_request_any_context_irq(&pdev->dev, irq, gab_charged,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
"battery charged", adc_bat);
if (ret < 0)
- goto gpio_req_fail;
+ return dev_err_probe(&pdev->dev, ret, "Failed to register irq\n");
}
platform_set_drvdata(pdev, adc_bat);
@@ -346,38 +344,6 @@ static int gab_probe(struct platform_device *pdev)
schedule_delayed_work(&adc_bat->bat_work,
msecs_to_jiffies(0));
return 0;
-
-gpio_req_fail:
- power_supply_unregister(adc_bat->psy);
-err_reg_fail:
- for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
- if (adc_bat->channel[chan])
- iio_channel_release(adc_bat->channel[chan]);
- }
-second_mem_fail:
- kfree(properties);
-first_mem_fail:
- return ret;
-}
-
-static int gab_remove(struct platform_device *pdev)
-{
- int chan;
- struct gab *adc_bat = platform_get_drvdata(pdev);
-
- power_supply_unregister(adc_bat->psy);
-
- if (adc_bat->charge_finished)
- free_irq(gpiod_to_irq(adc_bat->charge_finished), adc_bat);
-
- for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
- if (adc_bat->channel[chan])
- iio_channel_release(adc_bat->channel[chan]);
- }
-
- kfree(adc_bat->psy_desc.properties);
- cancel_delayed_work_sync(&adc_bat->bat_work);
- return 0;
}
static int __maybe_unused gab_suspend(struct device *dev)
@@ -411,7 +377,6 @@ static struct platform_driver gab_driver = {
.pm = &gab_pm_ops,
},
.probe = gab_probe,
- .remove = gab_remove,
};
module_platform_driver(gab_driver);
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 2/7] power: supply: generic-adc-battery: drop jitter delay support
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 3/7] power: supply: generic-adc-battery: drop charge now support Sasha Levin
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Sebastian Reichel, Linus Walleij, Sasha Levin
From: Sebastian Reichel <sre@kernel.org>
[ Upstream commit c8f573f312f36861db8e40d9953b6d4b84f1321b ]
Drop support for configuring IRQ jitter delay by using big
enough fixed value.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Stable-dep-of: 8ae5a3f40045 ("power: supply: generic-adc-battery: fix status with no supplier")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 13 ++++---------
include/linux/power/generic-adc-battery.h | 3 ---
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 535972a332b32..e20894460d7fb 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -227,12 +227,10 @@ static void gab_work(struct work_struct *work)
static irqreturn_t gab_charged(int irq, void *dev_id)
{
struct gab *adc_bat = dev_id;
- struct gab_platform_data *pdata = adc_bat->pdata;
- int delay;
- delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT;
schedule_delayed_work(&adc_bat->bat_work,
- msecs_to_jiffies(delay));
+ msecs_to_jiffies(JITTER_DEFAULT));
+
return IRQ_HANDLED;
}
@@ -358,14 +356,11 @@ static int __maybe_unused gab_suspend(struct device *dev)
static int __maybe_unused gab_resume(struct device *dev)
{
struct gab *adc_bat = dev_get_drvdata(dev);
- struct gab_platform_data *pdata = adc_bat->pdata;
- int delay;
-
- delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT;
/* Schedule timer to check current status */
schedule_delayed_work(&adc_bat->bat_work,
- msecs_to_jiffies(delay));
+ msecs_to_jiffies(JITTER_DEFAULT));
+
return 0;
}
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
index c68cbf34cd342..50eb4bf28286b 100644
--- a/include/linux/power/generic-adc-battery.h
+++ b/include/linux/power/generic-adc-battery.h
@@ -11,13 +11,10 @@
* @battery_info: recommended structure to specify static power supply
* parameters
* @cal_charge: calculate charge level.
- * @jitter_delay: delay required after the interrupt to check battery
- * status.Default set is 10ms.
*/
struct gab_platform_data {
struct power_supply_info battery_info;
int (*cal_charge)(long value);
- int jitter_delay;
};
#endif /* GENERIC_ADC_BATTERY_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 3/7] power: supply: generic-adc-battery: drop charge now support
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 2/7] power: supply: generic-adc-battery: drop jitter delay support Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 4/7] power: supply: generic-adc-battery: use simple-battery API Sasha Levin
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Sebastian Reichel, Linus Walleij, Matti Vaittinen, Sasha Levin
From: Sebastian Reichel <sre@kernel.org>
[ Upstream commit 3b6fd262bfcd696aa98af99d71dcf952f289cbee ]
Drop CHARGE_NOW support, which requires a platform specific
calculation method.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Stable-dep-of: 8ae5a3f40045 ("power: supply: generic-adc-battery: fix status with no supplier")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 4 ----
include/linux/power/generic-adc-battery.h | 2 --
2 files changed, 6 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index e20894460d7fb..d07eeb7d46d34 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -72,7 +72,6 @@ static const enum power_supply_property gab_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
- POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -166,9 +165,6 @@ static int gab_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
val->intval = 0;
break;
- case POWER_SUPPLY_PROP_CHARGE_NOW:
- val->intval = pdata->cal_charge(result);
- break;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
case POWER_SUPPLY_PROP_CURRENT_NOW:
case POWER_SUPPLY_PROP_POWER_NOW:
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
index 50eb4bf28286b..54434e4304d35 100644
--- a/include/linux/power/generic-adc-battery.h
+++ b/include/linux/power/generic-adc-battery.h
@@ -10,11 +10,9 @@
* struct gab_platform_data - platform_data for generic adc iio battery driver.
* @battery_info: recommended structure to specify static power supply
* parameters
- * @cal_charge: calculate charge level.
*/
struct gab_platform_data {
struct power_supply_info battery_info;
- int (*cal_charge)(long value);
};
#endif /* GENERIC_ADC_BATTERY_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 4/7] power: supply: generic-adc-battery: use simple-battery API
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 2/7] power: supply: generic-adc-battery: drop jitter delay support Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 3/7] power: supply: generic-adc-battery: drop charge now support Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 5/7] power: supply: generic-adc-battery: simplify read_channel logic Sasha Levin
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Sebastian Reichel, Linus Walleij, Matti Vaittinen, Sasha Levin
From: Sebastian Reichel <sre@kernel.org>
[ Upstream commit 1b27bf793fd46219c882b8e545ec736cfadc0841 ]
Constant battery data is available through power-supply's simple-battery
API. This works automatically, so the manual handling can be removed
without loosing any feature :)
Note, that the POWER_SUPPLY_STATUS_FULL check for the level variable can
be dropped, since the variable is never written. It can be re-introduced
properly once the driver gets functionality to calculate the current
charge level. Apart from that the check must be done fuzzy anyways,
since charge estimation usually is not precise enough to always return
exactly the full charge capacity for a full battery.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Stable-dep-of: 8ae5a3f40045 ("power: supply: generic-adc-battery: fix status with no supplier")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 60 ++--------------------
include/linux/power/generic-adc-battery.h | 18 -------
2 files changed, 4 insertions(+), 74 deletions(-)
delete mode 100644 include/linux/power/generic-adc-battery.h
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index d07eeb7d46d34..d89247d647f8a 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -22,7 +22,6 @@
#include <linux/slab.h>
#include <linux/iio/consumer.h>
#include <linux/iio/types.h>
-#include <linux/power/generic-adc-battery.h>
#include <linux/devm-helpers.h>
#define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -48,9 +47,7 @@ struct gab {
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
- struct gab_platform_data *pdata;
struct delayed_work bat_work;
- int level;
int status;
bool cable_plugged;
struct gpio_desc *charge_finished;
@@ -70,14 +67,6 @@ static void gab_ext_power_changed(struct power_supply *psy)
static const enum power_supply_property gab_props[] = {
POWER_SUPPLY_PROP_STATUS,
- POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
- POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
- POWER_SUPPLY_PROP_VOLTAGE_NOW,
- POWER_SUPPLY_PROP_CURRENT_NOW,
- POWER_SUPPLY_PROP_TECHNOLOGY,
- POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
- POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
- POWER_SUPPLY_PROP_MODEL_NAME,
};
/*
@@ -97,17 +86,6 @@ static bool gab_charge_finished(struct gab *adc_bat)
return gpiod_get_value(adc_bat->charge_finished);
}
-static int gab_get_status(struct gab *adc_bat)
-{
- struct gab_platform_data *pdata = adc_bat->pdata;
- struct power_supply_info *bat_info;
-
- bat_info = &pdata->battery_info;
- if (adc_bat->level == bat_info->charge_full_design)
- return POWER_SUPPLY_STATUS_FULL;
- return adc_bat->status;
-}
-
static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
{
switch (psp) {
@@ -144,27 +122,14 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
static int gab_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
- struct gab *adc_bat;
- struct gab_platform_data *pdata;
- struct power_supply_info *bat_info;
+ struct gab *adc_bat = to_generic_bat(psy);
int result = 0;
int ret = 0;
- adc_bat = to_generic_bat(psy);
- if (!adc_bat) {
- dev_err(&psy->dev, "no battery infos ?!\n");
- return -EINVAL;
- }
- pdata = adc_bat->pdata;
- bat_info = &pdata->battery_info;
-
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
- val->intval = gab_get_status(adc_bat);
- break;
- case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
- val->intval = 0;
- break;
+ val->intval = adc_bat->status;
+ return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
case POWER_SUPPLY_PROP_CURRENT_NOW:
case POWER_SUPPLY_PROP_POWER_NOW:
@@ -173,21 +138,6 @@ static int gab_get_property(struct power_supply *psy,
goto err;
val->intval = result;
break;
- case POWER_SUPPLY_PROP_TECHNOLOGY:
- val->intval = bat_info->technology;
- break;
- case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
- val->intval = bat_info->voltage_min_design;
- break;
- case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
- val->intval = bat_info->voltage_max_design;
- break;
- case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
- val->intval = bat_info->charge_full_design;
- break;
- case POWER_SUPPLY_PROP_MODEL_NAME:
- val->strval = bat_info->name;
- break;
default:
return -EINVAL;
}
@@ -235,7 +185,6 @@ static int gab_probe(struct platform_device *pdev)
struct gab *adc_bat;
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = {};
- struct gab_platform_data *pdata = pdev->dev.platform_data;
enum power_supply_property *properties;
int ret = 0;
int chan;
@@ -250,7 +199,7 @@ static int gab_probe(struct platform_device *pdev)
psy_cfg.drv_data = adc_bat;
psy_desc = &adc_bat->psy_desc;
- psy_desc->name = pdata->battery_info.name;
+ psy_desc->name = dev_name(&pdev->dev);
/* bootup default values for the battery */
adc_bat->cable_plugged = false;
@@ -258,7 +207,6 @@ static int gab_probe(struct platform_device *pdev)
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->get_property = gab_get_property;
psy_desc->external_power_changed = gab_ext_power_changed;
- adc_bat->pdata = pdata;
/*
* copying the static properties and allocating extra memory for holding
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
deleted file mode 100644
index 54434e4304d35..0000000000000
--- a/include/linux/power/generic-adc-battery.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2012, Anish Kumar <anish198519851985@gmail.com>
- */
-
-#ifndef GENERIC_ADC_BATTERY_H
-#define GENERIC_ADC_BATTERY_H
-
-/**
- * struct gab_platform_data - platform_data for generic adc iio battery driver.
- * @battery_info: recommended structure to specify static power supply
- * parameters
- */
-struct gab_platform_data {
- struct power_supply_info battery_info;
-};
-
-#endif /* GENERIC_ADC_BATTERY_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 5/7] power: supply: generic-adc-battery: simplify read_channel logic
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
` (2 preceding siblings ...)
2026-11-10 23:10 ` [PATCH 5.15.y 4/7] power: supply: generic-adc-battery: use simple-battery API Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 6/7] power: supply: generic-adc-battery: style fixes Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 7/7] power: supply: generic-adc-battery: fix status with no supplier Sasha Levin
5 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Sebastian Reichel, Linus Walleij, Matti Vaittinen, Sasha Levin
From: Sebastian Reichel <sre@kernel.org>
[ Upstream commit 9489d1bdb763a3dd954e61522043190a9fd1cb4c ]
Drop mostly useless gab_prop_to_chan() function by directly
supplying the correct enum value to read_channel().
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Stable-dep-of: 8ae5a3f40045 ("power: supply: generic-adc-battery: fix status with no supplier")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 35 ++++------------------
1 file changed, 5 insertions(+), 30 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index d89247d647f8a..be22fe9ae90bf 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -86,31 +86,12 @@ static bool gab_charge_finished(struct gab *adc_bat)
return gpiod_get_value(adc_bat->charge_finished);
}
-static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
-{
- switch (psp) {
- case POWER_SUPPLY_PROP_POWER_NOW:
- return GAB_POWER;
- case POWER_SUPPLY_PROP_VOLTAGE_NOW:
- return GAB_VOLTAGE;
- case POWER_SUPPLY_PROP_CURRENT_NOW:
- return GAB_CURRENT;
- default:
- WARN_ON(1);
- break;
- }
- return GAB_POWER;
-}
-
-static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
+static int read_channel(struct gab *adc_bat, enum gab_chan_type channel,
int *result)
{
int ret;
- int chan_index;
- chan_index = gab_prop_to_chan(psp);
- ret = iio_read_channel_processed(adc_bat->channel[chan_index],
- result);
+ ret = iio_read_channel_processed(adc_bat->channel[channel], result);
if (ret < 0)
pr_err("read channel error\n");
else
@@ -123,26 +104,20 @@ static int gab_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
struct gab *adc_bat = to_generic_bat(psy);
- int result = 0;
- int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
val->intval = adc_bat->status;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+ return read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_NOW:
+ return read_channel(adc_bat, GAB_CURRENT, &val->intval);
case POWER_SUPPLY_PROP_POWER_NOW:
- ret = read_channel(adc_bat, psp, &result);
- if (ret < 0)
- goto err;
- val->intval = result;
- break;
+ return read_channel(adc_bat, GAB_POWER, &val->intval);
default:
return -EINVAL;
}
-err:
- return ret;
}
static void gab_work(struct work_struct *work)
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 6/7] power: supply: generic-adc-battery: style fixes
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
` (3 preceding siblings ...)
2026-11-10 23:10 ` [PATCH 5.15.y 5/7] power: supply: generic-adc-battery: simplify read_channel logic Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 7/7] power: supply: generic-adc-battery: fix status with no supplier Sasha Levin
5 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Sebastian Reichel, Sasha Levin
From: Sebastian Reichel <sre@kernel.org>
[ Upstream commit 7cc7478e093782d2ac176c11a966de00bd0792dc ]
This does the following code-style changes:
* fix inconsistent indentation in 'struct gab'
* remove unused cable_plugged from 'struct gab'
* remove pointless temporary is_plugged variable
* add gab_ prefix to read_channel
No functionality changes are intended.
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Omit the temperature-property call-site rename because temperature
channels are not supported here. Rename the existing voltage, current
and power channel calls only.
Stable-dep-of: 8ae5a3f40045 ("power: supply: generic-adc-battery: fix status with no supplier")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 24 ++++++++--------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index be22fe9ae90bf..cac0ac5caa142 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -44,12 +44,11 @@ static const char *const gab_chan_name[] = {
};
struct gab {
- struct power_supply *psy;
- struct power_supply_desc psy_desc;
- struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
+ struct power_supply *psy;
+ struct power_supply_desc psy_desc;
+ struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
struct delayed_work bat_work;
- int status;
- bool cable_plugged;
+ int status;
struct gpio_desc *charge_finished;
};
@@ -86,7 +85,7 @@ static bool gab_charge_finished(struct gab *adc_bat)
return gpiod_get_value(adc_bat->charge_finished);
}
-static int read_channel(struct gab *adc_bat, enum gab_chan_type channel,
+static int gab_read_channel(struct gab *adc_bat, enum gab_chan_type channel,
int *result)
{
int ret;
@@ -110,11 +109,11 @@ static int gab_get_property(struct power_supply *psy,
val->intval = adc_bat->status;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
- return read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
+ return gab_read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_NOW:
- return read_channel(adc_bat, GAB_CURRENT, &val->intval);
+ return gab_read_channel(adc_bat, GAB_CURRENT, &val->intval);
case POWER_SUPPLY_PROP_POWER_NOW:
- return read_channel(adc_bat, GAB_POWER, &val->intval);
+ return gab_read_channel(adc_bat, GAB_POWER, &val->intval);
default:
return -EINVAL;
}
@@ -124,17 +123,13 @@ static void gab_work(struct work_struct *work)
{
struct gab *adc_bat;
struct delayed_work *delayed_work;
- bool is_plugged;
int status;
delayed_work = to_delayed_work(work);
adc_bat = container_of(delayed_work, struct gab, bat_work);
status = adc_bat->status;
- is_plugged = power_supply_am_i_supplied(adc_bat->psy);
- adc_bat->cable_plugged = is_plugged;
-
- if (!is_plugged)
+ if (!power_supply_am_i_supplied(adc_bat->psy))
adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
else if (gab_charge_finished(adc_bat))
adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
@@ -177,7 +172,6 @@ static int gab_probe(struct platform_device *pdev)
psy_desc->name = dev_name(&pdev->dev);
/* bootup default values for the battery */
- adc_bat->cable_plugged = false;
adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->get_property = gab_get_property;
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5.15.y 7/7] power: supply: generic-adc-battery: fix status with no supplier
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
` (4 preceding siblings ...)
2026-11-10 23:10 ` [PATCH 5.15.y 6/7] power: supply: generic-adc-battery: style fixes Sasha Levin
@ 2026-11-10 23:10 ` Sasha Levin
5 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-10 23:10 UTC (permalink / raw)
To: stable; +Cc: Tim Douglas, Sebastian Reichel, Sasha Levin
From: Tim Douglas <me@timdoug.com>
[ Upstream commit 8ae5a3f40045ff486826ed6b6a83e39a0f380073 ]
power_supply_am_i_supplied() returns -ENODEV when no registered power
supply supplies the battery. generic-adc-battery's gab_work() tests this
return value as a boolean, so -ENODEV takes the supplied branch and
reports CHARGING, or NOT_CHARGING if the charge-finished GPIO is asserted,
instead of DISCHARGING.
This was noticed while bringing up an out-of-tree Linux port to the
WikiReader: the driver reported CHARGING on a device powered by two AAA
batteries with no charging hardware.
Only a positive return value indicates an online supplier, so treat zero
and negative returns as discharging.
Fixes: 46cecd130d55 ("power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate")
Cc: stable@vger.kernel.org
Signed-off-by: Tim Douglas <me@timdoug.com>
Link: https://patch.msgid.link/20261013022153.6707-1-me@timdoug.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/generic-adc-battery.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index cac0ac5caa142..e7f45ce38ce2c 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -129,7 +129,7 @@ static void gab_work(struct work_struct *work)
adc_bat = container_of(delayed_work, struct gab, bat_work);
status = adc_bat->status;
- if (!power_supply_am_i_supplied(adc_bat->psy))
+ if (power_supply_am_i_supplied(adc_bat->psy) <= 0)
adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
else if (gab_charge_finished(adc_bat))
adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-10 23:10 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-07 11:08 FAILED: patch "[PATCH] power: supply: generic-adc-battery: fix status with no supplier" failed to apply to 5.15-stable tree Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 2/7] power: supply: generic-adc-battery: drop jitter delay support Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 3/7] power: supply: generic-adc-battery: drop charge now support Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 4/7] power: supply: generic-adc-battery: use simple-battery API Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 5/7] power: supply: generic-adc-battery: simplify read_channel logic Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 6/7] power: supply: generic-adc-battery: style fixes Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 7/7] power: supply: generic-adc-battery: fix status with no supplier Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox