devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2]  ARM: AM437X: Add rtc clock handling
@ 2015-08-17  4:55 Keerthy
       [not found] ` <1439787338-27396-1-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Keerthy @ 2015-08-17  4:55 UTC (permalink / raw)
  To: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw
  Cc: tony-4v6yS6AI5VpBDgjK7y7TUQ,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	johan-DgEjT+Ai2ygdnm+yROfE0A, grygorii.strashko-l0cyMroinI0,
	bcousson-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA, t-kristo-l0cyMroinI0,
	j-keerthy-l0cyMroinI0

The series is applicable for all am437x series of processors.
It adds clock handling support. Boot tested on am437x-gp-evm.

Keerthy (2):
  ARM: dts: AM437x: Add the internal and external clock nodes for rtc
  rtc: omap: Add external clock enabling support

 arch/arm/boot/dts/am4372.dtsi        |  2 ++
 arch/arm/boot/dts/am437x-gp-evm.dts  | 13 +++++++++++
 arch/arm/boot/dts/am437x-idk-evm.dts |  9 ++++++++
 arch/arm/boot/dts/am437x-sk-evm.dts  |  9 ++++++++
 drivers/rtc/rtc-omap.c               | 44 ++++++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2 1/2] ARM: dts: AM437x: Add the internal and external clock nodes for rtc
       [not found] ` <1439787338-27396-1-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
@ 2015-08-17  4:55   ` Keerthy
  2015-08-17  4:55   ` [PATCH v2 2/2] rtc: omap: Add external clock enabling support Keerthy
  1 sibling, 0 replies; 6+ messages in thread
From: Keerthy @ 2015-08-17  4:55 UTC (permalink / raw)
  To: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw
  Cc: tony-4v6yS6AI5VpBDgjK7y7TUQ,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	johan-DgEjT+Ai2ygdnm+yROfE0A, grygorii.strashko-l0cyMroinI0,
	bcousson-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA, t-kristo-l0cyMroinI0,
	j-keerthy-l0cyMroinI0

rtc can either be supplied from internal 32k clock or external crystal
generated 32k clock. Internal clock is SOC specific and the external
clock is board dependent. Adding the corresponding nodes.

Signed-off-by: Keerthy <j-keerthy-l0cyMroinI0@public.gmane.org>
---
 arch/arm/boot/dts/am4372.dtsi        |  2 ++
 arch/arm/boot/dts/am437x-gp-evm.dts  | 13 +++++++++++++
 arch/arm/boot/dts/am437x-idk-evm.dts |  9 +++++++++
 arch/arm/boot/dts/am437x-sk-evm.dts  |  9 +++++++++
 4 files changed, 33 insertions(+)

diff --git a/arch/arm/boot/dts/am4372.dtsi b/arch/arm/boot/dts/am4372.dtsi
index d99b2ee..484f092 100644
--- a/arch/arm/boot/dts/am4372.dtsi
+++ b/arch/arm/boot/dts/am4372.dtsi
@@ -336,6 +336,8 @@
 			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH
 				      GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>;
 			ti,hwmods = "rtc";
+			clocks = <&clk_32768_ck>;
+			clock-names = "int-clk";
 			status = "disabled";
 		};
 
diff --git a/arch/arm/boot/dts/am437x-gp-evm.dts b/arch/arm/boot/dts/am437x-gp-evm.dts
index 215775d..22038f2 100644
--- a/arch/arm/boot/dts/am437x-gp-evm.dts
+++ b/arch/arm/boot/dts/am437x-gp-evm.dts
@@ -112,6 +112,13 @@
 		clock-frequency = <12000000>;
 	};
 
+	/* fixed 32k external oscillator clock */
+	clk_32k_rtc: clk_32k_rtc {
+		#clock-cells = <0>;
+		compatible = "fixed-clock";
+		clock-frequency = <32768>;
+	};
+
 	sound0: sound@0 {
 		compatible = "simple-audio-card";
 		simple-audio-card,name = "AM437x-GP-EVM";
@@ -941,3 +948,9 @@
 	tx-num-evt = <32>;
 	rx-num-evt = <32>;
 };
