From patchwork Tue Jul 24 21:36:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 142832 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp65249ljj; Tue, 24 Jul 2018 14:36:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpebtmV8qLpfAlNhcxiHNTvc/XoKNX+gJTQkLtUy9UFFMS6i+uWwHs7PuIPrcLNOVaoAZj6p X-Received: by 2002:a63:5922:: with SMTP id n34-v6mr17921294pgb.113.1532468219527; Tue, 24 Jul 2018 14:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532468219; cv=none; d=google.com; s=arc-20160816; b=v8o9R5zzDNkO+Xqi6lZKhJuDvhoIWMHso2STIW4xVk/D2wWbRS/NELtvF0k5xOqlkj okgPcXbdL2nyjfhmt5eHod5k5/QFKgKc6s4ZmFrjfyk7a3I4oI+2hnraPxk+MedB/2WP NaYLRwVFMqnsqrk4PaaolJwdQDg7K1qWy6kV8X00slCGzEBPCfo2bBtaOkU3eV6XhI/d gfylcSYJrT9ioT6GM1X7Ax1T3Z/nNT60zVYOKI244QY3EUowO7PIbudgI/ShLTiQm9JF 4wxskHAmzIU+G5QWe1G85SpmPdYQiakEyGz2iPq4Uab21xY0bnwKED3sbF9N92Xzv0uT oB0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nXGhvgbtM2MVYnmUcBhRNm1HWv2dEUpncTRfWaB6YNs=; b=GL22ghyrRz7cqvxxD3S8mtJgrecylz4+zChS/eZ5lIkoJXJ2WmvPOPEAhsqfdejN7l vxYsVHP177h14Gj3lxHqVsfVFhME4DVCG832PYk4FuGdqt5x/Z+YXjAShyKgHYlO7EtV AqnsJ+eyK/PMj8PRHE7LrON2ZtjrI98D9gxPghQDWcvMqS7/EI854jkG93t8/kLkg0JQ +QdU1hPeewVGBdAx29jN9PvA6O9ZMuImVLTKqD2aG1BJ0IvskJYdyIHbKG4KAxSz4Cwp 6llDk0M7ULXFPJ/KTuX0/7cnAC0hviRjDRMQxc06tta2Z4OHwU/k/chK13IhXbSCynSO hNGA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 2-v6si12465873pgq.479.2018.07.24.14.36.59; Tue, 24 Jul 2018 14:36:59 -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 S2388838AbeGXWpW (ORCPT + 31 others); Tue, 24 Jul 2018 18:45:22 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:57848 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388608AbeGXWpV (ORCPT ); Tue, 24 Jul 2018 18:45:21 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id 0LthuT-1g74Rb04mr-011BmG; Tue, 24 Jul 2018 23:36:34 +0200 From: Arnd Bergmann To: dalias@libc.org Cc: ysato@users.sourceforge.jp, baolin.wang@linaro.org, y2038@lists.linaro.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 1/4] sh: dreamcast: rtc: push down rtc class ops into driver Date: Tue, 24 Jul 2018 23:36:21 +0200 Message-Id: <20180724213624.3899336-1-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 X-Provags-ID: V03:K1:7Uh8AsYkJMOjFM01VrXgDnXSbrDNz+LOZatv9aU/vPLtBX9TRwU E/uK2f+Hi7/H/2Uz3mJ9xlDK+IVFjfE6Z++qQbUs9KYqRtp18PO6DMqjCMBj8RjfkAp9fPC 5R730vBo6IYzv5xb9X6LS10ZqcGg60SznjdImIaivpkAfqB8IpWRHzog3kLhpqih6C7Qblm hu1HIJHr5+7NmNEDR+fYQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:zl42cKfB+Fg=:HJ61kPAGgHqO2PzTjPVUo+ 8Bnw2GE00aDnMlWsMM1rax08uLJu2J1ilkfDlCkthlEGiCcAHhjcwcFbGPZ3fz8F4THiswT7P TWH4VJvtWUlF31JJ+jWfCS4lcSNv1VRkaik2pikmjO/o+IlpdJKToXJPSzqULYoZB8WeIreEK TLCl9Ix+IZX5R1Ioc8IfgctoEhfnpUrHdqq40qoiLGhEecMuk/RSuQ85dghzgqV4uU4Ulth84 dLb4oZ72WYLlHW+QNYbz177EmKC1qh73iy+UVaeBTwz81jSX8MIfASRD3uoR3TedRfrERK9J4 2XuugufzB8lWGMUffcqsPunQ3XiWzIZbun+eSBjB2lHris42IYcefamrs6l2JXwRvvIb17j2Y RX7cUZ+D75LGsd7Wg5UhWyqXWdJ+QcDDEmmi392wJicLsqpoZaTkNJWbLWbPKllCd6KNi6Vc6 acqD71Eh9NANXyaCbWi0ntPoEiYj6Bx8oioEyH2nRaXrYDRUFZT7cureF3ge27kP8EGQSnKuz m3GWz7yr33RlDGvHo4OPverg7YrWFrXbG6pCzG6I2L4HhWa/TK47v4mGK/eXzgZCjmsRq/0T0 inWOZHdGK0Fo48XHYfsnLffxGZ/cp3RnJ8/v0zoBw8cct9RcfAqQR79XhyprmqulQowy7a1Pm lkoU82zO6uUM1kckG1YP2zJYLuQNlseWz8tI9S1KPJRhT+ZbLEIoDCqnfFoaKqRdlA08= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The dreamcast RTC support has an extra level of indirection to provide either the old read_persistent_clock/update_persistent_clock interface or the rtc-generic device for hctosys/systohc. Both do the same thing here, so we can do away with the abstraction and simply enable the RTC core code to take care of it. Signed-off-by: Arnd Bergmann --- arch/sh/boards/mach-dreamcast/Makefile | 4 +- arch/sh/boards/mach-dreamcast/rtc.c | 39 +++++++++++++------ arch/sh/boards/mach-dreamcast/setup.c | 1 - arch/sh/configs/dreamcast_defconfig | 2 + arch/sh/include/mach-dreamcast/mach/sysasic.h | 1 - 5 files changed, 31 insertions(+), 16 deletions(-) -- 2.18.0 diff --git a/arch/sh/boards/mach-dreamcast/Makefile b/arch/sh/boards/mach-dreamcast/Makefile index 7b97546c7e5f..62b024bc2a3e 100644 --- a/arch/sh/boards/mach-dreamcast/Makefile +++ b/arch/sh/boards/mach-dreamcast/Makefile @@ -2,5 +2,5 @@ # Makefile for the Sega Dreamcast specific parts of the kernel # -obj-y := setup.o irq.o rtc.o - +obj-y := setup.o irq.o +obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o diff --git a/arch/sh/boards/mach-dreamcast/rtc.c b/arch/sh/boards/mach-dreamcast/rtc.c index 061d65714fcc..4f168d8d2951 100644 --- a/arch/sh/boards/mach-dreamcast/rtc.c +++ b/arch/sh/boards/mach-dreamcast/rtc.c @@ -11,8 +11,9 @@ */ #include -#include -#include +#include +#include +#include /* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in seconds) to get the standard Unix Epoch when getting the time, and add @@ -30,9 +31,10 @@ * * Grabs the current RTC seconds counter and adjusts it to the Unix Epoch. */ -static void aica_rtc_gettimeofday(struct timespec *ts) +static int aica_rtc_gettimeofday(struct device *dev, struct rtc_time *tm) { unsigned long val1, val2; + time64_t t; do { val1 = ((__raw_readl(AICA_RTC_SECS_H) & 0xffff) << 16) | @@ -42,10 +44,12 @@ static void aica_rtc_gettimeofday(struct timespec *ts) (__raw_readl(AICA_RTC_SECS_L) & 0xffff); } while (val1 != val2); - ts->tv_sec = val1 - TWENTY_YEARS; + /* normalize to 1970..2106 time range */ + t = (u32)(val1 - TWENTY_YEARS); - /* Can't get nanoseconds with just a seconds counter. */ - ts->tv_nsec = 0; + rtc_time64_to_tm(t, tm); + + return 0; } /** @@ -54,10 +58,11 @@ static void aica_rtc_gettimeofday(struct timespec *ts) * * Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter. */ -static int aica_rtc_settimeofday(const time_t secs) +static int aica_rtc_settimeofday(struct device *dev, struct rtc_time *tm) { unsigned long val1, val2; - unsigned long adj = secs + TWENTY_YEARS; + time64_t secs = rtc_tm_to_time64(tm); + u32 adj = secs + TWENTY_YEARS; do { __raw_writel((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H); @@ -73,9 +78,19 @@ static int aica_rtc_settimeofday(const time_t secs) return 0; } -void aica_time_init(void) +static const struct rtc_class_ops rtc_generic_ops = { + .read_time = aica_rtc_gettimeofday, + .set_time = aica_rtc_settimeofday, +}; + +static int __init aica_time_init(void) { - rtc_sh_get_time = aica_rtc_gettimeofday; - rtc_sh_set_time = aica_rtc_settimeofday; -} + struct platform_device *pdev; + + pdev = platform_device_register_data(NULL, "rtc-generic", -1, + &rtc_generic_ops, + sizeof(rtc_generic_ops)); + return PTR_ERR_OR_ZERO(pdev); +} +arch_initcall(aica_time_init); diff --git a/arch/sh/boards/mach-dreamcast/setup.c b/arch/sh/boards/mach-dreamcast/setup.c index ad1a4db72e04..672c2ad8f8d5 100644 --- a/arch/sh/boards/mach-dreamcast/setup.c +++ b/arch/sh/boards/mach-dreamcast/setup.c @@ -30,7 +30,6 @@ static void __init dreamcast_setup(char **cmdline_p) { - board_time_init = aica_time_init; } static struct sh_machine_vector mv_dreamcast __initmv = { diff --git a/arch/sh/configs/dreamcast_defconfig b/arch/sh/configs/dreamcast_defconfig index 3f08dc54480b..1d27666c029f 100644 --- a/arch/sh/configs/dreamcast_defconfig +++ b/arch/sh/configs/dreamcast_defconfig @@ -70,3 +70,5 @@ CONFIG_PROC_KCORE=y CONFIG_TMPFS=y CONFIG_HUGETLBFS=y # CONFIG_CRYPTO_ANSI_CPRNG is not set +CONFIG_RTC_CLASS=y +CONFIG_RTC_DRV_GENERIC=y diff --git a/arch/sh/include/mach-dreamcast/mach/sysasic.h b/arch/sh/include/mach-dreamcast/mach/sysasic.h index 58f710e1ebc2..59effd1ed3e1 100644 --- a/arch/sh/include/mach-dreamcast/mach/sysasic.h +++ b/arch/sh/include/mach-dreamcast/mach/sysasic.h @@ -42,7 +42,6 @@ /* arch/sh/boards/mach-dreamcast/irq.c */ extern int systemasic_irq_demux(int); extern void systemasic_irq_init(void); -extern void aica_time_init(void); #endif /* __ASM_SH_DREAMCAST_SYSASIC_H */