linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rtc: omap: Fix selecting external osc
@ 2016-10-27  5:57 Keerthy
  2016-10-27  5:57 ` [PATCH 2/2] rtc: omap: prevent disabling of clock/module during suspend Keerthy
  2016-11-05  2:35 ` [PATCH 1/2] rtc: omap: Fix selecting external osc Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Keerthy @ 2016-10-27  5:57 UTC (permalink / raw)
  To: alexandre.belloni
  Cc: a.zummo, rtc-linux, linux-omap, linux-kernel, lokeshvutla,
	j-keerthy, t-kristo

From: Lokesh Vutla <lokeshvutla@ti.com>

RTC can be clocked from an external 32KHz oscillator, or from the
Peripheral PLL. The RTC has an internal oscillator buffer to support
direct operation with a crystal.

            ----------------------------------------
            |       Device          ---------       |
            |                       |       |       |
            |                       | RTCSS |       |
            |       ---------       |       |       |
    OSC     |<------| RTC   |       |       |       |
            |------>| OSC   |---    |       |       |
            |       --------   |    |       |       |
            |                   ----|clk    |       |
            |       --------   |    |       |       |
            |       | PRCM  |---    |       |       |
            |       --------        --------        |
            ----------------------------------------

The RTC functional clock is sourced by default from the clock derived
from the Peripheral PLL. In order to select source as external osc clk
the following changes needs to be done:
- Enable the RTC OSC (RTC_OSC_REG[4]OSC32K_GZ = 0)
- Enable the clock mux(RTC_OSC_REG[6]K32CLK_EN = 1)
- Select the external clock source (RTC_OSC_REG[3]32KCLK_SEL = 1)

Fixes: 399cf0f63f6f2 ("rtc: omap: Add external clock enabling support")
Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
---

Boot tested and checked for rtc ticking on am335x-boneblack, am335x-bone
am437x-gp-evm, dra7-evm, dra72-evm.

 drivers/rtc/rtc-omap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index b04ea9b..dddaa60 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -113,6 +113,7 @@
 /* OMAP_RTC_OSC_REG bit fields: */
 #define OMAP_RTC_OSC_32KCLK_EN		BIT(6)
 #define OMAP_RTC_OSC_SEL_32KCLK_SRC	BIT(3)
+#define OMAP_RTC_OSC_OSC32K_GZ_DISABLE	BIT(4)
 
 /* OMAP_RTC_IRQWAKEEN bit fields: */
 #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN	BIT(1)
@@ -786,8 +787,9 @@ static int omap_rtc_probe(struct platform_device *pdev)
 	 */
 	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);
+		reg &= ~OMAP_RTC_OSC_OSC32K_GZ_DISABLE;
+		reg |= OMAP_RTC_OSC_32KCLK_EN | OMAP_RTC_OSC_SEL_32KCLK_SRC;
+		rtc_writel(rtc, OMAP_RTC_OSC_REG, reg);
 	}
 
 	rtc->type->lock(rtc);
-- 
1.9.1

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

* [PATCH 2/2] rtc: omap: prevent disabling of clock/module during suspend
  2016-10-27  5:57 [PATCH 1/2] rtc: omap: Fix selecting external osc Keerthy
@ 2016-10-27  5:57 ` Keerthy
  2016-11-05  2:35 ` [PATCH 1/2] rtc: omap: Fix selecting external osc Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Keerthy @ 2016-10-27  5:57 UTC (permalink / raw)
  To: alexandre.belloni
  Cc: a.zummo, rtc-linux, linux-omap, linux-kernel, lokeshvutla,
	j-keerthy, t-kristo

From: Tero Kristo <t-kristo@ti.com>

If RTC is running from an internal clock source, the RTC module can't
be disabled; otherwise it stops ticking completely. Current suspend
handler implementation disables the clock/module unconditionally,
instead fix this by disabling the clock only if we are running on
external clock source, which is not affected by suspend.

The prevention of disabling the clock must be done via implementing
the runtime_pm handlers for the device, and returning an error code
from the runtime suspend handler; otherwise OMAP core PM will disable
the clocks for the driver.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
Signed-off-by: Keerthy <j-keerthy@ti.com>
---

Boot tested and checked for rtc ticking on am335x-boneblack, am335x-bone
am437x-gp-evm, dra7-evm, dra72-evm.

 drivers/rtc/rtc-omap.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index dddaa60..51e5244 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -147,6 +147,7 @@ struct omap_rtc {
 	u8 interrupts_reg;
 	bool is_pmic_controller;
 	bool has_ext_clk;
+	bool is_suspending;
 	const struct omap_rtc_device_type *type;
 	struct pinctrl_dev *pctldev;
 };
