public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] power: supply: bq25890: Add support for setting IINLIM
@ 2022-08-01  2:57 Marek Vasut
  2022-08-01  7:15 ` Hans de Goede
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2022-08-01  2:57 UTC (permalink / raw)
  To: linux-pm; +Cc: Marek Vasut, Andy Shevchenko, Hans de Goede, Sebastian Reichel

Let user set input current limit via sysfs. This is useful in case there
are multiple chargers connected to the device, each of which with its own
arbitrary maximum current which it can provide, some of which may provide
more than the default 500mA. In that case, userspace can listen for plug
events generated by each charger and adjust the current limit accordingly,
e.g. to permit battery to charge faster.

Note that the IINLIM is reset every time the bq25890 is disconnected from
a charger, so the userspace must adjust the limit repeatly on every plug
event.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
To: linux-pm@vger.kernel.org
---
V2: Use bq25890_find_idx(val->intval, F_IINLIM) instead of ad-hoc division
---
 drivers/power/supply/bq25890_charger.c | 29 ++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 131ec7d882fe9..892609f9dd250 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -613,6 +613,33 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 	return 0;
 }
 
+static int bq25890_power_supply_set_property(struct power_supply *psy,
+					     enum power_supply_property psp,
+					     const union power_supply_propval *val)
+{
+	struct bq25890_device *bq = power_supply_get_drvdata(psy);
+	u8 lval;
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+		lval = bq25890_find_idx(val->intval, F_IINLIM);
+		return bq25890_field_write(bq, F_IINLIM, lval);
+	default:
+		return -EINVAL;
+	}
+}
+
+static int bq25890_power_supply_property_is_writeable(struct power_supply *psy,
+						      enum power_supply_property psp)
+{
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+		return true;
+	default:
+		return false;
+	}
+}
+
 static int bq25890_get_chip_state(struct bq25890_device *bq,
 				  struct bq25890_state *state)
 {
@@ -837,6 +864,8 @@ static const struct power_supply_desc bq25890_power_supply_desc = {
 	.properties = bq25890_power_supply_props,
 	.num_properties = ARRAY_SIZE(bq25890_power_supply_props),
 	.get_property = bq25890_power_supply_get_property,
+	.set_property = bq25890_power_supply_set_property,
+	.property_is_writeable = bq25890_power_supply_property_is_writeable,
 };
 
 static int bq25890_power_supply_init(struct bq25890_device *bq)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] power: supply: bq25890: Add support for setting IINLIM
  2022-08-01  2:57 [PATCH v2] power: supply: bq25890: Add support for setting IINLIM Marek Vasut
@ 2022-08-01  7:15 ` Hans de Goede
  2022-08-23 15:59   ` Marek Vasut
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2022-08-01  7:15 UTC (permalink / raw)
  To: Marek Vasut, linux-pm; +Cc: Andy Shevchenko, Sebastian Reichel

Hi,

On 8/1/22 04:57, Marek Vasut wrote:
> Let user set input current limit via sysfs. This is useful in case there
> are multiple chargers connected to the device, each of which with its own
> arbitrary maximum current which it can provide, some of which may provide
> more than the default 500mA. In that case, userspace can listen for plug
> events generated by each charger and adjust the current limit accordingly,
> e.g. to permit battery to charge faster.
> 
> Note that the IINLIM is reset every time the bq25890 is disconnected from
> a charger, so the userspace must adjust the limit repeatly on every plug
> event.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
> To: linux-pm@vger.kernel.org
> ---
> V2: Use bq25890_find_idx(val->intval, F_IINLIM) instead of ad-hoc division
> ---
>  drivers/power/supply/bq25890_charger.c | 29 ++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
> index 131ec7d882fe9..892609f9dd250 100644
> --- a/drivers/power/supply/bq25890_charger.c
> +++ b/drivers/power/supply/bq25890_charger.c
> @@ -613,6 +613,33 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
>  	return 0;
>  }
>  
> +static int bq25890_power_supply_set_property(struct power_supply *psy,
> +					     enum power_supply_property psp,
> +					     const union power_supply_propval *val)
> +{
> +	struct bq25890_device *bq = power_supply_get_drvdata(psy);
> +	u8 lval;
> +
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> +		lval = bq25890_find_idx(val->intval, F_IINLIM);
> +		return bq25890_field_write(bq, F_IINLIM, lval);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int bq25890_power_supply_property_is_writeable(struct power_supply *psy,
> +						      enum power_supply_property psp)
> +{
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
>  static int bq25890_get_chip_state(struct bq25890_device *bq,
>  				  struct bq25890_state *state)
>  {
> @@ -837,6 +864,8 @@ static const struct power_supply_desc bq25890_power_supply_desc = {
>  	.properties = bq25890_power_supply_props,
>  	.num_properties = ARRAY_SIZE(bq25890_power_supply_props),
>  	.get_property = bq25890_power_supply_get_property,
> +	.set_property = bq25890_power_supply_set_property,
> +	.property_is_writeable = bq25890_power_supply_property_is_writeable,
>  };
>  
>  static int bq25890_power_supply_init(struct bq25890_device *bq)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] power: supply: bq25890: Add support for setting IINLIM
  2022-08-01  7:15 ` Hans de Goede
