From patchwork Thu Oct 15 16:11:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 55050 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 2108722FFA for ; Thu, 15 Oct 2015 16:12:20 +0000 (UTC) Received: by lbbyh1 with SMTP id yh1sf6721391lbb.0 for ; Thu, 15 Oct 2015 09:12:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3uOm1H5mP5J42x8beNlOWVG+KSh6Rm2HJBg53KBFNpQ=; b=O5Yyrli9NjpqRrWWp9yccrneRvFBtT4dibv6W4c7i4lZfoWVop2lEsu4/mK9wp82id pcfovnq8GKM1mZzuRTWk3Wbk+aFvmILv+98vMHXdNAU0tMh1wyyrdQh1ZQ+gljLl0wSb aGsZQpPWDfjpo3jVBjeD17EMTnebT9WoJRgw8QxW77YAw8YpFJYZnPqlDFdVW1bMFSKH SYnVBJBKbvDTYGJiZJbcnQAJYjNQAdnZvee/FybQmm9FufGo1X7IxNrjDUkHrNxbLWl3 BKfTgkXapZpLx8BJnRrzUbZYzgQezkCjWmalQlgoGMWH0z04w5kgzEHLSElyl6eYDta+ ChsQ== X-Gm-Message-State: ALoCoQmGEkWfiyPXWbfLjrqiri1dDT9NHRwj3l8pe1sOL6Q7EqEBRjLMVduYsMMJn24PcFrs5Ajh X-Received: by 10.112.63.165 with SMTP id h5mr2447307lbs.18.1444925539069; Thu, 15 Oct 2015 09:12:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.152.199 with SMTP id a190ls202404lfe.62.gmail; Thu, 15 Oct 2015 09:12:18 -0700 (PDT) X-Received: by 10.112.170.35 with SMTP id aj3mr5089137lbc.108.1444925538893; Thu, 15 Oct 2015 09:12:18 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id k5si9600860lfg.108.2015.10.15.09.12.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 09:12:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbwr8 with SMTP id r8so74715878lbw.2 for ; Thu, 15 Oct 2015 09:12:18 -0700 (PDT) X-Received: by 10.112.151.106 with SMTP id up10mr5152183lbb.106.1444925538366; Thu, 15 Oct 2015 09:12:18 -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 w3csp725671lbq; Thu, 15 Oct 2015 09:12:17 -0700 (PDT) X-Received: by 10.107.154.213 with SMTP id c204mr11512904ioe.80.1444925537120; Thu, 15 Oct 2015 09:12:17 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si21947259igl.33.2015.10.15.09.12.16; Thu, 15 Oct 2015 09:12:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753666AbbJOQMN (ORCPT + 30 others); Thu, 15 Oct 2015 12:12:13 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:54430 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752403AbbJOQMI (ORCPT ); Thu, 15 Oct 2015 12:12:08 -0400 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 t9FGBBSL020260; Thu, 15 Oct 2015 17:11:12 +0100 From: Liviu Dudau To: David Airlie , Daniel Vetter , Philipp Zabel , Mark Yao , Heiko Stuebner , Russell King Cc: dri-devel , linux-rockchip , LAKML , LKML Subject: [RFC PATCH 1/4] drm: Introduce generic probe function for component based masters. Date: Thu, 15 Oct 2015 17:11:07 +0100 Message-Id: <1444925470-9963-2-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.6.0 In-Reply-To: <1444925470-9963-1-git-send-email-Liviu.Dudau@arm.com> References: <1444925470-9963-1-git-send-email-Liviu.Dudau@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.177 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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__ */