Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3978185pxv; Mon, 28 Jun 2021 18:20:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcnlHXrKFNiT7M6OZ6Qjb+FvYVKiGZ1j4iXXFxHMDu9hUQaTDcqbRFjClp5g7uLmnDC8tK X-Received: by 2002:a17:906:c822:: with SMTP id dd2mr27811774ejb.474.1624929633982; Mon, 28 Jun 2021 18:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624929633; cv=none; d=google.com; s=arc-20160816; b=t8TedVWi7jcu1jPu/x7sUg6S2a0Yww9PHrb3dMDl8OdMO+OoaPMgQAMmfZolOZ1Im3 EvFPOw3OlBH7GorNnVZ6ravNSbuV+I3RhJcN9UzsKWYtaB7OZSbkr/ak7NTE/YQxL4if lIiD/160YPKxmgxodCqno4fW0QCgpQMtXKBb8QzSiDnwsmcfkfLcLYlnQAVYApP2i92S xCofUOqDnVyRwaHGmPSBg8xbhH3n/LhQipZbpaMcMouxqXzq7hDUSf4HY8z6f0y+Kq+v Qg54EFb79GoiIBxIs6fTGV31X1z43Dh6IdRLFTb+c9Ccw64LS1KMI5DFvmo0raLM+Bc+ B8cg== 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=9o2U8gjg5IJiqMWlHfNzLV796KyZvjAO/cXvDIvq/1o=; b=CUR+M5Ua6M7QDvGuMMX4N8QxoltOufPX5aaMurODhFLfVFB0bW+TmMC80/l2rJw1pg Bjt0ISo3+1SYrOuYxR+g+dL7YiQ1BZ1UsjFbvpgwFRWT5Zrmum7AkQaAOj6KsZjPqSGL r9HIW98eHSK1QBsyI6dQZAvBcexJrnnkrXjsdzaMsnOsr0b45PYn3ahCXcPe7pvS8/mr +LFn05PJvxL//49DClPm4BYvu2IlpfyVpUn4beD7i1RQg5kMuflGhUFTR+en0L4lHIFJ YJMHiuSOv1mOmB1rrlpmVsxZ7hARnNgp3ARhwctpel5BqjF8+4qM70sM5rKBYTDEruNk ukDw== 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 z26si18781681ejc.46.2021.06.28.18.20.10; Mon, 28 Jun 2021 18:20:33 -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 S231958AbhF2BVq (ORCPT + 99 others); Mon, 28 Jun 2021 21:21:46 -0400 Received: from mail.loongson.cn ([114.242.206.163]:46398 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230287AbhF2BVq (ORCPT ); Mon, 28 Jun 2021 21:21:46 -0400 Received: from localhost.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxP0ERddpgWAYaAA--.9325S2; Tue, 29 Jun 2021 09:19:13 +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 v5 1/2] MIPS: Loongson64: Add Loongson-2K1000 reset platform driver Date: Tue, 29 Jun 2021 09:19:12 +0800 Message-Id: <20210629011913.18611-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9DxP0ERddpgWAYaAA--.9325S2 X-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orr0wxvrqhubq/ Precedence: bulk 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 --- v5-v6: No change 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); -- 2.31.0