]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtc: m48t59: Use platform_data struct for year offset value
authorFinn Thain <fthain@linux-m68k.org>
Tue, 12 Nov 2024 22:32:15 +0000 (09:32 +1100)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 18 Nov 2024 13:31:57 +0000 (14:31 +0100)
Instead of hard-coded values and ifdefs, store the year offset in the
platform_data struct.

Tested-by: Daniel Palmer <daniel@0x0f.com>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
Tested-by: Andreas Larsson <andreas@gaisler.com>
Acked-by: Andreas Larsson <andreas@gaisler.com>
Link: https://lore.kernel.org/r/665c3526184a8d0c4a6373297d8e7d9a12591d8b.1731450735.git.fthain@linux-m68k.org
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
arch/sparc/kernel/time_32.c
arch/sparc/kernel/time_64.c
drivers/rtc/rtc-m48t59.c
include/linux/rtc/m48t59.h

index 08bbdc4585969c28b1ccc2d7df9934450abc64d3..578fd0d49f30668e2a2de9c8561fab5f43e7b81a 100644 (file)
@@ -255,6 +255,7 @@ static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
 static struct m48t59_plat_data m48t59_data = {
        .read_byte = mostek_read_byte,
        .write_byte = mostek_write_byte,
+       .yy_offset = 68,
 };
 
 /* resource is set at runtime */
index 60f1c8cc5363e6947ac23d0404206340ade4c168..b32f27f929d1ab49a5aa05cde60d3b88e90928ba 100644 (file)
@@ -544,6 +544,7 @@ static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
 static struct m48t59_plat_data m48t59_data = {
        .read_byte      = mostek_read_byte,
        .write_byte     = mostek_write_byte,
+       .yy_offset      = 68,
 };
 
 static struct platform_device m48t59_rtc = {
index 5d30ce8e13ca0368c69b50660ff669f8edad6d59..4e608bc8bbd369fd90bde059d92513428919c0d3 100644 (file)
@@ -71,7 +71,7 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
        /* Issue the READ command */
        M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
 
-       tm->tm_year     = bcd2bin(M48T59_READ(M48T59_YEAR));
+       tm->tm_year     = bcd2bin(M48T59_READ(M48T59_YEAR)) + pdata->yy_offset;
        /* tm_mon is 0-11 */
        tm->tm_mon      = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
        tm->tm_mday     = bcd2bin(M48T59_READ(M48T59_MDAY));
@@ -82,10 +82,6 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
                dev_dbg(dev, "Century bit is enabled\n");
                tm->tm_year += 100;     /* one century */
        }
-#ifdef CONFIG_SPARC
-       /* Sun SPARC machines count years since 1968 */
-       tm->tm_year += 68;
-#endif
 
        tm->tm_wday     = bcd2bin(val & 0x07);
        tm->tm_hour     = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F);
@@ -106,12 +102,7 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
        struct m48t59_private *m48t59 = dev_get_drvdata(dev);
        unsigned long flags;
        u8 val = 0;
-       int year = tm->tm_year;
-
-#ifdef CONFIG_SPARC
-       /* Sun SPARC machines count years since 1968 */
-       year -= 68;
-#endif
+       int year = tm->tm_year - pdata->yy_offset;
 
        dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
                year + 1900, tm->tm_mon, tm->tm_mday,
@@ -162,11 +153,7 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
        /* Issue the READ command */
        M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
 
-       tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
-#ifdef CONFIG_SPARC
-       /* Sun SPARC machines count years since 1968 */
-       tm->tm_year += 68;
-#endif
+       tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)) + pdata->yy_offset;
        /* tm_mon is 0-11 */
        tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
 
@@ -197,12 +184,7 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
        struct rtc_time *tm = &alrm->time;
        u8 mday, hour, min, sec;
        unsigned long flags;
-       int year = tm->tm_year;
-
-#ifdef CONFIG_SPARC
-       /* Sun SPARC machines count years since 1968 */
-       year -= 68;
-#endif
+       int year = tm->tm_year - pdata->yy_offset;
 
        /* If no irq, we don't support ALARM */
        if (m48t59->irq == NO_IRQ)
index 9465d5405fe28be2b9f82747c792dd16e3bc57fc..373ba77071c6b27a80ac0ec7d434bb2866e5263c 100644 (file)
@@ -56,6 +56,9 @@ struct m48t59_plat_data {
        void __iomem *ioaddr;
        /* offset to RTC registers, automatically set according to the type */
        unsigned int offset;
+
+       /* YY digits (in RTC) are offset, i.e. year is 1900 + yy_offset + YY */
+       int yy_offset;
 };
 
 #endif /* _LINUX_RTC_M48T59_H_ */