From patchwork Tue Jan 9 07:59:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 10151107 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 84A97601A1 for ; Tue, 9 Jan 2018 08:00:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79E2C287B4 for ; Tue, 9 Jan 2018 08:00:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EC4A287E7; Tue, 9 Jan 2018 08:00:54 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 C858A287C5 for ; Tue, 9 Jan 2018 08:00:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755976AbeAIH7t (ORCPT ); Tue, 9 Jan 2018 02:59:49 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:53682 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754302AbeAIH7J (ORCPT ); Tue, 9 Jan 2018 02:59:09 -0500 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20180109075906epoutp011c4bb3302d049b1fa5a98d72bffcf57e~IFVkE5kdx0125101251epoutp01_; Tue, 9 Jan 2018 07:59:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20180109075906epoutp011c4bb3302d049b1fa5a98d72bffcf57e~IFVkE5kdx0125101251epoutp01_ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1515484746; bh=IXczlP+9B+9WcWHuoc6c9aqsXptwNMNL0GDXWZCmRgw=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=VoP/f75qj8CsZE9z2uW6d5/Wz0PwWCnco0pRGvAMeUO4MXlebI6UGsRGhY44gKCLZ CKAuddac21YnWIJdD0zrI85vWEVndQQuRirUrf/9cqOaRW39rCoiYoNlcuw/o6x7kJ VVtReaBg2+0XFlyEbdIj67kEIKxS8BuRaQTexk2E= Received: from epsmges1p3.samsung.com (unknown [182.195.40.65]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20180109075906epcas1p1727c94034694ffcd0761307f3d64955e~IFVjdv0DK2646526465epcas1p1f; Tue, 9 Jan 2018 07:59:06 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 09.E2.04161.946745A5; Tue, 9 Jan 2018 16:59:05 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20180109075905epcas1p40431a90ecc3530f2200ade028bf54594~IFVi_hXaf3183531835epcas1p4i; Tue, 9 Jan 2018 07:59:05 +0000 (GMT) X-AuditID: b6c32a37-42bff70000001041-fe-5a547649df27 Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 71.1C.04148.946745A5; Tue, 9 Jan 2018 16:59:05 +0900 (KST) Received: from localhost.localdomain ([10.113.77.231]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P2A00EW93IGT980@mmp2.samsung.com>; Tue, 09 Jan 2018 16:59:05 +0900 (KST) From: Chanwoo Choi To: krzk@kernel.org, m.szyprowski@samsung.com, s.nawrocki@samsung.com, kgene@kernel.org Cc: tomasz.figa@gmail.com, cw00.choi@samsung.com, chanwoo@kernel.org, jh80.chung@samsung.com, inki.dae@samsung.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jonghwa Lee Subject: [RFC PATCH 4/9] soc: samsung: Add generic power-management driver for Exynos Date: Tue, 09 Jan 2018 16:59:01 +0900 Message-id: <1515484746-10656-5-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1515484746-10656-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNKsWRmVeSWpSXmKPExsWy7bCmrq5nWUiUQetna4uJN66wWFz/8pzV Yv6Rc6wWk+5PYLG48auN1aLz7BNmi/7Hr5ktzp/fwG6x6fE1VovLu+awWcw4v4/JYu2Ru+wW h9+0s1qs2vWH0YHPY+esu+wem1Z1snlsXlLv0bdlFaPH501yAaxRqTYZqYkpqUUKqXnJ+SmZ eem2St7B8c7xpmYGhrqGlhbmSgp5ibmptkouPgG6bpk5QIcqKZQl5pQChQISi4uV9O1sivJL S1IVMvKLS2yVog0NjfQMDcz1jIyM9EyMY62MTIFKElIzzr68z1zw2Kli8dJtbA2MLRZdjJwc EgImEgv6ljJ1MXJxCAnsYJSY3HyTBSQhJPCdUeLmu3yYorMzmpkhijYwSjSv/cIIUfSDUaJv tiiIzSagJbH/xQ02EFtEIFLi595jjCANzAJLmSR+rHnHBJIQFgiXOL3/Glgzi4CqxKwv58Fs XgFXiTf/1jJDbJOT+LDnETuIzSngJrH73xo2kEESAjvYJH5fucYCUeQiseTzAkYIW1ji1fEt QA0cQLa0xKWjthD17YwS7XvnMUM4Uxglzl2/xwTRYCzxbGEXmM0swCfx7msPK0Qzr0RHmxBE iYfE1Ec3oA5ylDj+fjIbxPszGSX2Ld/POoF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fP9//vlVspKSMQfF7BsIjt6KveGRxFxy6mWVrGKlrLVMWnsooYlLV/sBLM KlVOTvqlFGykfmjuukNz7GYpsRRnJBpqMRcVJwIAs3xmZEECAAA= X-CMS-MailID: 20180109075905epcas1p40431a90ecc3530f2200ade028bf54594 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180109075905epcas1p40431a90ecc3530f2200ade028bf54594 X-RootMTR: 20180109075905epcas1p40431a90ecc3530f2200ade028bf54594 References: <1515484746-10656-1-git-send-email-cw00.choi@samsung.com> 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 enter suspend, Exynos SoC requires the some machine dependent procedures. This patch introduces the generic power-management driver to support those requirements and generic interface for power state management. Signed-off-by: Jonghwa Lee Signed-off-by: Chanwoo Choi --- arch/arm/mach-exynos/common.h | 1 - arch/arm/mach-exynos/exynos.c | 23 +---- drivers/soc/samsung/Makefile | 2 +- drivers/soc/samsung/exynos-pm.c | 176 ++++++++++++++++++++++++++++++++++ include/linux/soc/samsung/exynos-pm.h | 21 ++++ 5 files changed, 199 insertions(+), 24 deletions(-) create mode 100644 drivers/soc/samsung/exynos-pm.c create mode 100644 include/linux/soc/samsung/exynos-pm.h -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h index afbc143a3d5d..ad482c0fc131 100644 --- a/arch/arm/mach-exynos/common.h +++ b/arch/arm/mach-exynos/common.h @@ -119,7 +119,6 @@ enum { * Magic values for bootloader indicating chosen low power mode. * See also Documentation/arm/Samsung/Bootloader-interface.txt */ -#define EXYNOS_SLEEP_MAGIC 0x00000bad #define EXYNOS_AFTR_MAGIC 0xfcba0d10 void exynos_set_boot_flag(unsigned int cpu, unsigned int mode); diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c index fbd108ce8745..0d5265d175c4 100644 --- a/arch/arm/mach-exynos/exynos.c +++ b/arch/arm/mach-exynos/exynos.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -41,28 +42,6 @@ .id = -1, }; -void __iomem *sysram_base_addr __ro_after_init; -void __iomem *sysram_ns_base_addr __ro_after_init; - -void __init exynos_sysram_init(void) -{ - struct device_node *node; - - for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram") { - if (!of_device_is_available(node)) - continue; - sysram_base_addr = of_iomap(node, 0); - break; - } - - for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram-ns") { - if (!of_device_is_available(node)) - continue; - sysram_ns_base_addr = of_iomap(node, 0); - break; - } -} - static void __init exynos_init_late(void) { if (of_machine_is_compatible("samsung,exynos5440")) diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile index d2e637339a45..58ca5bdabf1f 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o +obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o exynos-pm.o obj-$(CONFIG_EXYNOS_PMU_ARM_DRIVERS) += exynos3250-pmu.o exynos4-pmu.o \ exynos5250-pmu.o exynos5420-pmu.o \ diff --git a/drivers/soc/samsung/exynos-pm.c b/drivers/soc/samsung/exynos-pm.c new file mode 100644 index 000000000000..45d84bbe5e61 --- /dev/null +++ b/drivers/soc/samsung/exynos-pm.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// based on arch/arm/mach-exynos/suspend.c +// Copyright (c) 2018 Samsung Electronics Co., Ltd. +// +// Exynos Power Management support driver + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +/* + * The struct exynos_pm_data contains the callbacks of + * both struct platform_suspend_ops and syscore_ops. + * This structure is listed according to the call order, + * because the callback call order for the two structures is mixed. + */ +struct exynos_pm_data { + int (*prepare)(void); /* for platform_suspend_ops */ + int (*suspend)(void); /* for syscore_ops */ + int (*enter)(suspend_state_t state); /* for platform_suspend_ops */ + void (*resume)(void); /* for syscore_ops */ + void (*finish)(void); /* for platform_suspend_ops */ +}; + +static struct platform_suspend_ops exynos_pm_suspend_ops; +static struct syscore_ops exynos_pm_syscore_ops; +static const struct exynos_pm_data *pm_data __ro_after_init; + +void __iomem *sysram_base_addr __ro_after_init; +void __iomem *sysram_ns_base_addr __ro_after_init; + +static int exynos_pm_prepare(void) +{ + int ret; + + /* + * REVISIT: It would be better if struct platform_suspend_ops + * .prepare handler get the suspend_state_t as a parameter to + * avoid hard-coding the suspend to mem state. It's safe to do + * it now only because the suspend_valid_only_mem function is + * used as the .valid callback used to check if a given state + * is supported by the platform anyways. + */ + ret = regulator_suspend_prepare(PM_SUSPEND_MEM); + if (ret) { + pr_err("Failed to prepare regulators for suspend (%d)\n", ret); + return ret; + } + + if (pm_data->prepare) { + ret = pm_data->prepare(); + if (ret) { + pr_err("Failed to prepare for suspend (%d)\n", ret); + return ret; + } + } + + return 0; +} + +static int exynos_pm_suspend(void) +{ + if (pm_data->suspend) + return pm_data->suspend(); + + return 0; +} + +static int exynos_pm_enter(suspend_state_t state) +{ + int ret; + + exynos_sys_powerdown_conf(SYS_SLEEP); + + ret = pm_data->enter(state); + if (ret) { + pr_err("Failed to enter sleep\n"); + return ret; + } + + return 0; +} + +static void exynos_pm_resume(void) +{ + exynos_sys_powerup_conf(SYS_SLEEP); + + if (pm_data->resume) + pm_data->resume(); +} + +static void exynos_pm_finish(void) +{ + int ret; + + ret = regulator_suspend_finish(); + if (ret) + pr_warn("Failed to resume regulators from suspend (%d)\n", ret); + + if (pm_data->finish) + pm_data->finish(); +} + +/* + * Split the data between ARM architectures because it is relatively big + * and useless on other arch. + */ +#ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS +#define exynos_pm_data_arm_ptr(data) (&data) +#else +#define exynos_pm_data_arm_ptr(data) NULL +#endif + +static const struct of_device_id exynos_pm_of_device_ids[] = { + { /*sentinel*/ }, +}; + +void __init exynos_sysram_init(void) +{ + struct device_node *np; + + for_each_compatible_node(np, NULL, "samsung,exynos4210-sysram") { + if (!of_device_is_available(np)) + continue; + sysram_base_addr = of_iomap(np, 0); + break; + } + + for_each_compatible_node(np, NULL, "samsung,exynos4210-sysram-ns") { + if (!of_device_is_available(np)) + continue; + sysram_ns_base_addr = of_iomap(np, 0); + break; + } +} + +static int __init exynos_pm_init(void) +{ + const struct of_device_id *match; + struct device_node *np; + + np = of_find_matching_node_and_match(NULL, + exynos_pm_of_device_ids, &match); + if (!np) { + pr_err("Failed to find PMU node for Exynos Power-Management\n"); + return -ENODEV; + } + pm_data = (const struct exynos_pm_data *) match->data; + + exynos_sysram_init(); + + exynos_pm_suspend_ops.valid = suspend_valid_only_mem; + exynos_pm_suspend_ops.prepare = exynos_pm_prepare; + exynos_pm_syscore_ops.suspend = exynos_pm_suspend; + exynos_pm_suspend_ops.enter = exynos_pm_enter; + exynos_pm_syscore_ops.resume = exynos_pm_resume; + exynos_pm_suspend_ops.finish = exynos_pm_finish; + + register_syscore_ops(&exynos_pm_syscore_ops); + suspend_set_ops(&exynos_pm_suspend_ops); + + return 0; +} +postcore_initcall(exynos_pm_init); diff --git a/include/linux/soc/samsung/exynos-pm.h b/include/linux/soc/samsung/exynos-pm.h new file mode 100644 index 000000000000..b1afe95ed10c --- /dev/null +++ b/include/linux/soc/samsung/exynos-pm.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2018 Samsung Electronics Co., Ltd. +// +// Header for Exynos Power-Management support driver + +#ifndef __LINUX_SOC_EXYNOS_PM_H +#define __LINUX_SOC_EXYNOS_PM_H + +/* + * Magic values for bootloader indicating chosen low power mode. + * See also Documentation/arm/Samsung/Bootloader-interface.txt + */ +#define EXYNOS_SLEEP_MAGIC 0x00000bad + +extern void __iomem *sysram_base_addr; +extern void __iomem *sysram_ns_base_addr; + +extern void exynos_sysram_init(void); + +#endif /* __LINUX_SOC_EXYNOS_PMU_H */