Skip to contentSkip to conversation

rtc: ls2x: Add support for the Loongson-2K/LS7A RTC

PATCH In review Binbin Zhou 3 participants 11 messages Sep 3, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover rtc: ls2x: Add support for the Loongson-2K/LS7A RTC

Hi all:

The initial DT-base ls2x rtc driver was written by Wang Xuerui, he has released five versions of patchset before, and all related mail records are shown below if you are interested:

https://lore.kernel.org/all/?q=ls2x-rtc

In this series of patches, based on the code above, I have added the following support:

1. Add ACPI-related support, as Loongson-3 + LS7A is now ACPI-base by default on LoonArch;
2. Add rtc alarm/walarm related functions.

Unfortunately, I have only tested the Loongson-3A4000+LS7A1000/LS7A2000 under LoongArch architecture.

NOTE:
The related functions of rtc alarm/walarm depend on ACPI registers, so rtc alarm may not be available on the DT-base environment. Such as Loongson-2k/3 under MIPS.

Thanks.

Binbin Zhou (2):
rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
LoongArch: Enable LS2X RTC in loongson3_defconfig

WANG Xuerui (5):
dt-bindings: rtc: Add bindings for LS2X RTC
MIPS: Loongson64: DTS: Add RTC support to LS7A
MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig
MIPS: Loongson64: DTS: Add RTC support to Loongson-2K
MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig

 .../devicetree/bindings/rtc/trivial-rtc.yaml  |   2 +
 arch/loongarch/configs/loongson3_defconfig    |   1 +
 .../boot/dts/loongson/loongson64-2k1000.dtsi  |   5 +
 arch/mips/boot/dts/loongson/ls7a-pch.dtsi     |   5 +
 arch/mips/configs/loongson2k_defconfig        |   1 +
 arch/mips/configs/loongson3_defconfig         |   1 +
 drivers/rtc/Kconfig                           |  11 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-ls2x.c                        | 366 ++++++++++++++++++
 9 files changed, 393 insertions(+)
 create mode 100644 drivers/rtc/rtc-ls2x.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/7 rtc: ls2x: Add support for the Loongson-2K/LS7A RTC

This RTC module is integrated into the Loongson-2K SoC and the LS7A bridge chip. This version is almost entirely rewritten to make use of current kernel API, and it supports both ACPI and DT.

---
 drivers/rtc/Kconfig    |  11 ++
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-ls2x.c | 366 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 378 insertions(+)
 create mode 100644 drivers/rtc/rtc-ls2x.c
drivers/rtc/Kconfig +11 -0
index b8de25118ad0..7ec64306ab70 100644
@@ -1338,6 +1338,17 @@ config RTC_DRV_NTXEC
 	  embedded controller found in certain e-book readers designed by the
 	  original design manufacturer Netronix.
 
+config RTC_DRV_LS2X
+	tristate "Loongson LS2X RTC"
+	depends on (ACPI || OF) && MACH_LOONGSON64 || COMPILE_TEST
+	select REGMAP_MMIO
+	help
+	  If you say yes here you get support for the RTC on the Loongson-2K
+	  SoC and LS7A bridge, which first appeared on the Loongson-2H.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-ls2x.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
drivers/rtc/Makefile +1 -0
index aab22bc63432..d5a467e9eec8 100644
@@ -83,6 +83,7 @@ obj-$(CONFIG_RTC_DRV_LOONGSON1)	+= rtc-ls1x.o
 obj-$(CONFIG_RTC_DRV_LP8788)	+= rtc-lp8788.o
 obj-$(CONFIG_RTC_DRV_LPC24XX)	+= rtc-lpc24xx.o
 obj-$(CONFIG_RTC_DRV_LPC32XX)	+= rtc-lpc32xx.o
+obj-$(CONFIG_RTC_DRV_LS2X)	+= rtc-ls2x.o
 obj-$(CONFIG_RTC_DRV_M41T80)	+= rtc-m41t80.o
 obj-$(CONFIG_RTC_DRV_M41T93)	+= rtc-m41t93.o
 obj-$(CONFIG_RTC_DRV_M41T94)	+= rtc-m41t94.o
drivers/rtc/rtc-ls2x.c new file +366 -0

366 lines not on this page · raw message

Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/7 LoongArch: Enable LS2X RTC in loongson3_defconfig

In reply to Binbin Zhou

This is now supported, enable for Loongson-3 systems. Other systems are unaffected.

---
 arch/loongarch/configs/loongson3_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/loongarch/configs/loongson3_defconfig +1 -0
