1 From 9ff3c9d6063c6464e243b85bbbbd03e2096a57c0 Mon Sep 17 00:00:00 2001
2 From: Sandor Yu <Sandor.yu@nxp.com>
3 Date: Mon, 28 Oct 2019 17:07:06 +0800
4 Subject: [PATCH] drm: mhdp: reset video mode after hdmi/dp cable plugin
6 DP need setup link training, and HDMI need reset hdmi sink SCDC
7 status after cable reconnected.
8 Add video mode_set function when cable plugin.
9 Add 20ms/50ms delay for hdmi/dp to waite FW stable.
11 Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
13 drivers/gpu/drm/bridge/cadence/cdns-dp-core.c | 20 ++++----
14 drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c | 63 ++++++++++++-------------
15 2 files changed, 43 insertions(+), 40 deletions(-)
17 --- a/drivers/gpu/drm/bridge/cadence/cdns-dp-core.c
18 +++ b/drivers/gpu/drm/bridge/cadence/cdns-dp-core.c
19 @@ -108,19 +108,19 @@ static void dp_pixel_clk_reset(struct cd
20 cdns_mhdp_reg_write(mhdp, SOURCE_HDTX_CAR, val);
23 -static void cdns_dp_mode_set(struct cdns_mhdp_device *mhdp,
24 - const struct drm_display_mode *mode)
25 +static void cdns_dp_mode_set(struct cdns_mhdp_device *mhdp)
27 u32 lane_mapping = mhdp->lane_mapping;
28 struct drm_dp_link *link = &mhdp->dp.link;
32 - memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode));
33 + cdns_mhdp_plat_call(mhdp, pclk_rate);
35 - dp_pixel_clk_reset(mhdp);
36 + /* delay for DP FW stable after pixel clock relock */
39 - cdns_mhdp_plat_call(mhdp, pclk_rate);
40 + dp_pixel_clk_reset(mhdp);
42 ret = drm_dp_downstream_id(&mhdp->dp.aux, linkid);
44 @@ -330,11 +330,10 @@ static void cdns_dp_bridge_mode_set(stru
45 video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC);
47 DRM_INFO("Mode: %dx%dp%d\n", mode->hdisplay, mode->vdisplay, mode->clock);
48 + memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode));
50 mutex_lock(&mhdp->lock);
52 - cdns_dp_mode_set(mhdp, mode);
54 + cdns_dp_mode_set(mhdp);
55 mutex_unlock(&mhdp->lock);
58 @@ -367,6 +366,11 @@ static void hotplug_work_func(struct wor
59 drm_helper_hpd_irq_event(connector->dev);
61 if (connector->status == connector_status_connected) {
62 + /* reset video mode after cable plugin */
63 + mutex_lock(&mhdp->lock);
64 + cdns_dp_mode_set(mhdp);
65 + mutex_unlock(&mhdp->lock);
67 DRM_INFO("HDMI/DP Cable Plug In\n");
68 enable_irq(mhdp->irq[IRQ_OUT]);
69 } else if (connector->status == connector_status_disconnected) {
70 --- a/drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c
71 +++ b/drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c
74 #include <drm/bridge/cdns-mhdp-common.h>
75 #include <drm/drm_atomic_helper.h>
76 -#include <drm/drm_crtc_helper.h>
77 #include <drm/drm_edid.h>
78 #include <drm/drm_encoder_slave.h>
79 #include <drm/drm_of.h>
80 #include <drm/drm_probe_helper.h>
81 +#include <drm/drm_scdc_helper.h>
83 #include <linux/delay.h>
84 #include <linux/err.h>
86 #include <linux/mutex.h>
87 #include <linux/of_device.h>
89 -static int hdmi_sink_config(struct cdns_mhdp_device *mhdp)
90 +static void hdmi_sink_config(struct cdns_mhdp_device *mhdp)
92 struct drm_scdc *scdc = &mhdp->connector.base.display_info.hdmi.scdc;
96 + /* check sink support SCDC or not */
97 + if (scdc->supported != true) {
98 + DRM_INFO("Sink Not Support SCDC\n");
102 if (mhdp->hdmi.char_rate > 340000) {
104 * TMDS Character Rate above 340MHz should working in HDMI2.0
105 * Enable scrambling and TMDS_Bit_Clock_Ratio
108 + buff = SCDC_TMDS_BIT_CLOCK_RATIO_BY_40 | SCDC_SCRAMBLING_ENABLE;
109 mhdp->hdmi.hdmi_type = MODE_HDMI_2_0;
110 } else if (scdc->scrambling.low_rates) {
112 * Enable scrambling and HDMI2.0 when scrambling capability of sink
113 * be indicated in the HF-VSDB LTE_340Mcsc_scramble bit
116 + buff = SCDC_SCRAMBLING_ENABLE;
117 mhdp->hdmi.hdmi_type = MODE_HDMI_2_0;
119 /* Default work in HDMI1.4 */
120 @@ -53,8 +58,7 @@ static int hdmi_sink_config(struct cdns_
124 - ret = cdns_hdmi_scdc_write(mhdp, 0x20, buff);
126 + cdns_hdmi_scdc_write(mhdp, 0x20, buff);
129 static void hdmi_lanes_config(struct cdns_mhdp_device *mhdp)
130 @@ -142,7 +146,7 @@ static int hdmi_avi_info_set(struct cdns
134 -static int hdmi_vendor_info_set(struct cdns_mhdp_device *mhdp,
135 +static void hdmi_vendor_info_set(struct cdns_mhdp_device *mhdp,
136 struct drm_display_mode *mode)
138 struct hdmi_vendor_infoframe frame;
139 @@ -152,19 +156,18 @@ static int hdmi_vendor_info_set(struct c
140 /* Initialise vendor frame from DRM mode */
141 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame, &mhdp->connector.base, mode);
143 - DRM_WARN("Unable to init vendor infoframe: %d\n", ret);
145 + DRM_INFO("No vendor infoframe\n");
149 ret = hdmi_vendor_infoframe_pack(&frame, buf + 1, sizeof(buf) - 1);
151 DRM_WARN("Unable to pack vendor infoframe: %d\n", ret);
157 cdns_mhdp_infoframe_set(mhdp, 3, sizeof(buf), buf, HDMI_INFOFRAME_TYPE_VENDOR);
161 void cdns_hdmi_mode_set(struct cdns_mhdp_device *mhdp)
162 @@ -172,9 +175,16 @@ void cdns_hdmi_mode_set(struct cdns_mhdp
163 struct drm_display_mode *mode = &mhdp->mode;
166 - ret = hdmi_sink_config(mhdp);
168 - DRM_DEBUG("%s failed\n", __func__);
169 + hdmi_lanes_config(mhdp);
171 + cdns_mhdp_plat_call(mhdp, pclk_rate);
173 + /* delay for HDMI FW stable after pixel clock relock */
176 + cdns_mhdp_plat_call(mhdp, phy_set);
178 + hdmi_sink_config(mhdp);
180 ret = cdns_hdmi_ctrl_init(mhdp, mhdp->hdmi.hdmi_type, mhdp->hdmi.char_rate);
182 @@ -195,18 +205,13 @@ void cdns_hdmi_mode_set(struct cdns_mhdp
185 /* vendor info frame is enable only when HDMI1.4 4K mode */
186 - ret = hdmi_vendor_info_set(mhdp, mode);
188 - DRM_WARN("Unable to configure Vendor infoframe\n");
189 + hdmi_vendor_info_set(mhdp, mode);
191 ret = cdns_hdmi_mode_config(mhdp, mode, &mhdp->video_info);
193 DRM_ERROR("CDN_API_HDMITX_SetVic_blocking ret = %d\n", ret);
197 - /* wait HDMI PHY pixel clock stable */
201 static enum drm_connector_status
202 @@ -335,20 +340,11 @@ static void cdns_hdmi_bridge_mode_set(st
203 video->v_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NVSYNC);
204 video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC);
206 - mutex_lock(&mhdp->lock);
208 DRM_INFO("Mode: %dx%dp%d\n", mode->hdisplay, mode->vdisplay, mode->clock);
210 memcpy(&mhdp->mode, mode, sizeof(struct drm_display_mode));
212 - hdmi_lanes_config(mhdp);
214 - cdns_mhdp_plat_call(mhdp, pclk_rate);
216 - cdns_mhdp_plat_call(mhdp, phy_set);
218 + mutex_lock(&mhdp->lock);
219 cdns_hdmi_mode_set(mhdp);
221 mutex_unlock(&mhdp->lock);
224 @@ -367,8 +363,11 @@ static void hotplug_work_func(struct wor
225 drm_helper_hpd_irq_event(connector->dev);
227 if (connector->status == connector_status_connected) {
228 - /* Cable Connected */
229 DRM_INFO("HDMI Cable Plug In\n");
230 + /* reset video mode after cable plugin */
231 + mutex_lock(&mhdp->lock);
232 + cdns_hdmi_mode_set(mhdp);
233 + mutex_unlock(&mhdp->lock);
234 enable_irq(mhdp->irq[IRQ_OUT]);
235 } else if (connector->status == connector_status_disconnected) {
236 /* Cable Disconnedted */