+
+&rtc {
+	clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
+	clock-names = "ext-clk", "int-clk";
+	status = "okay";
+};
diff --git a/arch/arm/boot/dts/am437x-idk-evm.dts b/arch/arm/boot/dts/am437x-idk-evm.dts
index 37834427..af25801 100644
--- a/arch/arm/boot/dts/am437x-idk-evm.dts
+++ b/arch/arm/boot/dts/am437x-idk-evm.dts
@@ -110,6 +110,13 @@
 			gpios = <&gpio4 2 GPIO_ACTIVE_LOW>;
 		};
 	};
+
+	/* fixed 32k external oscillator clock */
+	clk_32k_rtc: clk_32k_rtc {
+		#clock-cells = <0>;
+		compatible = "fixed-clock";
+		clock-frequency = <32768>;
+	};
 };
 
 &am43xx_pinmux {
@@ -394,6 +401,8 @@
 };
 
 &rtc {
+	clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
+	clock-names = "ext-clk", "int-clk";
 	status = "okay";
 };
 
diff --git a/arch/arm/boot/dts/am437x-sk-evm.dts b/arch/arm/boot/dts/am437x-sk-evm.dts
index 22af448..7da7c2d 100644
--- a/arch/arm/boot/dts/am437x-sk-evm.dts
+++ b/arch/arm/boot/dts/am437x-sk-evm.dts
@@ -24,6 +24,13 @@
 		display0 = &lcd0;
 	};
 
+	/* fixed 32k external oscillator clock */
+	clk_32k_rtc: clk_32k_rtc {
+		#clock-cells = <0>;
+		compatible = "fixed-clock";
+		clock-frequency = <32768>;
+	};
+
 	backlight {
 		compatible = "pwm-backlight";
 		pwms = <&ecap0 0 50000 PWM_POLARITY_INVERTED>;
@@ -697,6 +704,8 @@
 };
 
 &rtc {
+	clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
+	clock-names = "ext-clk", "int-clk";
 	status = "okay";
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2 2/2] rtc: omap: Add external clock enabling support
       [not found] ` <1439787338-27396-1-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
  2015-08-17  4:55   ` [PATCH v2 1/2] ARM: dts: AM437x: Add the internal and external clock nodes for rtc Keerthy
@ 2015-08-17  4:55   ` Keerthy
       [not found]     ` <1439787338-27396-3-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
  1 sibling, 1 reply; 6+ messages in thread
From: Keerthy @ 2015-08-17  4:55 UTC (permalink / raw)
  To: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw
  Cc: tony-4v6yS6AI5VpBDgjK7y7TUQ,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	johan-DgEjT+Ai2ygdnm+yROfE0A, grygorii.strashko-l0cyMroinI0,
	bcousson-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA, t-kristo-l0cyMroinI0,
	j-keerthy-l0cyMroinI0

Configure the clock source to either internal clock
or external clock based on the availability of the clocks.
External clock is preferred as it can be ticking during suspend.

Signed-off-by: Keerthy <j-keerthy-l0cyMroinI0@public.gmane.org>
---

Changes in V2:

  * Changed clk_prepare calls to clk_prepare_enable.
  * Changed clk_unprepare calls to clk_disable_unprepare.
  * Added clk pointers for external and internal clock to omap_rtc structure.

 drivers/rtc/rtc-omap.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 8b6355f..46b3944 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -25,6 +25,7 @@
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/io.h>
+#include <linux/clk.h>
 
 /*
  * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock
@@ -107,6 +108,7 @@
 
 /* OMAP_RTC_OSC_REG bit fields: */
 #define OMAP_RTC_OSC_32KCLK_EN		BIT(6)