index 4083d3051109..b240bc4e2021 100644
@@ -660,6 +660,7 @@ CONFIG_USB_GADGET=y
 CONFIG_INFINIBAND=m
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_EFI=y
+CONFIG_RTC_DRV_LS2X=y
 CONFIG_DMADEVICES=y
 CONFIG_UIO=m
 CONFIG_UIO_PDRV_GENIRQ=m
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig

Quoted 17 lines · Binbin Zhou

This is now supported, enable for Loongson-3 systems. Other systems are unaffected.

---
 arch/loongarch/configs/loongson3_defconfig | 1 +

 1 file changed, 1 insertion(+)
arch/loongarch/configs/loongson3_defconfig +0 -0
index 4083d3051109..b240bc4e2021 100644
@@ -660,6 +660,7 @@ CONFIG_USB_GADGET=y
Quoted 4 lines

 CONFIG_INFINIBAND=m
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_EFI=y
+CONFIG_RTC_DRV_LS2X=y

We already have RTC_DRV_EFI=y, IIUC this means we leave LS7A RTC for the firmware to drive and operate it through EFI service. So is this really needed for LoongArch systems? And if we enable both RTC_DRV_EFI and RTC_DRV_LS2X, will some bad thing (a conflict) happen?

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
maintainer
#4 lore raw

Re: [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig

Hi, Ruoyao,

Quoted 13 lines · Xi Ruoyao
Quoted 11 lines · Binbin Zhou

This is now supported, enable for Loongson-3 systems. Other systems are unaffected.

---
 arch/loongarch/configs/loongson3_defconfig | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

arch/loongarch/configs/loongson3_defconfig CONFIG_USB_GADGET=y · line 663

Quoted 10 lines
arch/loongarch/configs/loongson3_defconfig +1 -0
index 4083d3051109..b240bc4e2021 100644
@@ -660,6 +660,7 @@ CONFIG_USB_GADGET=y
 CONFIG_INFINIBAND=m
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_EFI=y
+CONFIG_RTC_DRV_LS2X=y

We already have RTC_DRV_EFI=y, IIUC this means we leave LS7A RTC for the firmware to drive and operate it through EFI service. So is this really needed for LoongArch systems? And if we enable both RTC_DRV_EFI and RTC_DRV_LS2X, will some bad thing (a conflict) happen?

Don't worry, please. EFI RTC depends on EFI runtime, so we need an available RTC if EFI runtime is disabled (by command line or any other reasons). On the other hand, multi RTCs can perfectly co-exist, they will be rtc0 and rtc1 under sysfs and rtc0 is the default one.

Huacai

Quoted 5 lines

--
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University

#5 lore raw

PATCH 3/7 dt-bindings: rtc: Add bindings for LS2X RTC

In reply to Binbin Zhou

From: WANG Xuerui <[email protected]>

Document the binding for the LS2X RTC block found on the Loongson-2K SoC and the LS7A bridge, originally appearing on the Loongson-2H.

---
 Documentation/devicetree/bindings/rtc/trivial-rtc.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/rtc/trivial-rtc.yaml +2 -0
index d9fc120c61cc..4cfb289b5461 100644
@@ -47,6 +47,8 @@ properties:
       - isil,isl1218
       # Intersil ISL12022 Real-time Clock
       - isil,isl12022
+      # Loongson LS2X RTC
+      - loongson,ls2x-rtc
       # Real Time Clock Module with I2C-Bus
       - microcrystal,rv3028
       # Real Time Clock Module with I2C-Bus
Signature · 1 line
2.31.1
#6 lore raw

PATCH 4/7 MIPS: Loongson64: DTS: Add RTC support to LS7A

In reply to Binbin Zhou

From: WANG Xuerui <[email protected]>

The LS7A RTC module is now supported, enable it.

---
 arch/mips/boot/dts/loongson/ls7a-pch.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/mips/boot/dts/loongson/ls7a-pch.dtsi +5 -0
index 2f45fce2cdc4..82035de4774f 100644
@@ -19,6 +19,11 @@ pic: interrupt-controller@10000000 {
 			#interrupt-cells = <2>;
 		};
 
+		rtc0: rtc@100d0100 {
+			compatible = "loongson,ls2x-rtc";
+			reg = <0 0x100d0100 0 0x78>;
+		};
+
 		ls7a_uart0: serial@10080000 {
 			compatible = "ns16550a";
 			reg = <0 0x10080000 0 0x100>;
Signature · 1 line
2.31.1
#7 lore raw

PATCH 5/7 MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig

In reply to Binbin Zhou

From: WANG Xuerui <[email protected]>

This is now supported, enable for Loongson-3 systems. Other systems are unaffected.

Cc Thomas Bogendoerfer <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Tiezhu Yang <[email protected]>
Cc Youling Tang <[email protected]>
Cc Qing Zhang <[email protected]>
---
 arch/mips/configs/loongson3_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/mips/configs/loongson3_defconfig +1 -0
index 25ecd15bc952..166c9775de75 100644
@@ -321,6 +321,7 @@ CONFIG_USB_SERIAL_OPTION=m
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_CMOS=y
 CONFIG_RTC_DRV_GOLDFISH=y
+CONFIG_RTC_DRV_LS2X=y
 CONFIG_DMADEVICES=y
 CONFIG_VIRTIO_PCI=y
 CONFIG_VIRTIO_BALLOON=m
Signature · 1 line
2.31.1
#8 lore raw

PATCH 6/7 MIPS: Loongson64: DTS: Add RTC support to Loongson-2K

In reply to Binbin Zhou

From: WANG Xuerui <[email protected]>

The Loongson-2K RTC module is now supported, enable it.

The MMIO address is unclear from the Loongson 2K1000 user manual, I took it from Loongson's out-of-tree fork of Linux 4.19.

Cc Jiaxun Yang <[email protected]>
Cc Rob Herring <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Qing Zhang <[email protected]>
Cc Tiezhu Yang <[email protected]>
Cc zhaoxiao <[email protected]>
---
 arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi +5 -0
index 8143a61111e3..811a5ab753a2 100644
@@ -57,6 +57,11 @@ pm: reset-controller@1fe07000 {
 			reg = <0 0x1fe07000 0 0x422>;
 		};
 
+		rtc0: rtc@1fe07800 {
+			compatible = "loongson,ls2x-rtc";
+			reg = <0 0x1fe07800 0 0x78>;
+		};
+
 		liointc0: interrupt-controller@1fe11400 {
 			compatible = "loongson,liointc-2.0";
 			reg = <0 0x1fe11400 0 0x40>,
Signature · 1 line
2.31.1
#9 lore raw

PATCH 7/7 MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig

In reply to Binbin Zhou

From: WANG Xuerui <[email protected]>

This is now supported, enable for Loongson-2K systems. Other systems are unaffected.

---
 arch/mips/configs/loongson2k_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/mips/configs/loongson2k_defconfig +1 -0
index e948ca487e2d..e15f34857956 100644
@@ -280,6 +280,7 @@ CONFIG_USB_SERIAL=m
 CONFIG_USB_SERIAL_OPTION=m
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_CMOS=y
+CONFIG_RTC_DRV_LS2X=y
 CONFIG_DMADEVICES=y
 # CONFIG_CPU_HWMON is not set
 CONFIG_PM_DEVFREQ=y
Signature · 1 line
2.31.1
maintainer
#10 lore raw
In reply to Binbin Zhou

Hi, Binbin,

Quoted 12 lines · Binbin Zhou

Hi all:

The initial DT-base ls2x rtc driver was written by Wang Xuerui, he has released five versions of patchset before, and all related mail records are shown below if you are interested:

https://lore.kernel.org/all/?q=ls2x-rtc

In this series of patches, based on the code above, I have added the following support:

Quoted 6 lines

1. Add ACPI-related support, as Loongson-3 + LS7A is now ACPI-base by default on LoonArch;
2. Add rtc alarm/walarm related functions.

Unfortunately, I have only tested the Loongson-3A4000+LS7A1000/LS7A2000 under LoongArch architecture.

I think Loongson-3A4000 should be Loongson-3A5000 here. And I think Qing Zhang can help us to test on Loongson-2K platform.

Huacai

Quoted 35 lines

NOTE:
The related functions of rtc alarm/walarm depend on ACPI registers, so rtc alarm may not be available on the DT-base environment. Such as Loongson-2k/3 under MIPS.

Thanks.

Binbin Zhou (2):
rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
LoongArch: Enable LS2X RTC in loongson3_defconfig

WANG Xuerui (5):
dt-bindings: rtc: Add bindings for LS2X RTC
MIPS: Loongson64: DTS: Add RTC support to LS7A
MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig
MIPS: Loongson64: DTS: Add RTC support to Loongson-2K
MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig

 .../devicetree/bindings/rtc/trivial-rtc.yaml  |   2 +
 arch/loongarch/configs/loongson3_defconfig    |   1 +
 .../boot/dts/loongson/loongson64-2k1000.dtsi  |   5 +
 arch/mips/boot/dts/loongson/ls7a-pch.dtsi     |   5 +
 arch/mips/configs/loongson2k_defconfig        |   1 +
 arch/mips/configs/loongson3_defconfig         |   1 +
 drivers/rtc/Kconfig                           |  11 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-ls2x.c                        | 366 ++++++++++++++++++
 9 files changed, 393 insertions(+)
 create mode 100644 drivers/rtc/rtc-ls2x.c

--
2.31.1