From: Alexander Sverdlin <alexander.sverdlin@gmail.com>
To: soc@lists.linux.dev
Cc: Alexander Sverdlin <alexander.sverdlin@gmail.com>,
Chen Wang <unicorn_wang@outlook.com>,
Inochi Amaoto <inochiama@outlook.com>,
linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org,
Haylen Chu <heylenay@outlook.com>,
linux-arm-kernel@lists.infradead.org,
Sebastian Reichel <sre@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Philipp Zabel <p.zabel@pengutronix.de>,
Lee Jones <lee@kernel.org>
Subject: [PATCH 09/10] power: reset: cv18xx: New driver
Date: Sun, 9 Feb 2025 23:06:34 +0100 [thread overview]
Message-ID: <20250209220646.1090868-10-alexander.sverdlin@gmail.com> (raw)
In-Reply-To: <20250209220646.1090868-1-alexander.sverdlin@gmail.com>
Add new driver to support cold and warm reset on Cvitek CV18xx and Sophgo
SG2000 SoCs.
Link: https://github.com/sophgo/sophgo-doc/releases/download/sg2000-trm-v1.01/sg2000_trm_en.pdf
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
---
MAINTAINERS | 1 +
drivers/power/reset/Kconfig | 12 ++++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/cv18xx-reset.c | 89 ++++++++++++++++++++++++++++++
4 files changed, 103 insertions(+)
create mode 100644 drivers/power/reset/cv18xx-reset.c
diff --git a/MAINTAINERS b/MAINTAINERS
index e4f5d8f68581..b7fec02f7673 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -22147,6 +22147,7 @@ M: Chen Wang <unicorn_wang@outlook.com>
M: Inochi Amaoto <inochiama@outlook.com>
T: git https://github.com/sophgo/linux.git
S: Maintained
+F: drivers/power/reset/cv18xx-reset.c
N: sophgo
K: sophgo
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 60bf0ca64cf3..d41ed3c2a30d 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -75,6 +75,18 @@ config POWER_RESET_BRCMSTB
Say Y here if you have a Broadcom STB board and you wish
to have restart support.
+config POWER_RESET_CV18XX
+ bool "Cvitek CV18XX/Sophgo SG2000 reset driver"
+ depends on ARCH_SOPHGO || COMPILE_TEST
+ depends on MFD_SYSCON
+ default ARCH_SOPHGO
+ help
+ This driver provides restart support for Cvitek CV18xx and
+ Sophgo SG2000 SoCs.
+
+ Say Y here if you have a Cvitek CV18xx or Sophgo SG2000 SoC and
+ you wish to have restart support.
+
config POWER_RESET_EP93XX
bool "Cirrus EP93XX reset driver" if COMPILE_TEST
depends on MFD_SYSCON
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 10782d32e1da..ce24e74e0477 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_POWER_RESET_ATC260X) += atc260x-poweroff.o
obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
obj-$(CONFIG_POWER_RESET_BRCMKONA) += brcm-kona-reset.o
obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
+obj-$(CONFIG_POWER_RESET_CV18XX) += cv18xx-reset.o
obj-$(CONFIG_POWER_RESET_EP93XX) += ep93xx-restart.o
obj-$(CONFIG_POWER_RESET_GEMINI_POWEROFF) += gemini-poweroff.o
obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
diff --git a/drivers/power/reset/cv18xx-reset.c b/drivers/power/reset/cv18xx-reset.c
new file mode 100644
index 000000000000..bc1797e7d3f5
--- /dev/null
+++ b/drivers/power/reset/cv18xx-reset.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
+
+/* RTCSYS_CTRL registers */
+#define RTC_CTRL_UNLOCKKEY 0x04
+#define RTC_CTRL0 0x08
+#define REQ_PWR_CYC BIT(3)
+#define REQ_WARM_RST BIT(4)
+
+/* RTCSYS_CORE registers */
+#define RTC_EN_PWR_CYC_REQ 0xC8
+#define RTC_EN_WARM_RST_REQ 0xCC
+
+static struct regmap *rtcsys_ctrl_regs;
+static struct regmap *rtcsys_core_regs;
+
+static int cv18xx_restart_handler(struct sys_off_data *data)
+{
+ u32 reg_en = RTC_EN_WARM_RST_REQ;
+ u32 request = 0xFFFF0800;
+
+ if (data->mode == REBOOT_COLD) {
+ reg_en = RTC_EN_PWR_CYC_REQ;
+ request |= REQ_PWR_CYC;
+ } else {
+ request |= REQ_WARM_RST;
+ }
+
+ /* Enable reset request */
+ regmap_write(rtcsys_core_regs, reg_en, 1);
+ /* Enable CTRL0 register access */
+ regmap_write(rtcsys_ctrl_regs, RTC_CTRL_UNLOCKKEY, 0xAB18);
+ /* Request reset */
+ regmap_write(rtcsys_ctrl_regs, RTC_CTRL0, request);
+
+ return NOTIFY_DONE;
+}
+
+static int cv18xx_reset_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ int ret;
+
+ if (!np)
+ return -ENODEV;
+
+ rtcsys_ctrl_regs = syscon_regmap_lookup_by_phandle(np, "sophgo,rtcsys-ctrl");
+ if (IS_ERR(rtcsys_ctrl_regs))
+ return dev_err_probe(dev, PTR_ERR(rtcsys_ctrl_regs),
+ "sophgo,rtcsys-ctrl lookup failed\n");
+
+ rtcsys_core_regs = syscon_regmap_lookup_by_phandle(np, "sophgo,rtcsys-core");
+ if (IS_ERR(rtcsys_core_regs))
+ return dev_err_probe(dev, PTR_ERR(rtcsys_core_regs),
+ "sophgo,rtcsys-core lookup failed\n");
+
+ ret = devm_register_restart_handler(&pdev->dev, cv18xx_restart_handler, NULL);
+ if (ret)
+ dev_err(&pdev->dev, "Cannot register restart handler (%pe)\n", ERR_PTR(ret));
+ return ret;
+}
+
+static const struct of_device_id cv18xx_reset_of_match[] = {
+ { .compatible = "sophgo,cv1800-reset" },
+ {}
+};
+MODULE_DEVICE_TABLE(platform, cv18xx_reset_of_match);
+
+static struct platform_driver cv18xx_reset_driver = {
+ .probe = cv18xx_reset_probe,
+ .driver = {
+ .name = "cv18xx-reset",
+ .of_match_table = cv18xx_reset_of_match,
+ },
+};
+module_platform_driver(cv18xx_reset_driver);
+
+MODULE_AUTHOR("Alexander Sverdlin <alexander.sverdlin@gmail.com>");
+MODULE_DESCRIPTION("Cvitek CV18xx/Sophgo SG2000 Reset Driver");
+MODULE_ALIAS("platform:cv18xx-reset");
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-02-09 22:19 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-09 22:06 [PATCH 00/10] arm64 support for Milk-V Duo Module 01 EVB Alexander Sverdlin
2025-02-09 22:06 ` [PATCH 01/10] arm64: Add SOPHGO SOC family Kconfig support Alexander Sverdlin
2025-02-10 0:38 ` Chen Wang
2025-02-09 22:06 ` [PATCH 02/10] riscv: dts: sophgo: cv18xx: Split into CPU core and peripheral parts Alexander Sverdlin
2025-02-10 5:24 ` Inochi Amaoto
2025-02-10 8:43 ` Krzysztof Kozlowski
2025-02-10 13:45 ` Alexander Sverdlin
2025-02-11 8:08 ` Krzysztof Kozlowski
2025-02-11 9:14 ` Alexander Sverdlin
2025-02-10 14:26 ` Alexander Sverdlin
2025-02-10 15:31 ` Krzysztof Kozlowski
2025-02-09 22:06 ` [PATCH 03/10] arm64: dts: sophgo: Add initial SG2000 SoC device tree Alexander Sverdlin
2025-02-10 5:05 ` Inochi Amaoto
2025-02-10 14:16 ` Alexander Sverdlin
2025-02-10 5:26 ` Inochi Amaoto
2025-02-10 8:45 ` Krzysztof Kozlowski
2025-02-10 15:01 ` Alexander Sverdlin
2025-02-11 8:07 ` Krzysztof Kozlowski
2025-02-11 9:22 ` Alexander Sverdlin
2025-02-11 12:12 ` Krzysztof Kozlowski
2025-02-09 22:06 ` [PATCH 04/10] arm64: dts: sophgo: Add Duo Module 01 Alexander Sverdlin
2025-02-10 5:27 ` Inochi Amaoto
2025-02-10 8:47 ` Krzysztof Kozlowski
2025-02-09 22:06 ` [PATCH 05/10] arm64: dts: sophgo: Add Duo Module 01 Evaluation Board Alexander Sverdlin
2025-02-10 8:48 ` Krzysztof Kozlowski
2025-02-09 22:06 ` [PATCH 06/10] dt-bindings: mfd: syscon: Add Cvitek CV18xx rtcsys core and ctrl compatible Alexander Sverdlin
2025-02-10 5:15 ` Inochi Amaoto
2025-02-10 8:48 ` Krzysztof Kozlowski
2025-02-10 20:30 ` Alexander Sverdlin
2025-02-10 20:40 ` Alexander Sverdlin
2025-02-09 22:06 ` [PATCH 07/10] dt-bindings: reset: sophgo: Add CV18xx reset controller Alexander Sverdlin
2025-02-10 5:36 ` Inochi Amaoto
2025-02-10 8:49 ` Krzysztof Kozlowski
2025-02-09 22:06 ` [PATCH 08/10] riscv/arm64: dts: cv18xx: Add sysctl and reset nodes Alexander Sverdlin
2025-02-10 5:13 ` Inochi Amaoto
2025-02-10 11:47 ` Alexander Sverdlin
2025-02-10 12:29 ` Inochi Amaoto
2025-02-10 8:51 ` Krzysztof Kozlowski
2025-02-09 22:06 ` Alexander Sverdlin [this message]
2025-02-10 8:52 ` [PATCH 09/10] power: reset: cv18xx: New driver Krzysztof Kozlowski
2025-02-09 22:06 ` [PATCH 10/10] arm64: defconfig: Enable rudimentary Sophgo SG2000 support Alexander Sverdlin
2025-02-10 0:02 ` [PATCH 00/10] arm64 support for Milk-V Duo Module 01 EVB Chen Wang
2025-02-10 5:15 ` Inochi Amaoto
2025-02-10 5:33 ` Inochi Amaoto
2025-02-10 12:10 ` Alexander Sverdlin
2025-02-10 20:55 ` Alexander Sverdlin
2025-02-11 19:37 ` Alexander Sverdlin
2025-02-12 0:29 ` Inochi Amaoto
2025-02-12 9:33 ` Alexander Sverdlin
2025-02-10 16:22 ` Rob Herring (Arm)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250209220646.1090868-10-alexander.sverdlin@gmail.com \
--to=alexander.sverdlin@gmail.com \
--cc=arnd@arndb.de \
--cc=heylenay@outlook.com \
--cc=inochiama@outlook.com \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=p.zabel@pengutronix.de \
--cc=soc@lists.linux.dev \
--cc=sre@kernel.org \
--cc=unicorn_wang@outlook.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox