void __iomem *base;
struct clk *rtc_clk;
struct clk *rtc_src_clk;
- bool clk_disabled;
+ bool alarm_enabled;
const struct s3c_rtc_data *data;
int irq_tick;
spinlock_t pie_lock;
- spinlock_t alarm_clk_lock;
+ spinlock_t alarm_lock;
int ticnt_save;
int ticnt_en_save;
static int s3c_rtc_enable_clk(struct s3c_rtc *info)
{
- unsigned long irq_flags;
- int ret = 0;
+ int ret;
- spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
+ ret = clk_enable(info->rtc_clk);
+ if (ret)
+ return ret;
- if (info->clk_disabled) {
- ret = clk_enable(info->rtc_clk);
- if (ret)
- goto out;
-
- if (info->data->needs_src_clk) {
- ret = clk_enable(info->rtc_src_clk);
- if (ret) {
- clk_disable(info->rtc_clk);
- goto out;
- }
+ if (info->data->needs_src_clk) {
+ ret = clk_enable(info->rtc_src_clk);
+ if (ret) {
+ clk_disable(info->rtc_clk);
+ return ret;
}
- info->clk_disabled = false;
}
-
-out:
- spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
-
- return ret;
+ return 0;
}
static void s3c_rtc_disable_clk(struct s3c_rtc *info)
{
- unsigned long irq_flags;
-
- spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
- if (!info->clk_disabled) {
- if (info->data->needs_src_clk)
- clk_disable(info->rtc_src_clk);
- clk_disable(info->rtc_clk);
- info->clk_disabled = true;
- }
- spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
+ if (info->data->needs_src_clk)
+ clk_disable(info->rtc_src_clk);
+ clk_disable(info->rtc_clk);
}
/* IRQ Handlers */
static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
{
struct s3c_rtc *info = dev_get_drvdata(dev);
+ unsigned long flags;
unsigned int tmp;
int ret;
writeb(tmp, info->base + S3C2410_RTCALM);
- s3c_rtc_disable_clk(info);
+ spin_lock_irqsave(&info->alarm_lock, flags);
- if (enabled) {
- ret = s3c_rtc_enable_clk(info);
- if (ret)
- return ret;
- } else {
+ if (info->alarm_enabled && !enabled)
s3c_rtc_disable_clk(info);
- }
+ else if (!info->alarm_enabled && enabled)
+ ret = s3c_rtc_enable_clk(info);
- return 0;
+ info->alarm_enabled = enabled;
+ spin_unlock_irqrestore(&info->alarm_lock, flags);
+
+ s3c_rtc_disable_clk(info);
+
+ return ret;
}
/* Set RTC frequency */
writeb(alrm_en, info->base + S3C2410_RTCALM);
- s3c_rtc_disable_clk(info);
-
s3c_rtc_setaie(dev, alrm->enabled);
+ s3c_rtc_disable_clk(info);
+
return 0;
}
return -EINVAL;
}
spin_lock_init(&info->pie_lock);
- spin_lock_init(&info->alarm_clk_lock);
+ spin_lock_init(&info->alarm_lock);
platform_set_drvdata(pdev, info);
s3c_rtc_setfreq(info, 1);
+ s3c_rtc_disable_clk(info);
+
return 0;
err_nortc: