power: supply: bq25890: Add support for setting IINLIM
PATCH v2 1/1 power: supply: bq25890: Add support for setting IINLIM
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.
---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
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(+)
drivers/power/supply/bq25890_charger.c +29 -0
@@ -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)
Signature · 1 line
2.35.1
Hi,
Quoted 7 lines · Marek Vasut
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.
Quoted 5 lines
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 <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 58 lines
---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Usebq25890_find_idx(val->intval, F_IINLIM)instead of ad-hoc division--- drivers/power/supply/bq25890_charger.c | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)drivers/power/supply/bq25890_charger.c +29
-0@@ -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)
Quoted 1 line · Hans de Goede
Hi,
Hi,
Quoted 12 lines · Marek Vasut
Quoted 11 lines
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.
Quoted 5 lines
Quoted 1 line
Signed-off-by Marek Vasut <[email protected]>Thanks, patch looks good to me:
Reviewed-by Hans de Goede <[email protected]>
Can this be applied now ?
Hi,
Quoted 13 lines · Marek Vasut
Quoted 12 lines · Hans de Goede
Quoted 11 lines · Marek Vasut
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.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Marek Vasut <[email protected]>Thanks, patch looks good to me:
Reviewed-by Hans de Goede <[email protected]>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