From patchwork Mon Mar 20 21:21:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 13181865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B36AEC6FD1D for ; Mon, 20 Mar 2023 21:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wvFPsGsRhT7iIm0+22HHqWwTrG0AjWpEOK2ukxXl4fM=; b=Y72AFtU55fRwlz 0uUxJ1H78wO6IW72S+qWOIWHm7jV9Cx4cHfLWC4+rCDEyNnuITuX53GpwwmhwPacrd14it17GDIyd i35uoWpNslJl8ySiIwBUzRIyZIm4LtMJl+Ov5RehQuRSql0f7+Mz2SPt+ke6diCw/mE94GHKyRY88 kSL5ijaii3QQ23PSiQ7UEX8DW7nQFaYNgtN59pcgT+MBMnlMsneEmIvMuBzirEAJSpdWQDacS0fUp nx6whe/4qG6kaNaabcWSQnM34wrXFW/9Q6E4t6QgHF7RM5ZKD95AaAvohhmYWDkk9qZEcrRZbIuU7 IMMAPsWlaS2SKCG0CXGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peMxJ-00AWVv-31; Mon, 20 Mar 2023 21:22:13 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1peMxG-00AWTv-0k; Mon, 20 Mar 2023 21:22:11 +0000 Received: by mail-ed1-x530.google.com with SMTP id cn12so6608270edb.4; Mon, 20 Mar 2023 14:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; t=1679347321; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JKZyZ9UtP1ZZ748rC6wje4ZjvZJKdAV8kDbH4x8qqR8=; b=fOB38sbMMg7Xpl15jekHcEJ9v8TQ8siGqWnC9c3X7uj6+6zlhsGZjTasrkL8MsS8mC NRGmE3o6J9eIQBSoY/Gm/L5qD/B363AagucxmVfmmEUd4NG+LWtzX5lgzB0B5BaNCo6D RqxANucCnq42gDZoqhjJWauCKoNv4Te6+2Co4w9/vsVp2sD8kGip0qu4I93WUcc0vb8N cxda3Nf6t8vCHlinxft3VJmbJkthM8eynrqLX5zB44nYj4P8au3+4PHWVeiSVDP9WPqw mM6VEInnCGg/f0zR+rlARDJOkgIl/Uge9NZEZSPG53S+SeYuYn77fTekdIjEixoBYm/q r2SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679347321; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JKZyZ9UtP1ZZ748rC6wje4ZjvZJKdAV8kDbH4x8qqR8=; b=DLzWC7Td/xFnIZ/SmWPssK+P1hpwRr+dxCNyuX5JiUFslb3FIEQZT76dhuoP26wlc8 mJVdX1BOlMr9sIT65sytmwpSAu0LvUfG/uC1mi12pR/7RviQp/LfBQJ2sxMl82mSmAqF yw2hVIA8TPgunTuboMLgVDnOu10+24zXaxXsp5v3QvCUQAD3B012DEZGECW+EVnZNMdy 15qVHSn4rsPihyEbI2Nd4b4c9oI0oMiVnYN/r003uPdkVKtlsHMYyRJsAld3AFaC4HLp g6Y/EOuaQLXz059t+0Xamdw1XusMpyvmLjZjW/foeEyvYdkv5efCluWDWfICTOj9P/5v NwSA== X-Gm-Message-State: AO0yUKXVFOWNn/kxa/FDwBOcWTOyDYeVIfm4f4EEueXFVDNheefpMBtE UMReRa6NHKyy1XLBjsw35d4= X-Google-Smtp-Source: AK7set8AX5IQmx37Co1yuIMYxkdQKuukCk7qo9qZ3nFRwvxpknx1JxVBWM/utdYOKjq3h+SSzncEOw== X-Received: by 2002:a17:906:b845:b0:931:c6ba:8619 with SMTP id ga5-20020a170906b84500b00931c6ba8619mr495101ejb.72.1679347320677; Mon, 20 Mar 2023 14:22:00 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a01-0c22-73dd-8200-0000-0000-0000-0e63.c22.pool.telefonica.de. [2a01:c22:73dd:8200::e63]) by smtp.googlemail.com with ESMTPSA id j30-20020a508a9e000000b004af5968cb3bsm5346622edj.17.2023.03.20.14.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 14:22:00 -0700 (PDT) From: Martin Blumenstingl To: linux-rtc@vger.kernel.org, linux-amlogic@lists.infradead.org Cc: Alessandro Zummo , Alexandre Belloni , Neil Armstrong , Kevin Hilman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Blumenstingl Subject: [PATCH v1 RFC] rtc: meson-vrtc: Use ktime_get_real_ts64() to get the current time Date: Mon, 20 Mar 2023 22:21:42 +0100 Message-Id: <20230320212142.2355062-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230320_142210_286725_A1A93AF5 X-CRM114-Status: GOOD ( 16.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The VRTC alarm register can be programmed with an amount of seconds after which the SoC will be woken up by the VRTC timer again. We are already converting the alarm time from meson_vrtc_set_alarm() to "seconds since 1970". This means we also need to use "seconds since 1970" for the current time. This fixes a problem where setting the alarm to one minute in the future results in the firmware (which handles wakeup) to output (on the serial console) that the system will be woken up in billions of seconds. ktime_get_raw_ts64() returns the time since boot, not since 1970. Switch to ktime_get_real_ts64() to fix the calculation of the alarm time and to make the SoC wake up at the specified date/time. Also the firmware (which manages suspend) now prints either 59 or 60 seconds until wakeup (depending on how long it takes for the system to enter suspend). Fixes: 6ef35398e827 ("rtc: Add Amlogic Virtual Wake RTC") Signed-off-by: Martin Blumenstingl Reviewed-by: Kevin Hilman Reviewed-by: Neil Armstrong --- drivers/rtc/rtc-meson-vrtc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-meson-vrtc.c b/drivers/rtc/rtc-meson-vrtc.c index 1463c8621561..648fa362ec44 100644 --- a/drivers/rtc/rtc-meson-vrtc.c +++ b/drivers/rtc/rtc-meson-vrtc.c @@ -23,7 +23,7 @@ static int meson_vrtc_read_time(struct device *dev, struct rtc_time *tm) struct timespec64 time; dev_dbg(dev, "%s\n", __func__); - ktime_get_raw_ts64(&time); + ktime_get_real_ts64(&time); rtc_time64_to_tm(time.tv_sec, tm); return 0; @@ -96,7 +96,7 @@ static int __maybe_unused meson_vrtc_suspend(struct device *dev) long alarm_secs; struct timespec64 time; - ktime_get_raw_ts64(&time); + ktime_get_real_ts64(&time); local_time = time.tv_sec; dev_dbg(dev, "alarm_time = %lus, local_time=%lus\n",