Skip to contentSkip to conversation

MVME: Adopt standard RTC driver

PATCH Superseded Finn Thain 2 participants 5 messages Oct 7, 2024 – Oct 8, 2024

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Finn Thain

author
#0 lore raw

v2 cover MVME: Adopt standard RTC driver

This series removes some duplicated RTC driver code.
First rtc-m48t59 is tweaked to bring it into equivalence with the RTC drivers in arch/m68k/mvme*. Then platform devices are added for the former driver and the latter drivers are removed.

---
Changed since v1:
- Instead of adding ifdefs to the portable driver, store the year offset in struct m48t59_plat_data.

Finn Thain (2):
rtc: m48t59: Use platform_data struct for year offset value
m68k: mvme147, mvme16x: Adopt rtc-m48t59 platform driver

 arch/m68k/configs/multi_defconfig   |   1 +
 arch/m68k/configs/mvme147_defconfig |   1 +
 arch/m68k/configs/mvme16x_defconfig |   1 +
 arch/m68k/include/asm/mvme147hw.h   |  19 +---
 arch/m68k/include/asm/mvme16xhw.h   |  18 +--
 arch/m68k/mvme147/config.c          |  55 ++++------
 arch/m68k/mvme16x/Makefile          |   2 +-
 arch/m68k/mvme16x/config.c          |  57 ++++------
 arch/m68k/mvme16x/rtc.c             | 165 ----------------------------
 arch/sparc/kernel/time_32.c         |   1 +
 arch/sparc/kernel/time_64.c         |   1 +
 drivers/rtc/rtc-m48t59.c            |  26 +----
 include/linux/rtc/m48t59.h          |   3 +
 13 files changed, 63 insertions(+), 287 deletions(-)
 delete mode 100644 arch/m68k/mvme16x/rtc.c
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH v2 1/2 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.

---
I tested this for regressions using qemu-system-sparc64. Also, Daniel tested the RTC functionality on his MVME147 system.

---
 arch/sparc/kernel/time_32.c |  1 +
 arch/sparc/kernel/time_64.c |  1 +
 drivers/rtc/rtc-m48t59.c    | 26 ++++----------------------
 include/linux/rtc/m48t59.h  |  3 +++
 4 files changed, 9 insertions(+), 22 deletions(-)
arch/sparc/kernel/time_32.c +1 -0
index 08bbdc458596..578fd0d49f30 100644
@@ -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 */
arch/sparc/kernel/time_64.c +1 -0
index 60f1c8cc5363..b32f27f929d1 100644
@@ -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 = {
drivers/rtc/rtc-m48t59.c +4 -22
index f0f6b9b6daec..4c339fb45b5c 100644
@@ -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)
include/linux/rtc/m48t59.h +3 -0
index 9465d5405fe2..6ac1eb2cbeac 100644
@@ -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 */
+	time64_t yy_offset;
 };
 
 #endif /* _LINUX_RTC_M48T59_H_ */
Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH v2 1/2] rtc: m48t59: Use platform_data struct for year offset value

Hi Finn,

Quoted 5 lines · Finn Thain

Instead of hard-coded values and ifdefs, store the year offset in the platform_data struct.

Thanks for your patch!

