MIPS: Loongson64: Add Loongson-2K1000 reset platform driver

Started by Qing Zhang on Jun 30, 2021 · 4 messages from 2 authors · Last reply Jun 30, 2021

Subsystems (2)

Maintainers (2)

STALE1955d

open the first message on its own page

  1. [PATCH v6 2/2] MIPS: Loongson64: DTS: Add pm block node for Loongson-2K1000
    Related patches
Message details and related content
Add power management register operations to support reboot and poweroff.

Signed-off-by: Qing Zhang <redacted>
---

v5-v6:
Calculate others by base
---
 drivers/platform/mips/Kconfig      |  6 ++++
 drivers/platform/mips/Makefile     |  1 +
 drivers/platform/mips/ls2k-reset.c | 53 ++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+)
 create mode 100644 drivers/platform/mips/ls2k-reset.c
diff --git a/drivers/platform/mips/Kconfig b/drivers/platform/mips/Kconfig
index 8ac149173c64..d421e1482395 100644
--- a/drivers/platform/mips/Kconfig
+++ b/drivers/platform/mips/Kconfig
@@ -30,4 +30,10 @@ config RS780E_ACPI
 	help
 	  Loongson RS780E PCH ACPI Controller driver.
 
+config LS2K_RESET
+	bool "Loongson-2K1000 Reset Controller"
+	depends on MACH_LOONGSON64 || COMPILE_TEST
+	help
+	  Loongson-2K1000 Reset Controller driver.
+
 endif # MIPS_PLATFORM_DEVICES
diff --git a/drivers/platform/mips/Makefile b/drivers/platform/mips/Makefile
index 178149098777..4c71444e453a 100644
--- a/drivers/platform/mips/Makefile
+++ b/drivers/platform/mips/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_CPU_HWMON) += cpu_hwmon.o
 obj-$(CONFIG_RS780E_ACPI) += rs780e-acpi.o
+obj-$(CONFIG_LS2K_RESET) += ls2k-reset.o
diff --git a/drivers/platform/mips/ls2k-reset.c b/drivers/platform/mips/ls2k-reset.c
new file mode 100644
index 000000000000..286d47bf6964
--- /dev/null
+++ b/drivers/platform/mips/ls2k-reset.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Copyright (C) 2021, Qing Zhang <zhangqing@loongson.cn>
+ *  Loongson-2K1000 reset support
+ */
+
+#include <linux/of_address.h>
+#include <linux/pm.h>
+#include <asm/reboot.h>
+
+#define	PM1_STS		0x0c /* Power Management1 Status Register */
+#define	PM1_CNT		0x14 /* Power Management 1 Control Register */
+#define	RST_CNT		0x30 /* Reset Control Register */
+
+static void __iomem *base;
+
+static void ls2k_restart(char *command)
+{
+	writel(0x1, (void *)base + RST_CNT);
+}
+
+static void ls2k_poweroff(void)
+{
+	/* Clear */
+	writel((readl((void *)base + PM1_STS) & 0xffffffff), (void *)base + PM1_STS);
+	/* Sleep Enable | Soft Off*/
+	writel(GENMASK(12, 10)|BIT(13), (void *)base + PM1_CNT);
+}
+
+static int ls2k_reset_init(void)
+{
+	struct device_node *np;
+
+	np = of_find_compatible_node(NULL, NULL, "loongson,ls2k-pm");
+	if (!np) {
+		pr_info("Failed to get PM node\n");
+		return -ENODEV;
+	}
+
+	base = of_iomap(np, 0);
+	if (!base) {
+		pr_info("Failed to map PM register base address\n");
+		return -ENOMEM;
+	}
+
+	_machine_restart = ls2k_restart;
+	pm_power_off = ls2k_poweroff;
+
+	of_node_put(np);
+	return 0;
+}
+
+arch_initcall(ls2k_reset_init);
-- 
2.31.0

[PATCH v6 2/2] MIPS: Loongson64: DTS: Add pm block node for Loongson-2K1000

Message details and related content
The module is now supported, enable it.

Signed-off-by: Qing Zhang <redacted>
---
 arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 569e814def83..8f469b623740 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -52,6 +52,11 @@ package0: bus@10000000 {
 			0 0x40000000 0 0x40000000 0 0x40000000
 			0xfe 0x00000000 0xfe 0x00000000 0 0x40000000>;
 
+		pm: power-controller@1fe07000 {
+			compatible = "loongson,ls2k-pm";
+			reg = <0 0x1fe07000 0 0x422>;
+		};
+
 		liointc0: interrupt-controller@1fe11400 {
 			compatible = "loongson,liointc-2.0";
 			reg = <0 0x1fe11400 0 0x40>,
-- 
2.31.0

Re: [PATCH v6 2/2] MIPS: Loongson64: DTS: Add pm block node for Loongson-2K1000

Message details and related content
在 2021/6/30 14:51, Qing Zhang 写道:
The module is now supported, enable it.
Oh, you forgot binding document.

Thanks.

- Jiaxun
quoted hunk
Signed-off-by: Qing Zhang <redacted>
---
  arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 5 +++++
  1 file changed, 5 insertions(+)
diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 569e814def83..8f469b623740 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -52,6 +52,11 @@ package0: bus@10000000 {
  			0 0x40000000 0 0x40000000 0 0x40000000
  			0xfe 0x00000000 0xfe 0x00000000 0 0x40000000>;
  
+		pm: power-controller@1fe07000 {
+			compatible = "loongson,ls2k-pm";
+			reg = <0 0x1fe07000 0 0x422>;
+		};
+
  		liointc0: interrupt-controller@1fe11400 {
  			compatible = "loongson,liointc-2.0";
  			reg = <0 0x1fe11400 0 0x40>,

Re: [PATCH v6 2/2] MIPS: Loongson64: DTS: Add pm block node for Loongson-2K1000

Message details and related content

On 06/30/2021 04:20 PM, Jiaxun Yang wrote:
在 2021/6/30 14:51, Qing Zhang 写道:
quoted
The module is now supported, enable it.
Oh, you forgot binding document.
    oh, I forgot a patch... :
    I'll send it make RESEND.

    Thanks,

    -Qing
Thanks.

- Jiaxun
quoted
Signed-off-by: Qing Zhang <redacted>
---
  arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 5 +++++
  1 file changed, 5 insertions(+)
diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 569e814def83..8f469b623740 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -52,6 +52,11 @@ package0: bus@10000000 {
              0 0x40000000 0 0x40000000 0 0x40000000
              0xfe 0x00000000 0xfe 0x00000000 0 0x40000000>;
  +        pm: power-controller@1fe07000 {
+            compatible = "loongson,ls2k-pm";
+            reg = <0 0x1fe07000 0 0x422>;
+        };
+
          liointc0: interrupt-controller@1fe11400 {
              compatible = "loongson,liointc-2.0";
              reg = <0 0x1fe11400 0 0x40>,
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help