Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1026689ybb; Wed, 8 Apr 2020 14:58:21 -0700 (PDT) X-Google-Smtp-Source: APiQypJd2taJzNccWdYRp3cG+SyZaXLtvmO7auYy/PiGqwpqK63TGt4EBeAOx0252IjfYtzEObKA X-Received: by 2002:a4a:dbc7:: with SMTP id t7mr2012757oou.57.1586383101278; Wed, 08 Apr 2020 14:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586383101; cv=none; d=google.com; s=arc-20160816; b=G6vaD8Kw+EYUl1CFliCHyGsTUp2nSWaKjUSyWXELMn3ZyYp461VaTllBuxlkaVvTAD A2JwRG4VMhIxeLwHLxMwGdoctYWs1wyWisbeJRW0gKDDeCUgQP65S8Gn0GQs1Bc5bPID AZvU4p6IdoWvmj7d14M9F5Dlc0sTk8gc75msFRi1znfhLFdYguj8uk49zBj2LB9Bd5lu X54fbrx8wyCLNbKpoMoJlWKLllVAGUSl6xq0Ts0zwJU5W7Ik+pTN9+j7kwXknMGDfc12 Vp8QtMZ8FaUHEmEFQYN0hU9z6fD/Lj5a6tKyddHWCTcfCgCiQ9yvTntI594p8MOjOOzy KLEQ== 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=TPtsRtoR/FqlRGT6MCrotnb+50oKBAwpuanBdxP+0f8=; b=Lr0Vt9aVW5HPV1Cqp9kdiz/q4ACgqJDiOxrzbQWAfqrPsgKW8s0bWJCfPph5/+ciTV QY1YP86n2m2kxN6y2paR+OiigdtcKBtKgyt2Hn5MGDgaFkw449sNlPKEYEtcdFdepTKg Yis68WONL/xGoRdKEnaqh1y60uLm/toG8d4pSRXP2sLkX7yMDwH2cvS94IHi7ZolbDn9 7RmyAqp0yROeitd0BWO/SpyzS13ULqCxOz3RTcxgPaYIwdU34Gvfd4mXTzqqy4JERqwS K4LHbMUAM1CRJYrRu8YQOzlPW3rpqTHSodev+kupn9+NnwJEVwWW1NhkCSyRg9rHKfFL eMMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id l6si3322560otn.219.2020.04.08.14.58.09; Wed, 08 Apr 2020 14:58:21 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1730151AbgDHVLo (ORCPT + 99 others); Wed, 8 Apr 2020 17:11:44 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:57376 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730089AbgDHVLl (ORCPT ); Wed, 8 Apr 2020 17:11:41 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 4B3A629747E From: Enric Balletbo i Serra To: linux-kernel@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, Collabora Kernel ML , matthias.bgg@gmail.com, drinkcat@chromium.org, hsinyi@chromium.org, 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 6/7] drm/mediatek: mtk_dsi: Use the drm_panel_bridge API Date: Wed, 8 Apr 2020 23:11:19 +0200 Message-Id: <20200408211120.1407512-7-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200408211120.1407512-1-enric.balletbo@collabora.com> References: <20200408211120.1407512-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 Replace the manual panel handling code by a drm_panel_bridge. This simplifies the driver and allows all components in the display pipeline to be treated as bridges, paving the way to generic connector handling. Signed-off-by: Enric Balletbo i Serra --- drivers/gpu/drm/mediatek/mtk_dsi.c | 178 ++++------------------------- 1 file changed, 20 insertions(+), 158 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c index 48361c1e9f34..f9706f306275 100644 --- a/drivers/gpu/drm/mediatek/mtk_dsi.c +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c @@ -182,8 +182,7 @@ struct mtk_dsi { struct mipi_dsi_host host; struct drm_encoder encoder; struct drm_bridge bridge; - struct drm_connector conn; - struct drm_panel *panel; + struct drm_bridge *panel_bridge; struct drm_bridge *next_bridge; struct phy *phy; @@ -212,11 +211,6 @@ static inline struct mtk_dsi *bridge_to_dsi(struct drm_bridge *b) return container_of(b, struct mtk_dsi, bridge); } -static inline struct mtk_dsi *connector_to_dsi(struct drm_connector *c) -{ - return container_of(c, struct mtk_dsi, conn); -} - static inline struct mtk_dsi *host_to_dsi(struct mipi_dsi_host *h) { return container_of(h, struct mtk_dsi, host); @@ -682,16 +676,7 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi) mtk_dsi_lane0_ulp_mode_leave(dsi); mtk_dsi_clk_hs_mode(dsi, 0); - if (dsi->panel) { - if (drm_panel_prepare(dsi->panel)) { - DRM_ERROR("failed to prepare the panel\n"); - goto err_disable_digital_clk; - } - } - return 0; -err_disable_digital_clk: - clk_disable_unprepare(dsi->digital_clk); err_disable_engine_clk: clk_disable_unprepare(dsi->engine_clk); err_phy_power_off: @@ -718,15 +703,7 @@ static void mtk_dsi_poweroff(struct mtk_dsi *dsi) */ mtk_dsi_stop(dsi); - if (!mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500)) { - if (dsi->panel) { - if (drm_panel_unprepare(dsi->panel)) { - DRM_ERROR("failed to unprepare the panel\n"); - return; - } - } - } - + mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500); mtk_dsi_reset_engine(dsi); mtk_dsi_lane0_ulp_mode_enter(dsi); mtk_dsi_clk_ulp_mode_enter(dsi); @@ -757,19 +734,7 @@ static void mtk_output_dsi_enable(struct mtk_dsi *dsi) mtk_dsi_start(dsi); - if (dsi->panel) { - if (drm_panel_enable(dsi->panel)) { - DRM_ERROR("failed to enable the panel\n"); - goto err_dsi_power_off; - } - } - dsi->enabled = true; - - return; -err_dsi_power_off: - mtk_dsi_stop(dsi); - mtk_dsi_poweroff(dsi); } static void mtk_output_dsi_disable(struct mtk_dsi *dsi) @@ -777,34 +742,24 @@ static void mtk_output_dsi_disable(struct mtk_dsi *dsi) if (!dsi->enabled) return; - if (dsi->panel) { - if (drm_panel_disable(dsi->panel)) { - DRM_ERROR("failed to disable the panel\n"); - return; - } - } - mtk_dsi_poweroff(dsi); dsi->enabled = false; } -static int mtk_dsi_create_conn_enc(struct drm_device *drm, struct mtk_dsi *dsi); -static void mtk_dsi_destroy_conn_enc(struct mtk_dsi *dsi); - static int mtk_dsi_bridge_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) { struct mtk_dsi *dsi = bridge_to_dsi(bridge); + struct drm_bridge *next; - return mtk_dsi_create_conn_enc(bridge->dev, dsi); -} - -static void mtk_dsi_bridge_detach(struct drm_bridge *bridge) -{ - struct mtk_dsi *dsi = bridge_to_dsi(bridge); + if (dsi->next_bridge) + next = dsi->next_bridge; + else + next = dsi->panel_bridge; - mtk_dsi_destroy_conn_enc(dsi); + /* Attach the panel or bridge to the dsi bridge */ + return drm_bridge_attach(bridge->encoder, next, &dsi->bridge, flags); } static void mtk_dsi_bridge_mode_set(struct drm_bridge *bridge, @@ -830,101 +785,13 @@ static void mtk_dsi_bridge_enable(struct drm_bridge *bridge) mtk_output_dsi_enable(dsi); } -static int mtk_dsi_connector_get_modes(struct drm_connector *connector) -{ - struct mtk_dsi *dsi = connector_to_dsi(connector); - - return drm_panel_get_modes(dsi->panel, connector); -} - static const struct drm_bridge_funcs mtk_dsi_bridge_funcs = { .attach = mtk_dsi_bridge_attach, - .detach = mtk_dsi_bridge_detach, .disable = mtk_dsi_bridge_disable, .enable = mtk_dsi_bridge_enable, .mode_set = mtk_dsi_bridge_mode_set, }; -static const struct drm_connector_funcs mtk_dsi_connector_funcs = { - .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, - .reset = drm_atomic_helper_connector_reset, - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, -}; - -static const struct drm_connector_helper_funcs - mtk_dsi_connector_helper_funcs = { - .get_modes = mtk_dsi_connector_get_modes, -}; - -static int mtk_dsi_create_connector(struct drm_device *drm, struct mtk_dsi *dsi) -{ - int ret; - - ret = drm_connector_init(drm, &dsi->conn, &mtk_dsi_connector_funcs, - DRM_MODE_CONNECTOR_DSI); - if (ret) { - DRM_ERROR("Failed to connector init to drm\n"); - return ret; - } - - drm_connector_helper_add(&dsi->conn, &mtk_dsi_connector_helper_funcs); - - dsi->conn.dpms = DRM_MODE_DPMS_OFF; - drm_connector_attach_encoder(&dsi->conn, &dsi->encoder); - - if (dsi->panel) { - ret = drm_panel_attach(dsi->panel, &dsi->conn); - if (ret) { - DRM_ERROR("Failed to attach panel to drm\n"); - goto err_connector_cleanup; - } - } - - return 0; - -err_connector_cleanup: - drm_connector_cleanup(&dsi->conn); - return ret; -} - -static int mtk_dsi_create_conn_enc(struct drm_device *drm, struct mtk_dsi *dsi) -{ - int ret; - - /* If there's a bridge, attach to it and let it create the connector */ - if (dsi->next_bridge) { - ret = drm_bridge_attach(&dsi->encoder, dsi->next_bridge, NULL, - 0); - if (ret) { - DRM_ERROR("Failed to attach bridge to drm\n"); - goto err_encoder_cleanup; - } - } else { - /* Otherwise create our own connector and attach to a panel */ - ret = mtk_dsi_create_connector(drm, dsi); - if (ret) - goto err_encoder_cleanup; - } - - return 0; - -err_encoder_cleanup: - drm_encoder_cleanup(&dsi->encoder); - return ret; -} - -static void mtk_dsi_destroy_conn_enc(struct mtk_dsi *dsi) -{ - drm_encoder_cleanup(&dsi->encoder); - /* Skip connector cleanup if creation was delegated to the bridge */ - if (dsi->conn.dev) - drm_connector_cleanup(&dsi->conn); - if (dsi->panel) - drm_panel_detach(dsi->panel); -} - static void mtk_dsi_ddp_start(struct mtk_ddp_comp *comp) { struct mtk_dsi *dsi = container_of(comp, struct mtk_dsi, ddp_comp); @@ -953,20 +820,6 @@ static int mtk_dsi_host_attach(struct mipi_dsi_host *host, dsi->format = device->format; dsi->mode_flags = device->mode_flags; - if (dsi->conn.dev) - drm_helper_hpd_irq_event(dsi->conn.dev); - - return 0; -} - -static int mtk_dsi_host_detach(struct mipi_dsi_host *host, - struct mipi_dsi_device *device) -{ - struct mtk_dsi *dsi = host_to_dsi(host); - - if (dsi->conn.dev) - drm_helper_hpd_irq_event(dsi->conn.dev); - return 0; } @@ -1110,7 +963,6 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host, static const struct mipi_dsi_host_ops mtk_dsi_ops = { .attach = mtk_dsi_host_attach, - .detach = mtk_dsi_host_detach, .transfer = mtk_dsi_host_transfer, }; @@ -1184,6 +1036,7 @@ static int mtk_dsi_probe(struct platform_device *pdev) { struct mtk_dsi *dsi; struct device *dev = &pdev->dev; + struct drm_panel *panel; struct resource *regs; int irq_num; int comp_id; @@ -1202,10 +1055,19 @@ static int mtk_dsi_probe(struct platform_device *pdev) } ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, - &dsi->panel, &dsi->next_bridge); + &panel, &dsi->next_bridge); if (ret) goto err_unregister_host; + if (panel) { + panel->connector_type = DRM_MODE_CONNECTOR_DSI; + dsi->panel_bridge = devm_drm_panel_bridge_add(dev, panel); + if (IS_ERR(dsi->panel_bridge)) { + ret = PTR_ERR(dsi->panel_bridge); + goto err_unregister_host; + } + } + dsi->driver_data = of_device_get_match_data(dev); dsi->engine_clk = devm_clk_get(dev, "engine"); -- 2.25.1