Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4285627pxf; Tue, 30 Mar 2021 04:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypAda+vN3bzY0snt2ttJwPOJHDATykkk0NvOsgMw4S7059SLU+hcoTJ6uSnBylxuG7Ix8r X-Received: by 2002:a05:6402:1c98:: with SMTP id cy24mr32838595edb.296.1617102654337; Tue, 30 Mar 2021 04:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617102654; cv=none; d=google.com; s=arc-20160816; b=k1Fo6BgbADKyJFPXT8P6YSg66wn0ymxpX8orRw5tlWRfc0YfEyR4x1yCn4AyUeqdN9 j89Sdwy8gzyHQr/dJYYiwm0WMN0MQRGMPZ43eITJF/8sfvUmFpxgkBVFJyTnui2pgtKr xwXnngDDSHbHBFrBDatIWgN/kPgLsfj7XzL9sscxE+NLWb0/0MuSG/wGZG+3CbNd0qoo jALX9QGTluBUpSRwwuq/OmVDA6nR1GS98Lb+TbGcmLSjwWC47SQfl7DS3ovh+MEUBGn7 UozOpGiHahxxII1xwAHMY0Rl1+w6I48wLO0jO59N90FmT7isfbCcnHgELtZ/DQrBPw5p MVQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=RKaZOTaXzp/Bd0RwbiqxzhjQ4TV1fTwWcKLf2nmjfnQ=; b=VUVDhrP3xVntR+WqroUSGn282/Y+y0gDV7QsWhouIQq/YZnog46XWAjHrp+j+ek4CM wdhmNlj9R0HXFRWuoYjZlmzYVybEVQ+0Wulr9O0/PA3D5s5MAMtNjNatEugHhl5G5eDc F1+If79VR0KL4vTrPtDhD8BXoithjscw+FP7OiMWsiAOfz3u0eJaASyH4ie5s92ycJNp bgOZtSKQ7cvEBvp0LA+JuFYD0A5rLawaHSLF8QU3+e5C16q7TRGMdGgX1PeMNdDjIn8r bpuS0Aow/pv20TGl948YexL1Q/LgnxJP81v2xVhOSaiHNDAjJV/wSgmbNDzhcjHAx0VO 2+IA== 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 gt5si14637846ejb.181.2021.03.30.04.10.30; Tue, 30 Mar 2021 04:10:54 -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 S231749AbhC3LJe (ORCPT + 99 others); Tue, 30 Mar 2021 07:09:34 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39814 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231574AbhC3LJM (ORCPT ); Tue, 30 Mar 2021 07:09:12 -0400 Received: from guri.fritz.box (unknown [IPv6:2a02:810a:880:f54:2d37:13aa:2f32:9c00]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id C251F1F45335; Tue, 30 Mar 2021 12:09:10 +0100 (BST) From: Dafna Hirschfeld To: dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, kernel@collabora.com, dafna3@gmail.com, chunkuang.hu@kernel.org, p.zabel@pengutronix.de, airlied@linux.ie, daniel@ffwll.ch, enric.balletbo@collabora.com, laurent.pinchart@ideasonboard.com Subject: [PATCH v3 2/2] drm/mediatek: Don't support hdmi connector creation Date: Tue, 30 Mar 2021 13:09:02 +0200 Message-Id: <20210330110902.14178-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210330110902.14178-1-dafna.hirschfeld@collabora.com> References: <20210330110902.14178-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit f01195148967 ("drm/mediatek: mtk_dpi: Create connector for bridges") broke the display support for elm device since mtk_dpi calls drm_bridge_attach with the flag DRM_BRIDGE_ATTACH_NO_CONNECTOR while mtk_hdmi does not yet support this flag. Fix this by accepting DRM_BRIDGE_ATTACH_NO_CONNECTOR in bridge attachment. Implement the drm_bridge_funcs .detect() and .get_edid() operations, and call drm_bridge_hpd_notify() to report HPD. This provides the necessary API to support disabling connector creation. In addition, the field 'conn' is removed from the mtk_hdmi struct since mtk_hdmi don't create a connector. It is replaced with a pointer 'curr_conn' that points to the current connector which can be access through the global state. This patch is inspired by a similar patch for bridge/synopsys/dw-hdmi.c: commit ec971aaa6775 ("drm: bridge: dw-hdmi: Make connector creation optional") But with the difference that in mtk-hdmi only the option of not creating a connector is supported. Fixes: f01195148967 ("drm/mediatek: mtk_dpi: Create connector for bridges") Signed-off-by: Dafna Hirschfeld Reviewed-by: Laurent Pinchart --- drivers/gpu/drm/mediatek/mtk_hdmi.c | 151 +++++++++++----------------- 1 file changed, 56 insertions(+), 95 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index f2c810b767ef..7fb358167f8d 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -153,7 +153,7 @@ struct mtk_hdmi_conf { struct mtk_hdmi { struct drm_bridge bridge; struct drm_bridge *next_bridge; - struct drm_connector conn; + struct drm_connector *curr_conn;/* current connector (only valid when 'enabled') */ struct device *dev; const struct mtk_hdmi_conf *conf; struct phy *phy; @@ -186,11 +186,6 @@ static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b) return container_of(b, struct mtk_hdmi, bridge); } -static inline struct mtk_hdmi *hdmi_ctx_from_conn(struct drm_connector *c) -{ - return container_of(c, struct mtk_hdmi, conn); -} - static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset) { return readl(hdmi->regs + offset); @@ -974,7 +969,7 @@ static int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, ssize_t err; err = drm_hdmi_avi_infoframe_from_display_mode(&frame, - &hdmi->conn, mode); + hdmi->curr_conn, mode); if (err < 0) { dev_err(hdmi->dev, "Failed to get AVI infoframe from mode: %zd\n", err); @@ -1054,7 +1049,7 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi, ssize_t err; err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, - &hdmi->conn, mode); + hdmi->curr_conn, mode); if (err) { dev_err(hdmi->dev, "Failed to get vendor infoframe from mode: %zd\n", err); @@ -1201,48 +1196,16 @@ mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi) connector_status_connected : connector_status_disconnected; } -static enum drm_connector_status hdmi_conn_detect(struct drm_connector *conn, - bool force) +static enum drm_connector_status mtk_hdmi_detect(struct mtk_hdmi *hdmi) { - struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); return mtk_hdmi_update_plugged_status(hdmi); } -static void hdmi_conn_destroy(struct drm_connector *conn) -{ - struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); - - mtk_cec_set_hpd_event(hdmi->cec_dev, NULL, NULL); - - drm_connector_cleanup(conn); -} - -static int mtk_hdmi_conn_get_modes(struct drm_connector *conn) -{ - struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); - struct edid *edid; - int ret; - - if (!hdmi->ddc_adpt) - return -ENODEV; - - edid = drm_get_edid(conn, hdmi->ddc_adpt); - if (!edid) - return -ENODEV; - - hdmi->dvi_mode = !drm_detect_monitor_audio(edid); - - drm_connector_update_edid_property(conn, edid); - - ret = drm_add_edid_modes(conn, edid); - kfree(edid); - return ret; -} - -static int mtk_hdmi_conn_mode_valid(struct drm_connector *conn, - struct drm_display_mode *mode) +static int mtk_hdmi_bridge_mode_valid(struct drm_bridge *bridge, + const struct drm_display_info *info, + const struct drm_display_mode *mode) { - struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); + struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); struct drm_bridge *next_bridge; dev_dbg(hdmi->dev, "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n", @@ -1267,74 +1230,57 @@ static int mtk_hdmi_conn_mode_valid(struct drm_connector *conn, return drm_mode_validate_size(mode, 0x1fff, 0x1fff); } -static struct drm_encoder *mtk_hdmi_conn_best_enc(struct drm_connector *conn) -{ - struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); - - return hdmi->bridge.encoder; -} - -static const struct drm_connector_funcs mtk_hdmi_connector_funcs = { - .detect = hdmi_conn_detect, - .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = hdmi_conn_destroy, - .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_hdmi_connector_helper_funcs = { - .get_modes = mtk_hdmi_conn_get_modes, - .mode_valid = mtk_hdmi_conn_mode_valid, - .best_encoder = mtk_hdmi_conn_best_enc, -}; - static void mtk_hdmi_hpd_event(bool hpd, struct device *dev) { struct mtk_hdmi *hdmi = dev_get_drvdata(dev); - if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev) + if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev) { + static enum drm_connector_status status; + + status = mtk_hdmi_detect(hdmi); drm_helper_hpd_irq_event(hdmi->bridge.encoder->dev); + drm_bridge_hpd_notify(&hdmi->bridge, status); + } } /* * Bridge callbacks */ +static enum drm_connector_status mtk_hdmi_bridge_detect(struct drm_bridge *bridge) +{ + struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); + + return mtk_hdmi_detect(hdmi); +} + +static struct edid *mtk_hdmi_bridge_get_edid(struct drm_bridge *bridge, + struct drm_connector *connector) +{ + struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); + struct edid *edid; + + if (!hdmi->ddc_adpt) + return NULL; + edid = drm_get_edid(connector, hdmi->ddc_adpt); + if (!edid) + return NULL; + hdmi->dvi_mode = !drm_detect_monitor_audio(edid); + return edid; +} + static int mtk_hdmi_bridge_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) { struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); int ret; - if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) { - DRM_ERROR("Fix bridge driver to make connector optional!"); + if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) { + DRM_ERROR("%s: The flag DRM_BRIDGE_ATTACH_NO_CONNECTOR must be supplied\n", + __func__); return -EINVAL; } - ret = drm_connector_init_with_ddc(bridge->encoder->dev, &hdmi->conn, - &mtk_hdmi_connector_funcs, - DRM_MODE_CONNECTOR_HDMIA, - hdmi->ddc_adpt); - if (ret) { - dev_err(hdmi->dev, "Failed to initialize connector: %d\n", ret); - return ret; - } - drm_connector_helper_add(&hdmi->conn, &mtk_hdmi_connector_helper_funcs); - - hdmi->conn.polled = DRM_CONNECTOR_POLL_HPD; - hdmi->conn.interlace_allowed = true; - hdmi->conn.doublescan_allowed = false; - - ret = drm_connector_attach_encoder(&hdmi->conn, - bridge->encoder); - if (ret) { - dev_err(hdmi->dev, - "Failed to attach connector to encoder: %d\n", ret); - return ret; - } - if (hdmi->next_bridge) { ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge, bridge, flags); @@ -1369,6 +1315,8 @@ static void mtk_hdmi_bridge_atomic_disable(struct drm_bridge *bridge, clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); + hdmi->curr_conn = NULL; + hdmi->enabled = false; } @@ -1432,8 +1380,13 @@ static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi, static void mtk_hdmi_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_bridge_state *old_state) { + struct drm_atomic_state *state = old_state->base.state; struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); + /* Retrieve the connector through the atomic state. */ + hdmi->curr_conn = drm_atomic_get_new_connector_for_encoder(state, + bridge->encoder); + mtk_hdmi_output_set_display_mode(hdmi, &hdmi->mode); clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); @@ -1444,6 +1397,7 @@ static void mtk_hdmi_bridge_atomic_enable(struct drm_bridge *bridge, } static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = { + .mode_valid = mtk_hdmi_bridge_mode_valid, .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, .atomic_reset = drm_atomic_helper_bridge_reset, @@ -1454,6 +1408,8 @@ static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = { .mode_set = mtk_hdmi_bridge_mode_set, .atomic_pre_enable = mtk_hdmi_bridge_atomic_pre_enable, .atomic_enable = mtk_hdmi_bridge_atomic_enable, + .detect = mtk_hdmi_bridge_detect, + .get_edid = mtk_hdmi_bridge_get_edid, }; static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, @@ -1669,8 +1625,10 @@ static int mtk_hdmi_audio_get_eld(struct device *dev, void *data, uint8_t *buf, { struct mtk_hdmi *hdmi = dev_get_drvdata(dev); - memcpy(buf, hdmi->conn.eld, min(sizeof(hdmi->conn.eld), len)); - + if (hdmi->enabled) + memcpy(buf, hdmi->curr_conn->eld, min(sizeof(hdmi->curr_conn->eld), len)); + else + memset(buf, 0, len); return 0; } @@ -1762,6 +1720,9 @@ static int mtk_drm_hdmi_probe(struct platform_device *pdev) hdmi->bridge.funcs = &mtk_hdmi_bridge_funcs; hdmi->bridge.of_node = pdev->dev.of_node; + hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID + | DRM_BRIDGE_OP_HPD; + hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA; drm_bridge_add(&hdmi->bridge); ret = mtk_hdmi_clk_enable_audio(hdmi); -- 2.17.1