Skip to content

Commit a06e4a9

Browse files
fthainalexandrebelloni
authored andcommitted
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>
1 parent fb1283b commit a06e4a9

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

arch/sparc/kernel/time_32.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
255255
static struct m48t59_plat_data m48t59_data = {
256256
.read_byte = mostek_read_byte,
257257
.write_byte = mostek_write_byte,
258+
.yy_offset = 68,
258259
};
259260

260261
/* resource is set at runtime */

arch/sparc/kernel/time_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
544544
static struct m48t59_plat_data m48t59_data = {
545545
.read_byte = mostek_read_byte,
546546
.write_byte = mostek_write_byte,
547+
.yy_offset = 68,
547548
};
548549

549550
static struct platform_device m48t59_rtc = {

drivers/rtc/rtc-m48t59.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
7171
/* Issue the READ command */
7272
M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
7373

74-
tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
74+
tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)) + pdata->yy_offset;
7575
/* tm_mon is 0-11 */
7676
tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
7777
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)
8282
dev_dbg(dev, "Century bit is enabled\n");
8383
tm->tm_year += 100; /* one century */
8484
}
85-
#ifdef CONFIG_SPARC
86-
/* Sun SPARC machines count years since 1968 */
87-
tm->tm_year += 68;
88-
#endif
8985

9086
tm->tm_wday = bcd2bin(val & 0x07);
9187
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)
106102
struct m48t59_private *m48t59 = dev_get_drvdata(dev);
107103
unsigned long flags;
108104
u8 val = 0;
109-
int year = tm->tm_year;
110-
111-
#ifdef CONFIG_SPARC
112-
/* Sun SPARC machines count years since 1968 */
113-
year -= 68;
114-
#endif
105+
int year = tm->tm_year - pdata->yy_offset;
115106

116107
dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
117108
year + 1900, tm->tm_mon, tm->tm_mday,
@@ -162,11 +153,7 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
162153
/* Issue the READ command */
163154
M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
164155

165-
tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
166-
#ifdef CONFIG_SPARC
167-
/* Sun SPARC machines count years since 1968 */
168-
tm->tm_year += 68;
169-
#endif
156+
tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)) + pdata->yy_offset;
170157
/* tm_mon is 0-11 */
171158
tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
172159

@@ -197,12 +184,7 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
197184
struct rtc_time *tm = &alrm->time;
198185
u8 mday, hour, min, sec;
199186
unsigned long flags;
200-
int year = tm->tm_year;
201-
202-
#ifdef CONFIG_SPARC
203-
/* Sun SPARC machines count years since 1968 */
204-
year -= 68;
205-
#endif
187+
int year = tm->tm_year - pdata->yy_offset;
206188

207189
/* If no irq, we don't support ALARM */
208190
if (m48t59->irq == NO_IRQ)

include/linux/rtc/m48t59.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct m48t59_plat_data {
5656
void __iomem *ioaddr;
5757
/* offset to RTC registers, automatically set according to the type */
5858
unsigned int offset;
59+
60+
/* YY digits (in RTC) are offset, i.e. year is 1900 + yy_offset + YY */
61+
int yy_offset;
5962
};
6063

6164
#endif /* _LINUX_RTC_M48T59_H_ */

0 commit comments

Comments
 (0)