From patchwork Thu Mar 9 06:41:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hermes Zhang X-Patchwork-Id: 66613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp137535wrd; Wed, 8 Mar 2023 23:03:00 -0800 (PST) X-Google-Smtp-Source: AK7set+Q6/WIc2veINMmDxsxoPM7GbAWDQui5vmxkaKUehLj1heXmHIGvUXBpmeIECuqc9yH1aeR X-Received: by 2002:a05:6102:d93:b0:419:11b7:a8fa with SMTP id d19-20020a0561020d9300b0041911b7a8famr1231136vst.25.1678345380635; Wed, 08 Mar 2023 23:03:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678345380; cv=none; d=google.com; s=arc-20160816; b=zXjRlY80YJAGofC2IwE5dwH/manpXndnEIuaFgMlsHrgCwOn+I/e1W6tVNAHAcNnk/ 7ElynDXJr9zFpBgE+suBoOnF/2rQhQurX+rH3j+nZhSSS/UAYKz+pysbPESChPV8TfbH tCava/JiQ3fzkhZYpPOxWXaLeva5auTC7RX7D8Bkisg1AM5NMA2tP3KAdfxYQlYEi+kB 8Xm85wj4HU7zLmRm1qEK4tHUJgVzATo0eGdlYLwrPGzPj3jYBbwS2LehNot2ijEq6JiO 21FGOz4XMJSsvQYXvYVMEkDpZQG8gj3gnDQEe4OcT2XzzOzS1Sd7WkQTWno4kWKM1rMn j1cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YyvA9TXPf9GVqen8uKIEeEetOR39Q5lxbugDfV9IAuc=; b=qBxP1CL9RN5a8FV8Fn2Zoqzs/V91WhmgQrbrLviYyYl8I7YmKZ3x8e/w3UixkD3u+M 4kXvlyEkxUo2MJPsEuT20F3qFWjr0F9H88RguiAgYuTtkw8qRFQwbaygNrmISuv290nF JW380CshBX5vrZA39c1vUrFxordTxXoeDT1tAh+Lw27uH8+c/+ONjfaZY6g+pVRNemJo YnOsoeHziB+ntXmPZBWcp1rDhj9h8lWOMk1Xvs0FvRmiU8qtirwkRPBqaXX953jRuh7o JR0OPCqjvoCdhdJ8Dje18m1yH5k5yPmLYVQg9cZ4F/+mV1+chqAK6tv86U3UoNJmaeY+ Hpzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=WlSuLXXb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a056102066800b0041e91be80a3si5227497vsf.669.2023.03.08.23.02.42; Wed, 08 Mar 2023 23:03:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=WlSuLXXb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbjCIGmG (ORCPT + 99 others); Thu, 9 Mar 2023 01:42:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbjCIGl5 (ORCPT ); Thu, 9 Mar 2023 01:41:57 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E51F6A04D; Wed, 8 Mar 2023 22:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1678344103; x=1709880103; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YyvA9TXPf9GVqen8uKIEeEetOR39Q5lxbugDfV9IAuc=; b=WlSuLXXbAIv7652tAqjpynfaYlGLuyUIQ7uJU3b14IEGTsHBKfZNCYTl p4BOUvjvw2nqOSLiJEJK/+3ZwYA+7d3FtrSkD8P5lzIKdDEpu2VDpsUYk xVLaGCrvB0n4OX4P/aEstAZrgsrHGdGi/oVxUL+5gKV0jyvMrOOQeroM2 AHVWrZIyScsWQtRROV809ObdH/7oJStNVeyvgzWVcq35yHaqkuCVbnM7M H9OaZDwqJZQ02iaz1nXhxqzwXvFssqzIi6ojr0nU5LnbdoUTqmYxLF8jg YHA9KRgfM+4Y12J+c26rlBImzCPkU8ZGgO+LHa5gyc3vS4T22/7JcT/NU Q==; From: Hermes Zhang To: Sebastian Reichel CC: , Hermes Zhang , , Subject: [PATCH] power: supply: bq256xx: Support to disable charger Date: Thu, 9 Mar 2023 14:41:03 +0800 Message-ID: <20230309064104.79005-1-chenhuiz@axis.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759872685758325657?= X-GMAIL-MSGID: =?utf-8?q?1759872685758325657?= To be able to control the charging process flexible, we need to able to disable the charger. This commit will allow to disable the charger by "echo 1 > /sys/class/power_supply/bq256xx-charger/charge_type" (1 = POWER_SUPPLY_CHARGE_TYPE_NONE) and enable the charger by set it to 2/3 (POWER_SUPPLY_CHARGE_TYPE_TRICKLE/POWER_SUPPLY_CHARGE_TYPE_FAST) Signed-off-by: Hermes Zhang --- drivers/power/supply/bq256xx_charger.c | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c index 9cf4936440c9..e624834ae66c 100644 --- a/drivers/power/supply/bq256xx_charger.c +++ b/drivers/power/supply/bq256xx_charger.c @@ -70,6 +70,9 @@ #define BQ25611D_VBATREG_THRESH_uV 4290000 #define BQ25618_VBATREG_THRESH_uV 4300000 +#define BQ256XX_CHG_CONFIG_MASK BIT(4) +#define BQ256XX_CHG_CONFIG_BIT_SHIFT 4 + #define BQ256XX_ITERM_MASK GENMASK(3, 0) #define BQ256XX_ITERM_STEP_uA 60000 #define BQ256XX_ITERM_OFFSET_uA 60000 @@ -259,6 +262,7 @@ struct bq256xx_device { * @bq256xx_set_iterm: pointer to instance specific set_iterm function * @bq256xx_set_iprechg: pointer to instance specific set_iprechg function * @bq256xx_set_vindpm: pointer to instance specific set_vindpm function + * @bq256xx_set_charge_type: pointer to instance specific set_charge_type function * * @bq256xx_def_ichg: default ichg value in microamps * @bq256xx_def_iindpm: default iindpm value in microamps @@ -290,6 +294,7 @@ struct bq256xx_chip_info { int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm); int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg); int (*bq256xx_set_vindpm)(struct bq256xx_device *bq, int vindpm); + int (*bq256xx_set_charge_type)(struct bq256xx_device *bq, int type); int bq256xx_def_ichg; int bq256xx_def_iindpm; @@ -449,6 +454,27 @@ static int bq256xx_get_state(struct bq256xx_device *bq, return 0; } +static int bq256xx_set_charge_type(struct bq256xx_device *bq, int type) +{ + int chg_config = 0; + + switch (type) { + case POWER_SUPPLY_CHARGE_TYPE_NONE: + chg_config = 0x0; + break; + case POWER_SUPPLY_CHARGE_TYPE_TRICKLE: + case POWER_SUPPLY_CHARGE_TYPE_FAST: + chg_config = 0x1; + break; + default: + return -EINVAL; + } + + return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_0, + BQ256XX_CHG_CONFIG_MASK, + (chg_config ? 1 : 0) << BQ256XX_CHG_CONFIG_BIT_SHIFT); +} + static int bq256xx_get_ichg_curr(struct bq256xx_device *bq) { unsigned int charge_current_limit; @@ -915,6 +941,12 @@ static int bq256xx_set_charger_property(struct power_supply *psy, return ret; break; + case POWER_SUPPLY_PROP_CHARGE_TYPE: + ret = bq->chip_info->bq256xx_set_charge_type(bq, val->intval); + if (ret) + return ret; + break; + default: break; } @@ -1197,6 +1229,7 @@ static int bq256xx_property_is_writeable(struct power_supply *psy, case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: case POWER_SUPPLY_PROP_STATUS: case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT: + case POWER_SUPPLY_PROP_CHARGE_TYPE: return true; default: return false; @@ -1286,6 +1319,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1316,6 +1350,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1346,6 +1381,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1376,6 +1412,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1406,6 +1443,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ25611D_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1436,6 +1474,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq25618_619_set_term_curr, .bq256xx_set_iprechg = bq25618_619_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1466,6 +1505,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { .bq256xx_set_iterm = bq25618_619_set_term_curr, .bq256xx_set_iprechg = bq25618_619_set_prechrg_curr, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim, + .bq256xx_set_charge_type = bq256xx_set_charge_type, .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,