diff mbox

rtc: pcf8563: Do not disable clk out by default

Message ID 1481295829-21974-1-git-send-email-volodymyr.bendiuga@westermo.se
State Rejected
Headers show

Commit Message

Volodymyr Bendiuga Dec. 9, 2016, 3:03 p.m. UTC
From: Mattias Walström <mattias.walstrom@westermo.se>

Commit a39a6405d5f949bc651694028a disables CLKOUT of
the rtc after power-up to improve power consumption.
This is very useful, but some designs do require to
have the rtc on all the time, otherwise devices will
be bricked. Therefore this patch is a compromise that
works for both cases, where the default case is when
CLKOUT is on. If one wants to disable the CLKOUT,
clkout-allow-disable can be added to devicetree's rtc node.

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
---
 Documentation/devicetree/bindings/rtc/pcf8563.txt |  1 +
 drivers/rtc/rtc-pcf8563.c                         | 11 +++--------
 2 files changed, 4 insertions(+), 8 deletions(-)

Comments

Alexandre Belloni Dec. 19, 2016, 12:25 a.m. UTC | #1
On 09/12/2016 at 16:03:49 +0100, Volodymyr Bendiuga wrote :
> From: Mattias Walström <mattias.walstrom@westermo.se>
> 
> Commit a39a6405d5f949bc651694028a disables CLKOUT of
> the rtc after power-up to improve power consumption.
> This is very useful, but some designs do require to
> have the rtc on all the time, otherwise devices will
> be bricked. Therefore this patch is a compromise that
> works for both cases, where the default case is when
> CLKOUT is on. If one wants to disable the CLKOUT,
> clkout-allow-disable can be added to devicetree's rtc node.
> 

Actually, the commit description is misleading. The CCF is the one
disabling the clock if it is not used. If any user of the clock is
declared, it will not be disabled so it already works in both cases
(provided you have a proper driver getting the clock).
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/rtc/pcf8563.txt b/Documentation/devicetree/bindings/rtc/pcf8563.txt
index 086c998..0b06a36 100644
--- a/Documentation/devicetree/bindings/rtc/pcf8563.txt
+++ b/Documentation/devicetree/bindings/rtc/pcf8563.txt
@@ -7,6 +7,7 @@  see: Documentation/devicetree/bindings/i2c/trivial-admin-guide/devices.rst
 
 Optional property:
 - #clock-cells: Should be 0.
+- clkout-allow-disable: Allow the CLKOUT to be disabled if not used.
 - clock-output-names:
   overwrite the default clock name "pcf8563-clkout"
 
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 1227cea..1489ee9 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -519,18 +519,13 @@  static struct clk *pcf8563_clkout_register_clk(struct pcf8563 *pcf8563)
 	struct device_node *node = client->dev.of_node;
 	struct clk *clk;
 	struct clk_init_data init;
-	int ret;
-	unsigned char buf;
-
-	/* disable the clkout output */
-	buf = 0;
-	ret = pcf8563_write_block_data(client, PCF8563_REG_CLKO, 1, &buf);
-	if (ret < 0)
-		return ERR_PTR(ret);
 
 	init.name = "pcf8563-clkout";
 	init.ops = &pcf8563_clkout_ops;
+
+	/* disable the clkout output only if it is allowed in devicetree */
 	init.flags = 0;
+	init.flags |= !of_property_read_bool(node, "clkout-allow-disable") ? CLK_IGNORE_UNUSED : 0;
 	init.parent_names = NULL;
 	init.num_parents = 0;
 	pcf8563->clkout_hw.init = &init;