Received: by 10.192.165.148 with SMTP id m20csp422721imm; Fri, 20 Apr 2018 08:55:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+YUF1BZysSpn6lOtHmLQOvCa5Ee7b3f8QC5FAHaekiS00vqpDtCfiOYQhfUetTXVOXcSb3 X-Received: by 10.98.106.193 with SMTP id f184mr10356739pfc.201.1524239733400; Fri, 20 Apr 2018 08:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524239733; cv=none; d=google.com; s=arc-20160816; b=BLjsVVHOZ8iaDNH/KO9CxwpN/R996maTL58ygLPJNMMWlRKzIo2iF82d0UZ39EkQTD hBKh3rl5givDVi8qZ1VQroBqp59dG6D13mNQNor9vvse4fxt9ht68C5ZZroxEdRCfxUE 8bJmYbspoPaygL8XPGjBVA35wOKprTkCUMSoLlXu2+EtzpQUI3Em+C80hOKnx25uNpcY 6h9Cv0FK5J8HnlrKOmBQOkvePKYbGdIfHWXHp26nY1mB9oN7tC1rXmoO5NSF84DDX6tY teAVjG2PIFjnyA5d/zN3XspalB4qz9r3DKoBwf/zCrwcyet4aLG5cM/r02N4Yy3IMF8a Pzrg== 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:arc-authentication-results; bh=EsK6LyzV0fr0aDJFTBiFQ02SHTd19QbRHmO0j5rKt0o=; b=LUiaA16uoqkdlN5yXsSZyYs6CPVX0Gaf4LyC/dsAv8FIZTdoEqRr5BdWd0UPzziVt7 FIVHQtuDv3PCkKIqE3y+ciAT2vDfRoroTMQZT6YGPBTxvUbK9cVBXAEHx+KO/JpEeBAa pWvGVo0rjP4R1aPuHIuTvNxDdrP/WS+KpktveaKsQopwDazz+tcUouIKVmWUhy6lmC54 QrWNufteU9RZVmngcTe6x4SlKEl9C7UUzImX/TaD0J+HFgARd6OLO0yplvLyOuydeaH6 DkkBtrwpSu9RmdRPmiCVvi9a77BHuqe+NjhQy7uzqfM5jPr9ZizW4fnU0k/G3tXY8CP9 RFUA== 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 t14-v6si6138241plm.588.2018.04.20.08.54.49; Fri, 20 Apr 2018 08:55:33 -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 S1755911AbeDTPvJ (ORCPT + 99 others); Fri, 20 Apr 2018 11:51:09 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:53235 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755472AbeDTPvH (ORCPT ); Fri, 20 Apr 2018 11:51:07 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0MJYS7-1f74XF2lxL-0037kX; Fri, 20 Apr 2018 17:50:54 +0200 From: Arnd Bergmann To: Rich Felker Cc: Baolin Wang , Yoshinori Sato , linux-sh@vger.kernel.org, broonie@kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] sh: sh03: rtc: push down rtc class ops into driver Date: Fri, 20 Apr 2018 17:48:54 +0200 Message-Id: <20180420154933.3235131-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180420154933.3235131-1-arnd@arndb.de> References: <20180420154933.3235131-1-arnd@arndb.de> X-Provags-ID: V03:K1:1xeHnmiXMDG2DTaWNflZwqpgh543RPem6gKyN8LmpPBjRBn7EzH /gN++41156NmEPTyqkSWp3+TFLATbUJ0em9Gy415v+zji5vf6glGIncF85pl5brwKMTSPDZ KpELVTt9RM3b4ux1MvpoAY7K70IIxXX9Q5i6VYGWveTXORUwFjOh1RxdtbRcLK5NkXkuR13 6hAAdLZzqMa1RF03uJKZQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:vMx0ryBC2ls=:48s+U6voPXjmOWlQZOFwh2 hxkIpquGhB8Z9rO9USwEjdNN86btNQAgEVNFLmCSizVhd8dxL+nN2tkAyflOu+OXTjTxj2GQf ZUlYrvlKZNf4LWGMjzqs2R0PhZkNVgh7hwwnS8ckpA5V2X8SibiZcAu/h9UEeQ0qn4mI03yLp 8zcgJDWVIlKM67kmR7IcAUa3v3PNFLTshLnxFa69g33EkK+lvyYn0X5/BTNSl62+V5NURvxwD emKkzMT+he48WYORvVZsoy0t34rhcXTK6OXlaazEg1Jf6sFbmUqDaKp5wkyXwl0BI1Ku4V2pz 3tgasT8/vUWjoHprLhuIn10KPDaRVhckNmryvxhVDggvrj0pwz3CdX98gtfgDU7r/kbu4ttFv SHKi7TP4Ea2TEzwlOvyx8YVkCZ+QsD/0qCgtisYVEsf5oJBMPnIz9lTab/JntgUZv/Mn06wJR H/wA68fB5s18BWq/J8myhYa9LIq6Gt5YfcSBPs0hzuQFHSuhbul9EsuLDJG6hmsf7WGkfB6dy ot0wHHZ3FoWUly3Faw9G0NkI/yeE+rLaTcwaK+ljAstxwFxQrNPzNTBYw+EXHV/O5GubABjim B+uW8JB0tM8uRQ0LgbFlYCK9CJwoqvYpLoiy0sk6YSl7UOnxA9c6eAXOQKDGhjqIBBoNmTDn1 Sz96TQpYhA1O+uWvSbPQpPg9anW897T3BW7rbb2ZiWgq4Q6WDTnsbNMI+L9qniGUksqH2RjUj c0IncDigGRDIHecBOgszCTOwquQr7qRhjHPqug== 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(-) 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 -- 2.9.0