include/linux/rtc/m48t59.h struct m48t59_plat_data { · line 61

Quoted 9 lines
include/linux/rtc/m48t59.h +3 -0
@@ -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 */
+       time64_t yy_offset;

time64_t sounds like overkill to me...

include/linux/rtc/m48t59.h struct m48t59_plat_data { · line 64

Quoted 3 lines
include/linux/rtc/m48t59.h +0 -0
 };
 
 #endif /* _LINUX_RTC_M48T59_H_ */

The rest LGTM.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#3 lore raw

Re: [PATCH v2 1/2] rtc: m48t59: Use platform_data struct for year offset value

Quoted 11 lines · Geert Uytterhoeven

Hi Finn,

Quoted 5 lines · Finn Thain

Instead of hard-coded values and ifdefs, store the year offset in the platform_data struct.

Thanks for your patch!

Thanks for your review.

Quoted 12 lines

include/linux/rtc/m48t59.h struct m48t59_plat_data { · line 61

Quoted 9 lines
include/linux/rtc/m48t59.h +3 -0
@@ -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 */
+       time64_t yy_offset;

time64_t sounds like overkill to me...

A vestige of an earlier experiment. Sorry about that. I shall send v3.

author
#4 lore raw

PATCH v2 2/2 m68k: mvme147, mvme16x: Adopt rtc-m48t59 platform driver

In reply to Finn Thain

Both mvme147 and mvme16x platforms have their own RTC driver implementations that duplicate functionality provided by the rtc-m48t59 driver. Adopt the rtc-m48t59 driver and remove the other ones.

---
This patch depends upon the m48t59 driver changes in the preceding patch.

Changed since v1:
- Initialize yy_offset in struct m48t59_plat_data.

---
 arch/m68k/configs/multi_defconfig   |   1 +
 arch/m68k/configs/mvme147_defconfig |   1 +
 arch/m68k/configs/mvme16x_defconfig |   1 +
 arch/m68k/include/asm/mvme147hw.h   |  19 +---
 arch/m68k/include/asm/mvme16xhw.h   |  18 +--
 arch/m68k/mvme147/config.c          |  55 ++++------
 arch/m68k/mvme16x/Makefile          |   2 +-
 arch/m68k/mvme16x/config.c          |  57 ++++------
 arch/m68k/mvme16x/rtc.c             | 165 ----------------------------
 9 files changed, 54 insertions(+), 265 deletions(-)
 delete mode 100644 arch/m68k/mvme16x/rtc.c
arch/m68k/configs/multi_defconfig +1 -0
index 638df8442c98..617ac93298f3 100644
@@ -506,6 +506,7 @@ CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_MSM6242=m
 CONFIG_RTC_DRV_RP5C01=m
 CONFIG_RTC_DRV_GENERIC=m
+CONFIG_RTC_DRV_M48T59=m
 # CONFIG_VIRTIO_MENU is not set
 # CONFIG_VHOST_MENU is not set
 # CONFIG_IOMMU_SUPPORT is not set
arch/m68k/configs/mvme147_defconfig +1 -0
index 2248db426081..4a0928b3b842 100644
@@ -392,6 +392,7 @@ CONFIG_UHID=m
 CONFIG_RTC_CLASS=y
 # CONFIG_RTC_NVMEM is not set
 CONFIG_RTC_DRV_GENERIC=m
+CONFIG_RTC_DRV_M48T59=y
 # CONFIG_VIRTIO_MENU is not set
 # CONFIG_VHOST_MENU is not set
 # CONFIG_IOMMU_SUPPORT is not set
arch/m68k/configs/mvme16x_defconfig +1 -0
index 2975b66521f6..481fb2810f1e 100644
@@ -393,6 +393,7 @@ CONFIG_UHID=m
 CONFIG_RTC_CLASS=y
 # CONFIG_RTC_NVMEM is not set
 CONFIG_RTC_DRV_GENERIC=m
+CONFIG_RTC_DRV_M48T59=y
 # CONFIG_VIRTIO_MENU is not set
 # CONFIG_VHOST_MENU is not set
 # CONFIG_IOMMU_SUPPORT is not set
arch/m68k/include/asm/mvme147hw.h +1 -18
index dbf88059e47a..6ad93bac06f9 100644
@@ -4,24 +4,7 @@
 
 #include <asm/irq.h>
 
-typedef struct {
-	unsigned char
-		ctrl,
-		bcd_sec,
-		bcd_min,
-		bcd_hr,
-		bcd_dow,
-		bcd_dom,
-		bcd_mth,
-		bcd_year;
-} MK48T02;
-
-#define RTC_WRITE	0x80
-#define RTC_READ	0x40
-#define RTC_STOP	0x20
-
-#define m147_rtc ((MK48T02 * volatile)0xfffe07f8)
-
+#define MVME147_RTC_BASE	0xfffe0000
 
 struct pcc_regs {
    volatile u_long	dma_tadr;
arch/m68k/include/asm/mvme16xhw.h +1 -17
index cc7f5ae1220f..ff1126a51fbe 100644
@@ -24,23 +24,7 @@ typedef struct {
 
 #define mvmelp   ((*(volatile MVMElpPtr)(MVME_LPR_BASE)))
 
-typedef struct {
-	unsigned char
-		ctrl,
-		bcd_sec,
-		bcd_min,
-		bcd_hr,
-		bcd_dow,
-		bcd_dom,
-		bcd_mth,
-		bcd_year;
-} MK48T08_t, *MK48T08ptr_t;
-
-#define RTC_WRITE	0x80
-#define RTC_READ	0x40
-#define RTC_STOP	0x20
-
-#define MVME_RTC_BASE	0xfffc1ff8
+#define MVME_RTC_BASE	0xfffc0000
 
 #define MVME_I596_BASE	0xfff46000
 
arch/m68k/mvme147/config.c +24 -31

89 lines not on this page · raw message

arch/m68k/mvme16x/Makefile +1 -1
index a8a368c2cbea..02f9e4ad8209 100644
@@ -3,4 +3,4 @@
 # Makefile for Linux arch/m68k/mvme16x source directory
 #
 
-obj-y		:= config.o rtc.o
+obj-y		:= config.o
arch/m68k/mvme16x/config.c +24 -33

90 lines not on this page · raw message

arch/m68k/mvme16x/rtc.c deleted +0 -165

165 lines not on this page · raw message

Signature · 1 line
2.39.5