From patchwork Wed Jul 1 09:40:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6702321 Return-Path: X-Original-To: patchwork-alsa-devel@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 E2573C05AC for ; Wed, 1 Jul 2015 09:44:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EE4A62062A for ; Wed, 1 Jul 2015 09:44:24 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id A09E22066C for ; Wed, 1 Jul 2015 09:44:23 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id DE00C2610A1; Wed, 1 Jul 2015 11:44:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, NO_DNS_FOR_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id CF009260682; Wed, 1 Jul 2015 11:42:46 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5425226061B; Wed, 1 Jul 2015 11:42:43 +0200 (CEST) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by alsa0.perex.cz (Postfix) with ESMTP id 485EF260617 for ; Wed, 1 Jul 2015 11:42:32 +0200 (CEST) Received: by wiwl6 with SMTP id l6so159009462wiw.0 for ; Wed, 01 Jul 2015 02:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nzNLkLZlbVSdhcNlAfuEM79vuIIqmzLQdbDOFkWub5c=; b=B45/vakO6yf9R4rvX1mwtHcnhDi8vbAQzPl2WtUrAfjI2pWiS4Pa475D8CmyDyp+m1 C9VjDW3osijaWTKUU8472spra9O42bkYDOBqdoqEu7rxKJa+E2HTEc9TIcoA7zhDvC2f W/GQn4qLB4iySjXTHPVQ2PZoYlXyUCE0Vn0reNCLvJHVQCkGPF5sPryoLmzKW2vZ2pRX CcqrJRE6h2SoU5DQQZ5w6LTPBOCQbW1Jkw3z82rJlSswVAjvSG1LhcFB/uHb9zCVV2o7 u28UsyQt5UUG5CTKKaJfFPbJ/PWFnOqSHzsVvv8hRce6UcvbJjkkOR9sTyS1IpMHMcQ5 HZVA== X-Received: by 10.194.206.65 with SMTP id lm1mr47654071wjc.117.1435743752052; Wed, 01 Jul 2015 02:42:32 -0700 (PDT) Received: from cizrna.lan ([109.72.12.160]) by mx.google.com with ESMTPSA id x10sm1992663wjr.25.2015.07.01.02.42.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2015 02:42:31 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Date: Wed, 1 Jul 2015 11:40:57 +0200 Message-Id: <1435743667-11987-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> References: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> Cc: devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, Tomeu Vizoso , linux-gpio@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , alsa-devel@alsa-project.org, dri-devel@lists.freedesktop.org, linux-acpi@vger.kernel.org, Mark Brown , linux-pwm@vger.kernel.org Subject: [alsa-devel] [PATCH v2 02/12] device: property: find dependencies of a firmware node X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Adds API that allows callers to find out what other firmware nodes a node depends on. Implementors of bindings documentation can register callbacks that return the dependencies of a node. Dependency information can be used to change the order in which devices are probed, or to print a warning when a device node is going to be probed without all its dependencies fulfilled. Signed-off-by: Tomeu Vizoso --- Changes in v2: - Allow bindings implementations register a function instead of using class callbacks, as not only subsystems implement firmware bindings. drivers/base/property.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fwnode.h | 5 +++ include/linux/property.h | 12 +++++++ 3 files changed, 108 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 8ead1ba..9d38ede 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -19,7 +19,13 @@ #include #include +struct dependency_parser { + struct list_head parser; + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps); +}; + static bool fwnode_match_enable = false; +static LIST_HEAD(dependency_parsers); /** * device_add_property_set - Add a collection of properties to a device object. @@ -553,6 +559,27 @@ bool device_dma_is_coherent(struct device *dev) EXPORT_SYMBOL_GPL(device_dma_is_coherent); /** + * fwnode_add_dependency - add firmware node to the passed dependency list + * @fwnode: Firmware node to add to dependency list + * @list: Dependency list to add the fwnode to + */ +void fwnode_add_dependency(struct fwnode_handle *fwnode, + struct list_head *list) +{ + struct fwnode_dependency *dep; + + dep = kzalloc(sizeof(*dep), GFP_KERNEL); + if (!dep) + return; + + INIT_LIST_HEAD(&dep->dependency); + dep->fwnode = fwnode; + + list_add_tail(&dep->dependency, list); +} +EXPORT_SYMBOL_GPL(fwnode_add_dependency); + +/** * fwnode_get_parent - return the parent node of a device node * @fwnode: Device node to find the parent node of */ @@ -600,6 +627,70 @@ bool fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compatible) EXPORT_SYMBOL_GPL(fwnode_is_compatible); /** + * fwnode_add_dependency_parser - register dependency parser + * @func: Function that will be called to find out dependencies of a node + * + * Registers a callback that will be called when collecting the dependencies + * of a firmware node. The callback should inspect the properties of the node + * and call fwnode_add_dependency() for each dependency it recognizes, from + * the bindings documentation. + */ +void fwnode_add_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)) +{ + struct dependency_parser *parser; + + parser = kzalloc(sizeof(*parser), GFP_KERNEL); + if (!parser) + return; + + INIT_LIST_HEAD(&parser->parser); + parser->func = func; + + list_add_tail(&parser->parser, &dependency_parsers); +} +EXPORT_SYMBOL_GPL(fwnode_add_dependency_parser); + +/** + * fwnode_remove_dependency_parser - unregister dependency parser + * @func: Function that was to be called to find out dependencies of a node + */ +void fwnode_remove_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)) +{ + struct dependency_parser *parser, *tmp; + + list_for_each_entry_safe(parser, tmp, &dependency_parsers, parser) { + if (parser->func == func) { + list_del(&parser->parser); + kfree(parser); + return; + } + } +} +EXPORT_SYMBOL_GPL(fwnode_remove_dependency_parser); + +/** + * fwnode_get_dependencies - find out what dependencies a firmware node has + * @fwnode: firmware node to find its dependencies + * @deps: list of struct fwnode_dependency in which dependencies will be placed + */ +void fwnode_get_dependencies(struct fwnode_handle *fwnode, + struct list_head *deps) +{ + struct dependency_parser *parser; + struct fwnode_handle *child; + + list_for_each_entry(parser, &dependency_parsers, parser) + parser->func(fwnode, deps); + + /* Some device nodes will have dependencies in non-device sub-nodes */ + fwnode_for_each_child_node(fwnode, child) + if (!fwnode_property_present(child, "compatible")) + fwnode_get_dependencies(child, deps); +} + +/** * fwnode_driver_match_device - Tell if a driver matches a device. * @drv: the device_driver structure to test * @dev: the device structure to match against diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 0408545..68ab558 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -24,4 +24,9 @@ struct fwnode_handle { struct fwnode_handle *secondary; }; +struct fwnode_dependency { + struct fwnode_handle *fwnode; + struct list_head dependency; +}; + #endif diff --git a/include/linux/property.h b/include/linux/property.h index 4e453c4..b8b86ea 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -86,6 +86,18 @@ bool fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compatible); bool fwnode_driver_match_device(struct device *dev, const struct device_driver *drv); +void fwnode_add_dependency(struct fwnode_handle *fwnode, + struct list_head *list); + +void fwnode_add_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)); + +void fwnode_remove_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)); + +void fwnode_get_dependencies(struct fwnode_handle *fwnode, + struct list_head *list); + unsigned int device_get_child_node_count(struct device *dev); static inline bool device_property_read_bool(struct device *dev,