Message ID | 20230608090446.2899646-1-andrej.picej@norik.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp209206vqr; Thu, 8 Jun 2023 04:30:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65zjNax84EDOpBTxKbqv89Ul3qlSvn/KDOtWvFKYiAK7I3uS123q7iG89DnmGXXhp0kELF X-Received: by 2002:a05:6a20:244c:b0:114:f141:733b with SMTP id t12-20020a056a20244c00b00114f141733bmr6994349pzc.15.1686223811528; Thu, 08 Jun 2023 04:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686223811; cv=none; d=google.com; s=arc-20160816; b=bfUl3Q7yReNHL4azgoXqgFYq1nPZLDGEsopq3HtrGUTAzeB2HGe2uucHfMQqjzABJt xSGdSKh+K1v3GFQZBH8fLypzuOXeXFxiWO7xKQybxBAs772s24pTP0h3kwU9btBnCvFm tiTJa2WK9lfrQXZ/Tt/1Xlh3Pjf+DVUrtAwZUbPZG+o3TFanIOlMTR0jkRXEpLWYik7W 6SyR/PZ39W+3Jutg40ELSI1vmT3jJHmN+z5OnrnwPt5qFVfso+uOIMT5NdSHsgirEDnT o5c/RaemKIBdyJ/5YE0hq+SXz9mDobCjgjtyKTgGoqiY4dvvEPURErJC82GX6BRAYyaM zXPQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a638f4f000000b0053f25f2d32fsi834043pgn.831.2023.06.08.04.29.56; Thu, 08 Jun 2023 04:30:11 -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 S235776AbjFHLAf (ORCPT <rfc822;liningstudo@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <andrej.picej@norik.com>) id 1q7BZf-00CHxg-0m; Thu, 08 Jun 2023 11:04:54 +0200 From: Andrej Picej <andrej.picej@norik.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768127119706718394?= X-GMAIL-MSGID: =?utf-8?q?1768133819184423959?= |
Series |
rtc: rv3028: Improve trickle charger logic
|
|
Commit Message
Andrej Picej
June 8, 2023, 9:04 a.m. UTC
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 <andrej.picej@norik.com>
---
drivers/rtc/rtc-rv3028.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
Comments
Hi Andrej,
kernel test robot noticed the following build warnings:
[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on linus/master v6.4-rc5 next-20230608]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andrej-Picej/rtc-rv3028-Improve-trickle-charger-logic/20230608-190234
base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
patch link: https://lore.kernel.org/r/20230608090446.2899646-1-andrej.picej%40norik.com
patch subject: [PATCH] rtc: rv3028: Improve trickle charger logic
config: x86_64-randconfig-x062-20230608 (https://download.01.org/0day-ci/archive/20230608/202306082225.gJGvLhg6-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git remote add abelloni https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git
git fetch abelloni rtc-next
git checkout abelloni/rtc-next
b4 shazam https://lore.kernel.org/r/20230608090446.2899646-1-andrej.picej@norik.com
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/rtc/
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306082225.gJGvLhg6-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/rtc/rtc-rv3028.c:959:7: warning: variable 'val' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (i < ARRAY_SIZE(rv3028_trickle_resistors)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-rv3028.c:968:17: note: uninitialized use occurs here
if (val_old != val) {
^~~
drivers/rtc/rtc-rv3028.c:959:3: note: remove the 'if' if its condition is always true
if (i < ARRAY_SIZE(rv3028_trickle_resistors)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-rv3028.c:863:18: note: initialize the variable 'val' to silence this warning
int val_old, val;
^
= 0
1 warning generated.
vim +959 drivers/rtc/rtc-rv3028.c
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 857
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 858 static int rv3028_probe(struct i2c_client *client)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 859 {
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 860 struct rv3028_data *rv3028;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 861 int ret, status;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 862 u32 ohms;
7982492c6d02c7 Andrej Picej 2023-06-08 863 int val_old, val;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 864 struct nvmem_config nvmem_cfg = {
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 865 .name = "rv3028_nvram",
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 866 .word_size = 1,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 867 .stride = 1,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 868 .size = 2,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 869 .type = NVMEM_TYPE_BATTERY_BACKED,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 870 .reg_read = rv3028_nvram_read,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 871 .reg_write = rv3028_nvram_write,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 872 };
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 873 struct nvmem_config eeprom_cfg = {
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 874 .name = "rv3028_eeprom",
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 875 .word_size = 1,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 876 .stride = 1,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 877 .size = 43,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 878 .type = NVMEM_TYPE_EEPROM,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 879 .reg_read = rv3028_eeprom_read,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 880 .reg_write = rv3028_eeprom_write,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 881 };
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 882
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 883 rv3028 = devm_kzalloc(&client->dev, sizeof(struct rv3028_data),
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 884 GFP_KERNEL);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 885 if (!rv3028)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 886 return -ENOMEM;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 887
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 888 rv3028->regmap = devm_regmap_init_i2c(client, ®map_config);
c3b29bf6f166f6 Chuhong Yuan 2020-05-28 889 if (IS_ERR(rv3028->regmap))
c3b29bf6f166f6 Chuhong Yuan 2020-05-28 890 return PTR_ERR(rv3028->regmap);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 891
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 892 i2c_set_clientdata(client, rv3028);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 893
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 894 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 895 if (ret < 0)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 896 return ret;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 897
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 898 if (status & RV3028_STATUS_AF)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 899 dev_warn(&client->dev, "An alarm may have been missed.\n");
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 900
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 901 rv3028->rtc = devm_rtc_allocate_device(&client->dev);
44c638ce4ec6fb Alexandre Belloni 2019-08-19 902 if (IS_ERR(rv3028->rtc))
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 903 return PTR_ERR(rv3028->rtc);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 904
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 905 if (client->irq > 0) {
16b26f6027588b Wadim Egorov 2022-12-08 906 unsigned long flags;
16b26f6027588b Wadim Egorov 2022-12-08 907
16b26f6027588b Wadim Egorov 2022-12-08 908 /*
16b26f6027588b Wadim Egorov 2022-12-08 909 * If flags = 0, devm_request_threaded_irq() will use IRQ flags
16b26f6027588b Wadim Egorov 2022-12-08 910 * obtained from device tree.
16b26f6027588b Wadim Egorov 2022-12-08 911 */
16b26f6027588b Wadim Egorov 2022-12-08 912 if (dev_fwnode(&client->dev))
16b26f6027588b Wadim Egorov 2022-12-08 913 flags = 0;
16b26f6027588b Wadim Egorov 2022-12-08 914 else
16b26f6027588b Wadim Egorov 2022-12-08 915 flags = IRQF_TRIGGER_LOW;
16b26f6027588b Wadim Egorov 2022-12-08 916
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 917 ret = devm_request_threaded_irq(&client->dev, client->irq,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 918 NULL, rv3028_handle_irq,
16b26f6027588b Wadim Egorov 2022-12-08 919 flags | IRQF_ONESHOT,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 920 "rv3028", rv3028);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 921 if (ret) {
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 922 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 923 client->irq = 0;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 924 }
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 925 }
0f7695691be617 Alexandre Belloni 2021-01-11 926 if (!client->irq)
0f7695691be617 Alexandre Belloni 2021-01-11 927 clear_bit(RTC_FEATURE_ALARM, rv3028->rtc->features);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 928
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 929 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL1,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 930 RV3028_CTRL1_WADA, RV3028_CTRL1_WADA);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 931 if (ret)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 932 return ret;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 933
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 934 /* setup timestamping */
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 935 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 936 RV3028_CTRL2_EIE | RV3028_CTRL2_TSE,
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 937 RV3028_CTRL2_EIE | RV3028_CTRL2_TSE);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 938 if (ret)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 939 return ret;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 940
7982492c6d02c7 Andrej Picej 2023-06-08 941 ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &val_old);
7982492c6d02c7 Andrej Picej 2023-06-08 942 if (ret < 0)
7982492c6d02c7 Andrej Picej 2023-06-08 943 return ret;
7982492c6d02c7 Andrej Picej 2023-06-08 944
7982492c6d02c7 Andrej Picej 2023-06-08 945 /* mask out only trickle charger bits */
7982492c6d02c7 Andrej Picej 2023-06-08 946 val_old = val_old & (RV3028_BACKUP_TCE | RV3028_BACKUP_TCR_MASK);
7982492c6d02c7 Andrej Picej 2023-06-08 947
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 948 /* setup trickle charger */
7982492c6d02c7 Andrej Picej 2023-06-08 949 if (device_property_read_u32(&client->dev, "trickle-resistor-ohms", &ohms)) {
7982492c6d02c7 Andrej Picej 2023-06-08 950 /* disable the trickle charger */
7982492c6d02c7 Andrej Picej 2023-06-08 951 val = 0;
7982492c6d02c7 Andrej Picej 2023-06-08 952 } else {
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 953 int i;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 954
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 955 for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 956 if (ohms == rv3028_trickle_resistors[i])
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 957 break;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 958
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 @959 if (i < ARRAY_SIZE(rv3028_trickle_resistors)) {
7982492c6d02c7 Andrej Picej 2023-06-08 960 /* enable the trickle charger and setup its resistor accordingly */
7982492c6d02c7 Andrej Picej 2023-06-08 961 val = RV3028_BACKUP_TCE | i;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 962 } else {
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 963 dev_warn(&client->dev, "invalid trickle resistor value\n");
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 964 }
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 965 }
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 966
7982492c6d02c7 Andrej Picej 2023-06-08 967 /* only update EEPROM if changes are necessary */
7982492c6d02c7 Andrej Picej 2023-06-08 968 if (val_old != val) {
7982492c6d02c7 Andrej Picej 2023-06-08 969 ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE |
7982492c6d02c7 Andrej Picej 2023-06-08 970 RV3028_BACKUP_TCR_MASK, val);
7982492c6d02c7 Andrej Picej 2023-06-08 971 if (ret)
7982492c6d02c7 Andrej Picej 2023-06-08 972 return ret;
7982492c6d02c7 Andrej Picej 2023-06-08 973 }
7982492c6d02c7 Andrej Picej 2023-06-08 974
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 975 ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 976 if (ret)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 977 return ret;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 978
018d959ba7ffca Alexandre Belloni 2021-10-18 979 set_bit(RTC_FEATURE_BACKUP_SWITCH_MODE, rv3028->rtc->features);
018d959ba7ffca Alexandre Belloni 2021-10-18 980
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 981 rv3028->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 982 rv3028->rtc->range_max = RTC_TIMESTAMP_END_2099;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 983 rv3028->rtc->ops = &rv3028_rtc_ops;
fdcfd854333be5 Bartosz Golaszewski 2020-11-09 984 ret = devm_rtc_register_device(rv3028->rtc);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 985 if (ret)
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 986 return ret;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 987
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 988 nvmem_cfg.priv = rv3028->regmap;
3a905c2d9544a4 Bartosz Golaszewski 2020-11-09 989 devm_rtc_nvmem_register(rv3028->rtc, &nvmem_cfg);
de0ad60e79e1ce Alexandre Belloni 2020-10-09 990 eeprom_cfg.priv = rv3028;
3a905c2d9544a4 Bartosz Golaszewski 2020-11-09 991 devm_rtc_nvmem_register(rv3028->rtc, &eeprom_cfg);
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 992
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 993 rv3028->rtc->max_user_freq = 1;
e6e7376cfd7b3f Alexandre Belloni 2019-02-13 994
On 8. 06. 23 12:35, Andrej Picej wrote: > Hi Alexandre, > > On 8. 06. 23 11:31, Alexandre Belloni wrote: >> Hello, >> >> On 08/06/2023 11:04:46+0200, Andrej Picej wrote: >>> + 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; >> >> You can't do that, this will break existing users that may set the >> trickle charger from their bootloader for example. > > hmm...ok I understand that idea. I thought that might be a problem. I > guess keeping default as it is has a higher priority. > > What do you say if setting this property to 0 (or maybe -1) disabled the > trickle charger? > So if users add: > > trickle-resistor-ohms = <0>; > or > trickle-resistor-ohms = <(-1)>; > > this would mean disable the trickle charger? > > I know it is far from optimal, but this would solve both things: > * not braking existing implementation, > * users could disable the trickle charger. > > What do you say. Gentle ping. Would this be something you would consider? Thanks, Andrej > > Thanks for your review. > > Best regards, > Andrej > >> >>> + } 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 >>> >>
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;