From patchwork Mon Jun 12 11:30:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=i4Mh2nE9; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqTw4K0Rz20Wl for ; Mon, 12 Jun 2023 21:39:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232193AbjFLLj3 (ORCPT ); Mon, 12 Jun 2023 07:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233148AbjFLLiY (ORCPT ); Mon, 12 Jun 2023 07:38:24 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC1C446B3 for ; Mon, 12 Jun 2023 04:31:05 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f658a17aa4so3961598e87.0 for ; Mon, 12 Jun 2023 04:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569464; x=1689161464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jgVb0YJLMNEKVO6C16PIZb2dGiXFxsfavrt5+857HKY=; b=i4Mh2nE9YuLTcp2XbpN/eOJwtngu0h1LWO9aEmixp8l0pyW240BMU1J8Q5ABCGlWUM jI57wN1NNeplslst7Ooc8X23+g2BbnCZoA+tMrbPziCy7MgKwyoPhIguKO8jGDCei/5e sbEiItj88sX5FlOPjAzWrmWQbWCrHEad1yJ2Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569464; x=1689161464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jgVb0YJLMNEKVO6C16PIZb2dGiXFxsfavrt5+857HKY=; b=MBlbg5I2vVk4V8gfGgGWsqcrjUCCfB6UcNS4C/G2fezoQxAfC8U/+Wf+uA7l2HptFO j/X/L8SFq5YKeC5zsm/R8YtTo79yJaD2tlvPBvVU+/oGo4rRELP6pA9BBwJbgA/oPz1n eMQ1uXb9N61NSWYMrHvN7KiCk63dlBQgkh9GWhr5h2WaWL+GLJXuDVKGM+hipcudQryL MAoPtew7chkCD0qsnT9IFFbs0P+dGtVPE+yX2JyLdQEbxmsZZu7ju3T/tHOJeLMqCwIO NaPLwNVHjxlY55BPhUkN8Q7iuhfhzXKWU50gQlhTLEI33m5hMun56yKOt8ktfbwsp8fG 2gGg== X-Gm-Message-State: AC+VfDy+7L98Uv2XJV8ownaNtnkX8egyeJF0JDeYxcu0Z+JYfcpKDlFD 9IwDJWFGJt25Fb9F3w4BtulB1w== X-Google-Smtp-Source: ACHHUZ5X5cIhPpNI+TpxMxC3O5qv96l+D82oJntQHh+xdpggjzSo/YDmDHPdePMgi5rAGpSuAPIkUA== X-Received: by 2002:a19:7712:0:b0:4e8:c5d:42a5 with SMTP id s18-20020a197712000000b004e80c5d42a5mr3117418lfc.24.1686569463965; Mon, 12 Jun 2023 04:31:03 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:03 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 1/8] rtc: isl12022: remove wrong warning for low battery level Date: Mon, 12 Jun 2023 13:30:51 +0200 Message-Id: <20230612113059.247275-2-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-rtc@vger.kernel.org There are multiple problems with this warning. First of all, it triggers way too often, in fact nearly on every boot, because the SR_LBAT85/SR_LBAT75 bits have another meaning when in battery backup mode. Quoting from the data sheet: LOW BATTERY INDICATOR 85% BIT (LBAT85) In Normal Mode (VDD), this bit indicates when the battery level has dropped below the pre-selected trip levels. [...] The LBAT85 detection happens automatically once every minute when seconds register reaches 59. In Battery Mode (VBAT), this bit indicates the device has entered into battery mode by polling once every 10 minutes. The LBAT85 detection happens automatically once when the minute register reaches x9h or x0h minutes. Similar wording applies to the LBAT75 bit. This means that if the device is powered off for more than 10 minutes, the LBAT85 bit is guaranteed to be set. Upon power-on, unless we're close enough to the end of a minute and/or the boot is slow enough that the second register passes 59, the LBAT85 bit is still set when the kernel (or early userspace) reads the RTC to set the system's wallclock time. Another minor problem is with the bit logic. If the 75% level is reached, logically we're also below 85%, so both bits would most likely be set. So even if the battery is below 75%, the warning would still say "voltage dropped below 85%". A third problem is that the driver and current DT binding offer no way to indicate the nominal battery level and/or settings of the Battery Level Monitor Trip Bits. Since the default value of the VB85TP[2:0] and VB75TP[2:0] bits are 000, this means the actual setting of the LBAT85/LBAT75 bits in VDD mode doesn't happen until the battery is below 2.125V/1.875V, which for a standard 3V battery is way too late. A fourth problem is emitting this warning from ->read_time: util-linux' hwclock will, in the absence of support for getting an interrupt when the seconds counter is updated, issue ioctl(RTC_RD_TIME) in a busy-loop until it sees a change in the seconds field. In that case, if the battery low bits are set (either genuinely, more than a minute after boot, due to the battery actually being low, or as above, bogusly shortly after boot), the kernel log is swamped with hundreds of identical warnings. Subsequent patches will add such bindings and driver support, and also proper support for RTC_VL_READ. For now, remove the broken warning. Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-isl12022.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index e68a79b5e00e..ebd66b835cef 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -141,12 +141,6 @@ static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm) if (ret) return ret; - if (buf[ISL12022_REG_SR] & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) { - dev_warn(dev, - "voltage dropped below %u%%, date and time is not reliable.\n", - buf[ISL12022_REG_SR] & ISL12022_SR_LBAT85 ? 85 : 75); - } - dev_dbg(dev, "raw data is sec=%02x, min=%02x, hr=%02x, mday=%02x, mon=%02x, year=%02x, wday=%02x, sr=%02x, int=%02x", buf[ISL12022_REG_SC], From patchwork Mon Jun 12 11:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=LconL8RH; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqTx6h0Zz20Wl for ; Mon, 12 Jun 2023 21:39:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237451AbjFLLjb (ORCPT ); Mon, 12 Jun 2023 07:39:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234292AbjFLLiY (ORCPT ); Mon, 12 Jun 2023 07:38:24 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0398846BC for ; Mon, 12 Jun 2023 04:31:07 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f62b552751so4793506e87.3 for ; Mon, 12 Jun 2023 04:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569465; x=1689161465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YpuBhKsWEFwrG+U6fAOV3v6Ozr7I0OWP1C3aU0PzTV4=; b=LconL8RHpCpwjklWxyvC74ECVtkdib0L3H+oc1qrqBvkwzexWBLycAyBp4jZWjzYVF FbfFFqTLr7w3aEXgRDnHs8dWJe9JM+P+LRR7Cp506h6WBAFLpN7ANb2nvAygrAkXhKRL TcbDgzjRfLBsHxemcdzt5R6DkVdEwuyG2ChCg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569465; x=1689161465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YpuBhKsWEFwrG+U6fAOV3v6Ozr7I0OWP1C3aU0PzTV4=; b=KGsR2Ix07jVlpOLiPhFcM1U09WnlJ6G3JiQ5h1agEYtdfvvY8x6kQV8xZxJU4s4tYb PHr06kyAa4fozQTx9czn/SjZ68gI+QTADIqQHNSEPTa9LHD5yEesZk2SqSzvY9u9QRJu 1agkdRIQTBu3eF1hRVCxEH4GyVoe8zKuoviYj722L8jku69KfWH62xjE8YeB0cn3Tqv2 NkueV+UO3YLnra25W6k5VHbmzgaXUNcduiw4YJIDLIN7npIbl5BvmAsLepGW7gwTI8/H uo+oB/q7XDHHwhA0cldhO+DIR9WPCJ/sTcStVoWXJq5r9GOPzrl7kcn2GGwpZiaIcH8Z 8tOw== X-Gm-Message-State: AC+VfDyrksPD9a+FEep3xkXd3SYgMX4e2ELAPVcMPoO9E6oCdgkknG+l Um8rdS7kyyMytyRPdS8L4fgv4H1gM/SDBfVdKo1URQ== X-Google-Smtp-Source: ACHHUZ6laWK/Q3Q+PhWV0V2XyJiorOzxc6mfn2Qs3Lr2FsZ8f0qQfCBXjBJIbiby1VE5xsrBnBMasw== X-Received: by 2002:a19:e34e:0:b0:4f6:21db:e584 with SMTP id c14-20020a19e34e000000b004f621dbe584mr3372913lfk.0.1686569465413; Mon, 12 Jun 2023 04:31:05 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:04 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 2/8] dt-bindings: rtc: Move isil,isl12022 from trivial-rtc.yaml into own schema file Date: Mon, 12 Jun 2023 13:30:52 +0200 Message-Id: <20230612113059.247275-3-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-rtc@vger.kernel.org Move the isil,isl12022 RTC bindings from trivial-rtc.yaml into its own intersil,isl12022.yaml file, in preparation for adding more bindings. Signed-off-by: Rasmus Villemoes --- .../bindings/rtc/intersil,isl12022.yaml | 42 +++++++++++++++++++ .../devicetree/bindings/rtc/trivial-rtc.yaml | 2 - 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml diff --git a/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml b/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml new file mode 100644 index 000000000000..899c5edc72e4 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/rtc/intersil,isl12022.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Intersil ISL12022 Real-time Clock + +allOf: + - $ref: rtc.yaml# + +properties: + compatible: + const: isil,isl12022 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + rtc@6f { + compatible = "isil,isl12022"; + reg = <0x6f>; + interrupts-extended = <&gpio1 5 IRQ_TYPE_LEVEL_LOW>; + }; + }; + +... diff --git a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml index a3603e638c37..b062c64266a6 100644 --- a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml +++ b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml @@ -45,8 +45,6 @@ properties: - isil,isl1208 # Intersil ISL1218 Low Power RTC with Battery Backed SRAM - isil,isl1218 - # Intersil ISL12022 Real-time Clock - - isil,isl12022 # Loongson-2K Socs/LS7A bridge Real-time Clock - loongson,ls2x-rtc # Real Time Clock Module with I2C-Bus From patchwork Mon Jun 12 11:30:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=B7Fc5rs8; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqTx0HCyz20XR for ; Mon, 12 Jun 2023 21:39:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236813AbjFLLja (ORCPT ); Mon, 12 Jun 2023 07:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234564AbjFLLig (ORCPT ); Mon, 12 Jun 2023 07:38:36 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 497F261BE for ; Mon, 12 Jun 2023 04:31:08 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f655293a38so4527786e87.0 for ; Mon, 12 Jun 2023 04:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569466; x=1689161466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yg+ZdBpNlgvOVT9Mel57yzibQ4IWXPPH7Y7NoiRxgV8=; b=B7Fc5rs8l+9HatWL8qTZTKeUxSAhd/s0ahGyNZAoMi0LB1cmD7eWnTI573PL3J5PwY TPfEKiIAh1lyhuAV9Dcj4IVDw1BYb7kuRmglZEqct4uwgeR93b0+mxCTlkNBDESVw+eL AjL3ycniFVHhzfAU2EVnqNOKPOEGPXXhFSYlk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569466; x=1689161466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yg+ZdBpNlgvOVT9Mel57yzibQ4IWXPPH7Y7NoiRxgV8=; b=Anv9297Ssl1iwzLfA6wp9/hBcuTian/E0uyelXadDmczm9ThdRtjWWm9SCTpPE0MbI IDin4QCmPFVqL0zvhVgX3cOaSHfuEcxLee47hvVuWb+CXoYdjsWKoXGPbZiqhFAhovtO 0z3I+YK5ogfZzZFbWn78jG2cxfnad2qEwoHJ/69F0hZJVbXzjOroExovkO63OwivOlwA JDgd+CQni+H3KQeUnh73bETNW+fKd6WxOOs+rlW7ZNAgSPvrRfFdIDu9xXk3NgQeZ/fI t+FJdCa1M9UhDbHVJcVMZRZ0DxpBrWbF2DRmmCewQUzvsCq4387c+c9sGz42+MPzZcDp 3PdA== X-Gm-Message-State: AC+VfDxMWzOFQ5ymwv+yl+Wdsmo4Zqoy8DEfOsOPVBHKASRS2M83C8gJ K61yhBHGdXhvhKbu1EP/hafTbQ== X-Google-Smtp-Source: ACHHUZ6wSCynoIgW6K8OwvJAGylvueLACSd7ZTlBmVVHf1hvXbDrA/tV5u3JevmTNcOUlIYEHkjBtw== X-Received: by 2002:a05:6512:551:b0:4ee:e0c7:434d with SMTP id h17-20020a056512055100b004eee0c7434dmr3622544lfl.51.1686569466584; Mon, 12 Jun 2023 04:31:06 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:06 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 3/8] dt-bindings: rtc: isl12022: add bindings for battery alarm trip levels Date: Mon, 12 Jun 2023 13:30:53 +0200 Message-Id: <20230612113059.247275-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-rtc@vger.kernel.org The isl12022 has a built-in support for monitoring the voltage of the backup battery, and setting bits in the status register when that voltage drops below two predetermined levels (usually 85% and 75% of the nominal voltage). However, since it can operate at wide range of battery voltages (2.5V - 5.5V), one must configure those trip levels according to which battery is used on a given board. Add bindings for defining these two trip levels. While the register and bit names suggest that they should correspond to 85% and 75% of the nominal battery voltage, the data sheet also says There are total of 7 levels that could be selected for the first alarm. Any of the of levels could be selected as the first alarm with no reference as to nominal Battery voltage level. Hence this provides the hardware designer the ability to choose values based on the discharge characteristics of the battery chosen for the given product, rather than just having one battery-microvolt property and having the driver choose levels close to 0.85/0.75 times that. Signed-off-by: Rasmus Villemoes --- .../devicetree/bindings/rtc/intersil,isl12022.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml b/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml index 899c5edc72e4..1e85a9c8945b 100644 --- a/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml +++ b/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml @@ -19,6 +19,18 @@ properties: interrupts: maxItems: 1 + isil,trip-level85-microvolt: + description: | + The battery voltage at which the first alarm should trigger + (normally ~85% of nominal V_BAT). + enum: [2125000, 2295000, 2550000, 2805000, 3060000, 4250000, 4675000] + + isil,trip-level75-microvolt: + description: | + The battery voltage at which the second alarm should trigger + (normally ~75% of nominal V_BAT). + enum: [1875000, 2025000, 2250000, 2475000, 2700000, 3750000, 4125000] + required: - compatible - reg @@ -36,6 +48,8 @@ examples: compatible = "isil,isl12022"; reg = <0x6f>; interrupts-extended = <&gpio1 5 IRQ_TYPE_LEVEL_LOW>; + isil,trip-level85-microvolt = <2550000>; + isil,trip-level75-microvolt = <2250000>; }; }; From patchwork Mon Jun 12 11:30:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=iGaBlcQH; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqV44YlSz20XR for ; Mon, 12 Jun 2023 21:39:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231678AbjFLLji (ORCPT ); Mon, 12 Jun 2023 07:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234487AbjFLLiw (ORCPT ); Mon, 12 Jun 2023 07:38:52 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D63646587 for ; Mon, 12 Jun 2023 04:31:10 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f62cf9755eso4832591e87.1 for ; Mon, 12 Jun 2023 04:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569469; x=1689161469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iF8XkEzBn2bI8HNyXckNnxzb/f1aF1cm8iChUnH2MYQ=; b=iGaBlcQHbQKwQEkolODsOCPsDLgnefvvS+vIL7gyjiXNj6hoJ4CTU4x6g60FsJywt4 W6qfm3d1pRzijQHQ1LD2X7v7gjk3H80d5bgSHg2aMqgfaNGWq6e3mb/rgHLcnvPRIyaQ 1ovayB1mEWZ7+R6EF4N43+7JwiylhiIKRza7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569469; x=1689161469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iF8XkEzBn2bI8HNyXckNnxzb/f1aF1cm8iChUnH2MYQ=; b=IGLZB49ebw+s+SWwmrU5t2CMeLwZfRvyy9r4H0KjEeszPVsWyddMErsxb08ncOSydR u/4jWo7PZh0OjUcxweY4UVz96VS+FmWG7mDQK6XEiWxsrdBCk8zHHnzgbPpyGPQ/Xp9y vFVRRHiU1B4QHRUYN8IPlVtlin2aHUJRR2dOwFLkebBPH1xCZ/8zs+PHsrQJ5mnfdZfH UUikFmsgHy+kpS3oI39s758zMHC+OB7BDWvRwkj5hNdP1GVUx+KZwTvXiNUERAZOVLDp lRUz088B7sBl/j6izjytl0Vaei0wyMp8KC6SfthTRVhVL6N7hav3oXMyzTwlfnBZ04Rh ndyA== X-Gm-Message-State: AC+VfDyfY4B9Z4I2c1IT7A+uVHO9M+EIoC+cltuH2Rg5xz91qaXfWyfl z5vOh4qks0kRseqQccb88LsWHw== X-Google-Smtp-Source: ACHHUZ4hOCIN8xKvfoizozIxAJRqo5eCUyzL8mIenSNp8hPEvMwHUDV7qgJAMeF19sXoZyOIvRrI+g== X-Received: by 2002:a19:d611:0:b0:4f7:434b:70b4 with SMTP id n17-20020a19d611000000b004f7434b70b4mr1470471lfg.41.1686569469275; Mon, 12 Jun 2023 04:31:09 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:07 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 4/8] rtc: isl12022: add support for trip level DT bindings Date: Mon, 12 Jun 2023 13:30:54 +0200 Message-Id: <20230612113059.247275-5-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-rtc@vger.kernel.org Implement support for using the values given in the isil,trip-level[87]5-microvolt properties to set appropriate values in the VB[87]5TP bits in the PWR_VBAT register. Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-isl12022.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index ebd66b835cef..cb8f1d92e116 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -31,6 +31,8 @@ #define ISL12022_REG_SR 0x07 #define ISL12022_REG_INT 0x08 +#define ISL12022_REG_PWR_VBAT 0x0a + #define ISL12022_REG_BETA 0x0d #define ISL12022_REG_TEMP_L 0x28 @@ -42,6 +44,9 @@ #define ISL12022_INT_WRTC (1 << 6) +#define ISL12022_REG_VB85_MASK GENMASK(5, 3) +#define ISL12022_REG_VB75_MASK GENMASK(2, 0) + #define ISL12022_BETA_TSE (1 << 7) static umode_t isl12022_hwmon_is_visible(const void *data, @@ -209,6 +214,35 @@ static const struct regmap_config regmap_config = { .use_single_write = true, }; +static const u32 trip_level85[] = { 2125000, 2295000, 2550000, 2805000, 3060000, 4250000, 4675000 }; +static const u32 trip_level75[] = { 1875000, 2025000, 2250000, 2475000, 2700000, 3750000, 4125000 }; + +static void isl12022_set_trip_levels(struct device *dev) +{ + struct regmap *regmap = dev_get_drvdata(dev); + u32 level85 = 0, level75 = 0; + int ret, x85, x75; + u8 val, mask; + + device_property_read_u32(dev, "isil,trip-level85-microvolt", &level85); + device_property_read_u32(dev, "isil,trip-level75-microvolt", &level75); + + for (x85 = 0; x85 < ARRAY_SIZE(trip_level85) - 1; ++x85) + if (level85 <= trip_level85[x85]) + break; + + for (x75 = 0; x75 < ARRAY_SIZE(trip_level75) - 1; ++x75) + if (level75 <= trip_level75[x75]) + break; + + val = FIELD_PREP(ISL12022_REG_VB85_MASK, x85) | FIELD_PREP(ISL12022_REG_VB75_MASK, x75); + mask = ISL12022_REG_VB85_MASK | ISL12022_REG_VB75_MASK; + + ret = regmap_update_bits(regmap, ISL12022_REG_PWR_VBAT, mask, val); + if (ret) + dev_warn(dev, "unable to set battery alarm levels: %d\n", ret); +} + static int isl12022_probe(struct i2c_client *client) { struct rtc_device *rtc; @@ -225,6 +259,7 @@ static int isl12022_probe(struct i2c_client *client) dev_set_drvdata(&client->dev, regmap); + isl12022_set_trip_levels(&client->dev); isl12022_hwmon_register(&client->dev); rtc = devm_rtc_allocate_device(&client->dev); From patchwork Mon Jun 12 11:30:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=EpTSnNpe; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqV04QFGz20Wl for ; Mon, 12 Jun 2023 21:39:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229964AbjFLLjc (ORCPT ); Mon, 12 Jun 2023 07:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234745AbjFLLix (ORCPT ); Mon, 12 Jun 2023 07:38:53 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45C53658C for ; Mon, 12 Jun 2023 04:31:12 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4f4b2bc1565so4839717e87.2 for ; Mon, 12 Jun 2023 04:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569470; x=1689161470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kq7NS+iMzs82fomvoYuidxYVGVMWQQf8sysX64TDkNs=; b=EpTSnNpebF6RNHMi7hhR1Rc9CBjLQijktT6OPL8V00DFjeXsu4j+bxPvA7nQ/3lzSv FmdlUMEtZdkle4tew7XltHFvviIEl9WjG9C9GoDTRYCh1PFUVk7fBHiCBHkeHDhZaQjs n9wtRqhnsOMq4/YnZyVe2GGzAQs7C0Q+WmFJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569470; x=1689161470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kq7NS+iMzs82fomvoYuidxYVGVMWQQf8sysX64TDkNs=; b=aeHT3itiS/ubt/8EAm0IuzAWke6+cXzBxbkAFP5SInVlgJ9FjvgBKJWwtZiK9v1her Qtn1BnHco4cEQo9yY22b5mU9o2I9+9Dbji933y99z/IazqenDt3WfcIBDBEkI3X0uLpc OjmMXZ5eEW6mopryYv2jV1I56gCjQwBpYlSTvUQc7EpBqH0Gb1xEzK86RZ6qtaUTPM5v J3gb92b8Jqo+lajFZAfkvmW5nmDkB1BijtVkIDKy6RVcykE1g2/SpJWu01DWSxWqh5E4 p8Cld/SmjV6s2qswY/0PzrAlXMFf+k7GfM9olUDCxunmFFrOLrh/G1cAX6WerebK0JOk 3Efg== X-Gm-Message-State: AC+VfDyZUF4nZKwE6hSLo7obvALYgmY45xA+inyebKVa7P2TWlj1QIJZ Z4zQn99kDXaiPGCUjOW2SAru7g== X-Google-Smtp-Source: ACHHUZ5N8xpIBWvNjUIko64UBZMsqLNzVNmlWsaXSYDuzwyjut4I6r+XRV1RCddpqnJHYdIvLcYcqA== X-Received: by 2002:a19:5f0e:0:b0:4f4:d83e:4141 with SMTP id t14-20020a195f0e000000b004f4d83e4141mr4200387lfb.50.1686569470594; Mon, 12 Jun 2023 04:31:10 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:10 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 5/8] rtc: isl12022: implement RTC_VL_READ and RTC_VL_CLR ioctls Date: Mon, 12 Jun 2023 13:30:55 +0200 Message-Id: <20230612113059.247275-6-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-rtc@vger.kernel.org Hook up support for reading the values of the SR_LBAT85 and SR_LBAT75 bits. Translate the former to "battery low", and the latter to "battery empty or not-present". Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-isl12022.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index cb8f1d92e116..1b6659a9b33a 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -203,7 +203,48 @@ static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm) return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf)); } +static int isl12022_read_sr(struct regmap *regmap) +{ + int ret; + u32 val; + + ret = regmap_read(regmap, ISL12022_REG_SR, &val); + if (ret < 0) + return ret; + return val; +} + +static int isl12022_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) +{ + struct regmap *regmap = dev_get_drvdata(dev); + u32 user = 0; + int ret; + + switch (cmd) { + case RTC_VL_READ: + ret = isl12022_read_sr(regmap); + if (ret < 0) + return ret; + + if (ret & ISL12022_SR_LBAT85) + user |= RTC_VL_BACKUP_LOW; + + if (ret & ISL12022_SR_LBAT75) + user |= RTC_VL_BACKUP_EMPTY; + + return put_user(user, (u32 __user *)arg); + + case RTC_VL_CLR: + return regmap_clear_bits(regmap, ISL12022_REG_SR, + ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75); + + default: + return -ENOIOCTLCMD; + } +} + static const struct rtc_class_ops isl12022_rtc_ops = { + .ioctl = isl12022_rtc_ioctl, .read_time = isl12022_rtc_read_time, .set_time = isl12022_rtc_set_time, }; From patchwork Mon Jun 12 11:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=TI8xXEHM; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqV41VyMz20Wl for ; Mon, 12 Jun 2023 21:39:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232898AbjFLLjh (ORCPT ); Mon, 12 Jun 2023 07:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234029AbjFLLix (ORCPT ); Mon, 12 Jun 2023 07:38:53 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38C04658F for ; Mon, 12 Jun 2023 04:31:13 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f658a17aa4so3961739e87.0 for ; Mon, 12 Jun 2023 04:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569471; x=1689161471; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oCDq0HPnZ/JW4aurWSialUZv9qnBUgo1v/zNc5H3vQE=; b=TI8xXEHM0E1duX465xqlvlQJlUBu4kdYnE/gYUVnHchpW9NmMKbxTZ7pvXsNZ97Pyw VdSzV3IKFrAyAB5rXaWDofX5i9clGbUukci0IVENYxvf3rlTsTWPLmnoSv10Ew19MEdg l/YWMLYmrX+0ACs423hIDEnPAGTFv2+fxo8R0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569471; x=1689161471; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oCDq0HPnZ/JW4aurWSialUZv9qnBUgo1v/zNc5H3vQE=; b=EXksuiBdjInd0PpemElHKO2MDERgQ6t1x5DzIBU7sW7R3zvjqdEqmEIZMiE/b37icb KlAIKxelUxx6b2ncwEdY/i4VXA5q4y4gxwy4XuU0JB9ZF77YSWTMGGmbwb1KcfGh1jB+ hifIXZs/c6T0vK3UJ6Qzgvg2Cm3QQCZbaK+On+M3eAgmI0xMX03mtPkLC1PO5jJVW/dX UWhWvJPKO/TIu48ck4lkzIVgyq8wx+xKN6RbOsaScIBT66yDY0juUxmKmnVxYsfi9rFZ qnKvcUxS8chdJ5denYccsHARS4yjSo8KKvvF6gnYusWy0X2GvlJrSx5WffwLk2ecdiMW TNSQ== X-Gm-Message-State: AC+VfDxpbasDFUtR79As2OwvcfiJe/42VzEXmUmbZeHHC6Ih58MoJ1pZ mwxPlw6O7ExECtsSJPAGfhVA8w== X-Google-Smtp-Source: ACHHUZ6Y1cn5VIj9cr5Vm+dkpSLxN9iimVWfRCdcyU5A+yKCFy5s8duTk2D/jOxfIOpE+OpbfMhrww== X-Received: by 2002:a05:6512:3133:b0:4f6:2e4e:e425 with SMTP id p19-20020a056512313300b004f62e4ee425mr4005082lfd.50.1686569471577; Mon, 12 Jun 2023 04:31:11 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:11 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 6/8] rtc: isl12022: trigger battery level detection during probe Date: Mon, 12 Jun 2023 13:30:56 +0200 Message-Id: <20230612113059.247275-7-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-rtc@vger.kernel.org Since the meaning of the SR_LBAT85 and SR_LBAT75 bits are different in battery backup mode, they may very well be set after power on, and stay set for up to a minute (i.e. until the battery detection in VDD mode happens when the seconds counter hits 59). This would mean that userspace doing a ioctl(RTC_VL_READ) early on could get a false positive. The battery level detection can also be triggered by explicitly writing a 1 to the TSE bit in the BETA register. Do that once during boot (well, probe), and emit a single warning to the kernel log if the battery is already low. Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-isl12022.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index 1b6659a9b33a..690dbb446d1a 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -280,8 +280,25 @@ static void isl12022_set_trip_levels(struct device *dev) mask = ISL12022_REG_VB85_MASK | ISL12022_REG_VB75_MASK; ret = regmap_update_bits(regmap, ISL12022_REG_PWR_VBAT, mask, val); - if (ret) + if (ret) { dev_warn(dev, "unable to set battery alarm levels: %d\n", ret); + return; + } + + ret = regmap_write_bits(regmap, ISL12022_REG_BETA, + ISL12022_BETA_TSE, ISL12022_BETA_TSE); + if (ret) { + dev_warn(dev, "unable to trigger battery level detection: %d\n", ret); + return; + } + + ret = isl12022_read_sr(regmap); + if (ret < 0) { + dev_warn(dev, "unable to read status register: %d\n", ret); + } else if (ret & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) { + dev_warn(dev, "battery voltage is below %u%%\n", + (ret & ISL12022_SR_LBAT75) ? 75 : 85); + } } static int isl12022_probe(struct i2c_client *client) From patchwork Mon Jun 12 11:30:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=LecpfOFA; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqV32Dbzz20Wl for ; Mon, 12 Jun 2023 21:39:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233871AbjFLLjg (ORCPT ); Mon, 12 Jun 2023 07:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232898AbjFLLix (ORCPT ); Mon, 12 Jun 2023 07:38:53 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DEBA7EF9 for ; Mon, 12 Jun 2023 04:31:14 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4f63006b4e3so4939183e87.1 for ; Mon, 12 Jun 2023 04:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569472; x=1689161472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A/dhIkHJ/Bd/JpiRxxUt23+FRsEwSHxsnLx/azCSW6k=; b=LecpfOFA5R5ROPy2U4qCs9GjXST0XM1loQRP+J1c5EvCrAsd9vg3Ubk1q79K3T7GaL BAKxYsX2y3JPonza2iOv7Tk47bT4Po5+hRG4xdRnDdnjxbh728+YOQLt49LjKNpod2dd hoqlX3Te6x0E17igFGqYoXS8Sk3zJ8q78VKiQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569472; x=1689161472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A/dhIkHJ/Bd/JpiRxxUt23+FRsEwSHxsnLx/azCSW6k=; b=YOuX9UeztIQEdqK51/eZn9Fmjy83QsasgsoAXjnEhauYXd7RAb0qUrNM3sacf2AyZK MfrHqw98HohuehUrGgPC4UJBnrgyx68bREfJbsmDwZbWfAYbaBSnCeX9SEbB5GvL6CEH SimF8m8nM8rxWCI6Fs1mAXaj0/Q3N9rhNBKlDOCYL7GCKSycgSxtUkbvypainfXy7luK 9ECZkA11rcUSabu+3iD3iQmbsN5s0ffsXy+9K45aT/ub3RXdkNV3JYCmPw86TOyoFS0X sfOPqmyMCFW5f934f1An7ZNT5iX5Eux5lEDu2tFK3cEgb65Oosfjrhq3SQyccc5Y5DKU fYHw== X-Gm-Message-State: AC+VfDy+eDL/X6DYF+oP9nfphloGVpWvNG0za8WdYTj5VfueOEMrDOWN LR+pdeljkQgzT1d1a4a2iMgn2A== X-Google-Smtp-Source: ACHHUZ6w5tcUE3ULY1nK4ZqT+0gZwpI40pYe1yZEZMnG7ZSDhAjpuXKbtGJjor8ogsv7s6GC6GbELw== X-Received: by 2002:a05:6512:548:b0:4f6:4a10:ac4c with SMTP id h8-20020a056512054800b004f64a10ac4cmr3872985lfl.42.1686569472698; Mon, 12 Jun 2023 04:31:12 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:12 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 7/8] dt-bindings: rtc: isl12022: add #clock-cells property Date: Mon, 12 Jun 2023 13:30:57 +0200 Message-Id: <20230612113059.247275-8-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-rtc@vger.kernel.org The isl12022 has a dual-purpose irq/f_out pin, which can either be used as an interrupt or clock output. Signed-off-by: Rasmus Villemoes --- I've tried to express the fact that the pin can either be used for interrupts or as a clock source, so that at most one of "interrupts" and "#clock-cells" can be present, but I don't really have any idea if this is the proper way to do that. .../devicetree/bindings/rtc/intersil,isl12022.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml b/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml index 1e85a9c8945b..345abed9234f 100644 --- a/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml +++ b/Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml @@ -19,6 +19,9 @@ properties: interrupts: maxItems: 1 + '#clock-cells': + const: 0 + isil,trip-level85-microvolt: description: | The battery voltage at which the first alarm should trigger @@ -35,6 +38,13 @@ required: - compatible - reg +if: + properties: + '#clock-cells' +then: + properties: + interrupts: false + unevaluatedProperties: false examples: From patchwork Mon Jun 12 11:30:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1793903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.a=rsa-sha256 header.s=google header.b=GUirDWmf; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QfqV13phtz20Wl for ; Mon, 12 Jun 2023 21:39:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234745AbjFLLjc (ORCPT ); Mon, 12 Jun 2023 07:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235143AbjFLLiz (ORCPT ); Mon, 12 Jun 2023 07:38:55 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BF287EFB for ; Mon, 12 Jun 2023 04:31:15 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f5f728c4aaso4936856e87.0 for ; Mon, 12 Jun 2023 04:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686569473; x=1689161473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zVISWVLRgW0K7WAKXrrtHEIUr0IbbMXljAPQm1SU8cU=; b=GUirDWmfHeI1PQqvm31QSDtYOSZU83I1TUeXFUGgB/IDFtareX0LOnPd3d4MHo+SvB /LriIHBvcpXzsvClIDa/fc3We2zpJVGoy8P+UZa977vOiVipohu/T/bqQtLI3dndRweE fEQPS78uw6+XpzyHIeyu5jhU2lVehHPDZUZOY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686569473; x=1689161473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zVISWVLRgW0K7WAKXrrtHEIUr0IbbMXljAPQm1SU8cU=; b=U1fklR1talsQNCaUt1BogsMtLvo29ETmDOB8DSWhFzw1R++hXLsYfNWrNMDCaXUgaX 6sGHCF4TR7Q+uNE6aBrBsgT+l/W24gcBfu63QFLzZ0q16Cgy/0o9mtsFcv8LqmV6mUNk F8jN0WOf/MjgRp69d2Truyr0wlDImzRrzOsesBnlcX9p1aM07l3BvoShDIC+mq7CuV+O nbUT8mtuFOUu7d9EgQNt/lkciXkxUm/Iej+L6TCrz/YOv5WTC52FH4WuOKy10Ctc7bzU nhhQeuuGJoEUY+RoM4DzCD8VlzKkhcW/3WmiCt4wASdGBa+ie+SGtXl6cb52bFyDmqhO PNLg== X-Gm-Message-State: AC+VfDxi57DlKpw9D04uA7BpMDRM9osDpQYBIoWqqRdSxhJDwwbQNI5k lIZ2H3iow9kSVmgZilk1S1c80Q== X-Google-Smtp-Source: ACHHUZ4DO2f4AqARomXkmwy7A7bD4vgSbeOpkJmstbgRVEc/JnlEHVFXdAUVaNOIfvdiIbVhuxyX0g== X-Received: by 2002:ac2:465d:0:b0:4f4:b28d:73e8 with SMTP id s29-20020ac2465d000000b004f4b28d73e8mr3067413lfo.17.1686569473683; Mon, 12 Jun 2023 04:31:13 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w26-20020a19c51a000000b004edb8fac1cesm1399320lfe.215.2023.06.12.04.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 04:31:13 -0700 (PDT) From: Rasmus Villemoes To: Alessandro Zummo , Alexandre Belloni Cc: Andy Shevchenko , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-rtc@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 8/8] rtc: isl12022: implement support for the #clock-cells DT property Date: Mon, 12 Jun 2023 13:30:58 +0200 Message-Id: <20230612113059.247275-9-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230612113059.247275-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-rtc@vger.kernel.org If device tree implies that the chip's IRQ/F_OUT pin is used as a clock, expose that in the driver. For now, pretend it is a fixed-rate (32kHz) clock; if other use cases appear the driver can be updated to provide its own clk_ops etc. When the clock output is not used on a given board, one can prolong the battery life by ensuring that the FOx bits are 0. For the hardware I'm currently working on, the RTC draws 1.2uA with the FOx bits at their default 0001 value, dropping to 0.88uA when those bits are cleared. Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-isl12022.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index 690dbb446d1a..0054300b744b 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -43,6 +44,9 @@ #define ISL12022_SR_LBAT75 (1 << 1) #define ISL12022_INT_WRTC (1 << 6) +#define ISL12022_INT_FO_MASK GENMASK(3, 0) +#define ISL12022_INT_FO_OFF 0x0 +#define ISL12022_INT_FO_32K 0x1 #define ISL12022_REG_VB85_MASK GENMASK(5, 3) #define ISL12022_REG_VB75_MASK GENMASK(2, 0) @@ -255,6 +259,38 @@ static const struct regmap_config regmap_config = { .use_single_write = true, }; +static int isl12022_register_clock(struct device *dev) +{ + struct regmap *regmap = dev_get_drvdata(dev); + struct clk_hw *hw; + int ret; + + if (!device_property_present(dev, "#clock-cells")) { + /* + * Disabling the F_OUT pin reduces the power + * consumption in battery mode by ~25%. + */ + ret = regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, + ISL12022_INT_FO_OFF); + if (ret) + dev_warn(dev, "failed to clear FOx bits in INT register: %d", ret); + return 0; + } + + /* + * For now, only support a fixed clock of 32768Hz (the reset default). + */ + ret = regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, ISL12022_INT_FO_32K); + if (ret) + return ret; + + hw = devm_clk_hw_register_fixed_rate(dev, "isl12022_32kHz", NULL, 0, 32768); + if (IS_ERR(hw)) + return PTR_ERR(hw); + + return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw); +} + static const u32 trip_level85[] = { 2125000, 2295000, 2550000, 2805000, 3060000, 4250000, 4675000 }; static const u32 trip_level75[] = { 1875000, 2025000, 2250000, 2475000, 2700000, 3750000, 4125000 }; @@ -305,6 +341,7 @@ static int isl12022_probe(struct i2c_client *client) { struct rtc_device *rtc; struct regmap *regmap; + int ret; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; @@ -317,6 +354,10 @@ static int isl12022_probe(struct i2c_client *client) dev_set_drvdata(&client->dev, regmap); + ret = isl12022_register_clock(&client->dev); + if (ret) + return ret; + isl12022_set_trip_levels(&client->dev); isl12022_hwmon_register(&client->dev);