mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com
Cc: Russell King <linux@arm.linux.org.uk>,
	Will Deacon <will.deacon@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Alessandro Zummo <a.zummo@towertech.it>
Subject: [PATCH 3/7] rtc-cmos: allow MMIO to be used when initialized from FDT
Date: Fri, 25 Apr 2014 10:31:11 +0100	[thread overview]
Message-ID: <1398418275-9671-4-git-send-email-marc.zyngier@arm.com> (raw)
In-Reply-To: <1398418275-9671-1-git-send-email-marc.zyngier@arm.com>

Currently, rtc-cmos mandates the use of an I/O port. If the
resource obtained from the device tree is instead a memory mapped
range, the probing will fail.

Let the cmos_of_init function try to ioremap the range obtained
from FDT. Should this fail, fallback to the normal I/O port.

Tested on KVM/ARM with kvmtools as the backend for RTC emulation.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 drivers/rtc/Kconfig       |  3 +++
 drivers/rtc/rtc-cmos.c    | 67 ++++++++++++++++++++++++++++++++++++++++++-----
 include/asm-generic/rtc.h |  5 ++++
 3 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 2e565f8..7e88866 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -677,6 +677,9 @@ config RTC_DRV_CMOS
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-cmos.
 
+config RTC_DRV_CMOS_MMIO
+	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 be2dd17..d535e72 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -37,6 +37,7 @@
 #include <linux/log2.h>
 #include <linux/pm.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/dmi.h>
 
@@ -66,6 +67,41 @@ struct cmos_rtc {
 
 static const char driver_name[] = "rtc_cmos";
 
+#ifdef CONFIG_RTC_DRV_CMOS_MMIO
+static void __iomem *rtc_cmos_base;
+
+static u8 do_cmos_read(u8 reg)
+{
+	u8 val;
+
+	if (rtc_cmos_base) {
+		writeb(reg, rtc_cmos_base);
+		val = readb(rtc_cmos_base + 1);
+	} else {
+		val = CMOS_READ(reg);
+	}
+
+	return val;
+}
+
+static void do_cmos_write(u8 val, u8 reg)
+{
+	if (rtc_cmos_base) {
+		writeb(reg, rtc_cmos_base);
+		writeb(val, rtc_cmos_base + 1);
+	} else {
+		CMOS_WRITE(val, reg);
+	}
+}
+
+static inline void rtc_cmos_set_base(void __iomem *base)
+{
+	rtc_cmos_base = base;
+}
+#else
+static void rtc_cmos_set_base(void __iomem *base) {}
+#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.
@@ -663,13 +699,23 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 		return -ENODEV;
 
 	/* Claim I/O ports ASAP, minimizing conflict with legacy driver.
-	 *
-	 * REVISIT non-x86 systems may instead use memory space resources
-	 * (needing ioremap etc), not i/o space resources like this ...
+	 * MMIO gets requested the same way, not that it matters much.
 	 */
-	ports = request_region(ports->start,
-			resource_size(ports),
-			driver_name);
+	switch(resource_type(ports)) {
+	case IORESOURCE_IO:
+		ports = request_region(ports->start,
+				       resource_size(ports),
+				       driver_name);
+		break;
+	case IORESOURCE_MEM:
+		ports = request_mem_region(ports->start,
+					   resource_size(ports),
+					   driver_name);
+		break;
+	default:		/* Martian I/O??? */
+		ports = NULL;
+	}
+
 	if (!ports) {
 		dev_dbg(dev, "i/o registers already in use\n");
 		return -EBUSY;
@@ -1160,10 +1206,17 @@ static inline void cmos_of_init(struct platform_device *pdev) {}
 
 static int __init cmos_platform_probe(struct platform_device *pdev)
 {
+	struct resource *ports;
+
 	cmos_of_init(pdev);
+
+	ports = platform_get_resource(pdev, IORESOURCE_IO, 0);
+	if (!ports)
+		ports = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
 	cmos_wake_setup(&pdev->dev);
 	return cmos_do_probe(&pdev->dev,
-			platform_get_resource(pdev, IORESOURCE_IO, 0),
+			ports,
 			platform_get_irq(pdev, 0));
 }
 
diff --git a/include/asm-generic/rtc.h b/include/asm-generic/rtc.h
index 1ad3e78..236693b 100644
--- a/include/asm-generic/rtc.h
+++ b/include/asm-generic/rtc.h
@@ -28,6 +28,10 @@
 #define RTC_24H 0x02		/* 24 hour mode - else hours bit 7 means pm */
 #define RTC_DST_EN 0x01	        /* auto switch DST - works f. USA only */
 
+#ifdef CONFIG_RTC_DRV_CMOS_MMIO
+static u8 do_cmos_read(u8 reg);
+static void do_cmos_write(u8 val, u8 reg);
+#else
 static inline u8 do_cmos_read(u8 reg)
 {
 	return CMOS_READ(reg);
@@ -37,6 +41,7 @@ static inline void do_cmos_write(u8 val, u8 reg)
 {
 	CMOS_WRITE(val, reg);
 }
+#endif
 
 static inline unsigned long rtc_cmos_lock(void)
 {
-- 
1.8.3.4


  parent reply	other threads:[~2014-04-25  9:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-25  9:31 [PATCH 0/7] rtc-cmos: private locking and MMIO support Marc Zyngier
2014-04-25  9:31 ` [PATCH 1/7] rtc-cmos: abstract IO accessors Marc Zyngier
2014-04-25  9:31 ` [PATCH 2/7] rtc-cmos: abstract locking primitives Marc Zyngier
2014-04-25  9:31 ` Marc Zyngier [this message]
2014-04-25  9:31 ` [PATCH 4/7] rtc-cmos: allow strictly MMIO based configurations Marc Zyngier
2014-04-25  9:31 ` [PATCH 5/7] rtc-cmos: implement driver private locking Marc Zyngier
2014-04-25  9:31 ` [PATCH 6/7] ARM: rtc: update CMOS RTC to support MMIO and private lock Marc Zyngier
2014-04-25 10:27   ` Russell King - ARM Linux
2014-04-25 12:32     ` Marc Zyngier
2014-04-25  9:31 ` [PATCH 7/7] arm64: rtc: plug the PC CMOS RTC using MMIO accessors Marc Zyngier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398418275-9671-4-git-send-email-marc.zyngier@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=a.zummo@towertech.it \
    --cc=catalin.marinas@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=rtc-linux@googlegroups.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®