From patchwork Thu Nov 25 17:43:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 73108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-fx0-f56.google.com (mail-fx0-f56.google.com [209.85.161.56]) by ozlabs.org (Postfix) with ESMTP id 3F511B718F for ; Fri, 26 Nov 2010 04:43:30 +1100 (EST) Received: by fxm3 with SMTP id 3sf290327fxm.11 for ; Thu, 25 Nov 2010 09:43:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:mime-version:x-beenthere:received :received:received:received:received-spf:received:from:to:cc:subject :date:message-id:x-mailer:x-virus-scanned:x-virus-status :x-spam-status:x-spam-checker-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; bh=QplFcD/LqMquuSQIDgDAyoutvoFRwx06E/NZkOrBv0w=; b=EuspSKNsuhhQUBTNKQpPufBqHozrndGgvPvbbAZK1ZGhLZEDIUuNhQiGb7qr/H6PeY /s4UtIz21crr8iIYsWDDhHFcijEo0SWrCPxcwHFcOvZ9j/+jh1T7sQWN3OLP83HLy7py PXN9CdafFH6qs9kB+TvrGAaUEAfneOytQgljA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:x-virus-scanned:x-virus-status:x-spam-status :x-spam-checker-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; b=FM8iQkbUG1J5VWDON8PU6FgipVrGas/rbr56WgRp95wJ82CWSYZezrxI1KcohquGcL 3teffdvKyxtjR256PjK1JCGSRkSpR6Phr/SS5s1U2kUO2KkwTL+waaKpdVrR8CL8zM/z VjiN1UmTUXdVs50JO2daiKF8cZE/5Hg23nRaQ= Received: by 10.223.75.193 with SMTP id z1mr50006faj.46.1290707007634; Thu, 25 Nov 2010 09:43:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.204.49.197 with SMTP id w5ls51393bkf.3.p; Thu, 25 Nov 2010 09:43:27 -0800 (PST) Received: by 10.204.154.197 with SMTP id p5mr99566bkw.0.1290707007011; Thu, 25 Nov 2010 09:43:27 -0800 (PST) Received: by 10.204.154.197 with SMTP id p5mr99565bkw.0.1290707006969; Thu, 25 Nov 2010 09:43:26 -0800 (PST) Received: from www.tglx.de (www.tglx.de [62.245.132.106]) by gmr-mx.google.com with ESMTP id 2si77799fat.14.2010.11.25.09.43.26; Thu, 25 Nov 2010 09:43:26 -0800 (PST) Received-SPF: neutral (google.com: 62.245.132.106 is neither permitted nor denied by best guess record for domain of bigeasy@linutronix.de) client-ip=62.245.132.106; Received: from Shiva.tec.linutronix.de (www.tglx.de [127.0.0.1]) by www.tglx.de (8.13.8/8.13.8/TGLX-2007100201) with ESMTP id oAPHhKX6020952; Thu, 25 Nov 2010 18:43:23 +0100 From: Sebastian Andrzej Siewior To: Alessandro Zummo Cc: sodaville@linutronix.de, tglx@linutronix.de, Sebastian Andrzej Siewior , rtc-linux@googlegroups.com, Dirk Brandewie Subject: [rtc-linux] [PATCH] rtc/cmos: add OF bindings Date: Thu, 25 Nov 2010 18:43:10 +0100 Message-Id: <1290706990-8046-1-git-send-email-bigeasy@linutronix.de> X-Mailer: git-send-email 1.7.3.2 X-Virus-Scanned: clamav-milter 0.95.3 at www.tglx.de X-Virus-Status: Clean X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on www.tglx.de X-Original-Sender: bigeasy@linutronix.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 62.245.132.106 is neither permitted nor denied by best guess record for domain of bigeasy@linutronix.de) smtp.mail=bigeasy@linutronix.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , This allows to load the OF driver based informations from the device tree. Systems without BIOS may need to perform some initialization. PowerPC creates a PNP device from the OF information and performs this kind of initialization in their private PCI quirk. This looks more generic. Signed-off-by: Sebastian Andrzej Siewior CC: rtc-linux@googlegroups.com Signed-off-by: Dirk Brandewie --- drivers/rtc/rtc-cmos.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 107 insertions(+), 0 deletions(-) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 5856167..1817a4d 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ #include @@ -1120,6 +1123,97 @@ static struct pnp_driver cmos_pnp_driver = { }; #endif /* CONFIG_PNP */ +#ifdef CONFIG_OF +static bool of_driver_registered; + +static const struct of_device_id of_cmos_match[] = { + { + .compatible = "motorola,mc146818", + }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_cmos_match); + +static int __init of_cmos_probe(struct platform_device *dev, + const struct of_device_id *match) +{ + struct resource res; + struct device_node *node = dev->dev.of_node; + struct rtc_time time; + int ret; + int virq; + const __be32 *val; + + ret = of_address_to_resource(node, 0, &res); + if (ret) + return ret; + + virq = irq_of_parse_and_map(node, 0); + + val = of_get_property(node, "ctrl_reg", NULL); + if (val) + CMOS_WRITE(be32_to_cpup(val), RTC_CONTROL); + + val = of_get_property(node, "freq_reg", NULL); + if (val) + CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT); + + ret = rtc_valid_tm(&time); + if (ret) { + struct rtc_time def_time = { + .tm_year = 1, + }; + + set_rtc_time(&def_time); + } + + return cmos_do_probe(&dev->dev, &res, virq); +} + +static int __exit of_cmos_remove(struct platform_device *dev) +{ + cmos_do_remove(&dev->dev); + return 0; +} + +static int of_cmos_shutdown(struct platform_device *dev) +{ + if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(&dev->dev)) + return 0; + + cmos_do_shutdown(); + return 0; +} + +#ifdef CONFIG_PM +static int of_cmos_suspend(struct platform_device *dev, pm_message_t mesg) +{ + return cmos_suspend(&dev->dev, mesg); +} + +static int of_cmos_resume(struct platform_device *dev) +{ + return cmos_resume(&dev->dev); +} +#else +#define of_cmos_suspend NULL +#define of_cmos_resume NULL +#endif + +static struct of_platform_driver cmos_of_driver_probe = { + .driver = { + .name = "motorola-mc146818", + .owner = THIS_MODULE, + .of_match_table = of_cmos_match, + }, + .probe = of_cmos_probe, + .remove = of_cmos_remove, + .shutdown = of_cmos_shutdown, + .suspend = of_cmos_suspend, + .resume = of_cmos_resume, +}; +#endif + /*----------------------------------------------------------------*/ @@ -1176,6 +1270,11 @@ static int __init cmos_init(void) if (retval == 0) pnp_driver_registered = true; #endif +#ifdef CONFIG_OF + retval = of_register_platform_driver(&cmos_of_driver_probe); + if (retval == 0) + of_driver_registered = true; +#endif if (!cmos_rtc.dev) { retval = platform_driver_probe(&cmos_platform_driver, @@ -1191,6 +1290,10 @@ static int __init cmos_init(void) if (pnp_driver_registered) pnp_unregister_driver(&cmos_pnp_driver); #endif +#ifdef CONFIG_OF + if (of_driver_registered) + of_unregister_platform_driver(&cmos_of_driver_probe); +#endif return retval; } module_init(cmos_init); @@ -1201,6 +1304,10 @@ static void __exit cmos_exit(void) if (pnp_driver_registered) pnp_unregister_driver(&cmos_pnp_driver); #endif +#ifdef CONFIG_OF + if (of_driver_registered) + of_unregister_platform_driver(&cmos_of_driver_probe); +#endif if (platform_driver_registered) platform_driver_unregister(&cmos_platform_driver); }