[PATCH 5/7] rtc-cmos: implement driver private locking

From: Marc Zyngier
Date: Fri Apr 25 2014 - 05:31:37 EST


A number of architecture happen to share a lock between the rtc-cmos
driver and the core architectural code for good reasons (or at least,
reasons that matter to the architecture).

Other architectures don't do that, but still have to define a lock
that is only used by the RTC driver. How annoying!

Implement a set of driver private locking primitives, and expose
a config option allowing the architecture to select it if it doesn't
require to share the lock with the RTC driver.

Signed-off-by: Marc Zyngier <marc.zyngier@xxxxxxx>
---
drivers/rtc/Kconfig | 3 +++
drivers/rtc/rtc-cmos.c | 16 ++++++++++++++++
include/asm-generic/rtc.h | 5 +++++
3 files changed, 24 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 10974f7..12bc27d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -684,6 +684,9 @@ config RTC_DRV_CMOS_MMIO_STRICT
select RTC_DRV_CMOS_MMIO
bool

+config RTC_DRV_CMOS_PRIV_LOCK
+ bool
+
config RTC_DRV_ALPHA
bool "Alpha PC-style CMOS"
depends on ALPHA
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index e2d1338..eb5d05c 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -107,6 +107,22 @@ static inline void rtc_cmos_set_base(void __iomem *base)
static void rtc_cmos_set_base(void __iomem *base) {}
#endif

+#ifdef CONFIG_RTC_DRV_CMOS_PRIV_LOCK
+static DEFINE_SPINLOCK(rtc_private_lock);
+
+static unsigned long rtc_cmos_lock(void)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&rtc_private_lock, flags);
+ return flags;
+}
+
+static void rtc_cmos_unlock(unsigned long flags)
+{
+ spin_unlock_irqrestore(&rtc_private_lock, flags);
+}
+#endif
+
/* The RTC_INTR register may have e.g. RTC_PF set even if RTC_PIE is clear;
* always mask it against the irq enable bits in RTC_CONTROL. Bit values
* are the same: PF==PIE, AF=AIE, UF=UIE; so RTC_IRQMASK works with both.
diff --git a/include/asm-generic/rtc.h b/include/asm-generic/rtc.h
index 236693b..1d21408 100644
--- a/include/asm-generic/rtc.h
+++ b/include/asm-generic/rtc.h
@@ -43,6 +43,10 @@ static inline void do_cmos_write(u8 val, u8 reg)
}
#endif

+#ifdef CONFIG_RTC_DRV_CMOS_PRIV_LOCK
+static unsigned long rtc_cmos_lock(void);
+static void rtc_cmos_unlock(unsigned long flags);
+#else
static inline unsigned long rtc_cmos_lock(void)
{
unsigned long flags;
@@ -54,6 +58,7 @@ static inline void rtc_cmos_unlock(unsigned long flags)
{
spin_unlock_irqrestore(&rtc_lock, flags);
}
+#endif

/*
* Returns true if a clock update is in progress
--
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/