@ 2022-08-23 15:59   ` Marek Vasut
  2022-09-11 12:43     ` Sebastian Reichel
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2022-08-23 15:59 UTC (permalink / raw)
  To: Hans de Goede, linux-pm; +Cc: Andy Shevchenko, Sebastian Reichel

On 8/1/22 09:15, Hans de Goede wrote:
> Hi,

Hi,

> On 8/1/22 04:57, Marek Vasut wrote:
>> Let user set input current limit via sysfs. This is useful in case there
>> are multiple chargers connected to the device, each of which with its own
>> arbitrary maximum current which it can provide, some of which may provide
>> more than the default 500mA. In that case, userspace can listen for plug
>> events generated by each charger and adjust the current limit accordingly,
>> e.g. to permit battery to charge faster.
>>
>> Note that the IINLIM is reset every time the bq25890 is disconnected from
>> a charger, so the userspace must adjust the limit repeatly on every plug
>> event.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
> 
> Thanks, patch looks good to me:
> 
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Can this be applied now ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] power: supply: bq25890: Add support for setting IINLIM
  2022-08-23 15:59   ` Marek Vasut
@ 2022-09-11 12:43     ` Sebastian Reichel
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2022-09-11 12:43 UTC (permalink / raw)
  To: Marek Vasut; +Cc: Hans de Goede, linux-pm, Andy Shevchenko

[-- Attachment #1: Type: text/plain, Size: 1300 bytes --]

Hi,

On Tue, Aug 23, 2022 at 05:59:33PM +0200, Marek Vasut wrote:
> On 8/1/22 09:15, Hans de Goede wrote:
> > On 8/1/22 04:57, Marek Vasut wrote:
> > > Let user set input current limit via sysfs. This is useful in case there
> > > are multiple chargers connected to the device, each of which with its own
> > > arbitrary maximum current which it can provide, some of which may provide
> > > more than the default 500mA. In that case, userspace can listen for plug
> > > events generated by each charger and adjust the current limit accordingly,
> > > e.g. to permit battery to charge faster.
> > > 
> > > Note that the IINLIM is reset every time the bq25890 is disconnected from
> > > a charger, so the userspace must adjust the limit repeatly on every plug
> > > event.
> > > 
> > > Signed-off-by: Marek Vasut <marex@denx.de>
> > 
> > Thanks, patch looks good to me:
> > 
> > Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> 
> Can this be applied now ?

Thanks, queued to power-supply's for-next branch.

Please make sure you are sending patches based on recent for-next
branch next time. Your patch was from before eab25b4f93aa ("power:
supply: bq25890: On the bq25892 set the IINLIM based on external
charger detection") which was added in 5.18 :(

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-11 12:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-01  2:57 [PATCH v2] power: supply: bq25890: Add support for setting IINLIM Marek Vasut
2022-08-01  7:15 ` Hans de Goede
2022-08-23 15:59   ` Marek Vasut
2022-09-11 12:43     ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox