1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
6 #include <linux/module.h>
7 #include <linux/slab.h>
8 #include <linux/uaccess.h>
9 #include <linux/debugfs.h>
10 #include <linux/component.h>
11 #include <linux/of_irq.h>
12 #include <linux/phy/phy.h>
13 #include <linux/delay.h>
14 #include <drm/display/drm_dp_aux_bus.h>
15 #include <drm/drm_edid.h>
20 #include "dp_catalog.h"
25 #include "dp_display.h"
30 static bool psr_enabled = false;
31 module_param(psr_enabled, bool, 0);
32 MODULE_PARM_DESC(psr_enabled, "enable PSR for eDP and DP displays");
34 #define HPD_STRING_SIZE 30
41 ISR_IRQ_HPD_PULSE_COUNT,
42 ISR_HPD_LO_GLITH_COUNT,
45 /* event thread connection state */
50 ST_DISCONNECT_PENDING,
63 #define EVENT_TIMEOUT (HZ/10) /* 100ms */
64 #define DP_EVENT_Q_MAX 8
66 #define DP_TIMEOUT_NONE 0
68 #define WAIT_FOR_RESUME_TIMEOUT_JIFFIES (HZ / 2)
76 struct msm_dp_display_private {
82 bool core_initialized;
86 struct drm_device *drm_dev;
88 struct msm_dp_catalog *catalog;
89 struct drm_dp_aux *aux;
90 struct msm_dp_link *link;
91 struct msm_dp_panel *panel;
92 struct msm_dp_ctrl *ctrl;
94 struct msm_dp_display_mode msm_dp_mode;
95 struct msm_dp msm_dp_display;
97 /* wait for audio signaling */
98 struct completion audio_comp;
100 /* event related only access by event thread */
101 struct mutex event_mutex;
102 wait_queue_head_t event_q;
106 struct task_struct *ev_tsk;
107 struct msm_dp_event event_list[DP_EVENT_Q_MAX];
108 spinlock_t event_lock;
110 bool wide_bus_supported;
112 struct msm_dp_audio *audio;
116 phys_addr_t io_start;
118 bool wide_bus_supported;
121 static const struct msm_dp_desc msm_dp_desc_sa8775p[] = {
122 { .io_start = 0x0af54000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
123 { .io_start = 0x0af5c000, .id = MSM_DP_CONTROLLER_1, .wide_bus_supported = true },
124 { .io_start = 0x22154000, .id = MSM_DP_CONTROLLER_2, .wide_bus_supported = true },
125 { .io_start = 0x2215c000, .id = MSM_DP_CONTROLLER_3, .wide_bus_supported = true },
129 static const struct msm_dp_desc msm_dp_desc_sc7180[] = {
130 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
134 static const struct msm_dp_desc msm_dp_desc_sc7280[] = {
135 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
136 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_1, .wide_bus_supported = true },
140 static const struct msm_dp_desc msm_dp_desc_sc8180x[] = {
141 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
142 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .wide_bus_supported = true },
143 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .wide_bus_supported = true },
147 static const struct msm_dp_desc msm_dp_desc_sc8280xp[] = {
148 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
149 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .wide_bus_supported = true },
150 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .wide_bus_supported = true },
151 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_3, .wide_bus_supported = true },
152 { .io_start = 0x22090000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
153 { .io_start = 0x22098000, .id = MSM_DP_CONTROLLER_1, .wide_bus_supported = true },
154 { .io_start = 0x2209a000, .id = MSM_DP_CONTROLLER_2, .wide_bus_supported = true },
155 { .io_start = 0x220a0000, .id = MSM_DP_CONTROLLER_3, .wide_bus_supported = true },
159 static const struct msm_dp_desc msm_dp_desc_sm8650[] = {
160 { .io_start = 0x0af54000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
164 static const struct msm_dp_desc msm_dp_desc_x1e80100[] = {
165 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .wide_bus_supported = true },
166 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .wide_bus_supported = true },
167 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .wide_bus_supported = true },
168 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_3, .wide_bus_supported = true },
172 static const struct of_device_id msm_dp_dt_match[] = {
173 { .compatible = "qcom,sa8775p-dp", .data = &msm_dp_desc_sa8775p },
174 { .compatible = "qcom,sc7180-dp", .data = &msm_dp_desc_sc7180 },
175 { .compatible = "qcom,sc7280-dp", .data = &msm_dp_desc_sc7280 },
176 { .compatible = "qcom,sc7280-edp", .data = &msm_dp_desc_sc7280 },
177 { .compatible = "qcom,sc8180x-dp", .data = &msm_dp_desc_sc8180x },
178 { .compatible = "qcom,sc8180x-edp", .data = &msm_dp_desc_sc8180x },
179 { .compatible = "qcom,sc8280xp-dp", .data = &msm_dp_desc_sc8280xp },
180 { .compatible = "qcom,sc8280xp-edp", .data = &msm_dp_desc_sc8280xp },
181 { .compatible = "qcom,sdm845-dp", .data = &msm_dp_desc_sc7180 },
182 { .compatible = "qcom,sm8350-dp", .data = &msm_dp_desc_sc7180 },
183 { .compatible = "qcom,sm8650-dp", .data = &msm_dp_desc_sm8650 },
184 { .compatible = "qcom,x1e80100-dp", .data = &msm_dp_desc_x1e80100 },
188 static struct msm_dp_display_private *dev_get_dp_display_private(struct device *dev)
190 struct msm_dp *dp = dev_get_drvdata(dev);
192 return container_of(dp, struct msm_dp_display_private, msm_dp_display);
195 static int msm_dp_add_event(struct msm_dp_display_private *msm_dp_priv, u32 event,
199 struct msm_dp_event *todo;
202 spin_lock_irqsave(&msm_dp_priv->event_lock, flag);
203 pndx = msm_dp_priv->event_pndx + 1;
204 pndx %= DP_EVENT_Q_MAX;
205 if (pndx == msm_dp_priv->event_gndx) {
206 pr_err("event_q is full: pndx=%d gndx=%d\n",
207 msm_dp_priv->event_pndx, msm_dp_priv->event_gndx);
208 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
211 todo = &msm_dp_priv->event_list[msm_dp_priv->event_pndx++];
212 msm_dp_priv->event_pndx %= DP_EVENT_Q_MAX;
213 todo->event_id = event;
216 wake_up(&msm_dp_priv->event_q);
217 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
222 static int msm_dp_del_event(struct msm_dp_display_private *msm_dp_priv, u32 event)
225 struct msm_dp_event *todo;
228 spin_lock_irqsave(&msm_dp_priv->event_lock, flag);
229 if (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) {
230 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
234 gndx = msm_dp_priv->event_gndx;
235 while (msm_dp_priv->event_pndx != gndx) {
236 todo = &msm_dp_priv->event_list[gndx];
237 if (todo->event_id == event) {
238 todo->event_id = EV_NO_EVENT; /* deleted */
242 gndx %= DP_EVENT_Q_MAX;
244 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
249 void msm_dp_display_signal_audio_start(struct msm_dp *msm_dp_display)
251 struct msm_dp_display_private *dp;
253 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
255 reinit_completion(&dp->audio_comp);
258 void msm_dp_display_signal_audio_complete(struct msm_dp *msm_dp_display)
260 struct msm_dp_display_private *dp;
262 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
264 complete_all(&dp->audio_comp);
267 static int msm_dp_hpd_event_thread_start(struct msm_dp_display_private *msm_dp_priv);
269 static int msm_dp_display_bind(struct device *dev, struct device *master,
273 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
274 struct msm_drm_private *priv = dev_get_drvdata(master);
275 struct drm_device *drm = priv->dev;
277 dp->msm_dp_display.drm_dev = drm;
278 priv->dp[dp->id] = &dp->msm_dp_display;
283 dp->aux->drm_dev = drm;
284 rc = msm_dp_aux_register(dp->aux);
286 DRM_ERROR("DRM DP AUX register failed\n");
291 rc = msm_dp_register_audio_driver(dev, dp->audio);
293 DRM_ERROR("Audio registration Dp failed\n");
297 rc = msm_dp_hpd_event_thread_start(dp);
299 DRM_ERROR("Event thread create failed\n");
308 static void msm_dp_display_unbind(struct device *dev, struct device *master,
311 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
312 struct msm_drm_private *priv = dev_get_drvdata(master);
314 kthread_stop(dp->ev_tsk);
316 of_dp_aux_depopulate_bus(dp->aux);
318 msm_dp_unregister_audio_driver(dev, dp->audio);
319 msm_dp_aux_unregister(dp->aux);
321 dp->aux->drm_dev = NULL;
322 priv->dp[dp->id] = NULL;
325 static const struct component_ops msm_dp_display_comp_ops = {
326 .bind = msm_dp_display_bind,
327 .unbind = msm_dp_display_unbind,
330 static void msm_dp_display_send_hpd_event(struct msm_dp *msm_dp_display)
332 struct msm_dp_display_private *dp;
333 struct drm_connector *connector;
335 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
337 connector = dp->msm_dp_display.connector;
338 drm_helper_hpd_irq_event(connector->dev);
341 static int msm_dp_display_send_hpd_notification(struct msm_dp_display_private *dp,
344 if ((hpd && dp->msm_dp_display.link_ready) ||
345 (!hpd && !dp->msm_dp_display.link_ready)) {
346 drm_dbg_dp(dp->drm_dev, "HPD already %s\n",
347 (hpd ? "on" : "off"));
351 /* reset video pattern flag on disconnect */
353 dp->panel->video_test = false;
354 if (!dp->msm_dp_display.is_edp)
355 drm_dp_set_subconnector_property(dp->msm_dp_display.connector,
356 connector_status_disconnected,
358 dp->panel->downstream_ports);
361 dp->msm_dp_display.link_ready = hpd;
363 drm_dbg_dp(dp->drm_dev, "type=%d hpd=%d\n",
364 dp->msm_dp_display.connector_type, hpd);
365 msm_dp_display_send_hpd_event(&dp->msm_dp_display);
370 static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)
372 struct drm_connector *connector = dp->msm_dp_display.connector;
373 const struct drm_display_info *info = &connector->display_info;
376 rc = msm_dp_panel_read_sink_caps(dp->panel, connector);
380 msm_dp_link_process_request(dp->link);
382 if (!dp->msm_dp_display.is_edp)
383 drm_dp_set_subconnector_property(connector,
384 connector_status_connected,
386 dp->panel->downstream_ports);
388 dp->msm_dp_display.psr_supported = dp->panel->psr_cap.version && psr_enabled;
390 dp->audio_supported = info->has_audio;
391 msm_dp_panel_handle_sink_request(dp->panel);
394 * set sink to normal operation mode -- D0
397 msm_dp_link_psm_config(dp->link, &dp->panel->link_info, false);
399 msm_dp_link_reset_phy_params_vx_px(dp->link);
400 rc = msm_dp_ctrl_on_link(dp->ctrl);
402 DRM_ERROR("failed to complete DP link training\n");
406 msm_dp_add_event(dp, EV_USER_NOTIFICATION, true, 0);
412 static void msm_dp_display_host_phy_init(struct msm_dp_display_private *dp)
414 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
415 dp->msm_dp_display.connector_type, dp->core_initialized,
416 dp->phy_initialized);
418 if (!dp->phy_initialized) {
419 msm_dp_ctrl_phy_init(dp->ctrl);
420 dp->phy_initialized = true;
424 static void msm_dp_display_host_phy_exit(struct msm_dp_display_private *dp)
426 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
427 dp->msm_dp_display.connector_type, dp->core_initialized,
428 dp->phy_initialized);
430 if (dp->phy_initialized) {
431 msm_dp_ctrl_phy_exit(dp->ctrl);
432 dp->phy_initialized = false;
436 static void msm_dp_display_host_init(struct msm_dp_display_private *dp)
438 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
439 dp->msm_dp_display.connector_type, dp->core_initialized,
440 dp->phy_initialized);
442 msm_dp_ctrl_core_clk_enable(dp->ctrl);
443 msm_dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
444 msm_dp_aux_init(dp->aux);
445 dp->core_initialized = true;
448 static void msm_dp_display_host_deinit(struct msm_dp_display_private *dp)
450 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
451 dp->msm_dp_display.connector_type, dp->core_initialized,
452 dp->phy_initialized);
454 msm_dp_ctrl_reset_irq_ctrl(dp->ctrl, false);
455 msm_dp_aux_deinit(dp->aux);
456 msm_dp_ctrl_core_clk_disable(dp->ctrl);
457 dp->core_initialized = false;
460 static int msm_dp_display_usbpd_configure_cb(struct device *dev)
462 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
464 msm_dp_display_host_phy_init(dp);
466 return msm_dp_display_process_hpd_high(dp);
469 static int msm_dp_display_notify_disconnect(struct device *dev)
471 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
473 msm_dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
478 static void msm_dp_display_handle_video_request(struct msm_dp_display_private *dp)
480 if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
481 dp->panel->video_test = true;
482 msm_dp_link_send_test_response(dp->link);
486 static int msm_dp_display_handle_port_status_changed(struct msm_dp_display_private *dp)
490 if (drm_dp_is_branch(dp->panel->dpcd) && dp->link->sink_count == 0) {
491 drm_dbg_dp(dp->drm_dev, "sink count is zero, nothing to do\n");
492 if (dp->hpd_state != ST_DISCONNECTED) {
493 dp->hpd_state = ST_DISCONNECT_PENDING;
494 msm_dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
497 if (dp->hpd_state == ST_DISCONNECTED) {
498 dp->hpd_state = ST_MAINLINK_READY;
499 rc = msm_dp_display_process_hpd_high(dp);
501 dp->hpd_state = ST_DISCONNECTED;
508 static int msm_dp_display_handle_irq_hpd(struct msm_dp_display_private *dp)
510 u32 sink_request = dp->link->sink_request;
512 drm_dbg_dp(dp->drm_dev, "%d\n", sink_request);
513 if (dp->hpd_state == ST_DISCONNECTED) {
514 if (sink_request & DP_LINK_STATUS_UPDATED) {
515 drm_dbg_dp(dp->drm_dev, "Disconnected sink_request: %d\n",
517 DRM_ERROR("Disconnected, no DP_LINK_STATUS_UPDATED\n");
522 msm_dp_ctrl_handle_sink_request(dp->ctrl);
524 if (sink_request & DP_TEST_LINK_VIDEO_PATTERN)
525 msm_dp_display_handle_video_request(dp);
530 static int msm_dp_display_usbpd_attention_cb(struct device *dev)
534 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
536 /* check for any test request issued by sink */
537 rc = msm_dp_link_process_request(dp->link);
539 sink_request = dp->link->sink_request;
540 drm_dbg_dp(dp->drm_dev, "hpd_state=%d sink_request=%d\n",
541 dp->hpd_state, sink_request);
542 if (sink_request & DS_PORT_STATUS_CHANGED)
543 rc = msm_dp_display_handle_port_status_changed(dp);
545 rc = msm_dp_display_handle_irq_hpd(dp);
551 static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)
555 struct platform_device *pdev = dp->msm_dp_display.pdev;
557 msm_dp_aux_enable_xfers(dp->aux, true);
559 mutex_lock(&dp->event_mutex);
561 state = dp->hpd_state;
562 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
563 dp->msm_dp_display.connector_type, state);
565 if (state == ST_DISPLAY_OFF) {
566 mutex_unlock(&dp->event_mutex);
570 if (state == ST_MAINLINK_READY || state == ST_CONNECTED) {
571 mutex_unlock(&dp->event_mutex);
575 if (state == ST_DISCONNECT_PENDING) {
576 /* wait until ST_DISCONNECTED */
577 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 1); /* delay = 1 */
578 mutex_unlock(&dp->event_mutex);
582 ret = pm_runtime_resume_and_get(&pdev->dev);
584 DRM_ERROR("failed to pm_runtime_resume\n");
585 mutex_unlock(&dp->event_mutex);
589 ret = msm_dp_display_usbpd_configure_cb(&pdev->dev);
590 if (ret) { /* link train failed */
591 dp->hpd_state = ST_DISCONNECTED;
592 pm_runtime_put_sync(&pdev->dev);
594 dp->hpd_state = ST_MAINLINK_READY;
597 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
598 dp->msm_dp_display.connector_type, state);
599 mutex_unlock(&dp->event_mutex);
601 /* uevent will complete connection part */
605 static void msm_dp_display_handle_plugged_change(struct msm_dp *msm_dp_display,
608 struct msm_dp_display_private *dp;
610 dp = container_of(msm_dp_display,
611 struct msm_dp_display_private, msm_dp_display);
613 /* notify audio subsystem only if sink supports audio */
614 if (msm_dp_display->plugged_cb && msm_dp_display->codec_dev &&
616 msm_dp_display->plugged_cb(msm_dp_display->codec_dev, plugged);
619 static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data)
622 struct platform_device *pdev = dp->msm_dp_display.pdev;
624 msm_dp_aux_enable_xfers(dp->aux, false);
626 mutex_lock(&dp->event_mutex);
628 state = dp->hpd_state;
630 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
631 dp->msm_dp_display.connector_type, state);
633 /* unplugged, no more irq_hpd handle */
634 msm_dp_del_event(dp, EV_IRQ_HPD_INT);
636 if (state == ST_DISCONNECTED) {
637 /* triggered by irq_hdp with sink_count = 0 */
638 if (dp->link->sink_count == 0) {
639 msm_dp_display_host_phy_exit(dp);
641 msm_dp_display_notify_disconnect(&dp->msm_dp_display.pdev->dev);
642 mutex_unlock(&dp->event_mutex);
644 } else if (state == ST_DISCONNECT_PENDING) {
645 mutex_unlock(&dp->event_mutex);
647 } else if (state == ST_MAINLINK_READY) {
648 msm_dp_ctrl_off_link(dp->ctrl);
649 msm_dp_display_host_phy_exit(dp);
650 dp->hpd_state = ST_DISCONNECTED;
651 msm_dp_display_notify_disconnect(&dp->msm_dp_display.pdev->dev);
652 pm_runtime_put_sync(&pdev->dev);
653 mutex_unlock(&dp->event_mutex);
658 * We don't need separate work for disconnect as
659 * connect/attention interrupts are disabled
661 msm_dp_display_notify_disconnect(&dp->msm_dp_display.pdev->dev);
663 if (state == ST_DISPLAY_OFF) {
664 dp->hpd_state = ST_DISCONNECTED;
666 dp->hpd_state = ST_DISCONNECT_PENDING;
669 /* signal the disconnect event early to ensure proper teardown */
670 msm_dp_display_handle_plugged_change(&dp->msm_dp_display, false);
672 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
673 dp->msm_dp_display.connector_type, state);
675 /* uevent will complete disconnection part */
676 pm_runtime_put_sync(&pdev->dev);
677 mutex_unlock(&dp->event_mutex);
681 static int msm_dp_irq_hpd_handle(struct msm_dp_display_private *dp, u32 data)
685 mutex_lock(&dp->event_mutex);
687 /* irq_hpd can happen at either connected or disconnected state */
688 state = dp->hpd_state;
689 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
690 dp->msm_dp_display.connector_type, state);
692 if (state == ST_DISPLAY_OFF) {
693 mutex_unlock(&dp->event_mutex);
697 if (state == ST_MAINLINK_READY || state == ST_DISCONNECT_PENDING) {
698 /* wait until ST_CONNECTED */
699 msm_dp_add_event(dp, EV_IRQ_HPD_INT, 0, 1); /* delay = 1 */
700 mutex_unlock(&dp->event_mutex);
704 msm_dp_display_usbpd_attention_cb(&dp->msm_dp_display.pdev->dev);
706 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
707 dp->msm_dp_display.connector_type, state);
709 mutex_unlock(&dp->event_mutex);
714 static void msm_dp_display_deinit_sub_modules(struct msm_dp_display_private *dp)
716 msm_dp_audio_put(dp->audio);
717 msm_dp_panel_put(dp->panel);
718 msm_dp_aux_put(dp->aux);
721 static int msm_dp_init_sub_modules(struct msm_dp_display_private *dp)
724 struct device *dev = &dp->msm_dp_display.pdev->dev;
725 struct msm_dp_panel_in panel_in = {
730 phy = devm_phy_get(dev, "dp");
734 rc = phy_set_mode_ext(phy, PHY_MODE_DP,
735 dp->msm_dp_display.is_edp ? PHY_SUBMODE_EDP : PHY_SUBMODE_DP);
737 DRM_ERROR("failed to set phy submode, rc = %d\n", rc);
742 dp->catalog = msm_dp_catalog_get(dev);
743 if (IS_ERR(dp->catalog)) {
744 rc = PTR_ERR(dp->catalog);
745 DRM_ERROR("failed to initialize catalog, rc = %d\n", rc);
750 dp->aux = msm_dp_aux_get(dev, dp->catalog,
752 dp->msm_dp_display.is_edp);
753 if (IS_ERR(dp->aux)) {
754 rc = PTR_ERR(dp->aux);
755 DRM_ERROR("failed to initialize aux, rc = %d\n", rc);
760 dp->link = msm_dp_link_get(dev, dp->aux);
761 if (IS_ERR(dp->link)) {
762 rc = PTR_ERR(dp->link);
763 DRM_ERROR("failed to initialize link, rc = %d\n", rc);
768 panel_in.aux = dp->aux;
769 panel_in.catalog = dp->catalog;
770 panel_in.link = dp->link;
772 dp->panel = msm_dp_panel_get(&panel_in);
773 if (IS_ERR(dp->panel)) {
774 rc = PTR_ERR(dp->panel);
775 DRM_ERROR("failed to initialize panel, rc = %d\n", rc);
780 dp->ctrl = msm_dp_ctrl_get(dev, dp->link, dp->panel, dp->aux,
783 if (IS_ERR(dp->ctrl)) {
784 rc = PTR_ERR(dp->ctrl);
785 DRM_ERROR("failed to initialize ctrl, rc = %d\n", rc);
790 dp->audio = msm_dp_audio_get(dp->msm_dp_display.pdev, dp->panel, dp->catalog);
791 if (IS_ERR(dp->audio)) {
792 rc = PTR_ERR(dp->audio);
793 pr_err("failed to initialize audio, rc = %d\n", rc);
801 msm_dp_panel_put(dp->panel);
803 msm_dp_aux_put(dp->aux);
808 static int msm_dp_display_set_mode(struct msm_dp *msm_dp_display,
809 struct msm_dp_display_mode *mode)
811 struct msm_dp_display_private *dp;
813 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
815 drm_mode_copy(&dp->panel->msm_dp_mode.drm_mode, &mode->drm_mode);
816 dp->panel->msm_dp_mode.bpp = mode->bpp;
817 dp->panel->msm_dp_mode.out_fmt_is_yuv_420 = mode->out_fmt_is_yuv_420;
818 msm_dp_panel_init_panel_info(dp->panel);
822 static int msm_dp_display_enable(struct msm_dp_display_private *dp, bool force_link_train)
825 struct msm_dp *msm_dp_display = &dp->msm_dp_display;
827 drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
828 if (msm_dp_display->power_on) {
829 drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
833 rc = msm_dp_ctrl_on_stream(dp->ctrl, force_link_train);
835 msm_dp_display->power_on = true;
840 static int msm_dp_display_post_enable(struct msm_dp *msm_dp_display)
842 struct msm_dp_display_private *dp;
845 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
847 rate = dp->link->link_params.rate;
849 if (dp->audio_supported) {
850 dp->audio->bw_code = drm_dp_link_rate_to_bw_code(rate);
851 dp->audio->lane_count = dp->link->link_params.num_lanes;
854 /* signal the connect event late to synchronize video and display */
855 msm_dp_display_handle_plugged_change(msm_dp_display, true);
857 if (msm_dp_display->psr_supported)
858 msm_dp_ctrl_config_psr(dp->ctrl);
863 static int msm_dp_display_disable(struct msm_dp_display_private *dp)
865 struct msm_dp *msm_dp_display = &dp->msm_dp_display;
867 if (!msm_dp_display->power_on)
870 /* wait only if audio was enabled */
871 if (msm_dp_display->audio_enabled) {
872 /* signal the disconnect event */
873 msm_dp_display_handle_plugged_change(msm_dp_display, false);
874 if (!wait_for_completion_timeout(&dp->audio_comp,
876 DRM_ERROR("audio comp timeout\n");
879 msm_dp_display->audio_enabled = false;
881 if (dp->link->sink_count == 0) {
883 * irq_hpd with sink_count = 0
884 * hdmi unplugged out of dongle
886 msm_dp_ctrl_off_link_stream(dp->ctrl);
889 * unplugged interrupt
890 * dongle unplugged out of DUT
892 msm_dp_ctrl_off(dp->ctrl);
893 msm_dp_display_host_phy_exit(dp);
896 msm_dp_display->power_on = false;
898 drm_dbg_dp(dp->drm_dev, "sink count: %d\n", dp->link->sink_count);
902 int msm_dp_display_set_plugged_cb(struct msm_dp *msm_dp_display,
903 hdmi_codec_plugged_cb fn, struct device *codec_dev)
907 msm_dp_display->plugged_cb = fn;
908 msm_dp_display->codec_dev = codec_dev;
909 plugged = msm_dp_display->link_ready;
910 msm_dp_display_handle_plugged_change(msm_dp_display, plugged);
916 * msm_dp_bridge_mode_valid - callback to determine if specified mode is valid
917 * @bridge: Pointer to drm bridge structure
918 * @info: display info
919 * @mode: Pointer to drm mode structure
920 * Returns: Validity status for specified mode
922 enum drm_mode_status msm_dp_bridge_mode_valid(struct drm_bridge *bridge,
923 const struct drm_display_info *info,
924 const struct drm_display_mode *mode)
926 const u32 num_components = 3, default_bpp = 24;
927 struct msm_dp_display_private *msm_dp_display;
928 struct msm_dp_link_info *link_info;
929 u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
931 int mode_pclk_khz = mode->clock;
933 dp = to_dp_bridge(bridge)->msm_dp_display;
935 if (!dp || !mode_pclk_khz || !dp->connector) {
936 DRM_ERROR("invalid params\n");
940 if (mode->clock > DP_MAX_PIXEL_CLK_KHZ)
941 return MODE_CLOCK_HIGH;
943 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
944 link_info = &msm_dp_display->panel->link_info;
946 if (drm_mode_is_420_only(&dp->connector->display_info, mode) &&
947 msm_dp_display->panel->vsc_sdp_supported)
950 mode_bpp = dp->connector->display_info.bpc * num_components;
952 mode_bpp = default_bpp;
954 mode_bpp = msm_dp_panel_get_mode_bpp(msm_dp_display->panel,
955 mode_bpp, mode_pclk_khz);
957 mode_rate_khz = mode_pclk_khz * mode_bpp;
958 supported_rate_khz = link_info->num_lanes * link_info->rate * 8;
960 if (mode_rate_khz > supported_rate_khz)
966 int msm_dp_display_get_modes(struct msm_dp *dp)
968 struct msm_dp_display_private *msm_dp_display;
971 DRM_ERROR("invalid params\n");
975 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
977 return msm_dp_panel_get_modes(msm_dp_display->panel,
981 bool msm_dp_display_check_video_test(struct msm_dp *dp)
983 struct msm_dp_display_private *msm_dp_display;
985 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
987 return msm_dp_display->panel->video_test;
990 int msm_dp_display_get_test_bpp(struct msm_dp *dp)
992 struct msm_dp_display_private *msm_dp_display;
995 DRM_ERROR("invalid params\n");
999 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1001 return msm_dp_link_bit_depth_to_bpp(
1002 msm_dp_display->link->test_video.test_bit_depth);
1005 void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)
1007 struct msm_dp_display_private *msm_dp_display;
1009 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1012 * if we are reading registers we need the link clocks to be on
1013 * however till DP cable is connected this will not happen as we
1014 * do not know the resolution to power up with. Hence check the
1015 * power_on status before dumping DP registers to avoid crash due
1016 * to unclocked access
1018 mutex_lock(&msm_dp_display->event_mutex);
1020 if (!dp->power_on) {
1021 mutex_unlock(&msm_dp_display->event_mutex);
1025 msm_dp_catalog_snapshot(msm_dp_display->catalog, disp_state);
1027 mutex_unlock(&msm_dp_display->event_mutex);
1030 void msm_dp_display_set_psr(struct msm_dp *msm_dp_display, bool enter)
1032 struct msm_dp_display_private *dp;
1034 if (!msm_dp_display) {
1035 DRM_ERROR("invalid params\n");
1039 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1040 msm_dp_ctrl_set_psr(dp->ctrl, enter);
1043 static int hpd_event_thread(void *data)
1045 struct msm_dp_display_private *msm_dp_priv;
1047 struct msm_dp_event *todo;
1048 int timeout_mode = 0;
1050 msm_dp_priv = (struct msm_dp_display_private *)data;
1054 wait_event_timeout(msm_dp_priv->event_q,
1055 (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) ||
1056 kthread_should_stop(), EVENT_TIMEOUT);
1058 wait_event_interruptible(msm_dp_priv->event_q,
1059 (msm_dp_priv->event_pndx != msm_dp_priv->event_gndx) ||
1060 kthread_should_stop());
1063 if (kthread_should_stop())
1066 spin_lock_irqsave(&msm_dp_priv->event_lock, flag);
1067 todo = &msm_dp_priv->event_list[msm_dp_priv->event_gndx];
1069 struct msm_dp_event *todo_next;
1071 msm_dp_priv->event_gndx++;
1072 msm_dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1074 /* re enter delay event into q */
1075 todo_next = &msm_dp_priv->event_list[msm_dp_priv->event_pndx++];
1076 msm_dp_priv->event_pndx %= DP_EVENT_Q_MAX;
1077 todo_next->event_id = todo->event_id;
1078 todo_next->data = todo->data;
1079 todo_next->delay = todo->delay - 1;
1081 /* clean up older event */
1082 todo->event_id = EV_NO_EVENT;
1085 /* switch to timeout mode */
1087 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
1091 /* timeout with no events in q */
1092 if (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) {
1093 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
1097 msm_dp_priv->event_gndx++;
1098 msm_dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1100 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
1102 switch (todo->event_id) {
1103 case EV_HPD_PLUG_INT:
1104 msm_dp_hpd_plug_handle(msm_dp_priv, todo->data);
1106 case EV_HPD_UNPLUG_INT:
1107 msm_dp_hpd_unplug_handle(msm_dp_priv, todo->data);
1109 case EV_IRQ_HPD_INT:
1110 msm_dp_irq_hpd_handle(msm_dp_priv, todo->data);
1112 case EV_USER_NOTIFICATION:
1113 msm_dp_display_send_hpd_notification(msm_dp_priv,
1124 static int msm_dp_hpd_event_thread_start(struct msm_dp_display_private *msm_dp_priv)
1126 /* set event q to empty */
1127 msm_dp_priv->event_gndx = 0;
1128 msm_dp_priv->event_pndx = 0;
1130 msm_dp_priv->ev_tsk = kthread_run(hpd_event_thread, msm_dp_priv, "dp_hpd_handler");
1131 if (IS_ERR(msm_dp_priv->ev_tsk))
1132 return PTR_ERR(msm_dp_priv->ev_tsk);
1137 static irqreturn_t msm_dp_display_irq_handler(int irq, void *dev_id)
1139 struct msm_dp_display_private *dp = dev_id;
1140 irqreturn_t ret = IRQ_NONE;
1144 DRM_ERROR("invalid data\n");
1148 hpd_isr_status = msm_dp_catalog_hpd_get_intr_status(dp->catalog);
1150 if (hpd_isr_status & 0x0F) {
1151 drm_dbg_dp(dp->drm_dev, "type=%d isr=0x%x\n",
1152 dp->msm_dp_display.connector_type, hpd_isr_status);
1153 /* hpd related interrupts */
1154 if (hpd_isr_status & DP_DP_HPD_PLUG_INT_MASK)
1155 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1157 if (hpd_isr_status & DP_DP_IRQ_HPD_INT_MASK) {
1158 msm_dp_add_event(dp, EV_IRQ_HPD_INT, 0, 0);
1161 if (hpd_isr_status & DP_DP_HPD_REPLUG_INT_MASK) {
1162 msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1163 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 3);
1166 if (hpd_isr_status & DP_DP_HPD_UNPLUG_INT_MASK)
1167 msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1172 /* DP controller isr */
1173 ret |= msm_dp_ctrl_isr(dp->ctrl);
1176 ret |= msm_dp_aux_isr(dp->aux);
1181 static int msm_dp_display_request_irq(struct msm_dp_display_private *dp)
1184 struct platform_device *pdev = dp->msm_dp_display.pdev;
1186 dp->irq = platform_get_irq(pdev, 0);
1188 DRM_ERROR("failed to get irq\n");
1192 rc = devm_request_irq(&pdev->dev, dp->irq, msm_dp_display_irq_handler,
1193 IRQF_TRIGGER_HIGH|IRQF_NO_AUTOEN,
1194 "dp_display_isr", dp);
1197 DRM_ERROR("failed to request IRQ%u: %d\n",
1205 static const struct msm_dp_desc *msm_dp_display_get_desc(struct platform_device *pdev)
1207 const struct msm_dp_desc *descs = of_device_get_match_data(&pdev->dev);
1208 struct resource *res;
1211 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1215 for (i = 0; i < descs[i].io_start; i++) {
1216 if (descs[i].io_start == res->start)
1220 dev_err(&pdev->dev, "unknown displayport instance\n");
1224 static int msm_dp_display_probe_tail(struct device *dev)
1226 struct msm_dp *dp = dev_get_drvdata(dev);
1230 * External bridges are mandatory for eDP interfaces: one has to
1231 * provide at least an eDP panel (which gets wrapped into panel-bridge).
1233 * For DisplayPort interfaces external bridges are optional, so
1234 * silently ignore an error if one is not present (-ENODEV).
1236 dp->next_bridge = devm_drm_of_get_bridge(&dp->pdev->dev, dp->pdev->dev.of_node, 1, 0);
1237 if (IS_ERR(dp->next_bridge)) {
1238 ret = PTR_ERR(dp->next_bridge);
1239 dp->next_bridge = NULL;
1240 if (dp->is_edp || ret != -ENODEV)
1244 ret = component_add(dev, &msm_dp_display_comp_ops);
1246 DRM_ERROR("component add failed, rc=%d\n", ret);
1251 static int msm_dp_auxbus_done_probe(struct drm_dp_aux *aux)
1253 return msm_dp_display_probe_tail(aux->dev);
1256 static int msm_dp_display_get_connector_type(struct platform_device *pdev,
1257 const struct msm_dp_desc *desc)
1259 struct device_node *node = pdev->dev.of_node;
1260 struct device_node *aux_bus = of_get_child_by_name(node, "aux-bus");
1261 struct device_node *panel = of_get_child_by_name(aux_bus, "panel");
1265 connector_type = DRM_MODE_CONNECTOR_eDP;
1267 connector_type = DRM_MODE_SUBCONNECTOR_DisplayPort;
1270 of_node_put(aux_bus);
1272 return connector_type;
1275 static int msm_dp_display_probe(struct platform_device *pdev)
1278 struct msm_dp_display_private *dp;
1279 const struct msm_dp_desc *desc;
1281 if (!pdev || !pdev->dev.of_node) {
1282 DRM_ERROR("pdev not found\n");
1286 dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
1290 desc = msm_dp_display_get_desc(pdev);
1294 dp->msm_dp_display.pdev = pdev;
1296 dp->msm_dp_display.connector_type = msm_dp_display_get_connector_type(pdev, desc);
1297 dp->wide_bus_supported = desc->wide_bus_supported;
1298 dp->msm_dp_display.is_edp =
1299 (dp->msm_dp_display.connector_type == DRM_MODE_CONNECTOR_eDP);
1301 rc = msm_dp_init_sub_modules(dp);
1303 DRM_ERROR("init sub module failed\n");
1304 return -EPROBE_DEFER;
1308 mutex_init(&dp->event_mutex);
1309 init_waitqueue_head(&dp->event_q);
1310 spin_lock_init(&dp->event_lock);
1312 /* Store DP audio handle inside DP display */
1313 dp->msm_dp_display.msm_dp_audio = dp->audio;
1315 init_completion(&dp->audio_comp);
1317 platform_set_drvdata(pdev, &dp->msm_dp_display);
1319 rc = devm_pm_runtime_enable(&pdev->dev);
1323 rc = msm_dp_display_request_irq(dp);
1327 if (dp->msm_dp_display.is_edp) {
1328 rc = devm_of_dp_aux_populate_bus(dp->aux, msm_dp_auxbus_done_probe);
1330 DRM_ERROR("eDP auxbus population failed, rc=%d\n", rc);
1334 rc = msm_dp_display_probe_tail(&pdev->dev);
1342 msm_dp_display_deinit_sub_modules(dp);
1346 static void msm_dp_display_remove(struct platform_device *pdev)
1348 struct msm_dp_display_private *dp = dev_get_dp_display_private(&pdev->dev);
1350 component_del(&pdev->dev, &msm_dp_display_comp_ops);
1351 msm_dp_display_deinit_sub_modules(dp);
1352 platform_set_drvdata(pdev, NULL);
1355 static int msm_dp_pm_runtime_suspend(struct device *dev)
1357 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
1359 disable_irq(dp->irq);
1361 if (dp->msm_dp_display.is_edp) {
1362 msm_dp_display_host_phy_exit(dp);
1363 msm_dp_catalog_ctrl_hpd_disable(dp->catalog);
1365 msm_dp_display_host_deinit(dp);
1370 static int msm_dp_pm_runtime_resume(struct device *dev)
1372 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
1375 * for eDP, host cotroller, HPD block and PHY are enabled here
1376 * but with HPD irq disabled
1378 * for DP, only host controller is enabled here.
1379 * HPD block is enabled at msm_dp_bridge_hpd_enable()
1380 * PHY will be enabled at plugin handler later
1382 msm_dp_display_host_init(dp);
1383 if (dp->msm_dp_display.is_edp) {
1384 msm_dp_catalog_ctrl_hpd_enable(dp->catalog);
1385 msm_dp_display_host_phy_init(dp);
1388 enable_irq(dp->irq);
1392 static const struct dev_pm_ops msm_dp_pm_ops = {
1393 SET_RUNTIME_PM_OPS(msm_dp_pm_runtime_suspend, msm_dp_pm_runtime_resume, NULL)
1394 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1395 pm_runtime_force_resume)
1398 static struct platform_driver msm_dp_display_driver = {
1399 .probe = msm_dp_display_probe,
1400 .remove_new = msm_dp_display_remove,
1402 .name = "msm-dp-display",
1403 .of_match_table = msm_dp_dt_match,
1404 .suppress_bind_attrs = true,
1405 .pm = &msm_dp_pm_ops,
1409 int __init msm_dp_register(void)
1413 ret = platform_driver_register(&msm_dp_display_driver);
1415 DRM_ERROR("Dp display driver register failed");
1420 void __exit msm_dp_unregister(void)
1422 platform_driver_unregister(&msm_dp_display_driver);
1425 bool msm_dp_is_yuv_420_enabled(const struct msm_dp *msm_dp_display,
1426 const struct drm_display_mode *mode)
1428 struct msm_dp_display_private *dp;
1429 const struct drm_display_info *info;
1431 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1432 info = &msm_dp_display->connector->display_info;
1434 return dp->panel->vsc_sdp_supported && drm_mode_is_420_only(info, mode);
1437 bool msm_dp_needs_periph_flush(const struct msm_dp *msm_dp_display,
1438 const struct drm_display_mode *mode)
1440 return msm_dp_is_yuv_420_enabled(msm_dp_display, mode);
1443 bool msm_dp_wide_bus_available(const struct msm_dp *msm_dp_display)
1445 struct msm_dp_display_private *dp;
1447 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1449 if (dp->msm_dp_mode.out_fmt_is_yuv_420)
1452 return dp->wide_bus_supported;
1455 void msm_dp_display_debugfs_init(struct msm_dp *msm_dp_display, struct dentry *root, bool is_edp)
1457 struct msm_dp_display_private *dp;
1461 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1462 dev = &dp->msm_dp_display.pdev->dev;
1464 rc = msm_dp_debug_init(dev, dp->panel, dp->link, dp->msm_dp_display.connector, root, is_edp);
1466 DRM_ERROR("failed to initialize debug, rc = %d\n", rc);
1469 int msm_dp_modeset_init(struct msm_dp *msm_dp_display, struct drm_device *dev,
1470 struct drm_encoder *encoder, bool yuv_supported)
1472 struct msm_dp_display_private *msm_dp_priv;
1475 msm_dp_display->drm_dev = dev;
1477 msm_dp_priv = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1479 ret = msm_dp_bridge_init(msm_dp_display, dev, encoder, yuv_supported);
1481 DRM_DEV_ERROR(dev->dev,
1482 "failed to create dp bridge: %d\n", ret);
1486 msm_dp_display->connector = msm_dp_drm_connector_init(msm_dp_display, encoder);
1487 if (IS_ERR(msm_dp_display->connector)) {
1488 ret = PTR_ERR(msm_dp_display->connector);
1489 DRM_DEV_ERROR(dev->dev,
1490 "failed to create dp connector: %d\n", ret);
1491 msm_dp_display->connector = NULL;
1495 msm_dp_priv->panel->connector = msm_dp_display->connector;
1500 void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge,
1501 struct drm_bridge_state *old_bridge_state)
1503 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1504 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1506 struct msm_dp_display_private *msm_dp_display;
1508 bool force_link_train = false;
1510 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1511 if (!msm_dp_display->msm_dp_mode.drm_mode.clock) {
1512 DRM_ERROR("invalid params\n");
1517 msm_dp_hpd_plug_handle(msm_dp_display, 0);
1519 mutex_lock(&msm_dp_display->event_mutex);
1520 if (pm_runtime_resume_and_get(&dp->pdev->dev)) {
1521 DRM_ERROR("failed to pm_runtime_resume\n");
1522 mutex_unlock(&msm_dp_display->event_mutex);
1526 state = msm_dp_display->hpd_state;
1527 if (state != ST_DISPLAY_OFF && state != ST_MAINLINK_READY) {
1528 mutex_unlock(&msm_dp_display->event_mutex);
1532 rc = msm_dp_display_set_mode(dp, &msm_dp_display->msm_dp_mode);
1534 DRM_ERROR("Failed to perform a mode set, rc=%d\n", rc);
1535 mutex_unlock(&msm_dp_display->event_mutex);
1539 state = msm_dp_display->hpd_state;
1541 if (state == ST_DISPLAY_OFF) {
1542 msm_dp_display_host_phy_init(msm_dp_display);
1543 force_link_train = true;
1546 msm_dp_display_enable(msm_dp_display, force_link_train);
1548 rc = msm_dp_display_post_enable(dp);
1550 DRM_ERROR("DP display post enable failed, rc=%d\n", rc);
1551 msm_dp_display_disable(msm_dp_display);
1554 /* completed connection */
1555 msm_dp_display->hpd_state = ST_CONNECTED;
1557 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1558 mutex_unlock(&msm_dp_display->event_mutex);
1561 void msm_dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
1562 struct drm_bridge_state *old_bridge_state)
1564 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1565 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1566 struct msm_dp_display_private *msm_dp_display;
1568 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1570 msm_dp_ctrl_push_idle(msm_dp_display->ctrl);
1573 void msm_dp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,
1574 struct drm_bridge_state *old_bridge_state)
1576 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1577 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1579 struct msm_dp_display_private *msm_dp_display;
1581 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1584 msm_dp_hpd_unplug_handle(msm_dp_display, 0);
1586 mutex_lock(&msm_dp_display->event_mutex);
1588 state = msm_dp_display->hpd_state;
1589 if (state != ST_DISCONNECT_PENDING && state != ST_CONNECTED)
1590 drm_dbg_dp(dp->drm_dev, "type=%d wrong hpd_state=%d\n",
1591 dp->connector_type, state);
1593 msm_dp_display_disable(msm_dp_display);
1595 state = msm_dp_display->hpd_state;
1596 if (state == ST_DISCONNECT_PENDING) {
1597 /* completed disconnection */
1598 msm_dp_display->hpd_state = ST_DISCONNECTED;
1600 msm_dp_display->hpd_state = ST_DISPLAY_OFF;
1603 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1605 pm_runtime_put_sync(&dp->pdev->dev);
1606 mutex_unlock(&msm_dp_display->event_mutex);
1609 void msm_dp_bridge_mode_set(struct drm_bridge *drm_bridge,
1610 const struct drm_display_mode *mode,
1611 const struct drm_display_mode *adjusted_mode)
1613 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1614 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1615 struct msm_dp_display_private *msm_dp_display;
1616 struct msm_dp_panel *msm_dp_panel;
1618 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1619 msm_dp_panel = msm_dp_display->panel;
1621 memset(&msm_dp_display->msm_dp_mode, 0x0, sizeof(struct msm_dp_display_mode));
1623 if (msm_dp_display_check_video_test(dp))
1624 msm_dp_display->msm_dp_mode.bpp = msm_dp_display_get_test_bpp(dp);
1625 else /* Default num_components per pixel = 3 */
1626 msm_dp_display->msm_dp_mode.bpp = dp->connector->display_info.bpc * 3;
1628 if (!msm_dp_display->msm_dp_mode.bpp)
1629 msm_dp_display->msm_dp_mode.bpp = 24; /* Default bpp */
1631 drm_mode_copy(&msm_dp_display->msm_dp_mode.drm_mode, adjusted_mode);
1633 msm_dp_display->msm_dp_mode.v_active_low =
1634 !!(msm_dp_display->msm_dp_mode.drm_mode.flags & DRM_MODE_FLAG_NVSYNC);
1636 msm_dp_display->msm_dp_mode.h_active_low =
1637 !!(msm_dp_display->msm_dp_mode.drm_mode.flags & DRM_MODE_FLAG_NHSYNC);
1639 msm_dp_display->msm_dp_mode.out_fmt_is_yuv_420 =
1640 drm_mode_is_420_only(&dp->connector->display_info, adjusted_mode) &&
1641 msm_dp_panel->vsc_sdp_supported;
1643 /* populate wide_bus_support to different layers */
1644 msm_dp_display->ctrl->wide_bus_en =
1645 msm_dp_display->msm_dp_mode.out_fmt_is_yuv_420 ? false : msm_dp_display->wide_bus_supported;
1646 msm_dp_display->catalog->wide_bus_en =
1647 msm_dp_display->msm_dp_mode.out_fmt_is_yuv_420 ? false : msm_dp_display->wide_bus_supported;
1650 void msm_dp_bridge_hpd_enable(struct drm_bridge *bridge)
1652 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(bridge);
1653 struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display;
1654 struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1657 * this is for external DP with hpd irq enabled case,
1658 * step-1: msm_dp_pm_runtime_resume() enable dp host only
1659 * step-2: enable hdp block and have hpd irq enabled here
1660 * step-3: waiting for plugin irq while phy is not initialized
1661 * step-4: DP PHY is initialized at plugin handler before link training
1664 mutex_lock(&dp->event_mutex);
1665 if (pm_runtime_resume_and_get(&msm_dp_display->pdev->dev)) {
1666 DRM_ERROR("failed to resume power\n");
1667 mutex_unlock(&dp->event_mutex);
1671 msm_dp_catalog_ctrl_hpd_enable(dp->catalog);
1673 /* enable HDP interrupts */
1674 msm_dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, true);
1676 msm_dp_display->internal_hpd = true;
1677 mutex_unlock(&dp->event_mutex);
1680 void msm_dp_bridge_hpd_disable(struct drm_bridge *bridge)
1682 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(bridge);
1683 struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display;
1684 struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1686 mutex_lock(&dp->event_mutex);
1687 /* disable HDP interrupts */
1688 msm_dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, false);
1689 msm_dp_catalog_ctrl_hpd_disable(dp->catalog);
1691 msm_dp_display->internal_hpd = false;
1693 pm_runtime_put_sync(&msm_dp_display->pdev->dev);
1694 mutex_unlock(&dp->event_mutex);
1697 void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
1698 enum drm_connector_status status)
1700 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(bridge);
1701 struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display;
1702 struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1704 /* Without next_bridge interrupts are handled by the DP core directly */
1705 if (msm_dp_display->internal_hpd)
1708 if (!msm_dp_display->link_ready && status == connector_status_connected)
1709 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1710 else if (msm_dp_display->link_ready && status == connector_status_disconnected)
1711 msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);