From patchwork Thu Jan 2 21:28:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 3431681 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A4EC09F2E9 for ; Fri, 3 Jan 2014 15:22:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5DA322010C for ; Fri, 3 Jan 2014 15:22:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8656120108 for ; Fri, 3 Jan 2014 15:22:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 917F9FAA3A; Fri, 3 Jan 2014 07:22:13 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from pandora.arm.linux.org.uk (gw-1.arm.linux.org.uk [78.32.30.217]) by gabe.freedesktop.org (Postfix) with ESMTP id 0EFA1FB920 for ; Thu, 2 Jan 2014 13:31:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora; h=Date:Sender:Message-Id:Subject:Cc:To:From:References:In-Reply-To; bh=ZTtL3aGOszoKwzipJefTXgx+JtgSEwD2KyzMS8u1dwA=; b=EwvZzJrkKgucjT+LzzYcahhyyoT0QDtcym/F9vISiIDEZye2mFffqdOXmh5xBQyqhar82Rgg8dSsb3R23u6uLrE6eOx2Pfpza18owawaNk9y8Y8QQ1QwM2Ae6CxXBuA7633jaYOSMDRBZ2DcPG6p6SUdwciC5s1bT/iFMgBdROg=; Received: from e0022681537dd.dyn.arm.linux.org.uk ([2002:4e20:1eda:1:222:68ff:fe15:37dd]:46452 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1Vypog-0004BN-TG; Thu, 02 Jan 2014 21:28:35 +0000 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1Vypog-0007Fj-FH; Thu, 02 Jan 2014 21:28:34 +0000 In-Reply-To: <20140102212528.GD7383@n2100.arm.linux.org.uk> References: <20140102212528.GD7383@n2100.arm.linux.org.uk> From: Russell King To: David Airlie , Greg Kroah-Hartman , Sascha Hauer , Shawn Guo Subject: [PATCH RFC 33/46] imx-drm: imx-drm-core: provide helper function to parse possible crtcs Message-Id: Date: Thu, 02 Jan 2014 21:28:34 +0000 X-Mailman-Approved-At: Fri, 03 Jan 2014 07:21:54 -0800 Cc: devel@driverdev.osuosl.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide a helper function to parse possible crtcs before the encoder is registered. The crtc mask is derived from the position of the CRTCs registered in the drm_device. Signed-off-by: Russell King --- drivers/staging/imx-drm/imx-drm-core.c | 66 ++++++++++++++++++++++++++++++++ drivers/staging/imx-drm/imx-drm.h | 2 + 2 files changed, 68 insertions(+), 0 deletions(-) diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c index b11568d6444b..1cfb8a18d905 100644 --- a/drivers/staging/imx-drm/imx-drm-core.c +++ b/drivers/staging/imx-drm/imx-drm-core.c @@ -657,6 +657,72 @@ int imx_drm_add_encoder(struct drm_encoder *encoder, } EXPORT_SYMBOL_GPL(imx_drm_add_encoder); +/* + * Find the DRM CRTC possible mask for the device node cookie/id. + * + * The encoder possible masks are defined by their position in the + * mode_config crtc_list. This means that CRTCs must not be added + * or removed once the DRM device has been fully initialised. + */ +static uint32_t imx_drm_find_crtc_mask(struct imx_drm_device *imxdrm, + void *cookie, int id) +{ + unsigned i; + + for (i = 0; i < MAX_CRTC; i++) { + struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[i]; + if (imx_drm_crtc && imx_drm_crtc->cookie.id == id && + imx_drm_crtc->cookie.cookie == cookie) + return drm_helper_crtc_possible_mask(imx_drm_crtc->crtc); + } + + return 0; +} + +int imx_drm_encoder_parse_of(struct drm_device *drm, + struct drm_encoder *encoder, struct device_node *np) +{ + struct imx_drm_device *imxdrm = drm->dev_private; + uint32_t crtc_mask = 0; + int i, ret = 0; + + for (i = 0; !ret; i++) { + struct of_phandle_args args; + uint32_t mask; + int id; + + ret = of_parse_phandle_with_args(np, "crtcs", "#crtc-cells", i, + &args); + if (ret == -ENOENT) + break; + if (ret < 0) + return ret; + + id = args.args_count > 0 ? args.args[0] : 0; + mask = imx_drm_find_crtc_mask(imxdrm, args.np, id); + of_node_put(args.np); + + /* + * If we failed to find the CRTC(s) which this encoder is + * supposed to be connected to, it's because the CRTC has + * not been registered yet. Defer probing, and hope that + * the required CRTC is added later. + */ + if (mask == 0) + return -EPROBE_DEFER; + + crtc_mask |= mask; + } + + encoder->possible_crtcs = crtc_mask; + + /* FIXME: this is the mask of outputs which can clone this output. */ + encoder->possible_clones = ~0; + + return 0; +} +EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of); + int imx_drm_encoder_add_possible_crtcs( struct imx_drm_encoder *imx_drm_encoder, struct device_node *np) diff --git a/drivers/staging/imx-drm/imx-drm.h b/drivers/staging/imx-drm/imx-drm.h index 78465239ed4c..49d4aaf33f97 100644 --- a/drivers/staging/imx-drm/imx-drm.h +++ b/drivers/staging/imx-drm/imx-drm.h @@ -64,6 +64,8 @@ struct device_node; int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder); int imx_drm_encoder_add_possible_crtcs(struct imx_drm_encoder *imx_drm_encoder, struct device_node *np); +int imx_drm_encoder_parse_of(struct drm_device *drm, + struct drm_encoder *encoder, struct device_node *np); int imx_drm_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode);