Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp504460rwd; Thu, 8 Jun 2023 04:04:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6taIULg/oq/6qUCma1fG3DAahTg3fuxdv7xN/I4XTkehmjzuWOidMm6rEG4NzcujlQbwfm X-Received: by 2002:a05:6a00:2d21:b0:652:a91c:5599 with SMTP id fa33-20020a056a002d2100b00652a91c5599mr9893129pfb.24.1686222267631; Thu, 08 Jun 2023 04:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686222267; cv=none; d=google.com; s=arc-20160816; b=cvNJSyiw536RGhevLpNASgpa7rmEax58pyEfII5RMBsaznX7C63siKDoigbuHc62Db /Oa5Q0oduvrtx/xVtUGHfBYGf4xSxq08w6ZIpg5OWuKVIGuiijgtamNASsFWtJJXK50/ iW601jlJSlNDMVAYcAub13qLzvPL8jw7PBISXP6WxycMZXQuORbSvsHEC4+UPhif3Cnn 23xVgHjeFS/ZcptF5pt4qvJBM6eEG8DQ13cUlmqZgDVHAvAdio+RaRZjak1GJPRyTU0v nMSfJylVpvYkYxKsfYbsDIZQPQ+PrPIJS5uTnAFYra7nsl6PP01AQj5DBp7I1S6Bhj/q VIYQ== 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=GMxYhkc1VAN6YvzxDxUID5gzfvinfcgW0ko7ik3lln8=; b=XAXdgDS+l4cfFcncn7KpbogtT3/FUvrZ9QB9xiSgDF/3N8V85rsRYxuTB0QcaCfjQw tUFTvSY4ry4mwnSv0dajPg/ZURFVqfIFuLxw0LPWDXL81d53vTCEhdFtLPtU8jcuLF9M UNXsfltpd94gDfTQvAJpEN/xUf3Ne0YzDbeWpDhNEz4jSSJVvgzhR8XXNXlmDpFYNPLg z8lAUFakpQIjsWB/2/MigKLc7W7ySGkm+NnOdetqUpDvZkJce/OanHQ5B5LrWK5ZlWJC 4s3GExovmHTomWhdh+AKMEkYlapURyPFxo1Jq58H9iVACOUq76yRYMVVwlKLUq4D0q3/ RH/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@norik.com header.s=default header.b="GEMHS/US"; 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 e25-20020aa79819000000b00662db175212si720919pfl.47.2023.06.08.04.04.13; Thu, 08 Jun 2023 04:04:27 -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=fail header.i=@norik.com header.s=default header.b="GEMHS/US"; 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 S235695AbjFHLAf (ORCPT + 99 others); Thu, 8 Jun 2023 07:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232139AbjFHLAL (ORCPT ); Thu, 8 Jun 2023 07:00:11 -0400 Received: from cpanel.siel.si (cpanel.siel.si [46.19.9.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC0E11A for ; Thu, 8 Jun 2023 04:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=norik.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=GMxYhkc1VAN6YvzxDxUID5gzfvinfcgW0ko7ik3lln8=; b=GEMHS/USCzB14ZEJ4dE1ihPswr sqIhALd+xoeXPiSDsghHKisxV8XrLDTf8lFXrjPJUao0ayE2ulzMXTjh2pgjLQ/YiH5xknP6Wuh87 zJddKFt9BfGJdsuyBqLPsep+9gMN6s6PB95xbTGD4duoBM11C7PQW43MSQWn00wjbSN5I3g/gJtYJ EF+YfnQ8OI31b6ZVrkJuFffAtikqByGIfXnC2ILGVPAstHrXOKkGSg+3tRlmYsws8ETdMU06+j+G6 e5ETd25tBHvyvZMpG6VPaN8s3d4kd5exdmLYyueS5SZ/ovkGIVQS9L1R1sOLSd9cjeoZh68URsQyP uHdp4Ofw==; Received: from [89.212.21.243] (port=58494 helo=localhost.localdomain) by cpanel.siel.si with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1q7BZf-00CHxg-0m; Thu, 08 Jun 2023 11:04:54 +0200 From: Andrej Picej To: a.zummo@towertech.it, alexandre.belloni@bootlin.com Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, upstream@phytec.de Subject: [PATCH] rtc: rv3028: Improve trickle charger logic Date: Thu, 8 Jun 2023 11:04:46 +0200 Message-Id: <20230608090446.2899646-1-andrej.picej@norik.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel.siel.si X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - norik.com X-Get-Message-Sender-Via: cpanel.siel.si: authenticated_id: andrej.picej@norik.com X-Authenticated-Sender: cpanel.siel.si: andrej.picej@norik.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_NONE, 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-kernel@vger.kernel.org Property "trickle-resistor-ohms" allows us to set trickle charger resistor. However there is no possibility to disable it afterwards. From now on, disable trickle charger circuit in case device-tree property "trickle-resistor-ohms" is not present. RV3029 RTC driver uses the same trickle charger disable logic. Additionally, lets make sure we only update internal EEPROM in case of a change. This prevents wear due to excessive EEPROM writes on each probe. Signed-off-by: Andrej Picej --- drivers/rtc/rtc-rv3028.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-rv3028.c b/drivers/rtc/rtc-rv3028.c index ec5d7a614e2d..190507bf97d0 100644 --- a/drivers/rtc/rtc-rv3028.c +++ b/drivers/rtc/rtc-rv3028.c @@ -860,6 +860,7 @@ static int rv3028_probe(struct i2c_client *client) struct rv3028_data *rv3028; int ret, status; u32 ohms; + int val_old, val; struct nvmem_config nvmem_cfg = { .name = "rv3028_nvram", .word_size = 1, @@ -937,9 +938,18 @@ static int rv3028_probe(struct i2c_client *client) if (ret) return ret; + ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &val_old); + if (ret < 0) + return ret; + + /* mask out only trickle charger bits */ + val_old = val_old & (RV3028_BACKUP_TCE | RV3028_BACKUP_TCR_MASK); + /* setup trickle charger */ - if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms", - &ohms)) { + if (device_property_read_u32(&client->dev, "trickle-resistor-ohms", &ohms)) { + /* disable the trickle charger */ + val = 0; + } else { int i; for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++) @@ -947,15 +957,21 @@ static int rv3028_probe(struct i2c_client *client) break; if (i < ARRAY_SIZE(rv3028_trickle_resistors)) { - ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE | - RV3028_BACKUP_TCR_MASK, RV3028_BACKUP_TCE | i); - if (ret) - return ret; + /* enable the trickle charger and setup its resistor accordingly */ + val = RV3028_BACKUP_TCE | i; } else { dev_warn(&client->dev, "invalid trickle resistor value\n"); } } + /* only update EEPROM if changes are necessary */ + if (val_old != val) { + ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE | + RV3028_BACKUP_TCR_MASK, val); + if (ret) + return ret; + } + ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group); if (ret) return ret; -- 2.25.1