Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1214318rwd; Tue, 13 Jun 2023 06:27:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Pqk1gppT/Ifr7ZaJi/ooVG/QCxxPR4wkwyS7icJdi6VkKuZMfN1Cb9VkB4J60HgdpO+nF X-Received: by 2002:a05:6808:2a6e:b0:39a:b787:1aca with SMTP id fu14-20020a0568082a6e00b0039ab7871acamr7537365oib.49.1686662838206; Tue, 13 Jun 2023 06:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686662838; cv=none; d=google.com; s=arc-20160816; b=NU5Ou5Vq68kO+9X+mIynMpe/yLyLdVx/NCNQw8aqDJKrmzUSjSFyM58q2l/jZBIRTZ mnS6n34lGqU//ZOq7X2OJdrs89qLYYdKq562RMXqkgi3CTd03YrCLAfEJRKBBBzRW9I5 JDOhM2gV8dqru6pWaQ4+WoYpEmVLqGYHApVJSubTDJDilWBGoIXgWkBCRloqx/oxhAni kgLevE1ag0GXbiUAANslOhkDUeZK34BnKC+4+/1mUuHqiGhFRCr8ombSKQZkPXhxezOM XcZVLEo070eeOIM0LDc2UTMBwnNjt/mpmskxJlGhpncCR3S1EGcjZ26etsw1x2bN86oY KVIw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s3seTEyzOFrrpdej6mUJHYVSg+iFFYvDZ8cnJx/G6/U=; b=oquFe3hxWJYXHgqLUTo+v6jrpbQhxBEe6CPlkpMF0sf9wt8DVlFaakvf6x4rW6F4fe vIOuKudj17PrZ8jNrGR92//tDHbdKJTCY+hQYSPUSwhMiELz7Wb7iXsVGW6fQ66TiqXG C+e5ays2ODlIgBGxDQjtC+G043+qjpGeQAsaVLhMEV9xWCKb2Tzstf9nAMcLCsZKEMDd 6ReaDgcuNwoyxO5kogiVLliGDVG0EBudDM069EhtEiQjkYIqD8P4OrJQcdhbBbtSV3eG STmBcwsu4fwgtbRioS6el7flpzqblp0LrafEne2aUNof0ZKFXZg1mUEJA1DXb/wHEpC0 KzKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Zxtr6S2z; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id co11-20020a17090afe8b00b0025bd1db6083si4337843pjb.102.2023.06.13.06.27.05; Tue, 13 Jun 2023 06:27:18 -0700 (PDT) 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 header.i=@rasmusvillemoes.dk header.s=google header.b=Zxtr6S2z; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242561AbjFMNBm (ORCPT + 99 others); Tue, 13 Jun 2023 09:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242397AbjFMNBN (ORCPT ); Tue, 13 Jun 2023 09:01:13 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918061738 for ; Tue, 13 Jun 2023 06:01:11 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4f63ea7bfb6so6392422e87.3 for ; Tue, 13 Jun 2023 06:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686661270; x=1689253270; 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=s3seTEyzOFrrpdej6mUJHYVSg+iFFYvDZ8cnJx/G6/U=; b=Zxtr6S2z8XnVFD+tHbZOvxufbCCSddA+s67PIqPl4nvDcX65ZbN5o6gRuKwlESRGgg wC5+5hV4vam4CRDExDKeXyS06KbNHrxKZT+ymr3JeIdrNN9YIm8f1yHMLgoziQw4G5GA NOUSzJUMQ8QxagoMUV9PGBdMc4/tAtjTtB95o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686661270; x=1689253270; 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=s3seTEyzOFrrpdej6mUJHYVSg+iFFYvDZ8cnJx/G6/U=; b=HszET/ouAQkt7lKG8DGEQPLW9KD/Fm7Rkj5v2dHVqYXkeWED8HbixsuLS3AiuvaLTA 0DnGOldfFaXp9efJzrgDu39IUIL7yAWfqWlu/JdHtQ2/0K4Vt4Z8WO0KTgYz3JA7hxDs HXExrd9R7pfcf4CcmJK2x8hyK6bsIbJ/yqFGdIBcLzzBjfNrmR0Lm5XuHpoyh4YrIxHA sa+/ty+GoWr1H+/CViXUnU0pwwnLNFDncPEHMo+aEDUT5KQLIT4gXTaktB6WBz2d9+a3 diB3VkpFetIo4NrHUZbvTkVc8OAJuFaO6tGWQIj1Ol3j7E1WWBjot+ujHJts1S1T9J+o U56g== X-Gm-Message-State: AC+VfDyRFz3YeZvztBaiFNWZXrhK1op5CJddIn96ZXqivXUm59rv6Be6 I8t69acayJOWMs2R1K1vqEruAg== X-Received: by 2002:a05:6512:32ad:b0:4f4:b3a6:4140 with SMTP id q13-20020a05651232ad00b004f4b3a64140mr4935980lfe.42.1686661269606; Tue, 13 Jun 2023 06:01:09 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1793786lfl.28.2023.06.13.06.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 06:01:09 -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 v2 6/8] rtc: isl12022: trigger battery level detection during probe Date: Tue, 13 Jun 2023 15:00:08 +0200 Message-Id: <20230613130011.305589-7-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230613130011.305589-1-linux@rasmusvillemoes.dk> References: <20230612113059.247275-1-linux@rasmusvillemoes.dk> <20230613130011.305589-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,URIBL_BLOCKED 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-kernel@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. Empirically, this does not immediately update the bits in the status register (i.e., an immediate read of SR after this write can still show stale values), but the update is done after a few milliseconds, so certainly before the RTC device gets registered and userspace has a chance of doing the ioctl() on this device. Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-isl12022.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index bf0d65643897..44603169e575 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -268,6 +268,16 @@ static void isl12022_set_trip_levels(struct device *dev) 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); + + /* + * Force a write of the TSE bit in the BETA register, in order + * to trigger an update of the LBAT75 and LBAT85 bits in the + * status register. In battery backup mode, those bits have + * another meaning, so without this, they may contain stale + * values for up to a minute after power-on. + */ + regmap_write_bits(regmap, ISL12022_REG_BETA, + ISL12022_BETA_TSE, ISL12022_BETA_TSE); } static int isl12022_probe(struct i2c_client *client) -- 2.37.2