* [PATCH] power: supply: bd71828: add input current limit property
@ 2026-04-01 21:17 Andreas Kemnade
2026-04-02 22:54 ` Sebastian Reichel
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andreas Kemnade @ 2026-04-01 21:17 UTC (permalink / raw)
To: Matti Vaittinen, Sebastian Reichel
Cc: linux-pm, linux-kernel, Andreas Kemnade
Add input current property to be able to work around issues created by
automatic input limiting and have some control.
Disabling the automatic management is another step.
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
drivers/power/supply/bd71828-power.c | 62 ++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/drivers/power/supply/bd71828-power.c b/drivers/power/supply/bd71828-power.c
index 0e00acb589937..5e78faa0a4aaf 100644
--- a/drivers/power/supply/bd71828-power.c
+++ b/drivers/power/supply/bd71828-power.c
@@ -24,6 +24,7 @@
#define BD7182x_MASK_CONF_PON BIT(0)
#define BD71815_MASK_CONF_XSTB BIT(1)
#define BD7182x_MASK_BAT_STAT 0x3f
+#define BD7182x_MASK_ILIM 0x3f
#define BD7182x_MASK_DCIN_STAT 0x07
#define BD7182x_MASK_WDT_AUTO 0x40
@@ -48,9 +49,11 @@ struct pwr_regs {
unsigned int vbat_avg;
unsigned int ibat;
unsigned int ibat_avg;
+ unsigned int ilim_stat;
unsigned int btemp_vth;
unsigned int chg_state;
unsigned int bat_temp;
+ unsigned int dcin_set;
unsigned int dcin_stat;
unsigned int dcin_online_mask;
unsigned int dcin_collapse_limit;
@@ -66,9 +69,11 @@ static const struct pwr_regs pwr_regs_bd71828 = {
.vbat_avg = BD71828_REG_VBAT_U,
.ibat = BD71828_REG_IBAT_U,
.ibat_avg = BD71828_REG_IBAT_AVG_U,
+ .ilim_stat = BD71828_REG_ILIM_STAT,
.btemp_vth = BD71828_REG_VM_BTMP_U,
.chg_state = BD71828_REG_CHG_STATE,
.bat_temp = BD71828_REG_BAT_TEMP,
+ .dcin_set = BD71828_REG_DCIN_SET,
.dcin_stat = BD71828_REG_DCIN_STAT,
.dcin_online_mask = BD7182x_MASK_DCIN_DET,
.dcin_collapse_limit = BD71828_REG_DCIN_CLPS,
@@ -441,6 +446,7 @@ static int bd71828_charger_get_property(struct power_supply *psy,
struct bd71828_power *pwr = dev_get_drvdata(psy->dev.parent);
u32 vot;
u16 tmp;
+ int t;
int online;
int ret;
@@ -459,6 +465,20 @@ static int bd71828_charger_get_property(struct power_supply *psy,
vot = tmp;
/* 5 milli volt steps */
val->intval = 5000 * vot;
+ break;
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ if (!pwr->regs->ilim_stat)
+ return -ENODATA;
+
+ ret = regmap_read(pwr->regmap, pwr->regs->ilim_stat, &t);
+ if (ret)
+ return ret;
+
+ t++;
+ val->intval = (t & BD7182x_MASK_ILIM) * 50000;
+ if (val->intval > 2000000)
+ val->intval = 2000000;
+
break;
default:
return -EINVAL;
@@ -467,6 +487,45 @@ static int bd71828_charger_get_property(struct power_supply *psy,
return 0;
}
+static int bd71828_charger_set_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ const union power_supply_propval *val)
+{
+ struct bd71828_power *pwr = dev_get_drvdata(psy->dev.parent);
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ if (val->intval > 2000000)
+ return -EINVAL;
+
+ if (val->intval < 50000)
+ return -EINVAL;
+
+ if (!pwr->regs->dcin_set)
+ return -EINVAL;
+
+ return regmap_update_bits(pwr->regmap, pwr->regs->dcin_set,
+ BD7182x_MASK_ILIM,
+ val->intval / 50000 - 1);
+ break;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int bd71828_charger_property_is_writeable(struct power_supply *psy,
+ enum power_supply_property psp)
+{
+ struct bd71828_power *pwr = dev_get_drvdata(psy->dev.parent);
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ return !!(pwr->regs->dcin_set);
+ default:
+ return false;
+ }
+}
+
static int bd71828_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
@@ -571,6 +630,7 @@ static int bd71828_battery_property_is_writeable(struct power_supply *psy,
/** @brief ac properties */
static const enum power_supply_property bd71828_charger_props[] = {
+ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
};
@@ -600,6 +660,8 @@ static const struct power_supply_desc bd71828_ac_desc = {
.properties = bd71828_charger_props,
.num_properties = ARRAY_SIZE(bd71828_charger_props),
.get_property = bd71828_charger_get_property,
+ .set_property = bd71828_charger_set_property,
+ .property_is_writeable = bd71828_charger_property_is_writeable,
};
static const struct power_supply_desc bd71828_bat_desc = {
---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260401-bd-inp-limit-3acb51e15e9c
Best regards,
--
Andreas Kemnade <andreas@kemnade.info>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] power: supply: bd71828: add input current limit property
2026-04-01 21:17 [PATCH] power: supply: bd71828: add input current limit property Andreas Kemnade
@ 2026-04-02 22:54 ` Sebastian Reichel
2026-04-07 5:34 ` Matti Vaittinen
2026-04-07 6:33 ` Matti Vaittinen
2 siblings, 0 replies; 7+ messages in thread
From: Sebastian Reichel @ 2026-04-02 22:54 UTC (permalink / raw)
To: Matti Vaittinen, Sebastian Reichel, Andreas Kemnade
Cc: linux-pm, linux-kernel
On Wed, 01 Apr 2026 23:17:05 +0200, Andreas Kemnade wrote:
> Add input current property to be able to work around issues created by
> automatic input limiting and have some control.
> Disabling the automatic management is another step.
>
>
Applied, thanks!
[1/1] power: supply: bd71828: add input current limit property
commit: be353c6729d087925da702cf8c0ad3cb1ae53dec
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] power: supply: bd71828: add input current limit property
2026-04-01 21:17 [PATCH] power: supply: bd71828: add input current limit property Andreas Kemnade
2026-04-02 22:54 ` Sebastian Reichel
@ 2026-04-07 5:34 ` Matti Vaittinen
2026-04-07 5:48 ` Matti Vaittinen
2026-04-07 6:33 ` Matti Vaittinen
2 siblings, 1 reply; 7+ messages in thread
From: Matti Vaittinen @ 2026-04-07 5:34 UTC (permalink / raw)
To: Andreas Kemnade, Sebastian Reichel; +Cc: linux-pm, linux-kernel
On 02/04/2026 00:17, Andreas Kemnade wrote:
> Add input current property to be able to work around issues created by
> automatic input limiting and have some control.
> Disabling the automatic management is another step.
>
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
> ---
> drivers/power/supply/bd71828-power.c | 62 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 62 insertions(+)
>
> diff --git a/drivers/power/supply/bd71828-power.c b/drivers/power/supply/bd71828-power.c
> index 0e00acb589937..5e78faa0a4aaf 100644
> --- a/drivers/power/supply/bd71828-power.c
> +++ b/drivers/power/supply/bd71828-power.c
> @@ -24,6 +24,7 @@
> #define BD7182x_MASK_CONF_PON BIT(0)
> #define BD71815_MASK_CONF_XSTB BIT(1)
> #define BD7182x_MASK_BAT_STAT 0x3f
> +#define BD7182x_MASK_ILIM 0x3f
> #define BD7182x_MASK_DCIN_STAT 0x07
>
> #define BD7182x_MASK_WDT_AUTO 0x40
> @@ -48,9 +49,11 @@ struct pwr_regs {
> unsigned int vbat_avg;
> unsigned int ibat;
> unsigned int ibat_avg;
> + unsigned int ilim_stat;
> unsigned int btemp_vth;
> unsigned int chg_state;
> unsigned int bat_temp;
> + unsigned int dcin_set;
> unsigned int dcin_stat;
> unsigned int dcin_online_mask;
> unsigned int dcin_collapse_limit;
> @@ -66,9 +69,11 @@ static const struct pwr_regs pwr_regs_bd71828 = {
> .vbat_avg = BD71828_REG_VBAT_U,
> .ibat = BD71828_REG_IBAT_U,
> .ibat_avg = BD71828_REG_IBAT_AVG_U,
> + .ilim_stat = BD71828_REG_ILIM_STAT,
> .btemp_vth = BD71828_REG_VM_BTMP_U,
> .chg_state = BD71828_REG_CHG_STATE,
> .bat_temp = BD71828_REG_BAT_TEMP,
> + .dcin_set = BD71828_REG_DCIN_SET,
Hi Andreas / Sebastian,
Sorry for belated review (although, I don't think this did float on the
list quite THAT long...)
I believe this is the ILIM_STAT register in the data sheet, at address
0x6d, right? (The bit field is named as: LIM_DCIN_STAT[5:0]). If so,
then I have a follow-up question in the setter...
> .dcin_stat = BD71828_REG_DCIN_STAT,
> .dcin_online_mask = BD7182x_MASK_DCIN_DET,
> .dcin_collapse_limit = BD71828_REG_DCIN_CLPS,
> @@ -441,6 +446,7 @@ static int bd71828_charger_get_property(struct power_supply *psy,
> struct bd71828_power *pwr = dev_get_drvdata(psy->dev.parent);
> u32 vot;
> u16 tmp;
> + int t;
> int online;
> int ret;
>
> @@ -459,6 +465,20 @@ static int bd71828_charger_get_property(struct power_supply *psy,
> vot = tmp;
> /* 5 milli volt steps */
> val->intval = 5000 * vot;
> + break;
> + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> + if (!pwr->regs->ilim_stat)
> + return -ENODATA;
> +
> + ret = regmap_read(pwr->regmap, pwr->regs->ilim_stat, &t);
> + if (ret)
> + return ret;
> +
> + t++;
> + val->intval = (t & BD7182x_MASK_ILIM) * 50000;
> + if (val->intval > 2000000)
> + val->intval = 2000000;
I would have preferred using the linear-ranges here.
> +
> break;
> default:
> return -EINVAL;
> @@ -467,6 +487,45 @@ static int bd71828_charger_get_property(struct power_supply *psy,
> return 0;
> }
>
> +static int bd71828_charger_set_property(struct power_supply *psy,
> + enum power_supply_property psp,
> + const union power_supply_propval *val)
> +{
> + struct bd71828_power *pwr = dev_get_drvdata(psy->dev.parent);
> +
> + switch (psp) {
> + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> + if (val->intval > 2000000)
> + return -EINVAL;
> +
> + if (val->intval < 50000)
> + return -EINVAL;
> +
I would have preferred using the linear ranges here as well. That'd help
if we support this in the other variants.
> + if (!pwr->regs->dcin_set)
> + return -EINVAL;
> +
> + return regmap_update_bits(pwr->regmap, pwr->regs->dcin_set,
> + BD7182x_MASK_ILIM,
> + val->intval / 50000 - 1);
The "burning question" I have is - how well this has been verified? I
ask because the data-sheet version which I read (rev 0p17, DS2 draft)
marks this register as a read-only. I know my data-sheet, targeting the
design-sample 2 of bd71828 (not bd71879) is ancient. It may be this is
an error in the data-sheet but I had to ask anyways...
> + break;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int bd71828_charger_property_is_writeable(struct power_supply *psy,
> + enum power_supply_property psp)
> +{
> + struct bd71828_power *pwr = dev_get_drvdata(psy->dev.parent);
> +
> + switch (psp) {
> + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> + return !!(pwr->regs->dcin_set);
> + default:
> + return false;
> + }
> +}
> +
> static int bd71828_battery_get_property(struct power_supply *psy,
> enum power_supply_property psp,
> union power_supply_propval *val)
> @@ -571,6 +630,7 @@ static int bd71828_battery_property_is_writeable(struct power_supply *psy,
>
> /** @brief ac properties */
> static const enum power_supply_property bd71828_charger_props[] = {
> + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
> POWER_SUPPLY_PROP_ONLINE,
> POWER_SUPPLY_PROP_VOLTAGE_NOW,
> };
> @@ -600,6 +660,8 @@ static const struct power_supply_desc bd71828_ac_desc = {
> .properties = bd71828_charger_props,
> .num_properties = ARRAY_SIZE(bd71828_charger_props),
> .get_property = bd71828_charger_get_property,
> + .set_property = bd71828_charger_set_property,
> + .property_is_writeable = bd71828_charger_property_is_writeable,
> };
>
> static const struct power_supply_desc bd71828_bat_desc = {
>
> ---
> base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
> change-id: 20260401-bd-inp-limit-3acb51e15e9c
>
> Best regards,
> --
> Andreas Kemnade <andreas@kemnade.info>
Yours,
-- Matti
--
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] power: supply: bd71828: add input current limit property
2026-04-07 5:34 ` Matti Vaittinen
@ 2026-04-07 5:48 ` Matti Vaittinen
0 siblings, 0 replies; 7+ messages in thread
From: Matti Vaittinen @ 2026-04-07 5:48 UTC (permalink / raw)
To: Andreas Kemnade, Sebastian Reichel; +Cc: linux-pm, linux-kernel
On 07/04/2026 08:34, Matti Vaittinen wrote:
> On 02/04/2026 00:17, Andreas Kemnade wrote:
// snip
>> + .ilim_stat = BD71828_REG_ILIM_STAT,
>> .btemp_vth = BD71828_REG_VM_BTMP_U,
>> .chg_state = BD71828_REG_CHG_STATE,
>> .bat_temp = BD71828_REG_BAT_TEMP,
>> + .dcin_set = BD71828_REG_DCIN_SET,
>
> Hi Andreas / Sebastian,
>
> Sorry for belated review (although, I don't think this did float on the
> list quite THAT long...)
>
> I believe this is the ILIM_STAT register in the data sheet, at address
> 0x6d, right? (The bit field is named as: LIM_DCIN_STAT[5:0]). If so,
> then I have a follow-up question in the setter...
// snip
>> + return regmap_update_bits(pwr->regmap, pwr->regs->dcin_set,
>> + BD7182x_MASK_ILIM,
>> + val->intval / 50000 - 1);
>
> The "burning question" I have is - how well this has been verified? I
> ask because the data-sheet version which I read (rev 0p17, DS2 draft)
> marks this register as a read-only. I know my data-sheet, targeting the
> design-sample 2 of bd71828 (not bd71879) is ancient. It may be this is
> an error in the data-sheet but I had to ask anyways...
Please, ignore this bit. I somehow misread the patch. It is the DCIN_SET
which is used here, not the ILIM_STAT. Logic seems correct!
I would still prefer the linear-ranges, especially if other variants
support this. But the logic seems correct. Sorry for the noise.
Yours,
-- Matti
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] power: supply: bd71828: add input current limit property
2026-04-01 21:17 [PATCH] power: supply: bd71828: add input current limit property Andreas Kemnade
2026-04-02 22:54 ` Sebastian Reichel
2026-04-07 5:34 ` Matti Vaittinen
@ 2026-04-07 6:33 ` Matti Vaittinen
2026-04-15 20:13 ` Andreas Kemnade
2 siblings, 1 reply; 7+ messages in thread
From: Matti Vaittinen @ 2026-04-07 6:33 UTC (permalink / raw)
To: Andreas Kemnade, Sebastian Reichel; +Cc: linux-pm, linux-kernel
On 02/04/2026 00:17, Andreas Kemnade wrote:
> Add input current property to be able to work around issues created by
> automatic input limiting and have some control.
> Disabling the automatic management is another step.
>
Hi Andreas!
Long time no chat :)
First of all, thanks for the work you do with the BD71828/79! I do
admire the effort you're willing to put on it :)
I decided to just take a quick look at the BD71815 and BD72720, which
can be operated using the same driver. I didn't see similar control on
BD71815 data-sheet, so I just decided not to dig it further for now.
What comes to the BD72720, there is something:
The BD72720 has a VBUS_INLIM, which is a configurable current limit for
the bus. This, I believe does NOT directly correspond to the DCIN limit.
It _probably_ has similar impact when the DCIN is supplied, and when it
is powerful enough to run the system. However, I believe the VBUS
current limit is also having an impact when setup is powered from the
battery, or when it is in "battery assist" -mode, (where the battery is
used to "complement" the DCIN, if the DCIN isn't strong enough to power
the system).
I am afraid I don't know your use-case for the control of the DCIN input
limit well enough to decide, if the BD72720 would need something similar
- or if the VBUS_INLIM should be tied to the same knob. If you have the
enthusiasm to write some more words ... I am keen on learning! :)
Yours,
-- Matti
--
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] power: supply: bd71828: add input current limit property
2026-04-07 6:33 ` Matti Vaittinen
@ 2026-04-15 20:13 ` Andreas Kemnade
2026-04-17 7:33 ` Matti Vaittinen
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Kemnade @ 2026-04-15 20:13 UTC (permalink / raw)
To: Matti Vaittinen; +Cc: Sebastian Reichel, linux-pm, linux-kernel
On Tue, 7 Apr 2026 09:33:25 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> I am afraid I don't know your use-case for the control of the DCIN input
> limit well enough to decide, if the BD72720 would need something similar
> - or if the VBUS_INLIM should be tied to the same knob. If you have the
> enthusiasm to write some more words ... I am keen on learning! :)
Justification for this patch is mostly: there is a standard interface
for this functionality and the chip has that functionality.
The bigger picture: Attach a power source with changing properties causes
mess. To repreduce issues at my desk, I have played around with a labor power
supply with changeable current limitation, turining it down to zero (so
power is off) then turning it on slowly again, no charging will happen. My
usual way around such a problem is to clear DCIN_ILIM_EN (will add a sysfs
attribute for that) and set some conservative current.
Regards,
Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] power: supply: bd71828: add input current limit property
2026-04-15 20:13 ` Andreas Kemnade
@ 2026-04-17 7:33 ` Matti Vaittinen
0 siblings, 0 replies; 7+ messages in thread
From: Matti Vaittinen @ 2026-04-17 7:33 UTC (permalink / raw)
To: Andreas Kemnade; +Cc: Sebastian Reichel, linux-pm, linux-kernel
On 15/04/2026 23:13, Andreas Kemnade wrote:
> On Tue, 7 Apr 2026 09:33:25 +0300
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>
>> I am afraid I don't know your use-case for the control of the DCIN input
>> limit well enough to decide, if the BD72720 would need something similar
>> - or if the VBUS_INLIM should be tied to the same knob. If you have the
>> enthusiasm to write some more words ... I am keen on learning! :)
>
> Justification for this patch is mostly: there is a standard interface
> for this functionality and the chip has that functionality.
I wasn't doubting the justification for this patch. I was more like
wondering if the use-case of the functionality, toggled by the
interface, is such that BD72720 VBUS_INLIM should be tied to this same knob.
> The bigger picture: Attach a power source with changing properties causes
> mess. To repreduce issues at my desk, I have played around with a labor power
> supply with changeable current limitation, turining it down to zero (so
> power is off) then turning it on slowly again, no charging will happen. My
> usual way around such a problem is to clear DCIN_ILIM_EN (will add a sysfs
> attribute for that) and set some conservative current.
Right. I suppose deciding if the BD72720 should support changing the
VBUS_INLIM would require me to have the hardware to do some testing so I
could see how it behaves with variable charging currents. I don't
currently have that, and I haven't heard of any complaints. Furthermore,
AFAIR, there are some differences between the logic of BD71828 and
BD72720 (battery assisted mode in BD72720) - so they're not 100% same.
Hence, I won't touch the BD72720 for now.
Thanks for sharing the details!
Yours,
-- Matti
--
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-04-17 7:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 21:17 [PATCH] power: supply: bd71828: add input current limit property Andreas Kemnade
2026-04-02 22:54 ` Sebastian Reichel
2026-04-07 5:34 ` Matti Vaittinen
2026-04-07 5:48 ` Matti Vaittinen
2026-04-07 6:33 ` Matti Vaittinen
2026-04-15 20:13 ` Andreas Kemnade
2026-04-17 7:33 ` Matti Vaittinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox