From patchwork Fri Jun 27 17:27:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 32630 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 514DE200B9 for ; Fri, 27 Jun 2014 17:27:25 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id t59sf10531351yho.2 for ; Fri, 27 Jun 2014 10:27:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=MCWznjBso/Ow7ftRSG9RAewyx0sp7uiZbkSWpE+SQNw=; b=NLf1LbGsWWs7IUErvTxDCRwez7KzpyrYDgrwDQi5DhjfhAxKBoa03uognyMVsr1RFT eV2vCTQEn6OL5TgRF5Z08MzSvnxkIvHg6sRxWcXMAFTMZVqc2qwif/mjHYqTKM23RRtg Xd0/DEZ5dH4TIIZ/l9RAWoGru/96OswEhAbsnr4J7SKyqFu6OFPbMEkTXbpV4+C0jlJV kaueVFxLPZMtgRLFm5ysqlm8giHzCHcAlXuxuuMG42fno1uXU3IfUHBlL8u6NLjgzcf5 q3duqUz7aKzKh9pZJOop5iZFKnSAk8jApp+WxpnDHqyLNuXWx5tnuhXHCQmMwM07nsNK 4SAg== X-Gm-Message-State: ALoCoQlyY92jnCHF8yGkm1yAcxb/wrK+PAs8kP1rUqpnidm+LZvwr/AqoTvL6/ApkViQmaMvZytz X-Received: by 10.58.199.135 with SMTP id jk7mr12757647vec.22.1403890045113; Fri, 27 Jun 2014 10:27:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.209 with SMTP id x75ls645134qgx.46.gmail; Fri, 27 Jun 2014 10:27:25 -0700 (PDT) X-Received: by 10.220.7.71 with SMTP id c7mr78111vcc.77.1403890044983; Fri, 27 Jun 2014 10:27:24 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id y3si1742735vdv.1.2014.06.27.10.27.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 10:27:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hy10so5452963vcb.3 for ; Fri, 27 Jun 2014 10:27:24 -0700 (PDT) X-Received: by 10.52.27.133 with SMTP id t5mr18086172vdg.9.1403890044802; Fri, 27 Jun 2014 10:27:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp124428vcb; Fri, 27 Jun 2014 10:27:24 -0700 (PDT) X-Received: by 10.66.179.111 with SMTP id df15mr32522912pac.52.1403890043918; Fri, 27 Jun 2014 10:27:23 -0700 (PDT) Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com [209.85.192.176]) by mx.google.com with ESMTPS id su6si14619637pab.177.2014.06.27.10.27.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 10:27:23 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.176 as permitted sender) client-ip=209.85.192.176; Received: by mail-pd0-f176.google.com with SMTP id ft15so4646254pdb.21 for ; Fri, 27 Jun 2014 10:27:23 -0700 (PDT) X-Received: by 10.68.164.67 with SMTP id yo3mr32918061pbb.104.1403890043500; Fri, 27 Jun 2014 10:27:23 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id ln2sm54326979pab.35.2014.06.27.10.27.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 10:27:23 -0700 (PDT) From: John Stultz To: Linux Kernel Mailing List Cc: John Stultz , John Whitmore , Alessandro Zummo , Alexander Holler Subject: [PATCH 2/2][RFC] rtc: Rework hctosys so that it is called on RTC registration Date: Fri, 27 Jun 2014 10:27:11 -0700 Message-Id: <1403890031-26419-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1403890031-26419-1-git-send-email-john.stultz@linaro.org> References: <1403890031-26419-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Rather then calling hctosys at late_init, when RTC modules may not yet be loaded, call hctosys on each RTC device registration. We also change hctosys to usilize do_first_settimeofday() in order to make sure the time is only initialized once by an RTC and doesn't overwrite any time changes already made by userspace. Cc: John Whitmore Cc: Alessandro Zummo Cc: Alexander Holler Signed-off-by: John Stultz --- drivers/rtc/class.c | 2 ++ drivers/rtc/hctosys.c | 19 ++++++++----------- include/linux/rtc.h | 6 ++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 589351e..6986529 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -237,6 +237,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, dev_info(dev, "rtc core: registered %s as %s\n", rtc->name, dev_name(&rtc->dev)); + rtc_hctosys(); + return rtc; exit_kfree: diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c index 4aa60d7..72be031 100644 --- a/drivers/rtc/hctosys.c +++ b/drivers/rtc/hctosys.c @@ -22,7 +22,7 @@ * the best guess is to add 0.5s. */ -static int __init rtc_hctosys(void) +int rtc_hctosys(void) { int err = -ENODEV; struct rtc_time tm; @@ -54,14 +54,13 @@ static int __init rtc_hctosys(void) rtc_tm_to_time(&tm, &tv.tv_sec); - err = do_settimeofday(&tv); - - dev_info(rtc->dev.parent, - "setting system clock to " - "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned int) tv.tv_sec); + if (!do_first_settimeofday(&tv)) + dev_info(rtc->dev.parent, + "setting system clock to " + "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, + (unsigned int) tv.tv_sec); err_invalid: err_read: @@ -72,5 +71,3 @@ err_open: return err; } - -late_initcall(rtc_hctosys); diff --git a/include/linux/rtc.h b/include/linux/rtc.h index c2c2897..a524cc6 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -191,6 +191,12 @@ static inline bool is_leap_year(unsigned int year) return (!(year % 4) && (year % 100)) || !(year % 400); } +#ifdef CONFIG_RTC_SYSTOHC +int rtc_hctosys(void); +#else +#define rtc_hctosys() 0 +#endif + #ifdef CONFIG_RTC_HCTOSYS_DEVICE extern int rtc_hctosys_ret; #else