From patchwork Wed Dec 2 09:09:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 7743611 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CE5E3BEEE1 for ; Wed, 2 Dec 2015 09:12:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEE442063C for ; Wed, 2 Dec 2015 09:12:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CB0A20640 for ; Wed, 2 Dec 2015 09:12:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755503AbbLBJM0 (ORCPT ); Wed, 2 Dec 2015 04:12:26 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:12218 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756855AbbLBJMV (ORCPT ); Wed, 2 Dec 2015 04:12:21 -0500 Received: from 172.24.1.49 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.49]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DAB70786; Wed, 02 Dec 2015 17:11:23 +0800 (CST) Received: from localhost (10.177.19.180) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Wed, 2 Dec 2015 17:11:13 +0800 From: Kefeng Wang To: "Rafael J. Wysocki" , Arnd Bergmann CC: Hanjun Guo , , , Kefeng Wang Subject: [RFC PATCH 4/4] mfd: syscon: add ACPI support Date: Wed, 2 Dec 2015 17:09:28 +0800 Message-ID: <1449047368-5768-5-git-send-email-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1449047368-5768-1-git-send-email-wangkefeng.wang@huawei.com> References: <1449047368-5768-1-git-send-email-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.180] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.565EB5BC.009A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: d040e9cced961a5e9231abe34b4dde9d Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 enables syscon with ACPI support. syscon_regmap_lookup_by_dev_property() function was added. With helper device_get_reference_node() and acpi_dev_find_plat_dev(), it can be used in both DT and ACPI. The device driver can obtain syscon using _DSD method in DSDT, an example is shown below. Device(CTL0) { Name(_HID, "HISI0061") Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x80000000, 0x10000) }) } Device(DEV0) { Name(_HID, "HISI00B1") Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x8c030000, 0x10000) Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive){ 192 } }) Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () {"syscon",Package() {\_SB.CTL0} } } }) } Signed-off-by: Kefeng Wang --- drivers/mfd/syscon.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 8 ++++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 176bf0f..6f23418 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -12,6 +12,7 @@ * (at your option) any later version. */ +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -174,6 +176,47 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np, } EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle); +struct regmap *syscon_regmap_lookup_by_dev_property(struct device *dev, + const char *propname) +{ + struct fwnode_handle *fwnode; + struct regmap *regmap = NULL; + + fwnode = device_get_reference_node(dev, propname, 0); + + if (IS_ENABLED(CONFIG_OF) && dev->of_node) { + struct device_node *syscon_np; + if (propname) + syscon_np = to_of_node(fwnode); + else + syscon_np = dev->of_node; + if (!syscon_np) + return ERR_PTR(-ENODEV); + regmap = syscon_node_to_regmap(syscon_np); + of_node_put(syscon_np); + } else if (IS_ENABLED(CONFIG_ACPI)) { + struct platform_device *pdev; + struct acpi_device *adev; + struct syscon *syscon; + + adev = to_acpi_device_node(fwnode); + if (!adev) + return ERR_PTR(-ENODEV); + + pdev = acpi_dev_find_plat_dev(adev); + if (!pdev) + return ERR_PTR(-ENODEV); + + syscon = platform_get_drvdata(pdev); + if (!syscon) + return ERR_PTR(-ENODEV); + + regmap = syscon->regmap; + } + return regmap; +} +EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_dev_property); + static int syscon_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -216,9 +259,16 @@ static const struct platform_device_id syscon_ids[] = { { } }; +static const struct acpi_device_id syscon_acpi_match[] = { + { "HISI0061", 0 }, /* better to use generic ACPI ID */ + { } +}; +MODULE_DEVICE_TABLE(acpi, syscon_acpi_match); + static struct platform_driver syscon_driver = { .driver = { .name = "syscon", + .acpi_match_table = ACPI_PTR(syscon_acpi_match), }, .probe = syscon_probe, .id_table = syscon_ids, diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index 75e543b..db79ca2 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -17,6 +17,7 @@ #include +struct device; struct device_node; #ifdef CONFIG_MFD_SYSCON @@ -26,6 +27,8 @@ extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s); extern struct regmap *syscon_regmap_lookup_by_phandle( struct device_node *np, const char *property); +extern struct regmap *syscon_regmap_lookup_by_dev_property(struct device *dev, + const char *propname); #else static inline struct regmap *syscon_node_to_regmap(struct device_node *np) { @@ -48,6 +51,11 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle( { return ERR_PTR(-ENOSYS); } +static inline struct regmap *syscon_regmap_lookup_by_dev_property(struct device *dev, + const char *propname); +{ + return ERR_PTR(-ENOSYS); +} #endif #endif /* __LINUX_MFD_SYSCON_H__ */