mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <nobuhiro.iwamatsu.x90@mail.toshiba>
To: <fredrik.m.olsson@axis.com>, <alexandre.belloni@bootlin.com>,
	<robh@kernel.org>, <krzk+dt@kernel.org>, <conor+dt@kernel.org>
Cc: <linux-rtc@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <kernel@axis.com>
Subject: RE: [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130
Date: Wed, 24 Dec 2025 05:06:24 +0000	[thread overview]
Message-ID: <TY7PR01MB14818A301AD396B57AC28919FCDB2A@TY7PR01MB14818.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <20251219-ds1307-rx8901-add-v1-2-b13f346ebe93@axis.com>

Hi Fredrik,

> -----Original Message-----
> From: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> Sent: Friday, December 19, 2025 9:11 PM
> To: Alexandre Belloni <alexandre.belloni@bootlin.com>; Rob Herring
> <robh@kernel.org>; Krzysztof Kozlowski <krzk+dt@kernel.org>; Conor Dooley
> <conor+dt@kernel.org>; iwamatsu nobuhiro(岩松 信洋 □DITC○CPT)
> <nobuhiro.iwamatsu.x90@mail.toshiba>
> Cc: linux-rtc@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; Fredrik M Olsson <fredrik.m.olsson@axis.com>;
> kernel@axis.com
> Subject: [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130
> 
> The RTC represent each weekday with a individual bit set in the WDAY register,
> where the 0th bit represent the first day of the week and the 6th bit represents
> the last day of the week. For each passed day the chip performs a
> rotary-left-shift by one to advance the weekday by one.
> 
> The tm_wday field represent weekdays by a value in the range of 0-6.
> 
> The fls() function return the bit index of the last bit set. To handle when there
> are no bits set it will return 0, and if the 0th bit is set it will return 1, and if the
> 1st bit is set it will return 2, and so on.
> 
> In order to make the result of the fls() function fall into the expected range of
> 0-6 (instead of 1-7) this patch subtracts one from the result (which matches
> how the value is written in ds1307_set_time()).
> 
> Fixes: 204756f016726 ("rtc: ds1307: Fix wday settings for rx8130")
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>

Thanks for fixing.

Reviewed-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>

Best regards,
  Nobuhiro

> ---
>  drivers/rtc/rtc-ds1307.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index
> 7205c59ff729..bf42c250ea7d 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -308,7 +308,7 @@ static int ds1307_get_time(struct device *dev, struct
> rtc_time *t)
>  	t->tm_hour = bcd2bin(tmp);
>  	/* rx8130 is bit position, not BCD */
>  	if (ds1307->type == rx_8130)
> -		t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f);
> +		t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
>  	else
>  		t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
>  	t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f);
> 
> --
> 2.43.0


  reply	other threads:[~2025-12-24  6:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19 12:10 [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
2025-12-20  8:59   ` Krzysztof Kozlowski
2025-12-24  5:04   ` nobuhiro.iwamatsu.x90
2025-12-19 12:10 ` [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130 Fredrik M Olsson
2025-12-24  5:06   ` nobuhiro.iwamatsu.x90 [this message]
2025-12-19 12:10 ` [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE Fredrik M Olsson
2025-12-24  5:05   ` nobuhiro.iwamatsu.x90
2026-01-31  0:03   ` Alexandre Belloni
2026-02-03 14:23     ` Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status Fredrik M Olsson
2025-12-24  5:07   ` nobuhiro.iwamatsu.x90
2026-01-31  0:05   ` Alexandre Belloni
2026-02-03 14:26     ` Fredrik M Olsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=TY7PR01MB14818A301AD396B57AC28919FCDB2A@TY7PR01MB14818.jpnprd01.prod.outlook.com \
    --to=nobuhiro.iwamatsu.x90@mail.toshiba \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fredrik.m.olsson@axis.com \
    --cc=kernel@axis.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®