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;
727 phy = devm_phy_get(dev, "dp");
731 rc = phy_set_mode_ext(phy, PHY_MODE_DP,
732 dp->msm_dp_display.is_edp ? PHY_SUBMODE_EDP : PHY_SUBMODE_DP);
734 DRM_ERROR("failed to set phy submode, rc = %d\n", rc);
739 dp->catalog = msm_dp_catalog_get(dev);
740 if (IS_ERR(dp->catalog)) {
741 rc = PTR_ERR(dp->catalog);
742 DRM_ERROR("failed to initialize catalog, rc = %d\n", rc);
747 dp->aux = msm_dp_aux_get(dev, dp->catalog,
749 dp->msm_dp_display.is_edp);
750 if (IS_ERR(dp->aux)) {
751 rc = PTR_ERR(dp->aux);
752 DRM_ERROR("failed to initialize aux, rc = %d\n", rc);
757 dp->link = msm_dp_link_get(dev, dp->aux);
758 if (IS_ERR(dp->link)) {
759 rc = PTR_ERR(dp->link);
760 DRM_ERROR("failed to initialize link, rc = %d\n", rc);
765 dp->panel = msm_dp_panel_get(dev, dp->aux, dp->link, dp->catalog);
766 if (IS_ERR(dp->panel)) {
767 rc = PTR_ERR(dp->panel);
768 DRM_ERROR("failed to initialize panel, rc = %d\n", rc);
773 dp->ctrl = msm_dp_ctrl_get(dev, dp->link, dp->panel, dp->aux,
776 if (IS_ERR(dp->ctrl)) {
777 rc = PTR_ERR(dp->ctrl);
778 DRM_ERROR("failed to initialize ctrl, rc = %d\n", rc);
783 dp->audio = msm_dp_audio_get(dp->msm_dp_display.pdev, dp->catalog);
784 if (IS_ERR(dp->audio)) {
785 rc = PTR_ERR(dp->audio);
786 pr_err("failed to initialize audio, rc = %d\n", rc);
794 msm_dp_panel_put(dp->panel);
796 msm_dp_aux_put(dp->aux);
801 static int msm_dp_display_set_mode(struct msm_dp *msm_dp_display,
802 struct msm_dp_display_mode *mode)
804 struct msm_dp_display_private *dp;
806 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
808 drm_mode_copy(&dp->panel->msm_dp_mode.drm_mode, &mode->drm_mode);
809 dp->panel->msm_dp_mode.bpp = mode->bpp;
810 dp->panel->msm_dp_mode.out_fmt_is_yuv_420 = mode->out_fmt_is_yuv_420;
811 msm_dp_panel_init_panel_info(dp->panel);
815 static int msm_dp_display_enable(struct msm_dp_display_private *dp, bool force_link_train)
818 struct msm_dp *msm_dp_display = &dp->msm_dp_display;
820 drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
821 if (msm_dp_display->power_on) {
822 drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
826 rc = msm_dp_ctrl_on_stream(dp->ctrl, force_link_train);
828 msm_dp_display->power_on = true;
833 static int msm_dp_display_post_enable(struct msm_dp *msm_dp_display)
835 struct msm_dp_display_private *dp;
838 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
840 rate = dp->link->link_params.rate;
842 if (dp->audio_supported) {
843 dp->audio->bw_code = drm_dp_link_rate_to_bw_code(rate);
844 dp->audio->lane_count = dp->link->link_params.num_lanes;
847 /* signal the connect event late to synchronize video and display */
848 msm_dp_display_handle_plugged_change(msm_dp_display, true);
850 if (msm_dp_display->psr_supported)
851 msm_dp_ctrl_config_psr(dp->ctrl);
856 static int msm_dp_display_disable(struct msm_dp_display_private *dp)
858 struct msm_dp *msm_dp_display = &dp->msm_dp_display;
860 if (!msm_dp_display->power_on)
863 /* wait only if audio was enabled */
864 if (msm_dp_display->audio_enabled) {
865 /* signal the disconnect event */
866 msm_dp_display_handle_plugged_change(msm_dp_display, false);
867 if (!wait_for_completion_timeout(&dp->audio_comp,
869 DRM_ERROR("audio comp timeout\n");
872 msm_dp_display->audio_enabled = false;
874 if (dp->link->sink_count == 0) {
876 * irq_hpd with sink_count = 0
877 * hdmi unplugged out of dongle
879 msm_dp_ctrl_off_link_stream(dp->ctrl);
882 * unplugged interrupt
883 * dongle unplugged out of DUT
885 msm_dp_ctrl_off(dp->ctrl);
886 msm_dp_display_host_phy_exit(dp);
889 msm_dp_display->power_on = false;
891 drm_dbg_dp(dp->drm_dev, "sink count: %d\n", dp->link->sink_count);
895 int msm_dp_display_set_plugged_cb(struct msm_dp *msm_dp_display,
896 hdmi_codec_plugged_cb fn, struct device *codec_dev)
900 msm_dp_display->plugged_cb = fn;
901 msm_dp_display->codec_dev = codec_dev;
902 plugged = msm_dp_display->link_ready;
903 msm_dp_display_handle_plugged_change(msm_dp_display, plugged);
909 * msm_dp_bridge_mode_valid - callback to determine if specified mode is valid
910 * @bridge: Pointer to drm bridge structure
911 * @info: display info
912 * @mode: Pointer to drm mode structure
913 * Returns: Validity status for specified mode
915 enum drm_mode_status msm_dp_bridge_mode_valid(struct drm_bridge *bridge,
916 const struct drm_display_info *info,
917 const struct drm_display_mode *mode)
919 const u32 num_components = 3, default_bpp = 24;
920 struct msm_dp_display_private *msm_dp_display;
921 struct msm_dp_link_info *link_info;
922 u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
924 int mode_pclk_khz = mode->clock;
926 dp = to_dp_bridge(bridge)->msm_dp_display;
928 if (!dp || !mode_pclk_khz || !dp->connector) {
929 DRM_ERROR("invalid params\n");
933 if (mode->clock > DP_MAX_PIXEL_CLK_KHZ)
934 return MODE_CLOCK_HIGH;
936 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
937 link_info = &msm_dp_display->panel->link_info;
939 if (drm_mode_is_420_only(&dp->connector->display_info, mode) &&
940 msm_dp_display->panel->vsc_sdp_supported)
943 mode_bpp = dp->connector->display_info.bpc * num_components;
945 mode_bpp = default_bpp;
947 mode_bpp = msm_dp_panel_get_mode_bpp(msm_dp_display->panel,
948 mode_bpp, mode_pclk_khz);
950 mode_rate_khz = mode_pclk_khz * mode_bpp;
951 supported_rate_khz = link_info->num_lanes * link_info->rate * 8;
953 if (mode_rate_khz > supported_rate_khz)
959 int msm_dp_display_get_modes(struct msm_dp *dp)
961 struct msm_dp_display_private *msm_dp_display;
964 DRM_ERROR("invalid params\n");
968 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
970 return msm_dp_panel_get_modes(msm_dp_display->panel,
974 bool msm_dp_display_check_video_test(struct msm_dp *dp)
976 struct msm_dp_display_private *msm_dp_display;
978 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
980 return msm_dp_display->panel->video_test;
983 int msm_dp_display_get_test_bpp(struct msm_dp *dp)
985 struct msm_dp_display_private *msm_dp_display;
988 DRM_ERROR("invalid params\n");
992 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
994 return msm_dp_link_bit_depth_to_bpp(
995 msm_dp_display->link->test_video.test_bit_depth);
998 void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)
1000 struct msm_dp_display_private *msm_dp_display;
1002 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1005 * if we are reading registers we need the link clocks to be on
1006 * however till DP cable is connected this will not happen as we
1007 * do not know the resolution to power up with. Hence check the
1008 * power_on status before dumping DP registers to avoid crash due
1009 * to unclocked access
1011 mutex_lock(&msm_dp_display->event_mutex);
1013 if (!dp->power_on) {
1014 mutex_unlock(&msm_dp_display->event_mutex);
1018 msm_dp_catalog_snapshot(msm_dp_display->catalog, disp_state);
1020 mutex_unlock(&msm_dp_display->event_mutex);
1023 void msm_dp_display_set_psr(struct msm_dp *msm_dp_display, bool enter)
1025 struct msm_dp_display_private *dp;
1027 if (!msm_dp_display) {
1028 DRM_ERROR("invalid params\n");
1032 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1033 msm_dp_ctrl_set_psr(dp->ctrl, enter);
1036 static int hpd_event_thread(void *data)
1038 struct msm_dp_display_private *msm_dp_priv;
1040 struct msm_dp_event *todo;
1041 int timeout_mode = 0;
1043 msm_dp_priv = (struct msm_dp_display_private *)data;
1047 wait_event_timeout(msm_dp_priv->event_q,
1048 (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) ||
1049 kthread_should_stop(), EVENT_TIMEOUT);
1051 wait_event_interruptible(msm_dp_priv->event_q,
1052 (msm_dp_priv->event_pndx != msm_dp_priv->event_gndx) ||
1053 kthread_should_stop());
1056 if (kthread_should_stop())
1059 spin_lock_irqsave(&msm_dp_priv->event_lock, flag);
1060 todo = &msm_dp_priv->event_list[msm_dp_priv->event_gndx];
1062 struct msm_dp_event *todo_next;
1064 msm_dp_priv->event_gndx++;
1065 msm_dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1067 /* re enter delay event into q */
1068 todo_next = &msm_dp_priv->event_list[msm_dp_priv->event_pndx++];
1069 msm_dp_priv->event_pndx %= DP_EVENT_Q_MAX;
1070 todo_next->event_id = todo->event_id;
1071 todo_next->data = todo->data;
1072 todo_next->delay = todo->delay - 1;
1074 /* clean up older event */
1075 todo->event_id = EV_NO_EVENT;
1078 /* switch to timeout mode */
1080 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
1084 /* timeout with no events in q */
1085 if (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) {
1086 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
1090 msm_dp_priv->event_gndx++;
1091 msm_dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1093 spin_unlock_irqrestore(&msm_dp_priv->event_lock, flag);
1095 switch (todo->event_id) {
1096 case EV_HPD_PLUG_INT:
1097 msm_dp_hpd_plug_handle(msm_dp_priv, todo->data);
1099 case EV_HPD_UNPLUG_INT:
1100 msm_dp_hpd_unplug_handle(msm_dp_priv, todo->data);
1102 case EV_IRQ_HPD_INT:
1103 msm_dp_irq_hpd_handle(msm_dp_priv, todo->data);
1105 case EV_USER_NOTIFICATION:
1106 msm_dp_display_send_hpd_notification(msm_dp_priv,
1117 static int msm_dp_hpd_event_thread_start(struct msm_dp_display_private *msm_dp_priv)
1119 /* set event q to empty */
1120 msm_dp_priv->event_gndx = 0;
1121 msm_dp_priv->event_pndx = 0;
1123 msm_dp_priv->ev_tsk = kthread_run(hpd_event_thread, msm_dp_priv, "dp_hpd_handler");
1124 if (IS_ERR(msm_dp_priv->ev_tsk))
1125 return PTR_ERR(msm_dp_priv->ev_tsk);
1130 static irqreturn_t msm_dp_display_irq_handler(int irq, void *dev_id)
1132 struct msm_dp_display_private *dp = dev_id;
1133 irqreturn_t ret = IRQ_NONE;
1137 DRM_ERROR("invalid data\n");
1141 hpd_isr_status = msm_dp_catalog_hpd_get_intr_status(dp->catalog);
1143 if (hpd_isr_status & 0x0F) {
1144 drm_dbg_dp(dp->drm_dev, "type=%d isr=0x%x\n",
1145 dp->msm_dp_display.connector_type, hpd_isr_status);
1146 /* hpd related interrupts */
1147 if (hpd_isr_status & DP_DP_HPD_PLUG_INT_MASK)
1148 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1150 if (hpd_isr_status & DP_DP_IRQ_HPD_INT_MASK) {
1151 msm_dp_add_event(dp, EV_IRQ_HPD_INT, 0, 0);
1154 if (hpd_isr_status & DP_DP_HPD_REPLUG_INT_MASK) {
1155 msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1156 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 3);
1159 if (hpd_isr_status & DP_DP_HPD_UNPLUG_INT_MASK)
1160 msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1165 /* DP controller isr */
1166 ret |= msm_dp_ctrl_isr(dp->ctrl);
1169 ret |= msm_dp_aux_isr(dp->aux);
1174 static int msm_dp_display_request_irq(struct msm_dp_display_private *dp)
1177 struct platform_device *pdev = dp->msm_dp_display.pdev;
1179 dp->irq = platform_get_irq(pdev, 0);
1181 DRM_ERROR("failed to get irq\n");
1185 rc = devm_request_irq(&pdev->dev, dp->irq, msm_dp_display_irq_handler,
1186 IRQF_TRIGGER_HIGH|IRQF_NO_AUTOEN,
1187 "dp_display_isr", dp);
1190 DRM_ERROR("failed to request IRQ%u: %d\n",
1198 static const struct msm_dp_desc *msm_dp_display_get_desc(struct platform_device *pdev)
1200 const struct msm_dp_desc *descs = of_device_get_match_data(&pdev->dev);
1201 struct resource *res;
1204 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1208 for (i = 0; i < descs[i].io_start; i++) {
1209 if (descs[i].io_start == res->start)
1213 dev_err(&pdev->dev, "unknown displayport instance\n");
1217 static int msm_dp_display_probe_tail(struct device *dev)
1219 struct msm_dp *dp = dev_get_drvdata(dev);
1223 * External bridges are mandatory for eDP interfaces: one has to
1224 * provide at least an eDP panel (which gets wrapped into panel-bridge).
1226 * For DisplayPort interfaces external bridges are optional, so
1227 * silently ignore an error if one is not present (-ENODEV).
1229 dp->next_bridge = devm_drm_of_get_bridge(&dp->pdev->dev, dp->pdev->dev.of_node, 1, 0);
1230 if (IS_ERR(dp->next_bridge)) {
1231 ret = PTR_ERR(dp->next_bridge);
1232 dp->next_bridge = NULL;
1233 if (dp->is_edp || ret != -ENODEV)
1237 ret = component_add(dev, &msm_dp_display_comp_ops);
1239 DRM_ERROR("component add failed, rc=%d\n", ret);
1244 static int msm_dp_auxbus_done_probe(struct drm_dp_aux *aux)
1246 return msm_dp_display_probe_tail(aux->dev);
1249 static int msm_dp_display_get_connector_type(struct platform_device *pdev,
1250 const struct msm_dp_desc *desc)
1252 struct device_node *node = pdev->dev.of_node;
1253 struct device_node *aux_bus = of_get_child_by_name(node, "aux-bus");
1254 struct device_node *panel = of_get_child_by_name(aux_bus, "panel");
1258 connector_type = DRM_MODE_CONNECTOR_eDP;
1260 connector_type = DRM_MODE_SUBCONNECTOR_DisplayPort;
1263 of_node_put(aux_bus);
1265 return connector_type;
1268 static int msm_dp_display_probe(struct platform_device *pdev)
1271 struct msm_dp_display_private *dp;
1272 const struct msm_dp_desc *desc;
1274 if (!pdev || !pdev->dev.of_node) {
1275 DRM_ERROR("pdev not found\n");
1279 dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
1283 desc = msm_dp_display_get_desc(pdev);
1287 dp->msm_dp_display.pdev = pdev;
1289 dp->msm_dp_display.connector_type = msm_dp_display_get_connector_type(pdev, desc);
1290 dp->wide_bus_supported = desc->wide_bus_supported;
1291 dp->msm_dp_display.is_edp =
1292 (dp->msm_dp_display.connector_type == DRM_MODE_CONNECTOR_eDP);
1294 rc = msm_dp_init_sub_modules(dp);
1296 DRM_ERROR("init sub module failed\n");
1297 return -EPROBE_DEFER;
1301 mutex_init(&dp->event_mutex);
1302 init_waitqueue_head(&dp->event_q);
1303 spin_lock_init(&dp->event_lock);
1305 /* Store DP audio handle inside DP display */
1306 dp->msm_dp_display.msm_dp_audio = dp->audio;
1308 init_completion(&dp->audio_comp);
1310 platform_set_drvdata(pdev, &dp->msm_dp_display);
1312 rc = devm_pm_runtime_enable(&pdev->dev);
1316 rc = msm_dp_display_request_irq(dp);
1320 if (dp->msm_dp_display.is_edp) {
1321 rc = devm_of_dp_aux_populate_bus(dp->aux, msm_dp_auxbus_done_probe);
1323 DRM_ERROR("eDP auxbus population failed, rc=%d\n", rc);
1327 rc = msm_dp_display_probe_tail(&pdev->dev);
1335 msm_dp_display_deinit_sub_modules(dp);
1339 static void msm_dp_display_remove(struct platform_device *pdev)
1341 struct msm_dp_display_private *dp = dev_get_dp_display_private(&pdev->dev);
1343 component_del(&pdev->dev, &msm_dp_display_comp_ops);
1344 msm_dp_display_deinit_sub_modules(dp);
1345 platform_set_drvdata(pdev, NULL);
1348 static int msm_dp_pm_runtime_suspend(struct device *dev)
1350 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
1352 disable_irq(dp->irq);
1354 if (dp->msm_dp_display.is_edp) {
1355 msm_dp_display_host_phy_exit(dp);
1356 msm_dp_catalog_ctrl_hpd_disable(dp->catalog);
1358 msm_dp_display_host_deinit(dp);
1363 static int msm_dp_pm_runtime_resume(struct device *dev)
1365 struct msm_dp_display_private *dp = dev_get_dp_display_private(dev);
1368 * for eDP, host cotroller, HPD block and PHY are enabled here
1369 * but with HPD irq disabled
1371 * for DP, only host controller is enabled here.
1372 * HPD block is enabled at msm_dp_bridge_hpd_enable()
1373 * PHY will be enabled at plugin handler later
1375 msm_dp_display_host_init(dp);
1376 if (dp->msm_dp_display.is_edp) {
1377 msm_dp_catalog_ctrl_hpd_enable(dp->catalog);
1378 msm_dp_display_host_phy_init(dp);
1381 enable_irq(dp->irq);
1385 static const struct dev_pm_ops msm_dp_pm_ops = {
1386 SET_RUNTIME_PM_OPS(msm_dp_pm_runtime_suspend, msm_dp_pm_runtime_resume, NULL)
1387 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1388 pm_runtime_force_resume)
1391 static struct platform_driver msm_dp_display_driver = {
1392 .probe = msm_dp_display_probe,
1393 .remove = msm_dp_display_remove,
1395 .name = "msm-dp-display",
1396 .of_match_table = msm_dp_dt_match,
1397 .suppress_bind_attrs = true,
1398 .pm = &msm_dp_pm_ops,
1402 int __init msm_dp_register(void)
1406 ret = platform_driver_register(&msm_dp_display_driver);
1408 DRM_ERROR("Dp display driver register failed");
1413 void __exit msm_dp_unregister(void)
1415 platform_driver_unregister(&msm_dp_display_driver);
1418 bool msm_dp_is_yuv_420_enabled(const struct msm_dp *msm_dp_display,
1419 const struct drm_display_mode *mode)
1421 struct msm_dp_display_private *dp;
1422 const struct drm_display_info *info;
1424 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1425 info = &msm_dp_display->connector->display_info;
1427 return dp->panel->vsc_sdp_supported && drm_mode_is_420_only(info, mode);
1430 bool msm_dp_needs_periph_flush(const struct msm_dp *msm_dp_display,
1431 const struct drm_display_mode *mode)
1433 return msm_dp_is_yuv_420_enabled(msm_dp_display, mode);
1436 bool msm_dp_wide_bus_available(const struct msm_dp *msm_dp_display)
1438 struct msm_dp_display_private *dp;
1440 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1442 if (dp->msm_dp_mode.out_fmt_is_yuv_420)
1445 return dp->wide_bus_supported;
1448 void msm_dp_display_debugfs_init(struct msm_dp *msm_dp_display, struct dentry *root, bool is_edp)
1450 struct msm_dp_display_private *dp;
1454 dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1455 dev = &dp->msm_dp_display.pdev->dev;
1457 rc = msm_dp_debug_init(dev, dp->panel, dp->link, dp->msm_dp_display.connector, root, is_edp);
1459 DRM_ERROR("failed to initialize debug, rc = %d\n", rc);
1462 int msm_dp_modeset_init(struct msm_dp *msm_dp_display, struct drm_device *dev,
1463 struct drm_encoder *encoder, bool yuv_supported)
1465 struct msm_dp_display_private *msm_dp_priv;
1468 msm_dp_display->drm_dev = dev;
1470 msm_dp_priv = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1472 ret = msm_dp_bridge_init(msm_dp_display, dev, encoder, yuv_supported);
1474 DRM_DEV_ERROR(dev->dev,
1475 "failed to create dp bridge: %d\n", ret);
1479 msm_dp_display->connector = msm_dp_drm_connector_init(msm_dp_display, encoder);
1480 if (IS_ERR(msm_dp_display->connector)) {
1481 ret = PTR_ERR(msm_dp_display->connector);
1482 DRM_DEV_ERROR(dev->dev,
1483 "failed to create dp connector: %d\n", ret);
1484 msm_dp_display->connector = NULL;
1488 msm_dp_priv->panel->connector = msm_dp_display->connector;
1493 void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge,
1494 struct drm_bridge_state *old_bridge_state)
1496 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1497 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1499 struct msm_dp_display_private *msm_dp_display;
1501 bool force_link_train = false;
1503 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1504 if (!msm_dp_display->msm_dp_mode.drm_mode.clock) {
1505 DRM_ERROR("invalid params\n");
1510 msm_dp_hpd_plug_handle(msm_dp_display, 0);
1512 mutex_lock(&msm_dp_display->event_mutex);
1513 if (pm_runtime_resume_and_get(&dp->pdev->dev)) {
1514 DRM_ERROR("failed to pm_runtime_resume\n");
1515 mutex_unlock(&msm_dp_display->event_mutex);
1519 state = msm_dp_display->hpd_state;
1520 if (state != ST_DISPLAY_OFF && state != ST_MAINLINK_READY) {
1521 mutex_unlock(&msm_dp_display->event_mutex);
1525 rc = msm_dp_display_set_mode(dp, &msm_dp_display->msm_dp_mode);
1527 DRM_ERROR("Failed to perform a mode set, rc=%d\n", rc);
1528 mutex_unlock(&msm_dp_display->event_mutex);
1532 state = msm_dp_display->hpd_state;
1534 if (state == ST_DISPLAY_OFF) {
1535 msm_dp_display_host_phy_init(msm_dp_display);
1536 force_link_train = true;
1539 msm_dp_display_enable(msm_dp_display, force_link_train);
1541 rc = msm_dp_display_post_enable(dp);
1543 DRM_ERROR("DP display post enable failed, rc=%d\n", rc);
1544 msm_dp_display_disable(msm_dp_display);
1547 /* completed connection */
1548 msm_dp_display->hpd_state = ST_CONNECTED;
1550 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1551 mutex_unlock(&msm_dp_display->event_mutex);
1554 void msm_dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
1555 struct drm_bridge_state *old_bridge_state)
1557 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1558 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1559 struct msm_dp_display_private *msm_dp_display;
1561 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1563 msm_dp_ctrl_push_idle(msm_dp_display->ctrl);
1566 void msm_dp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,
1567 struct drm_bridge_state *old_bridge_state)
1569 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1570 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1572 struct msm_dp_display_private *msm_dp_display;
1574 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1577 msm_dp_hpd_unplug_handle(msm_dp_display, 0);
1579 mutex_lock(&msm_dp_display->event_mutex);
1581 state = msm_dp_display->hpd_state;
1582 if (state != ST_DISCONNECT_PENDING && state != ST_CONNECTED)
1583 drm_dbg_dp(dp->drm_dev, "type=%d wrong hpd_state=%d\n",
1584 dp->connector_type, state);
1586 msm_dp_display_disable(msm_dp_display);
1588 state = msm_dp_display->hpd_state;
1589 if (state == ST_DISCONNECT_PENDING) {
1590 /* completed disconnection */
1591 msm_dp_display->hpd_state = ST_DISCONNECTED;
1593 msm_dp_display->hpd_state = ST_DISPLAY_OFF;
1596 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1598 pm_runtime_put_sync(&dp->pdev->dev);
1599 mutex_unlock(&msm_dp_display->event_mutex);
1602 void msm_dp_bridge_mode_set(struct drm_bridge *drm_bridge,
1603 const struct drm_display_mode *mode,
1604 const struct drm_display_mode *adjusted_mode)
1606 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
1607 struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
1608 struct msm_dp_display_private *msm_dp_display;
1609 struct msm_dp_panel *msm_dp_panel;
1611 msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
1612 msm_dp_panel = msm_dp_display->panel;
1614 memset(&msm_dp_display->msm_dp_mode, 0x0, sizeof(struct msm_dp_display_mode));
1616 if (msm_dp_display_check_video_test(dp))
1617 msm_dp_display->msm_dp_mode.bpp = msm_dp_display_get_test_bpp(dp);
1618 else /* Default num_components per pixel = 3 */
1619 msm_dp_display->msm_dp_mode.bpp = dp->connector->display_info.bpc * 3;
1621 if (!msm_dp_display->msm_dp_mode.bpp)
1622 msm_dp_display->msm_dp_mode.bpp = 24; /* Default bpp */
1624 drm_mode_copy(&msm_dp_display->msm_dp_mode.drm_mode, adjusted_mode);
1626 msm_dp_display->msm_dp_mode.v_active_low =
1627 !!(msm_dp_display->msm_dp_mode.drm_mode.flags & DRM_MODE_FLAG_NVSYNC);
1629 msm_dp_display->msm_dp_mode.h_active_low =
1630 !!(msm_dp_display->msm_dp_mode.drm_mode.flags & DRM_MODE_FLAG_NHSYNC);
1632 msm_dp_display->msm_dp_mode.out_fmt_is_yuv_420 =
1633 drm_mode_is_420_only(&dp->connector->display_info, adjusted_mode) &&
1634 msm_dp_panel->vsc_sdp_supported;
1636 /* populate wide_bus_support to different layers */
1637 msm_dp_display->ctrl->wide_bus_en =
1638 msm_dp_display->msm_dp_mode.out_fmt_is_yuv_420 ? false : msm_dp_display->wide_bus_supported;
1639 msm_dp_display->catalog->wide_bus_en =
1640 msm_dp_display->msm_dp_mode.out_fmt_is_yuv_420 ? false : msm_dp_display->wide_bus_supported;
1643 void msm_dp_bridge_hpd_enable(struct drm_bridge *bridge)
1645 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(bridge);
1646 struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display;
1647 struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1650 * this is for external DP with hpd irq enabled case,
1651 * step-1: msm_dp_pm_runtime_resume() enable dp host only
1652 * step-2: enable hdp block and have hpd irq enabled here
1653 * step-3: waiting for plugin irq while phy is not initialized
1654 * step-4: DP PHY is initialized at plugin handler before link training
1657 mutex_lock(&dp->event_mutex);
1658 if (pm_runtime_resume_and_get(&msm_dp_display->pdev->dev)) {
1659 DRM_ERROR("failed to resume power\n");
1660 mutex_unlock(&dp->event_mutex);
1664 msm_dp_catalog_ctrl_hpd_enable(dp->catalog);
1666 /* enable HDP interrupts */
1667 msm_dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, true);
1669 msm_dp_display->internal_hpd = true;
1670 mutex_unlock(&dp->event_mutex);
1673 void msm_dp_bridge_hpd_disable(struct drm_bridge *bridge)
1675 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(bridge);
1676 struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display;
1677 struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1679 mutex_lock(&dp->event_mutex);
1680 /* disable HDP interrupts */
1681 msm_dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, false);
1682 msm_dp_catalog_ctrl_hpd_disable(dp->catalog);
1684 msm_dp_display->internal_hpd = false;
1686 pm_runtime_put_sync(&msm_dp_display->pdev->dev);
1687 mutex_unlock(&dp->event_mutex);
1690 void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
1691 enum drm_connector_status status)
1693 struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(bridge);
1694 struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display;
1695 struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display);
1697 /* Without next_bridge interrupts are handled by the DP core directly */
1698 if (msm_dp_display->internal_hpd)
1701 if (!msm_dp_display->link_ready && status == connector_status_connected)
1702 msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1703 else if (msm_dp_display->link_ready && status == connector_status_disconnected)
1704 msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);