From patchwork Mon Feb 20 07:45:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hermes Zhang X-Patchwork-Id: 59301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1182979wrn; Sun, 19 Feb 2023 23:59:07 -0800 (PST) X-Google-Smtp-Source: AK7set/m/N3L0+OPwPuoyJu2/xFW+Fm+wVxr2lGNC9v0saqF7oAh0VOsG6p3aW+jbu5luNiYnpEx X-Received: by 2002:a05:6402:4c6:b0:4ab:4569:4b9f with SMTP id n6-20020a05640204c600b004ab45694b9fmr1881726edw.0.1676879947689; Sun, 19 Feb 2023 23:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676879947; cv=none; d=google.com; s=arc-20160816; b=d+NaMD4ntVmce3unDuB/zhMMlALgcPj+udfreYTrWKr5PRgb/7XTfuxF2MtZYt0OQi 7AUlshxtzo7zGmMvD5sNXQgDVN44gTDFwPF5O8JtfK5/J+XvPU6YAtyiCCw4wgRD+K33 ZyDeIx/kac/2NrhF73HGB07O1g+GYL0F9r5nqttKgxmCr1RC9MmVy0ELmizUX58CP1Fy lWvCkpoTRqgGCyvHgEaqVwlSG9bzAmwxtoQwcRBMtxKTDFRsesM3jJl3Pru7uSjcDZs+ WFgrjnuN0a+UVk1z8UyOBZiUo1vrTi2cB/0uIvZFsFZAxZlj7/DyLVSSQXDq+pAZqHXq E0mw== 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=5yPWroyn3aNHh9K3OX8yo+biaUW5/hlX8pX089G89tg=; b=qunI1438kh3VWx9LYKPWLJuKzYI/Uiou4MliqNLiQ3lVmc+vqIk0JxgjrOgxehzPW7 Ih6rL1pDapIu2l5TrwzTpQvrjMF4mMakKNC72XDjI/88JyTpMOkJMSn9JOrzgnJwX9n6 yy+vzw8jlg3F6clnDvvLrRVFPepXn1/1SWZi2ZWfLWfRJCx0zuSXKgwnknVJsOcTCae8 dSR5fCs6W12z04aBRLvBZK8dmJDtC8G5g0jCYKxHK4Wb6M0GyuSU8avVKeLnkdnO0Ngg 2B726zP3l53Ff0FReBcBuRLoeVs3msKeREPLrYyO6sO9sFKgxyZvmpR7UhxSegybwv5R pHIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=VtAOtBOK; 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 y3-20020aa7c243000000b004ad7cfe06e2si6398550edo.199.2023.02.19.23.58.43; Sun, 19 Feb 2023 23:59:07 -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=VtAOtBOK; 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 S230258AbjBTHqS (ORCPT + 99 others); Mon, 20 Feb 2023 02:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjBTHqR (ORCPT ); Mon, 20 Feb 2023 02:46:17 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4C48C155; Sun, 19 Feb 2023 23:46:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1676879175; x=1708415175; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5yPWroyn3aNHh9K3OX8yo+biaUW5/hlX8pX089G89tg=; b=VtAOtBOKlFiKbvfzfhjHy+lWcsU1oJQgZAlgGE7VOWgPgtqnflpNT/UX Nbc/EsxcyFFoNjxK+ufVlnHRgbl/Ugqf1TrWpo27xEBAkrsUQS52pxzRj 2u9CgvZjYBqsgKslt/o3ijrRGoY7aw7bRBunAIJzOfLEbNDsw5wa9pYY8 7rijzzImeLbLglYegY28gkgQzun+MQwEXgMcOy23KG3HTBJPEtIuZZ8lu DsWOZ/cRlr8MUMsgqS3yF7v7u7Bvm+RDwDGwpZDGw9mMgZDaORUo/o/IG Xc9vIM8uByR/x444DvWh/sWmIxI547uNCxfr5vUxZ242J3PIwyhIjy8gR w==; From: Hermes Zhang To: Sebastian Reichel CC: , Hermes Zhang , , Subject: [PATCH] power: supply: bq256xx: Support enter shipping mode Date: Mon, 20 Feb 2023 15:45:30 +0800 Message-ID: <20230220074531.2092495-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?1758336068011015807?= X-GMAIL-MSGID: =?utf-8?q?1758336068011015807?= Enable shipping mode for bq256xx chip. The shipping mode can be enabled by echo 0 > /sys/class/power_supply/bq256xx-charger/online. Signed-off-by: Hermes Zhang --- drivers/power/supply/bq256xx_charger.c | 35 ++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c index db13e288e439..c01ef9d26d31 100644 --- a/drivers/power/supply/bq256xx_charger.c +++ b/drivers/power/supply/bq256xx_charger.c @@ -115,6 +115,9 @@ #define BQ256XX_VBUS_STAT_USB_DCP (BIT(6) | BIT(5)) #define BQ256XX_VBUS_STAT_USB_OTG (BIT(7) | BIT(6) | BIT(5)) +#define BQ256XX_BATFET_DISABLE_MASK BIT(5) +#define BQ256XX_BATFET_DISABLE_BIT_SHIFT 5 + #define BQ256XX_CHRG_STAT_MASK GENMASK(4, 3) #define BQ256XX_CHRG_STAT_NOT_CHRGING 0 #define BQ256XX_CHRG_STAT_PRECHRGING BIT(3) @@ -290,6 +293,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_online)(struct bq256xx_device *bq, bool online); int bq256xx_def_ichg; int bq256xx_def_iindpm; @@ -425,6 +429,7 @@ static int bq256xx_get_state(struct bq256xx_device *bq, { unsigned int charger_status_0; unsigned int charger_status_1; + unsigned int charger_control_3; int ret; ret = regmap_read(bq->regmap, BQ256XX_CHARGER_STATUS_0, @@ -437,9 +442,15 @@ static int bq256xx_get_state(struct bq256xx_device *bq, if (ret) return ret; + ret = regmap_read(bq->regmap, BQ256XX_CHARGER_CONTROL_3, + &charger_control_3); + if (ret) + return ret; + state->vbus_stat = charger_status_0 & BQ256XX_VBUS_STAT_MASK; state->chrg_stat = charger_status_0 & BQ256XX_CHRG_STAT_MASK; - state->online = charger_status_0 & BQ256XX_PG_STAT_MASK; + state->online = (charger_status_0 & BQ256XX_PG_STAT_MASK) + && !(charger_control_3 & BQ256XX_BATFET_DISABLE_MASK); state->wdt_fault = charger_status_1 & BQ256XX_WDT_FAULT_MASK; state->bat_fault = charger_status_1 & BQ256XX_BAT_FAULT_MASK; @@ -702,6 +713,13 @@ static int bq256xx_set_prechrg_curr(struct bq256xx_device *bq, int iprechg) BQ256XX_IPRECHG_MASK, iprechg_reg_code); } +static int bq256xx_set_online(struct bq256xx_device *bq, bool online) +{ + return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_3, + BQ256XX_BATFET_DISABLE_MASK, + (online ? 0 : 1) << BQ256XX_BATFET_DISABLE_BIT_SHIFT); +} + static int bq25618_619_get_prechrg_curr(struct bq256xx_device *bq) { unsigned int prechg_and_term_curr_lim; @@ -915,6 +933,11 @@ static int bq256xx_set_charger_property(struct power_supply *psy, return ret; break; + case POWER_SUPPLY_PROP_ONLINE: + ret = bq->chip_info->bq256xx_set_online(bq, val->intval); + if (ret) + return ret; + break; default: break; } @@ -1197,6 +1220,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_ONLINE: return true; default: return false; @@ -1229,7 +1253,7 @@ static bool bq256xx_is_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { case BQ256XX_INPUT_CURRENT_LIMIT: - case BQ256XX_CHARGER_STATUS_0...BQ256XX_CHARGER_STATUS_2: + case BQ256XX_CHARGER_CONTROL_3...BQ256XX_CHARGER_STATUS_2: return true; default: return false; @@ -1286,6 +1310,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1316,6 +1341,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1346,6 +1372,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1376,6 +1403,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1406,6 +1434,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ25611D_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1436,6 +1465,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, @@ -1466,6 +1496,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_online = bq256xx_set_online, .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,