From patchwork Mon Apr 1 23:22:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Clouter X-Patchwork-Id: 232833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wg0-f59.google.com (mail-wg0-f59.google.com [74.125.82.59]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 38EC52C015B for ; Tue, 2 Apr 2013 10:23:15 +1100 (EST) Received: by mail-wg0-f59.google.com with SMTP id b12sf1063021wgh.4 for ; Mon, 01 Apr 2013 16:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-received:mime-version:x-beenthere:x-received:received-spf:from:to :cc:subject:date:message-id:x-mailer:in-reply-to:references :x-wormnet-spam-score:x-wormnet-spam-report:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=EGBcZulItLYy/YuOiadA0BrqbBTO5Wi0k8VdTi0mh18=; b=DsJ0furqEVt0UDTUxTwrN5JI8FfKIWQKkU2sZwcvMbzc4M/eBgOOeWKg35+5Jyo5ai Hy+taVlsXEgQ5d1HC5gy8Hcvutr951I2QGU++HvEPr/HaafveGuE9Ad3CYm952a2cyH7 FZfYwq56kDU3u3JfDz1VfXrgHppnp9UxY9WNoR9a/TTz6tb8kgzSBxFm7nUFLIKyaqq9 FzV3Zp5nnQon1M5MvUyPgfQSqDI3ihNYhTSbub/mTk+h+uUzRHeFgUUJSAWapZyEM5QV i8sg3fNGgOJo46VQe9s2AbcNOohEN0v++jvxXNf820Nb3fty6UbRpfmR1N3gvbsErLaB Rp0g== X-Received: by 10.180.76.38 with SMTP id h6mr908384wiw.15.1364858591875; Mon, 01 Apr 2013 16:23:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.183.133 with SMTP id em5ls728428wic.38.canary; Mon, 01 Apr 2013 16:23:11 -0700 (PDT) X-Received: by 10.180.10.230 with SMTP id l6mr2135985wib.3.1364858591450; Mon, 01 Apr 2013 16:23:11 -0700 (PDT) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [2a03:9800:10:2d:3203:b3a5:8bdc:5b68]) by gmr-mx.google.com with ESMTPS id fs5si533702wib.1.2013.04.01.16.23.11 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 01 Apr 2013 16:23:11 -0700 (PDT) Received-SPF: neutral (google.com: 2a03:9800:10:2d:3203:b3a5:8bdc:5b68 is neither permitted nor denied by best guess record for domain of prvs=080340ab33=alex@digriz.org.uk) client-ip=2a03:9800:10:2d:3203:b3a5:8bdc:5b68; Received: from [2a01:348:45:1000:e978:af85:4e49:7987] (helo=berk.digriz.org.uk) by marmot.wormnet.eu with smtp (Exim 4.80) (envelope-from ) id 1UMo42-0002I9-Lu; Tue, 02 Apr 2013 00:23:00 +0100 Received: (nullmailer pid 17769 invoked by uid 1000); Mon, 01 Apr 2013 23:22:47 -0000 From: Alexander Clouter To: Alessandro Zummo , Hartley Sweeten , Grant Likely , Jason Cooper , Ryan Mallon , Rob Herring , Andrew Lunn Cc: devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com, Alexander Clouter Subject: [rtc-linux] [PATCH 3/6] rtc: rtc-m48t86: add detect method for RTC Date: Tue, 2 Apr 2013 00:22:42 +0100 Message-Id: <1364858565-17192-4-git-send-email-alex@digriz.org.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1364858565-17192-1-git-send-email-alex@digriz.org.uk> References: <1364858565-17192-1-git-send-email-alex@digriz.org.uk> X-WormNet-Spam-Score: 0.6 (/) X-WormNet-Spam-Report: from marmot.wormnet.eu 1.7 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Tokens: new, 64; hammy, 123; neutral, 69; spammy, 3. X-Original-Sender: alex@digriz.org.uk X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2a03:9800:10:2d:3203:b3a5:8bdc:5b68 is neither permitted nor denied by best guess record for domain of prvs=080340ab33=alex@digriz.org.uk) smtp.mail=prvs=080340ab33=alex@digriz.org.uk; dkim=pass header.i=@digriz.org.uk Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , 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 --- 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)) {