public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH resend v2] TWL4030-RTC: Fix the broken functionality
@ 2008-08-25  9:51 Pakaravoor, Jagadeesh
  2008-08-25 12:30 ` Dmitry Krivoschekov
  0 siblings, 1 reply; 5+ messages in thread
From: Pakaravoor, Jagadeesh @ 2008-08-25  9:51 UTC (permalink / raw)
  To: linux-omap@vger.kernel.org

From: Jagadeesh Bhaskar Pakaravoor <j-pakaravoor@ti.com>

rtc_irq_set_freq() function takes only powers of 2 as a valid
argument. This stipulates that an ioctl call on /dev/rtc0
can accept values of 1,2,4 and 8 only. But the function 
twl4030_rtc_irq_set_freq() takes only values 0-3. RTC_INTERRUPTS_REG
of TWL4030 also requires value in the range 0-3 for the interrupt
period. Hence it is required to map the argument from the powers of 2,
to the corresponding numbers 0-3, via a call to ilog2.

Signed-off-by: Jagadeesh Bhaskar Pakaravoor <j-pakaravoor@ti.com>
---
Fixing a bug in the last patch: argument to set_rtc_irq_bit()
function should have been "value" instead of "freq".
Index: my-local-git-dir/drivers/rtc/rtc-twl4030.c
===================================================================
--- my-local-git-dir.orig/drivers/rtc/rtc-twl4030.c	2008-08-22 17:37:33.000000000 +0530
+++ my-local-git-dir/drivers/rtc/rtc-twl4030.c	2008-08-22 19:25:41.616786397 +0530
@@ -38,6 +38,7 @@
 #include <linux/i2c/twl4030-rtc.h>
 #include <linux/io.h>
 #include <linux/irq.h>
+#include <linux/log2.h>
 
 #include <asm/mach/time.h>
 #include <asm/system.h>
@@ -363,14 +364,26 @@ out:
 static int twl4030_rtc_irq_set_freq(struct device *dev, int freq)
 {
 	struct rtc_device *rtc = dev_get_drvdata(dev);
+	u8 value;
 
-	if (freq < 0 || freq > 3)
+	/* RTC_INTERRUPTS_REG takes the value of 0 for interrupts every
+	 * second, 1 for every minute, 2 every hour and 3 every day.
+	 * But freq is in 2^N format, which needs to be converted back.
+	 */
+	value = ilog2(freq);
+	if (value < 0 || value > 3)
 		return -EINVAL;
 
-	rtc->irq_freq = freq;
+	rtc->irq_freq = value;
+
+	/* Clear the current periodicity of irq*/
+	mask_rtc_irq_bit(0x3);
 
-	/* set rtc irq freq to user defined value */
-	set_rtc_irq_bit(freq);
+	/* If the new value is non-zero, set the new periodicity */
+	if (value) {
+		/* set rtc irq freq to user defined value */
+		set_rtc_irq_bit(value);
+	}
 
 	return 0;
 }

--
With Regards,
Jagadeesh Bhaskar P
 
----------------------------
Some men see things as they are and say why - I dream things that never were and say why not.
- George Bernard Shaw
-------------------

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

end of thread, other threads:[~2008-09-09 19:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-25  9:51 [PATCH resend v2] TWL4030-RTC: Fix the broken functionality Pakaravoor, Jagadeesh
2008-08-25 12:30 ` Dmitry Krivoschekov
2008-09-09 17:44   ` Tony Lindgren
2008-09-09 18:35     ` David Brownell
2008-09-09 19:16       ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox