* [PATCH v14 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series
2025-03-15 22:49 [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800 Alexander Sverdlin
@ 2025-03-15 22:49 ` Alexander Sverdlin
2025-04-10 5:45 ` Inochi Amaoto
2025-03-15 22:49 ` [PATCH v14 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only) Alexander Sverdlin
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Alexander Sverdlin @ 2025-03-15 22:49 UTC (permalink / raw)
To: sophgo, devicetree, linux-rtc
Cc: Jingbao Qiu, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chen Wang, Inochi Amaoto, Alexandre Belloni, Arnd Bergmann,
Yangyu Chen, linux-kernel, Alexander Sverdlin,
Krzysztof Kozlowski
From: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
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.
Signed-off-by: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Changelog:
v14:
- no changes
v13:
- Moved bindings from MFD into SOC subsystem
v12:
- maintainer Jingbao Qiu <qiujingbao.dlmu@gmail.com> -> sophgo@lists.linux.dev
- 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
diff --git a/Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml b/Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml
new file mode 100644
index 000000000000..5cf186c396c9
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml
@@ -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:
+ - sophgo@lists.linux.dev
+
+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";
+ };
--
2.48.1
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v14 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series
2025-03-15 22:49 ` [PATCH v14 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series Alexander Sverdlin
@ 2025-04-10 5:45 ` Inochi Amaoto
0 siblings, 0 replies; 10+ messages in thread
From: Inochi Amaoto @ 2025-04-10 5:45 UTC (permalink / raw)
To: Alexander Sverdlin, sophgo, devicetree, linux-rtc
Cc: Jingbao Qiu, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chen Wang, Inochi Amaoto, Alexandre Belloni, Arnd Bergmann,
Yangyu Chen, linux-kernel, Krzysztof Kozlowski
On Sat, Mar 15, 2025 at 11:49:12PM +0100, Alexander Sverdlin wrote:
> From: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
>
> 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.
>
> Signed-off-by: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> Changelog:
> v14:
> - no changes
> v13:
> - Moved bindings from MFD into SOC subsystem
>
> v12:
> - maintainer Jingbao Qiu <qiujingbao.dlmu@gmail.com> -> sophgo@lists.linux.dev
> - 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
LGTM.
Reviewed-by: Inochi Amaoto <inochiama@gmail.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v14 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)
2025-03-15 22:49 [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800 Alexander Sverdlin
2025-03-15 22:49 ` [PATCH v14 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series Alexander Sverdlin
@ 2025-03-15 22:49 ` Alexander Sverdlin
2025-04-10 5:44 ` Inochi Amaoto
2025-03-15 22:49 ` [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC Alexander Sverdlin
2025-05-07 0:41 ` (subset) [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800 Inochi Amaoto
3 siblings, 1 reply; 10+ messages in thread
From: Alexander Sverdlin @ 2025-03-15 22:49 UTC (permalink / raw)
To: sophgo, devicetree, linux-rtc
Cc: Alexander Sverdlin, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Chen Wang, Inochi Amaoto, Alexandre Belloni,
Jingbao Qiu, Arnd Bergmann, Yangyu Chen, linux-kernel
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.
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
---
Changelog:
v14:
- Dropped MAINTAINERS F: entry in favour of the existing N: entry
- mfd_cell name "cv1800-rtc" -> "cv1800b-rtc"
- Removed Cvitek brand from Kconfig
- Not built by default if COMPILE_TEST
v13:
- Moved the driver from MFD into SOC subsystem
- Dropped unused "cv1800_rtcsys_rtc_subdev"
v12:
- new patch
drivers/soc/Kconfig | 1 +
drivers/soc/Makefile | 1 +
drivers/soc/sophgo/Kconfig | 23 ++++++++++++
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
diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 6a8daeb8c4b9..11e2383c0654 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -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"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 2037a8695cb2..0381a0abdec8 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -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/
diff --git a/drivers/soc/sophgo/Kconfig b/drivers/soc/sophgo/Kconfig
new file mode 100644
index 000000000000..e50666e423a9
--- /dev/null
+++ b/drivers/soc/sophgo/Kconfig
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Sophgo SoC drivers
+#
+
+if ARCH_SOPHGO || COMPILE_TEST
+menu "Sophgo SoC drivers"
+
+config SOPHGO_CV1800_RTCSYS
+ tristate "Sophgo CV1800 RTC MFD"
+ 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
diff --git a/drivers/soc/sophgo/Makefile b/drivers/soc/sophgo/Makefile
new file mode 100644
index 000000000000..8f22b4e79311
--- /dev/null
+++ b/drivers/soc/sophgo/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_SOPHGO_CV1800_RTCSYS) += cv1800-rtcsys.o
diff --git a/drivers/soc/sophgo/cv1800-rtcsys.c b/drivers/soc/sophgo/cv1800-rtcsys.c
new file mode 100644
index 000000000000..cb271f02afcc
--- /dev/null
+++ b/drivers/soc/sophgo/cv1800-rtcsys.c
@@ -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 <alexander.sverdlin@gmail.com>
+ *
+ */
+
+#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[] = {
+ {
+ .name = "cv1800b-rtc",
+ .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 <alexander.sverdlin@gmail.com>");
+MODULE_DESCRIPTION("Sophgo CV1800 series SoC RTC subsystem driver");
+MODULE_LICENSE("GPL");
--
2.48.1
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v14 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)
2025-03-15 22:49 ` [PATCH v14 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only) Alexander Sverdlin
@ 2025-04-10 5:44 ` Inochi Amaoto
0 siblings, 0 replies; 10+ messages in thread
From: Inochi Amaoto @ 2025-04-10 5:44 UTC (permalink / raw)
To: Alexander Sverdlin, sophgo, devicetree, linux-rtc
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen Wang,
Inochi Amaoto, Alexandre Belloni, Jingbao Qiu, Arnd Bergmann,
Yangyu Chen, linux-kernel
On Sat, Mar 15, 2025 at 11:49:13PM +0100, Alexander Sverdlin wrote:
> 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.
>
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
> ---
> Changelog:
> v14:
> - Dropped MAINTAINERS F: entry in favour of the existing N: entry
> - mfd_cell name "cv1800-rtc" -> "cv1800b-rtc"
> - Removed Cvitek brand from Kconfig
> - Not built by default if COMPILE_TEST
> v13:
> - Moved the driver from MFD into SOC subsystem
> - Dropped unused "cv1800_rtcsys_rtc_subdev"
> v12:
> - new patch
>
> drivers/soc/Kconfig | 1 +
> drivers/soc/Makefile | 1 +
> drivers/soc/sophgo/Kconfig | 23 ++++++++++++
> 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
>
LGTM.
Reviewed-by: Inochi Amaoto <inochiama@gmail.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC
2025-03-15 22:49 [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800 Alexander Sverdlin
2025-03-15 22:49 ` [PATCH v14 1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series Alexander Sverdlin
2025-03-15 22:49 ` [PATCH v14 2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only) Alexander Sverdlin
@ 2025-03-15 22:49 ` Alexander Sverdlin
2025-03-19 0:31 ` Chen Wang
2025-05-07 0:41 ` (subset) [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800 Inochi Amaoto
3 siblings, 1 reply; 10+ messages in thread
From: Alexander Sverdlin @ 2025-03-15 22:49 UTC (permalink / raw)
To: sophgo, devicetree, linux-rtc
Cc: Jingbao Qiu, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chen Wang, Inochi Amaoto, Alexandre Belloni, Arnd Bergmann,
Yangyu Chen, linux-kernel, Alexander Sverdlin
From: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
Implement the RTC driver for CV1800, which able to provide time alarm.
Signed-off-by: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
---
Changelog:
v14:
- platform device name "cv1800-rtc" -> "cv1800b-rtc"
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
diff --git a/MAINTAINERS b/MAINTAINERS
index ac15e448fffb..be8fee50a49c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -22354,6 +22354,7 @@ L: sophgo@lists.linux.dev
W: https://github.com/sophgo/linux/wiki
T: git https://github.com/sophgo/linux.git
S: Maintained
+F: drivers/rtc/rtc-cv1800.c
N: sophgo
K: sophgo
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 0bbbf778ecfa..46593103db11 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -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
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 489b4ab07068..621b30a33dda 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -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
diff --git a/drivers/rtc/rtc-cv1800.c b/drivers/rtc/rtc-cv1800.c
new file mode 100644
index 000000000000..18bc542bbdb8
--- /dev/null
+++ b/drivers/rtc/rtc-cv1800.c
@@ -0,0 +1,218 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * rtc-cv1800.c: RTC driver for Sophgo cv1800 RTC
+ *
+ * Author: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
+ */
+
+#include <linux/clk.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+
+#define SEC_PULSE_GEN 0x1004
+#define ALARM_TIME 0x1008
+#define ALARM_ENABLE 0x100C
+#define SET_SEC_CNTR_VAL 0x1010
+#define SET_SEC_CNTR_TRIG 0x1014
+#define SEC_CNTR_VAL 0x1018
+
+/*
+ * When in VDDBKUP domain, this MACRO register
+ * does not power down
+ */
+#define MACRO_RO_T 0x14A8
+#define MACRO_RG_SET_T 0x1498
+
+#define ALARM_ENABLE_MASK BIT(0)
+#define SEL_SEC_PULSE BIT(31)
+
+struct cv1800_rtc_priv {
+ struct rtc_device *rtc_dev;
+ struct regmap *rtc_map;
+ struct clk *clk;
+ int irq;
+};
+
+static bool cv1800_rtc_enabled(struct device *dev)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+ u32 reg;
+
+ regmap_read(info->rtc_map, SEC_PULSE_GEN, ®);
+
+ return (reg & SEL_SEC_PULSE) == 0;
+}
+
+static void cv1800_rtc_enable(struct device *dev)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+
+ /* Sec pulse generated internally */
+ regmap_update_bits(info->rtc_map, SEC_PULSE_GEN, SEL_SEC_PULSE, 0);
+}
+
+static int cv1800_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+
+ regmap_write(info->rtc_map, ALARM_ENABLE, enabled);
+
+ return 0;
+}
+
+static int cv1800_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+ unsigned long alarm_time;
+
+ alarm_time = rtc_tm_to_time64(&alrm->time);
+
+ cv1800_rtc_alarm_irq_enable(dev, 0);
+
+ regmap_write(info->rtc_map, ALARM_TIME, alarm_time);
+
+ cv1800_rtc_alarm_irq_enable(dev, alrm->enabled);
+
+ return 0;
+}
+
+static int cv1800_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+ u32 enabled;
+ u32 time;
+
+ if (!cv1800_rtc_enabled(dev)) {
+ alarm->enabled = 0;
+ return 0;
+ }
+
+ regmap_read(info->rtc_map, ALARM_ENABLE, &enabled);
+
+ alarm->enabled = enabled & ALARM_ENABLE_MASK;
+
+ regmap_read(info->rtc_map, ALARM_TIME, &time);
+
+ rtc_time64_to_tm(time, &alarm->time);
+
+ return 0;
+}
+
+static int cv1800_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+ u32 sec;
+
+ if (!cv1800_rtc_enabled(dev))
+ return -EINVAL;
+
+ regmap_read(info->rtc_map, SEC_CNTR_VAL, &sec);
+
+ rtc_time64_to_tm(sec, tm);
+
+ return 0;
+}
+
+static int cv1800_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct cv1800_rtc_priv *info = dev_get_drvdata(dev);
+ unsigned long sec;
+
+ sec = rtc_tm_to_time64(tm);
+
+ regmap_write(info->rtc_map, SET_SEC_CNTR_VAL, sec);
+ regmap_write(info->rtc_map, SET_SEC_CNTR_TRIG, 1);
+
+ regmap_write(info->rtc_map, MACRO_RG_SET_T, sec);
+
+ cv1800_rtc_enable(dev);
+
+ return 0;
+}
+
+static irqreturn_t cv1800_rtc_irq_handler(int irq, void *dev_id)
+{
+ struct cv1800_rtc_priv *info = dev_id;
+
+ rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
+
+ regmap_write(info->rtc_map, ALARM_ENABLE, 0);
+
+ return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops cv1800_rtc_ops = {
+ .read_time = cv1800_rtc_read_time,
+ .set_time = cv1800_rtc_set_time,
+ .read_alarm = cv1800_rtc_read_alarm,
+ .set_alarm = cv1800_rtc_set_alarm,
+ .alarm_irq_enable = cv1800_rtc_alarm_irq_enable,
+};
+
+static int cv1800_rtc_probe(struct platform_device *pdev)
+{
+ struct cv1800_rtc_priv *rtc;
+ int ret;
+
+ rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+ if (!rtc)
+ return -ENOMEM;
+
+ rtc->rtc_map = device_node_to_regmap(pdev->dev.parent->of_node);
+ if (IS_ERR(rtc->rtc_map))
+ return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtc_map),
+ "cannot get parent regmap\n");
+
+ rtc->irq = platform_get_irq(pdev, 0);
+ if (rtc->irq < 0)
+ return rtc->irq;
+
+ rtc->clk = devm_clk_get_enabled(pdev->dev.parent, "rtc");
+ if (IS_ERR(rtc->clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(rtc->clk),
+ "rtc clk not found\n");
+
+ platform_set_drvdata(pdev, rtc);
+
+ device_init_wakeup(&pdev->dev, 1);
+
+ rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+ if (IS_ERR(rtc->rtc_dev))
+ return PTR_ERR(rtc->rtc_dev);
+
+ rtc->rtc_dev->ops = &cv1800_rtc_ops;
+ rtc->rtc_dev->range_max = U32_MAX;
+
+ ret = devm_request_irq(&pdev->dev, rtc->irq, cv1800_rtc_irq_handler,
+ IRQF_TRIGGER_HIGH, "rtc alarm", rtc);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "cannot register interrupt handler\n");
+
+ return devm_rtc_register_device(rtc->rtc_dev);
+}
+
+static const struct platform_device_id cv1800_rtc_id[] = {
+ { .name = "cv1800b-rtc" },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(platform, cv1800_rtc_id);
+
+static struct platform_driver cv1800_rtc_driver = {
+ .driver = {
+ .name = "sophgo-cv1800-rtc",
+ },
+ .probe = cv1800_rtc_probe,
+ .id_table = cv1800_rtc_id,
+};
+
+module_platform_driver(cv1800_rtc_driver);
+MODULE_AUTHOR("Jingbao Qiu");
+MODULE_DESCRIPTION("Sophgo cv1800 RTC Driver");
+MODULE_LICENSE("GPL");
--
2.48.1
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC
2025-03-15 22:49 ` [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC Alexander Sverdlin
@ 2025-03-19 0:31 ` Chen Wang
2025-03-19 0:43 ` Inochi Amaoto
2025-04-14 9:14 ` Chen Wang
0 siblings, 2 replies; 10+ messages in thread
From: Chen Wang @ 2025-03-19 0:31 UTC (permalink / raw)
To: Inochi Amaoto
Cc: Jingbao Qiu, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Alexandre Belloni, Arnd Bergmann, Yangyu Chen, linux-kernel,
Alexander Sverdlin, sophgo, devicetree, linux-rtc
Hi, Inochi,
I see Alexander add "drivers/rtc/rtc-cv1800.c" in "SOPHGO DEVICETREES
and DRIVERS" of MAINTAINERS, would you like to take this?
Regards,
Chen
On 2025/3/16 6:49, Alexander Sverdlin wrote:
> From: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
>
> Implement the RTC driver for CV1800, which able to provide time alarm.
>
> Signed-off-by: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
> ---
> Changelog:
> v14:
> - platform device name "cv1800-rtc" -> "cv1800b-rtc"
> 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
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index ac15e448fffb..be8fee50a49c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -22354,6 +22354,7 @@ L: sophgo@lists.linux.dev
> W: https://github.com/sophgo/linux/wiki
> T: git https://github.com/sophgo/linux.git
> S: Maintained
> +F: drivers/rtc/rtc-cv1800.c
> N: sophgo
> K: sophgo
[......]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC
2025-03-19 0:31 ` Chen Wang
@ 2025-03-19 0:43 ` Inochi Amaoto
2025-04-14 9:14 ` Chen Wang
1 sibling, 0 replies; 10+ messages in thread
From: Inochi Amaoto @ 2025-03-19 0:43 UTC (permalink / raw)
To: Chen Wang, Inochi Amaoto
Cc: Jingbao Qiu, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Alexandre Belloni, Arnd Bergmann, Yangyu Chen, linux-kernel,
Alexander Sverdlin, sophgo, devicetree, linux-rtc
On Wed, Mar 19, 2025 at 08:31:11AM +0800, Chen Wang wrote:
> Hi, Inochi,
>
> I see Alexander add "drivers/rtc/rtc-cv1800.c" in "SOPHGO DEVICETREES and
> DRIVERS" of MAINTAINERS, would you like to take this?
>
> Regards,
>
> Chen
>
If it is not covered by our entry. It is fine for me to take it.
Regards,
Inochi
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC
2025-03-19 0:31 ` Chen Wang
2025-03-19 0:43 ` Inochi Amaoto
@ 2025-04-14 9:14 ` Chen Wang
1 sibling, 0 replies; 10+ messages in thread
From: Chen Wang @ 2025-04-14 9:14 UTC (permalink / raw)
To: Alexander Sverdlin, Alexandre Belloni
Cc: Jingbao Qiu, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Arnd Bergmann, Yangyu Chen, linux-kernel, sophgo, devicetree,
linux-rtc, Inochi Amaoto
Hi, Alexander Sverdlin,
I just find there is an exiting "REAL TIME CLOCK (RTC) SUBSYSTEM"
section in MAINTAINERS, seems we should not pick the rtc file in "SOPHGO
DEVICETREES and DRIVERS".
Chen
On 2025/3/19 8:31, Chen Wang wrote:
> Hi, Inochi,
>
> I see Alexander add "drivers/rtc/rtc-cv1800.c" in "SOPHGO DEVICETREES
> and DRIVERS" of MAINTAINERS, would you like to take this?
>
> Regards,
>
> Chen
>
> On 2025/3/16 6:49, Alexander Sverdlin wrote:
>> From: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
>>
>> Implement the RTC driver for CV1800, which able to provide time alarm.
>>
>> Signed-off-by: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
>> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
>> ---
>> Changelog:
>> v14:
>> - platform device name "cv1800-rtc" -> "cv1800b-rtc"
>> 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
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index ac15e448fffb..be8fee50a49c 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -22354,6 +22354,7 @@ L: sophgo@lists.linux.dev
>> W: https://github.com/sophgo/linux/wiki
>> T: git https://github.com/sophgo/linux.git
>> S: Maintained
>> +F: drivers/rtc/rtc-cv1800.c
>> N: sophgo
>> K: sophgo
>
> [......]
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: (subset) [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800
2025-03-15 22:49 [PATCH v14 0/3] rtc: sophgo: add rtc support for CV1800 Alexander Sverdlin
` (2 preceding siblings ...)
2025-03-15 22:49 ` [PATCH v14 3/3] rtc: sophgo: add rtc support for Sophgo CV1800 SoC Alexander Sverdlin
@ 2025-05-07 0:41 ` Inochi Amaoto
3 siblings, 0 replies; 10+ messages in thread
From: Inochi Amaoto @ 2025-05-07 0:41 UTC (permalink / raw)
To: sophgo, devicetree, linux-rtc, Alexander Sverdlin
Cc: Inochi Amaoto, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chen Wang, Alexandre Belloni, Jingbao Qiu, Arnd Bergmann,
Yangyu Chen, linux-kernel
On Sat, 15 Mar 2025 23:49:11 +0100, Alexander Sverdlin wrote:
> 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).
>
> [...]
Applied to soc-for-next, thanks!
[1/3] dt-bindings: soc: sophgo: add RTC support for Sophgo CV1800 series
https://github.com/sophgo/linux/commit/76517429dbfd8eca16fe85482cdb8024bbbd06bd
[2/3] soc: sophgo: cv1800: rtcsys: New driver (handling RTC only)
https://github.com/sophgo/linux/commit/c8754c7deab4cbfa947fa2d656cbaf83771828ef
Thanks,
Inochi
^ permalink raw reply [flat|nested] 10+ messages in thread