From patchwork Wed May 17 07:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 95087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp834883rwl; Wed, 17 May 2023 00:46:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+S/A84pUSWwI0QKfnaF6aRsFDUtolgfA8TPoMZhQa6gkDjCvrasgLnQaHNoMcvGC6jWqq X-Received: by 2002:a17:902:d483:b0:1ac:896f:f655 with SMTP id c3-20020a170902d48300b001ac896ff655mr38857489plg.50.1684309571137; Wed, 17 May 2023 00:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684309571; cv=none; d=google.com; s=arc-20160816; b=h0ZRfmeuQ1zs7a/Ir3QGcZxGRvMBZcrDUMCnzeBS0LpKMteT0lvWp1RZ1dazdE/wW7 ZvbMxOXj4n6UiU46/reZvPL4KFxoufR/X61oqLwjVrxZu2wph96xn8sgFpPAitJtPpEI BtyDcGE/zObsNouxh9760hKr7KO4LhJ80nZUNh8S7UInzAKK6axst+nYa1HM0Xja56Qs Fg2LrvwDeogcfWnXhxxC53dKrbpl62NDey6nHF7r3sltyLCJoNqC8WwQkXURGNLZG1Vg iktcEduuHKMbpt01v2yGjOuiMqOfyyhgXfW/LJTw6KzYcFZAWNrEnHjVI/Uf98LIbaxb uPkg== 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=3u6jmvc1p91KX1IQjFkSkJ+qbE7G8nsECw4x6nDEdiQ=; b=IIph3cnW1KcswxWrio1ALozxScWUU8ui6xjObchk9H+5wyF1QoyX2A7VXUTCRs5WyS YAG/ZLhfPiuGIZ1kDUhVLMmV6qKEDk0zebSgpdJ0KrHrF8OxKHyAEsoFU3K3Uu28pD7e nAJGBlzwblSJIFc2uCCtNoR0OjaZToySBHpxdDSzCYuCiV7QCAmyXDC9XOI/dl8NTPMm pTxAnyQz/pjov9URnURd59Afi9FWYWEd2xCo44BEQLJn/HbwZNbrnURQZsG7DY0uNAu/ K2RRtzt5jKieSDWyXe5yDRPpNk0I1gG96A275R4yIZSYLuwxbIXm34RNwzMhEpQoP2ev 9zEg== 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 u19-20020a63b553000000b0053084a794f0si14855111pgo.290.2023.05.17.00.45.56; Wed, 17 May 2023 00:46:11 -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 S229989AbjEQHcX (ORCPT + 99 others); Wed, 17 May 2023 03:32:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbjEQHcB (ORCPT ); Wed, 17 May 2023 03:32:01 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 788451717; Wed, 17 May 2023 00:31:58 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.35]) by gateway (Coremail) with SMTP id _____8Cxe+rtgmRkN2oJAA--.16218S3; Wed, 17 May 2023 15:31:57 +0800 (CST) Received: from user-pc.202.106.0.20 (unknown [10.20.42.35]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axmr3lgmRk_1plAA--.41619S3; Wed, 17 May 2023 15:31:55 +0800 (CST) From: Yinbo Zhu To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Huacai Chen , WANG Xuerui , "Rafael J . Wysocki" , Pavel Machek , Tiezhu Yang , Marc Zyngier , Youling Tang , Baoqi Zhang , Arnd Bergmann , Yun Liu , 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 v1 1/3] loongarch: export loongarch pm interface Date: Wed, 17 May 2023 15:31:47 +0800 Message-Id: <20230517073149.31980-2-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230517073149.31980-1-zhuyinbo@loongson.cn> References: <20230517073149.31980-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Axmr3lgmRk_1plAA--.41619S3 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCr4rXF1rtw47WFWDtw4fKrg_yoWrCry7p3 sFyrn8Kw4Fkr1rZryDtas8Xr15JrZ5Kr429a9rK3yUCwsrXw1rur1kKr98WF1jkw1rGF40 9ryFga1Y9F1UG3JanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bfkFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUXVWUAwA2ocxC64 kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28E F7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJwAaw2AFwI0_JF0_Jw1le2I262IYc4CY 6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x 0EwIxGrwCF04k20xvE74AGY7Cv6cx26rWl4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xF xVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWw C2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_ Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJV WUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxU2iFxUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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?1766126592911441790?= X-GMAIL-MSGID: =?utf-8?q?1766126592911441790?= 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 | 5 ++--- arch/loongarch/include/asm/suspend.h | 10 ++++++++++ arch/loongarch/power/suspend.c | 10 +++++----- arch/loongarch/power/suspend_asm.S | 8 ++++---- 4 files changed, 21 insertions(+), 12 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..d63507cc705f 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,13 +38,11 @@ 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; + return (unsigned long)loongson_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..a40b42f4f7f3 --- /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 loongson_common_resume(void); +void loongson_common_suspend(void); +void loongson_suspend_enter(void); +void loongson_wakeup_start(void); + +#endif diff --git a/arch/loongarch/power/suspend.c b/arch/loongarch/power/suspend.c index 5e19733e5e05..0587681b33ce 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 loongson_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 loongson_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(); + loongson_common_suspend(); /* processor specific suspend */ - loongarch_suspend_enter(); + loongson_suspend_enter(); - arch_common_resume(); + loongson_common_resume(); return 0; } diff --git a/arch/loongarch/power/suspend_asm.S b/arch/loongarch/power/suspend_asm.S index e2fc3b4e31f0..809abd3b119d 100644 --- a/arch/loongarch/power/suspend_asm.S +++ b/arch/loongarch/power/suspend_asm.S @@ -57,13 +57,13 @@ .align 12 /* Sleep/wakeup code for Loongson-3 */ -SYM_FUNC_START(loongarch_suspend_enter) +SYM_FUNC_START(loongson_suspend_enter) SETUP_SLEEP bl __flush_cache_all /* Pass RA and SP to BIOS */ addi.d a1, sp, 0 - la.pcrel a0, loongarch_wakeup_start + la.pcrel a0, loongson_wakeup_start la.pcrel t0, loongarch_suspend_addr ld.d t0, t0, 0 jirl a0, t0, 0 /* Call BIOS's STR sleep routine */ @@ -72,7 +72,7 @@ SYM_FUNC_START(loongarch_suspend_enter) * This is where we return upon wakeup. * Reload all of the registers and return. */ -SYM_INNER_LABEL(loongarch_wakeup_start, SYM_L_GLOBAL) +SYM_INNER_LABEL(loongson_wakeup_start, SYM_L_GLOBAL) li.d t0, CSR_DMW0_INIT # UC, PLV0 csrwr t0, LOONGARCH_CSR_DMWIN0 li.d t0, CSR_DMW1_INIT # CA, PLV0 @@ -89,4 +89,4 @@ SYM_INNER_LABEL(loongarch_wakeup_start, SYM_L_GLOBAL) SETUP_WAKEUP addi.d sp, sp, PT_SIZE jr ra -SYM_FUNC_END(loongarch_suspend_enter) +SYM_FUNC_END(loongson_suspend_enter) From patchwork Wed May 17 07:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 95084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp945390vqo; Wed, 17 May 2023 00:36:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7JYmgJc4MONqHmUHugxiGDVsPCXl3HvICeuRn+JbF1XJHRSUgxFIvxluz80sSmRTvRiNrJ X-Received: by 2002:a05:6a20:7492:b0:103:aa74:2b6f with SMTP id p18-20020a056a20749200b00103aa742b6fmr25262333pzd.7.1684308970689; Wed, 17 May 2023 00:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684308970; cv=none; d=google.com; s=arc-20160816; b=ThTHSFokwdzZk76EyOkVt4H8kKylqmH+RCtxMhofrGUAeZA7WhHt59XFu+HCYvi7gR /LZ1pnW21wMX4ITn6aTVTRM+Ve0Wcz1CMfOKxQhDEggaiEvg1YtoJyETGxYtWR2fSxmg BR4Ac3TicxvJ7x4JLWdmoOFUk1uIzMTtmuY/586mdA3zjehOFLQjFIhSTz5fj2Rc1hZs 2mpWPgIitaCN5IHc7JHcORe5b/q3BzRu38sBhMWGGh6WbfanJsRU62hiB6SrZYlTWuOH 1bYTYTrFmbqupSpbzoaf2HPM/BAn/toITKqQx1lvVpIEopbcYp7ICyBG/gpnFKTshy/s xILw== 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=eqHxGNKiROawdE2wymPNM0esXKwJBrp+3SftDgSa7aw=; b=J88Aoz/0kLZnqZQeaTe20Wi4jX6A+jjpF7LdJnxO5gCufe2+CzBlJZgmJaoExlCTn4 SQlfdWQES/6oHjHgGhL/ZC21ZGVtrvHG0qODSuOwGsmdWu2ursEVRIFKU4rgapVLuzrd pzz8K0fx0ob8uH/MfunCO5KsEO2qQ2OnyOAeE/gBWxU9oSj/YjIg3i2Z75Kzz+wAbd1A 75iXrOrRrXYGPVwZzGvNWwMZJRlBRqtNcKwYhqysb6WKXRFolfi0gh49Ej60hpB1T00p HPSEI/CW4fjuDm0BUXC3feaiHvfRPtUZCQCPWxjPTkRX9D9/Tw/Ng1EFZbNhHqy1cxk7 OKHw== 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 b15-20020a63340f000000b005303b3da2d1si21572738pga.173.2023.05.17.00.35.55; Wed, 17 May 2023 00:36:10 -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 S230073AbjEQHc1 (ORCPT + 99 others); Wed, 17 May 2023 03:32:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbjEQHcC (ORCPT ); Wed, 17 May 2023 03:32:02 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8D3519B0; Wed, 17 May 2023 00:31:59 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.35]) by gateway (Coremail) with SMTP id _____8Cx_erugmRkQGoJAA--.16200S3; Wed, 17 May 2023 15:31:58 +0800 (CST) Received: from user-pc.202.106.0.20 (unknown [10.20.42.35]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axmr3lgmRk_1plAA--.41619S4; Wed, 17 May 2023 15:31:56 +0800 (CST) From: Yinbo Zhu To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Huacai Chen , WANG Xuerui , "Rafael J . Wysocki" , Pavel Machek , Tiezhu Yang , Marc Zyngier , Youling Tang , Baoqi Zhang , Arnd Bergmann , Yun Liu , 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 v1 2/3] dt-bindings: soc: add loongson-2 pm Date: Wed, 17 May 2023 15:31:48 +0800 Message-Id: <20230517073149.31980-3-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230517073149.31980-1-zhuyinbo@loongson.cn> References: <20230517073149.31980-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Axmr3lgmRk_1plAA--.41619S4 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW7ArW7tFy3KryxJrykJFyrZwb_yoW8KFy3p3 ZxCas3KF40qF17Zws5KFy8C3W5ZF95C3ZrXFsrJw17Kr9rJ3WYvw43K3WDZF43Cry8JFW7 uF92krWjgFyUJw7anT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bfkFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUXVWUAwA2ocxC64 kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28E F7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJwAaw2AFwI0_JF0_Jw1le2I262IYc4CY 6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x 0EwIxGrwCF04k20xvE74AGY7Cv6cx26rWl4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xF xVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWw C2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_ Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJV WUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxU2iFxUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1766125963409311005?= X-GMAIL-MSGID: =?utf-8?q?1766125963409311005?= Add the Loongson-2 SoC Power Management Controller binding with DT schema format using json-schema. Signed-off-by: Yinbo Zhu --- .../soc/loongson/loongson,ls2k-pmc.yaml | 47 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 53 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..a52bfa5e3eb6 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/loongson/loongson,ls2k-pmc.yaml @@ -0,0 +1,47 @@ +# 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: + items: + - enum: + - loongson,ls2k-pmc + - const: syscon + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + suspend-address: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + This option indicate this PM suspend address. + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include + + pmc: pm@1fe27000 { + compatible = "loongson,ls2k-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 Wed May 17 07:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 95086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp834525rwl; Wed, 17 May 2023 00:45:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Ped91Dr8sAuuIBnHSWVGXVh+Ni63JEELiBXve5i42we/GGtqO7u7sYS2ygx4YWaKopuNr X-Received: by 2002:a17:90b:4c51:b0:250:5511:64b6 with SMTP id np17-20020a17090b4c5100b00250551164b6mr35748546pjb.44.1684309524056; Wed, 17 May 2023 00:45:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684309524; cv=none; d=google.com; s=arc-20160816; b=nmfnZsbwH7pyxWrMKelWaGyl70Kc3rR1DS7ZGLJKqsvk/iOseUwwA6ha+sUBm1TXjA Yeb5u68iFXebM/3rE43gx6NZZSggS+stUBSQ478p/rwQ62VnTRMIY/+uQEuXspKqnrP+ SIXTK3EE9hEf7g+CJdtzK3OukPLnaTEBvQNC8RS4Xf0aPS2vDyK2D+WDKPVvSIqgDApW FSNBVYDWkI223FKXHmDvN2lSwM05b4tlt82NN98EpuP7ZTnNIqOtyELPWGdx4xcuvoMb uOvPorcQnKxsWrucEEXkxhWuthreNh9wloZqPAdQz1nxs4vvrNeUWui5HiP31DCdDjJe lUzA== 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=S6SUKU/+LEHUipWZmfpJflQeMQAuDO/53f3rb4/SsRI=; b=MhSmfHHYeaOHDp3drTNqqcvhqNGbUfwJUxeyCzDoqFHwufynsEOt0ocDsVquyLP42W Lwd8VEl5a4IQtlp+lu2R12zhuGX657SzxyPigWH6q38qm9jqSXgn/qA4zY+6tH6vDEWA nkcV6LRB/LPkyxo7a2EY70WWxW6PEK1DpieRyEsv51MKpdGjq1C43/CIzkdU5aT/qG0z LMfsSbcCM529gSom8Zi0hWqGtEoEhuGMHSaPzf40/QZUkyTyy8z6w3LXM4eJA9d38Hat 6xQV31aPhMPwMMdaSsyOqCgLL/FtbbVUTfhFctfAfnde7XFVBhAg9tOIY8rqd7qQHkva R/mQ== 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 z19-20020a17090ad79300b002299b06dca9si1180524pju.83.2023.05.17.00.45.09; Wed, 17 May 2023 00:45:24 -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 S229964AbjEQHhY (ORCPT + 99 others); Wed, 17 May 2023 03:37:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230164AbjEQHgq (ORCPT ); Wed, 17 May 2023 03:36:46 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A1EC3E45; Wed, 17 May 2023 00:36:39 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.35]) by gateway (Coremail) with SMTP id _____8Bxb+sFhGRkm2oJAA--.16153S3; Wed, 17 May 2023 15:36:37 +0800 (CST) Received: from user-pc.202.106.0.20 (unknown [10.20.42.35]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxDbP9g2RkllxlAA--.42661S2; Wed, 17 May 2023 15:36:34 +0800 (CST) From: Yinbo Zhu To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Huacai Chen , WANG Xuerui , "Rafael J . Wysocki" , Pavel Machek , Tiezhu Yang , Marc Zyngier , Youling Tang , Baoqi Zhang , Arnd Bergmann , Yun Liu , 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 v1 3/3] soc: loongson2_pm: add power management support Date: Wed, 17 May 2023 15:36:25 +0800 Message-Id: <20230517073625.32090-1-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxDbP9g2RkllxlAA--.42661S2 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW3WryUJrWkCr4xGF1xGF17Wrg_yoWfAw4Up3 yfAay8GFWUGF43Zrn5XryDWF1YyFW3Ga9rJFZrGw1UG3s7Jwn5Wr1UJFyrZr4xAryDJFZr Z395CFWUCF4UWFUanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bS8Fc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUXVWUAwA2ocxC64 kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28E F7xvwVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr 1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkE cVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F4 0Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC 6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2 Ij64vIr41l42xK82IY6x8ErcxFaVAv8VWrMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI 1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_Jr Wlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj 6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r 1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1U YxBIdaVFxhVjvjDU0xZFpf9x07jetC7UUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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?1766126345243096324?= X-GMAIL-MSGID: =?utf-8?q?1766126543577848564?= 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 | 237 ++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 drivers/soc/loongson/loongson2_pm.c 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..2431a0bcbd84 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..e16a94544ed3 --- /dev/null +++ b/drivers/soc/loongson/loongson2_pm.c @@ -0,0 +1,237 @@ +// 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_pm_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); +} + +static void loongson2_pm_pwrbtn_irq_enable(void) +{ + u16 value; + + loongson2_pm_irq_enable(); + + value = loongson2_pm_readw(LOONGSON2_PM1_ENA_REG); + value |= LOONGSON2_PM1_PWRBTN_EN; + loongson2_pm_writew(value, LOONGSON2_PM1_ENA_REG); +} + +static void loongson2_pm_mach_resume(void) +{ + loongson_common_resume(); + loongson2_pm_irq_enable(); +} + +static void loongson2_pm_mach_suspend(void) +{ + loongson2_pm_status_clear(); + loongson_common_suspend(); +} + +static int loongson2_suspend_enter(suspend_state_t state) +{ + loongson2_pm_mach_suspend(); + loongson_suspend_enter(); + pm_set_resume_via_firmware(); + loongson2_pm_mach_resume(); + + 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 !!loongson_sysconf.suspend_addr; + + 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_pm_pwrbtn_init(struct device *dev, int irq) +{ + int ret; + struct input_dev *pwrbt; + + pwrbt = input_allocate_device(); + if (!dev) + return -ENOMEM; + + pwrbt->name = "Power Button"; + pwrbt->phys = "pm/button/input0"; + pwrbt->id.bustype = BUS_HOST; + pwrbt->dev.parent = NULL; + input_set_capability(pwrbt, EV_KEY, KEY_POWER); + + ret = input_register_device(pwrbt); + if (ret) + goto free_dev; + + dev_pm_set_wake_irq(&pwrbt->dev, irq); + device_set_wakeup_capable(&pwrbt->dev, true); + device_set_wakeup_enable(&pwrbt->dev, true); + + loongson2_pm.dev = pwrbt; + dev_info(dev, "Power Button: Init successful!\n"); + + return 0; + +free_dev: + input_free_device(pwrbt); + + 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"); + return -EINVAL; + } + + if (loongson2_pm_pwrbtn_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_pm_pwrbtn_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,ls2k-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"); +MODULE_LICENSE("GPL");