From patchwork Mon Jun 28 14:38:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhang X-Patchwork-Id: 12348145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC371C49EBB for ; Mon, 28 Jun 2021 14:41:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B509761D7D for ; Mon, 28 Jun 2021 14:41:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234487AbhF1On2 (ORCPT ); Mon, 28 Jun 2021 10:43:28 -0400 Received: from mail.loongson.cn ([114.242.206.163]:59590 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234490AbhF1Ol0 (ORCPT ); Mon, 28 Jun 2021 10:41:26 -0400 Received: from localhost.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxb0L93tlgmsoZAA--.8933S2; Mon, 28 Jun 2021 22:38:53 +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 v3 1/2] MIPS: Loongson-3: Add Loongson-2K1000 reset platform driver Date: Mon, 28 Jun 2021 22:38:51 +0800 Message-Id: <20210628143852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r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07boD7-UUUUU= X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Add power management register operations to support reboot and poweroff. Signed-off-by: Qing Zhang --- v2-v3: -make reset support as a driver Signed-off-by: Qing Zhang --- drivers/platform/mips/Kconfig | 6 +++ drivers/platform/mips/Makefile | 1 + drivers/platform/mips/ls2k-reset.c | 60 ++++++++++++++++++++++++++++++ 3 files changed, 67 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..c5f073c82c5e --- /dev/null +++ b/drivers/platform/mips/ls2k-reset.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021, Qing Zhang + * Loongson-2K1000 reset support + */ + +#include +#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 void ls2k_restart(char *command) +{ + writel(0x1, (void *)pm_reg_name[2]); +} + +static void ls2k_poweroff(void) +{ + /* 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]); +} + +static int ls2k_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]); + } + + _machine_restart = ls2k_restart; + pm_power_off = ls2k_poweroff; + + of_node_put(np); + return 0; +} + +arch_initcall(ls2k_reset_init); From patchwork Mon Jun 28 14:38:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhang X-Patchwork-Id: 12348143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AD4BC49EB9 for ; Mon, 28 Jun 2021 14:41:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5967661D80 for ; Mon, 28 Jun 2021 14:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234895AbhF1On2 (ORCPT ); Mon, 28 Jun 2021 10:43:28 -0400 Received: from mail.loongson.cn ([114.242.206.163]:59592 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234491AbhF1Ol0 (ORCPT ); Mon, 28 Jun 2021 10:41:26 -0400 Received: from localhost.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxb0L93tlgmsoZAA--.8933S3; Mon, 28 Jun 2021 22:38:54 +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 v3 2/2] MIPS: Loongson64: DTS: Add pm block node for Loongson-2K1000 Date: Mon, 28 Jun 2021 22:38:52 +0800 Message-Id: <20210628143852.11504-2-zhangqing@loongson.cn> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210628143852.11504-1-zhangqing@loongson.cn> References: <20210628143852.11504-1-zhangqing@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf9Dxb0L93tlgmsoZAA--.8933S3 X-Coremail-Antispam: 1UD129KBjvdXoW7XF43KFWxZFyxZFW8GFWxZwb_yoWfCFg_ta s293WkCrWfJF4ft3y8Xr1UGFy3u3y7Z3WrCFn8XF10qa90vFn3JFWUAayDCr1fWFyY9rs3 Xr4kWr18AF1xKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbf8YjsxI4VWxJwAYFVCjjxCrM7AC8VAFwI0_Gr0_Xr1l1xkIjI8I 6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7 IE14v26r18M28IrcIa0xkI8VCY1x0267AKxVWUCVW8JwA2ocxC64kIII0Yj41l84x0c7CE w4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6x kF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF 7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F4 0Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC 6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc2xSY4AK67AK6ry5MxAIw28IcxkI7VAKI4 8JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xv wVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjx v20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20E Y4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267 AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8M7K3UUUUU== X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The module is now supported, enable it. Signed-off-by: Qing Zhang --- arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi index 569e814def83..e31176ac0ac2 100644 --- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi +++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi @@ -101,6 +101,15 @@ uart0: serial@1fe00000 { no-loopback-test; }; + pm: power-controller { + device_type = "power management"; + compatible = "loongson, reset-controller"; + 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";