public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Andreas Kemnade <andreas@kemnade.info>,
	Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] power: supply: bd71828: add input current limit property
Date: Tue, 7 Apr 2026 08:34:12 +0300	[thread overview]
Message-ID: <16340915-f63f-41f7-b68f-6208120d9c09@gmail.com> (raw)
In-Reply-To: <20260401-bd-inp-limit-v1-1-689eb22531e2@kemnade.info>

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! ~~

  parent reply	other threads:[~2026-04-07  5:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-04-07  5:48   ` Matti Vaittinen
2026-04-07  6:33 ` Matti Vaittinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16340915-f63f-41f7-b68f-6208120d9c09@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=andreas@kemnade.info \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox