Skip to contentSkip to conversation

rtc: sophgo: add rtc support for CV1800

PATCH Superseded Alexander Sverdlin 4 participants 19 messages Mar 9, 2025 – Apr 9, 2025

Subsystems (3)

v13 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v13 cover rtc: sophgo: add rtc support for CV1800

Real Time Clock (RTC) is an independently powered module within the chip, which includes a 32KHz oscillator and a Power On Reset/POR submodule. It can be used for time display and timed alarm generation.

This series aims to provide complete DT bindings, but the drivers are only focusing on RTC implementation. Possible Power Management and remoteproc can be implemented later (hence the RTC driver is using syscon, because MMIO space is really interleaved among different functions).

Series is tested on Milk-V Duo Module 01 EVB (SG2000 SoC).

Changes since v12:
- Moved bindings and stub driver from MFD into SOC subsystem

Changes since v11:
- dropped restart handling (will be implemented in PSCI)
- split RTC driver into MFD stub and a platform RTC driver
- dropped Reviewed-by: Krzysztof Kozlowski from bindings, they've got a rework
- changed bindings maintainer from Jingbao Qiu <[email protected]> to [email protected]
- added link to TRM into bindings description
- bindings: mentioned 8051 core in the description
- bindings are now MFD, not RTC
- bindings: added "syscon" compatible
- bindings: added "interrupt-names", "clock-names" (because of added PM/remoteproc)
- bindings: main compatible "sophgo,cv1800-rtc" -> "sophgo,cv1800b-rtc"
- new patch "mfd: sophgo: cv1800: rtcsys: New driver (handling RTC only)"
- added both MFD and RTC drivers into MAINTAINERS file (N: K: entries didn't apply)
- RTC: depends on cv1800-rtcsys MFD driver
- RTC: use syscon for regmap
- RTC: get named clock from parent MFD
Changes since v10:
- only start RTC on set_time;
Changes since v9:
- further simplified bitmask macros;
- unconditional RTC start (rtc_enable_sec_counter()), otherwise didn't start on SG2000;
- dropped ANA_CALIB modification (has been forgotten in v8 with the drop of SW calibration to switch to HW calibration);
- successfully tested on SG2000;

Changes since v10:
- only start RTC on set_time;
- add machine restart handler (as separate patch 3/3);

Changes since v9:
- picked up orphaned series;
- further simplified bitmask macros;
- unconditional RTC start (rtc_enable_sec_counter());
- dropped ANA_CALIB modification;
- successfully tested on SG2000;

v9: https://lore.kernel.org/linux-riscv/[email protected]/

Changes since v8:
- delete unused macros
- using 0/1 instead of the DISABLE/ENABLE macro
- pass in the correct pointer when applying for IRQ
- convert the incoming pointer into an appropriate structure pointer in the irq handler

v8: https://lore.kernel.org/all/[email protected]/

Changes since v7:
- pass checkpatch.pl --strict
- using u32 replace uint32
- using devm_kzalloc(*) replace devm_kzalloc(sizeof())
- sort header files alphabetically
- delete unnecessary header files
- fix wrap error
- drop dependent description
- using hardware automatic calibration replace software calibration. see documentation 197 page

v7: https://lore.kernel.org/all/[email protected]/
documentation: https://github.com/milkv-duo/duo-files/blob/main/duo/datasheet/CV1800B-CV1801B-Preliminary-Datasheet-full-en.pdf

Changes since v6:
- completely delete POR dt node
- remove syscon tag
- use devm_regmap_init_mmio() replace
syscon_node_to_regmap

v6: https://lore.kernel.org/all/[email protected]/

Changes since v5:
- remove unnecessary lock
- fix cv1800_rtc_alarm_irq_enable()
- remove duplicate checks
- using alrm->enabled instead of unconditionally
enabling
- remove disable alarms on probe
- using rtc_update_irq() replace mess of alarm
- remove leak clk
- useing devm_rtc_allocate_device() and
devm_rtc_register_device() instead old way
- add judgment for rtc_enable_sec_counter()
- add POR nodes in DTS. This POR device shares
the register region with the RTC device

v5: https://lore.kernel.org/all/[email protected]/

Changes since v4:
- remove POR dt-bindings because it empty
- remove MFD dt-bindings because SoC does
not have MFDs
- add syscon attribute to share registers
with POR

v4: https://lore.kernel.org/all/[email protected]/

Changes since v3:
- temporarily not submitting RTC driver code
waiting for communication with IC designer
- add MFD dt-bindings
- add POR dt-bindings

v3: https://lore.kernel.org/all/[email protected]/

Changes since v2:
- add mfd support for CV1800
- add rtc to mfd
- using regmap replace iomap
- merge register address in dts

v2: https://lore.kernel.org/lkml/[email protected]/

Changes since v1
- fix duplicate names in subject
- using RTC replace RTC controller
- improve the properties of dt-bindings
- using unevaluatedProperties replace additionalProperties
- dt-bindings passed the test
- using devm_platform_ioremap_resource() replace platform_get_resource() and devm_ioremap_resource()
- fix random order of the code
- fix wrong wrapping of the devm_request_irq() and map the flag with dts
- using devm_clk_get_enabled replace devm_clk_get() and clk_prepare_enable()
- fix return style
- add rtc clock calibration function
- use spinlock when write register on read/set time

v1: https://lore.kernel.org/lkml/[email protected]/

Alexander Sverdlin (1):
soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Jingbao Qiu (2):
dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series
rtc: sophgo: add rtc support for Sophgo CV1800 SoC

 .../soc/sophgo/sophgo,cv1800b-rtc.yaml        |  86 +++++++
 MAINTAINERS                                   |   2 +
 drivers/rtc/Kconfig                           |  12 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-cv1800.c                      | 218 ++++++++++++++++++
 drivers/soc/Kconfig                           |   1 +
 drivers/soc/Makefile                          |   1 +
 drivers/soc/sophgo/Kconfig                    |  24 ++
 drivers/soc/sophgo/Makefile                   |   3 +
 drivers/soc/sophgo/cv1800-rtcsys.c            |  63 +++++
 10 files changed, 411 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml
 create mode 100644 drivers/rtc/rtc-cv1800.c
 create mode 100644 drivers/soc/sophgo/Kconfig
 create mode 100644 drivers/soc/sophgo/Makefile
 create mode 100644 drivers/soc/sophgo/cv1800-rtcsys.c
Signature · 1 line
2.48.1
#1 lore raw

PATCH v13 1/3 dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series

From: Jingbao Qiu <[email protected]>

Add RTC devicetree binding for Sophgo CV1800 series SoC. The device is called RTC, but contains control registers of other HW blocks in its address space, most notably of Power-on-Reset (PoR) module, DW8051 IP (MCU core), accompanying SRAM, hence putting it in SoC subsystem.

---
Changelog:
v13:
- Moved bindings from MFD into SOC subsystem

v12:
- maintainer Jingbao Qiu <[email protected]> -> [email protected]
- dropped Reviewed-by: Krzysztof Kozlowski
- link to TRM
- mentioned 8051 core in the description
- binding is now MFD, not RTC
- added "syscon" compatible
- added "interrupt-names", "clock-names" (because of added PM/remoteproc)
- main compatible "sophgo,cv1800-rtc" -> "sophgo,cv1800b-rtc"

 .../soc/sophgo/sophgo,cv1800b-rtc.yaml        | 86 +++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml
Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml new file +86 -0
new file mode 100644
index 000000000000..5cf186c396c9
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sophgo/sophgo,cv1800b-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Real Time Clock of the Sophgo CV1800 SoC
+
+description:
+  The RTC (Real Time Clock) is an independently powered module in the chip. It
+  contains a 32KHz oscillator and a Power-On-Reset (POR) sub-module, which can
+  be used for time display and scheduled alarm produce. In addition, the
+  hardware state machine provides triggering and timing control for chip
+  power-on, power-off and reset.
+
+  Furthermore, the 8051 subsystem is located within RTCSYS and is independently
+  powered. System software can use the 8051 to manage wake conditions and wake
+  the system while the system is asleep, and communicate with external devices
+  through peripheral controllers.
+
+  Technical Reference Manual available at
+    https://github.com/sophgo/sophgo-doc/tree/main/SG200X/TRM
+
+maintainers:
+  - [email protected]
+
+allOf:
+  - $ref: /schemas/rtc/rtc.yaml#
+
+properties:
+  compatible:
+    items:
+      - const: sophgo,cv1800b-rtc
+      - const: syscon
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: RTC Alarm
+      - description: RTC Longpress
+      - description: VBAT DET
+
+  interrupt-names:
+    items:
+      - const: alarm
+      - const: longpress
+      - const: vbat
+
+  clocks:
+    items:
+      - description: RTC clock source
+      - description: DW8051 MCU clock source
+
+  clock-names:
+    items:
+      - const: rtc
+      - const: mcu
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - clocks
+  - clock-names
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sophgo,cv1800.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    rtc@5025000 {
+        compatible = "sophgo,cv1800b-rtc", "syscon";
+        reg = <0x5025000 0x2000>;
+        interrupts = <17 IRQ_TYPE_LEVEL_HIGH>,
+                     <18 IRQ_TYPE_LEVEL_HIGH>,
+                     <19 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "alarm", "longpress", "vbat";
+        clocks = <&clk CLK_RTC_25M>,
+                 <&clk CLK_SRC_RTC_SYS_0>;
+        clock-names = "rtc", "mcu";
+    };
Signature · 1 line
2.48.1
Reviewed-by on v13 1/3
#2 lore raw

Re: [PATCH v13 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series

Quoted 7 lines · Alexander Sverdlin

From: Jingbao Qiu <[email protected]>

Add RTC devicetree binding for Sophgo CV1800 series SoC. The device is called RTC, but contains control registers of other HW blocks in its address space, most notably of Power-on-Reset (PoR) module, DW8051 IP (MCU core), accompanying SRAM, hence putting it in SoC subsystem.

Quoted 6 lines

---
Changelog:
v13:
- Moved bindings from MFD into SOC subsystem

Best regards,
Krzysztof

maintainer
#3 lore raw

Re: [PATCH v13 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series

In reply to Alexander Sverdlin
Quoted 7 lines · Alexander Sverdlin

From: Jingbao Qiu <[email protected]>

Add RTC devicetree binding for Sophgo CV1800 series SoC. The device is called RTC, but contains control registers of other HW blocks in its address space, most notably of Power-on-Reset (PoR) module, DW8051 IP (MCU core), accompanying SRAM, hence putting it in SoC subsystem.

I think this is a mfd device, so why not moving this into mfd subsystem?

Regards,
Inochi

#4 lore raw

Re: [PATCH v13 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series

Hi Inochi!

Quoted 7 lines · Inochi Amaoto
Quoted 5 lines

Add RTC devicetree binding for Sophgo CV1800 series SoC. The device is called RTC, but contains control registers of other HW blocks in its address space, most notably of Power-on-Reset (PoR) module, DW8051 IP (MCU core), accompanying SRAM, hence putting it in SoC subsystem.

I think this is a mfd device, so why not moving this into mfd subsystem?

MFD is by far the most tricky subsystem to get into [1] ;-) SOC looks much more realistic [2]

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/20250303-loud-mauve-coyote-1eefbb@krzk-bin/

Signature · 1 line
Alexander Sverdlin.
maintainer Reviewed-by
#5 lore raw

Re: [PATCH v13 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series

Quoted 9 lines · Alexander Sverdlin

Hi Inochi!

Quoted 6 lines · Inochi Amaoto
Quoted 5 lines

Add RTC devicetree binding for Sophgo CV1800 series SoC. The device is called RTC, but contains control registers of other HW blocks in its address space, most notably of Power-on-Reset (PoR) module, DW8051 IP (MCU core), accompanying SRAM, hence putting it in SoC subsystem.

Quoted 8 lines
Quoted 1 line

I think this is a mfd device, so why not moving this into mfd subsystem?

MFD is by far the most tricky subsystem to get into [1] ;-) SOC looks much more realistic [2]

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/20250303-loud-mauve-coyote-1eefbb@krzk-bin/

Cool, let's keep it.

LGTM.

#6 lore raw

Re: [PATCH v13 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series

Quoted 13 lines · Inochi Amaoto
Quoted 12 lines · Alexander Sverdlin

Hi Inochi!

Quoted 6 lines · Inochi Amaoto
Quoted 5 lines

Add RTC devicetree binding for Sophgo CV1800 series SoC. The device is called RTC, but contains control registers of other HW blocks in its address space, most notably of Power-on-Reset (PoR) module, DW8051 IP (MCU core), accompanying SRAM, hence putting it in SoC subsystem.

I think this is a mfd device, so why not moving this into mfd subsystem?

MFD is by far the most tricky subsystem to get into [1] ;-) SOC looks much more realistic [2]

Quoted 8 lines
Quoted 3 lines

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/20250303-loud-mauve-coyote-1eefbb@krzk-bin/

Cool, let's keep it.

LGTM.

Hi, Inochi

I think you were not reviewing the latest version of this patchset. The latest version is v14 @https://lore.kernel.org/linux-rtc/[email protected]/

Chen

#7 lore raw

PATCH v13 2/3 soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

In reply to Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

---
Changelog:
v13:
- Moved the driver from MFD into SOC subsystem
- Dropped unused "cv1800_rtcsys_rtc_subdev"
v12:
- new patch

 MAINTAINERS                        |  1 +
 drivers/soc/Kconfig                |  1 +
 drivers/soc/Makefile               |  1 +
 drivers/soc/sophgo/Kconfig         | 24 ++++++++++++
 drivers/soc/sophgo/Makefile        |  3 ++
 drivers/soc/sophgo/cv1800-rtcsys.c | 63 ++++++++++++++++++++++++++++++
 6 files changed, 93 insertions(+)
 create mode 100644 drivers/soc/sophgo/Kconfig
 create mode 100644 drivers/soc/sophgo/Makefile
 create mode 100644 drivers/soc/sophgo/cv1800-rtcsys.c
MAINTAINERS +1 -0
index 3eee238c2ea2..ac15e448fffb 100644
@@ -22354,6 +22354,7 @@ L:	[email protected]
 W:	https://github.com/sophgo/linux/wiki
 T:	git https://github.com/sophgo/linux.git
 S:	Maintained
+F:	drivers/soc/sophgo/cv1800-rtcsys.c
 N:	sophgo
 K:	sophgo
 
drivers/soc/Kconfig +1 -0
index 6a8daeb8c4b9..11e2383c0654 100644
@@ -23,6 +23,7 @@ source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/renesas/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
+source "drivers/soc/sophgo/Kconfig"
 source "drivers/soc/sunxi/Kconfig"
 source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
drivers/soc/Makefile +1 -0
index 2037a8695cb2..0381a0abdec8 100644
@@ -29,6 +29,7 @@ obj-y				+= qcom/
 obj-y				+= renesas/
 obj-y				+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
+obj-y				+= sophgo/
 obj-y				+= sunxi/
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
 obj-y				+= ti/
drivers/soc/sophgo/Kconfig new file +24 -0
new file mode 100644
index 000000000000..e50666e423a9
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Sophgo/Cvitek SoC drivers
+#
+
+if ARCH_SOPHGO || COMPILE_TEST
+menu "Sophgo/Cvitek SoC drivers"
+
+config SOPHGO_CV1800_RTCSYS
+	tristate "Sophgo CV1800 RTC MFD"
+	default y if COMPILE_TEST
+	select MFD_CORE
+	help
+	  If you say yes here you get support the RTC MFD driver for Sophgo
+	  CV1800 series SoC. The RTC module comprises a 32kHz oscillator,
+	  Power-on-Reset (PoR) sub-module, HW state machine to control chip
+	  power-on, power-off and reset. Furthermore, the 8051 subsystem is
+	  located within RTCSYS including associated SRAM block.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called cv1800-rtcsys.
+
+endmenu
+endif
drivers/soc/sophgo/Makefile new file +3 -0
new file mode 100644
index 000000000000..8f22b4e79311
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_SOPHGO_CV1800_RTCSYS)	+= cv1800-rtcsys.o
drivers/soc/sophgo/cv1800-rtcsys.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.48.1
maintainer
#8 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Quoted 32 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

---
Changelog:
v13:
- Moved the driver from MFD into SOC subsystem
- Dropped unused "cv1800_rtcsys_rtc_subdev"
v12:
- new patch

 MAINTAINERS                        |  1 +
 drivers/soc/Kconfig                |  1 +
 drivers/soc/Makefile               |  1 +
 drivers/soc/sophgo/Kconfig         | 24 ++++++++++++
 drivers/soc/sophgo/Makefile        |  3 ++
 drivers/soc/sophgo/cv1800-rtcsys.c | 63 ++++++++++++++++++++++++++++++
 6 files changed, 93 insertions(+)
 create mode 100644 drivers/soc/sophgo/Kconfig
 create mode 100644 drivers/soc/sophgo/Makefile
 create mode 100644 drivers/soc/sophgo/cv1800-rtcsys.c
MAINTAINERS +0 -0
index 3eee238c2ea2..ac15e448fffb 100644

MAINTAINERS L: [email protected] · line 22358

Quoted 5 lines
MAINTAINERS +1 -0
@@ -22354,6 +22354,7 @@ L:	[email protected]
 W:	https://github.com/sophgo/linux/wiki
 T:	git https://github.com/sophgo/linux.git
 S:	Maintained
 
+F:	drivers/soc/sophgo/cv1800-rtcsys.c

Please change to the drivers/soc/sophgo/.
We should maintain all files under this.

Quoted 33 lines
MAINTAINERS +0 -0
 N:	sophgo
 K:	sophgo
drivers/soc/Kconfig +1 -0
index 6a8daeb8c4b9..11e2383c0654 100644
@@ -23,6 +23,7 @@ source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/renesas/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
+source "drivers/soc/sophgo/Kconfig"
 source "drivers/soc/sunxi/Kconfig"
 source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
drivers/soc/Makefile +1 -0
index 2037a8695cb2..0381a0abdec8 100644
@@ -29,6 +29,7 @@ obj-y				+= qcom/
 obj-y				+= renesas/
 obj-y				+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
+obj-y				+= sophgo/
 obj-y				+= sunxi/
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
 obj-y				+= ti/
drivers/soc/sophgo/Kconfig new file +0 -0
new file mode 100644
index 000000000000..e50666e423a9

drivers/soc/sophgo/Kconfig line 7

Quoted 8 lines
drivers/soc/sophgo/Kconfig new file +7 -0
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Sophgo/Cvitek SoC drivers
+#
+
+if ARCH_SOPHGO || COMPILE_TEST
 
+menu "Sophgo/Cvitek SoC drivers"

No Cvitek, only left Sophgo here.

drivers/soc/sophgo/Kconfig line 11

Quoted 5 lines
drivers/soc/sophgo/Kconfig new file +4 -0
+
+config SOPHGO_CV1800_RTCSYS
+	tristate "Sophgo CV1800 RTC MFD"
 
+	default y if COMPILE_TEST

I do not think it is necessary.

Quoted 43 lines
drivers/soc/sophgo/Kconfig new file +13 -0
+	select MFD_CORE
+	help
+	  If you say yes here you get support the RTC MFD driver for Sophgo
+	  CV1800 series SoC. The RTC module comprises a 32kHz oscillator,
+	  Power-on-Reset (PoR) sub-module, HW state machine to control chip
+	  power-on, power-off and reset. Furthermore, the 8051 subsystem is
+	  located within RTCSYS including associated SRAM block.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called cv1800-rtcsys.
+
+endmenu
+endif
drivers/soc/sophgo/Makefile new file +3 -0
new file mode 100644
index 000000000000..8f22b4e79311
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_SOPHGO_CV1800_RTCSYS)	+= cv1800-rtcsys.o
drivers/soc/sophgo/cv1800-rtcsys.c new file +15 -0
new file mode 100644
index 000000000000..cb271f02afcc
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Sophgo CV1800 series SoC RTC subsystem
+ *
+ * The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module,
+ * HW state machine to control chip power-on, power-off and reset. Furthermore,
+ * the 8051 subsystem is located within RTCSYS including associated SRAM block.
+ *
+ * Copyright (C) 2025 Alexander Sverdlin <[email protected]>
+ *
+ */
+
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of.h>

drivers/soc/sophgo/cv1800-rtcsys.c line 24

Quoted 10 lines
drivers/soc/sophgo/cv1800-rtcsys.c new file +9 -0
+#include <linux/property.h>
+
+static struct resource cv1800_rtcsys_irq_resources[] = {
+	DEFINE_RES_IRQ_NAMED(0, "alarm"),
+};
+
+static const struct mfd_cell cv1800_rtcsys_subdev[] = {
+	{
 
+		.name = "cv1800-rtc",

Make this a specifc one, like "sophgo,cv1800b-rtc"

Quoted 42 lines
drivers/soc/sophgo/cv1800-rtcsys.c new file +39 -0
+		.num_resources = 1,
+		.resources = &cv1800_rtcsys_irq_resources[0],
+	},
+};
+
+static int cv1800_rtcsys_probe(struct platform_device *pdev)
+{
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "alarm");
+	if (irq < 0)
+		return irq;
+	cv1800_rtcsys_irq_resources[0].start = irq;
+	cv1800_rtcsys_irq_resources[0].end = irq;
+
+	return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
+				    cv1800_rtcsys_subdev,
+				    ARRAY_SIZE(cv1800_rtcsys_subdev),
+				    NULL, 0, NULL);
+}
+
+static const struct of_device_id cv1800_rtcsys_of_match[] = {
+	{ .compatible = "sophgo,cv1800b-rtc" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, cv1800_rtcsys_of_match);
+
+static struct platform_driver cv1800_rtcsys_mfd = {
+	.probe	= cv1800_rtcsys_probe,
+	.driver	= {
+		.name		= "cv1800_rtcsys",
+		.of_match_table	= cv1800_rtcsys_of_match,
+	},
+};
+module_platform_driver(cv1800_rtcsys_mfd);
+
+MODULE_AUTHOR("Alexander Sverdlin <[email protected]>");
+MODULE_DESCRIPTION("Sophgo CV1800 series SoC RTC subsystem driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.48.1
#9 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Hi Inochi!

Quoted 8 lines · Inochi Amaoto
Quoted 7 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

...

Quoted 26 lines
Quoted 25 lines

+++ b/drivers/soc/sophgo/cv1800-rtcsys.c

drivers/soc/sophgo/cv1800-rtcsys.c new file +23 -0
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Sophgo CV1800 series SoC RTC subsystem
+ *
+ * The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module,
+ * HW state machine to control chip power-on, power-off and reset. Furthermore,
+ * the 8051 subsystem is located within RTCSYS including associated SRAM block.
+ *
+ * Copyright (C) 2025 Alexander Sverdlin <[email protected]>
+ *
+ */
+
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/property.h>
+
+static struct resource cv1800_rtcsys_irq_resources[] = {
+	DEFINE_RES_IRQ_NAMED(0, "alarm"),
+};
+
+static const struct mfd_cell cv1800_rtcsys_subdev[] = {
+	{
Quoted 3 lines

drivers/soc/sophgo/cv1800-rtcsys.c line 24

Quoted 1 line
drivers/soc/sophgo/cv1800-rtcsys.c new file +1 -0
+		.name = "cv1800-rtc",

Make this a specifc one, like "sophgo,cv1800b-rtc"

Could it be that you mixed up device instance name and "compatible"?

Please refer to all other MFD cells with grep -C3 -R -F "struct mfd_cell" either in drivers/soc or in drivers/mfd, there are no vendor prefixes in the names.

Signature · 1 line
Alexander Sverdlin.
maintainer
#10 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Quoted 44 lines · Alexander Sverdlin

Hi Inochi!

Quoted 8 lines · Inochi Amaoto
Quoted 7 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

...

Quoted 26 lines
Quoted 25 lines

+++ b/drivers/soc/sophgo/cv1800-rtcsys.c

drivers/soc/sophgo/cv1800-rtcsys.c new file +23 -0
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Sophgo CV1800 series SoC RTC subsystem
+ *
+ * The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module,
+ * HW state machine to control chip power-on, power-off and reset. Furthermore,
+ * the 8051 subsystem is located within RTCSYS including associated SRAM block.
+ *
+ * Copyright (C) 2025 Alexander Sverdlin <[email protected]>
+ *
+ */
+
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/property.h>
+
+static struct resource cv1800_rtcsys_irq_resources[] = {
+	DEFINE_RES_IRQ_NAMED(0, "alarm"),
+};
+
+static const struct mfd_cell cv1800_rtcsys_subdev[] = {
+	{
Quoted 3 lines

drivers/soc/sophgo/cv1800-rtcsys.c line 24

Quoted 1 line
drivers/soc/sophgo/cv1800-rtcsys.c new file +1 -0
+		.name = "cv1800-rtc",

Make this a specifc one, like "sophgo,cv1800b-rtc"

Quoted 6 lines

Could it be that you mixed up device instance name and "compatible"?

Please refer to all other MFD cells with grep -C3 -R -F "struct mfd_cell" either in drivers/soc or in drivers/mfd, there are no vendor prefixes in the names.

Yeah, I misunderstand this, but at least please specific name as "cv1800b-rtc". This is more accuracy.

Regards,
Inochi

#11 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

In reply to Inochi Amaoto

Hey, Alexander

Quoted 28 lines · Inochi Amaoto
Quoted 27 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

---
Changelog:
v13:
- Moved the driver from MFD into SOC subsystem
- Dropped unused "cv1800_rtcsys_rtc_subdev"
v12:
- new patch

  MAINTAINERS                        |  1 +
  drivers/soc/Kconfig                |  1 +
  drivers/soc/Makefile               |  1 +
  drivers/soc/sophgo/Kconfig         | 24 ++++++++++++
  drivers/soc/sophgo/Makefile        |  3 ++
  drivers/soc/sophgo/cv1800-rtcsys.c | 63 ++++++++++++++++++++++++++++++
  6 files changed, 93 insertions(+)

create mode 100644 drivers/soc/sophgo/Kconfig create mode 100644 drivers/soc/sophgo/Makefile create mode 100644 drivers/soc/sophgo/cv1800-rtcsys.c

Quoted 11 lines

MAINTAINERS L: [email protected] · line 22357

Quoted 9 lines
MAINTAINERS +1 -0
index 3eee238c2ea2..ac15e448fffb 100644
@@ -22354,6 +22354,7 @@ L:	[email protected]
  W:	https://github.com/sophgo/linux/wiki
  T:	git https://github.com/sophgo/linux.git
  S:	Maintained
+F:	drivers/soc/sophgo/cv1800-rtcsys.c

Please change to the drivers/soc/sophgo/.
We should maintain all files under this.

In addition to what Inochi mentioned, please add the following line:

F:    Documentation/devicetree/bindings/soc/sophgo/

Thanks,

Chen

[......]

#12 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Hi Chen!

Quoted 10 lines · Chen Wang
Quoted 9 lines
Quoted 7 lines
MAINTAINERS +0 -0
@@ -22354,6 +22354,7 @@ L:	[email protected]

   W: https://github.com/sophgo/linux/wiki
   T: git https://github.com/sophgo/linux.git
   S: Maintained
+F: drivers/soc/sophgo/cv1800-rtcsys.c

Please change to the drivers/soc/sophgo/.
We should maintain all files under this.

Quoted 3 lines

In addition to what Inochi mentioned, please add the following line:

F:    Documentation/devicetree/bindings/soc/sophgo/

Isn't it already covered by the existing "N: sophgo" entry?

Signature · 1 line
Alexander Sverdlin.
#13 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Quoted 12 lines · Alexander Sverdlin

Hi Chen!

Quoted 9 lines · Chen Wang
Quoted 9 lines

MAINTAINERS L: [email protected] · line 22357

Quoted 7 lines
MAINTAINERS +1 -0
@@ -22354,6 +22354,7 @@ L:	[email protected]
    W:	https://github.com/sophgo/linux/wiki
    T:	git https://github.com/sophgo/linux.git
    S:	Maintained
+F:	drivers/soc/sophgo/cv1800-rtcsys.c

Please change to the drivers/soc/sophgo/.
We should maintain all files under this.

Quoted 4 lines
Quoted 3 lines

In addition to what Inochi mentioned, please add the following line:

F:    Documentation/devicetree/bindings/soc/sophgo/

Isn't it already covered by the existing "N: sophgo" entry?

Ok,  just ignore my comment.

Thanks,

Chen

Quoted 1 line
#14 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

In reply to Inochi Amaoto

Hi Inochi!

Quoted 9 lines · Inochi Amaoto
Quoted 8 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

...

Quoted 21 lines
Quoted 20 lines

  MAINTAINERS                        |  1 + drivers/soc/Kconfig                |  1 + drivers/soc/Makefile               |  1 + drivers/soc/sophgo/Kconfig         | 24 ++++++++++++ drivers/soc/sophgo/Makefile        |  3 ++ drivers/soc/sophgo/cv1800-rtcsys.c | 63 ++++++++++++++++++++++++++++++

  6 files changed, 93 insertions(+)

  create mode 100644 drivers/soc/sophgo/Kconfig create mode 100644 drivers/soc/sophgo/Makefile create mode 100644 drivers/soc/sophgo/cv1800-rtcsys.c

MAINTAINERS +0 -0
index 3eee238c2ea2..ac15e448fffb 100644
@@ -22354,6 +22354,7 @@ L:	[email protected]

  W: https://github.com/sophgo/linux/wiki
  T: git https://github.com/sophgo/linux.git
  S: Maintained

Quoted 6 lines
Quoted 1 line

+F: drivers/soc/sophgo/cv1800-rtcsys.c

Please change to the drivers/soc/sophgo/.
We should maintain all files under this.

Quoted 1 line

  N: sophgo

I suppose my F: entry is actually superfluous because of the above
N: entry and can be removed altogether?

Signature · 1 line
Alexander Sverdlin.
maintainer
#15 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Quoted 38 lines · Alexander Sverdlin

Hi Inochi!

Quoted 9 lines · Inochi Amaoto
Quoted 8 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

...

Quoted 23 lines
Quoted 22 lines

  MAINTAINERS                        |  1 + drivers/soc/Kconfig                |  1 + drivers/soc/Makefile               |  1 + drivers/soc/sophgo/Kconfig         | 24 ++++++++++++ drivers/soc/sophgo/Makefile        |  3 ++ drivers/soc/sophgo/cv1800-rtcsys.c | 63 ++++++++++++++++++++++++++++++

  6 files changed, 93 insertions(+)

  create mode 100644 drivers/soc/sophgo/Kconfig create mode 100644 drivers/soc/sophgo/Makefile create mode 100644 drivers/soc/sophgo/cv1800-rtcsys.c

MAINTAINERS +0 -0
index 3eee238c2ea2..ac15e448fffb 100644
@@ -22354,6 +22354,7 @@ L:	[email protected]

  W: https://github.com/sophgo/linux/wiki
  T: git https://github.com/sophgo/linux.git
  S: Maintained

+F: drivers/soc/sophgo/cv1800-rtcsys.c

Quoted 8 lines
Quoted 4 lines

Please change to the drivers/soc/sophgo/.
We should maintain all files under this.

Quoted 1 line

  N: sophgo

I suppose my F: entry is actually superfluous because of the above
N: entry and can be removed altogether?

It is fine to tell others we do maintain these files, so it is fine for me to keep the entry point to "drivers/soc/sophgo/".

Regards,
Inochi

#16 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

In reply to Inochi Amaoto

Hi Inochi!

Quoted 9 lines · Inochi Amaoto
Quoted 8 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

...

Quoted 13 lines

drivers/soc/sophgo/Kconfig line 7

Quoted 10 lines

+++ b/drivers/soc/sophgo/Kconfig

drivers/soc/sophgo/Kconfig new file +7 -0
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Sophgo/Cvitek SoC drivers
+#
+
+if ARCH_SOPHGO || COMPILE_TEST
 
+menu "Sophgo/Cvitek SoC drivers"

No Cvitek, only left Sophgo here.

Quoted 7 lines

drivers/soc/sophgo/Kconfig line 11

Quoted 5 lines
drivers/soc/sophgo/Kconfig new file +4 -0
+
+config SOPHGO_CV1800_RTCSYS
+	tristate "Sophgo CV1800 RTC MFD"
 
+	default y if COMPILE_TEST

I do not think it is necessary.

Maybe it should have been

tristate "Sophgo CV1800 RTC MFD" if COMPILE_TEST

like others do?

Signature · 1 line
Alexander Sverdlin.
maintainer
#17 lore raw

Re: [PATCH v13 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)

Quoted 36 lines · Alexander Sverdlin

Hi Inochi!

Quoted 9 lines · Inochi Amaoto
Quoted 8 lines · Alexander Sverdlin

Add driver for Sophgo CV1800 series SoC RTC subsystem. The RTC module comprises a 32kHz oscillator, Power-on-Reset (PoR) sub-module, HW state machine to control chip power-on, power-off and reset. Furthermore, the 8051 subsystem is located within RTCSYS including associated SRAM block.

This patch only populates RTC sub-device.

...

Quoted 13 lines

drivers/soc/sophgo/Kconfig line 7

Quoted 10 lines

+++ b/drivers/soc/sophgo/Kconfig

drivers/soc/sophgo/Kconfig new file +7 -0
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Sophgo/Cvitek SoC drivers
+#
+
+if ARCH_SOPHGO || COMPILE_TEST
 
+menu "Sophgo/Cvitek SoC drivers"

No Cvitek, only left Sophgo here.

Quoted 7 lines

drivers/soc/sophgo/Kconfig line 11

Quoted 5 lines
drivers/soc/sophgo/Kconfig new file +4 -0
+
+config SOPHGO_CV1800_RTCSYS
+	tristate "Sophgo CV1800 RTC MFD"
 
+	default y if COMPILE_TEST

I do not think it is necessary.

Quoted 6 lines

Maybe it should have been

tristate "Sophgo CV1800 RTC MFD" if COMPILE_TEST

like others do?

No, you needn't. The first line "if ARCH_SOPHGO || COMPILE_TEST" already does the expected things. This is equal to remove this "if" and add a line "depends on ARCH_SOPHGO || COMPILE_TEST" to this entry. Just remove the default line, and everything is OK.

Regards,
Inochi

#18 lore raw

PATCH v13 3/3 rtc: sophgo: add rtc support for Sophgo CV1800 SoC

In reply to Alexander Sverdlin

From: Jingbao Qiu <[email protected]>

Implement the RTC driver for CV1800, which able to provide time alarm.

---
Changelog:
v13:
- Change in the Kconfig dependency caused by the move of the previous patch from MFD into SOC
v12:
- added MAINTAINERS entry
- depends on cv1800-rtcsys MFD driver
- use syscon for regmap
- get named clock from parent MFD
- corresponding platform device is expected to be instantiated by MFD stub Changes since v10:
- only start RTC on set_time;
Changes since v9:
- further simplified bitmask macros;
- unconditional RTC start (rtc_enable_sec_counter()), otherwise didn't start on SG2000;
- dropped ANA_CALIB modification (has been forgotten in v8 with the drop of SW calibration to switch to HW calibration);
- successfully tested on SG2000;

 MAINTAINERS              |   1 +
 drivers/rtc/Kconfig      |  12 +++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-cv1800.c | 218 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 drivers/rtc/rtc-cv1800.c
MAINTAINERS +1 -0
index ac15e448fffb..be8fee50a49c 100644
@@ -22354,6 +22354,7 @@ L:	[email protected]
 W:	https://github.com/sophgo/linux/wiki
 T:	git https://github.com/sophgo/linux.git
 S:	Maintained
+F:	drivers/rtc/rtc-cv1800.c
 F:	drivers/soc/sophgo/cv1800-rtcsys.c
 N:	sophgo
 K:	sophgo
drivers/rtc/Kconfig +12 -0
index 0bbbf778ecfa..46593103db11 100644
@@ -1395,6 +1395,18 @@ config RTC_DRV_ASM9260
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-asm9260.
 
+config RTC_DRV_CV1800
+	tristate "Sophgo CV1800 RTC"
+	depends on SOPHGO_CV1800_RTCSYS || COMPILE_TEST
+	select MFD_SYSCON
+	select REGMAP
+	help
+	  If you say yes here you get support the RTC driver for Sophgo CV1800
+	  series SoC.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called rtc-cv1800.
+
 config RTC_DRV_DIGICOLOR
 	tristate "Conexant Digicolor RTC"
 	depends on ARCH_DIGICOLOR || COMPILE_TEST
drivers/rtc/Makefile +1 -0
index 489b4ab07068..621b30a33dda 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_RTC_DRV_CADENCE)	+= rtc-cadence.o
 obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_CPCAP)	+= rtc-cpcap.o
 obj-$(CONFIG_RTC_DRV_CROS_EC)	+= rtc-cros-ec.o
+obj-$(CONFIG_RTC_DRV_CV1800)	+= rtc-cv1800.o
 obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)	+= rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)	+= rtc-da9063.o
drivers/rtc/rtc-cv1800.c new file +218 -0

218 lines not on this page · raw message

Signature · 1 line
2.48.1