From patchwork Tue Mar 22 08:08:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2] RTC: Selectively enable PIE-Hrtimer emulation. Date: Mon, 21 Mar 2011 22:08:54 -0000 From: MyungJoo Ham X-Patchwork-Id: 87879 Message-Id: <1300781334-30308-1-git-send-email-myungjoo.ham@samsung.com> To: rtc-linux@googlegroups.com Cc: linux-kernel@vger.kernel.org, Alessandro Zummo , John Stultz , kyungmin.park@samsung.com, myungjoo.ham@gmail.com The patch of John Stultz, "RTC: Rework RTC code to use timerqueue for events", has enabled PIE interrupt emulation with hrtimer unconditionally. However, we do have RTC devices that support PIE and such devices are not meant to be emulated by hrtimer. Besides, we sometimes need RTC-PIE to function while hrtimer does not; e.g., CPU's RTC PIE as a suspend-to-RAM wakeup source. This patch allows to selectively use the PIE emulation. If the rtc driver has implemented PIE related ops (irq_set_state and irq_set_freq), PIE emulation is not used. Currently, rtc-s3c, rtc-cmos, rtc-davinci, rtc-pl031, rtc-pxa, rtc-sa1100, rtc-sh, and rtc-vt41xx have them. Besides, rtc->pie_enabled is renamed as rtc->pie_emul_enabled. It is because that variable denotes whether HRTimer-PIE is set or not. Signed-off-by: MyungJoo Ham Signed-off-by: Kyungmin Park --- drivers/rtc/class.c | 2 +- drivers/rtc/interface.c | 33 +++++++++++++++++++++++++-------- include/linux/rtc.h | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index c404b61..102d706 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -164,7 +164,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, /* Init pie timer */ hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); rtc->pie_timer.function = rtc_pie_update_irq; - rtc->pie_enabled = 0; + rtc->pie_emul_enabled = 0; strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); dev_set_name(&rtc->dev, "rtc%d", id); diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index cb2f072..6d5aa3b 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -450,16 +450,25 @@ int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled err = -EBUSY; if (rtc->irq_task != task) err = -EACCES; + if (err) + goto out; - if (enabled) { - ktime_t period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq); - hrtimer_start(&rtc->pie_timer, period, HRTIMER_MODE_REL); + if (rtc->ops->irq_set_state) { + err = rtc->ops->irq_set_state(rtc->dev.parent, enabled); + rtc->pie_emul_enabled = 0; } else { - hrtimer_cancel(&rtc->pie_timer); + if (enabled) { + ktime_t period = ktime_set(0, NSEC_PER_SEC / + rtc->irq_freq); + hrtimer_start(&rtc->pie_timer, period, + HRTIMER_MODE_REL); + } else { + hrtimer_cancel(&rtc->pie_timer); + } + rtc->pie_emul_enabled = enabled; } - rtc->pie_enabled = enabled; +out: spin_unlock_irqrestore(&rtc->irq_task_lock, flags); - return err; } EXPORT_SYMBOL_GPL(rtc_irq_set_state); @@ -487,9 +496,16 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq) err = -EBUSY; if (rtc->irq_task != task) err = -EACCES; - if (err == 0) { + if (err) + goto out; + + if (rtc->ops->irq_set_freq) { + err = rtc->ops->irq_set_freq(rtc->dev.parent, freq); + if (err == 0) + rtc->irq_freq = freq; + } else { rtc->irq_freq = freq; - if (rtc->pie_enabled) { + if (rtc->pie_emul_enabled) { ktime_t period; hrtimer_cancel(&rtc->pie_timer); period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq); @@ -497,6 +513,7 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq) HRTIMER_MODE_REL); } } +out: spin_unlock_irqrestore(&rtc->irq_task_lock, flags); return err; } diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 89c3e51..b2c0a62 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -201,7 +201,7 @@ struct rtc_device struct rtc_timer aie_timer; struct rtc_timer uie_rtctimer; struct hrtimer pie_timer; /* sub second exp, so needs hrtimer */ - int pie_enabled; + int pie_emul_enabled; struct work_struct irqwork;