From patchwork Thu Jun 15 09:17:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 108366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp501310vqr; Thu, 15 Jun 2023 02:29:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PzYw6Y7KCD3yt3X01dq/XyEnVtwzNmrl+v6o2ZydcbOh7swEB4cJV52Oaivg7zVto90qm X-Received: by 2002:a05:6870:8785:b0:19f:12a4:ea89 with SMTP id r5-20020a056870878500b0019f12a4ea89mr14229732oam.53.1686821365434; Thu, 15 Jun 2023 02:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686821365; cv=none; d=google.com; s=arc-20160816; b=oyOTbU8BU1tf3ccT053O03i2CexnVAMB0jthde5d0cengq+mUwmyRUawGiSHs4tkKr JyKLG1F89Ti+GkIs10YeNQYY84ryVdSsoDlKpR9GtuQ2tMG4HhCdSqX+lneEw0Pm/70H r9CXjvNV69oHr64k/dNM+OUFNaY21ACM4tNW+PsAsulqKe2r0lD/n6KmVE8A37mRcvEu VdY/TKuaQaKy3t9Rt21/rhhcpDVRKfzYu1Rxg+7BGtQ4oObAHoBmlAOzkeGE2M2O20oR 6vsnggVri/ys4d0v8VMYrXPteJC0wKsjR0l1zIxNkPtqykfF8B5dBkvgaAq/0f/+e3+O 4i5g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oO25GXSlyEAyRa52OqqK5/BaMtS/BRm34FcSpRAad7E=; b=X6pzz/asNkTVh6ogvmSOzCuOhYm++oNqpVSpPEkl/HzhHebN6/z+42HkaZSx+6Ob8s L1DLAsYEezPVhAPnlJVlYXNo/yzJ0ErIhSlD5tVhW4l1SQYTYiSO2t0cSIOg1pMRxNcW gRG8kMu8xNZCiJtNKylYI1dSu3/Nr7dOee+T5iPJg+C1ukgIcn/6gCqMz0KWPCDna6+4 GzhjQ7wbgcbW57mg4THwLlE6V6PcNq9YeH/2VZL6LhmE60jwjgdp/quGn0t20GMZacfu aP6fZuG0LbQSWLO9EZNZhm6Y51+c9X4B+Qtjwn8R7rNp/J5+BBgJRc1njs5EgNeCkxW/ 8JYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020aa798c7000000b00666878f8de7si1514406pfm.397.2023.06.15.02.29.12; Thu, 15 Jun 2023 02:29:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245498AbjFOJSX (ORCPT + 99 others); Thu, 15 Jun 2023 05:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245399AbjFOJSR (ORCPT ); Thu, 15 Jun 2023 05:18:17 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D530C1BC3; Thu, 15 Jun 2023 02:18:13 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.35]) by gateway (Coremail) with SMTP id _____8BxLutN14pkSoAFAA--.11919S3; Thu, 15 Jun 2023 17:18:05 +0800 (CST) Received: from user-pc.202.106.0.20 (unknown [10.20.42.35]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxVeRH14pkxssbAA--.13716S3; Thu, 15 Jun 2023 17:18:03 +0800 (CST) From: Yinbo Zhu To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Huacai Chen , WANG Xuerui , "Rafael J . Wysocki" , Pavel Machek , Marc Zyngier , Arnd Bergmann , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev Cc: Jianmin Lv , wanghongliang@loongson.cn, Liu Peibao , loongson-kernel@lists.loongnix.cn, Yinbo Zhu Subject: [PATCH v3 1/3] loongarch: export some arch-specific pm interfaces Date: Thu, 15 Jun 2023 17:17:55 +0800 Message-Id: <20230615091757.24686-2-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230615091757.24686-1-zhuyinbo@loongson.cn> References: <20230615091757.24686-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxVeRH14pkxssbAA--.13716S3 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768760400166191318?= X-GMAIL-MSGID: =?utf-8?q?1768760400166191318?= Some power management controllers need to support DTS and will use the suspend interface thus this patch was to export such interface for their use. Signed-off-by: Yinbo Zhu --- arch/loongarch/include/asm/acpi.h | 3 +-- arch/loongarch/include/asm/suspend.h | 10 ++++++++++ arch/loongarch/power/suspend.c | 8 ++++---- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 arch/loongarch/include/asm/suspend.h diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm/acpi.h index 976a810352c6..1d7810798c08 100644 --- a/arch/loongarch/include/asm/acpi.h +++ b/arch/loongarch/include/asm/acpi.h @@ -8,6 +8,7 @@ #ifndef _ASM_LOONGARCH_ACPI_H #define _ASM_LOONGARCH_ACPI_H +#include #ifdef CONFIG_ACPI extern int acpi_strict; extern int acpi_disabled; @@ -37,12 +38,10 @@ extern struct list_head acpi_wakeup_device_list; extern int loongarch_acpi_suspend(void); extern int (*acpi_suspend_lowlevel)(void); -extern void loongarch_suspend_enter(void); static inline unsigned long acpi_get_wakeup_address(void) { #ifdef CONFIG_SUSPEND - extern void loongarch_wakeup_start(void); return (unsigned long)loongarch_wakeup_start; #endif return 0UL; diff --git a/arch/loongarch/include/asm/suspend.h b/arch/loongarch/include/asm/suspend.h new file mode 100644 index 000000000000..fc64089fefaa --- /dev/null +++ b/arch/loongarch/include/asm/suspend.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_SUSPEND_H +#define __ASM_SUSPEND_H + +void loongarch_common_resume(void); +void loongarch_common_suspend(void); +void loongarch_suspend_enter(void); +void loongarch_wakeup_start(void); + +#endif diff --git a/arch/loongarch/power/suspend.c b/arch/loongarch/power/suspend.c index 5e19733e5e05..166d9e06a64b 100644 --- a/arch/loongarch/power/suspend.c +++ b/arch/loongarch/power/suspend.c @@ -27,7 +27,7 @@ struct saved_registers { }; static struct saved_registers saved_regs; -static void arch_common_suspend(void) +void loongarch_common_suspend(void) { save_counter(); saved_regs.pgd = csr_read64(LOONGARCH_CSR_PGDL); @@ -40,7 +40,7 @@ static void arch_common_suspend(void) loongarch_suspend_addr = loongson_sysconf.suspend_addr; } -static void arch_common_resume(void) +void loongarch_common_resume(void) { sync_counter(); local_flush_tlb_all(); @@ -62,12 +62,12 @@ int loongarch_acpi_suspend(void) enable_gpe_wakeup(); enable_pci_wakeup(); - arch_common_suspend(); + loongarch_common_suspend(); /* processor specific suspend */ loongarch_suspend_enter(); - arch_common_resume(); + loongarch_common_resume(); return 0; } From patchwork Thu Jun 15 09:17:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 108367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp501311vqr; Thu, 15 Jun 2023 02:29:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7PXu/NWoutehiT7I1nu0GMjgfI7GJd6XwKfXc3Xgx9tO/qkpKgkTCZaEoaxnD6IeCQT9CB X-Received: by 2002:a05:6a20:8e07:b0:10e:f1e3:8217 with SMTP id y7-20020a056a208e0700b0010ef1e38217mr4156405pzj.17.1686821365897; Thu, 15 Jun 2023 02:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686821365; cv=none; d=google.com; s=arc-20160816; b=vz5pWqiQaRB4DZRU9e6Nlb1BzJwh6UQzJdiT1kymsstrxPj9v0CL3gDNt0NqzPz6bc XTJggPwvx1NzY5DZViWPPAWl5NURtNeaqR1+0PHe9Wut5WizmpcVZN+OmzzuECUhJp7O ngU3oQA0IIxoqA22xnprIAiegutDLUkkYM0ZB8m19uThpR5DvIXGfs6tcJqRcYrisEps zluU8dszsX85heFh7/FbdA4IGHmxiBwrk7ETZD1U/H2pivjeu934O9CSzJqJd+iZwGCL J4LRYiNexxpSW6d6yCU15XqW5gZ82yUwBFWo6cuBeJHm/f/80xRkF0/pq2Cj1cspDkgz 2cQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=723AZ0EXAwi0zqTlYbr4E4ZOZWf0CwSFrsIe5gxthxU=; b=F/0FnG5a92gn9nO0bGrwy2qnSNn5CQlDoi3/CZ1kKOiIpKT1PWF61Q9GJfe17XNbo1 Xc7bAUV6PSIfWMpnqQgVii3eD5RrIYwUFz4APq9BqruAZ2oCytpsFrvqhCholzOGKu2R Sufu23wzoZronL8mi15y8iZbI0v2Rd8l86TvK7ss92Eask6CZihxU0BDpyKkPwTKcEW3 NJZyzRpJcSQQlxw1il2mU8gwVNjZyQKe1piNCXTHoX1L2SMWNwiyaMA9qASLC6ZB/R+d LaWGAYiDGlV7f3BZDYEIfHK43oX0sg1Im2JEA4N6aqa08KLUcXK+kBvWrQKKucuytggY xTpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iy9-20020a170903130900b001ae6b1c3fb6si11987364plb.470.2023.06.15.02.29.10; Thu, 15 Jun 2023 02:29:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245432AbjFOJSU (ORCPT + 99 others); Thu, 15 Jun 2023 05:18:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241335AbjFOJSQ (ORCPT ); Thu, 15 Jun 2023 05:18:16 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F2E21BEC; Thu, 15 Jun 2023 02:18:14 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.35]) by gateway (Coremail) with SMTP id _____8DxCepU14pkVYAFAA--.11780S3; Thu, 15 Jun 2023 17:18:12 +0800 (CST) Received: from user-pc.202.106.0.20 (unknown [10.20.42.35]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxVeRH14pkxssbAA--.13716S4; Thu, 15 Jun 2023 17:18:04 +0800 (CST) From: Yinbo Zhu To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Huacai Chen , WANG Xuerui , "Rafael J . Wysocki" , Pavel Machek , Marc Zyngier , Arnd Bergmann , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev Cc: Jianmin Lv , wanghongliang@loongson.cn, Liu Peibao , loongson-kernel@lists.loongnix.cn, Yinbo Zhu Subject: [PATCH v3 2/3] soc: dt-bindings: add loongson-2 pm Date: Thu, 15 Jun 2023 17:17:56 +0800 Message-Id: <20230615091757.24686-3-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230615091757.24686-1-zhuyinbo@loongson.cn> References: <20230615091757.24686-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxVeRH14pkxssbAA--.13716S4 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768760400444641402?= X-GMAIL-MSGID: =?utf-8?q?1768760400444641402?= Add the Loongson-2 SoC Power Management Controller binding with DT schema format using json-schema. Signed-off-by: Yinbo Zhu Reviewed-by: Krzysztof Kozlowski --- .../soc/loongson/loongson,ls2k-pmc.yaml | 53 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml diff --git a/Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml b/Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml new file mode 100644 index 000000000000..32499bd10f8c --- /dev/null +++ b/Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/loongson/loongson,ls2k-pmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Loongson-2 Power Manager controller + +maintainers: + - Yinbo Zhu + +properties: + compatible: + oneOf: + - items: + - enum: + - loongson,ls2k1000-pmc + - loongson,ls2k0500-pmc + - const: syscon + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + suspend-address: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The "suspend-address" is a deep sleep state (Suspend To RAM) + firmware entry address which was jumped from kernel and it's + value was dependent on specific platform firmware code. In + addition, the PM need according to it to indicate that current + SoC whether support Suspend To RAM. + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include + + pmc: pm@1fe27000 { + compatible = "loongson,ls2k1000-pmc", "syscon"; + reg = <0x1fe27000 0x58>; + interrupt-parent = <&liointc1>; + interrupts = <11 IRQ_TYPE_LEVEL_LOW>; + suspend-address = <0x1c000500>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 7a91f14cad2e..bcd05f1fa5c1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12190,6 +12190,12 @@ S: Maintained F: Documentation/devicetree/bindings/hwinfo/loongson,ls2k-chipid.yaml F: drivers/soc/loongson/loongson2_guts.c +LOONGSON-2 SOC SERIES PM DRIVER +M: Yinbo Zhu +L: linux-pm@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml + LOONGSON-2 SOC SERIES PINCTRL DRIVER M: zhanghongchen M: Yinbo Zhu From patchwork Thu Jun 15 09:37:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 108419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp530015vqr; Thu, 15 Jun 2023 03:30:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZcJJCxGilDxEELiHd029Hw3TSELU+2KVlbiboFfnwl4zOF+uqoyRO8/UYYriDZCSoFhAr X-Received: by 2002:a17:90a:1909:b0:25b:dae4:205 with SMTP id 9-20020a17090a190900b0025bdae40205mr3537268pjg.32.1686825005940; Thu, 15 Jun 2023 03:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686825005; cv=none; d=google.com; s=arc-20160816; b=uj9B6ooM9RNhvzngVVHF/ukuuGnH8STYpsO9ExIBpiCdbvFr6kt5sxbQeu5knA7SAm qzbysbUDc7t4d9q+KhknvprF5scW/BBOEZkdzYoYoV/Ht7qrCDKY6zRVrz4AfXzyk15w XHOsjLvaFlJM0Tn2Gob1t6hNiHDueveyDBD9EwicFOHXdNkeoyW6JR1qZpA8oDd9ShC0 yR76qlzRnp/dEPLsUT5YXP/3mUbdrjTDj3yp9+vRfax+keOsG1/oIhN5druva7irxLW3 aQnncgTAwwrqw9h4HVeOiNmmaWGBaOFB/Pn51kdPHtki1CHi5Ie5bSvXb14C5UiOmPV4 l9PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=0XFayibMwIRCXBj7uYpmFwqXLdB39kJesAepcKc6k34=; b=epBc47vHOvsoyxINDBW8PJjqJSsllXOsgV32sH5OBQHl8QAQ2ZxDfU6eYw/DKgUZt2 RcSmnI1Va3pPLs46voNRcafO9emUQfl9fg+MWuLawIC8Auto606hIAtNdz+E8xumDUPy Gzqc18PGmr8T6K2t/JfpuQ8DmInW407iQmFI9EXbKpNCH7oT4j/nUXjAiMFTyF2+lhbL UAEMU7bcII/36XKOVxKYgN33pO/9Wj9YqOTmFyEsyhGxCC9V00qye20/66EGg5aEJtzg 1FOnyaXNczqAJthYprVsghs/9SqFEodYW7djgCak9SR3d3YcKwBINVX1pmArfTtZTaYk 73Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902a40100b001b046c37589si9354385plq.428.2023.06.15.03.29.53; Thu, 15 Jun 2023 03:30:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343536AbjFOJjO (ORCPT + 99 others); Thu, 15 Jun 2023 05:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245611AbjFOJi6 (ORCPT ); Thu, 15 Jun 2023 05:38:58 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 11A623C0D; Thu, 15 Jun 2023 02:37:56 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.35]) by gateway (Coremail) with SMTP id _____8CxvOrR24pkNIIFAA--.11718S3; Thu, 15 Jun 2023 17:37:21 +0800 (CST) Received: from [10.20.42.35] (unknown [10.20.42.35]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxCOXO24pkg9EbAA--.13406S3; Thu, 15 Jun 2023 17:37:19 +0800 (CST) Subject: [PATCH v3 3/3] soc: loongson2_pm: add power management support To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Huacai Chen , WANG Xuerui , "Rafael J . Wysocki" , Pavel Machek , Marc Zyngier , Arnd Bergmann , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev Cc: Jianmin Lv , wanghongliang@loongson.cn, Liu Peibao , loongson-kernel@lists.loongnix.cn, zhuyinbo@loongson.cn References: <20230615091757.24686-1-zhuyinbo@loongson.cn> From: zhuyinbo Message-ID: <968b7c81-a24e-1e0d-31a4-f633a82d17b0@loongson.cn> Date: Thu, 15 Jun 2023 17:37:18 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20230615091757.24686-1-zhuyinbo@loongson.cn> Content-Language: en-US X-CM-TRANSID: AQAAf8CxCOXO24pkg9EbAA--.13406S3 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768761831782638132?= X-GMAIL-MSGID: =?utf-8?q?1768764217513260590?= From 6edcb9d6a1b18ccbecaf283b4f543afc9e7126d6 Mon Sep 17 00:00:00 2001 From: Yinbo Zhu Date: Tue, 18 Apr 2023 14:18:00 +0800 Subject: [PATCH v3 3/3] soc: loongson2_pm: add power management support The Loongson-2's power management controller was ACPI, supports ACPI S2Idle (Suspend To Idle), ACPI S3 (Suspend To RAM), ACPI S4 (Suspend To Disk), ACPI S5 (Soft Shutdown) and supports multiple wake-up methods (USB, GMAC, PWRBTN, etc.). This driver was to add power management controller support that base on dts for Loongson-2 series SoCs. Signed-off-by: Liu Yun Signed-off-by: Liu Peibao Signed-off-by: Yinbo Zhu --- MAINTAINERS | 1 + drivers/soc/loongson/Kconfig | 10 ++ drivers/soc/loongson/Makefile | 1 + drivers/soc/loongson/loongson2_pm.c | 218 ++++++++++++++++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 drivers/soc/loongson/loongson2_pm.c +MODULE_LICENSE("GPL"); diff --git a/MAINTAINERS b/MAINTAINERS index bcd05f1fa5c1..7c4ad0cbaeff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12195,6 +12195,7 @@ M: Yinbo Zhu L: linux-pm@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml +F: drivers/soc/loongson/loongson2_pm.c LOONGSON-2 SOC SERIES PINCTRL DRIVER M: zhanghongchen diff --git a/drivers/soc/loongson/Kconfig b/drivers/soc/loongson/Kconfig index 707f56358dc4..4f3ce9eb7520 100644 --- a/drivers/soc/loongson/Kconfig +++ b/drivers/soc/loongson/Kconfig @@ -16,3 +16,13 @@ config LOONGSON2_GUTS SoCs. Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading firmware configuration by default, should eventually be added into this driver as well. + +config LOONGSON2_PM + bool "Loongson-2 SoC Power Management Controller Driver" + depends on LOONGARCH && OF + help + The Loongson-2's power management controller was ACPI, supports ACPI + S2Idle (Suspend To Idle), ACPI S3 (Suspend To RAM), ACPI S4 (Suspend To + Disk), ACPI S5 (Soft Shutdown) and supports multiple wake-up methods + (USB, GMAC, PWRBTN, etc.). This driver was to add power management + controller support that base on dts for Loongson-2 series SoCs. diff --git a/drivers/soc/loongson/Makefile b/drivers/soc/loongson/Makefile index 263c486df638..4118f50f55e2 100644 --- a/drivers/soc/loongson/Makefile +++ b/drivers/soc/loongson/Makefile @@ -4,3 +4,4 @@ # obj-$(CONFIG_LOONGSON2_GUTS) += loongson2_guts.o +obj-$(CONFIG_LOONGSON2_PM) += loongson2_pm.o diff --git a/drivers/soc/loongson/loongson2_pm.c b/drivers/soc/loongson/loongson2_pm.c new file mode 100644 index 000000000000..287828413d72 --- /dev/null +++ b/drivers/soc/loongson/loongson2_pm.c @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Loongson-2 PM Support + * + * Copyright (C) 2023 Loongson Technology Corporation Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOONGSON2_PM1_CNT_REG 0x14 +#define LOONGSON2_PM1_STS_REG 0x0c +#define LOONGSON2_PM1_ENA_REG 0x10 +#define LOONGSON2_GPE0_STS_REG 0x28 +#define LOONGSON2_GPE0_ENA_REG 0x2c + +#define LOONGSON2_PM1_PWRBTN_STS BIT(8) +#define LOONGSON2_PM1_PCIEXP_WAKE_STS BIT(14) +#define LOONGSON2_PM1_WAKE_STS BIT(15) +#define LOONGSON2_PM1_CNT_INT_EN BIT(0) +#define LOONGSON2_PM1_PWRBTN_EN LOONGSON2_PM1_PWRBTN_STS + +static struct loongson2_pm { + void __iomem *base; + struct input_dev *dev; + bool suspended; +} loongson2_pm; + +#define loongson2_pm_readw(reg) readw(loongson2_pm.base + reg) +#define loongson2_pm_readl(reg) readl(loongson2_pm.base + reg) +#define loongson2_pm_writew(val, reg) writew(val, loongson2_pm.base + reg) +#define loongson2_pm_writel(val, reg) writel(val, loongson2_pm.base + reg) + +static void loongson2_pm_status_clear(void) +{ + u16 value; + + value = loongson2_pm_readw(LOONGSON2_PM1_STS_REG); + value |= (LOONGSON2_PM1_PWRBTN_STS | LOONGSON2_PM1_PCIEXP_WAKE_STS | + LOONGSON2_PM1_WAKE_STS); + loongson2_pm_writew(value, LOONGSON2_PM1_STS_REG); + loongson2_pm_writel(loongson2_pm_readl(LOONGSON2_GPE0_STS_REG), + LOONGSON2_GPE0_STS_REG); +} + +static void loongson2_power_button_irq_enable(void) +{ + u16 value; + + value = loongson2_pm_readw(LOONGSON2_PM1_CNT_REG); + value |= LOONGSON2_PM1_CNT_INT_EN; + loongson2_pm_writew(value, LOONGSON2_PM1_CNT_REG); + + value = loongson2_pm_readw(LOONGSON2_PM1_ENA_REG); + value |= LOONGSON2_PM1_PWRBTN_EN; + loongson2_pm_writew(value, LOONGSON2_PM1_ENA_REG); +} + +static int loongson2_suspend_enter(suspend_state_t state) +{ + loongson2_pm_status_clear(); + loongarch_common_suspend(); + loongarch_suspend_enter(); + loongarch_common_resume(); + loongson2_power_button_irq_enable(); + pm_set_resume_via_firmware(); + + return 0; +} + +static int loongson2_suspend_begin(suspend_state_t state) +{ + pm_set_suspend_via_firmware(); + + return 0; +} + +static int loongson2_suspend_valid_state(suspend_state_t state) +{ + if (state == PM_SUSPEND_MEM) + return 1; + + return 0; +} + +static const struct platform_suspend_ops loongson2_suspend_ops = { + .valid = loongson2_suspend_valid_state, + .begin = loongson2_suspend_begin, + .enter = loongson2_suspend_enter, +}; + +static int loongson2_power_button_init(struct device *dev, int irq) +{ + int ret; + struct input_dev *button; + + button = input_allocate_device(); + if (!dev) + return -ENOMEM; + + button->name = "Power Button"; + button->phys = "pm/button/input0"; + button->id.bustype = BUS_HOST; + button->dev.parent = NULL; + input_set_capability(button, EV_KEY, KEY_POWER); + + ret = input_register_device(button); + if (ret) + goto free_dev; + + dev_pm_set_wake_irq(&button->dev, irq); + device_set_wakeup_capable(&button->dev, true); + device_set_wakeup_enable(&button->dev, true); + + loongson2_pm.dev = button; + dev_info(dev, "Power Button: Init successful!\n"); + + return 0; + +free_dev: + input_free_device(button); + + return ret; +} + +static irqreturn_t loongson2_pm_irq_handler(int irq, void *dev_id) +{ + u16 status = loongson2_pm_readw(LOONGSON2_PM1_STS_REG); + + if (!loongson2_pm.suspended && (status & LOONGSON2_PM1_PWRBTN_STS)) { + pr_info("Power Button pressed...\n"); + input_report_key(loongson2_pm.dev, KEY_POWER, 1); + input_sync(loongson2_pm.dev); + input_report_key(loongson2_pm.dev, KEY_POWER, 0); + input_sync(loongson2_pm.dev); + } + + loongson2_pm_status_clear(); + + return IRQ_HANDLED; +} + +static int __maybe_unused loongson2_pm_suspend(struct device *dev) +{ + loongson2_pm.suspended = true; + + return 0; +} + +static int __maybe_unused loongson2_pm_resume(struct device *dev) +{ + loongson2_pm.suspended = false; + + return 0; +} +static SIMPLE_DEV_PM_OPS(loongson2_pm_ops, loongson2_pm_suspend, loongson2_pm_resume); + +static int loongson2_pm_probe(struct platform_device *pdev) +{ + int irq, retval; + u32 suspend_addr; + struct device *dev = &pdev->dev; + + loongson2_pm.base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(loongson2_pm.base)) + return PTR_ERR(loongson2_pm.base); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + + if (!device_property_read_u32(dev, "suspend-address", &suspend_addr)) + loongson_sysconf.suspend_addr = (u64)phys_to_virt(suspend_addr); + else + dev_err(dev, "No suspend-address, could not support S3!\n"); + + if (loongson2_power_button_init(dev, irq)) + return -EINVAL; + + retval = devm_request_irq(&pdev->dev, irq, loongson2_pm_irq_handler, + IRQF_SHARED, "pm_irq", &loongson2_pm); + if (retval) + return retval; + + loongson2_power_button_irq_enable(); + loongson2_pm_status_clear(); + + if (loongson_sysconf.suspend_addr) + suspend_set_ops(&loongson2_suspend_ops); + + return 0; +} + +static const struct of_device_id loongson2_pm_match[] = { + { .compatible = "loongson,ls2k1000-pmc", }, + {}, +}; + +static struct platform_driver loongson2_pm_driver = { + .driver = { + .name = "ls2k-pm", + .pm = &loongson2_pm_ops, + .of_match_table = loongson2_pm_match, + }, + .probe = loongson2_pm_probe, +}; +module_platform_driver(loongson2_pm_driver); + +MODULE_DESCRIPTION("Loongson-2 PM driver");