Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp251386pxv; Wed, 30 Jun 2021 20:02:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRaK4DH0J/UXCPI1BCQso+jGDvaC7dhESPEIQFmPlq5ObGsVdDgJBhxAp3jQEro9stu4R1 X-Received: by 2002:aa7:db94:: with SMTP id u20mr50779933edt.381.1625108577620; Wed, 30 Jun 2021 20:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625108577; cv=none; d=google.com; s=arc-20160816; b=cMmV26bF0CrAmaBofkfuNhF2VfJfYaRYWncXkW6rAOuBenSu55p9BxjJns3ILW7LY/ AyhILkfpi/MGDZ8KXnIHgQ0HeA4XdxMCma0IwfTCh9ZAVb9aIU0lwSa7h4QTrKtjMlIb lgKgA0xjNfujlxj+0HENzcdnCC9+9U8Z9g3HW85hzRc6+SStm730QcGAFVa+d5AKD8t3 S7FBdormD+3OcPt6bN/0tTbpgpg61mwxXnWvElR23ft7Rwe+p8iAJnj0M6tExSMExVK2 u7tGo9JSYmxswQvsxab/vJ/NPqMJltslckovL3hHPjUb0/fl7GZiV1n6k8Fhy0Q3Emw5 hUxg== 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=qwZrrPbYYc52R2HTLh4K1ibDwFniRmo1DA+BYYRQGYY=; b=b12YvD2uj5d5JDR5ZIw8cDc+tKj+z2ZwDK/V3m/TKpdcUkuV/0md0ctz0m/eTkAhjo 2Pa2z1ufMH57W+TQ95k+xFTE9QJFw/P8cLyR2YFaUxAYdcQuNMaSBgg0lgrcAD4+JmBv ia3E3Khe706qdK8seU/c0GuN1QJB7IWoadbpL2yZbRst8zzadmty85zu3pjHGas8dr6K 5wODo7t7jr09MFEgeOrMAmetbPkiLt8m3AOOY94mcVFcpybPqqoa3sgcK4trasQOALKg kKAMvDWQkojcaKbhpDA2xB3Rcg0seuViPor1X64VU+CbY51ck0LPitLY5vQe94xJmZ27 NIIQ== 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 f14si22107117ejj.667.2021.06.30.20.02.34; Wed, 30 Jun 2021 20:02:57 -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 S238700AbhGADEP (ORCPT + 99 others); Wed, 30 Jun 2021 23:04:15 -0400 Received: from mail.loongson.cn ([114.242.206.163]:52784 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238625AbhGADEO (ORCPT ); Wed, 30 Jun 2021 23:04:14 -0400 Received: from localhost.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxj0MRMN1gsBQbAA--.31546S2; Thu, 01 Jul 2021 11:01:37 +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 v7 1/3] MIPS: Loongson64: Add Loongson-2K1000 reset platform driver Date: Thu, 1 Jul 2021 11:01:35 +0800 Message-Id: <20210701030137.10566-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9Dxj0MRMN1gsBQbAA--.31546S2 X-Coremail-Antispam: 1UD129KBjvJXoWxArW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kd0wptlqwqxorr0wxvrqhubq/ 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 --- v6-v7: No Change --- 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