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/delay.h>
13 #include <drm/display/drm_dp_aux_bus.h>
14 #include <drm/drm_edid.h>
18 #include "dp_parser.h"
20 #include "dp_catalog.h"
26 #include "dp_display.h"
31 static bool psr_enabled = false;
32 module_param(psr_enabled, bool, 0);
33 MODULE_PARM_DESC(psr_enabled, "enable PSR for eDP and DP displays");
35 #define HPD_STRING_SIZE 30
42 ISR_IRQ_HPD_PULSE_COUNT,
43 ISR_HPD_LO_GLITH_COUNT,
46 /* event thread connection state */
51 ST_DISCONNECT_PENDING,
64 #define EVENT_TIMEOUT (HZ/10) /* 100ms */
65 #define DP_EVENT_Q_MAX 8
67 #define DP_TIMEOUT_NONE 0
69 #define WAIT_FOR_RESUME_TIMEOUT_JIFFIES (HZ / 2)
77 struct dp_display_private {
84 bool core_initialized;
89 struct drm_device *drm_dev;
92 struct dp_parser *parser;
93 struct dp_power *power;
94 struct dp_catalog *catalog;
95 struct drm_dp_aux *aux;
97 struct dp_panel *panel;
99 struct dp_debug *debug;
101 struct dp_display_mode dp_mode;
102 struct msm_dp dp_display;
104 /* wait for audio signaling */
105 struct completion audio_comp;
107 /* event related only access by event thread */
108 struct mutex event_mutex;
109 wait_queue_head_t event_q;
113 struct task_struct *ev_tsk;
114 struct dp_event event_list[DP_EVENT_Q_MAX];
115 spinlock_t event_lock;
119 struct dp_audio *audio;
123 phys_addr_t io_start;
125 unsigned int connector_type;
129 static const struct msm_dp_desc sc7180_dp_descs[] = {
130 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
134 static const struct msm_dp_desc sc7280_dp_descs[] = {
135 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
136 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
140 static const struct msm_dp_desc sc8180x_dp_descs[] = {
141 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
142 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
143 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_eDP },
147 static const struct msm_dp_desc sc8280xp_dp_descs[] = {
148 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
149 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
150 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
151 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
152 { .io_start = 0x22090000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
153 { .io_start = 0x22098000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
154 { .io_start = 0x2209a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
155 { .io_start = 0x220a0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
159 static const struct msm_dp_desc sc8280xp_edp_descs[] = {
160 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
161 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
162 { .io_start = 0x2209a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
163 { .io_start = 0x220a0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
167 static const struct msm_dp_desc sm8350_dp_descs[] = {
168 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
172 static const struct msm_dp_desc sm8650_dp_descs[] = {
173 { .io_start = 0x0af54000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
177 static const struct of_device_id dp_dt_match[] = {
178 { .compatible = "qcom,sc7180-dp", .data = &sc7180_dp_descs },
179 { .compatible = "qcom,sc7280-dp", .data = &sc7280_dp_descs },
180 { .compatible = "qcom,sc7280-edp", .data = &sc7280_dp_descs },
181 { .compatible = "qcom,sc8180x-dp", .data = &sc8180x_dp_descs },
182 { .compatible = "qcom,sc8180x-edp", .data = &sc8180x_dp_descs },
183 { .compatible = "qcom,sc8280xp-dp", .data = &sc8280xp_dp_descs },
184 { .compatible = "qcom,sc8280xp-edp", .data = &sc8280xp_edp_descs },
185 { .compatible = "qcom,sdm845-dp", .data = &sc7180_dp_descs },
186 { .compatible = "qcom,sm8350-dp", .data = &sm8350_dp_descs },
187 { .compatible = "qcom,sm8650-dp", .data = &sm8650_dp_descs },
191 static struct dp_display_private *dev_get_dp_display_private(struct device *dev)
193 struct msm_dp *dp = dev_get_drvdata(dev);
195 return container_of(dp, struct dp_display_private, dp_display);
198 static int dp_add_event(struct dp_display_private *dp_priv, u32 event,
202 struct dp_event *todo;
205 spin_lock_irqsave(&dp_priv->event_lock, flag);
206 pndx = dp_priv->event_pndx + 1;
207 pndx %= DP_EVENT_Q_MAX;
208 if (pndx == dp_priv->event_gndx) {
209 pr_err("event_q is full: pndx=%d gndx=%d\n",
210 dp_priv->event_pndx, dp_priv->event_gndx);
211 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
214 todo = &dp_priv->event_list[dp_priv->event_pndx++];
215 dp_priv->event_pndx %= DP_EVENT_Q_MAX;
216 todo->event_id = event;
219 wake_up(&dp_priv->event_q);
220 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
225 static int dp_del_event(struct dp_display_private *dp_priv, u32 event)
228 struct dp_event *todo;
231 spin_lock_irqsave(&dp_priv->event_lock, flag);
232 if (dp_priv->event_pndx == dp_priv->event_gndx) {
233 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
237 gndx = dp_priv->event_gndx;
238 while (dp_priv->event_pndx != gndx) {
239 todo = &dp_priv->event_list[gndx];
240 if (todo->event_id == event) {
241 todo->event_id = EV_NO_EVENT; /* deleted */
245 gndx %= DP_EVENT_Q_MAX;
247 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
252 void dp_display_signal_audio_start(struct msm_dp *dp_display)
254 struct dp_display_private *dp;
256 dp = container_of(dp_display, struct dp_display_private, dp_display);
258 reinit_completion(&dp->audio_comp);
261 void dp_display_signal_audio_complete(struct msm_dp *dp_display)
263 struct dp_display_private *dp;
265 dp = container_of(dp_display, struct dp_display_private, dp_display);
267 complete_all(&dp->audio_comp);
270 static int dp_hpd_event_thread_start(struct dp_display_private *dp_priv);
272 static int dp_display_bind(struct device *dev, struct device *master,
276 struct dp_display_private *dp = dev_get_dp_display_private(dev);
277 struct msm_drm_private *priv = dev_get_drvdata(master);
278 struct drm_device *drm = priv->dev;
280 dp->dp_display.drm_dev = drm;
281 priv->dp[dp->id] = &dp->dp_display;
286 dp->aux->drm_dev = drm;
287 rc = dp_aux_register(dp->aux);
289 DRM_ERROR("DRM DP AUX register failed\n");
294 rc = dp_register_audio_driver(dev, dp->audio);
296 DRM_ERROR("Audio registration Dp failed\n");
300 rc = dp_hpd_event_thread_start(dp);
302 DRM_ERROR("Event thread create failed\n");
311 static void dp_display_unbind(struct device *dev, struct device *master,
314 struct dp_display_private *dp = dev_get_dp_display_private(dev);
315 struct msm_drm_private *priv = dev_get_drvdata(master);
317 kthread_stop(dp->ev_tsk);
319 of_dp_aux_depopulate_bus(dp->aux);
321 dp_unregister_audio_driver(dev, dp->audio);
322 dp_aux_unregister(dp->aux);
324 dp->aux->drm_dev = NULL;
325 priv->dp[dp->id] = NULL;
328 static const struct component_ops dp_display_comp_ops = {
329 .bind = dp_display_bind,
330 .unbind = dp_display_unbind,
333 static int dp_display_send_hpd_notification(struct dp_display_private *dp,
336 struct drm_bridge *bridge = dp->dp_display.bridge;
338 /* reset video pattern flag on disconnect */
340 dp->panel->video_test = false;
341 if (!dp->dp_display.is_edp)
342 drm_dp_set_subconnector_property(dp->dp_display.connector,
343 connector_status_disconnected,
345 dp->panel->downstream_ports);
348 dp->dp_display.link_ready = hpd;
350 drm_dbg_dp(dp->drm_dev, "type=%d hpd=%d\n",
351 dp->dp_display.connector_type, hpd);
352 drm_bridge_hpd_notify(bridge, dp->dp_display.link_ready);
357 static int dp_display_process_hpd_high(struct dp_display_private *dp)
362 dp->panel->max_dp_lanes = dp->parser->max_dp_lanes;
363 dp->panel->max_dp_link_rate = dp->parser->max_dp_link_rate;
365 drm_dbg_dp(dp->drm_dev, "max_lanes=%d max_link_rate=%d\n",
366 dp->panel->max_dp_lanes, dp->panel->max_dp_link_rate);
368 rc = dp_panel_read_sink_caps(dp->panel, dp->dp_display.connector);
372 dp_link_process_request(dp->link);
374 if (!dp->dp_display.is_edp)
375 drm_dp_set_subconnector_property(dp->dp_display.connector,
376 connector_status_connected,
378 dp->panel->downstream_ports);
380 edid = dp->panel->edid;
382 dp->dp_display.psr_supported = dp->panel->psr_cap.version && psr_enabled;
384 dp->audio_supported = drm_detect_monitor_audio(edid);
385 dp_panel_handle_sink_request(dp->panel);
387 dp->dp_display.max_dp_lanes = dp->parser->max_dp_lanes;
390 * set sink to normal operation mode -- D0
393 dp_link_psm_config(dp->link, &dp->panel->link_info, false);
395 dp_link_reset_phy_params_vx_px(dp->link);
396 rc = dp_ctrl_on_link(dp->ctrl);
398 DRM_ERROR("failed to complete DP link training\n");
402 dp_add_event(dp, EV_USER_NOTIFICATION, true, 0);
408 static void dp_display_host_phy_init(struct dp_display_private *dp)
410 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
411 dp->dp_display.connector_type, dp->core_initialized,
412 dp->phy_initialized);
414 if (!dp->phy_initialized) {
415 dp_ctrl_phy_init(dp->ctrl);
416 dp->phy_initialized = true;
420 static void dp_display_host_phy_exit(struct dp_display_private *dp)
422 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
423 dp->dp_display.connector_type, dp->core_initialized,
424 dp->phy_initialized);
426 if (dp->phy_initialized) {
427 dp_ctrl_phy_exit(dp->ctrl);
428 dp->phy_initialized = false;
432 static void dp_display_host_init(struct dp_display_private *dp)
434 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
435 dp->dp_display.connector_type, dp->core_initialized,
436 dp->phy_initialized);
438 dp_power_init(dp->power);
439 dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
440 dp_aux_init(dp->aux);
441 dp->core_initialized = true;
444 static void dp_display_host_deinit(struct dp_display_private *dp)
446 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
447 dp->dp_display.connector_type, dp->core_initialized,
448 dp->phy_initialized);
450 dp_ctrl_reset_irq_ctrl(dp->ctrl, false);
451 dp_aux_deinit(dp->aux);
452 dp_power_deinit(dp->power);
453 dp->core_initialized = false;
456 static int dp_display_usbpd_configure_cb(struct device *dev)
458 struct dp_display_private *dp = dev_get_dp_display_private(dev);
460 dp_display_host_phy_init(dp);
462 return dp_display_process_hpd_high(dp);
465 static int dp_display_notify_disconnect(struct device *dev)
467 struct dp_display_private *dp = dev_get_dp_display_private(dev);
469 dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
474 static void dp_display_handle_video_request(struct dp_display_private *dp)
476 if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
477 dp->panel->video_test = true;
478 dp_link_send_test_response(dp->link);
482 static int dp_display_handle_port_ststus_changed(struct dp_display_private *dp)
486 if (drm_dp_is_branch(dp->panel->dpcd) && dp->link->sink_count == 0) {
487 drm_dbg_dp(dp->drm_dev, "sink count is zero, nothing to do\n");
488 if (dp->hpd_state != ST_DISCONNECTED) {
489 dp->hpd_state = ST_DISCONNECT_PENDING;
490 dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
493 if (dp->hpd_state == ST_DISCONNECTED) {
494 dp->hpd_state = ST_MAINLINK_READY;
495 rc = dp_display_process_hpd_high(dp);
497 dp->hpd_state = ST_DISCONNECTED;
504 static int dp_display_handle_irq_hpd(struct dp_display_private *dp)
506 u32 sink_request = dp->link->sink_request;
508 drm_dbg_dp(dp->drm_dev, "%d\n", sink_request);
509 if (dp->hpd_state == ST_DISCONNECTED) {
510 if (sink_request & DP_LINK_STATUS_UPDATED) {
511 drm_dbg_dp(dp->drm_dev, "Disconnected sink_request: %d\n",
513 DRM_ERROR("Disconnected, no DP_LINK_STATUS_UPDATED\n");
518 dp_ctrl_handle_sink_request(dp->ctrl);
520 if (sink_request & DP_TEST_LINK_VIDEO_PATTERN)
521 dp_display_handle_video_request(dp);
526 static int dp_display_usbpd_attention_cb(struct device *dev)
530 struct dp_display_private *dp = dev_get_dp_display_private(dev);
532 /* check for any test request issued by sink */
533 rc = dp_link_process_request(dp->link);
535 sink_request = dp->link->sink_request;
536 drm_dbg_dp(dp->drm_dev, "hpd_state=%d sink_request=%d\n",
537 dp->hpd_state, sink_request);
538 if (sink_request & DS_PORT_STATUS_CHANGED)
539 rc = dp_display_handle_port_ststus_changed(dp);
541 rc = dp_display_handle_irq_hpd(dp);
547 static int dp_hpd_plug_handle(struct dp_display_private *dp, u32 data)
551 struct platform_device *pdev = dp->dp_display.pdev;
553 mutex_lock(&dp->event_mutex);
555 state = dp->hpd_state;
556 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
557 dp->dp_display.connector_type, state);
559 if (state == ST_DISPLAY_OFF) {
560 mutex_unlock(&dp->event_mutex);
564 if (state == ST_MAINLINK_READY || state == ST_CONNECTED) {
565 mutex_unlock(&dp->event_mutex);
569 if (state == ST_DISCONNECT_PENDING) {
570 /* wait until ST_DISCONNECTED */
571 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 1); /* delay = 1 */
572 mutex_unlock(&dp->event_mutex);
576 ret = pm_runtime_resume_and_get(&pdev->dev);
578 DRM_ERROR("failed to pm_runtime_resume\n");
579 mutex_unlock(&dp->event_mutex);
583 ret = dp_display_usbpd_configure_cb(&pdev->dev);
584 if (ret) { /* link train failed */
585 dp->hpd_state = ST_DISCONNECTED;
587 dp->hpd_state = ST_MAINLINK_READY;
590 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
591 dp->dp_display.connector_type, state);
592 mutex_unlock(&dp->event_mutex);
594 /* uevent will complete connection part */
598 static void dp_display_handle_plugged_change(struct msm_dp *dp_display,
601 struct dp_display_private *dp;
603 dp = container_of(dp_display,
604 struct dp_display_private, dp_display);
606 /* notify audio subsystem only if sink supports audio */
607 if (dp_display->plugged_cb && dp_display->codec_dev &&
609 dp_display->plugged_cb(dp_display->codec_dev, plugged);
612 static int dp_hpd_unplug_handle(struct dp_display_private *dp, u32 data)
615 struct platform_device *pdev = dp->dp_display.pdev;
617 mutex_lock(&dp->event_mutex);
619 state = dp->hpd_state;
621 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
622 dp->dp_display.connector_type, state);
624 /* unplugged, no more irq_hpd handle */
625 dp_del_event(dp, EV_IRQ_HPD_INT);
627 if (state == ST_DISCONNECTED) {
628 /* triggered by irq_hdp with sink_count = 0 */
629 if (dp->link->sink_count == 0) {
630 dp_display_host_phy_exit(dp);
632 dp_display_notify_disconnect(&dp->dp_display.pdev->dev);
633 mutex_unlock(&dp->event_mutex);
635 } else if (state == ST_DISCONNECT_PENDING) {
636 mutex_unlock(&dp->event_mutex);
638 } else if (state == ST_MAINLINK_READY) {
639 dp_ctrl_off_link(dp->ctrl);
640 dp_display_host_phy_exit(dp);
641 dp->hpd_state = ST_DISCONNECTED;
642 dp_display_notify_disconnect(&dp->dp_display.pdev->dev);
643 mutex_unlock(&dp->event_mutex);
648 * We don't need separate work for disconnect as
649 * connect/attention interrupts are disabled
651 dp_display_notify_disconnect(&dp->dp_display.pdev->dev);
653 if (state == ST_DISPLAY_OFF) {
654 dp->hpd_state = ST_DISCONNECTED;
656 dp->hpd_state = ST_DISCONNECT_PENDING;
659 /* signal the disconnect event early to ensure proper teardown */
660 dp_display_handle_plugged_change(&dp->dp_display, false);
662 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
663 dp->dp_display.connector_type, state);
665 /* uevent will complete disconnection part */
666 pm_runtime_put_sync(&pdev->dev);
667 mutex_unlock(&dp->event_mutex);
671 static int dp_irq_hpd_handle(struct dp_display_private *dp, u32 data)
675 mutex_lock(&dp->event_mutex);
677 /* irq_hpd can happen at either connected or disconnected state */
678 state = dp->hpd_state;
679 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
680 dp->dp_display.connector_type, state);
682 if (state == ST_DISPLAY_OFF) {
683 mutex_unlock(&dp->event_mutex);
687 if (state == ST_MAINLINK_READY || state == ST_DISCONNECT_PENDING) {
688 /* wait until ST_CONNECTED */
689 dp_add_event(dp, EV_IRQ_HPD_INT, 0, 1); /* delay = 1 */
690 mutex_unlock(&dp->event_mutex);
694 dp_display_usbpd_attention_cb(&dp->dp_display.pdev->dev);
696 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
697 dp->dp_display.connector_type, state);
699 mutex_unlock(&dp->event_mutex);
704 static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
706 dp_audio_put(dp->audio);
707 dp_panel_put(dp->panel);
711 static int dp_init_sub_modules(struct dp_display_private *dp)
714 struct device *dev = &dp->dp_display.pdev->dev;
715 struct dp_panel_in panel_in = {
719 dp->parser = dp_parser_get(dp->dp_display.pdev);
720 if (IS_ERR(dp->parser)) {
721 rc = PTR_ERR(dp->parser);
722 DRM_ERROR("failed to initialize parser, rc = %d\n", rc);
727 dp->catalog = dp_catalog_get(dev, &dp->parser->io);
728 if (IS_ERR(dp->catalog)) {
729 rc = PTR_ERR(dp->catalog);
730 DRM_ERROR("failed to initialize catalog, rc = %d\n", rc);
735 dp->power = dp_power_get(dev, dp->parser);
736 if (IS_ERR(dp->power)) {
737 rc = PTR_ERR(dp->power);
738 DRM_ERROR("failed to initialize power, rc = %d\n", rc);
743 dp->aux = dp_aux_get(dev, dp->catalog, dp->dp_display.is_edp);
744 if (IS_ERR(dp->aux)) {
745 rc = PTR_ERR(dp->aux);
746 DRM_ERROR("failed to initialize aux, rc = %d\n", rc);
751 dp->link = dp_link_get(dev, dp->aux);
752 if (IS_ERR(dp->link)) {
753 rc = PTR_ERR(dp->link);
754 DRM_ERROR("failed to initialize link, rc = %d\n", rc);
759 panel_in.aux = dp->aux;
760 panel_in.catalog = dp->catalog;
761 panel_in.link = dp->link;
763 dp->panel = dp_panel_get(&panel_in);
764 if (IS_ERR(dp->panel)) {
765 rc = PTR_ERR(dp->panel);
766 DRM_ERROR("failed to initialize panel, rc = %d\n", rc);
771 dp->ctrl = dp_ctrl_get(dev, dp->link, dp->panel, dp->aux,
772 dp->power, dp->catalog, dp->parser);
773 if (IS_ERR(dp->ctrl)) {
774 rc = PTR_ERR(dp->ctrl);
775 DRM_ERROR("failed to initialize ctrl, rc = %d\n", rc);
780 dp->audio = dp_audio_get(dp->dp_display.pdev, dp->panel, dp->catalog);
781 if (IS_ERR(dp->audio)) {
782 rc = PTR_ERR(dp->audio);
783 pr_err("failed to initialize audio, rc = %d\n", rc);
788 /* populate wide_bus_en to differernt layers */
789 dp->ctrl->wide_bus_en = dp->wide_bus_en;
790 dp->catalog->wide_bus_en = dp->wide_bus_en;
795 dp_panel_put(dp->panel);
802 static int dp_display_set_mode(struct msm_dp *dp_display,
803 struct dp_display_mode *mode)
805 struct dp_display_private *dp;
807 dp = container_of(dp_display, struct dp_display_private, dp_display);
809 drm_mode_copy(&dp->panel->dp_mode.drm_mode, &mode->drm_mode);
810 dp->panel->dp_mode.bpp = mode->bpp;
811 dp->panel->dp_mode.capabilities = mode->capabilities;
812 dp_panel_init_panel_info(dp->panel);
816 static int dp_display_enable(struct dp_display_private *dp, bool force_link_train)
819 struct msm_dp *dp_display = &dp->dp_display;
821 drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
822 if (dp_display->power_on) {
823 drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
827 rc = dp_ctrl_on_stream(dp->ctrl, force_link_train);
829 dp_display->power_on = true;
834 static int dp_display_post_enable(struct msm_dp *dp_display)
836 struct dp_display_private *dp;
839 dp = container_of(dp_display, struct dp_display_private, dp_display);
841 rate = dp->link->link_params.rate;
843 if (dp->audio_supported) {
844 dp->audio->bw_code = drm_dp_link_rate_to_bw_code(rate);
845 dp->audio->lane_count = dp->link->link_params.num_lanes;
848 /* signal the connect event late to synchronize video and display */
849 dp_display_handle_plugged_change(dp_display, true);
851 if (dp_display->psr_supported)
852 dp_ctrl_config_psr(dp->ctrl);
857 static int dp_display_disable(struct dp_display_private *dp)
859 struct msm_dp *dp_display = &dp->dp_display;
861 if (!dp_display->power_on)
864 /* wait only if audio was enabled */
865 if (dp_display->audio_enabled) {
866 /* signal the disconnect event */
867 dp_display_handle_plugged_change(dp_display, false);
868 if (!wait_for_completion_timeout(&dp->audio_comp,
870 DRM_ERROR("audio comp timeout\n");
873 dp_display->audio_enabled = false;
875 if (dp->link->sink_count == 0) {
877 * irq_hpd with sink_count = 0
878 * hdmi unplugged out of dongle
880 dp_ctrl_off_link_stream(dp->ctrl);
883 * unplugged interrupt
884 * dongle unplugged out of DUT
886 dp_ctrl_off(dp->ctrl);
887 dp_display_host_phy_exit(dp);
890 dp_display->power_on = false;
892 drm_dbg_dp(dp->drm_dev, "sink count: %d\n", dp->link->sink_count);
896 int dp_display_set_plugged_cb(struct msm_dp *dp_display,
897 hdmi_codec_plugged_cb fn, struct device *codec_dev)
901 dp_display->plugged_cb = fn;
902 dp_display->codec_dev = codec_dev;
903 plugged = dp_display->link_ready;
904 dp_display_handle_plugged_change(dp_display, plugged);
910 * dp_bridge_mode_valid - callback to determine if specified mode is valid
911 * @bridge: Pointer to drm bridge structure
912 * @info: display info
913 * @mode: Pointer to drm mode structure
914 * Returns: Validity status for specified mode
916 enum drm_mode_status dp_bridge_mode_valid(struct drm_bridge *bridge,
917 const struct drm_display_info *info,
918 const struct drm_display_mode *mode)
920 const u32 num_components = 3, default_bpp = 24;
921 struct dp_display_private *dp_display;
922 struct dp_link_info *link_info;
923 u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
925 int mode_pclk_khz = mode->clock;
927 dp = to_dp_bridge(bridge)->dp_display;
929 if (!dp || !mode_pclk_khz || !dp->connector) {
930 DRM_ERROR("invalid params\n");
934 if (mode->clock > DP_MAX_PIXEL_CLK_KHZ)
935 return MODE_CLOCK_HIGH;
937 dp_display = container_of(dp, struct dp_display_private, dp_display);
938 link_info = &dp_display->panel->link_info;
940 mode_bpp = dp->connector->display_info.bpc * num_components;
942 mode_bpp = default_bpp;
944 mode_bpp = dp_panel_get_mode_bpp(dp_display->panel,
945 mode_bpp, mode_pclk_khz);
947 mode_rate_khz = mode_pclk_khz * mode_bpp;
948 supported_rate_khz = link_info->num_lanes * link_info->rate * 8;
950 if (mode_rate_khz > supported_rate_khz)
956 int dp_display_get_modes(struct msm_dp *dp)
958 struct dp_display_private *dp_display;
961 DRM_ERROR("invalid params\n");
965 dp_display = container_of(dp, struct dp_display_private, dp_display);
967 return dp_panel_get_modes(dp_display->panel,
971 bool dp_display_check_video_test(struct msm_dp *dp)
973 struct dp_display_private *dp_display;
975 dp_display = container_of(dp, struct dp_display_private, dp_display);
977 return dp_display->panel->video_test;
980 int dp_display_get_test_bpp(struct msm_dp *dp)
982 struct dp_display_private *dp_display;
985 DRM_ERROR("invalid params\n");
989 dp_display = container_of(dp, struct dp_display_private, dp_display);
991 return dp_link_bit_depth_to_bpp(
992 dp_display->link->test_video.test_bit_depth);
995 void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)
997 struct dp_display_private *dp_display;
999 dp_display = container_of(dp, struct dp_display_private, dp_display);
1002 * if we are reading registers we need the link clocks to be on
1003 * however till DP cable is connected this will not happen as we
1004 * do not know the resolution to power up with. Hence check the
1005 * power_on status before dumping DP registers to avoid crash due
1006 * to unclocked access
1008 mutex_lock(&dp_display->event_mutex);
1010 if (!dp->power_on) {
1011 mutex_unlock(&dp_display->event_mutex);
1015 dp_catalog_snapshot(dp_display->catalog, disp_state);
1017 mutex_unlock(&dp_display->event_mutex);
1020 void dp_display_set_psr(struct msm_dp *dp_display, bool enter)
1022 struct dp_display_private *dp;
1025 DRM_ERROR("invalid params\n");
1029 dp = container_of(dp_display, struct dp_display_private, dp_display);
1030 dp_ctrl_set_psr(dp->ctrl, enter);
1033 static int hpd_event_thread(void *data)
1035 struct dp_display_private *dp_priv;
1037 struct dp_event *todo;
1038 int timeout_mode = 0;
1040 dp_priv = (struct dp_display_private *)data;
1044 wait_event_timeout(dp_priv->event_q,
1045 (dp_priv->event_pndx == dp_priv->event_gndx) ||
1046 kthread_should_stop(), EVENT_TIMEOUT);
1048 wait_event_interruptible(dp_priv->event_q,
1049 (dp_priv->event_pndx != dp_priv->event_gndx) ||
1050 kthread_should_stop());
1053 if (kthread_should_stop())
1056 spin_lock_irqsave(&dp_priv->event_lock, flag);
1057 todo = &dp_priv->event_list[dp_priv->event_gndx];
1059 struct dp_event *todo_next;
1061 dp_priv->event_gndx++;
1062 dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1064 /* re enter delay event into q */
1065 todo_next = &dp_priv->event_list[dp_priv->event_pndx++];
1066 dp_priv->event_pndx %= DP_EVENT_Q_MAX;
1067 todo_next->event_id = todo->event_id;
1068 todo_next->data = todo->data;
1069 todo_next->delay = todo->delay - 1;
1071 /* clean up older event */
1072 todo->event_id = EV_NO_EVENT;
1075 /* switch to timeout mode */
1077 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1081 /* timeout with no events in q */
1082 if (dp_priv->event_pndx == dp_priv->event_gndx) {
1083 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1087 dp_priv->event_gndx++;
1088 dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1090 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1092 switch (todo->event_id) {
1093 case EV_HPD_PLUG_INT:
1094 dp_hpd_plug_handle(dp_priv, todo->data);
1096 case EV_HPD_UNPLUG_INT:
1097 dp_hpd_unplug_handle(dp_priv, todo->data);
1099 case EV_IRQ_HPD_INT:
1100 dp_irq_hpd_handle(dp_priv, todo->data);
1102 case EV_USER_NOTIFICATION:
1103 dp_display_send_hpd_notification(dp_priv,
1114 static int dp_hpd_event_thread_start(struct dp_display_private *dp_priv)
1116 /* set event q to empty */
1117 dp_priv->event_gndx = 0;
1118 dp_priv->event_pndx = 0;
1120 dp_priv->ev_tsk = kthread_run(hpd_event_thread, dp_priv, "dp_hpd_handler");
1121 if (IS_ERR(dp_priv->ev_tsk))
1122 return PTR_ERR(dp_priv->ev_tsk);
1127 static irqreturn_t dp_display_irq_handler(int irq, void *dev_id)
1129 struct dp_display_private *dp = dev_id;
1130 irqreturn_t ret = IRQ_NONE;
1134 DRM_ERROR("invalid data\n");
1138 hpd_isr_status = dp_catalog_hpd_get_intr_status(dp->catalog);
1140 if (hpd_isr_status & 0x0F) {
1141 drm_dbg_dp(dp->drm_dev, "type=%d isr=0x%x\n",
1142 dp->dp_display.connector_type, hpd_isr_status);
1143 /* hpd related interrupts */
1144 if (hpd_isr_status & DP_DP_HPD_PLUG_INT_MASK)
1145 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1147 if (hpd_isr_status & DP_DP_IRQ_HPD_INT_MASK) {
1148 dp_add_event(dp, EV_IRQ_HPD_INT, 0, 0);
1151 if (hpd_isr_status & DP_DP_HPD_REPLUG_INT_MASK) {
1152 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1153 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 3);
1156 if (hpd_isr_status & DP_DP_HPD_UNPLUG_INT_MASK)
1157 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1162 /* DP controller isr */
1163 ret |= dp_ctrl_isr(dp->ctrl);
1166 ret |= dp_aux_isr(dp->aux);
1171 static int dp_display_request_irq(struct dp_display_private *dp)
1174 struct platform_device *pdev = dp->dp_display.pdev;
1176 dp->irq = platform_get_irq(pdev, 0);
1178 DRM_ERROR("failed to get irq\n");
1182 rc = devm_request_irq(&pdev->dev, dp->irq, dp_display_irq_handler,
1183 IRQF_TRIGGER_HIGH|IRQF_NO_AUTOEN,
1184 "dp_display_isr", dp);
1187 DRM_ERROR("failed to request IRQ%u: %d\n",
1195 static const struct msm_dp_desc *dp_display_get_desc(struct platform_device *pdev)
1197 const struct msm_dp_desc *descs = of_device_get_match_data(&pdev->dev);
1198 struct resource *res;
1201 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1205 for (i = 0; i < descs[i].io_start; i++) {
1206 if (descs[i].io_start == res->start)
1210 dev_err(&pdev->dev, "unknown displayport instance\n");
1214 static int dp_display_get_next_bridge(struct msm_dp *dp);
1216 static int dp_display_probe_tail(struct device *dev)
1218 struct msm_dp *dp = dev_get_drvdata(dev);
1221 ret = dp_display_get_next_bridge(dp);
1225 ret = component_add(dev, &dp_display_comp_ops);
1227 DRM_ERROR("component add failed, rc=%d\n", ret);
1232 static int dp_auxbus_done_probe(struct drm_dp_aux *aux)
1234 return dp_display_probe_tail(aux->dev);
1237 static int dp_display_probe(struct platform_device *pdev)
1240 struct dp_display_private *dp;
1241 const struct msm_dp_desc *desc;
1243 if (!pdev || !pdev->dev.of_node) {
1244 DRM_ERROR("pdev not found\n");
1248 dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
1252 desc = dp_display_get_desc(pdev);
1256 dp->dp_display.pdev = pdev;
1257 dp->name = "drm_dp";
1259 dp->dp_display.connector_type = desc->connector_type;
1260 dp->wide_bus_en = desc->wide_bus_en;
1261 dp->dp_display.is_edp =
1262 (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP);
1264 rc = dp_init_sub_modules(dp);
1266 DRM_ERROR("init sub module failed\n");
1267 return -EPROBE_DEFER;
1270 rc = dp->parser->parse(dp->parser);
1272 DRM_ERROR("device tree parsing failed\n");
1276 rc = dp_power_client_init(dp->power);
1278 DRM_ERROR("Power client create failed\n");
1283 mutex_init(&dp->event_mutex);
1284 init_waitqueue_head(&dp->event_q);
1285 spin_lock_init(&dp->event_lock);
1287 /* Store DP audio handle inside DP display */
1288 dp->dp_display.dp_audio = dp->audio;
1290 init_completion(&dp->audio_comp);
1292 platform_set_drvdata(pdev, &dp->dp_display);
1294 rc = devm_pm_runtime_enable(&pdev->dev);
1298 rc = dp_display_request_irq(dp);
1302 if (dp->dp_display.is_edp) {
1303 rc = devm_of_dp_aux_populate_bus(dp->aux, dp_auxbus_done_probe);
1305 DRM_ERROR("eDP auxbus population failed, rc=%d\n", rc);
1309 rc = dp_display_probe_tail(&pdev->dev);
1317 dp_display_deinit_sub_modules(dp);
1321 static void dp_display_remove(struct platform_device *pdev)
1323 struct dp_display_private *dp = dev_get_dp_display_private(&pdev->dev);
1325 component_del(&pdev->dev, &dp_display_comp_ops);
1326 dp_display_deinit_sub_modules(dp);
1327 platform_set_drvdata(pdev, NULL);
1330 static int dp_pm_runtime_suspend(struct device *dev)
1332 struct dp_display_private *dp = dev_get_dp_display_private(dev);
1334 disable_irq(dp->irq);
1336 if (dp->dp_display.is_edp) {
1337 dp_display_host_phy_exit(dp);
1338 dp_catalog_ctrl_hpd_disable(dp->catalog);
1340 dp_display_host_deinit(dp);
1345 static int dp_pm_runtime_resume(struct device *dev)
1347 struct dp_display_private *dp = dev_get_dp_display_private(dev);
1350 * for eDP, host cotroller, HPD block and PHY are enabled here
1351 * but with HPD irq disabled
1353 * for DP, only host controller is enabled here.
1354 * HPD block is enabled at dp_bridge_hpd_enable()
1355 * PHY will be enabled at plugin handler later
1357 dp_display_host_init(dp);
1358 if (dp->dp_display.is_edp) {
1359 dp_catalog_ctrl_hpd_enable(dp->catalog);
1360 dp_display_host_phy_init(dp);
1363 enable_irq(dp->irq);
1367 static const struct dev_pm_ops dp_pm_ops = {
1368 SET_RUNTIME_PM_OPS(dp_pm_runtime_suspend, dp_pm_runtime_resume, NULL)
1369 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1370 pm_runtime_force_resume)
1373 static struct platform_driver dp_display_driver = {
1374 .probe = dp_display_probe,
1375 .remove_new = dp_display_remove,
1377 .name = "msm-dp-display",
1378 .of_match_table = dp_dt_match,
1379 .suppress_bind_attrs = true,
1384 int __init msm_dp_register(void)
1388 ret = platform_driver_register(&dp_display_driver);
1390 DRM_ERROR("Dp display driver register failed");
1395 void __exit msm_dp_unregister(void)
1397 platform_driver_unregister(&dp_display_driver);
1400 bool msm_dp_wide_bus_available(const struct msm_dp *dp_display)
1402 struct dp_display_private *dp;
1404 dp = container_of(dp_display, struct dp_display_private, dp_display);
1406 return dp->wide_bus_en;
1409 void dp_display_debugfs_init(struct msm_dp *dp_display, struct dentry *root, bool is_edp)
1411 struct dp_display_private *dp;
1415 dp = container_of(dp_display, struct dp_display_private, dp_display);
1416 dev = &dp->dp_display.pdev->dev;
1418 dp->debug = dp_debug_get(dev, dp->panel,
1419 dp->link, dp->dp_display.connector,
1421 if (IS_ERR(dp->debug)) {
1422 rc = PTR_ERR(dp->debug);
1423 DRM_ERROR("failed to initialize debug, rc = %d\n", rc);
1428 static int dp_display_get_next_bridge(struct msm_dp *dp)
1431 struct dp_display_private *dp_priv;
1433 dp_priv = container_of(dp, struct dp_display_private, dp_display);
1436 * External bridges are mandatory for eDP interfaces: one has to
1437 * provide at least an eDP panel (which gets wrapped into panel-bridge).
1439 * For DisplayPort interfaces external bridges are optional, so
1440 * silently ignore an error if one is not present (-ENODEV).
1442 rc = devm_dp_parser_find_next_bridge(&dp->pdev->dev, dp_priv->parser);
1443 if (!dp->is_edp && rc == -ENODEV)
1447 dp->next_bridge = dp_priv->parser->next_bridge;
1452 int msm_dp_modeset_init(struct msm_dp *dp_display, struct drm_device *dev,
1453 struct drm_encoder *encoder)
1455 struct dp_display_private *dp_priv;
1458 dp_display->drm_dev = dev;
1460 dp_priv = container_of(dp_display, struct dp_display_private, dp_display);
1462 ret = dp_bridge_init(dp_display, dev, encoder);
1464 DRM_DEV_ERROR(dev->dev,
1465 "failed to create dp bridge: %d\n", ret);
1469 dp_display->connector = dp_drm_connector_init(dp_display, encoder);
1470 if (IS_ERR(dp_display->connector)) {
1471 ret = PTR_ERR(dp_display->connector);
1472 DRM_DEV_ERROR(dev->dev,
1473 "failed to create dp connector: %d\n", ret);
1474 dp_display->connector = NULL;
1478 dp_priv->panel->connector = dp_display->connector;
1483 void dp_bridge_atomic_enable(struct drm_bridge *drm_bridge,
1484 struct drm_bridge_state *old_bridge_state)
1486 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1487 struct msm_dp *dp = dp_bridge->dp_display;
1489 struct dp_display_private *dp_display;
1491 bool force_link_train = false;
1493 dp_display = container_of(dp, struct dp_display_private, dp_display);
1494 if (!dp_display->dp_mode.drm_mode.clock) {
1495 DRM_ERROR("invalid params\n");
1500 dp_hpd_plug_handle(dp_display, 0);
1502 mutex_lock(&dp_display->event_mutex);
1503 if (pm_runtime_resume_and_get(&dp->pdev->dev)) {
1504 DRM_ERROR("failed to pm_runtime_resume\n");
1505 mutex_unlock(&dp_display->event_mutex);
1509 state = dp_display->hpd_state;
1510 if (state != ST_DISPLAY_OFF && state != ST_MAINLINK_READY) {
1511 mutex_unlock(&dp_display->event_mutex);
1515 rc = dp_display_set_mode(dp, &dp_display->dp_mode);
1517 DRM_ERROR("Failed to perform a mode set, rc=%d\n", rc);
1518 mutex_unlock(&dp_display->event_mutex);
1522 state = dp_display->hpd_state;
1524 if (state == ST_DISPLAY_OFF) {
1525 dp_display_host_phy_init(dp_display);
1526 force_link_train = true;
1529 dp_display_enable(dp_display, force_link_train);
1531 rc = dp_display_post_enable(dp);
1533 DRM_ERROR("DP display post enable failed, rc=%d\n", rc);
1534 dp_display_disable(dp_display);
1537 /* completed connection */
1538 dp_display->hpd_state = ST_CONNECTED;
1540 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1541 mutex_unlock(&dp_display->event_mutex);
1544 void dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
1545 struct drm_bridge_state *old_bridge_state)
1547 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1548 struct msm_dp *dp = dp_bridge->dp_display;
1549 struct dp_display_private *dp_display;
1551 dp_display = container_of(dp, struct dp_display_private, dp_display);
1553 dp_ctrl_push_idle(dp_display->ctrl);
1556 void dp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,
1557 struct drm_bridge_state *old_bridge_state)
1559 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1560 struct msm_dp *dp = dp_bridge->dp_display;
1562 struct dp_display_private *dp_display;
1564 dp_display = container_of(dp, struct dp_display_private, dp_display);
1567 dp_hpd_unplug_handle(dp_display, 0);
1569 mutex_lock(&dp_display->event_mutex);
1571 state = dp_display->hpd_state;
1572 if (state != ST_DISCONNECT_PENDING && state != ST_CONNECTED)
1573 drm_dbg_dp(dp->drm_dev, "type=%d wrong hpd_state=%d\n",
1574 dp->connector_type, state);
1576 dp_display_disable(dp_display);
1578 state = dp_display->hpd_state;
1579 if (state == ST_DISCONNECT_PENDING) {
1580 /* completed disconnection */
1581 dp_display->hpd_state = ST_DISCONNECTED;
1583 dp_display->hpd_state = ST_DISPLAY_OFF;
1586 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1588 pm_runtime_put_sync(&dp->pdev->dev);
1589 mutex_unlock(&dp_display->event_mutex);
1592 void dp_bridge_mode_set(struct drm_bridge *drm_bridge,
1593 const struct drm_display_mode *mode,
1594 const struct drm_display_mode *adjusted_mode)
1596 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1597 struct msm_dp *dp = dp_bridge->dp_display;
1598 struct dp_display_private *dp_display;
1600 dp_display = container_of(dp, struct dp_display_private, dp_display);
1602 memset(&dp_display->dp_mode, 0x0, sizeof(struct dp_display_mode));
1604 if (dp_display_check_video_test(dp))
1605 dp_display->dp_mode.bpp = dp_display_get_test_bpp(dp);
1606 else /* Default num_components per pixel = 3 */
1607 dp_display->dp_mode.bpp = dp->connector->display_info.bpc * 3;
1609 if (!dp_display->dp_mode.bpp)
1610 dp_display->dp_mode.bpp = 24; /* Default bpp */
1612 drm_mode_copy(&dp_display->dp_mode.drm_mode, adjusted_mode);
1614 dp_display->dp_mode.v_active_low =
1615 !!(dp_display->dp_mode.drm_mode.flags & DRM_MODE_FLAG_NVSYNC);
1617 dp_display->dp_mode.h_active_low =
1618 !!(dp_display->dp_mode.drm_mode.flags & DRM_MODE_FLAG_NHSYNC);
1621 void dp_bridge_hpd_enable(struct drm_bridge *bridge)
1623 struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge);
1624 struct msm_dp *dp_display = dp_bridge->dp_display;
1625 struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display);
1628 * this is for external DP with hpd irq enabled case,
1629 * step-1: dp_pm_runtime_resume() enable dp host only
1630 * step-2: enable hdp block and have hpd irq enabled here
1631 * step-3: waiting for plugin irq while phy is not initialized
1632 * step-4: DP PHY is initialized at plugin handler before link training
1635 mutex_lock(&dp->event_mutex);
1636 if (pm_runtime_resume_and_get(&dp_display->pdev->dev)) {
1637 DRM_ERROR("failed to resume power\n");
1638 mutex_unlock(&dp->event_mutex);
1642 dp_catalog_ctrl_hpd_enable(dp->catalog);
1644 /* enable HDP interrupts */
1645 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, true);
1647 dp_display->internal_hpd = true;
1648 mutex_unlock(&dp->event_mutex);
1651 void dp_bridge_hpd_disable(struct drm_bridge *bridge)
1653 struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge);
1654 struct msm_dp *dp_display = dp_bridge->dp_display;
1655 struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display);
1657 mutex_lock(&dp->event_mutex);
1658 /* disable HDP interrupts */
1659 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, false);
1660 dp_catalog_ctrl_hpd_disable(dp->catalog);
1662 dp_display->internal_hpd = false;
1664 pm_runtime_put_sync(&dp_display->pdev->dev);
1665 mutex_unlock(&dp->event_mutex);
1668 void dp_bridge_hpd_notify(struct drm_bridge *bridge,
1669 enum drm_connector_status status)
1671 struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge);
1672 struct msm_dp *dp_display = dp_bridge->dp_display;
1673 struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display);
1675 /* Without next_bridge interrupts are handled by the DP core directly */
1676 if (dp_display->internal_hpd)
1679 if (!dp_display->link_ready && status == connector_status_connected)
1680 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1681 else if (dp_display->link_ready && status == connector_status_disconnected)
1682 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);