From: Marek Vasut <marex@denx.de>
To: linux-pm@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Hans de Goede <hdegoede@redhat.com>,
Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: [PATCH] power: supply: bq25890: Add support for setting IINLIM
Date: Sat, 30 Jul 2022 20:06:30 +0200 [thread overview]
Message-ID: <20220730180630.152098-1-marex@denx.de> (raw)
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
---
drivers/power/supply/bq25890_charger.c | 30 ++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 131ec7d882fe9..e412bcf90b40c 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -613,6 +613,34 @@ 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);
+ u32 lval;
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ lval = clamp(val->intval, 100000, 3250000);
+ lval = DIV_ROUND_UP(lval - 100000, 50000);
+ 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 +865,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
next reply other threads:[~2022-07-30 18:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-30 18:06 Marek Vasut [this message]
2022-07-31 9:52 ` [PATCH] power: supply: bq25890: Add support for setting IINLIM Hans de Goede
2022-08-01 3:00 ` Marek Vasut
2022-08-01 7:15 ` Hans de Goede
2022-08-01 10:50 ` Marek Vasut
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=20220730180630.152098-1-marex@denx.de \
--to=marex@denx.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=linux-pm@vger.kernel.org \
--cc=sebastian.reichel@collabora.com \
/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