Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1541338ybk; Sat, 16 May 2020 14:55:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyQTLs0U4U+C375w9Y5VCZE/wY4agZMr7/vjJDvjYOYZXKIKxJ/Z1NGnfMWjOk8P0Gf+wY X-Received: by 2002:a17:907:9481:: with SMTP id dm1mr9326314ejc.268.1589666117954; Sat, 16 May 2020 14:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589666117; cv=none; d=google.com; s=arc-20160816; b=0o9AcZjJEYC2X09T2M7FEOXoOZCz4mkMKbup55fZSsMUIWUIhgjbAUb0vWimJVtO/f rWmvYLectHiECmJNH/L8NqhHh+3OwIINSLXyy32p3OYZP08wUGKMQ8fg2wpJg/o9X+Cf 6/JukpHpLvg9dl3zNBuyW66kuHD9DTLSYevGz9sHN4FT2XCNDGaVe1BLvgCRjBYCSgFk xA7h7hwh1VHEvEGtIK9gCt39W2dSfucY29LwuOQT0DoAP37vDaYa7VW0bsE9YnPJ/C6k l0+YGm/lifLpxIo6qNuamdWW0BwXZfx/W8uOI1jBYHxaOxlsh4lJ/wG+mP7q9yZnrtSn 7r3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1QAI1+lygs7RukytrBDJiA7TI+zQ9n1V3xrM8AumWXA=; b=Ho+csq2pOclzEi1l/lqDML+a8yp0lWVjSuCyiLo6KMQBYa/9fZjRRm/NBIqFjvqc2b 7/+/usUT7Bp7C3AI6qe9akdCLvkOFUb+6cPUFOa3MWexga+SfdYCew8a8vMrAbmP+ghI ztO8K1PORwpQA1KAjVk9vVQLq+xKvgx4RtWSl8cYqeAwAox6M1wXFR3tHulMUKMW7jZz gXVlvLqW+2hkKhI/8zjL0vuTGZNul+KDy8e00T/MSqXpWOXF48I9MzOaTyymPojR/Qqx 7op76iPqRZMyvNSjyJHO8k48C3GSMfGKAFGpKOzk4fgr85B95lECaYv1Zfgk6N7Qpnyv 7rnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=pW8KhGNg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si2266040edv.420.2020.05.16.14.54.55; Sat, 16 May 2020 14:55:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=pW8KhGNg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727039AbgEPVwg (ORCPT + 99 others); Sat, 16 May 2020 17:52:36 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:47632 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726670AbgEPVwf (ORCPT ); Sat, 16 May 2020 17:52:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1589665880; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1QAI1+lygs7RukytrBDJiA7TI+zQ9n1V3xrM8AumWXA=; b=pW8KhGNg2rkDX1s29kn2kWNFzAz/EL5hkHf9wAq8EKRiTrtfWRgFlMRtqu2efZswBjpD2T ybuuGoyx2mVCBaE3Ja/nPkWhpavKAcyXRTMz5Zne49El86/ZpNtEA2iSEzw0IqZUMrnRnh 79fDnXjNmE78d5GF0L7rj5KtG9BI/H4= From: Paul Cercueil To: David Airlie , Daniel Vetter , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: od@zcrc.me, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH 12/12] gpu/drm: Ingenic: Support multiple panels/bridges Date: Sat, 16 May 2020 23:50:57 +0200 Message-Id: <20200516215057.392609-12-paul@crapouillou.net> In-Reply-To: <20200516215057.392609-1-paul@crapouillou.net> References: <20200516215057.392609-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support multiple panels or bridges connected to the same DPI output of the SoC. This setup can be found for instance on the GCW Zero, where the same DPI output interfaces the internal 320x240 TFT panel, and the ITE IT6610 HDMI chip. Signed-off-by: Paul Cercueil --- drivers/gpu/drm/ingenic/ingenic-drm.c | 74 ++++++++++++++++----------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/ingenic/ingenic-drm.c b/drivers/gpu/drm/ingenic/ingenic-drm.c index ad1cec4f2a4d..091e3d3c9027 100644 --- a/drivers/gpu/drm/ingenic/ingenic-drm.c +++ b/drivers/gpu/drm/ingenic/ingenic-drm.c @@ -52,7 +52,6 @@ struct ingenic_drm { struct drm_device drm; struct drm_plane f0, f1, *ipu_plane; struct drm_crtc crtc; - struct drm_encoder encoder; struct device *dev; struct regmap *map; @@ -106,12 +105,6 @@ static inline struct ingenic_drm *drm_crtc_get_priv(struct drm_crtc *crtc) return container_of(crtc, struct ingenic_drm, crtc); } -static inline struct ingenic_drm * -drm_encoder_get_priv(struct drm_encoder *encoder) -{ - return container_of(encoder, struct ingenic_drm, encoder); -} - static void ingenic_drm_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_crtc_state *state) { @@ -456,7 +449,7 @@ static void ingenic_drm_encoder_atomic_mode_set(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { - struct ingenic_drm *priv = drm_encoder_get_priv(encoder); + struct ingenic_drm *priv = drm_device_get_priv(encoder->dev); struct drm_display_mode *mode = &crtc_state->adjusted_mode; struct drm_connector *conn = conn_state->connector; struct drm_display_info *info = &conn->display_info; @@ -670,9 +663,11 @@ static int ingenic_drm_bind(struct device *dev) struct clk *parent_clk; struct drm_bridge *bridge; struct drm_panel *panel; + struct drm_encoder *encoder; struct drm_device *drm; void __iomem *base; long parent_rate; + unsigned int i, clone_mask = 0; int ret, irq; soc_info = of_device_get_match_data(dev); @@ -744,17 +739,6 @@ static int ingenic_drm_bind(struct device *dev) return PTR_ERR(priv->pix_clk); } - ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &panel, &bridge); - if (ret) { - if (ret != -EPROBE_DEFER) - dev_err(dev, "Failed to get panel handle"); - return ret; - } - - if (panel) - bridge = devm_drm_panel_bridge_add_typed(dev, panel, - DRM_MODE_CONNECTOR_DPI); - priv->dma_hwdesc[0] = dma_alloc_coherent(dev, sizeof(*priv->dma_hwdesc[0]), &priv->dma_hwdesc_phys[0], @@ -821,22 +805,50 @@ static int ingenic_drm_bind(struct device *dev) } } - priv->encoder.possible_crtcs = 1; + for (i = 0; ; i++) { + ret = drm_of_find_panel_or_bridge(dev->of_node, 0, i, + &panel, &bridge); + if (ret) { + if (ret == -ENODEV) + break; /* we're done */ + if (ret != -EPROBE_DEFER) + dev_err(dev, "Failed to get bridge handle\n"); + return ret; + } - drm_encoder_helper_add(&priv->encoder, - &ingenic_drm_encoder_helper_funcs); + if (panel) + bridge = devm_drm_panel_bridge_add_typed(dev, panel, + DRM_MODE_CONNECTOR_DPI); - ret = drm_simple_encoder_init(drm, &priv->encoder, - DRM_MODE_ENCODER_DPI); - if (ret) { - dev_err(dev, "Failed to init encoder: %i", ret); - return ret; + encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL); + if (!encoder) + return -ENOMEM; + + encoder->possible_crtcs = 1; + + drm_encoder_helper_add(encoder, + &ingenic_drm_encoder_helper_funcs); + + ret = drm_simple_encoder_init(drm, encoder, + DRM_MODE_ENCODER_DPI); + if (ret) { + dev_err(dev, "Failed to init encoder: %d\n", ret); + return ret; + } + + ret = drm_bridge_attach(encoder, bridge, NULL, 0); + if (ret) { + dev_err(dev, "Unable to attach bridge"); + return ret; + } } - ret = drm_bridge_attach(&priv->encoder, bridge, NULL, 0); - if (ret) { - dev_err(dev, "Unable to attach bridge"); - return ret; + drm_for_each_encoder(encoder, drm) { + clone_mask |= BIT(drm_encoder_index(encoder)); + } + + drm_for_each_encoder(encoder, drm) { + encoder->possible_clones = clone_mask; } ret = drm_irq_install(drm, irq); -- 2.26.2