Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3732693pxv; Mon, 28 Jun 2021 11:24:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySRLlbbjqKNcpGWnZ1w7jRApM2EqwaBF4x2NT64Bl41HS83Zn8mEi9No8e+mZQwmtUUC60 X-Received: by 2002:a05:6402:68a:: with SMTP id f10mr34603567edy.99.1624904695878; Mon, 28 Jun 2021 11:24:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624904695; cv=none; d=google.com; s=arc-20160816; b=qk4FcgD80eoEOq0mrP6MZ/lk19zPO4O96J4MvH0Ml6Urt75wCVRPT2YIU+ZN4YAZrE V9lLSAQxHOoacYoDOPAZG3tvVY/NYr8AAHUseMtJn9oCYyKFW42e8M+mJYHKpqbcxiIZ 321592IeLTEpTD6jcC0uwDnSjMTe7lsivcGqEZy0rqd7PzVV813TX+fAnJErNK49fOO/ qGlNAxKremq5iVNVQtQfOwPCpKdlxD6adrtdj6RxmmHSJ924t9UEK6cew0tM0eSfyxaz s+PzGg26eV2OOxS2jlfuMH38crJ2XGDH4L1x1bZyqRJEURxbGw1ByVjKGIGPpQ1mKVci KIwQ== 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=t9gpJmkSYKkh4WPuOlertE968F2fS0s7f4zkHVKNw40=; b=kDEHAkZY3q3hzq0aaJC4ZgcRH5RZkAJgGVaemfMkB+dy6uwq6eJos4lPMrd39MKYKI plh33eieVMQPsutsFe7L4NhJOc/i0Aa80ac5WzLoHjMkCV/BG80ZKqDKwrb1AzrPXRkB Cfk8hy4PCK34IkyCOlL55pf7oCL1v5lPvjCukGORh7RU0ImB4MWE0truAK6mu0+dBGog /TQjvSNW4Y1bHkFUIvt7WC571w+rWxG/LosIRBu5oXTUGbQNSM5IJ3F79n4etBllFjvw bWR+iGH+NhqTcCSX+Shnh4P1ummrKZwejIjMekhUve6Idt9RRTzzCFop6tVjFys9Gv8P Pqtg== 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 4si14875775ejr.444.2021.06.28.11.24.30; Mon, 28 Jun 2021 11:24:55 -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 S236436AbhF1Oz3 (ORCPT + 99 others); Mon, 28 Jun 2021 10:55:29 -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.11504-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9Dxb0L93tlgmsoZAA--.8933S2 X-Coremail-Antispam: 1UD129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rqhubq/ 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 --- 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); -- 2.31.0