+#define OMAP_RTC_OSC_SEL_32KCLK_SRC	BIT(3)
 
 /* OMAP_RTC_IRQWAKEEN bit fields: */
 #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN	BIT(1)
@@ -132,10 +134,13 @@ struct omap_rtc_device_type {
 struct omap_rtc {
 	struct rtc_device *rtc;
 	void __iomem *base;
+	struct clk *ext_clk;
+	struct clk *int_clk;
 	int irq_alarm;
 	int irq_timer;
 	u8 interrupts_reg;
 	bool is_pmic_controller;
+	bool has_ext_clk;
 	const struct omap_rtc_device_type *type;
 };
 
@@ -553,6 +558,17 @@ static int omap_rtc_probe(struct platform_device *pdev)
 	if (rtc->irq_alarm <= 0)
 		return -ENOENT;
 
+	rtc->ext_clk = devm_clk_get(&pdev->dev, "ext-clk");
+	if (!IS_ERR(rtc->ext_clk)) {
+		rtc->has_ext_clk = true;
+		clk_prepare_enable(rtc->ext_clk);
+	} else {
+		rtc->int_clk = devm_clk_get(&pdev->dev, "int-clk");
+
+		if (!IS_ERR(rtc->int_clk))
+			clk_prepare_enable(rtc->int_clk);
+	}
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	rtc->base = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(rtc->base))
@@ -627,6 +643,16 @@ static int omap_rtc_probe(struct platform_device *pdev)
 	if (reg != new_ctrl)
 		rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl);
 
+	/*
+	 * If we have the external clock then switch to it so we can keep
+	 * ticking acorss suspend.
+	 */
+	if (rtc->has_ext_clk) {
+		reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
+		rtc_write(rtc, OMAP_RTC_OSC_REG, reg |
+			  OMAP_RTC_OSC_SEL_32KCLK_SRC);
+	}
+
 	rtc->type->lock(rtc);
 
 	device_init_wakeup(&pdev->dev, true);
