From patchwork Tue Jan 27 01:04:22 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Swierk X-Patchwork-Id: 20363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from wf-out-1516.google.com (wf-out-1516.google.com [209.85.200.165]) by ozlabs.org (Postfix) with ESMTP id 425C2DE105 for ; Tue, 27 Jan 2009 12:04:31 +1100 (EST) Received: by wf-out-1516.google.com with SMTP id r34so1794363wfc.41 for ; Mon, 26 Jan 2009 17:04:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received-spf:authentication-results:received :received:received:subject:from:to:mime-version:content-type:date :message-id:x-mailer:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=np5v9N8v4ws5j/FlFzlgcF4JQiugMgbVPg6++wOiPaw=; b=ZiHZcmV3GeEbxZRiMxKiGZmQc0NGql2W3MOk7Q5uRZk6gFSTwpqTuheMV4nFwHvTjS SFXgII0aa/+2s7RA9sX391iUHm87JDzX7KBmR1Hs3NOEGnR1zFxWt7ia1+SP+V/ZLqo3 uSwZwzMRsobLqxg/Fo8ElHBolw3JzDuunmAp8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results :subject:from:to:mime-version:content-type:date:message-id:x-mailer :reply-to:sender:precedence:x-google-loop:mailing-list:list-id :list-post:list-help:list-unsubscribe:x-beenthere-env:x-beenthere; b=lmaoc5Y2PqG5AGljSF0Y96TD0+UiGwfQN86NsUfAq4SJ/liNedsNl7GV/olNkYcJDv u1EwayKclou1At8fc1i6F3iEI+LXTHmvKNfGMk5vKV3gVF51c6OYgeDmBsr6hegCMi4R /aQag5wEE9A6tQGIUThToqTXV0E+sKu57WSi0= Received: by 10.143.31.11 with SMTP id i11mr1241070wfj.24.1233018266484; Mon, 26 Jan 2009 17:04:26 -0800 (PST) Received: by 10.107.155.40 with SMTP id h40gr1857pro.0; Mon, 26 Jan 2009 17:04:26 -0800 (PST) X-Sender: eswierk@aristanetworks.com X-Apparently-To: rtc-linux@googlegroups.com Received: by 10.141.99.1 with SMTP id b1mr1927476rvm.20.1233018265951; Mon, 26 Jan 2009 17:04:25 -0800 (PST) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.230]) by mx.google.com with ESMTP id m37si636196waf.2.2009.01.26.17.04.25; Mon, 26 Jan 2009 17:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of eswierk@aristanetworks.com designates 209.85.198.230 as permitted sender) client-ip=209.85.198.230; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eswierk@aristanetworks.com designates 209.85.198.230 as permitted sender) smtp.mail=eswierk@aristanetworks.com Received: by rv-out-0506.google.com with SMTP id g9so948316rvb.6 for ; Mon, 26 Jan 2009 17:04:25 -0800 (PST) Received: by 10.142.210.8 with SMTP id i8mr214150wfg.20.1233018265840; Mon, 26 Jan 2009 17:04:25 -0800 (PST) Received: from ?172.17.2.29? (65-119-47-100.dia.static.qwest.net [65.119.47.100]) by mx.google.com with ESMTPS id 22sm24193803wfg.30.2009.01.26.17.04.24 (version=SSLv3 cipher=RC4-MD5); Mon, 26 Jan 2009 17:04:25 -0800 (PST) Subject: [rtc-linux] [PATCH] rtc: add rtc_systohc for ntp use From: Ed Swierk To: a.zummo@towertech.it, rtc-linux@googlegroups.com, tglx@linutronix.de, mingo@redhat.com, linux-kernel@vger.kernel.org Mime-Version: 1.0 Date: Mon, 26 Jan 2009 17:04:22 -0800 Message-Id: <1233018262.14510.111.camel@localhost.localdomain> X-Mailer: Evolution 2.24.3 (2.24.3-1.fc10) Reply-To: rtc-linux@googlegroups.com Sender: rtc-linux@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rtc-linux@googlegroups.com; contact rtc-linux+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rtc-linux@googlegroups.com X-BeenThere: rtc-linux@googlegroups.com Following up to Alessandro's RFC of 10 Nov 2008, this patch implements rtc_systohc() to update the configured rtc device (cmos, i2c, etc.) from the ntp-synchronized system clock. It changes the ntp update code to call rtc_systohc() rather than update_persistent_clock() which (at least on x86) always updates the cmos rtc. No attempt is made to compensate for the 500-ms delay imposed when setting a cmos rtc chip. If you actually have a cmos rtc you can stick with the existing code, but at some point it would be nice to unify these. Signed-off-by: Ed Swierk --- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. -~----------~----~----~----~------~----~------~--~--- Index: linux-2.6.28.2/drivers/rtc/Kconfig =================================================================== --- linux-2.6.28.2.orig/drivers/rtc/Kconfig +++ linux-2.6.28.2/drivers/rtc/Kconfig @@ -30,7 +30,7 @@ config RTC_HCTOSYS unnecessary fsck runs at boot time, and to network better. config RTC_HCTOSYS_DEVICE - string "RTC used to set the system time" + string "RTC used to set the system time on startup and resume" depends on RTC_HCTOSYS = y default "rtc0" help @@ -52,6 +52,23 @@ config RTC_HCTOSYS_DEVICE sleep states. Do not specify an RTC here unless it stays powered during all this system's supported sleep states. +config RTC_SYSTOHC + bool "Set RTC from system time in NTP sync mode" + depends on RTC_CLASS = y + default y + help + If you say yes here, the system time (wall clock) will be written + to the hardware clock every 11 minutes, if the kernel is in NTP + mode and your platforms supports it. + +config RTC_SYSTOHC_DEVICE + string "RTC used to save the system time in NTP sync mode" + depends on RTC_SYSTOHC = y + default "rtc0" + help + The RTC device that will get written with the system time + in NTP mode. + config RTC_DEBUG bool "RTC debug support" depends on RTC_CLASS = y Index: linux-2.6.28.2/drivers/rtc/Makefile =================================================================== --- linux-2.6.28.2.orig/drivers/rtc/Makefile +++ linux-2.6.28.2/drivers/rtc/Makefile @@ -8,6 +8,7 @@ endif obj-$(CONFIG_RTC_LIB) += rtc-lib.o obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o +obj-$(CONFIG_RTC_SYSTOHC) += systohc.o obj-$(CONFIG_RTC_CLASS) += rtc-core.o rtc-core-y := class.o interface.o Index: linux-2.6.28.2/drivers/rtc/systohc.c =================================================================== --- /dev/null +++ linux-2.6.28.2/drivers/rtc/systohc.c @@ -0,0 +1,36 @@ +/* + * RTC subsystem, systohc for ntp use + * + * Copyright (C) 2008 Tower Technologies + * Author: Alessandro Zummo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +*/ + +#include + +int rtc_systohc(void) +{ + int err; + struct rtc_time tm; + struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_SYSTOHC_DEVICE); + + if (rtc == NULL) { + printk("%s: unable to open rtc device (%s)\n", + __FILE__, CONFIG_RTC_SYSTOHC_DEVICE); + return -ENODEV; + } + + rtc_time_to_tm(get_seconds(), &tm); + err = rtc_set_time(rtc, &tm); + if (err != 0) + dev_err(rtc->dev.parent, + "systohc: unable to set the hardware clock\n"); + + rtc_class_close(rtc); + + return err; +} +EXPORT_SYMBOL(rtc_systohc); Index: linux-2.6.28.2/kernel/time/ntp.c =================================================================== --- linux-2.6.28.2.orig/kernel/time/ntp.c +++ linux-2.6.28.2/kernel/time/ntp.c @@ -221,17 +221,20 @@ static void sync_cmos_clock(struct work_ static DECLARE_DELAYED_WORK(sync_cmos_work, sync_cmos_clock); +#ifdef CONFIG_RTC_SYSTOHC +extern int rtc_systohc(void); +#endif + static void sync_cmos_clock(struct work_struct *work) { +#ifndef CONFIG_RTC_SYSTOHC struct timespec now, next; int fail = 1; +#endif /* * If we have an externally synchronized Linux clock, then update - * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be - * called as close as possible to 500 ms before the new second starts. - * This code is run on a timer. If the clock is set, that timer - * may not expire at the correct time. Thus, we adjust... + * CMOS clock accordingly every ~11 minutes. */ if (!ntp_synced()) /* @@ -240,6 +243,19 @@ static void sync_cmos_clock(struct work_ */ return; +#ifdef CONFIG_RTC_SYSTOHC + + rtc_systohc(); + schedule_delayed_work(&sync_cmos_work, 660*HZ); + +#else + + /* + * Set_rtc_mmss() has to be called as close as possible to 500 ms + * before the new second starts. This code is run on a timer. + * If the clock is set, that timer may not expire at the correct + * time. Thus, we adjust... + */ getnstimeofday(&now); if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) fail = update_persistent_clock(now); @@ -258,6 +274,8 @@ static void sync_cmos_clock(struct work_ next.tv_nsec -= NSEC_PER_SEC; } schedule_delayed_work(&sync_cmos_work, timespec_to_jiffies(&next)); + +#endif } static void notify_cmos_timer(void)