All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: rv3028: Improve trickle charger logic
@ 2023-06-08  9:04 Andrej Picej
  2023-06-08  9:31 ` Alexandre Belloni
  2023-06-08 14:48 ` kernel test robot
  0 siblings, 2 replies; 6+ messages in thread
From: Andrej Picej @ 2023-06-08  9:04 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: linux-rtc, linux-kernel, upstream

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(-)

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: rv3028: Improve trickle charger logic
@ 2023-06-08 20:57 kernel test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2023-06-08 20:57 UTC (permalink / raw)
  Cc: oe-kbuild-all, llvm

In-Reply-To: <20230608090446.2899646-1-andrej.picej@norik.com>
References: <20230608090446.2899646-1-andrej.picej@norik.com>
TO: Andrej Picej <andrej.picej@norik.com>
TO: a.zummo@towertech.it
TO: alexandre.belloni@bootlin.com
CC: linux-rtc@vger.kernel.org
CC: linux-kernel@vger.kernel.org
CC: upstream@phytec.de

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-a015-20230608 (https://download.01.org/0day-ci/archive/20230609/202306090421.91eXRy6m-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/

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/202306090421.91eXRy6m-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.
>> drivers/rtc/rtc-rv3028.o: warning: objtool: rv3028_probe() falls through to next function rv3028_nvram_read()

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-15  6:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-08  9:04 [PATCH] rtc: rv3028: Improve trickle charger logic Andrej Picej
2023-06-08  9:31 ` Alexandre Belloni
2023-06-08 10:35   ` Andrej Picej
2023-06-15  6:06     ` Andrej Picej
2023-06-08 14:48 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-06-08 20:57 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.