From patchwork Wed Apr 27 22:34:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102429 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2444399qge; Wed, 27 Apr 2016 15:35:38 -0700 (PDT) X-Received: by 10.66.176.103 with SMTP id ch7mr9358959pac.20.1461796538192; Wed, 27 Apr 2016 15:35:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e66si6252540pfa.118.2016.04.27.15.35.37; Wed, 27 Apr 2016 15:35:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754033AbcD0Wfb (ORCPT + 29 others); Wed, 27 Apr 2016 18:35:31 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:63201 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753532AbcD0Wf2 (ORCPT ); Wed, 27 Apr 2016 18:35:28 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue104) with ESMTPA (Nemesis) id 0M5xcn-1bsqnb3ynZ-00xtDt; Thu, 28 Apr 2016 00:34:51 +0200 From: Arnd Bergmann To: Alexandre Belloni Cc: Arnd Bergmann , geert@linux-m68k.org, deller@gmx.de, benh@kernel.crashing.org, mpe@ellerman.id.au, dalias@libc.org, dhowells@redhat.com, linux-alpha@vger.kernel.org, a.zummo@towertech.it, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, linux-m68k@lists.linux-m68k.org, rtc-linux@googlegroups.com, linux-arch@vger.kernel.org Subject: [PATCH v3 07/16] rtc: parisc: provide rtc_class_ops directly Date: Thu, 28 Apr 2016 00:34:21 +0200 Message-Id: <1461796470-1291527-8-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1461796470-1291527-1-git-send-email-arnd@arndb.de> References: <1461796470-1291527-1-git-send-email-arnd@arndb.de> X-Provags-ID: V03:K0:62x2aIdnKqPcbygSy2sENMpJcKWeNB/mTUpBKKJ/eLubsRKZxZT vgqeOFbyF4Ow5fAHeDVhHoNROE+VX/3I4SOo7G7BRLud94NFThUvY67uDxb0KUw6D12Ut94 JVLlhePLyZCK4Mx8LVPFkQzrP0/XaTEewLMXRILfglf7djYnMY/tRWZWxpBtDEzkpuX0cDT BmPlvG3HDiv8dHINrhYjw== X-UI-Out-Filterresults: notjunk:1; V01:K0:TwoCPQQjntU=:3KW+cYvH1Kjlv23f/GpgTZ VrwjEOpbV5drQoa1MkdlY2tNqNDXinDw2Wjj+T6VGqyE3umtt9am/W/rcugvgm7QKryMRLC11 57CMrtVF2mUNLrYuTvGaPm0BdVE0UKZ7UOtBEHt68bKOfIFXwl9NlupI6UovXGE0gh1tqpNbh 8iDYQPHQfEyZB8z6ozGgrRkK6fOVLrylUKLUe0F757r5kfUKQO1g43hoiIFNuPwp4vM3t9qBh pIXZ+3Dk4ewzP6JGgY2gxCx2d1daHXjoJoSpgbQpKqKmsVXKqDYbmc6QwRun4A6k/Bb8JyrOf wQryd5YD3feaeOjmbV1YfUYxkHM5FTLKR3NVg10fXSgON92K/8XkD5vDrlaYUiIq3i79KCAo2 smTXna8COSOANqJRCAY9mVccUFam8rVguxCbfY1SQbqILLDywmi4mbCnvi/GCe5ixrTO9gNn4 pWRRnp7T88A9qY8Z1vVd0PIdYLJjDFCoMzVb6d/dorfh9XTQf/7l3HeKAp5Pepb2DY5tEfw/M PsRDYsJAWNXuoFxPpABaE3h9TwsltYwCiQqVmiPh42Xv8Y+Rq93HOyZLW/2QtigkUmONNHg+3 uzjWFb9sBIrVE7hWtuKiH5M4wVAdkg+3GNujHM38dGV3lObUHay090fml6a+DNv7tRtPErt9T QGTqA0+AFdDKyElbrPwggev1AKNaWzxWjSA03MgHZxbCSQQm8O5stfna7HgwGARaXF/w= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The rtc-generic driver provides an architecture specific wrapper on top of the generic rtc_class_ops abstraction, and on pa-risc, that is implemented using an open-coded version of rtc_time_to_tm/rtc_tm_to_time. This changes the parisc rtc-generic device to provide its rtc_class_ops directly, using the normal helper functions, which makes this y2038 safe (on 32-bit) and simplifies the implementation. Signed-off-by: Arnd Bergmann --- arch/parisc/kernel/time.c | 36 +++++++++++++++++++++++++++++++++++- drivers/rtc/rtc-generic.c | 3 +-- 2 files changed, 36 insertions(+), 3 deletions(-) -- 2.7.0 diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c index 58dd6801f5be..744878789752 100644 --- a/arch/parisc/kernel/time.c +++ b/arch/parisc/kernel/time.c @@ -12,6 +12,7 @@ */ #include #include +#include #include #include #include @@ -248,14 +249,47 @@ void __init start_cpu_itimer(void) per_cpu(cpu_data, cpu).it_value = next_tick; } +#if IS_ENABLED(CONFIG_RTC_DRV_GENERIC) +static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm) +{ + struct pdc_tod tod_data; + + memset(tm, 0, sizeof(*tm)); + if (pdc_tod_read(&tod_data) < 0) + return -EOPNOTSUPP; + + /* we treat tod_sec as unsigned, so this can work until year 2106 */ + rtc_time64_to_tm(tod_data.tod_sec, tm); + return rtc_valid_tm(tm); +} + +static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm) +{ + time64_t secs = rtc_tm_to_time64(tm); + + if (pdc_tod_set(secs, 0) < 0) + return -EOPNOTSUPP; + + return 0; +} + +static const struct rtc_class_ops rtc_generic_ops = { + .read_time = rtc_generic_get_time, + .set_time = rtc_generic_set_time, +}; + static int __init rtc_init(void) { struct platform_device *pdev; - pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); + pdev = platform_device_register_data(NULL, "rtc-generic", -1, + &rtc_generic_ops, + sizeof(rtc_generic_ops)); + return PTR_ERR_OR_ZERO(pdev); } device_initcall(rtc_init); +#endif void read_persistent_clock(struct timespec *ts) { diff --git a/drivers/rtc/rtc-generic.c b/drivers/rtc/rtc-generic.c index 3958e87a05fa..92b5e02a3750 100644 --- a/drivers/rtc/rtc-generic.c +++ b/drivers/rtc/rtc-generic.c @@ -9,8 +9,7 @@ #include #include -#if defined(CONFIG_M68K) || defined(CONFIG_PARISC) || \ - defined(CONFIG_PPC) +#if defined(CONFIG_M68K) || defined(CONFIG_PPC) #include static int generic_get_time(struct device *dev, struct rtc_time *tm)