@@ -672,6 +698,7 @@ err:
 static int __exit omap_rtc_remove(struct platform_device *pdev)
 {
 	struct omap_rtc *rtc = platform_get_drvdata(pdev);
+	u8 reg;
 
 	if (pm_power_off == omap_rtc_power_off &&
 			omap_rtc_power_off_rtc == rtc) {
@@ -681,10 +708,23 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 0);
 
+	if (!IS_ERR(rtc->ext_clk)) {
+		clk_disable_unprepare(rtc->ext_clk);
+	} else {
+		if (!IS_ERR(rtc->int_clk))
+			clk_disable_unprepare(rtc->int_clk);
+	}
+
 	rtc->type->unlock(rtc);
 	/* leave rtc running, but disable irqs */
 	rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
 
+	if (rtc->has_ext_clk) {
+		reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
+		reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC;
+		rtc_write(rtc, OMAP_RTC_OSC_REG, reg);
+	}
+
 	rtc->type->lock(rtc);
 
 	/* Disable the clock/module */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 2/2] rtc: omap: Add external clock enabling support
       [not found]     ` <1439787338-27396-3-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
@ 2015-08-17 11:30       ` Johan Hovold
  2015-08-17 11:38         ` Keerthy
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Hovold @ 2015-08-17 11:30 UTC (permalink / raw)
  To: Keerthy
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	johan-DgEjT+Ai2ygdnm+yROfE0A, grygorii.strashko-l0cyMroinI0,
	bcousson-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA, t-kristo-l0cyMroinI0

On Mon, Aug 17, 2015 at 10:25:38AM +0530, Keerthy wrote:
> Configure the clock source to either internal clock
> or external clock based on the availability of the clocks.
> External clock is preferred as it can be ticking during suspend.
> 
> Signed-off-by: Keerthy <j-keerthy-l0cyMroinI0@public.gmane.org>
> ---
> 
> Changes in V2:
> 
>   * Changed clk_prepare calls to clk_prepare_enable.
>   * Changed clk_unprepare calls to clk_disable_unprepare.
>   * Added clk pointers for external and internal clock to omap_rtc structure.
> 
>  drivers/rtc/rtc-omap.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> index 8b6355f..46b3944 100644
> --- a/drivers/rtc/rtc-omap.c
> +++ b/drivers/rtc/rtc-omap.c
> @@ -25,6 +25,7 @@
>  #include <linux/of_device.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/io.h>
> +#include <linux/clk.h>
>  
>  /*
>   * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock
> @@ -107,6 +108,7 @@
>  
>  /* OMAP_RTC_OSC_REG bit fields: */
>  #define OMAP_RTC_OSC_32KCLK_EN		BIT(6)
> +#define OMAP_RTC_OSC_SEL_32KCLK_SRC	BIT(3)
>  
>  /* OMAP_RTC_IRQWAKEEN bit fields: */
>  #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN	BIT(1)
> @@ -132,10 +134,13 @@ struct omap_rtc_device_type {
>  struct omap_rtc {
>  	struct rtc_device *rtc;
>  	void __iomem *base;
> +	struct clk *ext_clk;
> +	struct clk *int_clk;

As was already suggested, you could just use one clock here for now.

>  	int irq_alarm;
>  	int irq_timer;
>  	u8 interrupts_reg;
>  	bool is_pmic_controller;
> +	bool has_ext_clk;
>  	const struct omap_rtc_device_type *type;
>  };
>  
> @@ -553,6 +558,17 @@ static int omap_rtc_probe(struct platform_device *pdev)
>  	if (rtc->irq_alarm <= 0)
>  		return -ENOENT;
>  
> +	rtc->ext_clk = devm_clk_get(&pdev->dev, "ext-clk");
> +	if (!IS_ERR(rtc->ext_clk)) {
> +		rtc->has_ext_clk = true;
> +		clk_prepare_enable(rtc->ext_clk);
> +	} else {
> +		rtc->int_clk = devm_clk_get(&pdev->dev, "int-clk");
> +
> +		if (!IS_ERR(rtc->int_clk))
> +			clk_prepare_enable(rtc->int_clk);
> +	}
> +

Which would allow some simplification here.

But shouldn't enabling the internal clock go in its own patch before you
add support for the external clock?

>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	rtc->base = devm_ioremap_resource(&pdev->dev, res);
>  	if (IS_ERR(rtc->base))
> @@ -627,6 +643,16 @@ static int omap_rtc_probe(struct platform_device *pdev)
>  	if (reg != new_ctrl)
>  		rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl);
>  
> +	/*
> +	 * If we have the external clock then switch to it so we can keep
> +	 * ticking acorss suspend.

You forgot to fix the "acorss" typo.

> +	 */
> +	if (rtc->has_ext_clk) {
> +		reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
> +		rtc_write(rtc, OMAP_RTC_OSC_REG, reg |
> +			  OMAP_RTC_OSC_SEL_32KCLK_SRC);

Odd line break, break after the final comma instead?

> +	}
> +
>  	rtc->type->lock(rtc);
>  
>  	device_init_wakeup(&pdev->dev, true);
> @@ -672,6 +698,7 @@ err:
>  static int __exit omap_rtc_remove(struct platform_device *pdev)
>  {
>  	struct omap_rtc *rtc = platform_get_drvdata(pdev);
> +	u8 reg;
>  
>  	if (pm_power_off == omap_rtc_power_off &&
>  			omap_rtc_power_off_rtc == rtc) {
> @@ -681,10 +708,23 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
>  
>  	device_init_wakeup(&pdev->dev, 0);
>  
> +	if (!IS_ERR(rtc->ext_clk)) {
> +		clk_disable_unprepare(rtc->ext_clk);
> +	} else {
> +		if (!IS_ERR(rtc->int_clk))
> +			clk_disable_unprepare(rtc->int_clk);
> +	}
> +

This could also be simplified with a single clock entry in rtc.

>  	rtc->type->unlock(rtc);
>  	/* leave rtc running, but disable irqs */
>  	rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
>  
> +	if (rtc->has_ext_clk) {
> +		reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
> +		reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC;
> +		rtc_write(rtc, OMAP_RTC_OSC_REG, reg);
> +	}
> +
>  	rtc->type->lock(rtc);
>  
>  	/* Disable the clock/module */

Johan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 2/2] rtc: omap: Add external clock enabling support
  2015-08-17 11:30       ` Johan Hovold
