linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Chris Morgan <macroalpha82@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-sunxi@lists.linux.dev, linux-pm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com,
	mripard@kernel.org, tgamblin@baylibre.com,
	aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de,
	lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com,
	sre@kernel.org, wens@csie.org, conor+dt@kernel.org,
	krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de,
	Chris Morgan <macromorgan@hotmail.com>,
	Philippe Simons <simons.philippe@gmail.com>
Subject: Re: [PATCH V2 14/15] power: supply: axp20x_battery: add support for AXP717
Date: Wed, 14 Aug 2024 16:13:01 -0500	[thread overview]
Message-ID: <66bd1ddf.ca0a0220.13e5d4.8871@mx.google.com> (raw)
In-Reply-To: <20240803121044.20481897@jic23-huawei>

On Sat, Aug 03, 2024 at 12:10:44PM +0100, Jonathan Cameron wrote:
> On Fri,  2 Aug 2024 14:20:25 -0500
> Chris Morgan <macroalpha82@gmail.com> wrote:
> 
> > From: Chris Morgan <macromorgan@hotmail.com>
> > 
> > Add support for the AXP717 PMIC battery charger. The AXP717 differs
> > greatly from existing AXP battery chargers in that it cannot measure
> > the discharge current. The datasheet does not document the current
> > value's offset or scale, so the POWER_SUPPLY_PROP_CURRENT_NOW is left
> > unscaled.
> > 
> > Tested-by: Philippe Simons <simons.philippe@gmail.com>
> > Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> Hi.
> 
> A few drive by comments,
> 
> Jonathan
> 
> > ---
> >  drivers/power/supply/axp20x_battery.c | 444 ++++++++++++++++++++++++++
> >  1 file changed, 444 insertions(+)
> > 
> > diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> > index c903c588b361..53af4ad0549d 100644
> > --- a/drivers/power/supply/axp20x_battery.c
> > +++ b/drivers/power/supply/axp20x_battery.c
> > @@ -32,9 +32,19 @@
> >  #include <linux/mfd/axp20x.h>
> >  
> >  #define AXP20X_PWR_STATUS_BAT_CHARGING	BIT(2)
> > +#define AXP717_PWR_STATUS_MASK		GENMASK(6, 5)
> > +#define AXP717_PWR_STATUS_BAT_STANDBY	(0 << 5)
> > +#define AXP717_PWR_STATUS_BAT_CHRG	(1 << 5)
> > +#define AXP717_PWR_STATUS_BAT_DISCHRG	(2 << 5)
> 
> Fine to match local style in this patch, but just thought I'd
> comment that this driver would probably be more readable with
> use of FIELD_PREP and changing convention to not shift the defined
> values for contents of each field.
> 
> To change to that it would either need to be before this patch,
> or done as a follow up.

I'll take your other comments and apply them, but if it's okay with
you I'll opt to not use FIELD_PREP/FIELD_GET for the moment, so the
style remains the same. I will make sure to use those macros for
other drivers I'm working on though as they seem handy.

