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: 57536 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2738020lbb; Wed, 2 Dec 2015 01:12:28 -0800 (PST) X-Received: by 10.98.19.12 with SMTP id b12mr3049724pfj.78.1449047547621; Wed, 02 Dec 2015 01:12:27 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tq4si3363466pab.243.2015.12.02.01.12.27; Wed, 02 Dec 2015 01:12:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755503AbbLBJM0 (ORCPT + 6 others); 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 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(+) -- 1.7.12.4 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" 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/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__ */