From patchwork Fri Dec 7 13:48:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 153159 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp522131ljp; Fri, 7 Dec 2018 05:50:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/VghQcbzUvkVEeK2qD/0xrvD5TiE/07TJ1TCSv7mt1+3lvGZ8hiCk6MniggPlEoVmcMr5b8 X-Received: by 2002:a17:902:bd46:: with SMTP id b6mr2177137plx.231.1544190610005; Fri, 07 Dec 2018 05:50:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544190609; cv=none; d=google.com; s=arc-20160816; b=joXmvHHkHtkGMMkr1LEdB8+kVQBUivhqZdVMd4jCZ1F9YiRYv9Re0N1LJZRX67hIpL oWpuRB7P2mrl5A2DP+1+dvuWJWbitqkA/7vRBtFncqSUX7SyHs7EyMebXBcrhfOgq4o3 WnYQpnXELnKAzwsM8pUHJNVU6Rg+FwWiju44cbG1tbW2mrJ/Wb5pKsLufzWAMBNXHbS3 E66JMwDrTNJPEypwU5gQ//wf+l/KDUbC8ReJgA2S1W+WVcYTGKlKEeaANgK2nTidhi1T JClYn9nlltdnnOpJBGLhu2eWajrwzlVVhFPEJTH8zZX64tjJW8u2djgwuMbhtqwADAby HCKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=QFtiX/dPbNH5sJ8noK8cQLqDO4F+yvANdQqWBdQZ2sU=; b=FPUQxc6tZk3M6DzhnoOHk1LfEiRbjHnQIinNJryFpfGaNvhfmMdBFTtVjKFqnAJs1K Q8wINfKYHVtvP9cain4OuhSSCfrxNLswLrrxlx2kqHfk3XM4VIvZrlJ/Nx1CQ7pjamHb XKRdTOPsUtgHUAPHWbZw4uULsDAI0POMH9wLQlEINcSkOOjSDCHge4mFrVl1RKqVABgs div2kjIT7M7PTvSJF6XuymEuRWCONwWn3MlEE5ETIRhy1Wl+OBVaGsuXyggHl79cgTgi mdgzgL6N3c2Tdcgf+GYiLhNkufuFyn10b2YxLuScNs5lUAl1Yv5b5txDJgzQ/tTfQ7r1 nGuw== 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 76si3309264pfw.66.2018.12.07.05.50.09; Fri, 07 Dec 2018 05:50:09 -0800 (PST) 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 S1726227AbeLGNuH (ORCPT + 31 others); Fri, 7 Dec 2018 08:50:07 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:54789 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeLGNt0 (ORCPT ); Fri, 7 Dec 2018 08:49:26 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1MjjOl-1hAsiW0a0R-00lGqH; Fri, 07 Dec 2018 14:48:59 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-sh@vger.kernel.org, Baolin Wang , Andrew Morton , John Stultz , Alexander Viro , Thomas Gleixner , Rich Felker , Yoshinori Sato , Arnd Bergmann Subject: [PATCH 2/8] sh: sh03: rtc: push down rtc class ops into driver Date: Fri, 7 Dec 2018 14:48:18 +0100 Message-Id: <20181207134824.300024-3-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181207134824.300024-1-arnd@arndb.de> References: <20181207134824.300024-1-arnd@arndb.de> X-Provags-ID: V03:K1:tJmSj16kgzkEh+PiEE6u2e5OJ6CVxUnOP9y0L0ftlO7hoGjRl5J lf/sG53Ec1SwTov/pEjsL3u6qgtvkD1SFhPo6ri7XKDMsj06AsZiJ6YMGrjKwGjNY6OAkJu PxCT6gxO16XV57bdcY3hquOkAr3Noc+zqviCKZ3eU1x1y51X5ZbGMsuYjmsKJeqRj8gt/tR 4YuQQwatbWiqUQGVZQGUA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:WhaprctODx8=:U06puf8uqc/q8hnSWJZQYt ksDyox36bYVHeRLWq3hfejrWhAsKsqFn83jZvOOoK0UYDdvegewkBtRiw8yZOBVrlXV1NPsvO nPrMlTRcoMQjPbXJ1dQtXLdos+t7vj7FhcJl9EpFiHA/eigLqyjBInO1dV8MUqZZKaXLmFrbw nOTWKj/ZMAdoPd4cdRE+7+5cUelk1MqpAnu/pk+QxSgOJITh1Zmt4dkLE0+kAKSn5pj1XGQBI cO9VHYdBKuvkeznpfnVAOrr288FwiMoQPImHO2vW6FcTNpp9Aw372/Kiyndu/tMcNbfySKGep /2v2UPSZc/ESCvgt4csy5m5wJs4vNPLcPaEFuIJIIDiAs+dnvuP/BGrZMwui5md9EIttQkPV/ kjUXPN+25YVmen7ssDz0Q0VVN6xs7kjyu/y0vFqgXnoTVG63yuk0PrGiQpyMbazUEan6AflEM rBOzBH5J3wdaDsVSafBnvWTb1yHY29fGowP0r+2HblwfPTCoOG2h1jpTPOy12ZeHNju8gJhN4 tcdpeHLvJy0uxazyQCd2XzgHTXgWC3NAuLznr/lM5MyAORjOJxhdtQa20gVGQcHzCXTJ8W4Av N5LwEi1PfzdAbDfLeK6/1bbutdOw0N+TWCxBmnK/VAYXSQXkRa+YqcykbUZ/KiscYF+ZNjoRo ycMLhOCAfXv+AFnwmpKoesZZLnM7m4YVgbsWh0U3x1tMwc65Iz+WowYGePr53OBkP3BnC5su7 BH54wpCGHUbbSP0mbHHkUHYlURkud9SgOnM0pA== 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. By removing the indirection and always using the RTC_CLASS interface, we can avoid the lossy double conversion between rtc_time and timespec, so we end up supporting the entire range of 'year' values, and clarifying the rtc_set_time callback. I did not change the behavior of sh03_rtc_settimeofday(), which keeps just updating the seconds/minutes by calling set_rtc_mmss(), this could be improved if anyone cares. Also, the file should ideally be moved into drivers/rtc and not use rtc-generic. Signed-off-by: Arnd Bergmann --- arch/sh/boards/mach-sh03/Makefile | 3 +- arch/sh/boards/mach-sh03/rtc.c | 51 +++++++++++++++++++------------ arch/sh/boards/mach-sh03/setup.c | 9 ------ arch/sh/configs/sh03_defconfig | 2 ++ 4 files changed, 35 insertions(+), 30 deletions(-) -- 2.18.0 diff --git a/arch/sh/boards/mach-sh03/Makefile b/arch/sh/boards/mach-sh03/Makefile index 400306a796ec..47007a3a2fc8 100644 --- a/arch/sh/boards/mach-sh03/Makefile +++ b/arch/sh/boards/mach-sh03/Makefile @@ -2,4 +2,5 @@ # Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel # -obj-y := setup.o rtc.o +obj-y := setup.o +obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o diff --git a/arch/sh/boards/mach-sh03/rtc.c b/arch/sh/boards/mach-sh03/rtc.c index dc3d50e3b7a2..8b23ed7c201c 100644 --- a/arch/sh/boards/mach-sh03/rtc.c +++ b/arch/sh/boards/mach-sh03/rtc.c @@ -13,8 +13,9 @@ #include #include #include -#include -#include +#include +#include +#include #define RTC_BASE 0xb0000000 #define RTC_SEC1 (RTC_BASE + 0) @@ -38,7 +39,7 @@ static DEFINE_SPINLOCK(sh03_rtc_lock); -unsigned long get_cmos_time(void) +static int sh03_rtc_gettimeofday(struct device *dev, struct rtc_time *tm) { unsigned int year, mon, day, hour, min, sec; @@ -75,17 +76,18 @@ unsigned long get_cmos_time(void) } spin_unlock(&sh03_rtc_lock); - return mktime(year, mon, day, hour, min, sec); -} -void sh03_rtc_gettimeofday(struct timespec *tv) -{ + tm->tm_sec = sec; + tm->tm_min = min; + tm->tm_hour = hour; + tm->tm_mday = day; + tm->tm_mon = mon; + tm->tm_year = year - 1900; - tv->tv_sec = get_cmos_time(); - tv->tv_nsec = 0; + return 0; } -static int set_rtc_mmss(unsigned long nowtime) +static int set_rtc_mmss(struct rtc_time *tm) { int retval = 0; int real_seconds, real_minutes, cmos_minutes; @@ -97,8 +99,8 @@ static int set_rtc_mmss(unsigned long nowtime) if (!(__raw_readb(RTC_CTL) & RTC_BUSY)) break; cmos_minutes = (__raw_readb(RTC_MIN1) & 0xf) + (__raw_readb(RTC_MIN10) & 0xf) * 10; - real_seconds = nowtime % 60; - real_minutes = nowtime / 60; + real_seconds = tm->tm_sec; + real_minutes = tm->tm_min; if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) real_minutes += 30; /* correct for half hour time zone */ real_minutes %= 60; @@ -112,22 +114,31 @@ static int set_rtc_mmss(unsigned long nowtime) printk_once(KERN_NOTICE "set_rtc_mmss: can't update from %d to %d\n", cmos_minutes, real_minutes); - retval = -1; + retval = -EINVAL; } spin_unlock(&sh03_rtc_lock); return retval; } -int sh03_rtc_settimeofday(const time_t secs) +int sh03_rtc_settimeofday(struct device *dev, struct rtc_time *tm) { - unsigned long nowtime = secs; - - return set_rtc_mmss(nowtime); + return set_rtc_mmss(tm); } -void sh03_time_init(void) +static const struct rtc_class_ops rtc_generic_ops = { + .read_time = sh03_rtc_gettimeofday, + .set_time = sh03_rtc_settimeofday, +}; + +static int __init sh03_time_init(void) { - rtc_sh_get_time = sh03_rtc_gettimeofday; - rtc_sh_set_time = sh03_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(sh03_time_init); diff --git a/arch/sh/boards/mach-sh03/setup.c b/arch/sh/boards/mach-sh03/setup.c index 85e7059a77e9..3901b6031ad5 100644 --- a/arch/sh/boards/mach-sh03/setup.c +++ b/arch/sh/boards/mach-sh03/setup.c @@ -22,14 +22,6 @@ static void __init init_sh03_IRQ(void) plat_irq_setup_pins(IRQ_MODE_IRQ); } -/* arch/sh/boards/sh03/rtc.c */ -void sh03_time_init(void); - -static void __init sh03_setup(char **cmdline_p) -{ - board_time_init = sh03_time_init; -} - static struct resource cf_ide_resources[] = { [0] = { .start = 0x1f0, @@ -101,6 +93,5 @@ device_initcall(sh03_devices_setup); static struct sh_machine_vector mv_sh03 __initmv = { .mv_name = "Interface (CTP/PCI-SH03)", - .mv_setup = sh03_setup, .mv_init_irq = init_sh03_IRQ, }; diff --git a/arch/sh/configs/sh03_defconfig b/arch/sh/configs/sh03_defconfig index 2156223405a1..489ffdfb1517 100644 --- a/arch/sh/configs/sh03_defconfig +++ b/arch/sh/configs/sh03_defconfig @@ -130,3 +130,5 @@ CONFIG_CRYPTO_SHA1=y CONFIG_CRYPTO_DEFLATE=y # CONFIG_CRYPTO_ANSI_CPRNG is not set CONFIG_CRC_CCITT=y +CONFIG_RTC_CLASS=y +CONFIG_RTC_DRV_GENERIC=y