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>
17 #include "dp_parser.h"
19 #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,
65 #define EVENT_TIMEOUT (HZ/10) /* 100ms */
66 #define DP_EVENT_Q_MAX 8
68 #define DP_TIMEOUT_NONE 0
70 #define WAIT_FOR_RESUME_TIMEOUT_JIFFIES (HZ / 2)
78 struct dp_display_private {
85 bool core_initialized;
90 struct drm_device *drm_dev;
91 struct platform_device *pdev;
94 struct dp_parser *parser;
95 struct dp_power *power;
96 struct dp_catalog *catalog;
97 struct drm_dp_aux *aux;
99 struct dp_panel *panel;
100 struct dp_ctrl *ctrl;
101 struct dp_debug *debug;
103 struct dp_display_mode dp_mode;
104 struct msm_dp dp_display;
106 /* wait for audio signaling */
107 struct completion audio_comp;
109 /* event related only access by event thread */
110 struct mutex event_mutex;
111 wait_queue_head_t event_q;
115 struct task_struct *ev_tsk;
116 struct dp_event event_list[DP_EVENT_Q_MAX];
117 spinlock_t event_lock;
121 struct dp_audio *audio;
125 phys_addr_t io_start;
127 unsigned int connector_type;
131 static const struct msm_dp_desc sc7180_dp_descs[] = {
132 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
136 static const struct msm_dp_desc sc7280_dp_descs[] = {
137 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
138 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
142 static const struct msm_dp_desc sc8180x_dp_descs[] = {
143 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
144 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
145 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_eDP },
149 static const struct msm_dp_desc sc8280xp_dp_descs[] = {
150 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
151 { .io_start = 0x0ae98000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
152 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
153 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
154 { .io_start = 0x22090000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
155 { .io_start = 0x22098000, .id = MSM_DP_CONTROLLER_1, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
156 { .io_start = 0x2209a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
157 { .io_start = 0x220a0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
161 static const struct msm_dp_desc sc8280xp_edp_descs[] = {
162 { .io_start = 0x0ae9a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
163 { .io_start = 0x0aea0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
164 { .io_start = 0x2209a000, .id = MSM_DP_CONTROLLER_2, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
165 { .io_start = 0x220a0000, .id = MSM_DP_CONTROLLER_3, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
169 static const struct msm_dp_desc sm8350_dp_descs[] = {
170 { .io_start = 0x0ae90000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
174 static const struct msm_dp_desc sm8650_dp_descs[] = {
175 { .io_start = 0x0af54000, .id = MSM_DP_CONTROLLER_0, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
179 static const struct of_device_id dp_dt_match[] = {
180 { .compatible = "qcom,sc7180-dp", .data = &sc7180_dp_descs },
181 { .compatible = "qcom,sc7280-dp", .data = &sc7280_dp_descs },
182 { .compatible = "qcom,sc7280-edp", .data = &sc7280_dp_descs },
183 { .compatible = "qcom,sc8180x-dp", .data = &sc8180x_dp_descs },
184 { .compatible = "qcom,sc8180x-edp", .data = &sc8180x_dp_descs },
185 { .compatible = "qcom,sc8280xp-dp", .data = &sc8280xp_dp_descs },
186 { .compatible = "qcom,sc8280xp-edp", .data = &sc8280xp_edp_descs },
187 { .compatible = "qcom,sdm845-dp", .data = &sc7180_dp_descs },
188 { .compatible = "qcom,sm8350-dp", .data = &sm8350_dp_descs },
189 { .compatible = "qcom,sm8650-dp", .data = &sm8650_dp_descs },
193 static struct dp_display_private *dev_get_dp_display_private(struct device *dev)
195 struct msm_dp *dp = dev_get_drvdata(dev);
197 return container_of(dp, struct dp_display_private, dp_display);
200 static int dp_add_event(struct dp_display_private *dp_priv, u32 event,
204 struct dp_event *todo;
207 spin_lock_irqsave(&dp_priv->event_lock, flag);
208 pndx = dp_priv->event_pndx + 1;
209 pndx %= DP_EVENT_Q_MAX;
210 if (pndx == dp_priv->event_gndx) {
211 pr_err("event_q is full: pndx=%d gndx=%d\n",
212 dp_priv->event_pndx, dp_priv->event_gndx);
213 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
216 todo = &dp_priv->event_list[dp_priv->event_pndx++];
217 dp_priv->event_pndx %= DP_EVENT_Q_MAX;
218 todo->event_id = event;
221 wake_up(&dp_priv->event_q);
222 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
227 static int dp_del_event(struct dp_display_private *dp_priv, u32 event)
230 struct dp_event *todo;
233 spin_lock_irqsave(&dp_priv->event_lock, flag);
234 if (dp_priv->event_pndx == dp_priv->event_gndx) {
235 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
239 gndx = dp_priv->event_gndx;
240 while (dp_priv->event_pndx != gndx) {
241 todo = &dp_priv->event_list[gndx];
242 if (todo->event_id == event) {
243 todo->event_id = EV_NO_EVENT; /* deleted */
247 gndx %= DP_EVENT_Q_MAX;
249 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
254 void dp_display_signal_audio_start(struct msm_dp *dp_display)
256 struct dp_display_private *dp;
258 dp = container_of(dp_display, struct dp_display_private, dp_display);
260 reinit_completion(&dp->audio_comp);
263 void dp_display_signal_audio_complete(struct msm_dp *dp_display)
265 struct dp_display_private *dp;
267 dp = container_of(dp_display, struct dp_display_private, dp_display);
269 complete_all(&dp->audio_comp);
272 static int dp_hpd_event_thread_start(struct dp_display_private *dp_priv);
274 static int dp_display_bind(struct device *dev, struct device *master,
278 struct dp_display_private *dp = dev_get_dp_display_private(dev);
279 struct msm_drm_private *priv = dev_get_drvdata(master);
280 struct drm_device *drm = priv->dev;
282 dp->dp_display.drm_dev = drm;
283 priv->dp[dp->id] = &dp->dp_display;
285 rc = dp->parser->parse(dp->parser);
287 DRM_ERROR("device tree parsing failed\n");
293 dp->aux->drm_dev = drm;
294 rc = dp_aux_register(dp->aux);
296 DRM_ERROR("DRM DP AUX register failed\n");
300 rc = dp_power_client_init(dp->power);
302 DRM_ERROR("Power client create failed\n");
306 rc = dp_register_audio_driver(dev, dp->audio);
308 DRM_ERROR("Audio registration Dp failed\n");
312 rc = dp_hpd_event_thread_start(dp);
314 DRM_ERROR("Event thread create failed\n");
323 static void dp_display_unbind(struct device *dev, struct device *master,
326 struct dp_display_private *dp = dev_get_dp_display_private(dev);
327 struct msm_drm_private *priv = dev_get_drvdata(master);
329 /* disable all HPD interrupts */
330 if (dp->core_initialized)
331 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, false);
333 kthread_stop(dp->ev_tsk);
335 of_dp_aux_depopulate_bus(dp->aux);
337 dp_power_client_deinit(dp->power);
338 dp_unregister_audio_driver(dev, dp->audio);
339 dp_aux_unregister(dp->aux);
341 dp->aux->drm_dev = NULL;
342 priv->dp[dp->id] = NULL;
345 static const struct component_ops dp_display_comp_ops = {
346 .bind = dp_display_bind,
347 .unbind = dp_display_unbind,
350 static bool dp_display_is_ds_bridge(struct dp_panel *panel)
352 return (panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
353 DP_DWN_STRM_PORT_PRESENT);
356 static bool dp_display_is_sink_count_zero(struct dp_display_private *dp)
358 drm_dbg_dp(dp->drm_dev, "present=%#x sink_count=%d\n",
359 dp->panel->dpcd[DP_DOWNSTREAMPORT_PRESENT],
360 dp->link->sink_count);
361 return dp_display_is_ds_bridge(dp->panel) &&
362 (dp->link->sink_count == 0);
365 static void dp_display_send_hpd_event(struct msm_dp *dp_display)
367 struct dp_display_private *dp;
368 struct drm_connector *connector;
370 dp = container_of(dp_display, struct dp_display_private, dp_display);
372 connector = dp->dp_display.connector;
373 drm_helper_hpd_irq_event(connector->dev);
377 static int dp_display_send_hpd_notification(struct dp_display_private *dp,
380 if ((hpd && dp->dp_display.is_connected) ||
381 (!hpd && !dp->dp_display.is_connected)) {
382 drm_dbg_dp(dp->drm_dev, "HPD already %s\n",
383 (hpd ? "on" : "off"));
387 /* reset video pattern flag on disconnect */
389 dp->panel->video_test = false;
391 dp->dp_display.is_connected = hpd;
393 drm_dbg_dp(dp->drm_dev, "type=%d hpd=%d\n",
394 dp->dp_display.connector_type, hpd);
395 dp_display_send_hpd_event(&dp->dp_display);
400 static int dp_display_process_hpd_high(struct dp_display_private *dp)
405 dp->panel->max_dp_lanes = dp->parser->max_dp_lanes;
406 dp->panel->max_dp_link_rate = dp->parser->max_dp_link_rate;
408 drm_dbg_dp(dp->drm_dev, "max_lanes=%d max_link_rate=%d\n",
409 dp->panel->max_dp_lanes, dp->panel->max_dp_link_rate);
411 rc = dp_panel_read_sink_caps(dp->panel, dp->dp_display.connector);
415 dp_link_process_request(dp->link);
417 edid = dp->panel->edid;
419 dp->dp_display.psr_supported = dp->panel->psr_cap.version && psr_enabled;
421 dp->audio_supported = drm_detect_monitor_audio(edid);
422 dp_panel_handle_sink_request(dp->panel);
424 dp->dp_display.max_dp_lanes = dp->parser->max_dp_lanes;
427 * set sink to normal operation mode -- D0
430 dp_link_psm_config(dp->link, &dp->panel->link_info, false);
432 dp_link_reset_phy_params_vx_px(dp->link);
433 rc = dp_ctrl_on_link(dp->ctrl);
435 DRM_ERROR("failed to complete DP link training\n");
439 dp_add_event(dp, EV_USER_NOTIFICATION, true, 0);
445 static void dp_display_host_phy_init(struct dp_display_private *dp)
447 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
448 dp->dp_display.connector_type, dp->core_initialized,
449 dp->phy_initialized);
451 if (!dp->phy_initialized) {
452 dp_ctrl_phy_init(dp->ctrl);
453 dp->phy_initialized = true;
457 static void dp_display_host_phy_exit(struct dp_display_private *dp)
459 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
460 dp->dp_display.connector_type, dp->core_initialized,
461 dp->phy_initialized);
463 if (dp->phy_initialized) {
464 dp_ctrl_phy_exit(dp->ctrl);
465 dp->phy_initialized = false;
469 static void dp_display_host_init(struct dp_display_private *dp)
471 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
472 dp->dp_display.connector_type, dp->core_initialized,
473 dp->phy_initialized);
475 dp_power_init(dp->power);
476 dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
477 dp_aux_init(dp->aux);
478 dp->core_initialized = true;
481 static void dp_display_host_deinit(struct dp_display_private *dp)
483 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
484 dp->dp_display.connector_type, dp->core_initialized,
485 dp->phy_initialized);
487 dp_ctrl_reset_irq_ctrl(dp->ctrl, false);
488 dp_aux_deinit(dp->aux);
489 dp_power_deinit(dp->power);
490 dp->core_initialized = false;
493 static int dp_display_usbpd_configure_cb(struct device *dev)
495 struct dp_display_private *dp = dev_get_dp_display_private(dev);
497 dp_display_host_phy_init(dp);
499 return dp_display_process_hpd_high(dp);
502 static int dp_display_notify_disconnect(struct device *dev)
504 struct dp_display_private *dp = dev_get_dp_display_private(dev);
506 dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
511 static void dp_display_handle_video_request(struct dp_display_private *dp)
513 if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
514 dp->panel->video_test = true;
515 dp_link_send_test_response(dp->link);
519 static int dp_display_handle_port_ststus_changed(struct dp_display_private *dp)
523 if (dp_display_is_sink_count_zero(dp)) {
524 drm_dbg_dp(dp->drm_dev, "sink count is zero, nothing to do\n");
525 if (dp->hpd_state != ST_DISCONNECTED) {
526 dp->hpd_state = ST_DISCONNECT_PENDING;
527 dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
530 if (dp->hpd_state == ST_DISCONNECTED) {
531 dp->hpd_state = ST_MAINLINK_READY;
532 rc = dp_display_process_hpd_high(dp);
534 dp->hpd_state = ST_DISCONNECTED;
541 static int dp_display_handle_irq_hpd(struct dp_display_private *dp)
543 u32 sink_request = dp->link->sink_request;
545 drm_dbg_dp(dp->drm_dev, "%d\n", sink_request);
546 if (dp->hpd_state == ST_DISCONNECTED) {
547 if (sink_request & DP_LINK_STATUS_UPDATED) {
548 drm_dbg_dp(dp->drm_dev, "Disconnected sink_request: %d\n",
550 DRM_ERROR("Disconnected, no DP_LINK_STATUS_UPDATED\n");
555 dp_ctrl_handle_sink_request(dp->ctrl);
557 if (sink_request & DP_TEST_LINK_VIDEO_PATTERN)
558 dp_display_handle_video_request(dp);
563 static int dp_display_usbpd_attention_cb(struct device *dev)
567 struct dp_display_private *dp = dev_get_dp_display_private(dev);
569 /* check for any test request issued by sink */
570 rc = dp_link_process_request(dp->link);
572 sink_request = dp->link->sink_request;
573 drm_dbg_dp(dp->drm_dev, "hpd_state=%d sink_request=%d\n",
574 dp->hpd_state, sink_request);
575 if (sink_request & DS_PORT_STATUS_CHANGED)
576 rc = dp_display_handle_port_ststus_changed(dp);
578 rc = dp_display_handle_irq_hpd(dp);
584 static int dp_hpd_plug_handle(struct dp_display_private *dp, u32 data)
589 mutex_lock(&dp->event_mutex);
591 state = dp->hpd_state;
592 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
593 dp->dp_display.connector_type, state);
595 if (state == ST_DISPLAY_OFF || state == ST_SUSPENDED) {
596 mutex_unlock(&dp->event_mutex);
600 if (state == ST_MAINLINK_READY || state == ST_CONNECTED) {
601 mutex_unlock(&dp->event_mutex);
605 if (state == ST_DISCONNECT_PENDING) {
606 /* wait until ST_DISCONNECTED */
607 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 1); /* delay = 1 */
608 mutex_unlock(&dp->event_mutex);
612 ret = dp_display_usbpd_configure_cb(&dp->pdev->dev);
613 if (ret) { /* link train failed */
614 dp->hpd_state = ST_DISCONNECTED;
616 dp->hpd_state = ST_MAINLINK_READY;
619 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
620 dp->dp_display.connector_type, state);
621 mutex_unlock(&dp->event_mutex);
623 /* uevent will complete connection part */
627 static void dp_display_handle_plugged_change(struct msm_dp *dp_display,
630 struct dp_display_private *dp;
632 dp = container_of(dp_display,
633 struct dp_display_private, dp_display);
635 /* notify audio subsystem only if sink supports audio */
636 if (dp_display->plugged_cb && dp_display->codec_dev &&
638 dp_display->plugged_cb(dp_display->codec_dev, plugged);
641 static int dp_hpd_unplug_handle(struct dp_display_private *dp, u32 data)
645 mutex_lock(&dp->event_mutex);
647 state = dp->hpd_state;
649 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
650 dp->dp_display.connector_type, state);
652 /* unplugged, no more irq_hpd handle */
653 dp_del_event(dp, EV_IRQ_HPD_INT);
655 if (state == ST_DISCONNECTED) {
656 /* triggered by irq_hdp with sink_count = 0 */
657 if (dp->link->sink_count == 0) {
658 dp_display_host_phy_exit(dp);
660 dp_display_notify_disconnect(&dp->pdev->dev);
661 mutex_unlock(&dp->event_mutex);
663 } else if (state == ST_DISCONNECT_PENDING) {
664 mutex_unlock(&dp->event_mutex);
666 } else if (state == ST_MAINLINK_READY) {
667 dp_ctrl_off_link(dp->ctrl);
668 dp_display_host_phy_exit(dp);
669 dp->hpd_state = ST_DISCONNECTED;
670 dp_display_notify_disconnect(&dp->pdev->dev);
671 mutex_unlock(&dp->event_mutex);
676 * We don't need separate work for disconnect as
677 * connect/attention interrupts are disabled
679 dp_display_notify_disconnect(&dp->pdev->dev);
681 if (state == ST_DISPLAY_OFF) {
682 dp->hpd_state = ST_DISCONNECTED;
684 dp->hpd_state = ST_DISCONNECT_PENDING;
687 /* signal the disconnect event early to ensure proper teardown */
688 dp_display_handle_plugged_change(&dp->dp_display, false);
690 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
691 dp->dp_display.connector_type, state);
693 /* uevent will complete disconnection part */
694 mutex_unlock(&dp->event_mutex);
698 static int dp_irq_hpd_handle(struct dp_display_private *dp, u32 data)
702 mutex_lock(&dp->event_mutex);
704 /* irq_hpd can happen at either connected or disconnected state */
705 state = dp->hpd_state;
706 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
707 dp->dp_display.connector_type, state);
709 if (state == ST_DISPLAY_OFF || state == ST_SUSPENDED) {
710 mutex_unlock(&dp->event_mutex);
714 if (state == ST_MAINLINK_READY || state == ST_DISCONNECT_PENDING) {
715 /* wait until ST_CONNECTED */
716 dp_add_event(dp, EV_IRQ_HPD_INT, 0, 1); /* delay = 1 */
717 mutex_unlock(&dp->event_mutex);
721 dp_display_usbpd_attention_cb(&dp->pdev->dev);
723 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
724 dp->dp_display.connector_type, state);
726 mutex_unlock(&dp->event_mutex);
731 static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
733 dp_debug_put(dp->debug);
734 dp_audio_put(dp->audio);
735 dp_panel_put(dp->panel);
739 static int dp_init_sub_modules(struct dp_display_private *dp)
742 struct device *dev = &dp->pdev->dev;
743 struct dp_panel_in panel_in = {
747 dp->parser = dp_parser_get(dp->pdev);
748 if (IS_ERR(dp->parser)) {
749 rc = PTR_ERR(dp->parser);
750 DRM_ERROR("failed to initialize parser, rc = %d\n", rc);
755 dp->catalog = dp_catalog_get(dev, &dp->parser->io);
756 if (IS_ERR(dp->catalog)) {
757 rc = PTR_ERR(dp->catalog);
758 DRM_ERROR("failed to initialize catalog, rc = %d\n", rc);
763 dp->power = dp_power_get(dev, dp->parser);
764 if (IS_ERR(dp->power)) {
765 rc = PTR_ERR(dp->power);
766 DRM_ERROR("failed to initialize power, rc = %d\n", rc);
771 dp->aux = dp_aux_get(dev, dp->catalog, dp->dp_display.is_edp);
772 if (IS_ERR(dp->aux)) {
773 rc = PTR_ERR(dp->aux);
774 DRM_ERROR("failed to initialize aux, rc = %d\n", rc);
779 dp->link = dp_link_get(dev, dp->aux);
780 if (IS_ERR(dp->link)) {
781 rc = PTR_ERR(dp->link);
782 DRM_ERROR("failed to initialize link, rc = %d\n", rc);
787 panel_in.aux = dp->aux;
788 panel_in.catalog = dp->catalog;
789 panel_in.link = dp->link;
791 dp->panel = dp_panel_get(&panel_in);
792 if (IS_ERR(dp->panel)) {
793 rc = PTR_ERR(dp->panel);
794 DRM_ERROR("failed to initialize panel, rc = %d\n", rc);
799 dp->ctrl = dp_ctrl_get(dev, dp->link, dp->panel, dp->aux,
800 dp->power, dp->catalog, dp->parser);
801 if (IS_ERR(dp->ctrl)) {
802 rc = PTR_ERR(dp->ctrl);
803 DRM_ERROR("failed to initialize ctrl, rc = %d\n", rc);
808 dp->audio = dp_audio_get(dp->pdev, dp->panel, dp->catalog);
809 if (IS_ERR(dp->audio)) {
810 rc = PTR_ERR(dp->audio);
811 pr_err("failed to initialize audio, rc = %d\n", rc);
816 /* populate wide_bus_en to differernt layers */
817 dp->ctrl->wide_bus_en = dp->wide_bus_en;
818 dp->catalog->wide_bus_en = dp->wide_bus_en;
823 dp_panel_put(dp->panel);
830 static int dp_display_set_mode(struct msm_dp *dp_display,
831 struct dp_display_mode *mode)
833 struct dp_display_private *dp;
835 dp = container_of(dp_display, struct dp_display_private, dp_display);
837 drm_mode_copy(&dp->panel->dp_mode.drm_mode, &mode->drm_mode);
838 dp->panel->dp_mode.bpp = mode->bpp;
839 dp->panel->dp_mode.capabilities = mode->capabilities;
840 dp_panel_init_panel_info(dp->panel);
844 static int dp_display_enable(struct dp_display_private *dp, bool force_link_train)
847 struct msm_dp *dp_display = &dp->dp_display;
849 drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
850 if (dp_display->power_on) {
851 drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
855 rc = dp_ctrl_on_stream(dp->ctrl, force_link_train);
857 dp_display->power_on = true;
862 static int dp_display_post_enable(struct msm_dp *dp_display)
864 struct dp_display_private *dp;
867 dp = container_of(dp_display, struct dp_display_private, dp_display);
869 rate = dp->link->link_params.rate;
871 if (dp->audio_supported) {
872 dp->audio->bw_code = drm_dp_link_rate_to_bw_code(rate);
873 dp->audio->lane_count = dp->link->link_params.num_lanes;
876 /* signal the connect event late to synchronize video and display */
877 dp_display_handle_plugged_change(dp_display, true);
879 if (dp_display->psr_supported)
880 dp_ctrl_config_psr(dp->ctrl);
885 static int dp_display_disable(struct dp_display_private *dp)
887 struct msm_dp *dp_display = &dp->dp_display;
889 if (!dp_display->power_on)
892 /* wait only if audio was enabled */
893 if (dp_display->audio_enabled) {
894 /* signal the disconnect event */
895 dp_display_handle_plugged_change(dp_display, false);
896 if (!wait_for_completion_timeout(&dp->audio_comp,
898 DRM_ERROR("audio comp timeout\n");
901 dp_display->audio_enabled = false;
903 if (dp->link->sink_count == 0) {
905 * irq_hpd with sink_count = 0
906 * hdmi unplugged out of dongle
908 dp_ctrl_off_link_stream(dp->ctrl);
911 * unplugged interrupt
912 * dongle unplugged out of DUT
914 dp_ctrl_off(dp->ctrl);
915 dp_display_host_phy_exit(dp);
918 dp_display->power_on = false;
920 drm_dbg_dp(dp->drm_dev, "sink count: %d\n", dp->link->sink_count);
924 int dp_display_set_plugged_cb(struct msm_dp *dp_display,
925 hdmi_codec_plugged_cb fn, struct device *codec_dev)
929 dp_display->plugged_cb = fn;
930 dp_display->codec_dev = codec_dev;
931 plugged = dp_display->is_connected;
932 dp_display_handle_plugged_change(dp_display, plugged);
938 * dp_bridge_mode_valid - callback to determine if specified mode is valid
939 * @bridge: Pointer to drm bridge structure
940 * @info: display info
941 * @mode: Pointer to drm mode structure
942 * Returns: Validity status for specified mode
944 enum drm_mode_status dp_bridge_mode_valid(struct drm_bridge *bridge,
945 const struct drm_display_info *info,
946 const struct drm_display_mode *mode)
948 const u32 num_components = 3, default_bpp = 24;
949 struct dp_display_private *dp_display;
950 struct dp_link_info *link_info;
951 u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
953 int mode_pclk_khz = mode->clock;
955 dp = to_dp_bridge(bridge)->dp_display;
957 if (!dp || !mode_pclk_khz || !dp->connector) {
958 DRM_ERROR("invalid params\n");
962 if (mode->clock > DP_MAX_PIXEL_CLK_KHZ)
963 return MODE_CLOCK_HIGH;
965 dp_display = container_of(dp, struct dp_display_private, dp_display);
966 link_info = &dp_display->panel->link_info;
968 mode_bpp = dp->connector->display_info.bpc * num_components;
970 mode_bpp = default_bpp;
972 mode_bpp = dp_panel_get_mode_bpp(dp_display->panel,
973 mode_bpp, mode_pclk_khz);
975 mode_rate_khz = mode_pclk_khz * mode_bpp;
976 supported_rate_khz = link_info->num_lanes * link_info->rate * 8;
978 if (mode_rate_khz > supported_rate_khz)
984 int dp_display_get_modes(struct msm_dp *dp)
986 struct dp_display_private *dp_display;
989 DRM_ERROR("invalid params\n");
993 dp_display = container_of(dp, struct dp_display_private, dp_display);
995 return dp_panel_get_modes(dp_display->panel,
999 bool dp_display_check_video_test(struct msm_dp *dp)
1001 struct dp_display_private *dp_display;
1003 dp_display = container_of(dp, struct dp_display_private, dp_display);
1005 return dp_display->panel->video_test;
1008 int dp_display_get_test_bpp(struct msm_dp *dp)
1010 struct dp_display_private *dp_display;
1013 DRM_ERROR("invalid params\n");
1017 dp_display = container_of(dp, struct dp_display_private, dp_display);
1019 return dp_link_bit_depth_to_bpp(
1020 dp_display->link->test_video.test_bit_depth);
1023 void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)
1025 struct dp_display_private *dp_display;
1027 dp_display = container_of(dp, struct dp_display_private, dp_display);
1030 * if we are reading registers we need the link clocks to be on
1031 * however till DP cable is connected this will not happen as we
1032 * do not know the resolution to power up with. Hence check the
1033 * power_on status before dumping DP registers to avoid crash due
1034 * to unclocked access
1036 mutex_lock(&dp_display->event_mutex);
1038 if (!dp->power_on) {
1039 mutex_unlock(&dp_display->event_mutex);
1043 dp_catalog_snapshot(dp_display->catalog, disp_state);
1045 mutex_unlock(&dp_display->event_mutex);
1048 void dp_display_set_psr(struct msm_dp *dp_display, bool enter)
1050 struct dp_display_private *dp;
1053 DRM_ERROR("invalid params\n");
1057 dp = container_of(dp_display, struct dp_display_private, dp_display);
1058 dp_ctrl_set_psr(dp->ctrl, enter);
1061 static int hpd_event_thread(void *data)
1063 struct dp_display_private *dp_priv;
1065 struct dp_event *todo;
1066 int timeout_mode = 0;
1068 dp_priv = (struct dp_display_private *)data;
1072 wait_event_timeout(dp_priv->event_q,
1073 (dp_priv->event_pndx == dp_priv->event_gndx) ||
1074 kthread_should_stop(), EVENT_TIMEOUT);
1076 wait_event_interruptible(dp_priv->event_q,
1077 (dp_priv->event_pndx != dp_priv->event_gndx) ||
1078 kthread_should_stop());
1081 if (kthread_should_stop())
1084 spin_lock_irqsave(&dp_priv->event_lock, flag);
1085 todo = &dp_priv->event_list[dp_priv->event_gndx];
1087 struct dp_event *todo_next;
1089 dp_priv->event_gndx++;
1090 dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1092 /* re enter delay event into q */
1093 todo_next = &dp_priv->event_list[dp_priv->event_pndx++];
1094 dp_priv->event_pndx %= DP_EVENT_Q_MAX;
1095 todo_next->event_id = todo->event_id;
1096 todo_next->data = todo->data;
1097 todo_next->delay = todo->delay - 1;
1099 /* clean up older event */
1100 todo->event_id = EV_NO_EVENT;
1103 /* switch to timeout mode */
1105 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1109 /* timeout with no events in q */
1110 if (dp_priv->event_pndx == dp_priv->event_gndx) {
1111 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1115 dp_priv->event_gndx++;
1116 dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1118 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1120 switch (todo->event_id) {
1121 case EV_HPD_INIT_SETUP:
1122 dp_display_host_init(dp_priv);
1124 case EV_HPD_PLUG_INT:
1125 dp_hpd_plug_handle(dp_priv, todo->data);
1127 case EV_HPD_UNPLUG_INT:
1128 dp_hpd_unplug_handle(dp_priv, todo->data);
1130 case EV_IRQ_HPD_INT:
1131 dp_irq_hpd_handle(dp_priv, todo->data);
1133 case EV_USER_NOTIFICATION:
1134 dp_display_send_hpd_notification(dp_priv,
1145 static int dp_hpd_event_thread_start(struct dp_display_private *dp_priv)
1147 /* set event q to empty */
1148 dp_priv->event_gndx = 0;
1149 dp_priv->event_pndx = 0;
1151 dp_priv->ev_tsk = kthread_run(hpd_event_thread, dp_priv, "dp_hpd_handler");
1152 if (IS_ERR(dp_priv->ev_tsk))
1153 return PTR_ERR(dp_priv->ev_tsk);
1158 static irqreturn_t dp_display_irq_handler(int irq, void *dev_id)
1160 struct dp_display_private *dp = dev_id;
1161 irqreturn_t ret = IRQ_NONE;
1165 DRM_ERROR("invalid data\n");
1169 hpd_isr_status = dp_catalog_hpd_get_intr_status(dp->catalog);
1171 if (hpd_isr_status & 0x0F) {
1172 drm_dbg_dp(dp->drm_dev, "type=%d isr=0x%x\n",
1173 dp->dp_display.connector_type, hpd_isr_status);
1174 /* hpd related interrupts */
1175 if (hpd_isr_status & DP_DP_HPD_PLUG_INT_MASK)
1176 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1178 if (hpd_isr_status & DP_DP_IRQ_HPD_INT_MASK) {
1179 dp_add_event(dp, EV_IRQ_HPD_INT, 0, 0);
1182 if (hpd_isr_status & DP_DP_HPD_REPLUG_INT_MASK) {
1183 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1184 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 3);
1187 if (hpd_isr_status & DP_DP_HPD_UNPLUG_INT_MASK)
1188 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1193 /* DP controller isr */
1194 ret |= dp_ctrl_isr(dp->ctrl);
1197 ret |= dp_aux_isr(dp->aux);
1202 int dp_display_request_irq(struct msm_dp *dp_display)
1205 struct dp_display_private *dp;
1208 DRM_ERROR("invalid input\n");
1212 dp = container_of(dp_display, struct dp_display_private, dp_display);
1214 dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
1216 DRM_ERROR("failed to get irq\n");
1220 rc = devm_request_irq(dp_display->drm_dev->dev, dp->irq,
1221 dp_display_irq_handler,
1222 IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
1224 DRM_ERROR("failed to request IRQ%u: %d\n",
1232 static const struct msm_dp_desc *dp_display_get_desc(struct platform_device *pdev)
1234 const struct msm_dp_desc *descs = of_device_get_match_data(&pdev->dev);
1235 struct resource *res;
1238 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1242 for (i = 0; i < descs[i].io_start; i++) {
1243 if (descs[i].io_start == res->start)
1247 dev_err(&pdev->dev, "unknown displayport instance\n");
1251 static int dp_display_probe(struct platform_device *pdev)
1254 struct dp_display_private *dp;
1255 const struct msm_dp_desc *desc;
1257 if (!pdev || !pdev->dev.of_node) {
1258 DRM_ERROR("pdev not found\n");
1262 dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
1266 desc = dp_display_get_desc(pdev);
1271 dp->name = "drm_dp";
1273 dp->dp_display.connector_type = desc->connector_type;
1274 dp->wide_bus_en = desc->wide_bus_en;
1275 dp->dp_display.is_edp =
1276 (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP);
1278 rc = dp_init_sub_modules(dp);
1280 DRM_ERROR("init sub module failed\n");
1281 return -EPROBE_DEFER;
1285 mutex_init(&dp->event_mutex);
1286 init_waitqueue_head(&dp->event_q);
1287 spin_lock_init(&dp->event_lock);
1289 /* Store DP audio handle inside DP display */
1290 dp->dp_display.dp_audio = dp->audio;
1292 init_completion(&dp->audio_comp);
1294 platform_set_drvdata(pdev, &dp->dp_display);
1296 rc = component_add(&pdev->dev, &dp_display_comp_ops);
1298 DRM_ERROR("component add failed, rc=%d\n", rc);
1299 dp_display_deinit_sub_modules(dp);
1305 static int dp_display_remove(struct platform_device *pdev)
1307 struct dp_display_private *dp = dev_get_dp_display_private(&pdev->dev);
1309 component_del(&pdev->dev, &dp_display_comp_ops);
1310 dp_display_deinit_sub_modules(dp);
1312 platform_set_drvdata(pdev, NULL);
1317 static int dp_pm_resume(struct device *dev)
1319 struct platform_device *pdev = to_platform_device(dev);
1320 struct msm_dp *dp_display = platform_get_drvdata(pdev);
1321 struct dp_display_private *dp;
1324 dp = container_of(dp_display, struct dp_display_private, dp_display);
1326 mutex_lock(&dp->event_mutex);
1328 drm_dbg_dp(dp->drm_dev,
1329 "Before, type=%d core_inited=%d phy_inited=%d power_on=%d\n",
1330 dp->dp_display.connector_type, dp->core_initialized,
1331 dp->phy_initialized, dp_display->power_on);
1333 /* start from disconnected state */
1334 dp->hpd_state = ST_DISCONNECTED;
1336 /* turn on dp ctrl/phy */
1337 dp_display_host_init(dp);
1339 if (dp_display->is_edp)
1340 dp_catalog_ctrl_hpd_enable(dp->catalog);
1342 if (dp_catalog_link_is_connected(dp->catalog)) {
1344 * set sink to normal operation mode -- D0
1347 dp_display_host_phy_init(dp);
1348 dp_link_psm_config(dp->link, &dp->panel->link_info, false);
1349 sink_count = drm_dp_read_sink_count(dp->aux);
1353 dp_display_host_phy_exit(dp);
1356 dp->link->sink_count = sink_count;
1358 * can not declared display is connected unless
1359 * HDMI cable is plugged in and sink_count of
1361 * also only signal audio when disconnected
1363 if (dp->link->sink_count) {
1364 dp->dp_display.is_connected = true;
1366 dp->dp_display.is_connected = false;
1367 dp_display_handle_plugged_change(dp_display, false);
1370 drm_dbg_dp(dp->drm_dev,
1371 "After, type=%d sink=%d conn=%d core_init=%d phy_init=%d power=%d\n",
1372 dp->dp_display.connector_type, dp->link->sink_count,
1373 dp->dp_display.is_connected, dp->core_initialized,
1374 dp->phy_initialized, dp_display->power_on);
1376 mutex_unlock(&dp->event_mutex);
1381 static int dp_pm_suspend(struct device *dev)
1383 struct platform_device *pdev = to_platform_device(dev);
1384 struct msm_dp *dp_display = platform_get_drvdata(pdev);
1385 struct dp_display_private *dp;
1387 dp = container_of(dp_display, struct dp_display_private, dp_display);
1389 mutex_lock(&dp->event_mutex);
1391 drm_dbg_dp(dp->drm_dev,
1392 "Before, type=%d core_inited=%d phy_inited=%d power_on=%d\n",
1393 dp->dp_display.connector_type, dp->core_initialized,
1394 dp->phy_initialized, dp_display->power_on);
1396 /* mainlink enabled */
1397 if (dp_power_clk_status(dp->power, DP_CTRL_PM))
1398 dp_ctrl_off_link_stream(dp->ctrl);
1400 dp_display_host_phy_exit(dp);
1402 /* host_init will be called at pm_resume */
1403 dp_display_host_deinit(dp);
1405 dp->hpd_state = ST_SUSPENDED;
1407 drm_dbg_dp(dp->drm_dev,
1408 "After, type=%d core_inited=%d phy_inited=%d power_on=%d\n",
1409 dp->dp_display.connector_type, dp->core_initialized,
1410 dp->phy_initialized, dp_display->power_on);
1412 mutex_unlock(&dp->event_mutex);
1417 static const struct dev_pm_ops dp_pm_ops = {
1418 .suspend = dp_pm_suspend,
1419 .resume = dp_pm_resume,
1422 static struct platform_driver dp_display_driver = {
1423 .probe = dp_display_probe,
1424 .remove = dp_display_remove,
1426 .name = "msm-dp-display",
1427 .of_match_table = dp_dt_match,
1428 .suppress_bind_attrs = true,
1433 int __init msm_dp_register(void)
1437 ret = platform_driver_register(&dp_display_driver);
1439 DRM_ERROR("Dp display driver register failed");
1444 void __exit msm_dp_unregister(void)
1446 platform_driver_unregister(&dp_display_driver);
1449 void msm_dp_irq_postinstall(struct msm_dp *dp_display)
1451 struct dp_display_private *dp;
1456 dp = container_of(dp_display, struct dp_display_private, dp_display);
1458 if (!dp_display->is_edp)
1459 dp_add_event(dp, EV_HPD_INIT_SETUP, 0, 0);
1462 bool msm_dp_wide_bus_available(const struct msm_dp *dp_display)
1464 struct dp_display_private *dp;
1466 dp = container_of(dp_display, struct dp_display_private, dp_display);
1468 return dp->wide_bus_en;
1471 void msm_dp_debugfs_init(struct msm_dp *dp_display, struct drm_minor *minor)
1473 struct dp_display_private *dp;
1477 dp = container_of(dp_display, struct dp_display_private, dp_display);
1478 dev = &dp->pdev->dev;
1480 dp->debug = dp_debug_get(dev, dp->panel,
1481 dp->link, dp->dp_display.connector,
1483 if (IS_ERR(dp->debug)) {
1484 rc = PTR_ERR(dp->debug);
1485 DRM_ERROR("failed to initialize debug, rc = %d\n", rc);
1490 static int dp_display_get_next_bridge(struct msm_dp *dp)
1493 struct dp_display_private *dp_priv;
1494 struct device_node *aux_bus;
1497 dp_priv = container_of(dp, struct dp_display_private, dp_display);
1498 dev = &dp_priv->pdev->dev;
1499 aux_bus = of_get_child_by_name(dev->of_node, "aux-bus");
1501 if (aux_bus && dp->is_edp) {
1502 dp_display_host_init(dp_priv);
1503 dp_catalog_ctrl_hpd_enable(dp_priv->catalog);
1504 dp_display_host_phy_init(dp_priv);
1507 * The code below assumes that the panel will finish probing
1508 * by the time devm_of_dp_aux_populate_ep_devices() returns.
1509 * This isn't a great assumption since it will fail if the
1510 * panel driver is probed asynchronously but is the best we
1511 * can do without a bigger driver reorganization.
1513 rc = of_dp_aux_populate_bus(dp_priv->aux, NULL);
1514 of_node_put(aux_bus);
1517 } else if (dp->is_edp) {
1518 DRM_ERROR("eDP aux_bus not found\n");
1523 * External bridges are mandatory for eDP interfaces: one has to
1524 * provide at least an eDP panel (which gets wrapped into panel-bridge).
1526 * For DisplayPort interfaces external bridges are optional, so
1527 * silently ignore an error if one is not present (-ENODEV).
1529 rc = devm_dp_parser_find_next_bridge(dp->drm_dev->dev, dp_priv->parser);
1530 if (!dp->is_edp && rc == -ENODEV)
1534 dp->next_bridge = dp_priv->parser->next_bridge;
1540 of_dp_aux_depopulate_bus(dp_priv->aux);
1541 dp_display_host_phy_exit(dp_priv);
1542 dp_display_host_deinit(dp_priv);
1547 int msm_dp_modeset_init(struct msm_dp *dp_display, struct drm_device *dev,
1548 struct drm_encoder *encoder)
1550 struct msm_drm_private *priv = dev->dev_private;
1551 struct dp_display_private *dp_priv;
1554 dp_display->drm_dev = dev;
1556 dp_priv = container_of(dp_display, struct dp_display_private, dp_display);
1558 ret = dp_display_request_irq(dp_display);
1560 DRM_ERROR("request_irq failed, ret=%d\n", ret);
1564 ret = dp_display_get_next_bridge(dp_display);
1568 dp_display->bridge = dp_bridge_init(dp_display, dev, encoder);
1569 if (IS_ERR(dp_display->bridge)) {
1570 ret = PTR_ERR(dp_display->bridge);
1571 DRM_DEV_ERROR(dev->dev,
1572 "failed to create dp bridge: %d\n", ret);
1573 dp_display->bridge = NULL;
1577 priv->bridges[priv->num_bridges++] = dp_display->bridge;
1579 dp_display->connector = dp_drm_connector_init(dp_display, encoder);
1580 if (IS_ERR(dp_display->connector)) {
1581 ret = PTR_ERR(dp_display->connector);
1582 DRM_DEV_ERROR(dev->dev,
1583 "failed to create dp connector: %d\n", ret);
1584 dp_display->connector = NULL;
1588 dp_priv->panel->connector = dp_display->connector;
1593 void dp_bridge_atomic_enable(struct drm_bridge *drm_bridge,
1594 struct drm_bridge_state *old_bridge_state)
1596 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1597 struct msm_dp *dp = dp_bridge->dp_display;
1599 struct dp_display_private *dp_display;
1601 bool force_link_train = false;
1603 dp_display = container_of(dp, struct dp_display_private, dp_display);
1604 if (!dp_display->dp_mode.drm_mode.clock) {
1605 DRM_ERROR("invalid params\n");
1610 dp_hpd_plug_handle(dp_display, 0);
1612 mutex_lock(&dp_display->event_mutex);
1614 state = dp_display->hpd_state;
1615 if (state != ST_DISPLAY_OFF && state != ST_MAINLINK_READY) {
1616 mutex_unlock(&dp_display->event_mutex);
1620 rc = dp_display_set_mode(dp, &dp_display->dp_mode);
1622 DRM_ERROR("Failed to perform a mode set, rc=%d\n", rc);
1623 mutex_unlock(&dp_display->event_mutex);
1627 state = dp_display->hpd_state;
1629 if (state == ST_DISPLAY_OFF) {
1630 dp_display_host_phy_init(dp_display);
1631 force_link_train = true;
1634 dp_display_enable(dp_display, force_link_train);
1636 rc = dp_display_post_enable(dp);
1638 DRM_ERROR("DP display post enable failed, rc=%d\n", rc);
1639 dp_display_disable(dp_display);
1642 /* completed connection */
1643 dp_display->hpd_state = ST_CONNECTED;
1645 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1646 mutex_unlock(&dp_display->event_mutex);
1649 void dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
1650 struct drm_bridge_state *old_bridge_state)
1652 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1653 struct msm_dp *dp = dp_bridge->dp_display;
1654 struct dp_display_private *dp_display;
1656 dp_display = container_of(dp, struct dp_display_private, dp_display);
1658 dp_ctrl_push_idle(dp_display->ctrl);
1661 void dp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,
1662 struct drm_bridge_state *old_bridge_state)
1664 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1665 struct msm_dp *dp = dp_bridge->dp_display;
1667 struct dp_display_private *dp_display;
1669 dp_display = container_of(dp, struct dp_display_private, dp_display);
1672 dp_hpd_unplug_handle(dp_display, 0);
1674 mutex_lock(&dp_display->event_mutex);
1676 state = dp_display->hpd_state;
1677 if (state != ST_DISCONNECT_PENDING && state != ST_CONNECTED) {
1678 mutex_unlock(&dp_display->event_mutex);
1682 dp_display_disable(dp_display);
1684 state = dp_display->hpd_state;
1685 if (state == ST_DISCONNECT_PENDING) {
1686 /* completed disconnection */
1687 dp_display->hpd_state = ST_DISCONNECTED;
1689 dp_display->hpd_state = ST_DISPLAY_OFF;
1692 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1693 mutex_unlock(&dp_display->event_mutex);
1696 void dp_bridge_mode_set(struct drm_bridge *drm_bridge,
1697 const struct drm_display_mode *mode,
1698 const struct drm_display_mode *adjusted_mode)
1700 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1701 struct msm_dp *dp = dp_bridge->dp_display;
1702 struct dp_display_private *dp_display;
1704 dp_display = container_of(dp, struct dp_display_private, dp_display);
1706 memset(&dp_display->dp_mode, 0x0, sizeof(struct dp_display_mode));
1708 if (dp_display_check_video_test(dp))
1709 dp_display->dp_mode.bpp = dp_display_get_test_bpp(dp);
1710 else /* Default num_components per pixel = 3 */
1711 dp_display->dp_mode.bpp = dp->connector->display_info.bpc * 3;
1713 if (!dp_display->dp_mode.bpp)
1714 dp_display->dp_mode.bpp = 24; /* Default bpp */
1716 drm_mode_copy(&dp_display->dp_mode.drm_mode, adjusted_mode);
1718 dp_display->dp_mode.v_active_low =
1719 !!(dp_display->dp_mode.drm_mode.flags & DRM_MODE_FLAG_NVSYNC);
1721 dp_display->dp_mode.h_active_low =
1722 !!(dp_display->dp_mode.drm_mode.flags & DRM_MODE_FLAG_NHSYNC);
1725 void dp_bridge_hpd_enable(struct drm_bridge *bridge)
1727 struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge);
1728 struct msm_dp *dp_display = dp_bridge->dp_display;
1729 struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display);
1731 mutex_lock(&dp->event_mutex);
1732 dp_catalog_ctrl_hpd_enable(dp->catalog);
1734 /* enable HDP interrupts */
1735 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, true);
1737 dp_display->internal_hpd = true;
1738 mutex_unlock(&dp->event_mutex);
1741 void dp_bridge_hpd_disable(struct drm_bridge *bridge)
1743 struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge);
1744 struct msm_dp *dp_display = dp_bridge->dp_display;
1745 struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display);
1747 mutex_lock(&dp->event_mutex);
1748 /* disable HDP interrupts */
1749 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, false);
1750 dp_catalog_ctrl_hpd_disable(dp->catalog);
1752 dp_display->internal_hpd = false;
1753 mutex_unlock(&dp->event_mutex);
1756 void dp_bridge_hpd_notify(struct drm_bridge *bridge,
1757 enum drm_connector_status status)
1759 struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge);
1760 struct msm_dp *dp_display = dp_bridge->dp_display;
1761 struct dp_display_private *dp = container_of(dp_display, struct dp_display_private, dp_display);
1763 /* Without next_bridge interrupts are handled by the DP core directly */
1764 if (dp_display->internal_hpd)
1767 if (!dp->core_initialized) {
1768 drm_dbg_dp(dp->drm_dev, "not initialized\n");
1772 if (!dp_display->is_connected && status == connector_status_connected)
1773 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1774 else if (dp_display->is_connected && status == connector_status_disconnected)
1775 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);