From patchwork Mon Jul 7 13:01:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Sajjan X-Patchwork-Id: 4494711 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 308EEBEEAA for ; Mon, 7 Jul 2014 13:07:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02623202E6 for ; Mon, 7 Jul 2014 13:07:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF21E20274 for ; Mon, 7 Jul 2014 13:07:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X48bZ-0006QO-Af; Mon, 07 Jul 2014 13:05:13 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X48bV-0005Dq-NX for linux-arm-kernel@lists.infradead.org; Mon, 07 Jul 2014 13:05:11 +0000 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8C00DBKEZWC570@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 07 Jul 2014 22:04:44 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id CF.87.19452.CEA9AB35; Mon, 07 Jul 2014 22:04:44 +0900 (KST) X-AuditID: cbfee68e-b7fb96d000004bfc-45-53ba9aec7c8e Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 61.F1.04943.CEA9AB35; Mon, 07 Jul 2014 22:04:44 +0900 (KST) Received: from chromebld-server.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N8C00CNSEYNH630@mmp1.samsung.com>; Mon, 07 Jul 2014 22:04:44 +0900 (KST) From: Vikas Sajjan To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH v6 2/4] ARM: EXYNOS: Refactor the code to use DT based lookup Date: Mon, 07 Jul 2014 18:31:30 +0530 Message-id: <1404738090-30522-1-git-send-email-vikas.sajjan@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRmVeSWpSXmKPExsWyRsSkWvfNrF3BBrdnGlicXXaQzeL7ri/s Fr0LrrJZbHp8jdVixvl9TBZPDn9ktVi16w+jxc1n25kcODxmN1xk8dg56y67x+Yl9R59W1Yx enzeJBfAGsVlk5Kak1mWWqRvl8CVsXpNJ0vBDL+KvjPX2BoY1zl2MXJySAiYSPTt3MAMYYtJ XLi3nq2LkYtDSGApo8Svp8uYYIombdvKBJFYxCjxt/MulDOBSWLb6i/sIFVsAroSK049B2rn 4BAR8JZYfk0RpIZZYD6jxMTJX8BWCAv4SrxsamYBsVkEVCXWL1vLCmLzCnhInN6zhQmkV0JA QWLOJBuQXgmBbnaJm/tWQdULSHybfIgFokZWYtMBqKslJQ6uuMEygVFwASPDKkbR1ILkguKk 9CIjveLE3OLSvHS95PzcTYzA8D3971nfDsabB6wPMSYDjZvILCWanA8M/7ySeENjMyMLUxNT YyNzSzPShJXEeRc9TAoSEkhPLEnNTk0tSC2KLyrNSS0+xMjEwSnVwMh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/cI/ukAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140707_060510_122463_A1D7FEF6 X-CRM114-Status: GOOD ( 20.08 ) X-Spam-Score: -5.7 (-----) Cc: sajjan.linux@gmail.com, kgene.kim@samsung.com, tomasz.figa@gmail.com, dianders@chromium.org, Vikas Sajjan , joshi@samsung.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactoring the pm.c to avoid using "soc_is_exynos" checks, instead use the DT based lookup. While at it, consolidate the common code across SoCs and create a static helper functions. Signed-off-by: Vikas Sajjan --- arch/arm/mach-exynos/pm.c | 232 +++++++++++++++++++++++++++++++-------- arch/arm/mach-exynos/regs-pmu.h | 1 + 2 files changed, 189 insertions(+), 44 deletions(-) diff --git a/arch/arm/mach-exynos/pm.c b/arch/arm/mach-exynos/pm.c index ba75171..c0dae28 100644 --- a/arch/arm/mach-exynos/pm.c +++ b/arch/arm/mach-exynos/pm.c @@ -38,6 +38,8 @@ #include "regs-pmu.h" #include "regs-sys.h" +#define REG_TABLE_END (-1U) + /** * struct exynos_wkup_irq - Exynos GIC to PMU IRQ mapping * @hwirq: Hardware IRQ signal of the GIC @@ -61,6 +63,19 @@ static struct sleep_save exynos_core_save[] = { SAVE_ITEM(S5P_SROM_BC3), }; +struct exynos_pm_data { + const struct exynos_wkup_irq *wkup_irq; + unsigned int wake_disable_mask; + unsigned int *release_ret_regs; + + void (*pm_prepare)(void); + void (*pm_resume)(void); + int (*pm_suspend)(void); + int (*cpu_suspend)(unsigned long); +}; + +struct exynos_pm_data *pm_data; + /* * GIC wake-up support */ @@ -89,14 +104,21 @@ static inline u32 pmu_raw_readl(u32 offset) return __raw_readl(pmu_base_addr + offset); } +unsigned int exynos_release_ret_regs[] = { + S5P_PAD_RET_MAUDIO_OPTION, + S5P_PAD_RET_GPIO_OPTION, + S5P_PAD_RET_UART_OPTION, + S5P_PAD_RET_MMCA_OPTION, + S5P_PAD_RET_MMCB_OPTION, + S5P_PAD_RET_EBIA_OPTION, + S5P_PAD_RET_EBIB_OPTION, + REG_TABLE_END, +}; + static int exynos_irq_set_wake(struct irq_data *data, unsigned int state) { const struct exynos_wkup_irq *wkup_irq; - - if (soc_is_exynos5250()) - wkup_irq = exynos5250_wkup_irq; - else - wkup_irq = exynos4_wkup_irq; + wkup_irq = pm_data->wkup_irq; while (wkup_irq->mask) { if (wkup_irq->hwirq == data->hwirq) { @@ -253,13 +275,13 @@ static void exynos_cpu_restore_register(void) static int exynos_cpu_suspend(unsigned long arg) { -#ifdef CONFIG_CACHE_L2X0 - outer_flush_all(); -#endif - - if (soc_is_exynos5250()) - flush_cache_all(); + if (pm_data->cpu_suspend) + return pm_data->cpu_suspend(arg); + return -1; +} +static int exynos_cpu_do_idle(void) +{ /* issue the standby signal into the pm unit. */ cpu_do_idle(); @@ -269,32 +291,73 @@ static int exynos_cpu_suspend(unsigned long arg) static void exynos_pm_prepare(void) { - unsigned int tmp; + if (pm_data->pm_prepare) + pm_data->pm_prepare(); +} + +static int exynos4_cpu_suspend(unsigned long arg) +{ +#ifdef CONFIG_CACHE_L2X0 + outer_flush_all(); +#endif + return exynos_cpu_do_idle(); +} + +static int exynos5250_cpu_suspend(unsigned long arg) +{ +#ifdef CONFIG_CACHE_L2X0 + outer_flush_all(); +#endif + flush_cache_all(); + return exynos_cpu_do_idle(); +} +static void exynos_pm_set_wakeup_mask(void) +{ /* Set wake-up mask registers */ pmu_raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK); pmu_raw_writel(exynos_irqwake_intmask & ~(1 << 31), S5P_WAKEUP_MASK); +} - s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save)); - - if (soc_is_exynos5250()) { - s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save)); - /* Disable USE_RETENTION of JPEG_MEM_OPTION */ - tmp = pmu_raw_readl(EXYNOS5_JPEG_MEM_OPTION); - tmp &= ~EXYNOS5_OPTION_USE_RETENTION; - pmu_raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION); - } - +static void exynos_pm_enter_sleep_mode(void) +{ /* Set value of power down register for sleep mode */ - exynos_sys_powerdown_conf(SYS_SLEEP); pmu_raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1); /* ensure at least INFORM0 has the resume address */ - pmu_raw_writel(virt_to_phys(exynos_cpu_resume), S5P_INFORM0); } +static void exynos5250_pm_prepare(void) +{ + unsigned int tmp; + + /* Set wake-up mask registers */ + exynos_pm_set_wakeup_mask(); + + s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save)); + + s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save)); + + /* Disable USE_RETENTION of JPEG_MEM_OPTION */ + tmp = pmu_raw_readl(EXYNOS5_JPEG_MEM_OPTION); + tmp &= ~EXYNOS5_OPTION_USE_RETENTION; + pmu_raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION); + + exynos_pm_enter_sleep_mode(); +} + +static void exynos4_pm_prepare(void) +{ + /* Set wake-up mask registers */ + exynos_pm_set_wakeup_mask(); + + s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save)); + + exynos_pm_enter_sleep_mode(); +} + static void exynos_pm_central_suspend(void) { unsigned long tmp; @@ -307,6 +370,13 @@ static void exynos_pm_central_suspend(void) static int exynos_pm_suspend(void) { + if (pm_data->pm_suspend) + return pm_data->pm_suspend(); + return -1; +} + +static int exynos4_pm_suspend(void) +{ unsigned long tmp; exynos_pm_central_suspend(); @@ -316,9 +386,20 @@ static int exynos_pm_suspend(void) tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0); pmu_raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION); - if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9) - exynos_cpu_save_register(); + exynos_cpu_save_register(); + return 0; +} + +static int exynos5250_pm_suspend(void) +{ + unsigned long tmp; + + exynos_pm_central_suspend(); + + /* Setting SEQ_OPTION register */ + tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0); + pmu_raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION); return 0; } @@ -345,39 +426,57 @@ static int exynos_pm_central_resume(void) return 0; } +static void exynos_pm_set_release_retention(void) +{ + unsigned int i; + + for (i = 0; (pm_data->release_ret_regs[i] != REG_TABLE_END); i++) + pmu_raw_writel(EXYNOS_WAKEUP_FROM_LOWPWR, + pm_data->release_ret_regs[i]); +} + static void exynos_pm_resume(void) { + if (pm_data->pm_resume) + pm_data->pm_resume(); +} + +static void exynos4_pm_resume(void) +{ if (exynos_pm_central_resume()) goto early_wakeup; - if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9) - exynos_cpu_restore_register(); + exynos_cpu_restore_register(); /* For release retention */ - - pmu_raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION); - pmu_raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION); - pmu_raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION); - pmu_raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION); - pmu_raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION); - pmu_raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION); - pmu_raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION); - - if (soc_is_exynos5250()) - s3c_pm_do_restore(exynos5_sys_save, - ARRAY_SIZE(exynos5_sys_save)); + exynos_pm_set_release_retention(); s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save)); - if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9) - scu_enable(S5P_VA_SCU); + scu_enable(S5P_VA_SCU); early_wakeup: /* Clear SLEEP mode set in INFORM1 */ pmu_raw_writel(0x0, S5P_INFORM1); +} + +static void exynos5250_pm_resume(void) +{ + if (exynos_pm_central_resume()) + goto early_wakeup; - return; + /* For release retention */ + exynos_pm_set_release_retention(); + + s3c_pm_do_restore(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save)); + + s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save)); + +early_wakeup: + + /* Clear SLEEP mode set in INFORM1 */ + pmu_raw_writel(0x0, S5P_INFORM1); } static struct syscore_ops exynos_pm_syscore_ops = { @@ -480,18 +579,63 @@ static struct notifier_block exynos_cpu_pm_notifier_block = { .notifier_call = exynos_cpu_pm_notifier, }; +static struct exynos_pm_data exynos4_pm_data = { + .wkup_irq = exynos4_wkup_irq, + .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)), + .release_ret_regs = exynos_release_ret_regs, + .pm_suspend = exynos4_pm_suspend, + .pm_resume = exynos4_pm_resume, + .pm_prepare = exynos4_pm_prepare, + .cpu_suspend = exynos4_cpu_suspend, +}; + +static struct exynos_pm_data exynos5250_pm_data = { + .wkup_irq = exynos5250_wkup_irq, + .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)), + .release_ret_regs = exynos_release_ret_regs, + .pm_suspend = exynos5250_pm_suspend, + .pm_resume = exynos5250_pm_resume, + .pm_prepare = exynos5250_pm_prepare, + .cpu_suspend = exynos5250_cpu_suspend, +}; + +static struct of_device_id exynos_pmu_of_device_ids[] = { + { + .compatible = "samsung,exynos4210-pmu", + .data = (void *)&exynos4_pm_data, + }, { + .compatible = "samsung,exynos4212-pmu", + .data = (void *)&exynos4_pm_data, + }, { + .compatible = "samsung,exynos4412-pmu", + .data = (void *)&exynos4_pm_data, + }, { + .compatible = "samsung,exynos5250-pmu", + .data = (void *)&exynos5250_pm_data, + }, + { /*sentinel*/ }, +}; + void __init exynos_pm_init(void) { u32 tmp; + const struct of_device_id *match; cpu_pm_register_notifier(&exynos_cpu_pm_notifier_block); + of_find_matching_node_and_match(NULL, exynos_pmu_of_device_ids, &match); + + if (!match) + panic("Failed to find PMU node\n"); + + pm_data = (struct exynos_pm_data *) match->data; + /* Platform-specific GIC callback */ gic_arch_extn.irq_set_wake = exynos_irq_set_wake; /* All wakeup disable */ tmp = pmu_raw_readl(S5P_WAKEUP_MASK); - tmp |= ((0xFF << 8) | (0x1F << 1)); + tmp |= pm_data->wake_disable_mask; pmu_raw_writel(tmp, S5P_WAKEUP_MASK); register_syscore_ops(&exynos_pm_syscore_ops); diff --git a/arch/arm/mach-exynos/regs-pmu.h b/arch/arm/mach-exynos/regs-pmu.h index 9b46a52..3a6a559 100644 --- a/arch/arm/mach-exynos/regs-pmu.h +++ b/arch/arm/mach-exynos/regs-pmu.h @@ -21,6 +21,7 @@ #define S5P_USE_STANDBY_WFI0 (1 << 16) #define S5P_USE_STANDBY_WFE0 (1 << 24) +#define EXYNOS_WAKEUP_FROM_LOWPWR (1 << 28) #define EXYNOS_SWRESET 0x0400 #define EXYNOS5440_SWRESET 0x00C4