@ 2015-08-17 11:38         ` Keerthy
       [not found]           ` <55D1C7CF.3070406-l0cyMroinI0@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Keerthy @ 2015-08-17 11:38 UTC (permalink / raw)
  To: Johan Hovold, Keerthy
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	grygorii.strashko-l0cyMroinI0, bcousson-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA, t-kristo-l0cyMroinI0



On Monday 17 August 2015 05:00 PM, Johan Hovold wrote:
> On Mon, Aug 17, 2015 at 10:25:38AM +0530, Keerthy wrote:
>> Configure the clock source to either internal clock
>> or external clock based on the availability of the clocks.
>> External clock is preferred as it can be ticking during suspend.
>>
>> Signed-off-by: Keerthy <j-keerthy-l0cyMroinI0@public.gmane.org>
>> ---
>>
>> Changes in V2:
>>
>>    * Changed clk_prepare calls to clk_prepare_enable.
>>    * Changed clk_unprepare calls to clk_disable_unprepare.
>>    * Added clk pointers for external and internal clock to omap_rtc structure.
>>
>>   drivers/rtc/rtc-omap.c | 40 ++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 40 insertions(+)
>>
>> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
>> index 8b6355f..46b3944 100644
>> --- a/drivers/rtc/rtc-omap.c
>> +++ b/drivers/rtc/rtc-omap.c
>> @@ -25,6 +25,7 @@
>>   #include <linux/of_device.h>
>>   #include <linux/pm_runtime.h>
>>   #include <linux/io.h>
>> +#include <linux/clk.h>
>>
>>   /*
>>    * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock
>> @@ -107,6 +108,7 @@
>>
>>   /* OMAP_RTC_OSC_REG bit fields: */
>>   #define OMAP_RTC_OSC_32KCLK_EN		BIT(6)
>> +#define OMAP_RTC_OSC_SEL_32KCLK_SRC	BIT(3)
>>
>>   /* OMAP_RTC_IRQWAKEEN bit fields: */
>>   #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN	BIT(1)
>> @@ -132,10 +134,13 @@ struct omap_rtc_device_type {
>>   struct omap_rtc {
>>   	struct rtc_device *rtc;
>>   	void __iomem *base;
>> +	struct clk *ext_clk;
>> +	struct clk *int_clk;
>
> As was already suggested, you could just use one clock here for now.

If the intent is to enable dynamic switching in future why not have both 
the clock pointers ready?

>
>>   	int irq_alarm;
>>   	int irq_timer;
>>   	u8 interrupts_reg;
>>   	bool is_pmic_controller;
>> +	bool has_ext_clk;
>>   	const struct omap_rtc_device_type *type;
>>   };
>>
>> @@ -553,6 +558,17 @@ static int omap_rtc_probe(struct platform_device *pdev)
>>   	if (rtc->irq_alarm <= 0)
>>   		return -ENOENT;
>>
>> +	rtc->ext_clk = devm_clk_get(&pdev->dev, "ext-clk");
>> +	if (!IS_ERR(rtc->ext_clk)) {
>> +		rtc->has_ext_clk = true;
>> +		clk_prepare_enable(rtc->ext_clk);
>> +	} else {
>> +		rtc->int_clk = devm_clk_get(&pdev->dev, "int-clk");
>> +
>> +		if (!IS_ERR(rtc->int_clk))
>> +			clk_prepare_enable(rtc->int_clk);
>> +	}
>> +
>
> Which would allow some simplification here.
>
> But shouldn't enabling the internal clock go in its own patch before you
> add support for the external clock?

I am okay with splitting but for now its either or situation so enabling 
in one patch made sense to me.

>
>>   	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>   	rtc->base = devm_ioremap_resource(&pdev->dev, res);
>>   	if (IS_ERR(rtc->base))
>> @@ -627,6 +643,16 @@ static int omap_rtc_probe(struct platform_device *pdev)
>>   	if (reg != new_ctrl)
>>   		rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl);
>>
>> +	/*
>> +	 * If we have the external clock then switch to it so we can keep
>> +	 * ticking acorss suspend.
>
> You forgot to fix the "acorss" typo.

I will fix it.

>
>> +	 */
>> +	if (rtc->has_ext_clk) {
>> +		reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
>> +		rtc_write(rtc, OMAP_RTC_OSC_REG, reg |
>> +			  OMAP_RTC_OSC_SEL_32KCLK_SRC);
>
> Odd line break, break after the final comma instead?

Okay. I will fix it.

>
>> +	}
>> +
>>   	rtc->type->lock(rtc);
>>
>>   	device_init_wakeup(&pdev->dev, true);
>> @@ -672,6 +698,7 @@ err:
>>   static int __exit omap_rtc_remove(struct platform_device *pdev)
>>   {
>>   	struct omap_rtc *rtc = platform_get_drvdata(pdev);
>> +	u8 reg;
>>
>>   	if (pm_power_off == omap_rtc_power_off &&
>>   			omap_rtc_power_off_rtc == rtc) {
>> @@ -681,10 +708,23 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
>>
>>   	device_init_wakeup(&pdev->dev, 0);
>>
>> +	if (!IS_ERR(rtc->ext_clk)) {
>> +		clk_disable_unprepare(rtc->ext_clk);
>> +	} else {
>> +		if (!IS_ERR(rtc->int_clk))
>> +			clk_disable_unprepare(rtc->int_clk);
>> +	}
>> +
>
> This could also be simplified with a single clock entry in rtc.
>
>>   	rtc->type->unlock(rtc);
>>   	/* leave rtc running, but disable irqs */
>>   	rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
>>
>> +	if (rtc->has_ext_clk) {
>> +		reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
>> +		reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC;
>> +		rtc_write(rtc, OMAP_RTC_OSC_REG, reg);
>> +	}
>> +
>>   	rtc->type->lock(rtc);
>>
>>   	/* Disable the clock/module */
>
> Johan
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 2/2] rtc: omap: Add external clock enabling support
       [not found]           ` <55D1C7CF.3070406-l0cyMroinI0@public.gmane.org>
@ 2015-08-17 12:10             ` Johan Hovold
  0 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2015-08-17 12:10 UTC (permalink / raw)
  To: Keerthy
  Cc: Johan Hovold, Keerthy, linux-omap-u79uwXL29TY76Z2rM5mHXA,
	rtc-linux-/JYPxA39Uh5TLH3MbocFFw, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	grygorii.strashko-l0cyMroinI0, bcousson-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA, t-kristo-l0cyMroinI0

On Mon, Aug 17, 2015 at 05:08:55PM +0530, Keerthy wrote:
> 
> 
> On Monday 17 August 2015 05:00 PM, Johan Hovold wrote:
> > On Mon, Aug 17, 2015 at 10:25:38AM +0530, Keerthy wrote:
> >> Configure the clock source to either internal clock
> >> or external clock based on the availability of the clocks.
> >> External clock is preferred as it can be ticking during suspend.
> >>
> >> Signed-off-by: Keerthy <j-keerthy-l0cyMroinI0@public.gmane.org>
> >> ---
> >>
> >> Changes in V2:
> >>
> >>    * Changed clk_prepare calls to clk_prepare_enable.
> >>    * Changed clk_unprepare calls to clk_disable_unprepare.
> >>    * Added clk pointers for external and internal clock to omap_rtc structure.
> >>
> >>   drivers/rtc/rtc-omap.c | 40 ++++++++++++++++++++++++++++++++++++++++
> >>   1 file changed, 40 insertions(+)
> >>
> >> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> >> index 8b6355f..46b3944 100644
> >> --- a/drivers/rtc/rtc-omap.c
> >> +++ b/drivers/rtc/rtc-omap.c
> >> @@ -25,6 +25,7 @@
> >>   #include <linux/of_device.h>
> >>   #include <linux/pm_runtime.h>
> >>   #include <linux/io.h>
> >> +#include <linux/clk.h>
> >>
> >>   /*
> >>    * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock
> >> @@ -107,6 +108,7 @@
> >>
> >>   /* OMAP_RTC_OSC_REG bit fields: */
> >>   #define OMAP_RTC_OSC_32KCLK_EN		BIT(6)
> >> +#define OMAP_RTC_OSC_SEL_32KCLK_SRC	BIT(3)
> >>
> >>   /* OMAP_RTC_IRQWAKEEN bit fields: */
> >>   #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN	BIT(1)
> >> @@ -132,10 +134,13 @@ struct omap_rtc_device_type {
> >>   struct omap_rtc {
> >>   	struct rtc_device *rtc;
> >>   	void __iomem *base;
> >> +	struct clk *ext_clk;
> >> +	struct clk *int_clk;
> >
> > As was already suggested, you could just use one clock here for now.
> 
> If the intent is to enable dynamic switching in future why not have both 
> the clock pointers ready?

Because it needlessly complicates the clock handling below, and those
bits would need to be rewritten anyway when/if dynamic switching is
implemented.

> >
> >>   	int irq_alarm;
> >>   	int irq_timer;
> >>   	u8 interrupts_reg;
> >>   	bool is_pmic_controller;
> >> +	bool has_ext_clk;
> >>   	const struct omap_rtc_device_type *type;
> >>   };
> >>
> >> @@ -553,6 +558,17 @@ static int omap_rtc_probe(struct platform_device *pdev)
> >>   	if (rtc->irq_alarm <= 0)
> >>   		return -ENOENT;
> >>
> >> +	rtc->ext_clk = devm_clk_get(&pdev->dev, "ext-clk");
> >> +	if (!IS_ERR(rtc->ext_clk)) {
> >> +		rtc->has_ext_clk = true;
> >> +		clk_prepare_enable(rtc->ext_clk);
> >> +	} else {
> >> +		rtc->int_clk = devm_clk_get(&pdev->dev, "int-clk");
> >> +
> >> +		if (!IS_ERR(rtc->int_clk))
> >> +			clk_prepare_enable(rtc->int_clk);
> >> +	}
> >> +
> >
> > Which would allow some simplification here.
> >
> > But shouldn't enabling the internal clock go in its own patch before you
> > add support for the external clock?
> 
> I am okay with splitting but for now its either or situation so enabling 
> in one patch made sense to me.

Since you're doing two different things here (fixing the missing clock
enable and adding support for the external clock), I'd suggest doing it
in two patches.

Johan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-08-17 12:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-17  4:55 [PATCH v2 0/2] ARM: AM437X: Add rtc clock handling Keerthy
     [not found] ` <1439787338-27396-1-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
2015-08-17  4:55   ` [PATCH v2 1/2] ARM: dts: AM437x: Add the internal and external clock nodes for rtc Keerthy
2015-08-17  4:55   ` [PATCH v2 2/2] rtc: omap: Add external clock enabling support Keerthy
     [not found]     ` <1439787338-27396-3-git-send-email-j-keerthy-l0cyMroinI0@public.gmane.org>
2015-08-17 11:30       ` Johan Hovold
2015-08-17 11:38         ` Keerthy
     [not found]           ` <55D1C7CF.3070406-l0cyMroinI0@public.gmane.org>
2015-08-17 12:10             ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).