From patchwork Sat May 10 06:56:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 4146981 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 D8D539F387 for ; Sat, 10 May 2014 06:42:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C47562010F for ; Sat, 10 May 2014 06:42:44 +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 9241620263 for ; Sat, 10 May 2014 06:42:43 +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 1Wj0xO-0001xF-VL; Sat, 10 May 2014 06:40:26 +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 1Wj0w9-0008QE-16 for linux-arm-kernel@lists.infradead.org; Sat, 10 May 2014 06:39:10 +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 <0N5C00DLCIG4VG80@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Sat, 10 May 2014 15:38:28 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.50]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 6B.B1.18501.469CD635; Sat, 10 May 2014 15:38:28 +0900 (KST) X-AuditID: cbfee68d-b7f4e6d000004845-06-536dc964f041 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id E0.0F.25708.469CD635; Sat, 10 May 2014 15:38:28 +0900 (KST) Received: from localhost.localdomain ([12.36.165.191]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N5C00GCSIFT5B30@mmp2.samsung.com>; Sat, 10 May 2014 15:38:28 +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 v4 10/11] ARM: EXYNOS: Add platform driver support for Exynos PMU. Date: Sat, 10 May 2014 15:56:37 +0900 Message-id: <1399704998-13321-11-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1399704998-13321-1-git-send-email-pankaj.dubey@samsung.com> References: <1399704998-13321-1-git-send-email-pankaj.dubey@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRmVeSWpSXmKPExsVy+t8zI92Uk7nBBjfWGVgsm3SXzaJ3wVU2 i02Pr7FaXN41h81ixvl9TBa3L/NaLNr6hd1i/YzXLBY3n21nstjRsprFgcujpbmHzWPzknqP vi2rGD0+b5ILYInisklJzcksSy3St0vgyth56ytbwcTIih1z77I3MC726mLk5JAQMJHYdr6D GcIWk7hwbz1bFyMXh5DAMkaJ85PPssAUnfl/jAkiMZ1Rom9zBzuE08Yk8f3wX7B2NgFdiSfv 54LZIgLZElca7zODFDEL7GaUaGycxwaSEBYIkVjX8IoVxGYRUJVYtLQfLM4r4Cmxc/90xi5G DqB1ChJzJtmAhDmBwl+/LmYCsYUEPCQedC8FmykhsIpdYt3y+4wQcwQkvk0+xALRKyux6QDU O5ISB1fcYJnAKLyAkWEVo2hqQXJBcVJ6kaFecWJucWleul5yfu4mRkjg9+5gvH3A+hBjMtC4 ic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Tlfd/iVa l3Q8uPOYmaVfrlZ5U1bwx2Q5i8wT59ek/9BN2mu1jUvYxHXbs1inz5UW/tEOEkosxRmJhlrM RcWJADHrZO/vAgAA 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-20140509_233909_259192_B8D49631 X-CRM114-Status: GOOD ( 20.62 ) X-Spam-Score: -5.7 (-----) Cc: kgene.kim@samsung.com, linux@arm.linux.org.uk, Pankaj Dubey , t.figa@samsung.com, yg1004.jang@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 modifies Exynos Power Management Unit (PMU) initialization implementation in following way: - Added platform_device support by registering static platform device. - Added platform struct exynos_pmu_data to hold platform specific data. - For each SoC's PMU support now we can add platform data and statically bind PMU configuration and SoC specific initialization function. - Probe function will scan DT and based on matching PMU compatibility string initialize pmu_context which will be platform_data for driver. - Obtain PMU regmap handle using "syscon_regmap_lookup_by_phandle" so that we can reduce dependency over machine header files. - Separate each SoC's PMU initialization function and make it as part of platform data. - It also removes uses of soc_is_exynosXYZ() 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 | 266 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 210 insertions(+), 56 deletions(-) diff --git a/arch/arm/mach-exynos/pmu.c b/arch/arm/mach-exynos/pmu.c index 67116a5..6a7fa8e 100644 --- a/arch/arm/mach-exynos/pmu.c +++ b/arch/arm/mach-exynos/pmu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd. + * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. * http://www.samsung.com/ * * EXYNOS - CPU PMU(Power Management Unit) support @@ -9,20 +9,33 @@ * published by the Free Software Foundation. */ -#include -#include +#include #include - -#include +#include +#include +#include +#include #include "common.h" #include "regs-pmu.h" -static const struct exynos_pmu_conf *exynos_pmu_config; -static struct regmap *pmu_regmap; +struct exynos_pmu_data { + const struct exynos_pmu_conf *pmu_config; + const struct exynos_pmu_conf *pmu_config_extra; + void (*pmu_init)(void); + void (*powerdown_conf)(enum sys_powerdown); +}; + +struct exynos_pmu_context { + struct device *dev; + struct exynos_pmu_data *pmu_data; + struct regmap *pmu_regmap; +}; + +static struct exynos_pmu_context *pmu_context; static const struct exynos_pmu_conf exynos4210_pmu_config[] = { - /* { .reg = address, .val = { AFTR, LPA, SLEEP } */ + /* { .offset = address, .val = { AFTR, LPA, SLEEP } */ { S5P_ARM_CORE0_LOWPWR, { 0x0, 0x0, 0x2 } }, { S5P_DIS_IRQ_CORE0, { 0x0, 0x0, 0x0 } }, { S5P_DIS_IRQ_CENTRAL0, { 0x0, 0x0, 0x0 } }, @@ -216,7 +229,7 @@ static const struct exynos_pmu_conf exynos4412_pmu_config[] = { }; static const struct exynos_pmu_conf exynos5250_pmu_config[] = { - /* { .reg = address, .val = { AFTR, LPA, SLEEP } */ + /* { .offset = address, .val = { AFTR, LPA, SLEEP } */ { EXYNOS5_ARM_CORE0_SYS_PWR_REG, { 0x0, 0x0, 0x2} }, { EXYNOS5_DIS_IRQ_ARM_CORE0_LOCAL_SYS_PWR_REG, { 0x0, 0x0, 0x0} }, { EXYNOS5_DIS_IRQ_ARM_CORE0_CENTRAL_SYS_PWR_REG, { 0x0, 0x0, 0x0} }, @@ -339,7 +352,7 @@ static unsigned int const exynos5_list_diable_wfi_wfe[] = { EXYNOS5_ISP_ARM_OPTION, }; -static void exynos5_init_pmu(void) +void exynos5_powerdown_conf(enum sys_powerdown mode) { unsigned int i; unsigned int tmp; @@ -348,81 +361,222 @@ 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_context->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_context->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_context->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_context->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_context->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_context->pmu_regmap, + exynos5_list_diable_wfi_wfe[i], tmp); } } void exynos_sys_powerdown_conf(enum sys_powerdown mode) { unsigned int i; + struct exynos_pmu_data *pmu_data = pmu_context->pmu_data; + + if (pmu_data->powerdown_conf) + pmu_data->powerdown_conf(mode); + + if (pmu_data->pmu_config) { + for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END) ; i++) + regmap_write(pmu_context->pmu_regmap, + pmu_data->pmu_config[i].offset, + pmu_data->pmu_config[i].val[mode]); + } + + if (pmu_data->pmu_config_extra) { + for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++) + regmap_write(pmu_context->pmu_regmap, + pmu_data->pmu_config_extra[i].offset, + pmu_data->pmu_config_extra[i].val[mode]); + } +} + +static void exynos5250_pmu_init(void) +{ + unsigned int tmp; + struct regmap *pmu_regmap = pmu_context->pmu_regmap; + /* + * When SYS_WDTRESET is set, watchdog timer reset request + * is ignored by power management unit. + */ + regmap_read(pmu_regmap, EXYNOS5_AUTO_WDTRESET_DISABLE, &tmp); + tmp &= ~EXYNOS5_SYS_WDTRESET; + regmap_write(pmu_regmap, EXYNOS5_AUTO_WDTRESET_DISABLE, tmp); + + regmap_read(pmu_regmap, EXYNOS5_MASK_WDTRESET_REQUEST, &tmp); + tmp &= ~EXYNOS5_SYS_WDTRESET; + regmap_write(pmu_regmap, EXYNOS5_MASK_WDTRESET_REQUEST, tmp); +} + +static struct exynos_pmu_data exynos4210_pmu_data = { + .pmu_config = exynos4210_pmu_config, +}; + +static struct exynos_pmu_data exynos4x12_pmu_data = { + .pmu_config = exynos4x12_pmu_config, +}; + +static struct exynos_pmu_data exynos4412_pmu_data = { + .pmu_config = exynos4x12_pmu_config, + .pmu_config_extra = exynos4412_pmu_config, +}; + +static struct exynos_pmu_data exynos5250_pmu_data = { + .pmu_config = exynos5250_pmu_config, + .pmu_init = exynos5250_pmu_init, + .powerdown_conf = exynos5_powerdown_conf, +}; + +/* + * PMU platform driver and devicetree bindings. + */ +static struct of_device_id exynos_pmu_of_device_ids[] = { + { + .compatible = "samsung,exynos4210-pmu", + .data = (void *)&exynos4210_pmu_data, + }, + { + .compatible = "samsung,exynos4212-pmu", + .data = (void *)&exynos4x12_pmu_data, + }, + { + .compatible = "samsung,exynos4412-pmu", + .data = (void *)&exynos4412_pmu_data, + }, + { + .compatible = "samsung,exynos5250-pmu", + .data = (void *)&exynos5250_pmu_data, + }, + {}, +}; + +static int exynos_pmu_probe(struct platform_device *pdev) +{ + struct device_node *np; + const struct of_device_id *match; + struct device *dev = &pdev->dev; - if (soc_is_exynos5250()) - exynos5_init_pmu(); + pmu_context = devm_kzalloc(&pdev->dev, + sizeof(struct exynos_pmu_context), + GFP_KERNEL); + if (pmu_context == NULL) { + dev_err(dev, "Cannot allocate memory.\n"); + return -ENOMEM; + } + + np = of_find_matching_node_and_match(NULL, + exynos_pmu_of_device_ids, &match); + if (!np) { + pr_warn("%s, failed to find PMU node\n", __func__); + return -ENODEV; + } - for (i = 0; (exynos_pmu_config[i].offset != PMU_TABLE_END) ; i++) - regmap_write(pmu_regmap, exynos_pmu_config[i].offset, - exynos_pmu_config[i].val[mode]); + pmu_context->pmu_data = (struct exynos_pmu_data *) match->data; + pmu_context->pmu_regmap = syscon_regmap_lookup_by_phandle(np, NULL); - if (soc_is_exynos4412()) { - for (i = 0; exynos4412_pmu_config[i].offset != PMU_TABLE_END; i++) - regmap_write(pmu_regmap, exynos4412_pmu_config[i].offset, - exynos4412_pmu_config[i].val[mode]); + if (IS_ERR(pmu_context->pmu_regmap)) { + pr_err("failed to find exynos_pmu_regmap\n"); + return PTR_ERR(pmu_context->pmu_regmap); } + + if (pmu_context->pmu_data->pmu_init) + pmu_context->pmu_data->pmu_init(); + + pmu_context->dev = dev; + + platform_set_drvdata(pdev, pmu_context); + + pr_info("Exynos PMU Driver probe done!!!\n"); + return 0; +} + +static int exynos_pmu_suspend(struct device *dev) +{ + /* ToDo: */ + return 0; +} + +static int exynos_pmu_resume(struct device *dev) +{ + /* ToDo: */ + return 0; } -static int __init exynos_pmu_init(void) +static const struct dev_pm_ops exynos_pmu_pm = { + .suspend = exynos_pmu_suspend, + .resume = exynos_pmu_resume, +}; + +static int exynos_pmu_remove(struct platform_device *pdev) +{ + /* nothing to do here */ + return 0; +} + +static struct platform_device *exynos_pmu_pdev; + +static struct platform_driver exynos_pmu_driver = { + .driver = { + .name = "exynos-pmu", + .owner = THIS_MODULE, + .pm = &exynos_pmu_pm, + }, + .probe = exynos_pmu_probe, + .remove = exynos_pmu_remove, +}; + +static int __init exynos_pmu_of_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"); + int ret; + + ret = platform_driver_register(&exynos_pmu_driver); + if (ret < 0) + goto out; + + exynos_pmu_pdev = platform_device_register_simple("exynos-pmu", -1, + NULL, 0); + + if (IS_ERR(exynos_pmu_pdev)) { + ret = PTR_ERR(exynos_pmu_pdev); + goto out1; } return 0; +out1: + platform_driver_unregister(&exynos_pmu_driver); +out: + return ret; } -arch_initcall(exynos_pmu_init); +arch_initcall(exynos_pmu_of_init); + +static void __exit exynos_pmu_exit(void) +{ + platform_device_unregister(exynos_pmu_pdev); + platform_driver_unregister(&exynos_pmu_driver); +} +module_exit(exynos_pmu_exit); + +MODULE_AUTHOR("Pankaj Dubey