From patchwork Mon Sep 23 10:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13809457 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 710B8CF9C5B for ; Mon, 23 Sep 2024 10:02:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6rolbVD9IITwU8QeI5jrElmhIDPAa1liHNorfNCxAH8=; b=1FCn5cfvQpuHTZXzrsmjS/AXad I9ziMdqyvCoaMWHwGNGwMbPEUHgHR6U+P31Q4TdF/l4mTOE/d0x+yImvMF5ZCyMNgTmssCAmKwMhW HjeGZKUzT9hhcPOBbzDulM0f7W2Adb+voWGZ77G8oHWie0bZUtmmbc2E8xv3CLlf1jtlPxVdUR8jB 3ayZCAXAKNwEWy7gti63GymMukilTNtIRl3rjp0LmaJapgEYUKHTLbyS9OFCtD8pLIp1Ns4sf/AC0 hMZrECrHm9p7KE+tARzk9ENlFFG2GXQ6RkNEwDqsNN+9zIYdA0BitLzt+LEcNXfRHmyfDO7f+GHU8 hNCSYfPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssftq-0000000GuHv-0S1P; Mon, 23 Sep 2024 10:02:34 +0000 Received: from bali.collaboradmins.com ([148.251.105.195]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssfrb-0000000Gttj-2xHA; Mon, 23 Sep 2024 10:00:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1727085614; bh=7ECwv49t0WFiAx3RhC+fh1v+7w6XzbPg4STX+u9qe/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HAIVGcXgONpShgBWkyfL+ym8Jj4ookW2rEdYeDNvI+hsmFDEuKbmTVhk3gZsR6VwX oH/dC78n3lvf/ujs52/q8fZtEW1QxndWkKDEipAyUqgf13JdfBUFyDDqsxTF8gOlcx gSJj0a5oIGFTz9ATPhpVSyHaMU/HFAhxRecFGwwWFlP2bhrbBnifjHhXAK4RCwhAdo ejvAEfKZ/iyj4mYOPmoUMaqFPMGznqPkNSQjWO02LrbqcZZNL3yrQ/vJis6rjbjEZK 978tgdjkz4D6e5d8FPNz0aF1TuCp6vMIpIDDdFSYsIS1bfChzpk4xDie1ODWRvWhkq Cr1IpRs3Hmcrw== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id 55AB217E10AE; Mon, 23 Sep 2024 12:00:13 +0200 (CEST) From: AngeloGioacchino Del Regno To: lee@kernel.org Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, eddie.huang@mediatek.com, sean.wang@mediatek.com, alexandre.belloni@bootlin.com, sen.chu@mediatek.com, macpaul.lin@mediatek.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-rtc@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 1/3] dt-bindings: mfd: mediatek: mt6397: Add start-year property to RTC Date: Mon, 23 Sep 2024 12:00:08 +0200 Message-ID: <20240923100010.97470-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923100010.97470-1-angelogioacchino.delregno@collabora.com> References: <20240923100010.97470-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240923_030016_158930_15E0BB56 X-CRM114-Status: UNSURE ( 8.08 ) X-CRM114-Notice: Please train this message. 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 Enable evaluating the start-year property to allow shifting the RTC's HW range. Signed-off-by: AngeloGioacchino Del Regno Acked-by: Conor Dooley --- Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml b/Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml index 953358bc997a..a83cc35f51f1 100644 --- a/Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml +++ b/Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml @@ -71,6 +71,8 @@ properties: - mediatek,mt6366-rtc - const: mediatek,mt6358-rtc + start-year: true + required: - compatible From patchwork Mon Sep 23 10:00:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13809458 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 44C92CF9C6F for ; Mon, 23 Sep 2024 10:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7QIDGBJkxcmnvPA7pNjWrrUjxxIBOBco1l2oo2/sTnQ=; b=e1EZRcyFKNv36S/aHD782kNVdO QkOdXihOB7m8FuJqdWAGv3gK7p7KiTpzD8cBGbY+Gh0Q5o9EMFBddlqMSu6RBy+20j2ppXOAIQTsN REtTVPINIne5AlwYz2hllkzXJ7qa0cq1yKyT9tYeaOW/AnxS/FXdY1M9Y1hNbB8lyg3wJqzDJjPIr np1vExTGRO37daVxPf6jg4LvqHxzNSq+FnNHPtQJcYw0xKREr+LukE8yD2sUUe8R+CmWD2aY7IsTH KsGL6a5kiwhEFjDeK5JtyrpKOaLK+JonQ6HwL3+chYxgXG4AzhXBArIlHkQZWzeFOknblN9Y455p1 tWvMWetw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssfuu-0000000GuQG-2uwa; Mon, 23 Sep 2024 10:03:40 +0000 Received: from bali.collaboradmins.com ([148.251.105.195]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssfrc-0000000Gttm-0kQG; Mon, 23 Sep 2024 10:00:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1727085614; bh=YrvCOBRllTDZcvuPynXFN1lDKpyxG284BO/X9CnemNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h8Jax48P/c+QVuNQ6JkqF+x+nTEam9eaf+PQGnzo4bF0PAqJ+6UhtwoOaeJtaijvd z5Gsq1lzk2b+jBztRd9rDFQP96QEUVNMjJ5iODjPnRTm+lVV9YrdcxJJ6uvg6ESYWk 9XritmaOw2DS1cIuPEyPV05crKdkYhtNQWCvv/DyCTDUmyKoj3SCaOXjgd5kOoOKf4 LlUbRDDj2kMAPlmM6Ys9DwH1S08kIDBhhKq4HZp+t4ly7rYXCGQxdM33d9c0Tz3qjw HUYtQ9IRruDe2usZXAO21mMRxoB9KjOJ3ZXlV4vxNm2PqJYOweMToni3Gvg6LSY7TC l4GjVjxIJ0g7A== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id 28C1817E10D3; Mon, 23 Sep 2024 12:00:14 +0200 (CEST) From: AngeloGioacchino Del Regno To: lee@kernel.org Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, eddie.huang@mediatek.com, sean.wang@mediatek.com, alexandre.belloni@bootlin.com, sen.chu@mediatek.com, macpaul.lin@mediatek.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-rtc@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 2/3] rtc: mt6359: Add RTC hardware range and add support for start-year Date: Mon, 23 Sep 2024 12:00:09 +0200 Message-ID: <20240923100010.97470-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923100010.97470-1-angelogioacchino.delregno@collabora.com> References: <20240923100010.97470-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240923_030016_388101_F9D4034B X-CRM114-Status: GOOD ( 14.59 ) 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 Add the RTC hardware range parameters to enable the possibility of using the `start-year` devicetree property which, if present, will set the start_secs parameter by overriding the defaults that this driver is setting; To keep compatibility with (hence have the same date/time reading as) the old behavior, set: - range_min to 1900-01-01 00:00:00 - range_max to 2027-12-31 23:59:59 (HW year max range is 0-127) - start_secs defaulting to 1968-01-02 00:00:00 Please note that the oddness of starting from January 2nd is not a hardware quirk and it's done only to get the same date/time reading as an RTC which time was set before this commit. Also remove the RTC_MIN_YEAR_OFFSET addition and subtraction in callbacks set_time() and read_time() respectively, as now this is already done by the API. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Macpaul Lin Reviewed-by: ZhanZhan Ge --- drivers/rtc/rtc-mt6397.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index 1617063669cc..4785af123a7f 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -96,12 +96,6 @@ static int mtk_rtc_read_time(struct device *dev, struct rtc_time *tm) goto exit; } while (sec < tm->tm_sec); - /* HW register use 7 bits to store year data, minus - * RTC_MIN_YEAR_OFFSET before write year data to register, and plus - * RTC_MIN_YEAR_OFFSET back after read year from register - */ - tm->tm_year += RTC_MIN_YEAR_OFFSET; - /* HW register start mon from one, but tm_mon start from zero. */ tm->tm_mon--; time = rtc_tm_to_time64(tm); @@ -122,7 +116,6 @@ static int mtk_rtc_set_time(struct device *dev, struct rtc_time *tm) int ret; u16 data[RTC_OFFSET_COUNT]; - tm->tm_year -= RTC_MIN_YEAR_OFFSET; tm->tm_mon++; data[RTC_OFFSET_SEC] = tm->tm_sec; @@ -178,7 +171,6 @@ static int mtk_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_AL_MTH_MASK; tm->tm_year = data[RTC_OFFSET_YEAR] & RTC_AL_YEA_MASK; - tm->tm_year += RTC_MIN_YEAR_OFFSET; tm->tm_mon--; return 0; @@ -194,7 +186,6 @@ static int mtk_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) int ret; u16 data[RTC_OFFSET_COUNT]; - tm->tm_year -= RTC_MIN_YEAR_OFFSET; tm->tm_mon++; mutex_lock(&rtc->lock); @@ -302,6 +293,10 @@ static int mtk_rtc_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); rtc->rtc_dev->ops = &mtk_rtc_ops; + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; + rtc->rtc_dev->range_max = mktime64(2027, 12, 31, 23, 59, 59); + rtc->rtc_dev->start_secs = mktime64(1968, 1, 2, 0, 0, 0); + rtc->rtc_dev->set_start_time = true; return devm_rtc_register_device(rtc->rtc_dev); } From patchwork Mon Sep 23 10:00:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13809471 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 BD23CCF9C5B for ; Mon, 23 Sep 2024 10:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kgtwzFUdDnqEt9tDok1Z/6+uIxyAjbmhq9j5ECJ0Lfc=; b=1DRJbojBXw0SwH3beHK9yQJiSk ZwPG2TNcUKKE8+hA6cc4rVeA9Y5/MIP7ulkZiHgK4wSqNuK/04H/DxFaJSvKkMjEWC0ocWnRSZLQA rzKuI3OuuFcpQbJr8TfqvRvTasYsB/3o9kkzpdv3HtH3z+fJr+fxVZ603/qkdQjX7XKS6PQcaF4X3 14HqP4SKBbvxhiK8jHtuF9BCKCIy8ICIQKK3vNFljcSDoUKX8pawastA5qOPH2C7+xeMn399YnaHN CRo6CJCVYPjwOUXECFIkNEZPKdHnKf6BL5e2rU6e4B6DX169Km0Jpx590MxWTR9lOZBCr2YbxM0uD mkwo/47A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssfw1-0000000GubM-05wc; Mon, 23 Sep 2024 10:04:49 +0000 Received: from bali.collaboradmins.com ([2a01:4f8:201:9162::2]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssfrd-0000000Gtu4-01YC; Mon, 23 Sep 2024 10:00:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1727085615; bh=EVa8pFZK1Gg2RTP6+a6/2urfhYG5YFYSX1JAt7R4Yi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ih89HEvrjCdr+PhyTQoUw7wGQee/jfqo1S+wA+rutY1NkTRHoyBWrb7JUIxxbi6Pr og/QOh/P2Csh+mCIR2i6FJTlxhJ9Gap+3995bEtSzqkVNJg4hwF3NpfgvKWGh3aycB z/NTjbbx1nhKQg8a7G4MrdvnBetbeEfyhStNTE4CBQzOed66K+mpXdIix8KL69QFg5 Nh0Hr8IO1rhxfX6QFgYgodk1BXwz3tE7IBpfF3NX8fYzNhzPsqoN/HBU0V8S+fCNWo Kcj4U0Pj3CnuXleHU0ufRDowANlc9b+/gaeo0HnsIrAyN8vJ5V1VhyxjVud/oJufuL MxJBc+gzzplww== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id E93C217E10FC; Mon, 23 Sep 2024 12:00:14 +0200 (CEST) From: AngeloGioacchino Del Regno To: lee@kernel.org Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, eddie.huang@mediatek.com, sean.wang@mediatek.com, alexandre.belloni@bootlin.com, sen.chu@mediatek.com, macpaul.lin@mediatek.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-rtc@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 3/3] rtc: mt6359: Use RTC_TC_DOW hardware register for wday Date: Mon, 23 Sep 2024 12:00:10 +0200 Message-ID: <20240923100010.97470-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923100010.97470-1-angelogioacchino.delregno@collabora.com> References: <20240923100010.97470-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240923_030017_213057_C078E269 X-CRM114-Status: GOOD ( 13.23 ) 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 Instead of calculating the number of full days since Sunday with (days + 4) % 7, read (and write) that to the RTC Day-of-week Time Counter register (RTC_TC_DOW). Some transformation (addition and subtraction for set/get) is still done, as this register's range is [1..7], while the tm_wday in struct tm's range is [0..6]. Please note that this was added only to set_time() and read_time() callbacks because set_alarm() and read_alarm() are setting a bit in RTC_AL_MASK to ignore DOW for RTC HW alarms for unknown reasons. Signed-off-by: AngeloGioacchino Del Regno --- drivers/rtc/rtc-mt6397.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index 4785af123a7f..152699219a2b 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -75,6 +75,7 @@ static int __mtk_rtc_read_time(struct mt6397_rtc *rtc, tm->tm_min = data[RTC_OFFSET_MIN]; tm->tm_hour = data[RTC_OFFSET_HOUR]; tm->tm_mday = data[RTC_OFFSET_DOM]; + tm->tm_wday = data[RTC_OFFSET_DOW]; tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_TC_MTH_MASK; tm->tm_year = data[RTC_OFFSET_YEAR]; @@ -86,9 +87,8 @@ static int __mtk_rtc_read_time(struct mt6397_rtc *rtc, static int mtk_rtc_read_time(struct device *dev, struct rtc_time *tm) { - time64_t time; struct mt6397_rtc *rtc = dev_get_drvdata(dev); - int days, sec, ret; + int sec, ret; do { ret = __mtk_rtc_read_time(rtc, tm, &sec); @@ -96,15 +96,9 @@ static int mtk_rtc_read_time(struct device *dev, struct rtc_time *tm) goto exit; } while (sec < tm->tm_sec); - /* HW register start mon from one, but tm_mon start from zero. */ + /* HW register start mon/wday from one, but tm_mon/tm_wday start from zero. */ tm->tm_mon--; - time = rtc_tm_to_time64(tm); - - /* rtc_tm_to_time64 covert Gregorian date to seconds since - * 01-01-1970 00:00:00, and this date is Thursday. - */ - days = div_s64(time, 86400); - tm->tm_wday = (days + 4) % 7; + tm->tm_wday--; exit: return ret; @@ -117,11 +111,13 @@ static int mtk_rtc_set_time(struct device *dev, struct rtc_time *tm) u16 data[RTC_OFFSET_COUNT]; tm->tm_mon++; + tm->tm_wday++; data[RTC_OFFSET_SEC] = tm->tm_sec; data[RTC_OFFSET_MIN] = tm->tm_min; data[RTC_OFFSET_HOUR] = tm->tm_hour; data[RTC_OFFSET_DOM] = tm->tm_mday; + data[RTC_OFFSET_DOW] = tm->tm_wday; data[RTC_OFFSET_MTH] = tm->tm_mon; data[RTC_OFFSET_YEAR] = tm->tm_year;