> 
> 
> >  struct axp20x_batt_ps;
> >  
> > @@ -143,6 +176,41 @@ static int axp22x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
> >  	return 0;
> >  }
> >  
> > +static int axp717_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
> > +					  int *val)
> > +{
> > +	int ret, reg;
> > +
> > +	ret = regmap_read(axp20x_batt->regmap, AXP717_CV_CHG_SET, &reg);
> > +	if (ret)
> > +		return ret;
> > +
> > +	switch (reg & AXP717_CHRG_CV_VOLT_MASK) {
> > +	case AXP717_CHRG_CV_4_0V:
> > +		*val = 4000000;
> > +		break;
> > +	case AXP717_CHRG_CV_4_1V:
> > +		*val = 4100000;
> > +		break;
> > +	case AXP717_CHRG_CV_4_2V:
> > +		*val = 4200000;
> > +		break;
> > +	case AXP717_CHRG_CV_4_35V:
> > +		*val = 4350000;
> > +		break;
> > +	case AXP717_CHRG_CV_4_4V:
> > +		*val = 4400000;
> > +		break;
> > +	case AXP717_CHRG_CV_5_0V:
> > +		*val = 5000000;
> > +		break;
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +
> > +	return 0;
> Could just return instead of breaking an save reader having to look to see
> if anything else happens after the switch finishes.

Acknowledged.

> 
> > +}
> > +
> >  static int axp813_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
> >  					  int *val)
> >  {
> > @@ -188,6 +256,22 @@ static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp,
> >  	return 0;
> >  }
> >  
> > +static int axp717_get_constant_charge_current(struct axp20x_batt_ps *axp,
> > +					      int *val)
> > +{
> > +	int ret;
> > +
> > +	ret = regmap_read(axp->regmap, AXP717_ICC_CHG_SET, val);
> Trivial but I'd use a separate local variable for the register value.  

Will do.

> > +	if (ret)
> > +		return ret;
> > +
> > +	*val &= AXP717_ICC_CHARGER_LIM_MASK;
> 
> FIELD_GET() would be much more readable here as we'd not need to go
> check if LIM_MASK included bit 0 and it could be used directly inline
> with the below as
> 

Nack, if that's okay (as mentioned above). If it's not let me know and
I'll go back and redo this driver.

> 	*val = FIELD_GET(AXP717_IC_CHARGER_LIM_MASK, val) * axp->data->ccc_scale;
> 
> > +
> > +	*val = *val * axp->data->ccc_scale;
> > +
> > +	return 0;
> > +}
> > +
> >  static int axp20x_battery_get_prop(struct power_supply *psy,
> >  				   enum power_supply_property psp,
> >  				   union power_supply_propval *val)
> > @@ -340,6 +424,175 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
> >  	return 0;
> >  }
> >  
> > +static int axp717_battery_get_prop(struct power_supply *psy,
> > +				   enum power_supply_property psp,
> > +				   union power_supply_propval *val)
> > +{
> > +	struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
> > +	int ret = 0, reg;
> > +
> > +	switch (psp) {
> > +	case POWER_SUPPLY_PROP_PRESENT:
> > +	case POWER_SUPPLY_PROP_ONLINE:
> > +		ret = regmap_read(axp20x_batt->regmap, AXP717_ON_INDICATE,
> > +				  &reg);
> > +		if (ret)
> > +			return ret;
> > +
> > +		val->intval = !!(reg & AXP717_PWR_OP_BATT_PRESENT);
> 
> FIELD_GET() here would be cleaner.
> 
> > +		break;
> > +
> >;
> > +	}
> > +
> > +	return 0;
> 
> As nothing to do down here, I think early returns would make things more redabel.
> 

Will do.

> > +}
> > +
> >  static int axp20x_battery_set_prop(struct power_supply *psy,
> >  				   enum power_supply_property psp,
> >  				   const union power_supply_propval *val)
> > @@ -492,6 +805,42 @@ static int axp20x_battery_set_prop(struct power_supply *psy,
> >  	}
> >  }
> >  
> > +static int axp717_battery_set_prop(struct power_supply *psy,
> > +				   enum power_supply_property psp,
> > +				   const union power_supply_propval *val)
> > +{
> > +	struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
> > +
> > +	switch (psp) {
> > +	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
> > +		return axp717_set_voltage_min_design(axp20x_batt, val->intval);
> > +
> > +	case POWER_SUPPLY_PROP_VOLTAGE_MAX:
> > +		return axp20x_batt->data->set_max_voltage(axp20x_batt, val->intval);
> > +
> > +	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
> > +		return axp717_set_constant_charge_current(axp20x_batt,
> > +							  val->intval);
> > +	case POWER_SUPPLY_PROP_STATUS:
> > +		switch (val->intval) {
> > +		case POWER_SUPPLY_STATUS_CHARGING:
> > +			return regmap_update_bits(axp20x_batt->regmap,
> > +						  AXP717_MODULE_EN_CONTROL_2,
> > +						  AXP717_CHRG_ENABLE,
> > +						  AXP717_CHRG_ENABLE);
> > +
> > +		case POWER_SUPPLY_STATUS_DISCHARGING:
> > +		case POWER_SUPPLY_STATUS_NOT_CHARGING:
> > +			return regmap_update_bits(axp20x_batt->regmap,
> > +						  AXP717_MODULE_EN_CONTROL_2,
> > +						  AXP717_CHRG_ENABLE, 0);
> > +		}
> > +		fallthrough;
> Why bother? Just return -EINVAL here.
> 

Will do.

> > +	default:
> > +		return -EINVAL;
> > +	}
> > +}
> > +

