2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/string.h>
27 #include <linux/acpi.h>
28 #include <linux/i2c.h>
30 #include <drm/drm_probe_helper.h>
31 #include <drm/amdgpu_drm.h>
32 #include <drm/drm_edid.h>
34 #include "dm_services.h"
37 #include "amdgpu_dm.h"
38 #include "amdgpu_dm_irq.h"
39 #include "amdgpu_dm_mst_types.h"
41 #include "dm_helpers.h"
42 #include "ddc_service_types.h"
44 struct monitor_patch_info {
45 unsigned int manufacturer_id;
46 unsigned int product_id;
47 void (*patch_func)(struct dc_edid_caps *edid_caps, unsigned int param);
48 unsigned int patch_param;
50 static void set_max_dsc_bpp_limit(struct dc_edid_caps *edid_caps, unsigned int param);
52 static const struct monitor_patch_info monitor_patch_table[] = {
53 {0x6D1E, 0x5BBF, set_max_dsc_bpp_limit, 15},
54 {0x6D1E, 0x5B9A, set_max_dsc_bpp_limit, 15},
57 static void set_max_dsc_bpp_limit(struct dc_edid_caps *edid_caps, unsigned int param)
60 edid_caps->panel_patch.max_dsc_target_bpp_limit = param;
63 static int amdgpu_dm_patch_edid_caps(struct dc_edid_caps *edid_caps)
67 for (i = 0; i < ARRAY_SIZE(monitor_patch_table); i++)
68 if ((edid_caps->manufacturer_id == monitor_patch_table[i].manufacturer_id)
69 && (edid_caps->product_id == monitor_patch_table[i].product_id)) {
70 monitor_patch_table[i].patch_func(edid_caps, monitor_patch_table[i].patch_param);
77 /* dm_helpers_parse_edid_caps
81 * @edid: [in] pointer to edid
82 * edid_caps: [in] pointer to edid caps
86 enum dc_edid_status dm_helpers_parse_edid_caps(
88 const struct dc_edid *edid,
89 struct dc_edid_caps *edid_caps)
91 struct amdgpu_dm_connector *aconnector = link->priv;
92 struct drm_connector *connector = &aconnector->base;
93 struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid : NULL;
100 enum dc_edid_status result = EDID_OK;
102 if (!edid_caps || !edid)
103 return EDID_BAD_INPUT;
105 if (!drm_edid_is_valid(edid_buf))
106 result = EDID_BAD_CHECKSUM;
108 edid_caps->manufacturer_id = (uint16_t) edid_buf->mfg_id[0] |
109 ((uint16_t) edid_buf->mfg_id[1])<<8;
110 edid_caps->product_id = (uint16_t) edid_buf->prod_code[0] |
111 ((uint16_t) edid_buf->prod_code[1])<<8;
112 edid_caps->serial_number = edid_buf->serial;
113 edid_caps->manufacture_week = edid_buf->mfg_week;
114 edid_caps->manufacture_year = edid_buf->mfg_year;
116 drm_edid_get_monitor_name(edid_buf,
117 edid_caps->display_name,
118 AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS);
120 edid_caps->edid_hdmi = connector->display_info.is_hdmi;
122 sad_count = drm_edid_to_sad((struct edid *) edid->raw_edid, &sads);
126 edid_caps->audio_mode_count = sad_count < DC_MAX_AUDIO_DESC_COUNT ? sad_count : DC_MAX_AUDIO_DESC_COUNT;
127 for (i = 0; i < edid_caps->audio_mode_count; ++i) {
128 struct cea_sad *sad = &sads[i];
130 edid_caps->audio_modes[i].format_code = sad->format;
131 edid_caps->audio_modes[i].channel_count = sad->channels + 1;
132 edid_caps->audio_modes[i].sample_rate = sad->freq;
133 edid_caps->audio_modes[i].sample_size = sad->byte2;
136 sadb_count = drm_edid_to_speaker_allocation((struct edid *) edid->raw_edid, &sadb);
138 if (sadb_count < 0) {
139 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sadb_count);
144 edid_caps->speaker_flags = sadb[0];
146 edid_caps->speaker_flags = DEFAULT_SPEAKER_LOCATION;
151 amdgpu_dm_patch_edid_caps(edid_caps);
156 static void get_payload_table(
157 struct amdgpu_dm_connector *aconnector,
158 struct dp_mst_stream_allocation_table *proposed_table)
161 struct drm_dp_mst_topology_mgr *mst_mgr =
162 &aconnector->mst_port->mst_mgr;
164 mutex_lock(&mst_mgr->payload_lock);
166 proposed_table->stream_count = 0;
168 /* number of active streams */
169 for (i = 0; i < mst_mgr->max_payloads; i++) {
170 if (mst_mgr->payloads[i].num_slots == 0)
171 break; /* end of vcp_id table */
173 ASSERT(mst_mgr->payloads[i].payload_state !=
174 DP_PAYLOAD_DELETE_LOCAL);
176 if (mst_mgr->payloads[i].payload_state == DP_PAYLOAD_LOCAL ||
177 mst_mgr->payloads[i].payload_state ==
180 struct dp_mst_stream_allocation *sa =
181 &proposed_table->stream_allocations[
182 proposed_table->stream_count];
184 sa->slot_count = mst_mgr->payloads[i].num_slots;
185 sa->vcp_id = mst_mgr->proposed_vcpis[i]->vcpi;
186 proposed_table->stream_count++;
190 mutex_unlock(&mst_mgr->payload_lock);
193 void dm_helpers_dp_update_branch_info(
194 struct dc_context *ctx,
195 const struct dc_link *link)
199 * Writes payload allocation table in immediate downstream device.
201 bool dm_helpers_dp_mst_write_payload_allocation_table(
202 struct dc_context *ctx,
203 const struct dc_stream_state *stream,
204 struct dp_mst_stream_allocation_table *proposed_table,
207 struct amdgpu_dm_connector *aconnector;
208 struct dm_connector_state *dm_conn_state;
209 struct drm_dp_mst_topology_mgr *mst_mgr;
210 struct drm_dp_mst_port *mst_port;
212 u8 link_coding_cap = DP_8b_10b_ENCODING;
214 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
215 /* Accessing the connector state is required for vcpi_slots allocation
216 * and directly relies on behaviour in commit check
217 * that blocks before commit guaranteeing that the state
218 * is not gonna be swapped while still in use in commit tail */
220 if (!aconnector || !aconnector->mst_port)
223 dm_conn_state = to_dm_connector_state(aconnector->base.state);
225 mst_mgr = &aconnector->mst_port->mst_mgr;
227 if (!mst_mgr->mst_state)
230 mst_port = aconnector->port;
232 #if defined(CONFIG_DRM_AMD_DC_DCN)
233 link_coding_cap = dc_link_dp_mst_decide_link_encoding_format(aconnector->dc_link);
238 ret = drm_dp_mst_allocate_vcpi(mst_mgr, mst_port,
240 dm_conn_state->vcpi_slots);
245 drm_dp_mst_reset_vcpi_slots(mst_mgr, mst_port);
248 /* It's OK for this to fail */
249 drm_dp_update_payload_part1(mst_mgr, (link_coding_cap == DP_CAP_ANSI_128B132B) ? 0:1);
251 /* mst_mgr->->payloads are VC payload notify MST branch using DPCD or
252 * AUX message. The sequence is slot 1-63 allocated sequence for each
253 * stream. AMD ASIC stream slot allocation should follow the same
254 * sequence. copy DRM MST allocation to dc */
256 get_payload_table(aconnector, proposed_table);
262 * poll pending down reply
264 void dm_helpers_dp_mst_poll_pending_down_reply(
265 struct dc_context *ctx,
266 const struct dc_link *link)
270 * Clear payload allocation table before enable MST DP link.
272 void dm_helpers_dp_mst_clear_payload_allocation_table(
273 struct dc_context *ctx,
274 const struct dc_link *link)
278 * Polls for ACT (allocation change trigger) handled and sends
279 * ALLOCATE_PAYLOAD message.
281 enum act_return_status dm_helpers_dp_mst_poll_for_allocation_change_trigger(
282 struct dc_context *ctx,
283 const struct dc_stream_state *stream)
285 struct amdgpu_dm_connector *aconnector;
286 struct drm_dp_mst_topology_mgr *mst_mgr;
289 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
291 if (!aconnector || !aconnector->mst_port)
294 mst_mgr = &aconnector->mst_port->mst_mgr;
296 if (!mst_mgr->mst_state)
299 ret = drm_dp_check_act_status(mst_mgr);
307 bool dm_helpers_dp_mst_send_payload_allocation(
308 struct dc_context *ctx,
309 const struct dc_stream_state *stream,
312 struct amdgpu_dm_connector *aconnector;
313 struct drm_dp_mst_topology_mgr *mst_mgr;
314 struct drm_dp_mst_port *mst_port;
315 enum mst_progress_status set_flag = MST_ALLOCATE_NEW_PAYLOAD;
316 enum mst_progress_status clr_flag = MST_CLEAR_ALLOCATED_PAYLOAD;
318 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
320 if (!aconnector || !aconnector->mst_port)
323 mst_port = aconnector->port;
325 mst_mgr = &aconnector->mst_port->mst_mgr;
327 if (!mst_mgr->mst_state)
331 set_flag = MST_CLEAR_ALLOCATED_PAYLOAD;
332 clr_flag = MST_ALLOCATE_NEW_PAYLOAD;
335 if (drm_dp_update_payload_part2(mst_mgr)) {
336 amdgpu_dm_set_mst_status(&aconnector->mst_status,
339 amdgpu_dm_set_mst_status(&aconnector->mst_status,
341 amdgpu_dm_set_mst_status(&aconnector->mst_status,
346 drm_dp_mst_deallocate_vcpi(mst_mgr, mst_port);
351 void dm_dtn_log_begin(struct dc_context *ctx,
352 struct dc_log_buffer_ctx *log_ctx)
354 static const char msg[] = "[dtn begin]\n";
361 dm_dtn_log_append_v(ctx, log_ctx, "%s", msg);
365 void dm_dtn_log_append_v(struct dc_context *ctx,
366 struct dc_log_buffer_ctx *log_ctx,
367 const char *msg, ...)
374 /* No context, redirect to dmesg. */
375 struct va_format vaf;
381 pr_info("%pV", &vaf);
387 /* Measure the output. */
389 n = vsnprintf(NULL, 0, msg, args);
395 /* Reallocate the string buffer as needed. */
396 total = log_ctx->pos + n + 1;
398 if (total > log_ctx->size) {
399 char *buf = (char *)kvcalloc(total, sizeof(char), GFP_KERNEL);
402 memcpy(buf, log_ctx->buf, log_ctx->pos);
406 log_ctx->size = total;
413 /* Write the formatted string to the log buffer. */
416 log_ctx->buf + log_ctx->pos,
417 log_ctx->size - log_ctx->pos,
426 void dm_dtn_log_end(struct dc_context *ctx,
427 struct dc_log_buffer_ctx *log_ctx)
429 static const char msg[] = "[dtn end]\n";
436 dm_dtn_log_append_v(ctx, log_ctx, "%s", msg);
439 bool dm_helpers_dp_mst_start_top_mgr(
440 struct dc_context *ctx,
441 const struct dc_link *link,
444 struct amdgpu_dm_connector *aconnector = link->priv;
447 DRM_ERROR("Failed to find connector for link!");
452 DRM_INFO("DM_MST: Differing MST start on aconnector: %p [id: %d]\n",
453 aconnector, aconnector->base.base.id);
457 DRM_INFO("DM_MST: starting TM on aconnector: %p [id: %d]\n",
458 aconnector, aconnector->base.base.id);
460 return (drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true) == 0);
463 bool dm_helpers_dp_mst_stop_top_mgr(
464 struct dc_context *ctx,
465 struct dc_link *link)
467 struct amdgpu_dm_connector *aconnector = link->priv;
470 DRM_ERROR("Failed to find connector for link!");
474 DRM_INFO("DM_MST: stopping TM on aconnector: %p [id: %d]\n",
475 aconnector, aconnector->base.base.id);
477 if (aconnector->mst_mgr.mst_state == true) {
478 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, false);
479 link->cur_link_settings.lane_count = 0;
485 bool dm_helpers_dp_read_dpcd(
486 struct dc_context *ctx,
487 const struct dc_link *link,
493 struct amdgpu_dm_connector *aconnector = link->priv;
496 DC_LOG_DC("Failed to find connector for link!\n");
500 return drm_dp_dpcd_read(&aconnector->dm_dp_aux.aux, address,
504 bool dm_helpers_dp_write_dpcd(
505 struct dc_context *ctx,
506 const struct dc_link *link,
511 struct amdgpu_dm_connector *aconnector = link->priv;
514 DRM_ERROR("Failed to find connector for link!");
518 return drm_dp_dpcd_write(&aconnector->dm_dp_aux.aux,
519 address, (uint8_t *)data, size) > 0;
522 bool dm_helpers_submit_i2c(
523 struct dc_context *ctx,
524 const struct dc_link *link,
525 struct i2c_command *cmd)
527 struct amdgpu_dm_connector *aconnector = link->priv;
528 struct i2c_msg *msgs;
530 int num = cmd->number_of_payloads;
534 DRM_ERROR("Failed to find connector for link!");
538 msgs = kcalloc(num, sizeof(struct i2c_msg), GFP_KERNEL);
543 for (i = 0; i < num; i++) {
544 msgs[i].flags = cmd->payloads[i].write ? 0 : I2C_M_RD;
545 msgs[i].addr = cmd->payloads[i].address;
546 msgs[i].len = cmd->payloads[i].length;
547 msgs[i].buf = cmd->payloads[i].data;
550 result = i2c_transfer(&aconnector->i2c->base, msgs, num) == num;
557 #if defined(CONFIG_DRM_AMD_DC_DCN)
558 static bool execute_synaptics_rc_command(struct drm_dp_aux *aux,
565 bool success = false;
566 unsigned char rc_data[16] = {0};
567 unsigned char rc_offset[4] = {0};
568 unsigned char rc_length[2] = {0};
569 unsigned char rc_cmd = 0;
570 unsigned char rc_result = 0xFF;
576 memmove(rc_data, data, length);
577 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_DATA, rc_data, sizeof(rc_data));
581 rc_offset[0] = (unsigned char) offset & 0xFF;
582 rc_offset[1] = (unsigned char) (offset >> 8) & 0xFF;
583 rc_offset[2] = (unsigned char) (offset >> 16) & 0xFF;
584 rc_offset[3] = (unsigned char) (offset >> 24) & 0xFF;
585 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_OFFSET, rc_offset, sizeof(rc_offset));
588 rc_length[0] = (unsigned char) length & 0xFF;
589 rc_length[1] = (unsigned char) (length >> 8) & 0xFF;
590 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_LENGTH, rc_length, sizeof(rc_length));
594 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_COMMAND, &rc_cmd, sizeof(rc_cmd));
597 DRM_ERROR(" execute_synaptics_rc_command - write cmd ..., err = %d\n", ret);
601 // poll until active is 0
602 for (i = 0; i < 10; i++) {
603 drm_dp_dpcd_read(aux, SYNAPTICS_RC_COMMAND, &rc_cmd, sizeof(rc_cmd));
611 drm_dp_dpcd_read(aux, SYNAPTICS_RC_RESULT, &rc_result, sizeof(rc_result));
612 success = (rc_result == 0);
614 if (success && !is_write_cmd) {
616 drm_dp_dpcd_read(aux, SYNAPTICS_RC_DATA, data, length);
619 DC_LOG_DC(" execute_synaptics_rc_command - success = %d\n", success);
624 static void apply_synaptics_fifo_reset_wa(struct drm_dp_aux *aux)
626 unsigned char data[16] = {0};
628 DC_LOG_DC("Start apply_synaptics_fifo_reset_wa\n");
637 if (!execute_synaptics_rc_command(aux, true, 0x01, 5, 0, data))
641 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220998, data))
644 data[0] &= (~(1 << 1)); // set bit 1 to 0
645 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x220998, data))
648 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220D98, data))
651 data[0] &= (~(1 << 1)); // set bit 1 to 0
652 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x220D98, data))
655 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x221198, data))
658 data[0] &= (~(1 << 1)); // set bit 1 to 0
659 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x221198, data))
663 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220998, data))
666 data[0] |= (1 << 1); // set bit 1 to 1
667 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x220998, data))
670 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220D98, data))
673 data[0] |= (1 << 1); // set bit 1 to 1
676 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x221198, data))
679 data[0] |= (1 << 1); // set bit 1 to 1
680 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x221198, data))
684 if (!execute_synaptics_rc_command(aux, true, 0x02, 0, 0, NULL))
687 DC_LOG_DC("Done apply_synaptics_fifo_reset_wa\n");
690 static uint8_t write_dsc_enable_synaptics_non_virtual_dpcd_mst(
691 struct drm_dp_aux *aux,
692 const struct dc_stream_state *stream,
697 DC_LOG_DC("Configure DSC to non-virtual dpcd synaptics\n");
700 /* When DSC is enabled on previous boot and reboot with the hub,
701 * there is a chance that Synaptics hub gets stuck during reboot sequence.
702 * Applying a workaround to reset Synaptics SDP fifo before enabling the first stream
704 if (!stream->link->link_status.link_active &&
705 memcmp(stream->link->dpcd_caps.branch_dev_name,
706 (int8_t *)SYNAPTICS_DEVICE_ID, 4) == 0)
707 apply_synaptics_fifo_reset_wa(aux);
709 ret = drm_dp_dpcd_write(aux, DP_DSC_ENABLE, &enable, 1);
710 DRM_INFO("Send DSC enable to synaptics\n");
713 /* Synaptics hub not support virtual dpcd,
714 * external monitor occur garbage while disable DSC,
715 * Disable DSC only when entire link status turn to false,
717 if (!stream->link->link_status.link_active) {
718 ret = drm_dp_dpcd_write(aux, DP_DSC_ENABLE, &enable, 1);
719 DRM_INFO("Send DSC disable to synaptics\n");
727 bool dm_helpers_dp_write_dsc_enable(
728 struct dc_context *ctx,
729 const struct dc_stream_state *stream,
732 uint8_t enable_dsc = enable ? 1 : 0;
733 struct amdgpu_dm_connector *aconnector;
739 if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
740 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
742 if (!aconnector->dsc_aux)
745 #if defined(CONFIG_DRM_AMD_DC_DCN)
746 // apply w/a to synaptics
747 if (needs_dsc_aux_workaround(aconnector->dc_link) &&
748 (aconnector->mst_downstream_port_present.byte & 0x7) != 0x3)
749 return write_dsc_enable_synaptics_non_virtual_dpcd_mst(
750 aconnector->dsc_aux, stream, enable_dsc);
753 ret = drm_dp_dpcd_write(aconnector->dsc_aux, DP_DSC_ENABLE, &enable_dsc, 1);
754 DC_LOG_DC("Send DSC %s to MST RX\n", enable_dsc ? "enable" : "disable");
757 if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT || stream->signal == SIGNAL_TYPE_EDP) {
758 #if defined(CONFIG_DRM_AMD_DC_DCN)
759 if (stream->sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_NONE) {
761 ret = dm_helpers_dp_write_dpcd(ctx, stream->link, DP_DSC_ENABLE, &enable_dsc, 1);
762 DC_LOG_DC("Send DSC %s to SST RX\n", enable_dsc ? "enable" : "disable");
763 #if defined(CONFIG_DRM_AMD_DC_DCN)
764 } else if (stream->sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER) {
765 ret = dm_helpers_dp_write_dpcd(ctx, stream->link, DP_DSC_ENABLE, &enable_dsc, 1);
766 DC_LOG_DC("Send DSC %s to DP-HDMI PCON\n", enable_dsc ? "enable" : "disable");
774 bool dm_helpers_is_dp_sink_present(struct dc_link *link)
776 bool dp_sink_present;
777 struct amdgpu_dm_connector *aconnector = link->priv;
780 BUG_ON("Failed to find connector for link!");
784 mutex_lock(&aconnector->dm_dp_aux.aux.hw_mutex);
785 dp_sink_present = dc_link_is_dp_sink_present(link);
786 mutex_unlock(&aconnector->dm_dp_aux.aux.hw_mutex);
787 return dp_sink_present;
790 enum dc_edid_status dm_helpers_read_local_edid(
791 struct dc_context *ctx,
792 struct dc_link *link,
793 struct dc_sink *sink)
795 struct amdgpu_dm_connector *aconnector = link->priv;
796 struct drm_connector *connector = &aconnector->base;
797 struct i2c_adapter *ddc;
799 enum dc_edid_status edid_status;
803 ddc = &aconnector->dm_dp_aux.aux.ddc;
805 ddc = &aconnector->i2c->base;
807 /* some dongles read edid incorrectly the first time,
808 * do check sum and retry to make sure read correct edid.
812 edid = drm_get_edid(&aconnector->base, ddc);
814 /* DP Compliance Test 4.2.2.6 */
815 if (link->aux_mode && connector->edid_corrupt)
816 drm_dp_send_real_edid_checksum(&aconnector->dm_dp_aux.aux, connector->real_edid_checksum);
818 if (!edid && connector->edid_corrupt) {
819 connector->edid_corrupt = false;
820 return EDID_BAD_CHECKSUM;
824 return EDID_NO_RESPONSE;
826 sink->dc_edid.length = EDID_LENGTH * (edid->extensions + 1);
827 memmove(sink->dc_edid.raw_edid, (uint8_t *)edid, sink->dc_edid.length);
829 /* We don't need the original edid anymore */
832 edid_status = dm_helpers_parse_edid_caps(
837 } while (edid_status == EDID_BAD_CHECKSUM && --retry > 0);
839 if (edid_status != EDID_OK)
840 DRM_ERROR("EDID err: %d, on connector: %s",
842 aconnector->base.name);
844 /* DP Compliance Test 4.2.2.3 */
846 drm_dp_send_real_edid_checksum(&aconnector->dm_dp_aux.aux, sink->dc_edid.raw_edid[sink->dc_edid.length-1]);
850 int dm_helper_dmub_aux_transfer_sync(
851 struct dc_context *ctx,
852 const struct dc_link *link,
853 struct aux_payload *payload,
854 enum aux_return_code_type *operation_result)
856 return amdgpu_dm_process_dmub_aux_transfer_sync(true, ctx,
857 link->link_index, (void *)payload,
858 (void *)operation_result);
861 int dm_helpers_dmub_set_config_sync(struct dc_context *ctx,
862 const struct dc_link *link,
863 struct set_config_cmd_payload *payload,
864 enum set_config_status *operation_result)
866 return amdgpu_dm_process_dmub_aux_transfer_sync(false, ctx,
867 link->link_index, (void *)payload,
868 (void *)operation_result);
871 void dm_set_dcn_clocks(struct dc_context *ctx, struct dc_clocks *clks)
873 /* TODO: something */
876 void dm_helpers_smu_timeout(struct dc_context *ctx, unsigned int msg_id, unsigned int param, unsigned int timeout_us)
879 //amdgpu_device_gpu_recover(dc_context->driver-context, NULL);
882 void *dm_helpers_allocate_gpu_mem(
883 struct dc_context *ctx,
884 enum dc_gpu_mem_alloc_type type,
888 struct amdgpu_device *adev = ctx->driver_context;
889 struct dal_allocation *da;
890 u32 domain = (type == DC_MEM_ALLOC_TYPE_GART) ?
891 AMDGPU_GEM_DOMAIN_GTT : AMDGPU_GEM_DOMAIN_VRAM;
894 da = kzalloc(sizeof(struct dal_allocation), GFP_KERNEL);
898 ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
900 &da->gpu_addr, &da->cpu_ptr);
902 *addr = da->gpu_addr;
909 /* add da to list in dm */
910 list_add(&da->list, &adev->dm.da_list);
915 void dm_helpers_free_gpu_mem(
916 struct dc_context *ctx,
917 enum dc_gpu_mem_alloc_type type,
920 struct amdgpu_device *adev = ctx->driver_context;
921 struct dal_allocation *da;
923 /* walk the da list in DM */
924 list_for_each_entry(da, &adev->dm.da_list, list) {
925 if (pvMem == da->cpu_ptr) {
926 amdgpu_bo_free_kernel(&da->bo, &da->gpu_addr, &da->cpu_ptr);
934 bool dm_helpers_dmub_outbox_interrupt_control(struct dc_context *ctx, bool enable)
936 enum dc_irq_source irq_source;
939 irq_source = DC_IRQ_SOURCE_DMCUB_OUTBOX;
941 ret = dc_interrupt_set(ctx->dc, irq_source, enable);
943 DRM_DEBUG_DRIVER("Dmub trace irq %sabling: r=%d\n",
944 enable ? "en" : "dis", ret);
948 void dm_helpers_mst_enable_stream_features(const struct dc_stream_state *stream)
950 /* TODO: virtual DPCD */
951 struct dc_link *link = stream->link;
952 union down_spread_ctrl old_downspread;
953 union down_spread_ctrl new_downspread;
955 if (link->aux_access_disabled)
958 if (!dm_helpers_dp_read_dpcd(link->ctx, link, DP_DOWNSPREAD_CTRL,
960 sizeof(old_downspread)))
963 new_downspread.raw = old_downspread.raw;
964 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
965 (stream->ignore_msa_timing_param) ? 1 : 0;
967 if (new_downspread.raw != old_downspread.raw)
968 dm_helpers_dp_write_dpcd(link->ctx, link, DP_DOWNSPREAD_CTRL,
970 sizeof(new_downspread));
973 void dm_set_phyd32clk(struct dc_context *ctx, int freq_khz)
978 void dm_helpers_enable_periodic_detection(struct dc_context *ctx, bool enable)
980 /* TODO: add periodic detection implementation */