[PATCH] power: supply: bq256xx: Remove init ichg/vbat with max value

Hermes Zhang posted 1 patch 2 years, 9 months ago
drivers/power/supply/bq256xx_charger.c | 10 ----------
1 file changed, 10 deletions(-)
[PATCH] power: supply: bq256xx: Remove init ichg/vbat with max value
Posted by Hermes Zhang 2 years, 9 months ago
Init the ichg and vbat reg with max value is not good. First the chip
already has a default value for ichg and vbat (small value). Init these
two reg with max value will result an unsafe case (e.g. battery is over
charging in a hot environment) if no user space change them later.

Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
---
 drivers/power/supply/bq256xx_charger.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
index 01ad84fd147c..d1aa92c10c22 100644
--- a/drivers/power/supply/bq256xx_charger.c
+++ b/drivers/power/supply/bq256xx_charger.c
@@ -1562,21 +1562,11 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
 	if (ret)
 		return ret;
 
-	ret = bq->chip_info->bq256xx_set_ichg(bq,
-				bat_info->constant_charge_current_max_ua);
-	if (ret)
-		return ret;
-
 	ret = bq->chip_info->bq256xx_set_iprechg(bq,
 				bat_info->precharge_current_ua);
 	if (ret)
 		return ret;
 
-	ret = bq->chip_info->bq256xx_set_vbatreg(bq,
-				bat_info->constant_charge_voltage_max_uv);
-	if (ret)
-		return ret;
-
 	ret = bq->chip_info->bq256xx_set_iterm(bq,
 				bat_info->charge_term_current_ua);
 	if (ret)
-- 
2.30.2
Re: [PATCH] power: supply: bq256xx: Remove init ichg/vbat with max value
Posted by Sebastian Reichel 2 years, 9 months ago
Hi,

On Tue, Nov 29, 2022 at 05:01:12PM +0800, Hermes Zhang wrote:
> Init the ichg and vbat reg with max value is not good. First the chip
> already has a default value for ichg and vbat (small value). Init these
> two reg with max value will result an unsafe case (e.g. battery is over
> charging in a hot environment) if no user space change them later.
> 
> Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
> ---

It's the driver's task to setup safe initial maximum values.
Pre-kernel values may or may not be safe if you consider things
like kexec. If you get unsafe values programmed, then fix the
values instead.

-- Sebastian

>  drivers/power/supply/bq256xx_charger.c | 10 ----------
>  1 file changed, 10 deletions(-)
> 
> diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
> index 01ad84fd147c..d1aa92c10c22 100644
> --- a/drivers/power/supply/bq256xx_charger.c
> +++ b/drivers/power/supply/bq256xx_charger.c
> @@ -1562,21 +1562,11 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
>  	if (ret)
>  		return ret;
>  
> -	ret = bq->chip_info->bq256xx_set_ichg(bq,
> -				bat_info->constant_charge_current_max_ua);
> -	if (ret)
> -		return ret;
> -
>  	ret = bq->chip_info->bq256xx_set_iprechg(bq,
>  				bat_info->precharge_current_ua);
>  	if (ret)
>  		return ret;
>  
> -	ret = bq->chip_info->bq256xx_set_vbatreg(bq,
> -				bat_info->constant_charge_voltage_max_uv);
> -	if (ret)
> -		return ret;
> -
>  	ret = bq->chip_info->bq256xx_set_iterm(bq,
>  				bat_info->charge_term_current_ua);
>  	if (ret)
> -- 
> 2.30.2
> 
Re: [PATCH] power: supply: bq256xx: Remove init ichg/vbat with max value
Posted by Hermes Zhang 2 years, 9 months ago
Hi,

在 2022/11/29 23:27, Sebastian Reichel 写道:
> Hi,
>
> On Tue, Nov 29, 2022 at 05:01:12PM +0800, Hermes Zhang wrote:
>> Init the ichg and vbat reg with max value is not good. First the chip
>> already has a default value for ichg and vbat (small value). Init these
>> two reg with max value will result an unsafe case (e.g. battery is over
>> charging in a hot environment) if no user space change them later.
>>
>> Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
>> ---
> It's the driver's task to setup safe initial maximum values.
> Pre-kernel values may or may not be safe if you consider things
> like kexec. If you get unsafe values programmed, then fix the
> values instead.
>
> -- Sebastian

The constant_charge_current_max_ua is either from dts or default value 
for each chip in the code, but I guess I could ot change them because it 
has their own meaning (it will be used to check if the setting is valid 
or not). Do you mean I can set some other value here instead of 
constant_xxx_max?

Best Regards,
Hermes


>>   drivers/power/supply/bq256xx_charger.c | 10 ----------
>>   1 file changed, 10 deletions(-)
>>
>> diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
>> index 01ad84fd147c..d1aa92c10c22 100644
>> --- a/drivers/power/supply/bq256xx_charger.c
>> +++ b/drivers/power/supply/bq256xx_charger.c
>> @@ -1562,21 +1562,11 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
>>   	if (ret)
>>   		return ret;
>>   
>> -	ret = bq->chip_info->bq256xx_set_ichg(bq,
>> -				bat_info->constant_charge_current_max_ua);
>> -	if (ret)
>> -		return ret;
>> -
>>   	ret = bq->chip_info->bq256xx_set_iprechg(bq,
>>   				bat_info->precharge_current_ua);
>>   	if (ret)
>>   		return ret;
>>   
>> -	ret = bq->chip_info->bq256xx_set_vbatreg(bq,
>> -				bat_info->constant_charge_voltage_max_uv);
>> -	if (ret)
>> -		return ret;
>> -
>>   	ret = bq->chip_info->bq256xx_set_iterm(bq,
>>   				bat_info->charge_term_current_ua);
>>   	if (ret)
>> -- 
>> 2.30.2
>>

Re: [PATCH] power: supply: bq256xx: Remove init ichg/vbat with max value
Posted by Sebastian Reichel 2 years, 9 months ago
Hi,

On Wed, Nov 30, 2022 at 09:27:42AM +0000, Hermes Zhang wrote:
> Hi,
> 
> 在 2022/11/29 23:27, Sebastian Reichel 写道:
> > Hi,
> >
> > On Tue, Nov 29, 2022 at 05:01:12PM +0800, Hermes Zhang wrote:
> >> Init the ichg and vbat reg with max value is not good. First the chip
> >> already has a default value for ichg and vbat (small value). Init these
> >> two reg with max value will result an unsafe case (e.g. battery is over
> >> charging in a hot environment) if no user space change them later.
> >>
> >> Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
> >> ---
> > It's the driver's task to setup safe initial maximum values.
> > Pre-kernel values may or may not be safe if you consider things
> > like kexec. If you get unsafe values programmed, then fix the
> > values instead.
> >
> > -- Sebastian
> 
> The constant_charge_current_max_ua is either from dts or default value 
> for each chip in the code, but I guess I could ot change them because it 
> has their own meaning (it will be used to check if the setting is valid 
> or not). Do you mean I can set some other value here instead of 
> constant_xxx_max?

You can just change the DT value to something safe as it is meant to be?

-- Sebastian