All of lore.kernel.org
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <20230613130011.305589-9-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <20230613130011.305589-1-linux@rasmusvillemoes.dk>

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

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);
 
-- 
2.37.2


  parent reply	other threads:[~2023-06-13 13:01 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 11:30 [PATCH 0/8] rtc: isl12022: battery backup voltage and clock support Rasmus Villemoes
2023-06-12 11:30 ` [PATCH 1/8] rtc: isl12022: remove wrong warning for low battery level Rasmus Villemoes
2023-06-12 11:30 ` [PATCH 2/8] dt-bindings: rtc: Move isil,isl12022 from trivial-rtc.yaml into own schema file Rasmus Villemoes
2023-06-12 12:26   ` Rob Herring
2023-06-12 12:36     ` Rasmus Villemoes
2023-06-12 13:54       ` Alexandre Belloni
2023-06-12 14:20       ` Rob Herring
2023-06-13  8:13         ` Rasmus Villemoes
2023-06-12 11:30 ` [PATCH 3/8] dt-bindings: rtc: isl12022: add bindings for battery alarm trip levels Rasmus Villemoes
2023-06-12 11:30 ` [PATCH 4/8] rtc: isl12022: add support for trip level DT bindings Rasmus Villemoes
2023-06-12 15:44   ` Andy Shevchenko
2023-06-12 18:10   ` kernel test robot
2023-06-12 18:58   ` kernel test robot
2023-06-12 11:30 ` [PATCH 5/8] rtc: isl12022: implement RTC_VL_READ and RTC_VL_CLR ioctls Rasmus Villemoes
2023-06-12 14:07   ` Alexandre Belloni
2023-06-13  7:27     ` Rasmus Villemoes
2023-06-12 15:48   ` Andy Shevchenko
2023-06-12 16:10     ` Alexandre Belloni
2023-06-13  7:53       ` Rasmus Villemoes
2023-06-13  9:00         ` Alexandre Belloni
2023-06-12 11:30 ` [PATCH 6/8] rtc: isl12022: trigger battery level detection during probe Rasmus Villemoes
2023-06-12 12:30   ` Rasmus Villemoes
2023-06-12 14:17     ` Alexandre Belloni
2023-06-13  7:51       ` Rasmus Villemoes
2023-06-12 14:15   ` Alexandre Belloni
2023-06-13  7:44     ` Rasmus Villemoes
2023-06-13  8:58       ` Alexandre Belloni
2023-06-12 11:30 ` [PATCH 7/8] dt-bindings: rtc: isl12022: add #clock-cells property Rasmus Villemoes
2023-06-13  7:41   ` Krzysztof Kozlowski
2023-06-12 11:30 ` [PATCH 8/8] rtc: isl12022: implement support for the #clock-cells DT property Rasmus Villemoes
2023-06-13 13:00 ` [PATCH v2 0/8] rtc: isl12022: battery backup voltage and clock support Rasmus Villemoes
2023-06-13 13:00   ` [PATCH v2 1/8] rtc: isl12022: remove wrong warning for low battery level Rasmus Villemoes
2023-06-13 13:00   ` [PATCH v2 2/8] dt-bindings: rtc: Move isil,isl12022 from trivial-rtc.yaml into own schema file Rasmus Villemoes
2023-06-13 19:06     ` Krzysztof Kozlowski
2023-06-13 13:00   ` [PATCH v2 3/8] dt-bindings: rtc: isl12022: add bindings for battery alarm trip levels Rasmus Villemoes
2023-06-13 19:09     ` Krzysztof Kozlowski
2023-06-13 19:51       ` Rasmus Villemoes
2023-06-13 21:37         ` Krzysztof Kozlowski
2023-06-13 13:00   ` [PATCH v2 4/8] rtc: isl12022: add support for trip level DT bindings Rasmus Villemoes
2023-06-13 13:00   ` [PATCH v2 5/8] rtc: isl12022: implement RTC_VL_READ ioctl Rasmus Villemoes
2023-06-13 15:20     ` Andy Shevchenko
2023-06-13 21:26       ` Alexandre Belloni
2023-06-14 12:16         ` Andy Shevchenko
2023-06-14 13:50           ` Alexandre Belloni
2023-06-14 15:13             ` Andy Shevchenko
2023-06-15 10:53               ` Rasmus Villemoes
2023-06-15 10:58                 ` Andy Shevchenko
2023-06-13 13:00   ` [PATCH v2 6/8] rtc: isl12022: trigger battery level detection during probe Rasmus Villemoes
2023-06-13 13:00   ` [PATCH v2 7/8] dt-bindings: rtc: isl12022: add #clock-cells property Rasmus Villemoes
2023-06-13 19:10     ` Krzysztof Kozlowski
2023-06-13 20:25       ` Rasmus Villemoes
2023-06-13 21:38         ` Krzysztof Kozlowski
2023-06-13 13:00   ` Rasmus Villemoes [this message]
2023-06-13 15:25     ` [PATCH v2 8/8] rtc: isl12022: implement support for the #clock-cells DT property Andy Shevchenko
2023-06-14 10:51       ` Rasmus Villemoes
2023-06-14 12:13         ` Andy Shevchenko
2023-06-13 19:10     ` kernel test robot
2023-06-14  5:27     ` kernel test robot
2023-06-13 15:26   ` [PATCH v2 0/8] rtc: isl12022: battery backup voltage and clock support Andy Shevchenko
2023-06-13 19:06   ` Krzysztof Kozlowski
2023-06-15 11:03     ` Rasmus Villemoes
2023-06-15 10:58 ` [PATCH v3 " Rasmus Villemoes
2023-06-15 10:58   ` [PATCH v3 1/8] rtc: isl12022: remove wrong warning for low battery level Rasmus Villemoes
2023-06-15 10:58   ` [PATCH v3 2/8] dt-bindings: rtc: Move isil,isl12022 from trivial-rtc.yaml into own schema file Rasmus Villemoes
2023-06-15 10:58   ` [PATCH v3 3/8] dt-bindings: rtc: isl12022: add bindings for battery alarm trip levels Rasmus Villemoes
2023-06-17  8:12     ` Krzysztof Kozlowski
2023-06-15 10:58   ` [PATCH v3 4/8] rtc: isl12022: add support for trip level DT binding Rasmus Villemoes
2023-06-15 11:11     ` Andy Shevchenko
2023-06-19  7:27       ` Rasmus Villemoes
2023-06-15 10:58   ` [PATCH v3 5/8] rtc: isl12022: implement RTC_VL_READ ioctl Rasmus Villemoes
2023-06-15 10:58   ` [PATCH v3 6/8] rtc: isl12022: trigger battery level detection during probe Rasmus Villemoes
2023-06-15 10:58   ` [PATCH v3 7/8] dt-bindings: rtc: isl12022: add #clock-cells property Rasmus Villemoes
2023-06-17  8:13     ` Krzysztof Kozlowski
2023-06-15 10:58   ` [PATCH v3 8/8] rtc: isl12022: implement support for the #clock-cells DT property Rasmus Villemoes
2023-07-28 14:31   ` [PATCH v3 0/8] rtc: isl12022: battery backup voltage and clock support Rasmus Villemoes
2023-08-03  6:45     ` Rasmus Villemoes
2023-08-09 12:28       ` Rasmus Villemoes
2023-08-15 23:28   ` Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230613130011.305589-9-linux@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.