From patchwork Tue Jul 17 11:24:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 142129 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3530729ljj; Tue, 17 Jul 2018 04:25:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfymFPLefyLXr1s3UPlxAveEC/4ge5uAgH8hx37gfiXv1/UGJ5ifXghCvaU+G2K7DbSuV8J X-Received: by 2002:a63:67c3:: with SMTP id b186-v6mr1222005pgc.5.1531826717813; Tue, 17 Jul 2018 04:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826717; cv=none; d=google.com; s=arc-20160816; b=oLnhCaCXojiq/vEaHOTk7ZTreghG+MbBfFEukfhQcCyA90D4huWzr9b25bo/p0hniI Z09TehmYCKx0KsA7VqOzcMSDSO0kYvk3z4TjBfxmoAaOOGti64iT7JlBxPlr+LM8evpZ NOY4MhtZ98y09r4+s8p5Pon52EEKEamkUWFXkjzSL52fNxVj5uNZ9y/MUesuvTTTyvHa x70i8cwYxb9o9UEeLlP3+AM0PCBn9uVOkS6BeCeVije4y6yu1wXDsJrrpnd+OYEpnKZr nf38ThFT4PFfXLMoq3ZiyttYa9rD+jCdTQi8TQshYJwkf6xgbmrb5EWDFCEnrVqV7Br7 KrFQ== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=PTtFId+Y0EEs5+cllmvrMc/Z4BBjEeLBQmZE8Amw2Fs=; b=QrbeuxDlGDydV5uEpWc0AGh4OSlANcrKJQojU5guGkcUq+dXfiy25mTbzwWp/+UfR6 KkO5kvIUCW+Myq/TRqCqO56/fzSXAPIjQUkepVZ91SESBf6Vu6xUMbHYhffowlcw1c6j THnLyDjJ+NKksjYjpFSdv50RmDuEWzhPDRJI9UxIwHPanNlVMWOsMbHrUG8t8MVHeKXQ 6IOcaOPsKVRAYYzGwjsdaxFoiSW9eyWM2mnyU0P5VMDsYZGueT4u1bdx8ykp4R4XYdKh RgcTcfvEjJ453Yb580Blwne1cGrkNFs7iTfUCjEXObLwlRWkOoSzsSLiTo/SQNf9j97q YJUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JOZmj5tu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8-v6si745573pgs.324.2018.07.17.04.25.17; Tue, 17 Jul 2018 04:25:17 -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; dkim=pass header.i=@linaro.org header.s=google header.b=JOZmj5tu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731431AbeGQL5Z (ORCPT + 31 others); Tue, 17 Jul 2018 07:57:25 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36066 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731256AbeGQL5Y (ORCPT ); Tue, 17 Jul 2018 07:57:24 -0400 Received: by mail-pf0-f196.google.com with SMTP id d14-v6so365959pfo.3 for ; Tue, 17 Jul 2018 04:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=PTtFId+Y0EEs5+cllmvrMc/Z4BBjEeLBQmZE8Amw2Fs=; b=JOZmj5tuLw2cxLCnpI93zZTUwIZv+Z6685Ga82IC6HSk74uIe9xTOqwuzOyXsLSjou fsmqRX7gwVUtXjilC31ujon5hxjxqfgB2ixE9ovqN0eT30OQPGbs1Fkgq35QPrRq4bJH TpSOMbdHUxnKMGuMWbEN7UnGEGRSCyN2EVND0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=PTtFId+Y0EEs5+cllmvrMc/Z4BBjEeLBQmZE8Amw2Fs=; b=s45kG2OP69UDic/H6eOVX+GNV3mQTW3Jv8MBzb1GJA0lFAVtbOwPT0kDyEMd8kxLQf abQijsMU99M70KjGtJbxb09GDNjeBhpmMSFeRxX88pzZ+8ZxgBHkXFpJvgcl8lQrdMJW oWLFEDfO/+kRhqw6G68eAGwN7f+KWEQ7RqrJFdRQ44txSGe1i3OrJ7Jm9qg+z3JtcUdU caWYa1SRbLSC/W+qEBUAsT5dwRpQKT80lEBBcLdVrIIGORUObZjfBatahMoog4A0ygRe hT86Vu7fwnG0EoDP8CMeEsEpZATT3bIthxYnrJnPAYd9EEAbKAxzgpoZJ0CriLGEvwrD fIeA== X-Gm-Message-State: AOUpUlGzKI2eZXS8Jy6z0v+bmk44xxwX/nSec3xCYSmXIe3i9w3DweM8 d2s/09rjSfxavtYyQPBBOQK9XQ== X-Received: by 2002:a65:614a:: with SMTP id o10-v6mr1151025pgv.387.1531826713954; Tue, 17 Jul 2018 04:25:13 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id y3-v6sm1391207pge.29.2018.07.17.04.25.11 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jul 2018 04:25:13 -0700 (PDT) From: Baolin Wang To: ysato@users.sourceforge.jp, dalias@libc.org, corbet@lwn.net Cc: baolin.wang@linaro.org, arnd@arndb.de, broonie@kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH 2/4] sh: sh03: rtc: push down rtc class ops into driver Date: Tue, 17 Jul 2018 19:24:25 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann 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 Signed-off-by: Baolin Wang --- 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(-) -- 1.7.9.5 diff --git a/arch/sh/boards/mach-sh03/Makefile b/arch/sh/boards/mach-sh03/Makefile index 400306a..47007a3 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 dc3d50e..8b23ed7 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 85e7059..3901b60 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 @@ static int __init sh03_devices_setup(void) 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 2156223..489ffdf 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