From patchwork Fri Apr 25 12:32:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 4062131 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BE0BF9F271 for ; Fri, 25 Apr 2014 13:02:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F75E203AB for ; Fri, 25 Apr 2014 13:02:52 +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 7323820397 for ; Fri, 25 Apr 2014 13:02:51 +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 1Wdfix-0007Hl-5t; Fri, 25 Apr 2014 12:59:27 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wdf2Q-0005Dk-QQ for linux-arm-kernel@lists.infradead.org; Fri, 25 Apr 2014 12:15:31 +0000 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N4L005VL616EX60@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 25 Apr 2014 21:15:06 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.51]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 6E.DA.18501.AC15A535; Fri, 25 Apr 2014 21:15:06 +0900 (KST) X-AuditID: cbfee68d-b7f4e6d000004845-f7-535a51ca3f6f Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 65.D7.25708.AC15A535; Fri, 25 Apr 2014 21:15:06 +0900 (KST) Received: from localhost.localdomain ([12.36.165.191]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N4L00MQN60WE500@mmp1.samsung.com>; Fri, 25 Apr 2014 21:15:05 +0900 (KST) From: Pankaj Dubey To: linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 10/10] ARM: EXYNOS: Add device tree based initialization support for PMU. Date: Fri, 25 Apr 2014 21:32:46 +0900 Message-id: <1398429166-5539-11-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1398429166-5539-1-git-send-email-pankaj.dubey@samsung.com> References: <1396425058-4012-1-git-send-email-pankaj.dubey@samsung.com> <1398429166-5539-1-git-send-email-pankaj.dubey@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeLIzCtJLcpLzFFi42I5/e+Zse6pwKhgg53v+Cw2zljParFs0l02 i94FV9ksNj2+xmpxedccNosZ5/cxWdy+zGuxaOsXdovDb9pZLdbPeM1icfPZdiaLHS2rWRx4 PFqae9g8Ni+p9+jbsorR4/MmuQCWKC6blNSczLLUIn27BK6My9dmMxassKu4ekOigXGxSRcj J4eEgInEvadzGCFsMYkL99azdTFycQgJLGOUaL4zkwWmqLF9GhNEYhGjxJX9N1ghnDYmiSO9 K8Cq2AR0JZ68n8sMYosIZEtcabwPZjMLvGeU+HxYHcQWFoiT2LvkJBOIzSKgKrH053kwm1fA Q6Jh+Tmg1RxA2xQk5kyyAQlzAoVPLP/IDrGrlVHi/O/bLCCOhMA2dommPxNZIQYJSHybfIgF ollWYtM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TZ3v/6m3b47XUlr15qT0t2xuzKc Zi5emfPP6OLPtAWHe7T/M6dkagjdEWSJUbpyILF/jd3BaXfennz0+6Zo/OazTGFnOzTefZ1g 6jeX573NJObNwhaHuhjT95w88/pSyrHJV9WvZ2YemWCwyNXElmnZPhX1yXo2ea936ixe/zvk sRJLcUaioRZzUXEiANFvBKv4AgAA 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-20140425_051531_041146_8C72EEEE X-CRM114-Status: GOOD ( 17.64 ) X-Spam-Score: -5.7 (-----) Cc: kgene.kim@samsung.com, linux@arm.linux.org.uk, b.zolnierkie@samsung.com, Pankaj Dubey , t.figa@samsung.com, yg1004.jang@samsung.com, s.nawrocki@samsung.com, vikas.sajjan@samsung.com, chow.kim@samsung.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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.5 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 This patch adds device tree based initialization for PMU and modifies PMU initialization implementation in following way: 1: Let's initialize PMU based on device tree compatibility string. 2: Obtain PMU regmap handle using "syscon_early_regmap_lookup_by_phandle" so that we can reduce dependency over machine header files. 3: Separate each SoC's PMU initialization function and bind this initialization function with PMU compatibility string. 4 : It also removes uses of soc_is_exynosXXXX() thus making PMU implementation independent of "plat/cpu.h". Signed-off-by: Pankaj Dubey Signed-off-by: Young-Gun Jang --- arch/arm/mach-exynos/pmu.c | 182 +++++++++++++++++++++++++++++++++----------- 1 file changed, 138 insertions(+), 44 deletions(-) diff --git a/arch/arm/mach-exynos/pmu.c b/arch/arm/mach-exynos/pmu.c index 67116a5..abcf753 100644 --- a/arch/arm/mach-exynos/pmu.c +++ b/arch/arm/mach-exynos/pmu.c @@ -9,17 +9,31 @@ * published by the Free Software Foundation. */ -#include #include #include - -#include +#include +#include +#include +#include #include "common.h" #include "regs-pmu.h" +enum exynos_pmu_id { + PMU_EXYNOS4210, + PMU_EXYNOS4X12, + PMU_EXYNOS4412, + PMU_EXYNOS5250, +}; + +struct exynos_pmu_data { + enum exynos_pmu_id pmu_id; + struct regmap *pmu_regmap; +}; + +struct exynos_pmu_data *pmu_data; static const struct exynos_pmu_conf *exynos_pmu_config; -static struct regmap *pmu_regmap; +typedef void (*exynos_pmu_init_t)(void); static const struct exynos_pmu_conf exynos4210_pmu_config[] = { /* { .reg = address, .val = { AFTR, LPA, SLEEP } */ @@ -348,28 +362,31 @@ static void exynos5_init_pmu(void) * Enable both SC_FEEDBACK and SC_COUNTER */ for (i = 0 ; i < ARRAY_SIZE(exynos5_list_both_cnt_feed) ; i++) { - regmap_read(pmu_regmap, exynos5_list_both_cnt_feed[i], &tmp); + regmap_read(pmu_data->pmu_regmap, + exynos5_list_both_cnt_feed[i], &tmp); tmp |= (EXYNOS5_USE_SC_FEEDBACK | EXYNOS5_USE_SC_COUNTER); - regmap_write(pmu_regmap, exynos5_list_both_cnt_feed[i], tmp); + regmap_write(pmu_data->pmu_regmap, + exynos5_list_both_cnt_feed[i], tmp); } /* * SKIP_DEACTIVATE_ACEACP_IN_PWDN_BITFIELD Enable */ - regmap_read(pmu_regmap, EXYNOS5_ARM_COMMON_OPTION, &tmp); + regmap_read(pmu_data->pmu_regmap, EXYNOS5_ARM_COMMON_OPTION, &tmp); tmp |= EXYNOS5_SKIP_DEACTIVATE_ACEACP_IN_PWDN; - regmap_write(pmu_regmap, EXYNOS5_ARM_COMMON_OPTION, tmp); + regmap_write(pmu_data->pmu_regmap, EXYNOS5_ARM_COMMON_OPTION, tmp); /* * Disable WFI/WFE on XXX_OPTION */ for (i = 0 ; i < ARRAY_SIZE(exynos5_list_diable_wfi_wfe) ; i++) { - tmp = regmap_read(pmu_regmap, exynos5_list_diable_wfi_wfe[i], - &tmp); + tmp = regmap_read(pmu_data->pmu_regmap, + exynos5_list_diable_wfi_wfe[i], &tmp); tmp &= ~(EXYNOS5_OPTION_USE_STANDBYWFE | EXYNOS5_OPTION_USE_STANDBYWFI); - regmap_write(pmu_regmap, exynos5_list_diable_wfi_wfe[i], tmp); + regmap_write(pmu_data->pmu_regmap, + exynos5_list_diable_wfi_wfe[i], tmp); } } @@ -377,52 +394,129 @@ void exynos_sys_powerdown_conf(enum sys_powerdown mode) { unsigned int i; - if (soc_is_exynos5250()) + if (pmu_data->pmu_id == PMU_EXYNOS5250) exynos5_init_pmu(); for (i = 0; (exynos_pmu_config[i].offset != PMU_TABLE_END) ; i++) - regmap_write(pmu_regmap, exynos_pmu_config[i].offset, + regmap_write(pmu_data->pmu_regmap, exynos_pmu_config[i].offset, exynos_pmu_config[i].val[mode]); - if (soc_is_exynos4412()) { + if (pmu_data->pmu_id == PMU_EXYNOS4412) { for (i = 0; exynos4412_pmu_config[i].offset != PMU_TABLE_END; i++) - regmap_write(pmu_regmap, exynos4412_pmu_config[i].offset, + regmap_write(pmu_data->pmu_regmap, + exynos4412_pmu_config[i].offset, exynos4412_pmu_config[i].val[mode]); } } -static int __init exynos_pmu_init(void) +static void exynos4210_pmu_init(void) { - unsigned int value; - exynos_pmu_config = exynos4210_pmu_config; - pmu_regmap = get_exynos_pmuregmap(); - - if (soc_is_exynos4210()) { - exynos_pmu_config = exynos4210_pmu_config; - pr_info("EXYNOS4210 PMU Initialize\n"); - } else if (soc_is_exynos4212() || soc_is_exynos4412()) { - exynos_pmu_config = exynos4x12_pmu_config; - pr_info("EXYNOS4x12 PMU Initialize\n"); - } else if (soc_is_exynos5250()) { - /* - * When SYS_WDTRESET is set, watchdog timer reset request - * is ignored by power management unit. - */ - regmap_read(pmu_regmap, EXYNOS5_AUTO_WDTRESET_DISABLE, &value); - value &= ~EXYNOS5_SYS_WDTRESET; - regmap_write(pmu_regmap, EXYNOS5_AUTO_WDTRESET_DISABLE, value); - - regmap_read(pmu_regmap, EXYNOS5_MASK_WDTRESET_REQUEST, &value); - value &= ~EXYNOS5_SYS_WDTRESET; - regmap_write(pmu_regmap, EXYNOS5_MASK_WDTRESET_REQUEST, value); - - exynos_pmu_config = exynos5250_pmu_config; - pr_info("EXYNOS5250 PMU Initialize\n"); - } else { - pr_info("EXYNOS: PMU not supported\n"); + pmu_data->pmu_id = PMU_EXYNOS4210; + + pr_info("EXYNOS4210 PMU Initialize\n"); +} + +static void exynos4x12_pmu_init(void) +{ + exynos_pmu_config = exynos4x12_pmu_config; + pmu_data->pmu_id = PMU_EXYNOS4X12; + + pr_info("EXYNOS4x12 PMU Initialize\n"); +} + +static void exynos4412_pmu_init(void) +{ + exynos_pmu_config = exynos4x12_pmu_config; + pmu_data->pmu_id = PMU_EXYNOS4412; + + pr_info("EXYNOS4412 PMU Initialize\n"); +} + +static void exynos5250_pmu_init(void) +{ + unsigned int tmp; + + /* + * When SYS_WDTRESET is set, watchdog timer reset request + * is ignored by power management unit. + */ + regmap_read(pmu_data->pmu_regmap, EXYNOS5_AUTO_WDTRESET_DISABLE, &tmp); + tmp &= ~EXYNOS5_SYS_WDTRESET; + regmap_write(pmu_data->pmu_regmap, EXYNOS5_AUTO_WDTRESET_DISABLE, tmp); + + regmap_read(pmu_data->pmu_regmap, EXYNOS5_MASK_WDTRESET_REQUEST, &tmp); + tmp &= ~EXYNOS5_SYS_WDTRESET; + regmap_write(pmu_data->pmu_regmap, EXYNOS5_MASK_WDTRESET_REQUEST, tmp); + + exynos_pmu_config = exynos5250_pmu_config; + pmu_data->pmu_id = PMU_EXYNOS5250; + + pr_info("EXYNOS5250 PMU Initialize\n"); +} + +/* + * PMU platform driver and devicetree bindings. + */ +static struct of_device_id exynos_pmu_of_device_ids[] = { + { + .compatible = "samsung,exynos4210-pmu", + .data = (void *)exynos4210_pmu_init + }, + { + .compatible = "samsung,exynos4212-pmu", + .data = (void *)exynos4x12_pmu_init + }, + { + .compatible = "samsung,exynos4412-pmu", + .data = (void *)exynos4412_pmu_init + }, + { + .compatible = "samsung,exynos5250-pmu", + .data = (void *)exynos5250_pmu_init + }, + {}, +}; + +static int exynos_pmu_probe(struct device_node *np) +{ + const struct of_device_id *match; + exynos_pmu_init_t exynos_pmu_init; + + pmu_data = kzalloc(sizeof(struct exynos_pmu_data), GFP_KERNEL); + if (!pmu_data) { + pr_err("exynos_pmu driver probe failed\n"); + return -ENOMEM; } + match = of_match_node(exynos_pmu_of_device_ids, np); + if (!match) { + pr_err("fail to get matching of_match struct\n"); + return -EINVAL; + } + + exynos_pmu_init = match->data; + + pmu_data->pmu_regmap = syscon_early_regmap_lookup_by_phandle(np, + "samsung,syscon-phandle"); + if (IS_ERR(pmu_data->pmu_regmap)) { + pr_err("failed to find exynos_pmu_regmap\n"); + return PTR_ERR(pmu_data->pmu_regmap); + } + + exynos_pmu_init(); + return 0; +}; + +static int __init exynos_pmu_of_init(void) +{ + int ret = 0; + struct device_node *np; + + for_each_matching_node_and_match(np, exynos_pmu_of_device_ids, NULL) + ret = exynos_pmu_probe(np); + + return ret ? ret:0; } -arch_initcall(exynos_pmu_init); +arch_initcall(exynos_pmu_of_init);