Lines Matching defs:dp
25 #include "cdn-dp-core.h"
26 #include "cdn-dp-reg.h"
61 { .compatible = "rockchip,rk3399-cdn-dp",
68 static int cdn_dp_grf_write(struct cdn_dp_device *dp,
73 ret = clk_prepare_enable(dp->grf_clk);
75 DRM_DEV_ERROR(dp->dev, "Failed to prepare_enable grf clock\n");
79 ret = regmap_write(dp->grf, reg, val);
81 DRM_DEV_ERROR(dp->dev, "Could not write to GRF: %d\n", ret);
82 clk_disable_unprepare(dp->grf_clk);
86 clk_disable_unprepare(dp->grf_clk);
91 static int cdn_dp_clk_enable(struct cdn_dp_device *dp)
96 ret = clk_prepare_enable(dp->pclk);
98 DRM_DEV_ERROR(dp->dev, "cannot enable dp pclk %d\n", ret);
102 ret = clk_prepare_enable(dp->core_clk);
104 DRM_DEV_ERROR(dp->dev, "cannot enable core_clk %d\n", ret);
108 ret = pm_runtime_get_sync(dp->dev);
110 DRM_DEV_ERROR(dp->dev, "cannot get pm runtime %d\n", ret);
114 reset_control_assert(dp->core_rst);
115 reset_control_assert(dp->dptx_rst);
116 reset_control_assert(dp->apb_rst);
117 reset_control_deassert(dp->core_rst);
118 reset_control_deassert(dp->dptx_rst);
119 reset_control_deassert(dp->apb_rst);
121 rate = clk_get_rate(dp->core_clk);
123 DRM_DEV_ERROR(dp->dev, "get clk rate failed\n");
128 cdn_dp_set_fw_clk(dp, rate);
129 cdn_dp_clock_reset(dp);
134 pm_runtime_put(dp->dev);
136 clk_disable_unprepare(dp->core_clk);
138 clk_disable_unprepare(dp->pclk);
143 static void cdn_dp_clk_disable(struct cdn_dp_device *dp)
145 pm_runtime_put_sync(dp->dev);
146 clk_disable_unprepare(dp->pclk);
147 clk_disable_unprepare(dp->core_clk);
172 static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count)
178 ret = cdn_dp_dpcd_read(dp, DP_SINK_COUNT, &value, 1);
186 static struct cdn_dp_port *cdn_dp_connected_port(struct cdn_dp_device *dp)
191 for (i = 0; i < dp->ports; i++) {
192 port = dp->port[i];
200 static bool cdn_dp_check_sink_connection(struct cdn_dp_device *dp)
206 if (dp->active_port < 0 || dp->active_port >= dp->ports) {
207 DRM_DEV_ERROR(dp->dev, "active_port is wrong!\n");
211 port = dp->port[dp->active_port];
223 if (!cdn_dp_get_sink_count(dp, &sink_count))
229 DRM_DEV_ERROR(dp->dev, "Get sink capability timed out\n");
236 struct cdn_dp_device *dp = connector_to_dp(connector);
239 mutex_lock(&dp->lock);
240 if (dp->connected)
242 mutex_unlock(&dp->lock);
264 struct cdn_dp_device *dp = connector_to_dp(connector);
267 mutex_lock(&dp->lock);
271 mutex_unlock(&dp->lock);
280 struct cdn_dp_device *dp = connector_to_dp(connector);
281 struct drm_display_info *display_info = &dp->connector.display_info;
286 if (!dp->connected)
303 source_max = dp->lanes;
304 sink_max = drm_dp_max_lane_count(dp->dpcd);
308 sink_max = drm_dp_max_link_rate(dp->dpcd);
317 DRM_DEV_DEBUG_KMS(dp->dev,
331 static int cdn_dp_firmware_init(struct cdn_dp_device *dp)
335 const struct firmware *fw = dp->fw;
340 DRM_DEV_ERROR(dp->dev, "firmware is invalid\n");
347 ret = cdn_dp_load_firmware(dp, iram_data, hdr->iram_size,
352 ret = cdn_dp_set_firmware_active(dp, true);
354 DRM_DEV_ERROR(dp->dev, "active ucpu failed: %d\n", ret);
358 return cdn_dp_event_config(dp);
361 static int cdn_dp_get_sink_capability(struct cdn_dp_device *dp)
363 const struct drm_display_info *info = &dp->connector.display_info;
366 if (!cdn_dp_check_sink_connection(dp))
369 ret = cdn_dp_dpcd_read(dp, DP_DPCD_REV, dp->dpcd,
372 DRM_DEV_ERROR(dp->dev, "Failed to get caps %d\n", ret);
376 drm_edid_free(dp->drm_edid);
377 dp->drm_edid = drm_edid_read_custom(&dp->connector,
378 cdn_dp_get_edid_block, dp);
379 drm_edid_connector_update(&dp->connector, dp->drm_edid);
381 dp->sink_has_audio = info->has_audio;
383 if (dp->drm_edid)
384 DRM_DEV_DEBUG_KMS(dp->dev, "got edid: width[%d] x height[%d]\n",
390 static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port)
398 DRM_DEV_ERROR(dp->dev, "phy power on failed: %d\n",
405 ret = cdn_dp_grf_write(dp, GRF_SOC_CON26,
408 DRM_DEV_ERROR(dp->dev, "Failed to write HPD_SEL %d\n", ret);
412 ret = cdn_dp_get_hpd_status(dp);
415 DRM_DEV_ERROR(dp->dev, "hpd does not exist\n");
422 DRM_DEV_ERROR(dp->dev, "get property failed\n");
427 ret = cdn_dp_set_host_cap(dp, port->lanes, property.intval);
429 DRM_DEV_ERROR(dp->dev, "set host capabilities failed: %d\n",
434 dp->active_port = port->id;
439 DRM_DEV_ERROR(dp->dev, "phy power off failed: %d", ret);
444 cdn_dp_grf_write(dp, GRF_SOC_CON26,
449 static int cdn_dp_disable_phy(struct cdn_dp_device *dp,
457 DRM_DEV_ERROR(dp->dev, "phy power off failed: %d", ret);
464 dp->active_port = -1;
468 static int cdn_dp_disable(struct cdn_dp_device *dp)
472 if (!dp->active)
475 for (i = 0; i < dp->ports; i++)
476 cdn_dp_disable_phy(dp, dp->port[i]);
478 ret = cdn_dp_grf_write(dp, GRF_SOC_CON26,
481 DRM_DEV_ERROR(dp->dev, "Failed to clear hpd sel %d\n",
486 cdn_dp_set_firmware_active(dp, false);
487 cdn_dp_clk_disable(dp);
488 dp->active = false;
489 dp->max_lanes = 0;
490 dp->max_rate = 0;
491 if (!dp->connected) {
492 drm_edid_free(dp->drm_edid);
493 dp->drm_edid = NULL;
499 static int cdn_dp_enable(struct cdn_dp_device *dp)
504 port = cdn_dp_connected_port(dp);
506 DRM_DEV_ERROR(dp->dev,
511 if (dp->active)
514 ret = cdn_dp_clk_enable(dp);
518 ret = cdn_dp_firmware_init(dp);
520 DRM_DEV_ERROR(dp->dev, "firmware init failed: %d", ret);
525 for (i = port->id; i < dp->ports; i++) {
526 port = dp->port[i];
529 ret = cdn_dp_enable_phy(dp, port);
533 ret = cdn_dp_get_sink_capability(dp);
535 cdn_dp_disable_phy(dp, port);
537 dp->active = true;
538 dp->lanes = port->lanes;
545 cdn_dp_clk_disable(dp);
553 struct cdn_dp_device *dp = encoder_to_dp(encoder);
554 struct drm_display_info *display_info = &dp->connector.display_info;
555 struct video_info *video = &dp->video_info;
573 drm_mode_copy(&dp->mode, adjusted);
576 static bool cdn_dp_check_link_status(struct cdn_dp_device *dp)
579 struct cdn_dp_port *port = cdn_dp_connected_port(dp);
580 u8 sink_lanes = drm_dp_max_lane_count(dp->dpcd);
582 if (!port || !dp->max_rate || !dp->max_lanes)
585 if (cdn_dp_dpcd_read(dp, DP_LANE0_1_STATUS, link_status,
595 static void cdn_dp_audio_handle_plugged_change(struct cdn_dp_device *dp,
598 if (dp->codec_dev)
599 dp->plugged_cb(dp->codec_dev, plugged);
604 struct cdn_dp_device *dp = encoder_to_dp(encoder);
607 ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder);
609 DRM_DEV_ERROR(dp->dev, "Could not get vop id, %d", ret);
613 DRM_DEV_DEBUG_KMS(dp->dev, "vop %s output to cdn-dp\n",
620 ret = cdn_dp_grf_write(dp, GRF_SOC_CON9, val);
624 mutex_lock(&dp->lock);
626 ret = cdn_dp_enable(dp);
628 DRM_DEV_ERROR(dp->dev, "Failed to enable encoder %d\n",
632 if (!cdn_dp_check_link_status(dp)) {
633 ret = cdn_dp_train_link(dp);
635 DRM_DEV_ERROR(dp->dev, "Failed link train %d\n", ret);
640 ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_IDLE);
642 DRM_DEV_ERROR(dp->dev, "Failed to idle video %d\n", ret);
646 ret = cdn_dp_config_video(dp);
648 DRM_DEV_ERROR(dp->dev, "Failed to config video %d\n", ret);
652 ret = cdn_dp_set_video_status(dp, CONTROL_VIDEO_VALID);
654 DRM_DEV_ERROR(dp->dev, "Failed to valid video %d\n", ret);
658 cdn_dp_audio_handle_plugged_change(dp, true);
661 mutex_unlock(&dp->lock);
666 struct cdn_dp_device *dp = encoder_to_dp(encoder);
669 mutex_lock(&dp->lock);
670 cdn_dp_audio_handle_plugged_change(dp, false);
672 if (dp->active) {
673 ret = cdn_dp_disable(dp);
675 DRM_DEV_ERROR(dp->dev, "Failed to disable encoder %d\n",
679 mutex_unlock(&dp->lock);
690 if (!dp->connected && cdn_dp_connected_port(dp))
691 schedule_work(&dp->event_work);
713 static int cdn_dp_parse_dt(struct cdn_dp_device *dp)
715 struct device *dev = dp->dev;
719 dp->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
720 if (IS_ERR(dp->grf)) {
721 DRM_DEV_ERROR(dev, "cdn-dp needs rockchip,grf property\n");
722 return PTR_ERR(dp->grf);
725 dp->regs = devm_platform_ioremap_resource(pdev, 0);
726 if (IS_ERR(dp->regs)) {
728 return PTR_ERR(dp->regs);
731 dp->core_clk = devm_clk_get(dev, "core-clk");
732 if (IS_ERR(dp->core_clk)) {
734 return PTR_ERR(dp->core_clk);
737 dp->pclk = devm_clk_get(dev, "pclk");
738 if (IS_ERR(dp->pclk)) {
740 return PTR_ERR(dp->pclk);
743 dp->spdif_clk = devm_clk_get(dev, "spdif");
744 if (IS_ERR(dp->spdif_clk)) {
746 return PTR_ERR(dp->spdif_clk);
749 dp->grf_clk = devm_clk_get(dev, "grf");
750 if (IS_ERR(dp->grf_clk)) {
752 return PTR_ERR(dp->grf_clk);
755 dp->spdif_rst = devm_reset_control_get(dev, "spdif");
756 if (IS_ERR(dp->spdif_rst)) {
758 return PTR_ERR(dp->spdif_rst);
761 dp->dptx_rst = devm_reset_control_get(dev, "dptx");
762 if (IS_ERR(dp->dptx_rst)) {
764 return PTR_ERR(dp->dptx_rst);
767 dp->core_rst = devm_reset_control_get(dev, "core");
768 if (IS_ERR(dp->core_rst)) {
770 return PTR_ERR(dp->core_rst);
773 dp->apb_rst = devm_reset_control_get(dev, "apb");
774 if (IS_ERR(dp->apb_rst)) {
776 return PTR_ERR(dp->apb_rst);
786 struct cdn_dp_device *dp = dev_get_drvdata(dev);
794 mutex_lock(&dp->lock);
795 if (!dp->active) {
813 ret = cdn_dp_audio_config(dp, &audio);
815 dp->audio_info = audio;
818 mutex_unlock(&dp->lock);
824 struct cdn_dp_device *dp = dev_get_drvdata(dev);
827 mutex_lock(&dp->lock);
828 if (!dp->active)
831 ret = cdn_dp_audio_stop(dp, &dp->audio_info);
833 dp->audio_info.format = AFMT_UNUSED;
835 mutex_unlock(&dp->lock);
841 struct cdn_dp_device *dp = dev_get_drvdata(dev);
844 mutex_lock(&dp->lock);
845 if (!dp->active) {
850 ret = cdn_dp_audio_mute(dp, enable);
853 mutex_unlock(&dp->lock);
860 struct cdn_dp_device *dp = dev_get_drvdata(dev);
862 memcpy(buf, dp->connector.eld, min(sizeof(dp->connector.eld), len));
871 struct cdn_dp_device *dp = dev_get_drvdata(dev);
873 mutex_lock(&dp->lock);
874 dp->plugged_cb = fn;
875 dp->codec_dev = codec_dev;
876 cdn_dp_audio_handle_plugged_change(dp, dp->connected);
877 mutex_unlock(&dp->lock);
890 static int cdn_dp_audio_codec_init(struct cdn_dp_device *dp,
901 dp->audio_pdev = platform_device_register_data(
905 return PTR_ERR_OR_ZERO(dp->audio_pdev);
908 static int cdn_dp_request_firmware(struct cdn_dp_device *dp)
914 WARN_ON(!mutex_is_locked(&dp->lock));
916 if (dp->fw_loaded)
920 mutex_unlock(&dp->lock);
923 ret = request_firmware(&dp->fw, CDN_DP_FIRMWARE, dp->dev);
929 DRM_DEV_ERROR(dp->dev,
934 dp->fw_loaded = true;
939 DRM_DEV_ERROR(dp->dev, "Timed out trying to load firmware\n");
942 mutex_lock(&dp->lock);
948 struct cdn_dp_device *dp = container_of(work, struct cdn_dp_device,
952 mutex_lock(&dp->lock);
954 if (dp->suspended)
957 ret = cdn_dp_request_firmware(dp);
961 dp->connected = true;
964 if (!cdn_dp_connected_port(dp)) {
965 DRM_DEV_INFO(dp->dev, "Not connected; disabling cdn\n");
966 dp->connected = false;
969 } else if (!dp->active) {
970 DRM_DEV_INFO(dp->dev, "Connected, not enabled; enabling cdn\n");
971 ret = cdn_dp_enable(dp);
973 DRM_DEV_ERROR(dp->dev, "Enabling dp failed: %d\n", ret);
974 dp->connected = false;
978 } else if (!cdn_dp_check_sink_connection(dp)) {
979 DRM_DEV_INFO(dp->dev, "Connected without sink; assert hpd\n");
980 dp->connected = false;
983 } else if (!cdn_dp_check_link_status(dp)) {
984 unsigned int rate = dp->max_rate;
985 unsigned int lanes = dp->max_lanes;
986 struct drm_display_mode *mode = &dp->mode;
988 DRM_DEV_INFO(dp->dev, "Connected with sink; re-train link\n");
989 ret = cdn_dp_train_link(dp);
991 dp->connected = false;
992 DRM_DEV_ERROR(dp->dev, "Training link failed: %d\n", ret);
998 (rate != dp->max_rate || lanes != dp->max_lanes)) {
999 ret = cdn_dp_config_video(dp);
1001 dp->connected = false;
1002 DRM_DEV_ERROR(dp->dev, "Failed to configure video: %d\n", ret);
1008 mutex_unlock(&dp->lock);
1009 drm_connector_helper_hpd_irq_event(&dp->connector);
1017 struct cdn_dp_device *dp = port->dp;
1024 schedule_work(&dp->event_work);
1031 struct cdn_dp_device *dp = dev_get_drvdata(dev);
1038 ret = cdn_dp_parse_dt(dp);
1042 dp->drm_dev = drm_dev;
1043 dp->connected = false;
1044 dp->active = false;
1045 dp->active_port = -1;
1046 dp->fw_loaded = false;
1048 INIT_WORK(&dp->event_work, cdn_dp_pd_event_work);
1050 encoder = &dp->encoder.encoder;
1065 connector = &dp->connector;
1085 for (i = 0; i < dp->ports; i++) {
1086 port = dp->port[i];
1089 ret = devm_extcon_register_notifier(dp->dev, port->extcon,
1101 schedule_work(&dp->event_work);
1114 struct cdn_dp_device *dp = dev_get_drvdata(dev);
1115 struct drm_encoder *encoder = &dp->encoder.encoder;
1116 struct drm_connector *connector = &dp->connector;
1118 cancel_work_sync(&dp->event_work);
1124 if (dp->fw_loaded)
1125 release_firmware(dp->fw);
1126 drm_edid_free(dp->drm_edid);
1127 dp->drm_edid = NULL;
1137 struct cdn_dp_device *dp = dev_get_drvdata(dev);
1140 mutex_lock(&dp->lock);
1141 if (dp->active)
1142 ret = cdn_dp_disable(dp);
1143 dp->suspended = true;
1144 mutex_unlock(&dp->lock);
1151 struct cdn_dp_device *dp = dev_get_drvdata(dev);
1153 mutex_lock(&dp->lock);
1154 dp->suspended = false;
1155 if (dp->fw_loaded)
1156 schedule_work(&dp->event_work);
1157 mutex_unlock(&dp->lock);
1168 struct cdn_dp_device *dp;
1174 dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL);
1175 if (!dp)
1177 dp->dev = dev;
1199 port->dp = dp;
1201 dp->port[dp->ports++] = port;
1204 if (!dp->ports) {
1209 mutex_init(&dp->lock);
1210 dev_set_drvdata(dev, dp);
1212 ret = cdn_dp_audio_codec_init(dp, dev);
1223 platform_device_unregister(dp->audio_pdev);
1229 struct cdn_dp_device *dp = platform_get_drvdata(pdev);
1231 platform_device_unregister(dp->audio_pdev);
1232 cdn_dp_suspend(dp->dev);
1238 struct cdn_dp_device *dp = platform_get_drvdata(pdev);
1240 cdn_dp_suspend(dp->dev);
1253 .name = "cdn-dp",