@@ -900,8 +901,7 @@ static int omap_rtc_suspend(struct device *dev)
 		rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
 	rtc->type->lock(rtc);
 
-	/* Disable the clock/module */
-	pm_runtime_put_sync(dev);
+	rtc->is_suspending = true;
 
 	return 0;
 }
@@ -910,9 +910,6 @@ static int omap_rtc_resume(struct device *dev)
 {
 	struct omap_rtc *rtc = dev_get_drvdata(dev);
 
-	/* Enable the clock/module so that we can access the registers */
-	pm_runtime_get_sync(dev);
-
 	rtc->type->unlock(rtc);
 	if (device_may_wakeup(dev))
 		disable_irq_wake(rtc->irq_alarm);
@@ -920,11 +917,34 @@ static int omap_rtc_resume(struct device *dev)
 		rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg);
 	rtc->type->lock(rtc);
 
+	rtc->is_suspending = false;
+
 	return 0;
 }
 #endif
 
-static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume);
+#ifdef CONFIG_PM
+static int omap_rtc_runtime_suspend(struct device *dev)
+{
+	struct omap_rtc *rtc = dev_get_drvdata(dev);
+
+	if (rtc->is_suspending && !rtc->has_ext_clk)
+		return -EBUSY;
+
+	return 0;
+}
+
+static int omap_rtc_runtime_resume(struct device *dev)
+{
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops omap_rtc_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(omap_rtc_suspend, omap_rtc_resume)
+	SET_RUNTIME_PM_OPS(omap_rtc_runtime_suspend,
+			   omap_rtc_runtime_resume, NULL)
+};
 
 static void omap_rtc_shutdown(struct platform_device *pdev)
 {
-- 
1.9.1

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

* Re: [PATCH 1/2] rtc: omap: Fix selecting external osc
  2016-10-27  5:57 [PATCH 1/2] rtc: omap: Fix selecting external osc Keerthy
  2016-10-27  5:57 ` [PATCH 2/2] rtc: omap: prevent disabling of clock/module during suspend Keerthy
@ 2016-11-05  2:35 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2016-11-05  2:35 UTC (permalink / raw)
  To: Keerthy
  Cc: a.zummo, rtc-linux, linux-omap, linux-kernel, lokeshvutla, t-kristo

On 27/10/2016 at 11:27:25 +0530, Keerthy wrote :
> From: Lokesh Vutla <lokeshvutla@ti.com>
> 
> RTC can be clocked from an external 32KHz oscillator, or from the
> Peripheral PLL. The RTC has an internal oscillator buffer to support
> direct operation with a crystal.
> 
>             ----------------------------------------
>             |       Device          ---------       |
>             |                       |       |       |
>             |                       | RTCSS |       |
>             |       ---------       |       |       |
>     OSC     |<------| RTC   |       |       |       |
>             |------>| OSC   |---    |       |       |
>             |       --------   |    |       |       |
>             |                   ----|clk    |       |
>             |       --------   |    |       |       |
>             |       | PRCM  |---    |       |       |
>             |       --------        --------        |
>             ----------------------------------------
> 
> The RTC functional clock is sourced by default from the clock derived
> from the Peripheral PLL. In order to select source as external osc clk
> the following changes needs to be done:
> - Enable the RTC OSC (RTC_OSC_REG[4]OSC32K_GZ = 0)
> - Enable the clock mux(RTC_OSC_REG[6]K32CLK_EN = 1)
> - Select the external clock source (RTC_OSC_REG[3]32KCLK_SEL = 1)
> 
> Fixes: 399cf0f63f6f2 ("rtc: omap: Add external clock enabling support")
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
> Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
> ---
> 
> Boot tested and checked for rtc ticking on am335x-boneblack, am335x-bone
> am437x-gp-evm, dra7-evm, dra72-evm.
> 
>  drivers/rtc/rtc-omap.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
Both applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

end of thread, other threads:[~2016-11-05  2:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-27  5:57 [PATCH 1/2] rtc: omap: Fix selecting external osc Keerthy
2016-10-27  5:57 ` [PATCH 2/2] rtc: omap: prevent disabling of clock/module during suspend Keerthy
2016-11-05  2:35 ` [PATCH 1/2] rtc: omap: Fix selecting external osc Alexandre Belloni

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