From patchwork Sat Dec 10 13:08:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 9469291 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 E21BD60231 for ; Sat, 10 Dec 2016 13:06:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3FCA284F0 for ; Sat, 10 Dec 2016 13:06:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C72292858C; Sat, 10 Dec 2016 13:06:26 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C5AD284F0 for ; Sat, 10 Dec 2016 13:06:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753198AbcLJNGZ (ORCPT ); Sat, 10 Dec 2016 08:06:25 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:50948 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752971AbcLJNGZ (ORCPT ); Sat, 10 Dec 2016 08:06:25 -0500 Received: from epcpsbgm1new.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OHZ01LMM0EMG690@mailout2.samsung.com> for linux-samsung-soc@vger.kernel.org; Sat, 10 Dec 2016 22:06:22 +0900 (KST) X-AuditID: cbfee61a-f79916d0000062de-19-584bfdceaf2b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 39.E3.25310.ECDFB485; Sat, 10 Dec 2016 22:06:22 +0900 (KST) Received: from pankaj.sisodomain.com ([107.108.83.125]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OHZ000990EAMM70@mmp1.samsung.com>; Sat, 10 Dec 2016 22:06:22 +0900 (KST) From: Pankaj Dubey To: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: krzk@kernel.org, arnd@arndb.de, geert+renesas@glider.be, m.szyprowski@samsung.com, javier@osg.samsung.com, kgene@kernel.org, thomas.ab@samsung.com, Pankaj Dubey Subject: [PATCH v8 4/8] ARM: EXYNOS: refactor firmware specific routines Date: Sat, 10 Dec 2016 18:38:39 +0530 Message-id: <1481375323-29724-5-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1481375323-29724-1-git-send-email-pankaj.dubey@samsung.com> References: <1481375323-29724-1-git-send-email-pankaj.dubey@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeLIzCtJLcpLzFFi42I5/e+xgO65v94RBk1rjC3+TjrGbjF39iRG izdv1zBZ9D9+zWxx/vwGdotNj6+xWsw4v4/JYu2Ru+wWi7Z+YbfoWMbowOXx+9ckRo+JZ3U9 Nq3qZPPYvKTeY0v/XXaPvi2rGD0+b5ILYI9ys8lITUxJLVJIzUvOT8nMS7dVCg1x07VQUshL zE21VYrQ9Q0JUlIoS8wpBfKMDNCAg3OAe7CSvl2CW8aFhgXMBX90K069/cnawPhStYuRk0NC wERi06n37BC2mMSFe+vZuhi5OIQEljJKvFhxkRHC+ckoMefXbxaQKjYBXYkn7+cyg9giAt4S k8/8ZQcpYhY4zChx6+UdNpCEsICHxLsl7awgNouAqsSGD71gK3iB4nMWHWaDWCcncfNcJ9gg TgFPiQe3p4DFhYBqvs/byDKBkXcBI8MqRonUguSC4qT0XMO81HK94sTc4tK8dL3k/NxNjOAY eCa1g/HgLvdDjAIcjEo8vA6HvCKEWBPLiitzDzFKcDArifDu/uEdIcSbklhZlVqUH19UmpNa fIjRFOiwicxSosn5wPjMK4k3NDE3MTc2sDC3tDQxUhLnbZz9LFxIID2xJDU7NbUgtQimj4mD U6qB8eREE/cfwosDsvadke6avWW/9rVFDJP8yzv6djy6fibrh6ttjOVD6/vTF3W6Ldu4KeTk i08K1gypH5T0bn86eyT1wbR3mYt1f/G86z5ZOKWsWq11rqDoxNZ6E74yfpFIBk/R651fbkRN rjpV5HX/2MSrZzYt/jFrh8gMYeY9hseauLdfKJvRMEeJpTgj0VCLuag4EQDoMGWnlwIAAA== X-MTR: 20000000000000000@CPGS Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To remove dependency on soc_is_exynosMMMM macros and remove multiple checks for such macros lets 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 --- arch/arm/mach-exynos/firmware.c | 100 ++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/arch/arm/mach-exynos/firmware.c b/arch/arm/mach-exynos/firmware.c index fd6da54..525fbd9 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(virt_to_phys(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 exynos4412_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,23 @@ 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 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 = exynos4412_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, @@ -212,7 +257,12 @@ 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")) + register_firmware_ops(&exynos3250_firmware_ops); + else if (of_machine_is_compatible("samsung,exynos4412")) + register_firmware_ops(&exynos4412_firmware_ops); + else + register_firmware_ops(&exynos_firmware_ops); /* * Exynos 4 SoCs (based on Cortex A9 and equipped with L2C-310),