From patchwork Thu Mar 30 13:16:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 9654133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0749260349 for ; Thu, 30 Mar 2017 13:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECC9628501 for ; Thu, 30 Mar 2017 13:15:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFDAC28510; Thu, 30 Mar 2017 13:15:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 549A728501 for ; Thu, 30 Mar 2017 13:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-reply-to:Message-id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=FTG+ch2dJhlwQmVKHYJ8tLGWLj49Kz5vUdotNrAxQDk=; b=o6Wo2/2itxPIul6S3GjtEtiZiW copjdEY0IfjIc5DwkMdCOjBmDN7ceglxcamkt8q5bqpqSlotQV9IUMQ26m9hqFEsMZCD9lEX+EUxW vkXJSS0NtMsqlNlZqgRiJ+8H6JCIH4M//dJNWqiFFZLS2FvVm+aJCIVxPTQ0Pjvj1jRCGOqHJd1PG ZJ5HzHSAlz6Uk+w9r2jsbdLfTtxG/UMAletKJrgDxO8XAxeA4/h1hHJbPlC91mzvWmn8gMd8cPwos 0vjcqJ2I/dZUlCXf1y3lWUXXC3gh3SLvuXgNDbXJoEjtzuAydfialKORLtjefpPZqkQMBd3y+lPgm tMcMSS9Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctZvY-0002Go-LR; Thu, 30 Mar 2017 13:15:48 +0000 Received: from mailout2.samsung.com ([203.254.224.25] helo=epoutp02.samsung.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctZuX-0000Jg-3D for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2017 13:14:49 +0000 Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by epoutp02.samsung.com (KnoxPortal) with ESMTP id 20170330131420epoutp020307ac8253bcf8dc4db72c9d9b7c20b6~wqycBJr2S0839708397epoutp02w; Thu, 30 Mar 2017 13:14:20 +0000 (GMT) Received: from epsmges5p3.samsung.com (unknown [182.195.42.46]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20170330131420epcas5p3b82afff74cd3f3f73fc28d9d5fb27555~wqyboRLxG0986309863epcas5p3V; Thu, 30 Mar 2017 13:14:20 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3.samsung.com (EPCPMTA) with SMTP id 06.C9.18112.CA40DD85; Thu, 30 Mar 2017 22:14:20 +0900 (KST) Received: from epcpsbgm2new.samsung.com (u27.gpu120.samsung.co.kr [203.254.230.27]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20170330131419epcas5p4ac36250d3a9225643e327e60f47956c2~wqybIOMsX2027120271epcas5p4M; Thu, 30 Mar 2017 13:14:19 +0000 (GMT) X-AuditID: b6c32a2e-f79506d0000046c0-a1-58dd04accaa2 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 1C.1B.05013.BA40DD85; Thu, 30 Mar 2017 22:14:19 +0900 (KST) Received: from pankaj.com ([107.108.83.125]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ONM009R0Q3AAC60@mmp2.samsung.com>; Thu, 30 Mar 2017 22:14:19 +0900 (KST) From: Pankaj Dubey To: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v9 01/12] ARM: EXYNOS: refactor firmware specific routines Date: Thu, 30 Mar 2017 18:46:55 +0530 Message-id: <1490879826-16754-2-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1490879826-16754-1-git-send-email-pankaj.dubey@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJIsWRmVeSWpSXmKPExsWy7bCmhu4alrsRBuef8FjcWneO1eLvpGPs Fs+Oalu8ebuGyaL/8Wtmi/PnN7BbbHp8jdVixvl9TBYvj/xgtFh75C67xaKtX9gduD1+/5rE 6HHrTr3Hzll32T02repk89i8pN5jSz+Q17dlFaPH501yARxRXDYpqTmZZalF+nYJXBkXu/UL 7hlXnDjQwdbAeFqri5GTQ0LAROLyyq3sELaYxIV769lAbCGBpYwSs467dzFyAdntTBLvjq1g 6WLkAGs4s7sWomYOo8Tl90oQNe8YJd7cXsUCkmAT0JV48n4uM4gtIuAtMfnMX3aQImaBa4wS C7tXgCWEBbwkdp3qZAKxWQRUJTb3XQCzeQU8JCbuf8MKcZGcxM1znWD1nAKeEicfTWMDGSQh sIhdYs7fjWwQF8lKbDrADFHvItGzvROqV1ji1fEtUJ9JS/xdeosRorcb6LPpV9kgEusZJS78 To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AhgfTEktTs 1NSC1CKYPiYOTqkGxqSm20X6zvlnGtMPekwNOLfcmfl80akXs3cYrFki5dd+TEZT3ea+TpAf k1XaYrmwxgMT33ScmKf5u0qz1Gh59f39ijPubEtiPpm9PqJt6ZsHJyqXnyiYIWd9WvvbiQMW UTlKrqoiexyvF58JNxfPlE+cZL3SXs+e84yxYZSSU26c1nmLDb1ySizFGYmGWsxFxYkAWlVW /J4CAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170330131419epcas5p4ac36250d3a9225643e327e60f47956c2 X-Msg-Generator: CA X-Sender-IP: 203.254.230.27 X-Local-Sender: =?UTF-8?B?7YyQ7Lm07KaIG1NTSVItVHVybiBLZXkgU29sdXRpb25zGw==?= =?UTF-8?B?7IK87ISx7KCE7J6QGy4vU2VuaW9yIENoaWVmIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?UEFOS0FKIEtVTUFSIERVQkVZG1NTSVItVHVybiBLZXkgU29s?= =?UTF-8?B?dXRpb25zG1NhbXN1bmcgRWxlY3Ryb25pY3MbLi9TZW5pb3IgQ2hpZWYgRW5n?= =?UTF-8?B?aW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1NXQUhRG0MxMElEMDdJRDAxMDk5Nw==?= CMS-TYPE: 105P X-CMS-RootMailID: 20170330131419epcas5p4ac36250d3a9225643e327e60f47956c2 X-RootMTR: 20170330131419epcas5p4ac36250d3a9225643e327e60f47956c2 References: <1490879826-16754-1-git-send-email-pankaj.dubey@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_061445_510506_251CE017 X-CRM114-Status: GOOD ( 13.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: arnd@arndb.de, javier@osg.samsung.com, Pankaj Dubey , krzk@kernel.org, m.reichl@fivetechno.de, a.hajda@samsung.com, kgene@kernel.org, cwchoi00@gmail.com, m.szyprowski@samsung.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP To remove dependency on soc_is_exynosMMMM macros and remove multiple checks for such macros, let's refactor code in firmware.c file. SoC specific firmware_ops are separated and registered during exynos_firmware_init based on matching machine compatible. Signed-off-by: Pankaj Dubey Reviewed-by: Krzysztof Kozlowski --- arch/arm/mach-exynos/firmware.c | 114 +++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 25 deletions(-) diff --git a/arch/arm/mach-exynos/firmware.c b/arch/arm/mach-exynos/firmware.c index e81a78b..b04c47a 100644 --- a/arch/arm/mach-exynos/firmware.c +++ b/arch/arm/mach-exynos/firmware.c @@ -35,6 +35,25 @@ static void exynos_save_cp15(void) : : "cc"); } +static int exynos3250_do_idle(unsigned long mode) +{ + switch (mode) { + case FW_DO_IDLE_AFTR: + writel_relaxed(virt_to_phys(exynos_cpu_resume_ns), + sysram_ns_base_addr + 0x24); + writel_relaxed(EXYNOS_AFTR_MAGIC, sysram_ns_base_addr + 0x20); + flush_cache_all(); + exynos_smc(SMC_CMD_SAVE, OP_TYPE_CORE, + SMC_POWERSTATE_IDLE, 0); + exynos_smc(SMC_CMD_SHUTDOWN, OP_TYPE_CLUSTER, + SMC_POWERSTATE_IDLE, 0); + break; + case FW_DO_IDLE_SLEEP: + exynos_smc(SMC_CMD_SLEEP, 0, 0, 0); + } + return 0; +} + static int exynos_do_idle(unsigned long mode) { switch (mode) { @@ -44,14 +63,7 @@ static int exynos_do_idle(unsigned long mode) writel_relaxed(__pa_symbol(exynos_cpu_resume_ns), sysram_ns_base_addr + 0x24); writel_relaxed(EXYNOS_AFTR_MAGIC, sysram_ns_base_addr + 0x20); - if (soc_is_exynos3250()) { - flush_cache_all(); - exynos_smc(SMC_CMD_SAVE, OP_TYPE_CORE, - SMC_POWERSTATE_IDLE, 0); - exynos_smc(SMC_CMD_SHUTDOWN, OP_TYPE_CLUSTER, - SMC_POWERSTATE_IDLE, 0); - } else - exynos_smc(SMC_CMD_CPU0AFTR, 0, 0, 0); + exynos_smc(SMC_CMD_CPU0AFTR, 0, 0, 0); break; case FW_DO_IDLE_SLEEP: exynos_smc(SMC_CMD_SLEEP, 0, 0, 0); @@ -59,28 +71,25 @@ static int exynos_do_idle(unsigned long mode) return 0; } -static int exynos_cpu_boot(int cpu) +static int exynos4212_cpu_boot(int cpu) { /* - * Exynos3250 doesn't need to send smc command for secondary CPU boot - * because Exynos3250 removes WFE in secure mode. - */ - if (soc_is_exynos3250()) - return 0; - - /* * The second parameter of SMC_CMD_CPU1BOOT command means CPU id. * But, Exynos4212 has only one secondary CPU so second parameter * isn't used for informing secure firmware about CPU id. */ - if (soc_is_exynos4212()) - cpu = 0; + cpu = 0; + exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0); + return 0; +} +static int exynos_cpu_boot(int cpu) +{ exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0); return 0; } -static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr) +static int exynos4412_set_cpu_boot_addr(int cpu, unsigned long boot_addr) { void __iomem *boot_reg; @@ -94,14 +103,24 @@ static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr) * additional offset for every CPU, with Exynos4412 being the only * exception. */ - if (soc_is_exynos4412()) - boot_reg += 4 * cpu; + boot_reg += 4 * cpu; + writel_relaxed(boot_addr, boot_reg); + return 0; +} + +static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr) +{ + void __iomem *boot_reg; + + if (!sysram_ns_base_addr) + return -ENODEV; + boot_reg = sysram_ns_base_addr + 0x1c; writel_relaxed(boot_addr, boot_reg); return 0; } -static int exynos_get_cpu_boot_addr(int cpu, unsigned long *boot_addr) +static int exynos4412_get_cpu_boot_addr(int cpu, unsigned long *boot_addr) { void __iomem *boot_reg; @@ -109,10 +128,19 @@ static int exynos_get_cpu_boot_addr(int cpu, unsigned long *boot_addr) return -ENODEV; boot_reg = sysram_ns_base_addr + 0x1c; + boot_reg += 4 * cpu; + *boot_addr = readl_relaxed(boot_reg); + return 0; +} + +static int exynos_get_cpu_boot_addr(int cpu, unsigned long *boot_addr) +{ + void __iomem *boot_reg; - if (soc_is_exynos4412()) - boot_reg += 4 * cpu; + if (!sysram_ns_base_addr) + return -ENODEV; + boot_reg = sysram_ns_base_addr + 0x1c; *boot_addr = readl_relaxed(boot_reg); return 0; } @@ -148,6 +176,32 @@ static int exynos_resume(void) return 0; } +static const struct firmware_ops exynos3250_firmware_ops = { + .do_idle = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos3250_do_idle : NULL, + .set_cpu_boot_addr = exynos_set_cpu_boot_addr, + .get_cpu_boot_addr = exynos_get_cpu_boot_addr, + .suspend = IS_ENABLED(CONFIG_PM_SLEEP) ? exynos_suspend : NULL, + .resume = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos_resume : NULL, +}; + +static const struct firmware_ops exynos4212_firmware_ops = { + .do_idle = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos_do_idle : NULL, + .set_cpu_boot_addr = exynos_set_cpu_boot_addr, + .get_cpu_boot_addr = exynos_get_cpu_boot_addr, + .cpu_boot = exynos4212_cpu_boot, + .suspend = IS_ENABLED(CONFIG_PM_SLEEP) ? exynos_suspend : NULL, + .resume = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos_resume : NULL, +}; + +static const struct firmware_ops exynos4412_firmware_ops = { + .do_idle = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos_do_idle : NULL, + .set_cpu_boot_addr = exynos4412_set_cpu_boot_addr, + .get_cpu_boot_addr = exynos4412_get_cpu_boot_addr, + .cpu_boot = exynos_cpu_boot, + .suspend = IS_ENABLED(CONFIG_PM_SLEEP) ? exynos_suspend : NULL, + .resume = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos_resume : NULL, +}; + static const struct firmware_ops exynos_firmware_ops = { .do_idle = IS_ENABLED(CONFIG_EXYNOS_CPU_SUSPEND) ? exynos_do_idle : NULL, .set_cpu_boot_addr = exynos_set_cpu_boot_addr, @@ -198,6 +252,7 @@ void __init exynos_firmware_init(void) { struct device_node *nd; const __be32 *addr; + const struct firmware_ops *ops; nd = of_find_compatible_node(NULL, NULL, "samsung,secure-firmware"); @@ -212,7 +267,16 @@ void __init exynos_firmware_init(void) pr_info("Running under secure firmware.\n"); - register_firmware_ops(&exynos_firmware_ops); + if (of_machine_is_compatible("samsung,exynos3250")) + ops = &exynos3250_firmware_ops; + else if (of_machine_is_compatible("samsung,exynos4212")) + ops = &exynos4212_firmware_ops; + else if (of_machine_is_compatible("samsung,exynos4412")) + ops = &exynos4412_firmware_ops; + else + ops = &exynos_firmware_ops; + + register_firmware_ops(ops); /* * Exynos 4 SoCs (based on Cortex A9 and equipped with L2C-310),