From patchwork Mon Aug 1 02:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12933348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CF08C00140 for ; Mon, 1 Aug 2022 02:57:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229569AbiHAC5r (ORCPT ); Sun, 31 Jul 2022 22:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238241AbiHAC5q (ORCPT ); Sun, 31 Jul 2022 22:57:46 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34A16DEFC for ; Sun, 31 Jul 2022 19:57:41 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 2954E8407F; Mon, 1 Aug 2022 04:57:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1659322658; bh=lBkpKVy/TRGRLwMMmH+MnR8dS+/6RFcbhJl6fcWc7Iw=; h=From:To:Cc:Subject:Date:From; b=V1F0ik0bCZMwh9Ufdn9OHoRBSPbUQiSWo6Q56SeC9CofHLCiKQYz03FSgQxjOnaXL fPiB4TRknjxLO48fX1Hdn9eAlOhdhC/jwMDhKyHhporwOtl+sbweUBbsdqe/QA+VvW 7+0Y8DNZ8ZMxhbjX1cp8AFA54IZmra78q5qRv+MpdP6mOExz7vG7F1BWwywlGDWouR U1PM8iiUVMbKwrL+bIeoXfWqZadfv7Rk+3H4bNd9htcx9df5HwY/q1+tR+r8gN+9BE ipf3uGDo8SIgVObccauVwhORBk+s2uS7CrzM1xLinftEmikffgI8/ePWdcyTdLGqH7 Kn69tz2vUTxRQ== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Hans de Goede , Sebastian Reichel Subject: [PATCH v2] power: supply: bq25890: Add support for setting IINLIM Date: Mon, 1 Aug 2022 04:57:27 +0200 Message-Id: <20220801025727.778218-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 Reviewed-by: Hans de Goede --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Sebastian Reichel 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)