From patchwork Sat Jan 20 03:20:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 10176241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8A2F460386 for ; Sat, 20 Jan 2018 03:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FBEA26E1A for ; Sat, 20 Jan 2018 03:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70D5228795; Sat, 20 Jan 2018 03:23:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E160F26E1A for ; Sat, 20 Jan 2018 03:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qZW/ES6J314CgIJTUmUsbhlA5vZsJ08rPqcm6Whzm+w=; b=lL4fFAr3yOIY7xUF0+ReB389oT eijLzDl8tpFGGQiu7/vWfo5pOnD/okCqsoIVXO1UUSCkT+p/HHfzkieQyOA4fZ3z+cajguebme9ua anBO6xtRXGPS8PKCqCUNQE9BsE71ps4HFERmR8xWgooAQIKLV+GpLNXcUp2Eb6eJ+qkm+SYyHllI9 kbsV/nIsCrRl90woZUFeW5Gu55d2dCcIbTa/40ZiTShSP0A48/IDUHfLitm7tmt/h6Lr9DFXyw/bV /kkzf3EfBkNc0SfW/oxflpDXHlroMOjHjOA5pg/+ImMYR9rJQmfSHspnprRj3or/NlekzJa+6/hK0 VXvvUcHQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ecjkK-0007FW-En; Sat, 20 Jan 2018 03:23:08 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ecjkI-0007F0-L5 for linux-arm-kernel@bombadil.infradead.org; Sat, 20 Jan 2018 03:23:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4OKFdWeyCeyHdl/nJXEXfcOSdzKaqpMm9Mi0xNWl4rU=; b=J1QNykmEIpZhptL4VsfEOo4Uo RO5u5ehv87GKsmeFhYgjh4hqdbshlGZyQX2deX5gujWTtd2UmdvAP6nuWXp16ySl/p2K2ZDV6+q7L 1d52q0qQfu37Fplyq0n+DbG/Im3m/HHAyP5s4qmNKWxlF3TcFZDrQgt1tN+LrMxGL8T5p/MwKN5MC fKNWamY0Ht6r5V82Z3sPPfk9SwrNOF3eUu1cJBRfv51F8nopOHTcmyBbIU8jJuQPGv0miY0B9A2QJ yYwHf2fuH5j7wHR9sEW6ML0HeSqH4hNIBt29q7x4Gm1TkWGQZTVIvZP0CjgwdpxnEhewjDjC1JRBc UNkqwkNzg==; Received: from vern.gendns.com ([206.190.152.46]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ecjkD-0002gG-0D for linux-arm-kernel@lists.infradead.org; Sat, 20 Jan 2018 03:23:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4OKFdWeyCeyHdl/nJXEXfcOSdzKaqpMm9Mi0xNWl4rU=; b=fRCVbLXhHIYQHI46Q9TwvpzeG hQxIVtSbVppDVpVOvSYCE/YNzNBLaAU1djwrin7TAUBXdeHhsYNdn95oCUE0s8n1CQvamxjW2hbak 3ByGaVmhyrt0mcsngcDwH4n6ZqqZmHvXBzzomv7DuCaC1i0OenfKG/RtgUBXgS/ekNwBnLl5ez4vA DvPW0sm31DO57IY8mwnZu7jZ9oB+V1KqdYW40jdvs5b6hrBxxEcvDvEKpH6H+RPx/qutuZtuPCLcR 6w8O5ndBC56nc+xlR3f+uzFlCJ+hXyJesmNSYd9jeQfqh5Sl4gYaXABgr65C4wK9BK+2oeHwYTXRl VEiisDUtg==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:44372 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1ecjhz-002FtH-Pf; Fri, 19 Jan 2018 22:20:44 -0500 From: David Lechner To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/6] mfd: syscon: Add syscon_register() function Date: Fri, 19 Jan 2018 21:20:19 -0600 Message-Id: <1516418424-28686-2-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516418424-28686-1-git-send-email-david@lechnology.com> References: <1516418424-28686-1-git-send-email-david@lechnology.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180120_032301_286957_39C63405 X-CRM114-Status: GOOD ( 19.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Lechner , Arnd Bergmann , Kevin Hilman , Adam Ford , Sekhar Nori , linux-kernel@vger.kernel.org, Kishon Vijay Abraham I , Bartosz Golaszewski , Lee Jones MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This adds a new syscon_register() function that creates a new syscon regmap and adds it to the lookup list. This function serves two purposes: 1. This is needed for platforms without device tree support where the syscon regmap is needed in early boot (e.g. clocks), because using a platform driver at this point in boot is not an option. 2. It allows other drivers to use syscon_regmap_lookup_by_compatible() for both device tree and non-DT platforms instead of having to have a separate case that calls syscon_regmap_lookup_by_pdevname(). Signed-off-by: David Lechner --- drivers/mfd/syscon.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 9 ++++++ 2 files changed, 80 insertions(+) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index b93fe4c..ab086b1 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -25,6 +25,8 @@ #include #include +#define SYSCON_COMPATIBLE_SIZE 50 + static struct platform_driver syscon_driver; static DEFINE_SPINLOCK(syscon_list_slock); @@ -34,6 +36,7 @@ struct syscon { struct device_node *np; struct regmap *regmap; struct list_head list; + char compatible[SYSCON_COMPATIBLE_SIZE]; }; static const struct regmap_config syscon_regmap_config = { @@ -140,9 +143,27 @@ EXPORT_SYMBOL_GPL(syscon_node_to_regmap); struct regmap *syscon_regmap_lookup_by_compatible(const char *s) { + struct syscon *entry, *syscon = NULL; struct device_node *syscon_np; struct regmap *regmap; + spin_lock(&syscon_list_slock); + + /* Check for entries registered with syscon_register() */ + list_for_each_entry(entry, &syscon_list, list) { + if (!entry->compatible) + continue; + if (!strncmp(entry->compatible, s, SYSCON_COMPATIBLE_SIZE)) { + syscon = entry; + break; + } + } + + spin_unlock(&syscon_list_slock); + + if (syscon) + return syscon->regmap; + syscon_np = of_find_compatible_node(NULL, NULL, s); if (!syscon_np) return ERR_PTR(-ENODEV); @@ -196,6 +217,56 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np, } EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle); +/** + * syscon_register - Register a new syscon regmap + * @start: The starting memory address of the regmap + * @size: The size of the regmap in bytes + * @compatible: Compatible string used for lookup + * + * Returns: Pointer to a regmap or a negative error code. + */ +struct regmap *syscon_register(resource_size_t start, size_t size, + const char *compatible) +{ + struct regmap_config syscon_config = syscon_regmap_config; + struct syscon *syscon; + void __iomem *base; + int err; + + syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); + if (!syscon) + return ERR_PTR(-ENOMEM); + + base = ioremap(start, size); + if (!base) { + err = -ENOMEM; + goto err_free_syscon; + } + + strncpy(syscon->compatible, compatible, SYSCON_COMPATIBLE_SIZE); + + syscon_config.max_register = size - 1; + syscon->regmap = regmap_init_mmio(NULL, base, &syscon_config); + if (IS_ERR(syscon->regmap)) { + err = PTR_ERR(syscon->regmap); + goto err_iounmap; + } + + spin_lock(&syscon_list_slock); + list_add_tail(&syscon->list, &syscon_list); + spin_unlock(&syscon_list_slock); + + return syscon->regmap; + +err_iounmap: + iounmap(base); +err_free_syscon: + kfree(syscon); + + return ERR_PTR(err); +} +EXPORT_SYMBOL_GPL(syscon_register); + static int syscon_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index 40a76b9..ce531b4 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -27,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_register(resource_size_t start, size_t size, + const char *compatible); #else static inline struct regmap *syscon_node_to_regmap(struct device_node *np) { @@ -49,6 +51,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle( { return ERR_PTR(-ENOTSUPP); } + +static inline struct regmap *syscon_register(resource_size_t start, + size_t size, + const char *id) +{ + return ERR_PTR(-ENOTSUPP); +} #endif #endif /* __LINUX_MFD_SYSCON_H__ */