Re: [PATCH v2] MIPS: Loongson64: Add Loongson-2K1000 reset support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/28/2021 09:12 AM, Jiaxun Yang wrote:

在 2021/6/27 下午3:38, Qing Zhang 写道:
Add power management register operations to support reboot and poweroff.

Signed-off-by: Qing Zhang <zhangqing@xxxxxxxxxxx>
---

v1-v2:
- Add pm block node

Signed-off-by: Qing Zhang <zhangqing@xxxxxxxxxxx>

diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 569e814def83..929e8ddf86eb 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -101,6 +101,14 @@ uart0: serial@1fe00000 {
              no-loopback-test;
          };
  +        pm: power-controller {
+            device_type = "power management";

Hi Qing,

Not compatible?


+            reg = <0 0x1fe0700c 0 0x8>,
+                <0 0x1fe07014 0 0x8>,
+                <0 0x1fe07030 0 0x8>;
+            reg-names = "pm1_sts", "pm1_cnt", "rst_cnt";
+        };
+
          pci@1a000000 {
              compatible = "loongson,ls2k-pci";
              device_type = "pci";
diff --git a/arch/mips/loongson64/reset.c b/arch/mips/loongson64/reset.c
index c97bfdc8c922..ea125e925d44 100644
--- a/arch/mips/loongson64/reset.c
+++ b/arch/mips/loongson64/reset.c
@@ -10,6 +10,7 @@
  #include <linux/delay.h>
  #include <linux/init.h>
  #include <linux/kexec.h>
+#include <linux/of_address.h>
  #include <linux/pm.h>
  #include <linux/slab.h>
  @@ -20,12 +21,50 @@
  #include <loongson.h>
  #include <boot_param.h>
  +static char *pm_reg_name[] = {"pm1_sts", "pm1_cnt", "rst_cnt"};
+
+static void __iomem *get_reg_byname(struct device_node *node, const char *name)
+{
+    int index = of_property_match_string(node, "reg-names", name);
+
+    if (index < 0)
+        return NULL;
+
+    return of_iomap(node, index);
+}

We do have that helper in of_address.h.

Btw, I'd prefer make it as a driver in driver/platform/mips.

Also the approach using PRID to tell protocol type doesn't really make sense to me.

You can override _machine_restart callback in diver once FDT node is found.

Hi jiaxun,

Thanks for your suggestion,
I will send v3 in the soon.

Thanks.,

Qing

Thanks.

- Jiaxun

+
+static int  __init loongson_fdt_reset_init(void)
+{
+    struct device_node *np;
+    int i;
+
+    np = of_find_node_by_type(NULL, "power management");
+    if (!np) {
+        pr_info("Failed to get PM node\n");
+        return -ENODEV;
+    }
+
+    for (i = 0; i < sizeof(pm_reg_name)/sizeof(char *); i++) {
+        pm_reg_name[i] = get_reg_byname(np, pm_reg_name[i]);
+        if (!pm_reg_name[i])
+            iounmap(pm_reg_name[i]);
+    }
+
+    of_node_put(np);
+    return 0;
+}
+arch_initcall(loongson_fdt_reset_init);
+
  static void loongson_restart(char *command)
  {
+    if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R) {
+        writel(0x1, (void *)pm_reg_name[2]);
+    } else {
+ void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
  -    void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
+        fw_restart();
+    }
  -    fw_restart();
      while (1) {
          if (cpu_wait)
              cpu_wait();
@@ -34,9 +73,18 @@ static void loongson_restart(char *command)
    static void loongson_poweroff(void)
  {
-    void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
+    if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R) {
+        /* Clear */
+ writel((readl((void *)pm_reg_name[0]) & 0xffffffff), (void *)pm_reg_name[0]);
+        /* Sleep Enable | Soft Off*/
+        writel(GENMASK(12, 10)|BIT(13), (void *)pm_reg_name[1]);
+    } else {
+
+ void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
+
+        fw_poweroff();
+    }
  -    fw_poweroff();
      while (1) {
          if (cpu_wait)
              cpu_wait();




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux