Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2525471pxv; Sun, 27 Jun 2021 00:39:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3+Z/8jfpJlVOV56cQFs8j3+bAznV9zIquldHypACegtEuNAxl4EVXNdHD+z/TWZ/cBwNN X-Received: by 2002:a50:a6db:: with SMTP id f27mr26430113edc.18.1624779570471; Sun, 27 Jun 2021 00:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624779570; cv=none; d=google.com; s=arc-20160816; b=q6uy44ZSgE2L09EaslaAiVaTWTqnB3B8soVNg/j73KcFrC3d+qrJmmpVVG3jTCqXBB We+dVav/CwTWd/4FBE+fnhnZ3Gjqg7N1CjRXDfZEzGXPSgn15WKqvajZZwBiE9q6Qy5A sV5m3b9jCxe6vx4S4yLz+fnyC//KRYWkKfsBtaaSfJdhtg3HBP4fxrK1QSaO+fCa1ojC ZfwVSQVy7E7YWThFYUJa9GrwHUF27mtpZi8R3G8aNZ09qjfuvmbWrFOTodxr+idn8904 RcwH3TH6c4c7jBLP7z9jf+DVRaBBw8syo/eTfxgRhro3vZFG9vn+cZfPFnKlxSbTEY9G Uixw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=HYvolLuJrDq7C7yvBvmoOeB3hfyeBKwGA7YxdspFexQ=; b=dUKaqQvXy0sB9peZ5j6Vzg+sxLffDHrfUyXISzqTNCnoprybZ7dkIosKIOKWY9Nvo/ mDRedrujwztbhjHsxn4HAa/jStEEubt5IHbcn0wxcZMgig5RDmhEbsE+w4Ce9x7AWcbX I3uJwYNdJyg00ifqX05xXgHiF7nX+kZM2tClNNlKlS5gKMi3VgBzfPzYqaj8V6TQ9vK6 rgrRkKe1Q7xm3SXpKGRSDFu6M4u3/ZX0jjFHFXkp7OVgmvGtofjF0vQsdfBP7mIpuVDV /+v2E/jk2prD7FJlpVGxB8epT8s+IX54nyCv7Hp0vJWea1prR2a1SWJO+FqS67H+C3t3 vBvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si11220291edv.519.2021.06.27.00.39.07; Sun, 27 Jun 2021 00:39:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbhF0Hkk (ORCPT + 99 others); Sun, 27 Jun 2021 03:40:40 -0400 Received: from mail.loongson.cn ([114.242.206.163]:60092 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229519AbhF0Hkj (ORCPT ); Sun, 27 Jun 2021 03:40:39 -0400 Received: from localhost.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxb0DfKthgFewYAA--.29429S2; Sun, 27 Jun 2021 15:38:07 +0800 (CST) From: Qing Zhang To: Thomas Bogendoerfer , Rob Herring , Jiaxun Yang , Huacai Chen Cc: devicetree@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] MIPS: Loongson64: Add Loongson-2K1000 reset support Date: Sun, 27 Jun 2021 15:38:06 +0800 Message-Id: <20210627073806.32564-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9Dxb0DfKthgFewYAA--.29429S2 X-Coremail-Antispam: 1U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k List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add power management register operations to support reboot and poweroff. Signed-off-by: Qing Zhang --- v1-v2: - Add pm block node Signed-off-by: Qing Zhang 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"; + 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 #include #include +#include #include #include @@ -20,12 +21,50 @@ #include #include +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); +} + +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(); -- 2.31.0