From patchwork Mon Oct 19 12:21:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 55223 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 2AF8B22EA2 for ; Mon, 19 Oct 2015 12:22:26 +0000 (UTC) Received: by lbbor1 with SMTP id or1sf25742459lbb.2 for ; Mon, 19 Oct 2015 05:22:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:subject:date :message-id:in-reply-to:references:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=mVRnYRefRDdBdkI4orLkVGDu4VWjL6X90mRLz6bgUiU=; b=WeVi2KcEfXw+2ypxU2HzpubQ7RmVskeA6C69qELJH+t2A0JKfaunSSECeeh2PKsyr3 NTsOhFKwlkuVToxplABVnQ+yRJEnMf84NZDEC47MKLTNGC0SKbaXTRUxkilBwLbz8nh8 d6S7yo6g1k04sphvffgr0/dTz4xyQSo+EHTSH9VmBSQGDSmju3mNuUNXlypigr9coG5L cUvePkAmIzG6Q8Yp/0FeL9z7FPq/fe6lG6aG5UWCkPHGniTCGEzRBDVSDN8hHLQb6/Yy aOnJpEKJkRnTzLFG2pFmTW+RPC8KeabFH0RehprMXrKuUlgHMoFk8ahYI1FHMCwm87FV k3Pg== X-Gm-Message-State: ALoCoQl3LkvtAzNddiwLJC6xbsvOujsOWC23XfOUSowaz0kiWq+Kw8IOxYqyhN7MAiVz3igGnVdN X-Received: by 10.180.160.194 with SMTP id xm2mr1826927wib.6.1445257345113; Mon, 19 Oct 2015 05:22:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.15.147 with SMTP id 19ls570685lfp.5.gmail; Mon, 19 Oct 2015 05:22:24 -0700 (PDT) X-Received: by 10.25.209.80 with SMTP id i77mr9517489lfg.92.1445257344962; Mon, 19 Oct 2015 05:22:24 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id j68si21017123lfi.25.2015.10.19.05.22.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 05:22:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbpp2 with SMTP id pp2so114527142lbb.0 for ; Mon, 19 Oct 2015 05:22:24 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr14838120lbb.56.1445257344829; Mon, 19 Oct 2015 05:22:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1437779lbq; Mon, 19 Oct 2015 05:22:23 -0700 (PDT) X-Received: by 10.50.128.130 with SMTP id no2mr13609139igb.81.1445257343627; Mon, 19 Oct 2015 05:22:23 -0700 (PDT) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id e193si25982835ioe.131.2015.10.19.05.22.23; Mon, 19 Oct 2015 05:22:23 -0700 (PDT) Received-SPF: pass (google.com: domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 503A96E8DC; Mon, 19 Oct 2015 05:22:22 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17F166E8CA for ; Mon, 19 Oct 2015 05:22:19 -0700 (PDT) Received: from e106497-lin.cambridge.arm.com (e106497-lin.cambridge.arm.com [10.2.131.158]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id t9JCLrED003452; Mon, 19 Oct 2015 13:21:54 +0100 From: Liviu Dudau To: David Airlie , Daniel Vetter , Philipp Zabel , Mark Yao , Heiko Stuebner , Russell King Subject: [RFC PATCH v2 1/4] drm: Introduce generic probe function for component based masters. Date: Mon, 19 Oct 2015 13:21:50 +0100 Message-Id: <1445257313-7147-2-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.6.0 In-Reply-To: <1445257313-7147-1-git-send-email-Liviu.Dudau@arm.com> References: <1445257313-7147-1-git-send-email-Liviu.Dudau@arm.com> Cc: linux-rockchip , LAKML , dri-devel , LKML X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: liviu.dudau@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 A lot of component based DRM drivers use a variant of the same code as the probe function. They bind the crtc ports in the first iteration and then scan through the child nodes and bind the encoders attached to the remote endpoints. Factor the common code into a separate function called drm_of_component_probe() in order to increase code reuse. Cc: David Airlie Signed-off-by: Liviu Dudau --- drivers/gpu/drm/drm_of.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_of.h | 12 +++++++ 2 files changed, 104 insertions(+) diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index be38840..cf16240 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -61,3 +62,94 @@ uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, return possible_crtcs; } EXPORT_SYMBOL(drm_of_find_possible_crtcs); + +/** + * drm_of_component_probe - Generic probe function for a component based master + * @dev: master device containing the OF node + * @compare_of: compare function used for matching components + * @master_ops: component master ops to be used + * + * Parse the platform device OF node and bind all the components associated + * with the master. Interface ports are added before the encoders in order to + * satisfy their .bind requirements + * See Documentation/devicetree/bindings/graph.txt for the bindings. + * + * Returns zero if successful, or one of the standard error codes if it fails. + */ +int drm_of_component_probe(struct device *dev, + int (*compare_of)(struct device *, void *), + const struct component_master_ops *master_ops) +{ + struct device_node *ep, *port, *remote; + struct component_match *match = NULL; + int i, ret; + + if (!dev->of_node) + return -EINVAL; + + /* + * Bind the crtc's ports first, so that drm_of_find_possible_crtcs() + * called from encoder's .bind callbacks works as expected + */ + for (i = 0; ; i++) { + port = of_parse_phandle(dev->of_node, "ports", i); + if (!port) + break; + + if (!of_device_is_available(port->parent)) { + of_node_put(port); + continue; + } + + component_match_add(dev, &match, compare_of, port); + of_node_put(port); + } + + if (i == 0) { + dev_err(dev, "missing 'ports' property\n"); + return -ENODEV; + } + + if (!match) { + dev_err(dev, "no available port\n"); + return -ENODEV; + } + + /* + * For bound crtcs, bind the encoders attached to their remote endpoint + */ + for (i = 0; ; i++) { + port = of_parse_phandle(dev->of_node, "ports", i); + if (!port) + break; + + if (!of_device_is_available(port->parent)) { + of_node_put(port); + continue; + } + + for_each_child_of_node(port, ep) { + remote = of_graph_get_remote_port_parent(ep); + if (!remote || !of_device_is_available(remote)) { + of_node_put(remote); + continue; + } else if (!of_device_is_available(remote->parent)) { + dev_warn(dev, "parent device of %s is not available\n", + remote->full_name); + of_node_put(remote); + continue; + } + + component_match_add(dev, &match, compare_of, remote); + of_node_put(remote); + } + of_node_put(port); + } + + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + + return component_master_add_with_match(dev, master_ops, match); +} +EXPORT_SYMBOL(drm_of_component_probe); diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h index 2441f71..7c0c05b 100644 --- a/include/drm/drm_of.h +++ b/include/drm/drm_of.h @@ -1,18 +1,30 @@ #ifndef __DRM_OF_H__ #define __DRM_OF_H__ +struct component_master_ops; +struct device; struct drm_device; struct device_node; #ifdef CONFIG_OF extern uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, struct device_node *port); +extern int drm_of_component_probe(struct device *dev, + int (*compare_of)(struct device *, void *), + const struct component_master_ops *master_ops); #else static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, struct device_node *port) { return 0; } + +static inline int drm_of_component_probe(struct device *dev, + int (*compare_of)(struct device *, void *), + const struct component_master_ops *master_ops) +{ + return -EINVAL; +} #endif #endif /* __DRM_OF_H__ */