Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: m48t59: Use platform_data struct for year offset value

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>

authored by

Finn Thain and committed by
Alexandre Belloni
a06e4a93 fb1283bf

+9 -22
+1
arch/sparc/kernel/time_32.c
··· 255 255 static struct m48t59_plat_data m48t59_data = { 256 256 .read_byte = mostek_read_byte, 257 257 .write_byte = mostek_write_byte, 258 + .yy_offset = 68, 258 259 }; 259 260 260 261 /* resource is set at runtime */
+1
arch/sparc/kernel/time_64.c
··· 544 544 static struct m48t59_plat_data m48t59_data = { 545 545 .read_byte = mostek_read_byte, 546 546 .write_byte = mostek_write_byte, 547 + .yy_offset = 68, 547 548 }; 548 549 549 550 static struct platform_device m48t59_rtc = {
+4 -22
drivers/rtc/rtc-m48t59.c
··· 71 71 /* Issue the READ command */ 72 72 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 73 73 74 - tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); 74 + tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)) + pdata->yy_offset; 75 75 /* tm_mon is 0-11 */ 76 76 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; 77 77 tm->tm_mday = bcd2bin(M48T59_READ(M48T59_MDAY)); ··· 82 82 dev_dbg(dev, "Century bit is enabled\n"); 83 83 tm->tm_year += 100; /* one century */ 84 84 } 85 - #ifdef CONFIG_SPARC 86 - /* Sun SPARC machines count years since 1968 */ 87 - tm->tm_year += 68; 88 - #endif 89 85 90 86 tm->tm_wday = bcd2bin(val & 0x07); 91 87 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); ··· 102 106 struct m48t59_private *m48t59 = dev_get_drvdata(dev); 103 107 unsigned long flags; 104 108 u8 val = 0; 105 - int year = tm->tm_year; 106 - 107 - #ifdef CONFIG_SPARC 108 - /* Sun SPARC machines count years since 1968 */ 109 - year -= 68; 110 - #endif 109 + int year = tm->tm_year - pdata->yy_offset; 111 110 112 111 dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n", 113 112 year + 1900, tm->tm_mon, tm->tm_mday, ··· 153 162 /* Issue the READ command */ 154 163 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 155 164 156 - tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); 157 - #ifdef CONFIG_SPARC 158 - /* Sun SPARC machines count years since 1968 */ 159 - tm->tm_year += 68; 160 - #endif 165 + tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)) + pdata->yy_offset; 161 166 /* tm_mon is 0-11 */ 162 167 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; 163 168 ··· 184 197 struct rtc_time *tm = &alrm->time; 185 198 u8 mday, hour, min, sec; 186 199 unsigned long flags; 187 - int year = tm->tm_year; 188 - 189 - #ifdef CONFIG_SPARC 190 - /* Sun SPARC machines count years since 1968 */ 191 - year -= 68; 192 - #endif 200 + int year = tm->tm_year - pdata->yy_offset; 193 201 194 202 /* If no irq, we don't support ALARM */ 195 203 if (m48t59->irq == NO_IRQ)
+3
include/linux/rtc/m48t59.h
··· 56 56 void __iomem *ioaddr; 57 57 /* offset to RTC registers, automatically set according to the type */ 58 58 unsigned int offset; 59 + 60 + /* YY digits (in RTC) are offset, i.e. year is 1900 + yy_offset + YY */ 61 + int yy_offset; 59 62 }; 60 63 61 64 #endif /* _LINUX_RTC_M48T59_H_ */