Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3893645ybz; Mon, 4 May 2020 11:39:32 -0700 (PDT) X-Google-Smtp-Source: APiQypI+jtqCeLQdYV2vNWoMFgXLazaHyIiIaHVZvoJYczJqRI60VcUqCvqlP+/AOYX8OuAgYbdv X-Received: by 2002:a17:906:35cd:: with SMTP id p13mr16765418ejb.206.1588617572139; Mon, 04 May 2020 11:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588617572; cv=none; d=google.com; s=arc-20160816; b=LlKGtVLggDFkAMpaNPqWhe0TT3pDr/pz5BXL2wYBAYsB/WNyd4wT2Ba0l83104GS31 Vuv7AwxB8yPMUiZeZvmzRGVV/DDSUo8a1WXo6JueTBenIgh3gUfQ/F85uxi7VSOn9v1d Y1Rrlx5PfEtXDV6IOjR1UnRgWWUoe1M/8/I5kRrlKZEiln/z5CncBARqrao0Q2cLB2ln Ir8uK7a4yUpMNMFox0Gti5MOBJFX+FQLFrGW7ov/v1pnkNyHFVEABDIU+QSefkBLqE1c qrwvAEGZe7bLsQT8ryCRZym+pEeXl5/W2NmZSl/oa9F71StZSt75HGNpiPaol2ugss5K 9fog== 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; bh=XAScWyJlbBQ8fyb5DZfhmjLbA1WLoiCXK/8Pyz8Q49Y=; b=suWa8l3GO+JQq39VDsl9QN5uCTcF4TkOQMFDgMHKxw0cfboddJpSuNODhHsS7/In5J NohiRlIeS3/zzBk4/o1t5LbWhRkq2krudlLJtPfRxHVBrfvpgDyq08YvPTtGJ0cTGj/g ul0vM2Ok0E1mDbwozDUM3HwMg7Dnv3QjkE8YN0jN/e1sAbf7q5Hy1vYQVbsMaX7X2wbz cn+/L+Y4VvL+KJRgXqOybvirP2HVaE7OPJ/GeWw+jVdehcG6Ef5b8TJAjo8Sr95fWVRp EcEi3DzRDM53HzITjJ1JVALbLt1jVPCZLcomhRtb0jeXT4u3p6nnMHcryMeTUKcDi3+0 YPcQ== ARC-Authentication-Results: i=1; mx.google.com; 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dx8si7355094ejb.6.2020.05.04.11.39.09; Mon, 04 May 2020 11:39:32 -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; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729017AbgEDOOU (ORCPT + 99 others); Mon, 4 May 2020 10:14:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728918AbgEDOOS (ORCPT ); Mon, 4 May 2020 10:14:18 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF29C061A0F for ; Mon, 4 May 2020 07:14:18 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 881642A131D From: Enric Balletbo i Serra To: linux-kernel@vger.kernel.org, Collabora Kernel ML Cc: matthias.bgg@gmail.com, drinkcat@chromium.org, hsinyi@chromium.org, laurent.pinchart@ideasonboard.com, Chun-Kuang Hu , Daniel Vetter , David Airlie , Philipp Zabel , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH 2/3] drm/mediatek: mtk_dpi: Convert to bridge driver Date: Mon, 4 May 2020 16:14:07 +0200 Message-Id: <20200504141408.60877-3-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200504141408.60877-1-enric.balletbo@collabora.com> References: <20200504141408.60877-1-enric.balletbo@collabora.com> 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 Convert mtk_dpi to a bridge driver with built-in encoder support for compatibility with existing component drivers. Signed-off-by: Enric Balletbo i Serra --- drivers/gpu/drm/mediatek/mtk_dpi.c | 66 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c b/drivers/gpu/drm/mediatek/mtk_dpi.c index 7112125dc3d1..baad198c69eb 100644 --- a/drivers/gpu/drm/mediatek/mtk_dpi.c +++ b/drivers/gpu/drm/mediatek/mtk_dpi.c @@ -61,6 +61,7 @@ enum mtk_dpi_out_color_format { struct mtk_dpi { struct mtk_ddp_comp ddp_comp; struct drm_encoder encoder; + struct drm_bridge bridge; struct drm_bridge *next_bridge; void __iomem *regs; struct device *dev; @@ -77,9 +78,9 @@ struct mtk_dpi { int refcount; }; -static inline struct mtk_dpi *mtk_dpi_from_encoder(struct drm_encoder *e) +static inline struct mtk_dpi *bridge_to_dpi(struct drm_bridge *b) { - return container_of(e, struct mtk_dpi, encoder); + return container_of(b, struct mtk_dpi, bridge); } enum mtk_dpi_polarity { @@ -518,50 +519,44 @@ static const struct drm_encoder_funcs mtk_dpi_encoder_funcs = { .destroy = mtk_dpi_encoder_destroy, }; -static bool mtk_dpi_encoder_mode_fixup(struct drm_encoder *encoder, - const struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) +static int mtk_dpi_bridge_attach(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) { - return true; + struct mtk_dpi *dpi = bridge_to_dpi(bridge); + + return drm_bridge_attach(bridge->encoder, dpi->next_bridge, + &dpi->bridge, flags); } -static void mtk_dpi_encoder_mode_set(struct drm_encoder *encoder, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) +static void mtk_dpi_bridge_mode_set(struct drm_bridge *bridge, + const struct drm_display_mode *mode, + const struct drm_display_mode *adjusted_mode) { - struct mtk_dpi *dpi = mtk_dpi_from_encoder(encoder); + struct mtk_dpi *dpi = bridge_to_dpi(bridge); drm_mode_copy(&dpi->mode, adjusted_mode); } -static void mtk_dpi_encoder_disable(struct drm_encoder *encoder) +static void mtk_dpi_bridge_disable(struct drm_bridge *bridge) { - struct mtk_dpi *dpi = mtk_dpi_from_encoder(encoder); + struct mtk_dpi *dpi = bridge_to_dpi(bridge); mtk_dpi_power_off(dpi); } -static void mtk_dpi_encoder_enable(struct drm_encoder *encoder) +static void mtk_dpi_bridge_enable(struct drm_bridge *bridge) { - struct mtk_dpi *dpi = mtk_dpi_from_encoder(encoder); + struct mtk_dpi *dpi = bridge_to_dpi(bridge); mtk_dpi_power_on(dpi); mtk_dpi_set_display_mode(dpi, &dpi->mode); } -static int mtk_dpi_atomic_check(struct drm_encoder *encoder, - struct drm_crtc_state *crtc_state, - struct drm_connector_state *conn_state) -{ - return 0; -} - -static const struct drm_encoder_helper_funcs mtk_dpi_encoder_helper_funcs = { - .mode_fixup = mtk_dpi_encoder_mode_fixup, - .mode_set = mtk_dpi_encoder_mode_set, - .disable = mtk_dpi_encoder_disable, - .enable = mtk_dpi_encoder_enable, - .atomic_check = mtk_dpi_atomic_check, +static const struct drm_bridge_funcs mtk_dpi_bridge_funcs = { + .attach = mtk_dpi_bridge_attach, + .mode_set = mtk_dpi_bridge_mode_set, + .disable = mtk_dpi_bridge_disable, + .enable = mtk_dpi_bridge_enable, }; static void mtk_dpi_start(struct mtk_ddp_comp *comp) @@ -602,16 +597,13 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data) dev_err(dev, "Failed to initialize decoder: %d\n", ret); goto err_unregister; } - drm_encoder_helper_add(&dpi->encoder, &mtk_dpi_encoder_helper_funcs); /* Currently DPI0 is fixed to be driven by OVL1 */ dpi->encoder.possible_crtcs = BIT(1); - ret = drm_bridge_attach(&dpi->encoder, dpi->next_bridge, NULL, 0); - if (ret) { - dev_err(dev, "Failed to attach bridge: %d\n", ret); + ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL, 0); + if (ret) goto err_cleanup; - } dpi->bit_num = MTK_DPI_OUT_BIT_NUM_8BITS; dpi->channel_swap = MTK_DPI_OUT_CHANNEL_SWAP_RGB; @@ -768,8 +760,15 @@ static int mtk_dpi_probe(struct platform_device *pdev) platform_set_drvdata(pdev, dpi); + dpi->bridge.funcs = &mtk_dpi_bridge_funcs; + dpi->bridge.of_node = dev->of_node; + dpi->bridge.type = DRM_MODE_CONNECTOR_DPI; + + drm_bridge_add(&dpi->bridge); + ret = component_add(dev, &mtk_dpi_component_ops); if (ret) { + drm_bridge_remove(&dpi->bridge); dev_err(dev, "Failed to add component: %d\n", ret); return ret; } @@ -779,7 +778,10 @@ static int mtk_dpi_probe(struct platform_device *pdev) static int mtk_dpi_remove(struct platform_device *pdev) { + struct mtk_dpi *dpi = platform_get_drvdata(pdev); + component_del(&pdev->dev, &mtk_dpi_component_ops); + drm_bridge_remove(&dpi->bridge); return 0; } -- 2.26.2