From patchwork Thu Apr 18 10:00:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF3t0YZHz9sBb for ; Thu, 18 Apr 2019 20:00:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388573AbfDRKA5 (ORCPT ); Thu, 18 Apr 2019 06:00:57 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:53437 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733049AbfDRKA4 (ORCPT ); Thu, 18 Apr 2019 06:00:56 -0400 X-Originating-IP: 109.212.207.226 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 5534A24001B; Thu, 18 Apr 2019 10:00:54 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 1/7] rtc: jz4740: set range Date: Thu, 18 Apr 2019 12:00:39 +0200 Message-Id: <20190418100045.29288-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org RTC_SEC is a 32-bit seconds counter. Signed-off-by: Alexandre Belloni Tested-by: Mathieu Malaterre --- drivers/rtc/rtc-jz4740.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index d0a891777f44..079469627bd7 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -348,10 +348,18 @@ static int jz4740_rtc_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); - rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, - &jz4740_rtc_ops, THIS_MODULE); + rtc->rtc = devm_rtc_allocate_device(&pdev->dev); if (IS_ERR(rtc->rtc)) { ret = PTR_ERR(rtc->rtc); + dev_err(&pdev->dev, "Failed to allocate rtc device: %d\n", ret); + return ret; + } + + rtc->rtc->ops = &jz4740_rtc_ops; + rtc->rtc->range_max = U32_MAX; + + ret = rtc_register_device(rtc->rtc); + if (ret) { dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); return ret; } From patchwork Thu Apr 18 10:00:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF4P4smZz9sBV for ; Thu, 18 Apr 2019 20:01:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388623AbfDRKA7 (ORCPT ); Thu, 18 Apr 2019 06:00:59 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:49451 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388577AbfDRKA6 (ORCPT ); Thu, 18 Apr 2019 06:00:58 -0400 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id B0936240005; Thu, 18 Apr 2019 10:00:55 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 2/7] rtc: jz4740: switch to rtc_time64_to_tm/rtc_tm_to_time64 Date: Thu, 18 Apr 2019 12:00:40 +0200 Message-Id: <20190418100045.29288-2-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190418100045.29288-1-alexandre.belloni@bootlin.com> References: <20190418100045.29288-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Call the 64bit versions of rtc_tm time conversion now that the range is enforced by the core. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 079469627bd7..15b6832f3931 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -171,7 +171,7 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) if (timeout == 0) return -EIO; - rtc_time_to_tm(secs, time); + rtc_time64_to_tm(secs, time); return 0; } @@ -196,7 +196,7 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE); alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF); - rtc_time_to_tm(secs, &alrm->time); + rtc_time64_to_tm(secs, &alrm->time); return rtc_valid_tm(&alrm->time); } @@ -205,9 +205,7 @@ static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) { int ret; struct jz4740_rtc *rtc = dev_get_drvdata(dev); - unsigned long secs; - - rtc_tm_to_time(&alrm->time, &secs); + unsigned long secs = rtc_tm_to_time64(&alrm->time); ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs); if (!ret) From patchwork Thu Apr 18 10:00:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF4N2vftz9sBb for ; Thu, 18 Apr 2019 20:01:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388647AbfDRKBD (ORCPT ); Thu, 18 Apr 2019 06:01:03 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:52783 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388577AbfDRKBC (ORCPT ); Thu, 18 Apr 2019 06:01:02 -0400 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 05B7C20001D; Thu, 18 Apr 2019 10:00:56 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 3/7] rtc: jz4740: remove useless check Date: Thu, 18 Apr 2019 12:00:41 +0200 Message-Id: <20190418100045.29288-3-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190418100045.29288-1-alexandre.belloni@bootlin.com> References: <20190418100045.29288-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org rtc_time64_to_tm always returns a valid tm, it is not necessary to validate it. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 15b6832f3931..a7e1a382cac5 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -198,7 +198,7 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) rtc_time64_to_tm(secs, &alrm->time); - return rtc_valid_tm(&alrm->time); + return 0; } static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) From patchwork Thu Apr 18 10:00:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF4L4JsBz9sBV for ; Thu, 18 Apr 2019 20:01:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388667AbfDRKBF (ORCPT ); Thu, 18 Apr 2019 06:01:05 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:43151 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388577AbfDRKBE (ORCPT ); Thu, 18 Apr 2019 06:01:04 -0400 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id B7C07240018; Thu, 18 Apr 2019 10:01:01 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 4/7] rtc: jz4740: use .set_time Date: Thu, 18 Apr 2019 12:00:42 +0200 Message-Id: <20190418100045.29288-4-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190418100045.29288-1-alexandre.belloni@bootlin.com> References: <20190418100045.29288-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Use .set_time instead of the deprecated .set_mmss. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index a7e1a382cac5..91ccb45bb886 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -176,11 +176,11 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) return 0; } -static int jz4740_rtc_set_mmss(struct device *dev, unsigned long secs) +static int jz4740_rtc_set_time(struct device *dev, struct rtc_time *time) { struct jz4740_rtc *rtc = dev_get_drvdata(dev); - return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, secs); + return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, rtc_tm_to_time64(time)); } static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) @@ -223,7 +223,7 @@ static int jz4740_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) static const struct rtc_class_ops jz4740_rtc_ops = { .read_time = jz4740_rtc_read_time, - .set_mmss = jz4740_rtc_set_mmss, + .set_time = jz4740_rtc_set_time, .read_alarm = jz4740_rtc_read_alarm, .set_alarm = jz4740_rtc_set_alarm, .alarm_irq_enable = jz4740_rtc_alarm_irq_enable, From patchwork Thu Apr 18 10:00:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF4K6NB5z9sBb for ; Thu, 18 Apr 2019 20:01:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388673AbfDRKBG (ORCPT ); Thu, 18 Apr 2019 06:01:06 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:49113 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388664AbfDRKBG (ORCPT ); Thu, 18 Apr 2019 06:01:06 -0400 X-Originating-IP: 109.212.207.226 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 27F5DFF808; Thu, 18 Apr 2019 10:01:04 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 5/7] rtc: jz4740: use dev_pm_set_wake_irq() to simplify code Date: Thu, 18 Apr 2019 12:00:43 +0200 Message-Id: <20190418100045.29288-5-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190418100045.29288-1-alexandre.belloni@bootlin.com> References: <20190418100045.29288-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Use dev_pm_set_wake_irq() to set the RTC as a wakeup source for suspend. This allows to remove the whole dev_pm_ops structure. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 91ccb45bb886..fa15ad9fbe13 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -346,6 +347,12 @@ static int jz4740_rtc_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); + ret = dev_pm_set_wake_irq(&pdev->dev, rtc->irq); + if (ret) { + dev_err(&pdev->dev, "Failed to set wake irq: %d\n", ret); + return ret; + } + rtc->rtc = devm_rtc_allocate_device(&pdev->dev); if (IS_ERR(rtc->rtc)) { ret = PTR_ERR(rtc->rtc); @@ -403,35 +410,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) return 0; } -#ifdef CONFIG_PM -static int jz4740_rtc_suspend(struct device *dev) -{ - struct jz4740_rtc *rtc = dev_get_drvdata(dev); - - if (device_may_wakeup(dev)) - enable_irq_wake(rtc->irq); - return 0; -} - -static int jz4740_rtc_resume(struct device *dev) -{ - struct jz4740_rtc *rtc = dev_get_drvdata(dev); - - if (device_may_wakeup(dev)) - disable_irq_wake(rtc->irq); - return 0; -} - -static const struct dev_pm_ops jz4740_pm_ops = { - .suspend = jz4740_rtc_suspend, - .resume = jz4740_rtc_resume, -}; -#define JZ4740_RTC_PM_OPS (&jz4740_pm_ops) - -#else -#define JZ4740_RTC_PM_OPS NULL -#endif /* CONFIG_PM */ - static const struct platform_device_id jz4740_rtc_ids[] = { { "jz4740-rtc", ID_JZ4740 }, { "jz4780-rtc", ID_JZ4780 }, @@ -443,7 +421,6 @@ static struct platform_driver jz4740_rtc_driver = { .probe = jz4740_rtc_probe, .driver = { .name = "jz4740-rtc", - .pm = JZ4740_RTC_PM_OPS, .of_match_table = of_match_ptr(jz4740_rtc_of_match), }, .id_table = jz4740_rtc_ids, From patchwork Thu Apr 18 10:00:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF4C6vg7z9sBp for ; Thu, 18 Apr 2019 20:01:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388664AbfDRKBJ (ORCPT ); Thu, 18 Apr 2019 06:01:09 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:37425 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388683AbfDRKBI (ORCPT ); Thu, 18 Apr 2019 06:01:08 -0400 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 8720C240015; Thu, 18 Apr 2019 10:01:05 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 6/7] rtc: jz4740: rework invalid time detection Date: Thu, 18 Apr 2019 12:00:44 +0200 Message-Id: <20190418100045.29288-6-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190418100045.29288-1-alexandre.belloni@bootlin.com> References: <20190418100045.29288-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The scratchpad register is used to detect an invalid time when power to the RTC has been lost. Instead of deleting that precious information and set the time to the UNIX epoch, forward it to userspace. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index fa15ad9fbe13..c9e16d857fa8 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -157,6 +157,9 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) uint32_t secs, secs2; int timeout = 5; + if (jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD) != 0x12345678) + return -EINVAL; + /* If the seconds register is read while it is updated, it can contain a * bogus value. This can be avoided by making sure that two consecutive * reads have the same value. @@ -180,8 +183,13 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) static int jz4740_rtc_set_time(struct device *dev, struct rtc_time *time) { struct jz4740_rtc *rtc = dev_get_drvdata(dev); + int ret; + + ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, rtc_tm_to_time64(time)); + if (ret) + return ret; - return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, rtc_tm_to_time64(time)); + return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678); } static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) @@ -308,7 +316,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) { int ret; struct jz4740_rtc *rtc; - uint32_t scratchpad; struct resource *mem; const struct platform_device_id *id = platform_get_device_id(pdev); const struct of_device_id *of_id = of_match_device( @@ -376,16 +383,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) return ret; } - scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD); - if (scratchpad != 0x12345678) { - ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678); - ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0); - if (ret) { - dev_err(&pdev->dev, "Could not write to RTC registers\n"); - return ret; - } - } - if (np && of_device_is_system_power_controller(np)) { if (!pm_power_off) { /* Default: 60ms */ From patchwork Thu Apr 18 10:00:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 1087487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44lF4J3CNFz9sBb for ; Thu, 18 Apr 2019 20:01:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388568AbfDRKBP (ORCPT ); Thu, 18 Apr 2019 06:01:15 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:35857 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388693AbfDRKBJ (ORCPT ); Thu, 18 Apr 2019 06:01:09 -0400 X-Originating-IP: 109.212.207.226 Received: from localhost (alyon-652-1-176-226.w109-212.abo.wanadoo.fr [109.212.207.226]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 1FD6CFF819; Thu, 18 Apr 2019 10:01:06 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Paul Cercueil , Mathieu Malaterre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 7/7] rtc: jz4740: convert to SPDX identifier Date: Thu, 18 Apr 2019 12:00:45 +0200 Message-Id: <20190418100045.29288-7-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190418100045.29288-1-alexandre.belloni@bootlin.com> References: <20190418100045.29288-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Use SPDX-License-Identifier instead of a verbose license text. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index c9e16d857fa8..0e95282df525 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2009-2010, Lars-Peter Clausen * Copyright (C) 2010, Paul Cercueil * JZ4740 SoC RTC driver - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 675 Mass Ave, Cambridge, MA 02139, USA. - * */ #include