From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Sender: rtc-linux@googlegroups.com Received: from authsmtp.register.it (authsmtp77.register.it. [195.110.122.162]) by gmr-mx.google.com with ESMTPS id p199si12237wmd.1.2016.07.21.03.42.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Jul 2016 03:42:02 -0700 (PDT) From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= To: rtc-linux@googlegroups.com Cc: linux-kernel@vger.kernel.org, Alessandro Zummo , Alexandre Belloni , =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Subject: [rtc-linux] [PATCH 3/6] rtc: rv8803: Fix read day of week Date: Thu, 21 Jul 2016 12:41:29 +0200 Message-Id: <1469097692-103146-3-git-send-email-benoit@wsystem.com> In-Reply-To: <1469097692-103146-1-git-send-email-benoit@wsystem.com> References: <1469097692-103146-1-git-send-email-benoit@wsystem.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Reply-To: rtc-linux@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The Weekday register is encoded as 2^tm_wday, with tm_wday in 0..6, so using tm_wday =3D ffs(reg) to fill tm_wday from the register value is wrong because this gives the expected value + 1. This could be fixed as tm_wday =3D ffs(reg) - 1, but tm_wday =3D ilog2(reg) works as well and is more direct. Signed-off-by: Beno=C3=AEt Th=C3=A9baudeau --- drivers/rtc/rtc-rv8803.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c index e740c83..aa1d6b6 100644 --- a/drivers/rtc/rtc-rv8803.c +++ b/drivers/rtc/rtc-rv8803.c @@ -13,6 +13,7 @@ =20 #include #include +#include #include #include #include @@ -145,7 +146,7 @@ static int rv8803_get_time(struct device *dev, struct r= tc_time *tm) tm->tm_sec =3D bcd2bin(date[RV8803_SEC] & 0x7f); tm->tm_min =3D bcd2bin(date[RV8803_MIN] & 0x7f); tm->tm_hour =3D bcd2bin(date[RV8803_HOUR] & 0x3f); - tm->tm_wday =3D ffs(date[RV8803_WEEK] & 0x7f); + tm->tm_wday =3D ilog2(date[RV8803_WEEK] & 0x7f); tm->tm_mday =3D bcd2bin(date[RV8803_DAY] & 0x3f); tm->tm_mon =3D bcd2bin(date[RV8803_MONTH] & 0x1f) - 1; tm->tm_year =3D bcd2bin(date[RV8803_YEAR]) + 100; --=20 2.5.0 --=20 You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. ---=20 You received this message because you are subscribed to the Google Groups "= rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to rtc-linux+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752168AbcGUKrO (ORCPT ); Thu, 21 Jul 2016 06:47:14 -0400 Received: from authsmtp71.register.it ([195.110.101.55]:47718 "EHLO authsmtp.register.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751451AbcGUKrJ (ORCPT ); Thu, 21 Jul 2016 06:47:09 -0400 X-Greylist: delayed 305 seconds by postgrey-1.27 at vger.kernel.org; Thu, 21 Jul 2016 06:47:09 EDT X-Rid: benoit@wsystem.com@90.105.184.123 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= To: rtc-linux@googlegroups.com Cc: linux-kernel@vger.kernel.org, Alessandro Zummo , Alexandre Belloni , =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Subject: [PATCH 3/6] rtc: rv8803: Fix read day of week Date: Thu, 21 Jul 2016 12:41:29 +0200 Message-Id: <1469097692-103146-3-git-send-email-benoit@wsystem.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1469097692-103146-1-git-send-email-benoit@wsystem.com> References: <1469097692-103146-1-git-send-email-benoit@wsystem.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Weekday register is encoded as 2^tm_wday, with tm_wday in 0..6, so using tm_wday = ffs(reg) to fill tm_wday from the register value is wrong because this gives the expected value + 1. This could be fixed as tm_wday = ffs(reg) - 1, but tm_wday = ilog2(reg) works as well and is more direct. Signed-off-by: Benoît Thébaudeau --- drivers/rtc/rtc-rv8803.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c index e740c83..aa1d6b6 100644 --- a/drivers/rtc/rtc-rv8803.c +++ b/drivers/rtc/rtc-rv8803.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -145,7 +146,7 @@ static int rv8803_get_time(struct device *dev, struct rtc_time *tm) tm->tm_sec = bcd2bin(date[RV8803_SEC] & 0x7f); tm->tm_min = bcd2bin(date[RV8803_MIN] & 0x7f); tm->tm_hour = bcd2bin(date[RV8803_HOUR] & 0x3f); - tm->tm_wday = ffs(date[RV8803_WEEK] & 0x7f); + tm->tm_wday = ilog2(date[RV8803_WEEK] & 0x7f); tm->tm_mday = bcd2bin(date[RV8803_DAY] & 0x3f); tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1; tm->tm_year = bcd2bin(date[RV8803_YEAR]) + 100; -- 2.5.0