Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp73937pxv; Tue, 29 Jun 2021 23:53:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytiS/HSpoZeLezYC/V5ji7PiRIpdfdN8w8+vcbiB1cAffeWUbrjs+WsU3UO1AQbgt8m1bw X-Received: by 2002:a05:6402:40c4:: with SMTP id z4mr45326972edb.364.1625035981554; Tue, 29 Jun 2021 23:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625035981; cv=none; d=google.com; s=arc-20160816; b=XgREhoGIxH+hDicnQ/J6ffYvP2hO2lTrWMt9tFOsAmMly6yKL6IgdvUl8F1Kr2l1G5 JQH5rcwP7lko20sSa3u+1yhTJGkQjQ5SzAyEnRwc3C0dVUXAzuHQNPbiNMfmjXvgYJYR u5HhmDNetNIRbuqEeMQnlOl+U5s/yFdCJ7eQnfgtOtkDpVi3igO9XdRvUKwur6m5Odlw K+3LYZEkd+NAHmEvq1K9bdbXcq37ectvZCTOX0vbvYHQq4oMUvJPTVGgu4ng8uU1nR5W 6KWmxjDHT1sGA4LOpQmlyOLs5/0Xq9kLkDv4HfsK+p7/VCmJhYEeF+F+OkMIATtpqfzV 32Ag== 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=X/dDB1Warjbo5b+ClU8/7mx6e6UId/vIGz+lfQaEYdM=; b=aZXs6bn7p1sTwFMbzkI95tGgjQKgqbvOY6tNIqGEVugY+OuKDB4lUSNcUEM9LFwGqB ocgcluisCFfPUzmwdrXJ4yh80kDz8xoBIUDK+907OeXsQLGulESptG4LtRvs8dYrYO3v yp99KPWS4FVEtHRUnp7wWNXNXn00kZWvhjeF64Rbe/xq6qhGF2FgJkBW5sHFy3OTL6uS 8AZv6oSeByT8oHjXVpCszIEeHLpgpMyP3DApLoFOn/Pj0jOi5wLIqxHesuBhoAkHUcnW gdPZLivp3jzQE9R9L30BDC5oue5kPWRHopkI8YKah8gGFLqra8LCLKy5H8a61AiZh9ls oIEg== 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 a9si19180693ejj.647.2021.06.29.23.52.38; Tue, 29 Jun 2021 23:53:01 -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 S232716AbhF3Gxo (ORCPT + 99 others); Wed, 30 Jun 2021 02:53:44 -0400 Received: from mail.loongson.cn ([114.242.206.163]:50560 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232518AbhF3Gxj (ORCPT ); Wed, 30 Jun 2021 02:53:39 -0400 Received: from localhost.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxn0BYFNxgj64aAA--.10153S2; Wed, 30 Jun 2021 14:51:04 +0800 (CST) From: Qing Zhang To: Thomas Bogendoerfer , Rob Herring , Jiaxun Yang Cc: devicetree@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/2] MIPS: Loongson64: Add Loongson-2K1000 reset platform driver Date: Wed, 30 Jun 2021 14:51:02 +0800 Message-Id: <20210630065103.23665-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9Dxn0BYFNxgj64aAA--.10153S2 X-Coremail-Antispam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vrqhubq/ 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: Calculate others by base --- drivers/platform/mips/Kconfig | 6 ++++ drivers/platform/mips/Makefile | 1 + drivers/platform/mips/ls2k-reset.c | 53 ++++++++++++++++++++++++++++++ 3 files changed, 60 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..286d47bf6964 --- /dev/null +++ b/drivers/platform/mips/ls2k-reset.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021, Qing Zhang + * Loongson-2K1000 reset support + */ + +#include +#include +#include + +#define PM1_STS 0x0c /* Power Management1 Status Register */ +#define PM1_CNT 0x14 /* Power Management 1 Control Register */ +#define RST_CNT 0x30 /* Reset Control Register */ + +static void __iomem *base; + +static void ls2k_restart(char *command) +{ + writel(0x1, (void *)base + RST_CNT); +} + +static void ls2k_poweroff(void) +{ + /* Clear */ + writel((readl((void *)base + PM1_STS) & 0xffffffff), (void *)base + PM1_STS); + /* Sleep Enable | Soft Off*/ + writel(GENMASK(12, 10)|BIT(13), (void *)base + PM1_CNT); +} + +static int ls2k_reset_init(void) +{ + struct device_node *np; + + np = of_find_compatible_node(NULL, NULL, "loongson,ls2k-pm"); + if (!np) { + pr_info("Failed to get PM node\n"); + return -ENODEV; + } + + base = of_iomap(np, 0); + if (!base) { + pr_info("Failed to map PM register base address\n"); + return -ENOMEM; + } + + _machine_restart = ls2k_restart; + pm_power_off = ls2k_poweroff; + + of_node_put(np); + return 0; +} + +arch_initcall(ls2k_reset_init); -- 2.31.0