devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Clouter <alex@digriz.org.uk>
To: Alessandro Zummo <a.zummo@towertech.it>,
	Hartley Sweeten <hsweeten@visionengravers.com>,
	Grant Likely <grant.likely@secretlab.ca>,
	Jason Cooper <jason@lakedaemon.net>,
	Ryan Mallon <rmallon@gmail.com>,
	Rob Herring <rob.herring@calxeda.com>,
	Andrew Lunn <andrew@lunn.ch>
Cc: devicetree-discuss@lists.ozlabs.org, rtc-linux@googlegroups.com,
	linux-arm-kernel@lists.infradead.org,
	Alexander Clouter <alex@digriz.org.uk>
Subject: [PATCH 3/6] rtc: rtc-m48t86: add detect method for RTC
Date: Tue,  2 Apr 2013 00:22:42 +0100	[thread overview]
Message-ID: <1364858565-17192-4-git-send-email-alex@digriz.org.uk> (raw)
In-Reply-To: <1364858565-17192-1-git-send-email-alex@digriz.org.uk>

The m48t86 has 114 bytes of user space available, so we can use this
space to detect for the presence of the RTC.

Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
---
 drivers/rtc/rtc-m48t86.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 6f99e64..b8edf73 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -173,6 +173,41 @@ static const struct rtc_class_ops m48t86_rtc_ops = {
 	.proc		= m48t86_rtc_proc,
 };
 
+/*
+ * The RTC chip has 114 bytes upper bytes that can be used as user storage
+ * space which we can use to test if the chip is present; for example it is
+ * an optional feature and not all boards will have it present.
+ *
+ * I've used the method Technologic Systems use in their rtc7800.c example
+ * for the detection.
+ *
+ * TODO: track down a guinea pig without an RTC to see if we can work out a
+ *	better RTC detection routine
+ */
+static int m48t86_rtc_detect(struct device *dev)
+{
+	unsigned char tmp_rtc0, tmp_rtc1;
+
+	tmp_rtc0 = m48t86_rtc_readbyte(dev, 126);
+	tmp_rtc1 = m48t86_rtc_readbyte(dev, 127);
+
+	m48t86_rtc_writebyte(dev, 0x00, 126);
+	m48t86_rtc_writebyte(dev, 0x55, 127);
+	if (m48t86_rtc_readbyte(dev, 127) == 0x55) {
+		m48t86_rtc_writebyte(dev, 0xaa, 127);
+		if (m48t86_rtc_readbyte(dev, 127) == 0xaa
+				&& m48t86_rtc_readbyte(dev, 126) == 0x00) {
+			m48t86_rtc_writebyte(dev, tmp_rtc0, 126);
+			m48t86_rtc_writebyte(dev, tmp_rtc1, 127);
+
+			return 0;
+		}
+	}
+
+	dev_info(dev, "RTC not found\n");
+	return -ENODEV;
+}
+
 static int m48t86_rtc_probe(struct platform_device *pdev)
 {
 	unsigned char reg;
@@ -232,6 +267,14 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
 	} else
 		priv->ops = pdev->dev.platform_data;
 
+	err = m48t86_rtc_detect(&pdev->dev);
+	if (err) {
+		if (!pdev->dev.platform_data)
+			goto out_io_data;
+		else
+			goto out_free;
+	}
+
 	priv->rtc = rtc_device_register("m48t86",
 				&pdev->dev, &m48t86_rtc_ops, THIS_MODULE);
 	if (IS_ERR(priv->rtc)) {
-- 
1.7.10.4

      parent reply	other threads:[~2013-04-01 23:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01 23:22 [PATCHv2 0/6] add devicetree bindings for rtc-m48t86 Alexander Clouter
     [not found] ` <1364858565-17192-1-git-send-email-alex-L4GPcECwBoDe9xe1eoZjHA@public.gmane.org>
2013-04-01 23:22   ` [PATCH 1/6] rtc: rtc-m48t86: move m48t86.h to platform_data Alexander Clouter
2013-04-01 23:22   ` [PATCH 2/6] rtc: rtc-m48t86: add hooks to support driver side memory mapping Alexander Clouter
     [not found]     ` <1364858565-17192-3-git-send-email-alex-L4GPcECwBoDe9xe1eoZjHA@public.gmane.org>
2013-04-01 23:36       ` Ryan Mallon
     [not found]         ` <515A1A0B.8040803-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-04-01 23:42           ` Alexander Clouter
2013-04-02  5:37             ` Ryan Mallon
2013-04-02  5:34       ` Ryan Mallon
2013-04-02 11:04       ` [PATCHv2 " Alexander Clouter
2013-04-04  7:25       ` [PATCH " Andrew Lunn
2013-04-01 23:22   ` [PATCH 4/6] arm: orion5x: move ts78xx to use rtc-m48t86 driver side memory interface Alexander Clouter
     [not found]     ` <1364858565-17192-5-git-send-email-alex-L4GPcECwBoDe9xe1eoZjHA@public.gmane.org>
2013-04-02 11:50       ` Jason Cooper
2013-04-01 23:22   ` [PATCH 5/6] arm: ep93xx: move ts72xx " Alexander Clouter
2013-04-01 23:22   ` [PATCH 6/6] rtc: rtc-m48t86: add devicetree bindings Alexander Clouter
2013-04-01 23:22 ` Alexander Clouter [this message]

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=1364858565-17192-4-git-send-email-alex@digriz.org.uk \
    --to=alex@digriz.org.uk \
    --cc=a.zummo@towertech.it \
    --cc=andrew@lunn.ch \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=hsweeten@visionengravers.com \
    --cc=jason@lakedaemon.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=rmallon@gmail.com \
    --cc=rob.herring@calxeda.com \
    --cc=rtc-linux@googlegroups.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;
as well as URLs for NNTP newsgroup(s).