From patchwork Mon May 30 18:57:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9142063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 406BB60757 for ; Mon, 30 May 2016 19:03:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35A1028066 for ; Mon, 30 May 2016 19:03:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A9912819C; Mon, 30 May 2016 19:03:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7B7528066 for ; Mon, 30 May 2016 19:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161723AbcE3TD3 (ORCPT ); Mon, 30 May 2016 15:03:29 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:54942 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161631AbcE3TD1 (ORCPT ); Mon, 30 May 2016 15:03:27 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue104) with ESMTPA (Nemesis) id 0M89Tt-1bTg890IhV-00vgHP; Mon, 30 May 2016 20:58:00 +0200 From: Arnd Bergmann To: Alexandre Belloni Cc: Arnd Bergmann , geert@linux-m68k.org, gregkh@linuxfoundation.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 v4 07/16] rtc: parisc: provide rtc_class_ops directly Date: Mon, 30 May 2016 20:57:55 +0200 Message-Id: <1464634684-1248135-8-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1464634684-1248135-1-git-send-email-arnd@arndb.de> References: <1464634684-1248135-1-git-send-email-arnd@arndb.de> X-Provags-ID: V03:K0:yodo/1pk8vzwHj4lmImtc35ZAFUmXsEYszlPovJFu+7YnpdIoGw RRs2Jab2wggrGMhbO+FYJ/L7P3XJgKI41OTcmsxhdhYEYLQ9erqAq1VB/7f64m2ztK1tTbZ 7jGN4UoUQF1UrOvtGGlgM908d6A5k+LGGyzuUhi8I4wcuWT6nBQuao75RX+AOmlI1KZTJT0 gRsmo4my8J/b6AJCAbR7g== X-UI-Out-Filterresults: notjunk:1; V01:K0:1sdl2ElRgMw=:xB81oP9/O44T/GTzHTsAaW cISQPIhy8S3Ojt+lcLfkgKc0WtsOa9TgG6AwPPnFUasDkWSonFuWfnMjMkprYaSjGsyWrMwzs MuKD1GarmPI0hekTLLpucpeGyr3sIR0SdAQ/fcaa76P1rUw3aCBK9Tx0KhfSPZHMlfgLqqVEB Lt2mjGylUmzGTtCgFMEpgPVQJ+tdtBXxzUgTqG1Iiu9oNv9J4jYBhk+XbxtasjF3Imnj0LTxf SQnFNQEQoxA7czM7RmMU1JJiDyeYOylLx6z6ZKamBEIIyUuoHl2VlUYI9WzI1nxrMr/U6FRnt ALStX1UKfM0kDJyvV7ClfGB2JAyK7BmVpWnGA6R6Oh2XYdaXUr4hG4cwEu3gKCDiNK2WOgsy1 aDG2pUK+1Rv80F1sza/BGlpmjVwMQzXGSE9DxRR2PgTYR4SMhuuDH343CkVxbEasmJ463VTGO kOztmPzc6BgynbXcI/cOkajs7OtALVu1lAI9XVAKjALt8hyKaoECIRwMmNwkPIUfnJEY52oqK cSHw66aQtfBQDRj0xraMdVcmnWFNRv/8lJGojPM27lLZOSq4wX1s1TtZuu6XeK1ro3vUZpOv/ YI+VImbKaX+H8Wpr6ZEFClUtut8cbXupP9PBb0MjgzinV4If9ai/69UseUeEhfCyCtbxaZH7Y z8GCg2eRVosl5jp72RFvkvyLDn0FGeLqJ18T5GgASjxA+NqftsTSvg9dqzFc9KlFo1aQ= Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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)