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>
18 #include "dp_parser.h"
20 #include "dp_catalog.h"
26 #include "dp_display.h"
31 #define HPD_STRING_SIZE 30
38 ISR_IRQ_HPD_PULSE_COUNT,
39 ISR_HPD_LO_GLITH_COUNT,
42 /* event thread connection state */
47 ST_DISCONNECT_PENDING,
62 #define EVENT_TIMEOUT (HZ/10) /* 100ms */
63 #define DP_EVENT_Q_MAX 8
65 #define DP_TIMEOUT_NONE 0
67 #define WAIT_FOR_RESUME_TIMEOUT_JIFFIES (HZ / 2)
75 struct dp_display_private {
82 bool core_initialized;
87 struct drm_device *drm_dev;
88 struct platform_device *pdev;
91 struct dp_usbpd *usbpd;
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_usbpd_cb usbpd_cb;
102 struct dp_display_mode dp_mode;
103 struct msm_dp dp_display;
105 /* wait for audio signaling */
106 struct completion audio_comp;
108 /* event related only access by event thread */
109 struct mutex event_mutex;
110 wait_queue_head_t event_q;
114 struct task_struct *ev_tsk;
115 struct dp_event event_list[DP_EVENT_Q_MAX];
116 spinlock_t event_lock;
120 struct dp_audio *audio;
124 phys_addr_t io_start;
125 unsigned int connector_type;
129 struct msm_dp_config {
130 const struct msm_dp_desc *descs;
134 static const struct msm_dp_config sc7180_dp_cfg = {
135 .descs = (const struct msm_dp_desc[]) {
136 [MSM_DP_CONTROLLER_0] = { .io_start = 0x0ae90000, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
141 static const struct msm_dp_config sc7280_dp_cfg = {
142 .descs = (const struct msm_dp_desc[]) {
143 [MSM_DP_CONTROLLER_0] = { .io_start = 0x0ae90000, .connector_type = DRM_MODE_CONNECTOR_DisplayPort, .wide_bus_en = true },
144 [MSM_DP_CONTROLLER_1] = { .io_start = 0x0aea0000, .connector_type = DRM_MODE_CONNECTOR_eDP, .wide_bus_en = true },
149 static const struct msm_dp_config sc8180x_dp_cfg = {
150 .descs = (const struct msm_dp_desc[]) {
151 [MSM_DP_CONTROLLER_0] = { .io_start = 0x0ae90000, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
152 [MSM_DP_CONTROLLER_1] = { .io_start = 0x0ae98000, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
153 [MSM_DP_CONTROLLER_2] = { .io_start = 0x0ae9a000, .connector_type = DRM_MODE_CONNECTOR_eDP },
158 static const struct msm_dp_config sm8350_dp_cfg = {
159 .descs = (const struct msm_dp_desc[]) {
160 [MSM_DP_CONTROLLER_0] = { .io_start = 0x0ae90000, .connector_type = DRM_MODE_CONNECTOR_DisplayPort },
165 static const struct of_device_id dp_dt_match[] = {
166 { .compatible = "qcom,sc7180-dp", .data = &sc7180_dp_cfg },
167 { .compatible = "qcom,sc7280-dp", .data = &sc7280_dp_cfg },
168 { .compatible = "qcom,sc7280-edp", .data = &sc7280_dp_cfg },
169 { .compatible = "qcom,sc8180x-dp", .data = &sc8180x_dp_cfg },
170 { .compatible = "qcom,sc8180x-edp", .data = &sc8180x_dp_cfg },
171 { .compatible = "qcom,sm8350-dp", .data = &sm8350_dp_cfg },
175 static struct dp_display_private *dev_get_dp_display_private(struct device *dev)
177 struct msm_dp *dp = dev_get_drvdata(dev);
179 return container_of(dp, struct dp_display_private, dp_display);
182 static int dp_add_event(struct dp_display_private *dp_priv, u32 event,
186 struct dp_event *todo;
189 spin_lock_irqsave(&dp_priv->event_lock, flag);
190 pndx = dp_priv->event_pndx + 1;
191 pndx %= DP_EVENT_Q_MAX;
192 if (pndx == dp_priv->event_gndx) {
193 pr_err("event_q is full: pndx=%d gndx=%d\n",
194 dp_priv->event_pndx, dp_priv->event_gndx);
195 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
198 todo = &dp_priv->event_list[dp_priv->event_pndx++];
199 dp_priv->event_pndx %= DP_EVENT_Q_MAX;
200 todo->event_id = event;
203 wake_up(&dp_priv->event_q);
204 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
209 static int dp_del_event(struct dp_display_private *dp_priv, u32 event)
212 struct dp_event *todo;
215 spin_lock_irqsave(&dp_priv->event_lock, flag);
216 if (dp_priv->event_pndx == dp_priv->event_gndx) {
217 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
221 gndx = dp_priv->event_gndx;
222 while (dp_priv->event_pndx != gndx) {
223 todo = &dp_priv->event_list[gndx];
224 if (todo->event_id == event) {
225 todo->event_id = EV_NO_EVENT; /* deleted */
229 gndx %= DP_EVENT_Q_MAX;
231 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
236 void dp_display_signal_audio_start(struct msm_dp *dp_display)
238 struct dp_display_private *dp;
240 dp = container_of(dp_display, struct dp_display_private, dp_display);
242 reinit_completion(&dp->audio_comp);
245 void dp_display_signal_audio_complete(struct msm_dp *dp_display)
247 struct dp_display_private *dp;
249 dp = container_of(dp_display, struct dp_display_private, dp_display);
251 complete_all(&dp->audio_comp);
254 static int dp_hpd_event_thread_start(struct dp_display_private *dp_priv);
256 static int dp_display_bind(struct device *dev, struct device *master,
260 struct dp_display_private *dp = dev_get_dp_display_private(dev);
261 struct msm_drm_private *priv = dev_get_drvdata(master);
262 struct drm_device *drm = priv->dev;
264 dp->dp_display.drm_dev = drm;
265 priv->dp[dp->id] = &dp->dp_display;
267 rc = dp->parser->parse(dp->parser);
269 DRM_ERROR("device tree parsing failed\n");
275 dp->aux->drm_dev = drm;
276 rc = dp_aux_register(dp->aux);
278 DRM_ERROR("DRM DP AUX register failed\n");
282 rc = dp_power_client_init(dp->power);
284 DRM_ERROR("Power client create failed\n");
288 rc = dp_register_audio_driver(dev, dp->audio);
290 DRM_ERROR("Audio registration Dp failed\n");
294 rc = dp_hpd_event_thread_start(dp);
296 DRM_ERROR("Event thread create failed\n");
305 static void dp_display_unbind(struct device *dev, struct device *master,
308 struct dp_display_private *dp = dev_get_dp_display_private(dev);
309 struct msm_drm_private *priv = dev_get_drvdata(master);
311 /* disable all HPD interrupts */
312 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_INT_MASK, false);
314 kthread_stop(dp->ev_tsk);
316 dp_power_client_deinit(dp->power);
317 dp_aux_unregister(dp->aux);
318 priv->dp[dp->id] = NULL;
321 static const struct component_ops dp_display_comp_ops = {
322 .bind = dp_display_bind,
323 .unbind = dp_display_unbind,
326 static bool dp_display_is_ds_bridge(struct dp_panel *panel)
328 return (panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
329 DP_DWN_STRM_PORT_PRESENT);
332 static bool dp_display_is_sink_count_zero(struct dp_display_private *dp)
334 drm_dbg_dp(dp->drm_dev, "present=%#x sink_count=%d\n",
335 dp->panel->dpcd[DP_DOWNSTREAMPORT_PRESENT],
336 dp->link->sink_count);
337 return dp_display_is_ds_bridge(dp->panel) &&
338 (dp->link->sink_count == 0);
341 static void dp_display_send_hpd_event(struct msm_dp *dp_display)
343 struct dp_display_private *dp;
344 struct drm_connector *connector;
346 dp = container_of(dp_display, struct dp_display_private, dp_display);
348 connector = dp->dp_display.connector;
349 drm_helper_hpd_irq_event(connector->dev);
353 static int dp_display_send_hpd_notification(struct dp_display_private *dp,
356 if ((hpd && dp->dp_display.is_connected) ||
357 (!hpd && !dp->dp_display.is_connected)) {
358 drm_dbg_dp(dp->drm_dev, "HPD already %s\n",
359 (hpd ? "on" : "off"));
363 /* reset video pattern flag on disconnect */
365 dp->panel->video_test = false;
367 dp->dp_display.is_connected = hpd;
369 drm_dbg_dp(dp->drm_dev, "type=%d hpd=%d\n",
370 dp->dp_display.connector_type, hpd);
371 dp_display_send_hpd_event(&dp->dp_display);
376 static int dp_display_process_hpd_high(struct dp_display_private *dp)
381 dp->panel->max_dp_lanes = dp->parser->max_dp_lanes;
383 rc = dp_panel_read_sink_caps(dp->panel, dp->dp_display.connector);
387 dp_link_process_request(dp->link);
389 edid = dp->panel->edid;
391 dp->audio_supported = drm_detect_monitor_audio(edid);
392 dp_panel_handle_sink_request(dp->panel);
394 dp->dp_display.max_dp_lanes = dp->parser->max_dp_lanes;
397 * set sink to normal operation mode -- D0
400 dp_link_psm_config(dp->link, &dp->panel->link_info, false);
402 dp_link_reset_phy_params_vx_px(dp->link);
403 rc = dp_ctrl_on_link(dp->ctrl);
405 DRM_ERROR("failed to complete DP link training\n");
409 dp_add_event(dp, EV_USER_NOTIFICATION, true, 0);
415 static void dp_display_host_phy_init(struct dp_display_private *dp)
417 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
418 dp->dp_display.connector_type, dp->core_initialized,
419 dp->phy_initialized);
421 if (!dp->phy_initialized) {
422 dp_ctrl_phy_init(dp->ctrl);
423 dp->phy_initialized = true;
427 static void dp_display_host_phy_exit(struct dp_display_private *dp)
429 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
430 dp->dp_display.connector_type, dp->core_initialized,
431 dp->phy_initialized);
433 if (dp->phy_initialized) {
434 dp_ctrl_phy_exit(dp->ctrl);
435 dp->phy_initialized = false;
439 static void dp_display_host_init(struct dp_display_private *dp)
441 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
442 dp->dp_display.connector_type, dp->core_initialized,
443 dp->phy_initialized);
445 dp_power_init(dp->power, false);
446 dp_ctrl_reset_irq_ctrl(dp->ctrl, true);
447 dp_aux_init(dp->aux);
448 dp->core_initialized = true;
451 static void dp_display_host_deinit(struct dp_display_private *dp)
453 drm_dbg_dp(dp->drm_dev, "type=%d core_init=%d phy_init=%d\n",
454 dp->dp_display.connector_type, dp->core_initialized,
455 dp->phy_initialized);
457 dp_ctrl_reset_irq_ctrl(dp->ctrl, false);
458 dp_aux_deinit(dp->aux);
459 dp_power_deinit(dp->power);
460 dp->core_initialized = false;
463 static int dp_display_usbpd_configure_cb(struct device *dev)
465 struct dp_display_private *dp = dev_get_dp_display_private(dev);
467 dp_display_host_phy_init(dp);
469 return dp_display_process_hpd_high(dp);
472 static int dp_display_usbpd_disconnect_cb(struct device *dev)
477 static int dp_display_notify_disconnect(struct device *dev)
479 struct dp_display_private *dp = dev_get_dp_display_private(dev);
481 dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
486 static void dp_display_handle_video_request(struct dp_display_private *dp)
488 if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
489 dp->panel->video_test = true;
490 dp_link_send_test_response(dp->link);
494 static int dp_display_handle_port_ststus_changed(struct dp_display_private *dp)
498 if (dp_display_is_sink_count_zero(dp)) {
499 drm_dbg_dp(dp->drm_dev, "sink count is zero, nothing to do\n");
500 if (dp->hpd_state != ST_DISCONNECTED) {
501 dp->hpd_state = ST_DISCONNECT_PENDING;
502 dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
505 if (dp->hpd_state == ST_DISCONNECTED) {
506 dp->hpd_state = ST_MAINLINK_READY;
507 rc = dp_display_process_hpd_high(dp);
509 dp->hpd_state = ST_DISCONNECTED;
516 static int dp_display_handle_irq_hpd(struct dp_display_private *dp)
518 u32 sink_request = dp->link->sink_request;
520 drm_dbg_dp(dp->drm_dev, "%d\n", sink_request);
521 if (dp->hpd_state == ST_DISCONNECTED) {
522 if (sink_request & DP_LINK_STATUS_UPDATED) {
523 drm_dbg_dp(dp->drm_dev, "Disconnected sink_request: %d\n",
525 DRM_ERROR("Disconnected, no DP_LINK_STATUS_UPDATED\n");
530 dp_ctrl_handle_sink_request(dp->ctrl);
532 if (sink_request & DP_TEST_LINK_VIDEO_PATTERN)
533 dp_display_handle_video_request(dp);
538 static int dp_display_usbpd_attention_cb(struct device *dev)
542 struct dp_display_private *dp = dev_get_dp_display_private(dev);
544 /* check for any test request issued by sink */
545 rc = dp_link_process_request(dp->link);
547 sink_request = dp->link->sink_request;
548 drm_dbg_dp(dp->drm_dev, "hpd_state=%d sink_request=%d\n",
549 dp->hpd_state, sink_request);
550 if (sink_request & DS_PORT_STATUS_CHANGED)
551 rc = dp_display_handle_port_ststus_changed(dp);
553 rc = dp_display_handle_irq_hpd(dp);
559 static int dp_hpd_plug_handle(struct dp_display_private *dp, u32 data)
561 struct dp_usbpd *hpd = dp->usbpd;
568 mutex_lock(&dp->event_mutex);
570 state = dp->hpd_state;
571 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
572 dp->dp_display.connector_type, state);
574 if (state == ST_DISPLAY_OFF || state == ST_SUSPENDED) {
575 mutex_unlock(&dp->event_mutex);
579 if (state == ST_MAINLINK_READY || state == ST_CONNECTED) {
580 mutex_unlock(&dp->event_mutex);
584 if (state == ST_DISCONNECT_PENDING) {
585 /* wait until ST_DISCONNECTED */
586 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 1); /* delay = 1 */
587 mutex_unlock(&dp->event_mutex);
591 ret = dp_display_usbpd_configure_cb(&dp->pdev->dev);
592 if (ret) { /* link train failed */
593 dp->hpd_state = ST_DISCONNECTED;
595 dp->hpd_state = ST_MAINLINK_READY;
598 /* enable HDP irq_hpd/replug interrupt */
599 dp_catalog_hpd_config_intr(dp->catalog,
600 DP_DP_IRQ_HPD_INT_MASK | DP_DP_HPD_REPLUG_INT_MASK, true);
602 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
603 dp->dp_display.connector_type, state);
604 mutex_unlock(&dp->event_mutex);
606 /* uevent will complete connection part */
610 static int dp_display_enable(struct dp_display_private *dp, u32 data);
611 static int dp_display_disable(struct dp_display_private *dp, u32 data);
613 static void dp_display_handle_plugged_change(struct msm_dp *dp_display,
616 struct dp_display_private *dp;
618 dp = container_of(dp_display,
619 struct dp_display_private, dp_display);
621 /* notify audio subsystem only if sink supports audio */
622 if (dp_display->plugged_cb && dp_display->codec_dev &&
624 dp_display->plugged_cb(dp_display->codec_dev, plugged);
627 static int dp_hpd_unplug_handle(struct dp_display_private *dp, u32 data)
629 struct dp_usbpd *hpd = dp->usbpd;
635 mutex_lock(&dp->event_mutex);
637 state = dp->hpd_state;
639 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
640 dp->dp_display.connector_type, state);
642 /* disable irq_hpd/replug interrupts */
643 dp_catalog_hpd_config_intr(dp->catalog,
644 DP_DP_IRQ_HPD_INT_MASK | DP_DP_HPD_REPLUG_INT_MASK, false);
646 /* unplugged, no more irq_hpd handle */
647 dp_del_event(dp, EV_IRQ_HPD_INT);
649 if (state == ST_DISCONNECTED) {
650 /* triggered by irq_hdp with sink_count = 0 */
651 if (dp->link->sink_count == 0) {
652 dp_display_host_phy_exit(dp);
654 dp_display_notify_disconnect(&dp->pdev->dev);
655 mutex_unlock(&dp->event_mutex);
657 } else if (state == ST_DISCONNECT_PENDING) {
658 mutex_unlock(&dp->event_mutex);
660 } else if (state == ST_MAINLINK_READY) {
661 dp_ctrl_off_link(dp->ctrl);
662 dp_display_host_phy_exit(dp);
663 dp->hpd_state = ST_DISCONNECTED;
664 dp_display_notify_disconnect(&dp->pdev->dev);
665 mutex_unlock(&dp->event_mutex);
669 /* disable HPD plug interrupts */
670 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_PLUG_INT_MASK, false);
673 * We don't need separate work for disconnect as
674 * connect/attention interrupts are disabled
676 dp_display_notify_disconnect(&dp->pdev->dev);
678 if (state == ST_DISPLAY_OFF) {
679 dp->hpd_state = ST_DISCONNECTED;
681 dp->hpd_state = ST_DISCONNECT_PENDING;
684 /* signal the disconnect event early to ensure proper teardown */
685 dp_display_handle_plugged_change(&dp->dp_display, false);
687 /* enable HDP plug interrupt to prepare for next plugin */
688 if (!dp->dp_display.is_edp)
689 dp_catalog_hpd_config_intr(dp->catalog, DP_DP_HPD_PLUG_INT_MASK, true);
691 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
692 dp->dp_display.connector_type, state);
694 /* uevent will complete disconnection part */
695 mutex_unlock(&dp->event_mutex);
699 static int dp_irq_hpd_handle(struct dp_display_private *dp, u32 data)
703 mutex_lock(&dp->event_mutex);
705 /* irq_hpd can happen at either connected or disconnected state */
706 state = dp->hpd_state;
707 drm_dbg_dp(dp->drm_dev, "Before, type=%d hpd_state=%d\n",
708 dp->dp_display.connector_type, state);
710 if (state == ST_DISPLAY_OFF || state == ST_SUSPENDED) {
711 mutex_unlock(&dp->event_mutex);
715 if (state == ST_MAINLINK_READY || state == ST_DISCONNECT_PENDING) {
716 /* wait until ST_CONNECTED */
717 dp_add_event(dp, EV_IRQ_HPD_INT, 0, 1); /* delay = 1 */
718 mutex_unlock(&dp->event_mutex);
722 dp_display_usbpd_attention_cb(&dp->pdev->dev);
724 drm_dbg_dp(dp->drm_dev, "After, type=%d hpd_state=%d\n",
725 dp->dp_display.connector_type, state);
727 mutex_unlock(&dp->event_mutex);
732 static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
734 dp_debug_put(dp->debug);
735 dp_audio_put(dp->audio);
736 dp_panel_put(dp->panel);
740 static int dp_init_sub_modules(struct dp_display_private *dp)
743 struct device *dev = &dp->pdev->dev;
744 struct dp_usbpd_cb *cb = &dp->usbpd_cb;
745 struct dp_panel_in panel_in = {
749 /* Callback APIs used for cable status change event */
750 cb->configure = dp_display_usbpd_configure_cb;
751 cb->disconnect = dp_display_usbpd_disconnect_cb;
752 cb->attention = dp_display_usbpd_attention_cb;
754 dp->usbpd = dp_hpd_get(dev, cb);
755 if (IS_ERR(dp->usbpd)) {
756 rc = PTR_ERR(dp->usbpd);
757 DRM_ERROR("failed to initialize hpd, rc = %d\n", rc);
762 dp->parser = dp_parser_get(dp->pdev);
763 if (IS_ERR(dp->parser)) {
764 rc = PTR_ERR(dp->parser);
765 DRM_ERROR("failed to initialize parser, rc = %d\n", rc);
770 dp->catalog = dp_catalog_get(dev, &dp->parser->io);
771 if (IS_ERR(dp->catalog)) {
772 rc = PTR_ERR(dp->catalog);
773 DRM_ERROR("failed to initialize catalog, rc = %d\n", rc);
778 dp->power = dp_power_get(dev, dp->parser);
779 if (IS_ERR(dp->power)) {
780 rc = PTR_ERR(dp->power);
781 DRM_ERROR("failed to initialize power, rc = %d\n", rc);
786 dp->aux = dp_aux_get(dev, dp->catalog, dp->dp_display.is_edp);
787 if (IS_ERR(dp->aux)) {
788 rc = PTR_ERR(dp->aux);
789 DRM_ERROR("failed to initialize aux, rc = %d\n", rc);
794 dp->link = dp_link_get(dev, dp->aux);
795 if (IS_ERR(dp->link)) {
796 rc = PTR_ERR(dp->link);
797 DRM_ERROR("failed to initialize link, rc = %d\n", rc);
802 panel_in.aux = dp->aux;
803 panel_in.catalog = dp->catalog;
804 panel_in.link = dp->link;
806 dp->panel = dp_panel_get(&panel_in);
807 if (IS_ERR(dp->panel)) {
808 rc = PTR_ERR(dp->panel);
809 DRM_ERROR("failed to initialize panel, rc = %d\n", rc);
814 dp->ctrl = dp_ctrl_get(dev, dp->link, dp->panel, dp->aux,
815 dp->power, dp->catalog, dp->parser);
816 if (IS_ERR(dp->ctrl)) {
817 rc = PTR_ERR(dp->ctrl);
818 DRM_ERROR("failed to initialize ctrl, rc = %d\n", rc);
823 dp->audio = dp_audio_get(dp->pdev, dp->panel, dp->catalog);
824 if (IS_ERR(dp->audio)) {
825 rc = PTR_ERR(dp->audio);
826 pr_err("failed to initialize audio, rc = %d\n", rc);
831 /* populate wide_bus_en to differernt layers */
832 dp->ctrl->wide_bus_en = dp->wide_bus_en;
833 dp->catalog->wide_bus_en = dp->wide_bus_en;
838 dp_panel_put(dp->panel);
845 static int dp_display_set_mode(struct msm_dp *dp_display,
846 struct dp_display_mode *mode)
848 struct dp_display_private *dp;
850 dp = container_of(dp_display, struct dp_display_private, dp_display);
852 dp->panel->dp_mode.drm_mode = mode->drm_mode;
853 dp->panel->dp_mode.bpp = mode->bpp;
854 dp->panel->dp_mode.capabilities = mode->capabilities;
855 dp_panel_init_panel_info(dp->panel);
859 static int dp_display_prepare(struct msm_dp *dp_display)
864 static int dp_display_enable(struct dp_display_private *dp, u32 data)
867 struct msm_dp *dp_display = &dp->dp_display;
869 drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
870 if (dp_display->power_on) {
871 drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
875 rc = dp_ctrl_on_stream(dp->ctrl);
877 dp_display->power_on = true;
882 static int dp_display_post_enable(struct msm_dp *dp_display)
884 struct dp_display_private *dp;
887 dp = container_of(dp_display, struct dp_display_private, dp_display);
889 rate = dp->link->link_params.rate;
891 if (dp->audio_supported) {
892 dp->audio->bw_code = drm_dp_link_rate_to_bw_code(rate);
893 dp->audio->lane_count = dp->link->link_params.num_lanes;
896 /* signal the connect event late to synchronize video and display */
897 dp_display_handle_plugged_change(dp_display, true);
901 static int dp_display_disable(struct dp_display_private *dp, u32 data)
903 struct msm_dp *dp_display = &dp->dp_display;
905 if (!dp_display->power_on)
908 /* wait only if audio was enabled */
909 if (dp_display->audio_enabled) {
910 /* signal the disconnect event */
911 dp_display_handle_plugged_change(dp_display, false);
912 if (!wait_for_completion_timeout(&dp->audio_comp,
914 DRM_ERROR("audio comp timeout\n");
917 dp_display->audio_enabled = false;
919 if (dp->link->sink_count == 0) {
921 * irq_hpd with sink_count = 0
922 * hdmi unplugged out of dongle
924 dp_ctrl_off_link_stream(dp->ctrl);
927 * unplugged interrupt
928 * dongle unplugged out of DUT
930 dp_ctrl_off(dp->ctrl);
931 dp_display_host_phy_exit(dp);
934 dp_display->power_on = false;
936 drm_dbg_dp(dp->drm_dev, "sink count: %d\n", dp->link->sink_count);
940 static int dp_display_unprepare(struct msm_dp *dp_display)
945 int dp_display_set_plugged_cb(struct msm_dp *dp_display,
946 hdmi_codec_plugged_cb fn, struct device *codec_dev)
950 dp_display->plugged_cb = fn;
951 dp_display->codec_dev = codec_dev;
952 plugged = dp_display->is_connected;
953 dp_display_handle_plugged_change(dp_display, plugged);
959 * dp_bridge_mode_valid - callback to determine if specified mode is valid
960 * @bridge: Pointer to drm bridge structure
961 * @info: display info
962 * @mode: Pointer to drm mode structure
963 * Returns: Validity status for specified mode
965 enum drm_mode_status dp_bridge_mode_valid(struct drm_bridge *bridge,
966 const struct drm_display_info *info,
967 const struct drm_display_mode *mode)
969 const u32 num_components = 3, default_bpp = 24;
970 struct dp_display_private *dp_display;
971 struct dp_link_info *link_info;
972 u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
974 int mode_pclk_khz = mode->clock;
976 dp = to_dp_bridge(bridge)->dp_display;
978 if (!dp || !mode_pclk_khz || !dp->connector) {
979 DRM_ERROR("invalid params\n");
984 * The eDP controller currently does not have a reliable way of
985 * enabling panel power to read sink capabilities. So, we rely
986 * on the panel driver to populate only supported modes for now.
991 if (mode->clock > DP_MAX_PIXEL_CLK_KHZ)
994 dp_display = container_of(dp, struct dp_display_private, dp_display);
995 link_info = &dp_display->panel->link_info;
997 mode_bpp = dp->connector->display_info.bpc * num_components;
999 mode_bpp = default_bpp;
1001 mode_bpp = dp_panel_get_mode_bpp(dp_display->panel,
1002 mode_bpp, mode_pclk_khz);
1004 mode_rate_khz = mode_pclk_khz * mode_bpp;
1005 supported_rate_khz = link_info->num_lanes * link_info->rate * 8;
1007 if (mode_rate_khz > supported_rate_khz)
1013 int dp_display_get_modes(struct msm_dp *dp)
1015 struct dp_display_private *dp_display;
1018 DRM_ERROR("invalid params\n");
1022 dp_display = container_of(dp, struct dp_display_private, dp_display);
1024 return dp_panel_get_modes(dp_display->panel,
1028 bool dp_display_check_video_test(struct msm_dp *dp)
1030 struct dp_display_private *dp_display;
1032 dp_display = container_of(dp, struct dp_display_private, dp_display);
1034 return dp_display->panel->video_test;
1037 int dp_display_get_test_bpp(struct msm_dp *dp)
1039 struct dp_display_private *dp_display;
1042 DRM_ERROR("invalid params\n");
1046 dp_display = container_of(dp, struct dp_display_private, dp_display);
1048 return dp_link_bit_depth_to_bpp(
1049 dp_display->link->test_video.test_bit_depth);
1052 void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)
1054 struct dp_display_private *dp_display;
1056 dp_display = container_of(dp, struct dp_display_private, dp_display);
1059 * if we are reading registers we need the link clocks to be on
1060 * however till DP cable is connected this will not happen as we
1061 * do not know the resolution to power up with. Hence check the
1062 * power_on status before dumping DP registers to avoid crash due
1063 * to unclocked access
1065 mutex_lock(&dp_display->event_mutex);
1067 if (!dp->power_on) {
1068 mutex_unlock(&dp_display->event_mutex);
1072 dp_catalog_snapshot(dp_display->catalog, disp_state);
1074 mutex_unlock(&dp_display->event_mutex);
1077 static void dp_display_config_hpd(struct dp_display_private *dp)
1080 dp_display_host_init(dp);
1081 dp_catalog_ctrl_hpd_config(dp->catalog);
1083 /* Enable plug and unplug interrupts only for external DisplayPort */
1084 if (!dp->dp_display.is_edp)
1085 dp_catalog_hpd_config_intr(dp->catalog,
1086 DP_DP_HPD_PLUG_INT_MASK |
1087 DP_DP_HPD_UNPLUG_INT_MASK,
1090 /* Enable interrupt first time
1091 * we are leaving dp clocks on during disconnect
1092 * and never disable interrupt
1094 enable_irq(dp->irq);
1097 static int hpd_event_thread(void *data)
1099 struct dp_display_private *dp_priv;
1101 struct dp_event *todo;
1102 int timeout_mode = 0;
1104 dp_priv = (struct dp_display_private *)data;
1108 wait_event_timeout(dp_priv->event_q,
1109 (dp_priv->event_pndx == dp_priv->event_gndx) ||
1110 kthread_should_stop(), EVENT_TIMEOUT);
1112 wait_event_interruptible(dp_priv->event_q,
1113 (dp_priv->event_pndx != dp_priv->event_gndx) ||
1114 kthread_should_stop());
1117 if (kthread_should_stop())
1120 spin_lock_irqsave(&dp_priv->event_lock, flag);
1121 todo = &dp_priv->event_list[dp_priv->event_gndx];
1123 struct dp_event *todo_next;
1125 dp_priv->event_gndx++;
1126 dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1128 /* re enter delay event into q */
1129 todo_next = &dp_priv->event_list[dp_priv->event_pndx++];
1130 dp_priv->event_pndx %= DP_EVENT_Q_MAX;
1131 todo_next->event_id = todo->event_id;
1132 todo_next->data = todo->data;
1133 todo_next->delay = todo->delay - 1;
1135 /* clean up older event */
1136 todo->event_id = EV_NO_EVENT;
1139 /* switch to timeout mode */
1141 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1145 /* timeout with no events in q */
1146 if (dp_priv->event_pndx == dp_priv->event_gndx) {
1147 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1151 dp_priv->event_gndx++;
1152 dp_priv->event_gndx %= DP_EVENT_Q_MAX;
1154 spin_unlock_irqrestore(&dp_priv->event_lock, flag);
1156 switch (todo->event_id) {
1157 case EV_HPD_INIT_SETUP:
1158 dp_display_config_hpd(dp_priv);
1160 case EV_HPD_PLUG_INT:
1161 dp_hpd_plug_handle(dp_priv, todo->data);
1163 case EV_HPD_UNPLUG_INT:
1164 dp_hpd_unplug_handle(dp_priv, todo->data);
1166 case EV_IRQ_HPD_INT:
1167 dp_irq_hpd_handle(dp_priv, todo->data);
1169 case EV_USER_NOTIFICATION:
1170 dp_display_send_hpd_notification(dp_priv,
1181 static int dp_hpd_event_thread_start(struct dp_display_private *dp_priv)
1183 /* set event q to empty */
1184 dp_priv->event_gndx = 0;
1185 dp_priv->event_pndx = 0;
1187 dp_priv->ev_tsk = kthread_run(hpd_event_thread, dp_priv, "dp_hpd_handler");
1188 if (IS_ERR(dp_priv->ev_tsk))
1189 return PTR_ERR(dp_priv->ev_tsk);
1194 static irqreturn_t dp_display_irq_handler(int irq, void *dev_id)
1196 struct dp_display_private *dp = dev_id;
1197 irqreturn_t ret = IRQ_HANDLED;
1201 DRM_ERROR("invalid data\n");
1205 hpd_isr_status = dp_catalog_hpd_get_intr_status(dp->catalog);
1207 if (hpd_isr_status & 0x0F) {
1208 drm_dbg_dp(dp->drm_dev, "type=%d isr=0x%x\n",
1209 dp->dp_display.connector_type, hpd_isr_status);
1210 /* hpd related interrupts */
1211 if (hpd_isr_status & DP_DP_HPD_PLUG_INT_MASK)
1212 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0);
1214 if (hpd_isr_status & DP_DP_IRQ_HPD_INT_MASK) {
1215 dp_add_event(dp, EV_IRQ_HPD_INT, 0, 0);
1218 if (hpd_isr_status & DP_DP_HPD_REPLUG_INT_MASK) {
1219 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1220 dp_add_event(dp, EV_HPD_PLUG_INT, 0, 3);
1223 if (hpd_isr_status & DP_DP_HPD_UNPLUG_INT_MASK)
1224 dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0);
1227 /* DP controller isr */
1228 dp_ctrl_isr(dp->ctrl);
1231 dp_aux_isr(dp->aux);
1236 int dp_display_request_irq(struct msm_dp *dp_display)
1239 struct dp_display_private *dp;
1242 DRM_ERROR("invalid input\n");
1246 dp = container_of(dp_display, struct dp_display_private, dp_display);
1248 dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
1250 DRM_ERROR("failed to get irq\n");
1254 rc = devm_request_irq(&dp->pdev->dev, dp->irq,
1255 dp_display_irq_handler,
1256 IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
1258 DRM_ERROR("failed to request IRQ%u: %d\n",
1262 disable_irq(dp->irq);
1267 static const struct msm_dp_desc *dp_display_get_desc(struct platform_device *pdev,
1270 const struct msm_dp_config *cfg = of_device_get_match_data(&pdev->dev);
1271 struct resource *res;
1274 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1278 for (i = 0; i < cfg->num_descs; i++) {
1279 if (cfg->descs[i].io_start == res->start) {
1281 return &cfg->descs[i];
1285 dev_err(&pdev->dev, "unknown displayport instance\n");
1289 static int dp_display_probe(struct platform_device *pdev)
1292 struct dp_display_private *dp;
1293 const struct msm_dp_desc *desc;
1295 if (!pdev || !pdev->dev.of_node) {
1296 DRM_ERROR("pdev not found\n");
1300 dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
1304 desc = dp_display_get_desc(pdev, &dp->id);
1309 dp->name = "drm_dp";
1310 dp->dp_display.connector_type = desc->connector_type;
1311 dp->wide_bus_en = desc->wide_bus_en;
1312 dp->dp_display.is_edp =
1313 (dp->dp_display.connector_type == DRM_MODE_CONNECTOR_eDP);
1315 rc = dp_init_sub_modules(dp);
1317 DRM_ERROR("init sub module failed\n");
1318 return -EPROBE_DEFER;
1322 mutex_init(&dp->event_mutex);
1323 init_waitqueue_head(&dp->event_q);
1324 spin_lock_init(&dp->event_lock);
1326 /* Store DP audio handle inside DP display */
1327 dp->dp_display.dp_audio = dp->audio;
1329 init_completion(&dp->audio_comp);
1331 platform_set_drvdata(pdev, &dp->dp_display);
1333 rc = component_add(&pdev->dev, &dp_display_comp_ops);
1335 DRM_ERROR("component add failed, rc=%d\n", rc);
1336 dp_display_deinit_sub_modules(dp);
1342 static int dp_display_remove(struct platform_device *pdev)
1344 struct dp_display_private *dp = dev_get_dp_display_private(&pdev->dev);
1346 dp_display_deinit_sub_modules(dp);
1348 component_del(&pdev->dev, &dp_display_comp_ops);
1349 platform_set_drvdata(pdev, NULL);
1354 static int dp_pm_resume(struct device *dev)
1356 struct platform_device *pdev = to_platform_device(dev);
1357 struct msm_dp *dp_display = platform_get_drvdata(pdev);
1358 struct dp_display_private *dp;
1361 dp = container_of(dp_display, struct dp_display_private, dp_display);
1363 mutex_lock(&dp->event_mutex);
1365 drm_dbg_dp(dp->drm_dev,
1366 "Before, type=%d core_inited=%d phy_inited=%d power_on=%d\n",
1367 dp->dp_display.connector_type, dp->core_initialized,
1368 dp->phy_initialized, dp_display->power_on);
1370 /* start from disconnected state */
1371 dp->hpd_state = ST_DISCONNECTED;
1373 /* turn on dp ctrl/phy */
1374 dp_display_host_init(dp);
1376 dp_catalog_ctrl_hpd_config(dp->catalog);
1379 if (!dp->dp_display.is_edp)
1380 dp_catalog_hpd_config_intr(dp->catalog,
1381 DP_DP_HPD_PLUG_INT_MASK |
1382 DP_DP_HPD_UNPLUG_INT_MASK,
1385 if (dp_catalog_link_is_connected(dp->catalog)) {
1387 * set sink to normal operation mode -- D0
1390 dp_display_host_phy_init(dp);
1391 dp_link_psm_config(dp->link, &dp->panel->link_info, false);
1392 sink_count = drm_dp_read_sink_count(dp->aux);
1396 dp_display_host_phy_exit(dp);
1399 dp->link->sink_count = sink_count;
1401 * can not declared display is connected unless
1402 * HDMI cable is plugged in and sink_count of
1404 * also only signal audio when disconnected
1406 if (dp->link->sink_count) {
1407 dp->dp_display.is_connected = true;
1409 dp->dp_display.is_connected = false;
1410 dp_display_handle_plugged_change(dp_display, false);
1413 drm_dbg_dp(dp->drm_dev,
1414 "After, type=%d sink=%d conn=%d core_init=%d phy_init=%d power=%d\n",
1415 dp->dp_display.connector_type, dp->link->sink_count,
1416 dp->dp_display.is_connected, dp->core_initialized,
1417 dp->phy_initialized, dp_display->power_on);
1419 mutex_unlock(&dp->event_mutex);
1424 static int dp_pm_suspend(struct device *dev)
1426 struct platform_device *pdev = to_platform_device(dev);
1427 struct msm_dp *dp_display = platform_get_drvdata(pdev);
1428 struct dp_display_private *dp;
1430 dp = container_of(dp_display, struct dp_display_private, dp_display);
1432 mutex_lock(&dp->event_mutex);
1434 drm_dbg_dp(dp->drm_dev,
1435 "Before, type=%d core_inited=%d phy_inited=%d power_on=%d\n",
1436 dp->dp_display.connector_type, dp->core_initialized,
1437 dp->phy_initialized, dp_display->power_on);
1439 /* mainlink enabled */
1440 if (dp_power_clk_status(dp->power, DP_CTRL_PM))
1441 dp_ctrl_off_link_stream(dp->ctrl);
1443 dp_display_host_phy_exit(dp);
1445 /* host_init will be called at pm_resume */
1446 dp_display_host_deinit(dp);
1448 dp->hpd_state = ST_SUSPENDED;
1450 drm_dbg_dp(dp->drm_dev,
1451 "After, type=%d core_inited=%d phy_inited=%d power_on=%d\n",
1452 dp->dp_display.connector_type, dp->core_initialized,
1453 dp->phy_initialized, dp_display->power_on);
1455 mutex_unlock(&dp->event_mutex);
1460 static int dp_pm_prepare(struct device *dev)
1465 static void dp_pm_complete(struct device *dev)
1470 static const struct dev_pm_ops dp_pm_ops = {
1471 .suspend = dp_pm_suspend,
1472 .resume = dp_pm_resume,
1473 .prepare = dp_pm_prepare,
1474 .complete = dp_pm_complete,
1477 static struct platform_driver dp_display_driver = {
1478 .probe = dp_display_probe,
1479 .remove = dp_display_remove,
1481 .name = "msm-dp-display",
1482 .of_match_table = dp_dt_match,
1483 .suppress_bind_attrs = true,
1488 int __init msm_dp_register(void)
1492 ret = platform_driver_register(&dp_display_driver);
1494 DRM_ERROR("Dp display driver register failed");
1499 void __exit msm_dp_unregister(void)
1501 platform_driver_unregister(&dp_display_driver);
1504 void msm_dp_irq_postinstall(struct msm_dp *dp_display)
1506 struct dp_display_private *dp;
1511 dp = container_of(dp_display, struct dp_display_private, dp_display);
1513 if (!dp_display->is_edp)
1514 dp_add_event(dp, EV_HPD_INIT_SETUP, 0, 100);
1517 bool msm_dp_wide_bus_available(const struct msm_dp *dp_display)
1519 struct dp_display_private *dp;
1521 dp = container_of(dp_display, struct dp_display_private, dp_display);
1523 return dp->wide_bus_en;
1526 void msm_dp_debugfs_init(struct msm_dp *dp_display, struct drm_minor *minor)
1528 struct dp_display_private *dp;
1532 dp = container_of(dp_display, struct dp_display_private, dp_display);
1533 dev = &dp->pdev->dev;
1535 dp->debug = dp_debug_get(dev, dp->panel, dp->usbpd,
1536 dp->link, dp->dp_display.connector,
1538 if (IS_ERR(dp->debug)) {
1539 rc = PTR_ERR(dp->debug);
1540 DRM_ERROR("failed to initialize debug, rc = %d\n", rc);
1545 static int dp_display_get_next_bridge(struct msm_dp *dp)
1548 struct dp_display_private *dp_priv;
1549 struct device_node *aux_bus;
1552 dp_priv = container_of(dp, struct dp_display_private, dp_display);
1553 dev = &dp_priv->pdev->dev;
1554 aux_bus = of_get_child_by_name(dev->of_node, "aux-bus");
1556 if (aux_bus && dp->is_edp) {
1557 dp_display_host_init(dp_priv);
1558 dp_catalog_ctrl_hpd_config(dp_priv->catalog);
1559 dp_display_host_phy_init(dp_priv);
1560 enable_irq(dp_priv->irq);
1563 * The code below assumes that the panel will finish probing
1564 * by the time devm_of_dp_aux_populate_ep_devices() returns.
1565 * This isn't a great assumption since it will fail if the
1566 * panel driver is probed asynchronously but is the best we
1567 * can do without a bigger driver reorganization.
1569 rc = devm_of_dp_aux_populate_ep_devices(dp_priv->aux);
1570 of_node_put(aux_bus);
1573 } else if (dp->is_edp) {
1574 DRM_ERROR("eDP aux_bus not found\n");
1579 * External bridges are mandatory for eDP interfaces: one has to
1580 * provide at least an eDP panel (which gets wrapped into panel-bridge).
1582 * For DisplayPort interfaces external bridges are optional, so
1583 * silently ignore an error if one is not present (-ENODEV).
1585 rc = dp_parser_find_next_bridge(dp_priv->parser);
1586 if (!dp->is_edp && rc == -ENODEV)
1590 dp->next_bridge = dp_priv->parser->next_bridge;
1596 disable_irq(dp_priv->irq);
1597 dp_display_host_phy_exit(dp_priv);
1598 dp_display_host_deinit(dp_priv);
1603 int msm_dp_modeset_init(struct msm_dp *dp_display, struct drm_device *dev,
1604 struct drm_encoder *encoder)
1606 struct msm_drm_private *priv;
1607 struct dp_display_private *dp_priv;
1610 if (WARN_ON(!encoder) || WARN_ON(!dp_display) || WARN_ON(!dev))
1613 priv = dev->dev_private;
1614 dp_display->drm_dev = dev;
1616 dp_priv = container_of(dp_display, struct dp_display_private, dp_display);
1618 ret = dp_display_request_irq(dp_display);
1620 DRM_ERROR("request_irq failed, ret=%d\n", ret);
1624 dp_display->encoder = encoder;
1626 ret = dp_display_get_next_bridge(dp_display);
1630 dp_display->bridge = dp_bridge_init(dp_display, dev, encoder);
1631 if (IS_ERR(dp_display->bridge)) {
1632 ret = PTR_ERR(dp_display->bridge);
1633 DRM_DEV_ERROR(dev->dev,
1634 "failed to create dp bridge: %d\n", ret);
1635 dp_display->bridge = NULL;
1639 priv->bridges[priv->num_bridges++] = dp_display->bridge;
1641 dp_display->connector = dp_drm_connector_init(dp_display);
1642 if (IS_ERR(dp_display->connector)) {
1643 ret = PTR_ERR(dp_display->connector);
1644 DRM_DEV_ERROR(dev->dev,
1645 "failed to create dp connector: %d\n", ret);
1646 dp_display->connector = NULL;
1650 dp_priv->panel->connector = dp_display->connector;
1655 void dp_bridge_enable(struct drm_bridge *drm_bridge)
1657 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1658 struct msm_dp *dp = dp_bridge->dp_display;
1660 struct dp_display_private *dp_display;
1663 dp_display = container_of(dp, struct dp_display_private, dp_display);
1664 if (!dp_display->dp_mode.drm_mode.clock) {
1665 DRM_ERROR("invalid params\n");
1670 dp_hpd_plug_handle(dp_display, 0);
1672 mutex_lock(&dp_display->event_mutex);
1674 state = dp_display->hpd_state;
1675 if (state != ST_DISPLAY_OFF && state != ST_MAINLINK_READY) {
1676 mutex_unlock(&dp_display->event_mutex);
1680 rc = dp_display_set_mode(dp, &dp_display->dp_mode);
1682 DRM_ERROR("Failed to perform a mode set, rc=%d\n", rc);
1683 mutex_unlock(&dp_display->event_mutex);
1687 rc = dp_display_prepare(dp);
1689 DRM_ERROR("DP display prepare failed, rc=%d\n", rc);
1690 mutex_unlock(&dp_display->event_mutex);
1694 state = dp_display->hpd_state;
1696 if (state == ST_DISPLAY_OFF)
1697 dp_display_host_phy_init(dp_display);
1699 dp_display_enable(dp_display, 0);
1701 rc = dp_display_post_enable(dp);
1703 DRM_ERROR("DP display post enable failed, rc=%d\n", rc);
1704 dp_display_disable(dp_display, 0);
1705 dp_display_unprepare(dp);
1708 /* manual kick off plug event to train link */
1709 if (state == ST_DISPLAY_OFF)
1710 dp_add_event(dp_display, EV_IRQ_HPD_INT, 0, 0);
1712 /* completed connection */
1713 dp_display->hpd_state = ST_CONNECTED;
1715 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1716 mutex_unlock(&dp_display->event_mutex);
1719 void dp_bridge_disable(struct drm_bridge *drm_bridge)
1721 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1722 struct msm_dp *dp = dp_bridge->dp_display;
1723 struct dp_display_private *dp_display;
1725 dp_display = container_of(dp, struct dp_display_private, dp_display);
1727 dp_ctrl_push_idle(dp_display->ctrl);
1730 void dp_bridge_post_disable(struct drm_bridge *drm_bridge)
1732 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1733 struct msm_dp *dp = dp_bridge->dp_display;
1736 struct dp_display_private *dp_display;
1738 dp_display = container_of(dp, struct dp_display_private, dp_display);
1741 dp_hpd_unplug_handle(dp_display, 0);
1743 mutex_lock(&dp_display->event_mutex);
1745 state = dp_display->hpd_state;
1746 if (state != ST_DISCONNECT_PENDING && state != ST_CONNECTED) {
1747 mutex_unlock(&dp_display->event_mutex);
1751 dp_display_disable(dp_display, 0);
1753 rc = dp_display_unprepare(dp);
1755 DRM_ERROR("DP display unprepare failed, rc=%d\n", rc);
1757 state = dp_display->hpd_state;
1758 if (state == ST_DISCONNECT_PENDING) {
1759 /* completed disconnection */
1760 dp_display->hpd_state = ST_DISCONNECTED;
1762 dp_display->hpd_state = ST_DISPLAY_OFF;
1765 drm_dbg_dp(dp->drm_dev, "type=%d Done\n", dp->connector_type);
1766 mutex_unlock(&dp_display->event_mutex);
1769 void dp_bridge_mode_set(struct drm_bridge *drm_bridge,
1770 const struct drm_display_mode *mode,
1771 const struct drm_display_mode *adjusted_mode)
1773 struct msm_dp_bridge *dp_bridge = to_dp_bridge(drm_bridge);
1774 struct msm_dp *dp = dp_bridge->dp_display;
1775 struct dp_display_private *dp_display;
1777 dp_display = container_of(dp, struct dp_display_private, dp_display);
1779 memset(&dp_display->dp_mode, 0x0, sizeof(struct dp_display_mode));
1781 if (dp_display_check_video_test(dp))
1782 dp_display->dp_mode.bpp = dp_display_get_test_bpp(dp);
1783 else /* Default num_components per pixel = 3 */
1784 dp_display->dp_mode.bpp = dp->connector->display_info.bpc * 3;
1786 if (!dp_display->dp_mode.bpp)
1787 dp_display->dp_mode.bpp = 24; /* Default bpp */
1789 drm_mode_copy(&dp_display->dp_mode.drm_mode, adjusted_mode);
1791 dp_display->dp_mode.v_active_low =
1792 !!(dp_display->dp_mode.drm_mode.flags & DRM_MODE_FLAG_NVSYNC);
1794 dp_display->dp_mode.h_active_low =
1795 !!(dp_display->dp_mode.drm_mode.flags & DRM_MODE_FLAG_NHSYNC);