From patchwork Fri Jun 3 14:21:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9153215 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 ABC4060221 for ; Fri, 3 Jun 2016 14:23:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C6942780C for ; Fri, 3 Jun 2016 14:23:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 910E1282E8; Fri, 3 Jun 2016 14:23:38 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9AA5F2780C for ; Fri, 3 Jun 2016 14:23:37 +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 1b8pz6-0000ly-LS; Fri, 03 Jun 2016 14:22:00 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8pz2-0000fy-I4 for linux-arm-kernel@lists.infradead.org; Fri, 03 Jun 2016 14:21:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=N606vpbwNzeGCwCw3kAtCSRs8AbPgR12VUUMHJqoH8Y=; b=V84/e9k8wvIt0O8weabAUiYTyvFwa20vXsK846VZTmss8PvuBSdzHaeIU6HsBVbe0ESbLRO+wLbxHCs67kcYMeki6gnnV4NXM7eXFFFYK5am968DM6zF50WapeIJEdlzWtAiDDkG3m9cXfjFA7KFPJ+D3JUwVHGYwRZ9YmsJVM4=; Received: from e0022681537dd.dyn.armlinux.org.uk ([2002:4e20:1eda:1:222:68ff:fe15:37dd]:40312 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1b8pyS-00013V-RA; Fri, 03 Jun 2016 15:21:20 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1b8pyR-0005OJ-V3; Fri, 03 Jun 2016 15:21:20 +0100 In-Reply-To: <20160603141548.GC1041@n2100.armlinux.org.uk> References: <20160603141548.GC1041@n2100.armlinux.org.uk> From: Russell King To: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org Subject: [PATCH v2 1/3] of: add common OF-based component functionality MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Fri, 03 Jun 2016 15:21:19 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160603_072157_081594_9E341659 X-CRM114-Status: GOOD ( 14.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Grant Likely , Rob Herring , Frank Rowand 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 Add common OF-based component functionality for matching devices by device node, and releasing the device node at the appropraite time. Signed-off-by: Russell King --- drivers/of/Makefile | 2 +- drivers/of/of_component.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/of_component.h | 14 ++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 drivers/of/of_component.c create mode 100644 include/linux/of_component.h diff --git a/drivers/of/Makefile b/drivers/of/Makefile index d7efd9d458aa..6a4a5e2c0839 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -1,4 +1,4 @@ -obj-y = base.o device.o platform.o +obj-y = base.o of_component.o device.o platform.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o obj-$(CONFIG_OF_FLATTREE) += fdt.o obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o diff --git a/drivers/of/of_component.c b/drivers/of/of_component.c new file mode 100644 index 000000000000..41e6e817d264 --- /dev/null +++ b/drivers/of/of_component.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2016 Russell King. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include + +static void component_release_of(struct device *dev, void *data) +{ + of_node_put(data); +} + +void component_match_add_of_compare(struct device *master, + struct component_match **matchptr, + int (*compare)(struct device *, void *), struct device_node *node) +{ + of_node_get(node); + component_match_add_release(master, matchptr, component_release_of, + compare, node); +} +EXPORT_SYMBOL_GPL(component_match_add_of_compare); + +static void component_compare_of(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +void component_match_add_of(struct device *master, + struct component_match **matchptr, struct device_node *node) +{ + of_node_get(node); + component_match_add_release(master, matchptr, component_release_of, + component_compare_of, node); +} +EXPORT_SYMBOL_GPL(component_match_add_of); diff --git a/include/linux/of_component.h b/include/linux/of_component.h new file mode 100644 index 000000000000..a8170ba3b786 --- /dev/null +++ b/include/linux/of_component.h @@ -0,0 +1,14 @@ +#ifndef __LINUX_COMPONENT_OF_H +#define __LINUX_COMPONENT_OF_H + +struct component_match; +struct device; +struct device_node; + +void component_match_add_of_compare(struct device *master, + struct component_match **matchptr, + int (*compare)(struct device *, void *), struct device_node *node); +void component_match_add_of(struct device *master, + struct component_match **matchptr, struct device_node *node); + +#endif