From b60b757d9c4d4d9ba077a26343b0984a84789695 Mon Sep 17 00:00:00 2001 From: Shubhi Garg Date: Mon, 13 Jun 2022 10:31:45 +0000 Subject: [PATCH] rtc: fix year calculation in max77851 pmic rtc Add +100 to year only if PMIC does not have separate alarm enable registers. Since MAX77851 has separate alarm enable register , MAX77851 RTC supports year calculation from 0..199 so we do not need to add 100 on reading RTC YEAR register. Currently, default, driver is adding +100 which is wrong. This change fixes rtc year calculation. Bug 200749982 Change-Id: Ibaf1d2fb81e59cc21c22d509cf9ffc7b6005916c Signed-off-by: Shubhi Garg Reviewed-on: https://git-master.nvidia.com/r/c/linux-5.10/+/2727859 (cherry picked from commit b43364942c67fdf7958a42bfad5fe02725da00e3) Reviewed-on: https://git-master.nvidia.com/r/c/linux-5.10/+/2728926 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2947785 Reviewed-by: svcacv Reviewed-by: Bitan Biswas Tested-by: Bitan Biswas GVS: Gerrit_Virtual_Submit --- drivers/rtc/rtc-max77851.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-max77851.c b/drivers/rtc/rtc-max77851.c index 043b3c3b..97fe5043 100644 --- a/drivers/rtc/rtc-max77851.c +++ b/drivers/rtc/rtc-max77851.c @@ -240,9 +240,12 @@ static void max77851_rtc_data_to_tm(u8 *data, struct rtc_time *tm, tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1; tm->tm_mday = data[RTC_DATE] & 0x1f; tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1; - tm->tm_year = (data[RTC_YEAR] & mask) + 100; + tm->tm_year = (data[RTC_YEAR] & mask); tm->tm_yday = 0; tm->tm_isdst = 0; + + if (!info->drv_data->alarm_enable_reg) + tm->tm_year += 100; } static int max77851_rtc_tm_to_data(struct rtc_time *tm, u8 *data,