devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Haojian Zhuang <haojian.zhuang@marvell.com>
To: arnd@arndb.de, linux-arm-kernel@lists.infradead.org,
	devicetree-discuss@lists.ozlabs.org, grant.likely@secretlab.ca,
	linux@arm.linux.org.uk, eric.y.miao@gmail.com
Cc: Haojian Zhuang <haojian.zhuang@marvell.com>
Subject: [PATCH 3/8] rtc: sa1100: add OF support
Date: Thu,  1 Mar 2012 14:10:23 +0800	[thread overview]
Message-ID: <1330582228-12424-4-git-send-email-haojian.zhuang@marvell.com> (raw)
In-Reply-To: <1330582228-12424-1-git-send-email-haojian.zhuang@marvell.com>

There're two interrupts are used in rtc-sa1100 devices. The RTC-alarm
interrupt is specified as default interrupt. The RTC-1Hz interrupt is
specified as "mrvl,rtc-irqhz" property in DTS file.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 drivers/rtc/rtc-sa1100.c |   54 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 962510c..09f05d5 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -30,6 +30,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/of.h>
 #include <linux/pm.h>
 #include <linux/bitops.h>
 
@@ -228,28 +229,64 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
 	.alarm_irq_enable = sa1100_rtc_alarm_irq_enable,
 };
 
+static struct of_device_id sa1100_rtc_dt_ids[] = {
+	{ .compatible = "mrvl,sa1100-rtc", },
+	{ .compatible = "mrvl,mmp-rtc", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, sa1100_rtc_dt_ids);
+
+#ifdef CONFIG_OF
+static int sa1100_rtc_probe_dt(struct platform_device *pdev,
+			       struct sa1100_rtc *info)
+{
+	info->irq_alarm = platform_get_irq(pdev, 0);
+	info->irq_1hz = platform_get_irq(pdev, 1);
+	if (info->irq_1hz < 0 || info->irq_alarm < 0)
+		return -ENODEV;
+	return 0;
+}
+#else
+static int sa1100_rtc_probe_dt(struct platform_device *pdev,
+			       struct sa1100_rtc *info)
+{
+	return 1;
+}
+#endif
+
+static int sa1100_rtc_probe_irq(struct platform_device *pdev,
+				struct sa1100_rtc *info)
+{
+	info->irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
+	info->irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
+	if (info->irq_1hz < 0 || info->irq_alarm < 0)
+		return -ENODEV;
+	return 0;
+}
+
 static int sa1100_rtc_probe(struct platform_device *pdev)
 {
 	struct rtc_device *rtc;
 	struct sa1100_rtc *info;
-	int irq_1hz, irq_alarm, ret = 0;
-
-	irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
-	irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
-	if (irq_1hz < 0 || irq_alarm < 0)
-		return -ENODEV;
+	int ret = 0;
 
 	info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
+	ret = sa1100_rtc_probe_dt(pdev, info);
+	if (ret > 0)
+		ret = sa1100_rtc_probe_irq(pdev, info);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to get rtc irq\n");
+		goto err_clk;
+	}
+
 	info->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(info->clk)) {
 		dev_err(&pdev->dev, "failed to find rtc clock source\n");
 		ret = PTR_ERR(info->clk);
 		goto err_clk;
 	}
-	info->irq_1hz = irq_1hz;
-	info->irq_alarm = irq_alarm;
 	spin_lock_init(&info->lock);
 	platform_set_drvdata(pdev, info);
 
@@ -357,6 +394,7 @@ static struct platform_driver sa1100_rtc_driver = {
 #ifdef CONFIG_PM
 		.pm	= &sa1100_rtc_pm_ops,
 #endif
+		.of_match_table = sa1100_rtc_dt_ids,
 	},
 };
 
-- 
1.7.0.4

  parent reply	other threads:[~2012-03-01  6:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-01  6:10 [PATCH 0/8] ARM: mmp: support OF on pxa168 Haojian Zhuang
2012-03-01  6:10 ` [PATCH 1/8] gpio: pxa: add OF support Haojian Zhuang
     [not found]   ` <1330582228-12424-2-git-send-email-haojian.zhuang-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>
2012-03-01  9:40     ` Arnd Bergmann
     [not found]       ` <201203010940.37123.arnd-r2nGTMty4D4@public.gmane.org>
2012-03-01  9:51         ` Arnd Bergmann
2012-03-01  6:10 ` [PATCH 2/8] serial: " Haojian Zhuang
     [not found]   ` <1330582228-12424-3-git-send-email-haojian.zhuang-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>
2012-03-01  9:47     ` Arnd Bergmann
     [not found]       ` <201203010947.39601.arnd-r2nGTMty4D4@public.gmane.org>
2012-03-01  9:48         ` Russell King - ARM Linux
     [not found]           ` <20120301094853.GA7363-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-03-01 12:55             ` Haojian Zhuang
2012-03-01  6:10 ` Haojian Zhuang [this message]
     [not found]   ` <1330582228-12424-4-git-send-email-haojian.zhuang-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>
2012-03-01  9:51     ` [PATCH 3/8] rtc: sa1100: " Arnd Bergmann
     [not found]       ` <201203010951.12405.arnd-r2nGTMty4D4@public.gmane.org>
2012-03-01 12:52         ` Haojian Zhuang
2012-03-01  6:10 ` [PATCH 4/8] i2c: pxa: " Haojian Zhuang
     [not found]   ` <1330582228-12424-5-git-send-email-haojian.zhuang-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>
2012-03-01 10:01     ` Arnd Bergmann
2012-03-01  6:10 ` [PATCH 5/8] ARM: mmp: enable rtc clk in pxa168 Haojian Zhuang
2012-03-01  6:10 ` [PATCH 6/8] ARM: mmp: append OF support on pxa168 Haojian Zhuang
2012-03-01  6:10 ` [PATCH 7/8] ARM: dts: append DTS file of pxa168 Haojian Zhuang
2012-03-01  6:10 ` [PATCH 8/8] Document: devicetree: add OF documents for arch-mmp Haojian Zhuang

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=1330582228-12424-4-git-send-email-haojian.zhuang@marvell.com \
    --to=haojian.zhuang@marvell.com \
    --cc=arnd@arndb.de \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=eric.y.miao@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@arm.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).