From patchwork Tue Sep 2 14:42:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 4826271 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 BE25F9F32F for ; Tue, 2 Sep 2014 14:50:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D8F00201B4 for ; Tue, 2 Sep 2014 14:50:35 +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 8A6F72018B for ; Tue, 2 Sep 2014 14:50:34 +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 1XOpN6-0000gV-6S; Tue, 02 Sep 2014 14:47:48 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XOpN1-0000ad-Ox for linux-arm-kernel@lists.infradead.org; Tue, 02 Sep 2014 14:47:45 +0000 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NBA00K593QU7700@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 02 Sep 2014 23:47:18 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.125]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id F3.93.04513.678D5045; Tue, 02 Sep 2014 23:47:18 +0900 (KST) X-AuditID: cbfee691-f79546d0000011a1-76-5405d876754b Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C1.54.04943.678D5045; Tue, 02 Sep 2014 23:47:18 +0900 (KST) Received: from chromebld-server.sisodomain.com ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NBA002EC3P2K060@mmp2.samsung.com>; Tue, 02 Sep 2014 23:47:17 +0900 (KST) From: Pankaj Dubey To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mfd: syscon: Decouple syscon interface from platform devices Date: Tue, 02 Sep 2014 20:12:15 +0530 Message-id: <1409668935-10667-1-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrELMWRmVeSWpSXmKPExsWyRsSkVrfsBmuIwYTfQhZ/Jx1jt1g26S6b xfddX9gtehdcZbO4//Uoo8Wmx9dYLS7vmsNmMeP8PiaL25d5LT4d/c9qsWgrUNn6Ga9ZLDqW MVqs2vWH0eLms+1MDvweLc09bB6/f01i9Ng56y67x51re9g8Ni+p9+jbsorR4/MmuQD2KC6b lNSczLLUIn27BK6M7bMlC47bVJzpu8DUwLjIqIuRk0NCwERiyfsWZghbTOLCvfVsXYxcHEIC Sxkl3p6+ygZT9HvOARaIxHRGiclXupghnAlMEtumL2EFqWIT0JV48n4u2CgRgWyJ/turwTqY BdYzSXza8A6sSFggQGLZu+mMIDaLgKrE8/kz2UFsXgEPiUV/lwA1cACtU5CYM8kGpFdC4Bi7 xKf250wQ9QIS3yYfgqqRldh0AOpsSYmDK26wTGAUXMDIsIpRNLUguaA4Kb3IVK84Mbe4NC9d Lzk/dxMjMCpO/3s2cQfj/QPWhxgFOBiVeHglfrCECLEmlhVX5h5iNAXaMJF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M/TTtoSaW/+ 2vvTndNbIorrcy3v8Z1QKpbJZA9WO2tf6X1Tln2SuaVZm3n1ba+/u7o+1c9bbHSrMD1WqjJx 59W3y88ulHB021dWqsRSnJFoqMVcVJwIAOwuU+fPAgAA 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-20140902_074743_950662_E7492245 X-CRM114-Status: GOOD ( 19.33 ) X-Spam-Score: -6.7 (------) Cc: kgene.kim@samsung.com, linux@arm.linux.org.uk, arnd@arndb.de, naushad@samsung.com, Pankaj Dubey , Tomasz Figa , joshi@samsung.com, tomasz.figa@gmail.com, thomas.ab@samsung.com, vikas.sajjan@samsung.com, chow.kim@samsung.com, lee.jones@linaro.org 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=-3.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 Currently a syscon entity can only be registered directly through a platform device that binds to a dedicated syscon driver. However in certain cases it is required to bind a device with it's dedicated driver rather than binding with syscon driver. For example, certain SoCs (e.g. Exynos) contain system controller blocks which perform various functions such as power domain control, CPU power management, low power mode control, but in addition contain certain IP integration glue, such as various signal masks, coprocessor power control, etc. In such case, there is a need to have a dedicated driver for such system controller but also share registers with other drivers. The latter is where the syscon interface is helpful. This patch decouples syscon object from syscon platform driver, and allows to create syscon objects first time when it is required by calling of syscon_regmap_lookup_by APIs and keeps a list of such syscon objects along with syscon provider device_nodes and regmap handles. Signed-off-by: Pankaj Dubey Signed-off-by: Tomasz Figa Tested-by: Vivek Gautam --- V1 of this patchset [1] and related discussion can be found here [1]. Changes since v1: - Removed of_syscon_unregister function. - Modified of_syscon_register function and it will be used by syscon.c to create syscon objects whenever required. - Removed platform device support from syscon. - Removed syscon_regmap_lookup_by_pdevname API support. - As there are significant changes w.r.t patchset v1, I am taking over author for this patchset from Tomasz Figa. Note: Current kernel has clps711x user of syscon_regmap_lookup_by_pdevname and will be broken after this patch. As per discussion over here [1], patches for making these drivers DT based are ready and once that is done they can use syscon_regmap_lookup_by_phandle or syscon_regmap_lookup_by_compatible. [1]: https://lkml.org/lkml/2014/8/22/81 drivers/mfd/syscon.c | 143 +++++++++++++------------------------------- include/linux/mfd/syscon.h | 1 + 2 files changed, 44 insertions(+), 100 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index ca15878..8247e93 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -14,41 +14,45 @@ #include #include -#include +#include #include #include -#include -#include -#include #include #include +#include -static struct platform_driver syscon_driver; +static DEFINE_SPINLOCK(syscon_list_slock); +static LIST_HEAD(syscon_list); struct syscon { + struct device_node *np; struct regmap *regmap; + struct list_head list; }; -static int syscon_match_node(struct device *dev, void *data) -{ - struct device_node *dn = data; - - return (dev->of_node == dn) ? 1 : 0; -} +static struct syscon *of_syscon_register(struct device_node *np); struct regmap *syscon_node_to_regmap(struct device_node *np) { - struct syscon *syscon; - struct device *dev; + struct syscon *entry, *syscon = NULL; + + spin_lock(&syscon_list_slock); - dev = driver_find_device(&syscon_driver.driver, NULL, np, - syscon_match_node); - if (!dev) - return ERR_PTR(-EPROBE_DEFER); + list_for_each_entry(entry, &syscon_list, list) + if (entry->np == np) { + syscon = entry; + break; + } - syscon = dev_get_drvdata(dev); + spin_unlock(&syscon_list_slock); - return syscon->regmap; + if (!syscon) + syscon = of_syscon_register(np); + + if (!IS_ERR(syscon)) + return syscon->regmap; + else + return ERR_CAST(syscon); } EXPORT_SYMBOL_GPL(syscon_node_to_regmap); @@ -68,27 +72,6 @@ struct regmap *syscon_regmap_lookup_by_compatible(const char *s) } EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_compatible); -static int syscon_match_pdevname(struct device *dev, void *data) -{ - return !strcmp(dev_name(dev), (const char *)data); -} - -struct regmap *syscon_regmap_lookup_by_pdevname(const char *s) -{ - struct device *dev; - struct syscon *syscon; - - dev = driver_find_device(&syscon_driver.driver, NULL, (void *)s, - syscon_match_pdevname); - if (!dev) - return ERR_PTR(-EPROBE_DEFER); - - syscon = dev_get_drvdata(dev); - - return syscon->regmap; -} -EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_pdevname); - struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np, const char *property) { @@ -110,81 +93,41 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np, } EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle); -static const struct of_device_id of_syscon_match[] = { - { .compatible = "syscon", }, - { }, -}; - static struct regmap_config syscon_regmap_config = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, }; -static int syscon_probe(struct platform_device *pdev) +static struct syscon *of_syscon_register(struct device_node *np) { - struct device *dev = &pdev->dev; - struct syscon_platform_data *pdata = dev_get_platdata(dev); struct syscon *syscon; - struct resource *res; + struct regmap *regmap; void __iomem *base; - syscon = devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL); - if (!syscon) - return -ENOMEM; + if (!of_device_is_compatible(np, "syscon")) + return ERR_PTR(-EINVAL); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -ENOENT; + syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); + if (!syscon) + return ERR_PTR(-ENOMEM); - base = devm_ioremap(dev, res->start, resource_size(res)); + base = of_iomap(np, 0); if (!base) - return -ENOMEM; - - syscon_regmap_config.max_register = res->end - res->start - 3; - if (pdata) - syscon_regmap_config.name = pdata->label; - syscon->regmap = devm_regmap_init_mmio(dev, base, - &syscon_regmap_config); - if (IS_ERR(syscon->regmap)) { - dev_err(dev, "regmap init failed\n"); - return PTR_ERR(syscon->regmap); - } - - platform_set_drvdata(pdev, syscon); + return ERR_PTR(-ENOMEM); - dev_dbg(dev, "regmap %pR registered\n", res); - - return 0; -} - -static const struct platform_device_id syscon_ids[] = { - { "syscon", }, - { } -}; + regmap = regmap_init_mmio(NULL, base, &syscon_regmap_config); + if (IS_ERR(regmap)) { + pr_err("regmap init failed\n"); + return ERR_CAST(regmap); + } -static struct platform_driver syscon_driver = { - .driver = { - .name = "syscon", - .owner = THIS_MODULE, - .of_match_table = of_syscon_match, - }, - .probe = syscon_probe, - .id_table = syscon_ids, -}; + syscon->regmap = regmap; + syscon->np = np; -static int __init syscon_init(void) -{ - return platform_driver_register(&syscon_driver); -} -postcore_initcall(syscon_init); + spin_lock(&syscon_list_slock); + list_add_tail(&syscon->list, &syscon_list); + spin_unlock(&syscon_list_slock); -static void __exit syscon_exit(void) -{ - platform_driver_unregister(&syscon_driver); + return syscon; } -module_exit(syscon_exit); - -MODULE_AUTHOR("Dong Aisheng "); -MODULE_DESCRIPTION("System Control driver"); -MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index 75e543b..a8e4c4b 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -18,6 +18,7 @@ #include struct device_node; +struct regmap; #ifdef CONFIG_MFD_SYSCON extern struct regmap *syscon_node_to_regmap(struct device_node *np);