mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 01:32:21 +02:00
rtc: renesas-rtca3: Factor out year decoding helper
The logic to decode the year value from the hardware registers is duplicated in both rtca3_read_time() and rtca3_read_alarm(). Introduce a helper rtca3_decode_year() to centralize this conversion. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> # on RZ/G3S Link: https://patch.msgid.link/20260602192559.1791344-6-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
9fb12656a7
commit
2098bb8ac5
|
|
@ -228,12 +228,19 @@ static void rtca3_prepare_cntalrm_regs_for_read(struct rtca3_priv *priv, bool cn
|
|||
}
|
||||
}
|
||||
|
||||
static u32 rtca3_decode_year(u8 mask, u16 year)
|
||||
{
|
||||
u8 y = FIELD_GET(mask, year);
|
||||
u32 century = bcd2bin((y == 0x99) ? 0x19 : 0x20);
|
||||
|
||||
return (century * 100 + bcd2bin(y)) - 1900;
|
||||
}
|
||||
|
||||
static int rtca3_read_time(struct device *dev, struct rtc_time *tm)
|
||||
{
|
||||
struct rtca3_priv *priv = dev_get_drvdata(dev);
|
||||
u8 sec, min, hour, wday, mday, month, tmp;
|
||||
u8 trials = 0;
|
||||
u32 year100;
|
||||
u16 year;
|
||||
|
||||
guard(spinlock_irqsave)(&priv->lock);
|
||||
|
|
@ -274,9 +281,7 @@ static int rtca3_read_time(struct device *dev, struct rtc_time *tm)
|
|||
tm->tm_wday = bcd2bin(FIELD_GET(RTCA3_RWKCNT_WK, wday));
|
||||
tm->tm_mday = bcd2bin(FIELD_GET(RTCA3_RDAYCNT_DAY, mday));
|
||||
tm->tm_mon = bcd2bin(FIELD_GET(RTCA3_RMONCNT_MONTH, month)) - 1;
|
||||
year = FIELD_GET(RTCA3_RYRCNT_YEAR, year);
|
||||
year100 = bcd2bin((year == 0x99) ? 0x19 : 0x20);
|
||||
tm->tm_year = (year100 * 100 + bcd2bin(year)) - 1900;
|
||||
tm->tm_year = rtca3_decode_year(RTCA3_RYRCNT_YEAR, year);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -354,7 +359,6 @@ static int rtca3_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
|
|||
struct rtca3_priv *priv = dev_get_drvdata(dev);
|
||||
u8 sec, min, hour, wday, mday, month;
|
||||
struct rtc_time *tm = &wkalrm->time;
|
||||
u32 year100;
|
||||
u16 year;
|
||||
|
||||
guard(spinlock_irqsave)(&priv->lock);
|
||||
|
|
@ -373,9 +377,7 @@ static int rtca3_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
|
|||
tm->tm_wday = bcd2bin(FIELD_GET(RTCA3_RWKAR_DAYW, wday));
|
||||
tm->tm_mday = bcd2bin(FIELD_GET(RTCA3_RDAYAR_DATE, mday));
|
||||
tm->tm_mon = bcd2bin(FIELD_GET(RTCA3_RMONAR_MON, month)) - 1;
|
||||
year = FIELD_GET(RTCA3_RYRAR_YR, year);
|
||||
year100 = bcd2bin((year == 0x99) ? 0x19 : 0x20);
|
||||
tm->tm_year = (year100 * 100 + bcd2bin(year)) - 1900;
|
||||
tm->tm_year = rtca3_decode_year(RTCA3_RYRAR_YR, year);
|
||||
|
||||
wkalrm->enabled = !!(readb(priv->base + RTCA3_RCR1) & RTCA3_RCR1_AIE);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user