Message ID | 20230613130011.305589-9-linux@rasmusvillemoes.dk |
---|---|
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 k13csp526285vqr; Tue, 13 Jun 2023 06:04:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6C8srIkWWUIfeOgObpESqDTgi/eFxCO5G/j/RUsXd3G8vJRhVoDc6HZYIebiBnexHG3i0y X-Received: by 2002:a17:907:9620:b0:978:8790:9103 with SMTP id gb32-20020a170907962000b0097887909103mr15894268ejc.70.1686661452272; Tue, 13 Jun 2023 06:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686661452; cv=none; d=google.com; s=arc-20160816; b=yZ76GZBJxzyC5BDlD3Rfpjdb54i0OMJjTDjwszHd3+f0RXUiG1RuKFfv7Sk0w7wjwp dfBtTMkDVcmRelOHJRrtZ98nl0nCTDYQ8XV3HQWzLdUeFGQoeoJAwTiFixziu7fP+Vwk 1p2BYPF3QrRBrwFdk7+EdvelmDujqDOJD/vZf5addBD4EBbVUap6K+zvAYAwUC87F62d JFMvnfJXP4R8zn6G6vCirFYkGSaBoAPIOTqJ75b+FAvknOxQ+v4dSLmA2JPZ3d+xkkKR 6N3fOIqFXVr25u1qkYKsFuBaOIU98aA2pKkwZ7+xFNLi9dF/pye8XZkGdswA5dlhNGXr 6Qjw== 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=46KkCoyCaP4pL/jEPklf2fuk5AVWyAvfGth05Co0T18=; b=X/+6f5OtuP7Rbm09ICleDQZKWe7EPs3iqnUlaPjpA71QJp07m+uo4Q7RptXQjxG2tL EdQlvJd3JaYmvYOQLpqamajSjPHBkeRZyRAFvUK9ERGb7c4XifvIZ4bW5gV9fAAm/2pc s2/RFx0prKdgDX/sc+9zkMFoLTkwScn6TMtDA26LlmZ7owxDSTEfVbuLAqOSOa2KBtwt zIYV5qcrs5amf1BNOy+QdUNv435IYjFLGhblYb/lYDYvdnQbvEEf5JrWk10NABPpYwLw VqowVXfxq+/DLEsrElqLJqweZPSQDIep/Q8N/MHNP2rJHdCk8De1pZo6SkRdduSwyy6I fprg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=haQOPWKa; 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 f25-20020a170906391900b009788caec3f8si7187126eje.352.2023.06.13.06.03.44; Tue, 13 Jun 2023 06:04:12 -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=haQOPWKa; 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 S242544AbjFMNB4 (ORCPT <rfc822;lekhanya01809@gmail.com> + 99 others); Tue, 13 Jun 2023 09:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242499AbjFMNBP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 13 Jun 2023 09:01:15 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 456D410E9 for <linux-kernel@vger.kernel.org>; Tue, 13 Jun 2023 06:01:14 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f649db9b25so6691340e87.0 for <linux-kernel@vger.kernel.org>; Tue, 13 Jun 2023 06:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686661272; x=1689253272; 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=46KkCoyCaP4pL/jEPklf2fuk5AVWyAvfGth05Co0T18=; b=haQOPWKa3ER2duykMm+Sd0Nw4FfDB0m4UkrtopsZoLbZe5z0EQuBlcfaZjRcVf7oI7 gSOYW1J5eCDYEE938vG6q9t9zkVV1LYsz1/P0Ya6BTaYoYiY2lRDk6SfKNE6FV+Qc1+D QK/hgXfh4ct2iLAwQgA0Z8UuyFOUsvcCdAGS0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686661272; x=1689253272; 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=46KkCoyCaP4pL/jEPklf2fuk5AVWyAvfGth05Co0T18=; b=EcOACeSCe7ROQKiIczjgQoFL0nDkecoJnz2O2LiJUnfb8xGx9TN0NdfpR6pQDHLUGG KSAUYEpdmzPVtBrA4HX1Iz/JZPBucRglMXKS2JX4HeGwcubTx1/awKy58uXIcxI7OqRF n2eypMQrkxfkg3GXH6RWHFW8seeNMcWz4XpsuNp9MSwWFatLfAFpw1AnVRRBTu0TNj1U thhdl+NhcQATe90GqfmXXryV9UsUGe+evbxyqYKOWDbMz5UfmTzishFZUq8AKOuxJZdu YXD30DUD/pRwOTwh71Zfa4UD/I7bT76YAkhLICk3rIeqqYLPebDQm32YDqhwbh+kwFw0 WduA== X-Gm-Message-State: AC+VfDy8mTidhPjNZh4rjT2Vm7twa/j1U7rsCtgphEfJscovopJ3/2Yr OgeCIg8dN6ENZYZnF3yjztCwxw== X-Received: by 2002:a19:771d:0:b0:4f6:217a:561e with SMTP id s29-20020a19771d000000b004f6217a561emr5797407lfc.37.1686661272390; Tue, 13 Jun 2023 06:01:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 06:01:11 -0700 (PDT) From: Rasmus Villemoes <linux@rasmusvillemoes.dk> To: Alessandro Zummo <a.zummo@towertech.it>, Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>, devicetree@vger.kernel.org, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, linux-rtc@vger.kernel.org, Rasmus Villemoes <linux@rasmusvillemoes.dk>, linux-kernel@vger.kernel.org Subject: [PATCH v2 8/8] rtc: isl12022: implement support for the #clock-cells DT property Date: Tue, 13 Jun 2023 15:00:10 +0200 Message-Id: <20230613130011.305589-9-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=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: <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?1768496922138312599?= X-GMAIL-MSGID: =?utf-8?q?1768592718987268380?= |
Series |
rtc: isl12022: battery backup voltage and clock support
|
|
Commit Message
Rasmus Villemoes
June 13, 2023, 1 p.m. UTC
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 <linux@rasmusvillemoes.dk>
---
drivers/rtc/rtc-isl12022.c | 40 ++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
Comments
On Tue, Jun 13, 2023 at 03:00:10PM +0200, Rasmus Villemoes wrote: > 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. ... > +#define ISL12022_INT_FO_MASK GENMASK(3, 0) > +#define ISL12022_INT_FO_OFF 0x0 > +#define ISL12022_INT_FO_32K 0x1 A nit-pick. Are they decimal or bit fields? To me seems like the 0x can be dropped. ... > + ret = regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, ISL12022_INT_FO_32K); Seems too long even for 100 limit. Maybe: ret = regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, ISL12022_INT_FO_32K); ?
Hi Rasmus, kernel test robot noticed the following build errors: [auto build test ERROR on abelloni/rtc-next] [also build test ERROR on robh/for-next linus/master v6.4-rc6 next-20230613] [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/Rasmus-Villemoes/rtc-isl12022-remove-wrong-warning-for-low-battery-level/20230613-210308 base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next patch link: https://lore.kernel.org/r/20230613130011.305589-9-linux%40rasmusvillemoes.dk patch subject: [PATCH v2 8/8] rtc: isl12022: implement support for the #clock-cells DT property config: hexagon-randconfig-r041-20230612 (https://download.01.org/0day-ci/archive/20230614/202306140237.9IMWa7cz-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) 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/20230613130011.305589-9-linux@rasmusvillemoes.dk # 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=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash 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/202306140237.9IMWa7cz-lkp@intel.com/ All errors (new ones prefixed by >>): >> ld.lld: error: undefined symbol: __clk_hw_register_fixed_rate >>> referenced by rtc-isl12022.c:272 (drivers/rtc/rtc-isl12022.c:272) >>> drivers/rtc/rtc-isl12022.o:(isl12022_probe) in archive vmlinux.a >>> referenced by rtc-isl12022.c:272 (drivers/rtc/rtc-isl12022.c:272) >>> drivers/rtc/rtc-isl12022.o:(isl12022_probe) in archive vmlinux.a
Hi Rasmus, kernel test robot noticed the following build errors: [auto build test ERROR on abelloni/rtc-next] [also build test ERROR on robh/for-next linus/master v6.4-rc6 next-20230613] [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/Rasmus-Villemoes/rtc-isl12022-remove-wrong-warning-for-low-battery-level/20230613-210308 base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next patch link: https://lore.kernel.org/r/20230613130011.305589-9-linux%40rasmusvillemoes.dk patch subject: [PATCH v2 8/8] rtc: isl12022: implement support for the #clock-cells DT property config: i386-randconfig-i012-20230612 (https://download.01.org/0day-ci/archive/20230614/202306141318.xPzubJXo-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): 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/20230613130011.305589-9-linux@rasmusvillemoes.dk # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 olddefconfig make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash 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/202306141318.xPzubJXo-lkp@intel.com/ All errors (new ones prefixed by >>, old ones prefixed by <<): >> ERROR: modpost: "__clk_hw_register_fixed_rate" [drivers/rtc/rtc-isl12022.ko] undefined! >> ERROR: modpost: "of_clk_hw_simple_get" [drivers/rtc/rtc-isl12022.ko] undefined! >> ERROR: modpost: "devm_of_clk_add_hw_provider" [drivers/rtc/rtc-isl12022.ko] undefined!
On 13/06/2023 17.25, Andy Shevchenko wrote: > On Tue, Jun 13, 2023 at 03:00:10PM +0200, Rasmus Villemoes wrote: >> 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. > > ... > >> +#define ISL12022_INT_FO_MASK GENMASK(3, 0) >> +#define ISL12022_INT_FO_OFF 0x0 >> +#define ISL12022_INT_FO_32K 0x1 > > A nit-pick. Are they decimal or bit fields? -ENOPARSE. A number is a number. Its representation in C code may be decimal or hexadecimal (or...). And sure, 0 and 0x0 are different spellings of the same thing. The data sheet lists the possible values in terms of individual bits, so I suppose I could even do 0b0000 and 0b0001, but that's too unusual (even if perfectly acceptable by gcc). > To me seems like the 0x can be dropped. Can, but won't, a single hex digit is more natural way to represent a four-bit field. >> + ret = regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, ISL12022_INT_FO_32K); > > Seems too long even for 100 limit. > Maybe: > > ret = regmap_update_bits(regmap, ISL12022_REG_INT, > ISL12022_INT_FO_MASK, ISL12022_INT_FO_32K); Sure. Rasmus
On Wed, Jun 14, 2023 at 12:51:47PM +0200, Rasmus Villemoes wrote: > On 13/06/2023 17.25, Andy Shevchenko wrote: > > On Tue, Jun 13, 2023 at 03:00:10PM +0200, Rasmus Villemoes wrote: ... > >> +#define ISL12022_INT_FO_MASK GENMASK(3, 0) > >> +#define ISL12022_INT_FO_OFF 0x0 > >> +#define ISL12022_INT_FO_32K 0x1 > > > > A nit-pick. Are they decimal or bit fields? > > -ENOPARSE. A number is a number. Its representation in C code may be > decimal or hexadecimal (or...). And sure, 0 and 0x0 are different > spellings of the same thing. The data sheet lists the possible values in > terms of individual bits, so I suppose I could even do 0b0000 and > 0b0001, but that's too unusual (even if perfectly acceptable by gcc). What does datasheet define? bits or the value in a 4-bit field? If bits, why don't you put it that way #define ISL12022_INT_FO_OFF 0 #define ISL12022_INT_FO_32K BIT(0) ? It's a nit-pick, of course, but the nuance is that proposed form might give a hint to the reader, current -- not. > > To me seems like the 0x can be dropped. > > Can, but won't, a single hex digit is more natural way to represent a > four-bit field.
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index 44603169e575..3e69f1a5dc12 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -10,6 +10,7 @@ #include <linux/bcd.h> #include <linux/bitfield.h> +#include <linux/clk-provider.h> #include <linux/err.h> #include <linux/hwmon.h> #include <linux/i2c.h> @@ -44,6 +45,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) @@ -241,6 +245,37 @@ 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%. + */ + regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, + ISL12022_INT_FO_OFF); + + 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", 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 }; @@ -284,6 +319,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; @@ -296,6 +332,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);