Thank you for your review,
Chris


  reply	other threads:[~2024-08-14 21:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02 19:20 [PATCH V2 00/15] Add Battery and USB Supply for AXP717 Chris Morgan
2024-08-02 19:20 ` [PATCH V2 01/15] iio: adc: axp20x_adc: Add adc_en1 and adc_en1 to axp_data Chris Morgan
2024-08-03 10:58   ` Jonathan Cameron
2024-08-02 19:20 ` [PATCH V2 02/15] power: supply: axp20x_battery: Remove design from min and max voltage Chris Morgan
2024-08-02 19:20 ` [PATCH V2 03/15] power: supply: axp20x_battery: Make iio and battery config per device Chris Morgan
2024-08-02 19:20 ` [PATCH V2 04/15] power: supply: axp20x_usb_power: Make VBUS and IIO " Chris Morgan
2024-08-02 19:20 ` [PATCH V2 05/15] dt-bindings: power: supply: axp20x: Add input-current-limit-microamp Chris Morgan
2024-08-04 15:37   ` Krzysztof Kozlowski
2024-08-02 19:20 ` [PATCH V2 06/15] power: supply: axp20x_usb_power: add input-current-limit-microamp Chris Morgan
2024-08-02 19:20 ` [PATCH V2 07/15] dt-bindings: power: supply: axp20x-battery: Add monitored-battery Chris Morgan
2024-08-04 15:38   ` Krzysztof Kozlowski
2024-08-02 19:20 ` [PATCH V2 08/15] dt-bindings: iio: adc: Add AXP717 compatible Chris Morgan
2024-08-03 10:59   ` Jonathan Cameron
2024-08-02 19:20 ` [PATCH V2 09/15] dt-bindings: power: supply: axp20x: " Chris Morgan
2024-08-04 15:38   ` Krzysztof Kozlowski
2024-08-02 19:20 ` [PATCH V2 10/15] " Chris Morgan
2024-08-04 15:38   ` Krzysztof Kozlowski
2024-08-02 19:20 ` [PATCH V2 11/15] mfd: axp20x: Add ADC, BAT, and USB cells for AXP717 Chris Morgan
2024-08-02 19:20 ` [PATCH V2 12/15] iio: adc: axp20x_adc: add support for AXP717 ADC Chris Morgan
2024-08-03 11:00   ` Jonathan Cameron
2024-08-02 19:20 ` [PATCH V2 13/15] power: supply: axp20x_usb_power: Add support for AXP717 Chris Morgan
2024-08-02 19:20 ` [PATCH V2 14/15] power: supply: axp20x_battery: add " Chris Morgan
2024-08-03 11:10   ` Jonathan Cameron
2024-08-14 21:13     ` Chris Morgan [this message]
2024-08-17  9:59       ` Jonathan Cameron
2024-08-02 19:20 ` [PATCH V2 15/15] arm64: dts: allwinner: h700: Add charger for Anbernic RG35XX Chris Morgan

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=66bd1ddf.ca0a0220.13e5d4.8871@mx.google.com \
    --to=macroalpha82@gmail.com \
    --cc=aidanmacdonald.0x0@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=macromorgan@hotmail.com \
    --cc=mripard@kernel.org \
    --cc=quentin.schulz@free-electrons.com \
    --cc=robh@kernel.org \
    --cc=samuel@sholland.org \
    --cc=simons.philippe@gmail.com \
    --cc=sre@kernel.org \
    --cc=tgamblin@baylibre.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wens@csie.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;
as well as URLs for NNTP newsgroup(s).