Patchwork rtc: rtc-s3c: fix no occurrence of alarm interrupt

login
register
mail settings
Submitter Donggeun Kim
Date Aug. 31, 2011, 10:21 a.m.
Message ID <1314786110-1297-1-git-send-email-dg77.kim@samsung.com>
Download mbox | patch
Permalink /patch/112499/
State New
Headers show

Comments

Donggeun Kim - Aug. 31, 2011, 10:21 a.m.
The driver does not generate alarm interrupt
even though time for alarm is set.
This results from disabling rtc_clk after setting time for alarm.
To generate alarm interrupt,
the driver should maintain enabled state for rtc_clk
until alarm interrupt occurs.
This patch allows to generate alarm interrupt.

Signed-off-by: Donggeun Kim <dg77.kim@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/rtc/rtc-s3c.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

Patch

diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 4e7c04e..b68697e 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -50,6 +50,27 @@  static bool wake_en;
 static enum s3c_cpu_type s3c_rtc_cpu_type;
 
 static DEFINE_SPINLOCK(s3c_rtc_pie_lock);
+static DEFINE_SPINLOCK(s3c_rtc_alarm_clk_lock);
+
+static void s3c_rtc_alarm_clk_enable(bool enable)
+{
+	static bool alarm_clk_enabled;
+	unsigned long irq_flags;
+
+	spin_lock_irqsave(&s3c_rtc_alarm_clk_lock, irq_flags);
+	if (enable) {
+		if (!alarm_clk_enabled) {
+			clk_enable(rtc_clk);
+			alarm_clk_enabled = true;
+		}
+	} else {
+		if (alarm_clk_enabled) {
+			clk_disable(rtc_clk);
+			alarm_clk_enabled = false;
+		}
+	}
+	spin_unlock_irqrestore(&s3c_rtc_alarm_clk_lock, irq_flags);
+}
 
 /* IRQ Handlers */
 
@@ -64,6 +85,9 @@  static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
 		writeb(S3C2410_INTP_ALM, s3c_rtc_base + S3C2410_INTP);
 
 	clk_disable(rtc_clk);
+
+	s3c_rtc_alarm_clk_enable(false);
+
 	return IRQ_HANDLED;
 }
 
@@ -97,6 +121,8 @@  static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
 	writeb(tmp, s3c_rtc_base + S3C2410_RTCALM);
 	clk_disable(rtc_clk);
 
+	s3c_rtc_alarm_clk_enable(enabled);
+
 	return 0;
 }