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: 9153197 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 470556072B for ; Fri, 3 Jun 2016 14:21:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 384A626E39 for ; Fri, 3 Jun 2016 14:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CC99282E8; Fri, 3 Jun 2016 14:21:31 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A1326E39 for ; Fri, 3 Jun 2016 14:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932326AbcFCOV3 (ORCPT ); Fri, 3 Jun 2016 10:21:29 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:52374 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932297AbcFCOV2 (ORCPT ); Fri, 3 Jun 2016 10:21:28 -0400 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 Cc: Rob Herring , Frank Rowand , Grant Likely 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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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