From patchwork Tue Jul 6 19:55:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Meneguele X-Patchwork-Id: 470674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90F75C07E96 for ; Tue, 6 Jul 2021 19:55:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 790FF61C5B for ; Tue, 6 Jul 2021 19:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbhGFT63 (ORCPT ); Tue, 6 Jul 2021 15:58:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39994 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbhGFT63 (ORCPT ); Tue, 6 Jul 2021 15:58:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625601350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K4iYqWImM1l/eHMp4+ECi30Nkvth8XA31wOblPl7aIY=; b=NFMdjVohNXHl0cjh9eSn4v34aKYEAozib7KcVcusw6c/B3SgTlFJEAexrYO9VT8Fka/9qY UFUsGUWeEjZMv/CjZN9feWIZPHXyWgLTBYwtZDs4Tz6MfrDotERZWssn3+ddqpSoYhWzi5 wIT9/knzgaA3uHpFCse0UkwMBY/T7Ys= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-pZM1Ede2MvajXIyrHkrRRg-1; Tue, 06 Jul 2021 15:55:48 -0400 X-MC-Unique: pZM1Ede2MvajXIyrHkrRRg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A02E71084F57; Tue, 6 Jul 2021 19:55:47 +0000 (UTC) Received: from localhost (ovpn-113-53.rdu2.redhat.com [10.10.113.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34E545C1D5; Tue, 6 Jul 2021 19:55:40 +0000 (UTC) From: Bruno Meneguele To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Bruno Meneguele Subject: [PATCH v2 1/2] power: supply: bq24735: reorganize ChargeOption command macros Date: Tue, 6 Jul 2021 16:55:26 -0300 Message-Id: <20210706195527.371108-2-bmeneg@redhat.com> In-Reply-To: <20210706195527.371108-1-bmeneg@redhat.com> References: <20210706195527.371108-1-bmeneg@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Rename ChargeOption macros to match the others for ChargeCurrent and ChargeVoltage and also separate the command & masks macros from the bits of interest macros for each command. This macro doesn't introduce any functional change, only code re-org. Signed-off-by: Bruno Meneguele --- drivers/power/supply/bq24735-charger.c | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index b5d619db79f6..3ce36d09c017 100644 --- a/drivers/power/supply/bq24735-charger.c +++ b/drivers/power/supply/bq24735-charger.c @@ -31,9 +31,8 @@ #include -#define BQ24735_CHG_OPT 0x12 -#define BQ24735_CHG_OPT_CHARGE_DISABLE (1 << 0) -#define BQ24735_CHG_OPT_AC_PRESENT (1 << 4) +/* BQ24735 available commands and their respective masks */ +#define BQ24735_CHARGE_OPT 0x12 #define BQ24735_CHARGE_CURRENT 0x14 #define BQ24735_CHARGE_CURRENT_MASK 0x1fc0 #define BQ24735_CHARGE_VOLTAGE 0x15 @@ -43,6 +42,10 @@ #define BQ24735_MANUFACTURER_ID 0xfe #define BQ24735_DEVICE_ID 0xff +/* ChargeOptions bits of interest */ +#define BQ24735_CHARGE_OPT_CHG_DISABLE (1 << 0) +#define BQ24735_CHARGE_OPT_AC_PRESENT (1 << 4) + struct bq24735 { struct power_supply *charger; struct power_supply_desc charger_desc; @@ -167,8 +170,8 @@ static inline int bq24735_enable_charging(struct bq24735 *charger) if (ret) return ret; - return bq24735_update_word(charger->client, BQ24735_CHG_OPT, - BQ24735_CHG_OPT_CHARGE_DISABLE, 0); + return bq24735_update_word(charger->client, BQ24735_CHARGE_OPT, + BQ24735_CHARGE_OPT_CHG_DISABLE, 0); } static inline int bq24735_disable_charging(struct bq24735 *charger) @@ -176,9 +179,9 @@ static inline int bq24735_disable_charging(struct bq24735 *charger) if (charger->pdata->ext_control) return 0; - return bq24735_update_word(charger->client, BQ24735_CHG_OPT, - BQ24735_CHG_OPT_CHARGE_DISABLE, - BQ24735_CHG_OPT_CHARGE_DISABLE); + return bq24735_update_word(charger->client, BQ24735_CHARGE_OPT, + BQ24735_CHARGE_OPT_CHG_DISABLE, + BQ24735_CHARGE_OPT_CHG_DISABLE); } static bool bq24735_charger_is_present(struct bq24735 *charger) @@ -188,14 +191,14 @@ static bool bq24735_charger_is_present(struct bq24735 *charger) } else { int ac = 0; - ac = bq24735_read_word(charger->client, BQ24735_CHG_OPT); + ac = bq24735_read_word(charger->client, BQ24735_CHARGE_OPT); if (ac < 0) { dev_dbg(&charger->client->dev, "Failed to read charger options : %d\n", ac); return false; } - return (ac & BQ24735_CHG_OPT_AC_PRESENT) ? true : false; + return (ac & BQ24735_CHARGE_OPT_AC_PRESENT) ? true : false; } return false; @@ -208,11 +211,11 @@ static int bq24735_charger_is_charging(struct bq24735 *charger) if (!bq24735_charger_is_present(charger)) return 0; - ret = bq24735_read_word(charger->client, BQ24735_CHG_OPT); + ret = bq24735_read_word(charger->client, BQ24735_CHARGE_OPT); if (ret < 0) return ret; - return !(ret & BQ24735_CHG_OPT_CHARGE_DISABLE); + return !(ret & BQ24735_CHARGE_OPT_CHG_DISABLE); } static void bq24735_update(struct bq24735 *charger) From patchwork Tue Jul 6 19:55:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Meneguele X-Patchwork-Id: 471045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3C80C07E96 for ; Tue, 6 Jul 2021 19:55:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8306261C3A for ; Tue, 6 Jul 2021 19:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbhGFT6e (ORCPT ); Tue, 6 Jul 2021 15:58:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55805 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbhGFT6e (ORCPT ); Tue, 6 Jul 2021 15:58:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625601355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H5hr1jkfiR6AahtYXG4oxTXgC9cQ55LO9WjbhjrCQHU=; b=IKmlBAxOHpC7flZWfqV/sn3LcuEIkP5nlhLXwqTVCulfiQVyH2tprDqBAsjSQM8uJHgSw6 XXz1u5y2FPfEI1zw0Zll7L4s23QEqfyndNlXEYyp91e2XJ3zUhJ0+gbdQy5ejvaBTWFPft j1oylRTfJM0FPYIgFd0n8k0ixHTBPk4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-418-g1jsj-a7M_2awig4YWxuig-1; Tue, 06 Jul 2021 15:55:53 -0400 X-MC-Unique: g1jsj-a7M_2awig4YWxuig-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C60521084F4C; Tue, 6 Jul 2021 19:55:52 +0000 (UTC) Received: from localhost (ovpn-113-53.rdu2.redhat.com [10.10.113.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10BA22EB38; Tue, 6 Jul 2021 19:55:48 +0000 (UTC) From: Bruno Meneguele To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Bruno Meneguele Subject: [PATCH v2 2/2] power: supply: bq24735: add watchdog timer delay support Date: Tue, 6 Jul 2021 16:55:27 -0300 Message-Id: <20210706195527.371108-3-bmeneg@redhat.com> In-Reply-To: <20210706195527.371108-1-bmeneg@redhat.com> References: <20210706195527.371108-1-bmeneg@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The BQ24735 charger allows the user to set the watchdog timer delay between two consecutives ChargeCurrent or ChargeVoltage command writes, if the IC doesn't receive any command before the timeout happens, the charge is turned off. This patch adds the support to the user to change the default/POR value with four discrete values: 0 - disabled 1 - enabled, 44 sec 2 - enabled, 88 sec 3 - enabled, 175 sec (default at POR) These are the options supported in the ChargeOptions register bits 13&14. Also, this patch make one additional check when poll-interval is set by the user: if the interval set is greater than the WDT timeout it'll fail during the probe stage, preventing the user to set non-compatible values between the two options. Signed-off-by: Bruno Meneguele --- Changelog: v1 - corrected the type of new bq24735_platform member wdt_timeout .../bindings/power/supply/bq24735.yaml | 13 +++++ drivers/power/supply/bq24735-charger.c | 48 +++++++++++++++++++ include/linux/power/bq24735-charger.h | 1 + 3 files changed, 62 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/bq24735.yaml b/Documentation/devicetree/bindings/power/supply/bq24735.yaml index 131be6782c4b..62399efab467 100644 --- a/Documentation/devicetree/bindings/power/supply/bq24735.yaml +++ b/Documentation/devicetree/bindings/power/supply/bq24735.yaml @@ -56,6 +56,19 @@ properties: The POR value is 0x1000h. This number is in mA (e.g. 8064). See the spec for more information about the InputCurrent (0x3fh) register. + ti,wdt-timeout: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Used to control and set the charger watchdog delay between consecutive + charge voltage and charge current commands. + This value must be: + 0 - disabled + 1 - 44 seconds + 2 - 88 seconds + 3 - 175 seconds + The POR value is 0x11 (3). + See the spec for more information about the ChargeOptions(0x12h) register. + ti,external-control: type: boolean description: | diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index 3ce36d09c017..88f1cb1e9fee 100644 --- a/drivers/power/supply/bq24735-charger.c +++ b/drivers/power/supply/bq24735-charger.c @@ -45,6 +45,8 @@ /* ChargeOptions bits of interest */ #define BQ24735_CHARGE_OPT_CHG_DISABLE (1 << 0) #define BQ24735_CHARGE_OPT_AC_PRESENT (1 << 4) +#define BQ24735_CHARGE_OPT_WDT_OFFSET 13 +#define BQ24735_CHARGE_OPT_WDT (3 << BQ24735_CHARGE_OPT_WDT_OFFSET) struct bq24735 { struct power_supply *charger; @@ -156,6 +158,20 @@ static int bq24735_config_charger(struct bq24735 *charger) } } + if (pdata->wdt_timeout) { + value = pdata->wdt_timeout; + + ret = bq24735_update_word(charger->client, BQ24735_CHARGE_OPT, + BQ24735_CHARGE_OPT_WDT, + (value << BQ24735_CHARGE_OPT_WDT_OFFSET)); + if (ret < 0) { + dev_err(&charger->client->dev, + "Failed to write watchdog timer: %d\n", + ret); + return ret; + } + } + return 0; } @@ -347,6 +363,17 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) if (!ret) pdata->input_current = val; + ret = of_property_read_u32(np, "ti,wdt-timeout", &val); + if (!ret) { + if (val <= 3) { + pdata->wdt_timeout = val; + } else { + dev_warn(&client->dev, + "Invalid value for ti,wdt-timeout: %d", + val); + } + } + pdata->ext_control = of_property_read_bool(np, "ti,external-control"); return pdata; @@ -476,6 +503,27 @@ static int bq24735_charger_probe(struct i2c_client *client, return 0; if (!charger->poll_interval) return 0; + if (charger->pdata->wdt_timeout) { + int wdt_ms; + + switch (charger->pdata->wdt_timeout) { + case 1: + wdt_ms = 44000; + break; + case 2: + wdt_ms = 88000; + break; + case 3: + wdt_ms = 175000; + break; + } + + if (charger->poll_interval > wdt_ms) { + dev_err(&client->dev, + "Poll interval greater than WDT timeout\n"); + return -EINVAL; + } + } ret = devm_delayed_work_autocancel(&client->dev, &charger->poll, bq24735_poll); diff --git a/include/linux/power/bq24735-charger.h b/include/linux/power/bq24735-charger.h index 321dd009ce66..ce5a030ca111 100644 --- a/include/linux/power/bq24735-charger.h +++ b/include/linux/power/bq24735-charger.h @@ -12,6 +12,7 @@ struct bq24735_platform { uint32_t charge_current; uint32_t charge_voltage; uint32_t input_current; + uint32_t wdt_timeout; const char *name;