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 <acpi/video.h>
28 #include <linux/string.h>
29 #include <linux/acpi.h>
30 #include <linux/i2c.h>
32 #include <drm/drm_atomic.h>
33 #include <drm/drm_probe_helper.h>
34 #include <drm/amdgpu_drm.h>
35 #include <drm/drm_edid.h>
36 #include <drm/drm_fixed.h>
38 #include "dm_services.h"
41 #include "amdgpu_dm.h"
42 #include "amdgpu_dm_irq.h"
43 #include "amdgpu_dm_mst_types.h"
44 #include "dpcd_defs.h"
45 #include "dc/inc/core_types.h"
47 #include "dm_helpers.h"
48 #include "ddc_service_types.h"
51 static u32 edid_extract_panel_id(struct edid *edid)
53 return (u32)edid->mfg_id[0] << 24 |
54 (u32)edid->mfg_id[1] << 16 |
55 (u32)EDID_PRODUCT_ID(edid);
58 static void apply_edid_quirks(struct edid *edid, struct dc_edid_caps *edid_caps)
60 uint32_t panel_id = edid_extract_panel_id(edid);
63 /* Workaround for some monitors which does not work well with FAMS */
64 case drm_edid_encode_panel_id('S', 'A', 'M', 0x0E5E):
65 case drm_edid_encode_panel_id('S', 'A', 'M', 0x7053):
66 case drm_edid_encode_panel_id('S', 'A', 'M', 0x71AC):
67 DRM_DEBUG_DRIVER("Disabling FAMS on monitor with panel id %X\n", panel_id);
68 edid_caps->panel_patch.disable_fams = true;
70 /* Workaround for some monitors that do not clear DPCD 0x317 if FreeSync is unsupported */
71 case drm_edid_encode_panel_id('A', 'U', 'O', 0xA7AB):
72 case drm_edid_encode_panel_id('A', 'U', 'O', 0xE69B):
73 case drm_edid_encode_panel_id('B', 'O', 'E', 0x092A):
74 case drm_edid_encode_panel_id('L', 'G', 'D', 0x06D1):
75 case drm_edid_encode_panel_id('M', 'S', 'F', 0x1003):
76 DRM_DEBUG_DRIVER("Clearing DPCD 0x317 on monitor with panel id %X\n", panel_id);
77 edid_caps->panel_patch.remove_sink_ext_caps = true;
79 case drm_edid_encode_panel_id('S', 'D', 'C', 0x4154):
80 DRM_DEBUG_DRIVER("Disabling VSC on monitor with panel id %X\n", panel_id);
81 edid_caps->panel_patch.disable_colorimetry = true;
89 * dm_helpers_parse_edid_caps() - Parse edid caps
91 * @link: current detected link
92 * @edid: [in] pointer to edid
93 * @edid_caps: [in] pointer to edid caps
97 enum dc_edid_status dm_helpers_parse_edid_caps(
99 const struct dc_edid *edid,
100 struct dc_edid_caps *edid_caps)
102 struct amdgpu_dm_connector *aconnector = link->priv;
103 struct drm_connector *connector = &aconnector->base;
104 struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid : NULL;
105 struct cea_sad *sads;
109 uint8_t *sadb = NULL;
111 enum dc_edid_status result = EDID_OK;
113 if (!edid_caps || !edid)
114 return EDID_BAD_INPUT;
116 if (!drm_edid_is_valid(edid_buf))
117 result = EDID_BAD_CHECKSUM;
119 edid_caps->manufacturer_id = (uint16_t) edid_buf->mfg_id[0] |
120 ((uint16_t) edid_buf->mfg_id[1])<<8;
121 edid_caps->product_id = (uint16_t) edid_buf->prod_code[0] |
122 ((uint16_t) edid_buf->prod_code[1])<<8;
123 edid_caps->serial_number = edid_buf->serial;
124 edid_caps->manufacture_week = edid_buf->mfg_week;
125 edid_caps->manufacture_year = edid_buf->mfg_year;
127 drm_edid_get_monitor_name(edid_buf,
128 edid_caps->display_name,
129 AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS);
131 edid_caps->edid_hdmi = connector->display_info.is_hdmi;
133 apply_edid_quirks(edid_buf, edid_caps);
135 sad_count = drm_edid_to_sad((struct edid *) edid->raw_edid, &sads);
139 edid_caps->audio_mode_count = min(sad_count, DC_MAX_AUDIO_DESC_COUNT);
140 for (i = 0; i < edid_caps->audio_mode_count; ++i) {
141 struct cea_sad *sad = &sads[i];
143 edid_caps->audio_modes[i].format_code = sad->format;
144 edid_caps->audio_modes[i].channel_count = sad->channels + 1;
145 edid_caps->audio_modes[i].sample_rate = sad->freq;
146 edid_caps->audio_modes[i].sample_size = sad->byte2;
149 sadb_count = drm_edid_to_speaker_allocation((struct edid *) edid->raw_edid, &sadb);
151 if (sadb_count < 0) {
152 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sadb_count);
157 edid_caps->speaker_flags = sadb[0];
159 edid_caps->speaker_flags = DEFAULT_SPEAKER_LOCATION;
168 fill_dc_mst_payload_table_from_drm(struct dc_link *link,
170 struct drm_dp_mst_atomic_payload *target_payload,
171 struct dc_dp_mst_stream_allocation_table *table)
173 struct dc_dp_mst_stream_allocation_table new_table = { 0 };
174 struct dc_dp_mst_stream_allocation *sa;
175 struct link_mst_stream_allocation_table copy_of_link_table =
176 link->mst_stream_alloc_table;
179 int current_hw_table_stream_cnt = copy_of_link_table.stream_count;
180 struct link_mst_stream_allocation *dc_alloc;
182 /* TODO: refactor to set link->mst_stream_alloc_table directly if possible.*/
185 ©_of_link_table.stream_allocations[current_hw_table_stream_cnt];
186 dc_alloc->vcp_id = target_payload->vcpi;
187 dc_alloc->slot_count = target_payload->time_slots;
189 for (i = 0; i < copy_of_link_table.stream_count; i++) {
191 ©_of_link_table.stream_allocations[i];
193 if (dc_alloc->vcp_id == target_payload->vcpi) {
194 dc_alloc->vcp_id = 0;
195 dc_alloc->slot_count = 0;
199 ASSERT(i != copy_of_link_table.stream_count);
202 /* Fill payload info*/
203 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
205 ©_of_link_table.stream_allocations[i];
206 if (dc_alloc->vcp_id > 0 && dc_alloc->slot_count > 0) {
207 sa = &new_table.stream_allocations[new_table.stream_count];
208 sa->slot_count = dc_alloc->slot_count;
209 sa->vcp_id = dc_alloc->vcp_id;
210 new_table.stream_count++;
214 /* Overwrite the old table */
218 void dm_helpers_dp_update_branch_info(
219 struct dc_context *ctx,
220 const struct dc_link *link)
223 static void dm_helpers_construct_old_payload(
224 struct drm_dp_mst_topology_mgr *mgr,
225 struct drm_dp_mst_topology_state *mst_state,
226 struct drm_dp_mst_atomic_payload *new_payload,
227 struct drm_dp_mst_atomic_payload *old_payload)
229 struct drm_dp_mst_atomic_payload *pos;
230 int pbn_per_slot = dfixed_trunc(mst_state->pbn_div);
231 u8 next_payload_vc_start = mgr->next_start_slot;
232 u8 payload_vc_start = new_payload->vc_start_slot;
233 u8 allocated_time_slots;
235 *old_payload = *new_payload;
237 /* Set correct time_slots/PBN of old payload.
238 * other fields (delete & dsc_enabled) in
239 * struct drm_dp_mst_atomic_payload are don't care fields
240 * while calling drm_dp_remove_payload_part2()
242 list_for_each_entry(pos, &mst_state->payloads, next) {
243 if (pos != new_payload &&
244 pos->vc_start_slot > payload_vc_start &&
245 pos->vc_start_slot < next_payload_vc_start)
246 next_payload_vc_start = pos->vc_start_slot;
249 allocated_time_slots = next_payload_vc_start - payload_vc_start;
251 old_payload->time_slots = allocated_time_slots;
252 old_payload->pbn = allocated_time_slots * pbn_per_slot;
256 * Writes payload allocation table in immediate downstream device.
258 bool dm_helpers_dp_mst_write_payload_allocation_table(
259 struct dc_context *ctx,
260 const struct dc_stream_state *stream,
261 struct dc_dp_mst_stream_allocation_table *proposed_table,
264 struct amdgpu_dm_connector *aconnector;
265 struct drm_dp_mst_topology_state *mst_state;
266 struct drm_dp_mst_atomic_payload *target_payload, *new_payload, old_payload;
267 struct drm_dp_mst_topology_mgr *mst_mgr;
269 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
270 /* Accessing the connector state is required for vcpi_slots allocation
271 * and directly relies on behaviour in commit check
272 * that blocks before commit guaranteeing that the state
273 * is not gonna be swapped while still in use in commit tail
276 if (!aconnector || !aconnector->mst_root)
279 mst_mgr = &aconnector->mst_root->mst_mgr;
280 mst_state = to_drm_dp_mst_topology_state(mst_mgr->base.state);
281 new_payload = drm_atomic_get_mst_payload_state(mst_state, aconnector->mst_output_port);
284 target_payload = new_payload;
286 /* It's OK for this to fail */
287 drm_dp_add_payload_part1(mst_mgr, mst_state, new_payload);
289 /* construct old payload by VCPI*/
290 dm_helpers_construct_old_payload(mst_mgr, mst_state,
291 new_payload, &old_payload);
292 target_payload = &old_payload;
294 drm_dp_remove_payload_part1(mst_mgr, mst_state, new_payload);
297 /* mst_mgr->->payloads are VC payload notify MST branch using DPCD or
298 * AUX message. The sequence is slot 1-63 allocated sequence for each
299 * stream. AMD ASIC stream slot allocation should follow the same
300 * sequence. copy DRM MST allocation to dc
302 fill_dc_mst_payload_table_from_drm(stream->link, enable, target_payload, proposed_table);
308 * poll pending down reply
310 void dm_helpers_dp_mst_poll_pending_down_reply(
311 struct dc_context *ctx,
312 const struct dc_link *link)
316 * Clear payload allocation table before enable MST DP link.
318 void dm_helpers_dp_mst_clear_payload_allocation_table(
319 struct dc_context *ctx,
320 const struct dc_link *link)
324 * Polls for ACT (allocation change trigger) handled and sends
325 * ALLOCATE_PAYLOAD message.
327 enum act_return_status dm_helpers_dp_mst_poll_for_allocation_change_trigger(
328 struct dc_context *ctx,
329 const struct dc_stream_state *stream)
331 struct amdgpu_dm_connector *aconnector;
332 struct drm_dp_mst_topology_mgr *mst_mgr;
335 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
337 if (!aconnector || !aconnector->mst_root)
340 mst_mgr = &aconnector->mst_root->mst_mgr;
342 if (!mst_mgr->mst_state)
345 ret = drm_dp_check_act_status(mst_mgr);
353 void dm_helpers_dp_mst_send_payload_allocation(
354 struct dc_context *ctx,
355 const struct dc_stream_state *stream)
357 struct amdgpu_dm_connector *aconnector;
358 struct drm_dp_mst_topology_state *mst_state;
359 struct drm_dp_mst_topology_mgr *mst_mgr;
360 struct drm_dp_mst_atomic_payload *new_payload;
361 enum mst_progress_status set_flag = MST_ALLOCATE_NEW_PAYLOAD;
362 enum mst_progress_status clr_flag = MST_CLEAR_ALLOCATED_PAYLOAD;
365 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
367 if (!aconnector || !aconnector->mst_root)
370 mst_mgr = &aconnector->mst_root->mst_mgr;
371 mst_state = to_drm_dp_mst_topology_state(mst_mgr->base.state);
372 new_payload = drm_atomic_get_mst_payload_state(mst_state, aconnector->mst_output_port);
374 ret = drm_dp_add_payload_part2(mst_mgr, new_payload);
377 amdgpu_dm_set_mst_status(&aconnector->mst_status,
380 amdgpu_dm_set_mst_status(&aconnector->mst_status,
382 amdgpu_dm_set_mst_status(&aconnector->mst_status,
387 void dm_helpers_dp_mst_update_mst_mgr_for_deallocation(
388 struct dc_context *ctx,
389 const struct dc_stream_state *stream)
391 struct amdgpu_dm_connector *aconnector;
392 struct drm_dp_mst_topology_state *mst_state;
393 struct drm_dp_mst_topology_mgr *mst_mgr;
394 struct drm_dp_mst_atomic_payload *new_payload, old_payload;
395 enum mst_progress_status set_flag = MST_CLEAR_ALLOCATED_PAYLOAD;
396 enum mst_progress_status clr_flag = MST_ALLOCATE_NEW_PAYLOAD;
398 aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
400 if (!aconnector || !aconnector->mst_root)
403 mst_mgr = &aconnector->mst_root->mst_mgr;
404 mst_state = to_drm_dp_mst_topology_state(mst_mgr->base.state);
405 new_payload = drm_atomic_get_mst_payload_state(mst_state, aconnector->mst_output_port);
406 dm_helpers_construct_old_payload(mst_mgr, mst_state,
407 new_payload, &old_payload);
409 drm_dp_remove_payload_part2(mst_mgr, mst_state, &old_payload, new_payload);
411 amdgpu_dm_set_mst_status(&aconnector->mst_status, set_flag, true);
412 amdgpu_dm_set_mst_status(&aconnector->mst_status, clr_flag, false);
415 void dm_dtn_log_begin(struct dc_context *ctx,
416 struct dc_log_buffer_ctx *log_ctx)
418 static const char msg[] = "[dtn begin]\n";
425 dm_dtn_log_append_v(ctx, log_ctx, "%s", msg);
429 void dm_dtn_log_append_v(struct dc_context *ctx,
430 struct dc_log_buffer_ctx *log_ctx,
431 const char *msg, ...)
438 /* No context, redirect to dmesg. */
439 struct va_format vaf;
445 pr_info("%pV", &vaf);
451 /* Measure the output. */
453 n = vsnprintf(NULL, 0, msg, args);
459 /* Reallocate the string buffer as needed. */
460 total = log_ctx->pos + n + 1;
462 if (total > log_ctx->size) {
463 char *buf = kvcalloc(total, sizeof(char), GFP_KERNEL);
466 memcpy(buf, log_ctx->buf, log_ctx->pos);
470 log_ctx->size = total;
477 /* Write the formatted string to the log buffer. */
480 log_ctx->buf + log_ctx->pos,
481 log_ctx->size - log_ctx->pos,
490 void dm_dtn_log_end(struct dc_context *ctx,
491 struct dc_log_buffer_ctx *log_ctx)
493 static const char msg[] = "[dtn end]\n";
500 dm_dtn_log_append_v(ctx, log_ctx, "%s", msg);
503 bool dm_helpers_dp_mst_start_top_mgr(
504 struct dc_context *ctx,
505 const struct dc_link *link,
508 struct amdgpu_dm_connector *aconnector = link->priv;
512 DRM_ERROR("Failed to find connector for link!");
517 DRM_INFO("DM_MST: Differing MST start on aconnector: %p [id: %d]\n",
518 aconnector, aconnector->base.base.id);
522 DRM_INFO("DM_MST: starting TM on aconnector: %p [id: %d]\n",
523 aconnector, aconnector->base.base.id);
525 ret = drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
527 DRM_ERROR("DM_MST: Failed to set the device into MST mode!");
531 DRM_INFO("DM_MST: DP%x, %d-lane link detected\n", aconnector->mst_mgr.dpcd[0],
532 aconnector->mst_mgr.dpcd[2] & DP_MAX_LANE_COUNT_MASK);
537 bool dm_helpers_dp_mst_stop_top_mgr(
538 struct dc_context *ctx,
539 struct dc_link *link)
541 struct amdgpu_dm_connector *aconnector = link->priv;
544 DRM_ERROR("Failed to find connector for link!");
548 DRM_INFO("DM_MST: stopping TM on aconnector: %p [id: %d]\n",
549 aconnector, aconnector->base.base.id);
551 if (aconnector->mst_mgr.mst_state == true) {
552 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, false);
553 link->cur_link_settings.lane_count = 0;
559 bool dm_helpers_dp_read_dpcd(
560 struct dc_context *ctx,
561 const struct dc_link *link,
567 struct amdgpu_dm_connector *aconnector = link->priv;
572 return drm_dp_dpcd_read(&aconnector->dm_dp_aux.aux, address, data,
576 bool dm_helpers_dp_write_dpcd(
577 struct dc_context *ctx,
578 const struct dc_link *link,
583 struct amdgpu_dm_connector *aconnector = link->priv;
588 return drm_dp_dpcd_write(&aconnector->dm_dp_aux.aux,
589 address, (uint8_t *)data, size) > 0;
592 bool dm_helpers_submit_i2c(
593 struct dc_context *ctx,
594 const struct dc_link *link,
595 struct i2c_command *cmd)
597 struct amdgpu_dm_connector *aconnector = link->priv;
598 struct i2c_msg *msgs;
600 int num = cmd->number_of_payloads;
604 DRM_ERROR("Failed to find connector for link!");
608 msgs = kcalloc(num, sizeof(struct i2c_msg), GFP_KERNEL);
613 for (i = 0; i < num; i++) {
614 msgs[i].flags = cmd->payloads[i].write ? 0 : I2C_M_RD;
615 msgs[i].addr = cmd->payloads[i].address;
616 msgs[i].len = cmd->payloads[i].length;
617 msgs[i].buf = cmd->payloads[i].data;
620 result = i2c_transfer(&aconnector->i2c->base, msgs, num) == num;
627 static bool execute_synaptics_rc_command(struct drm_dp_aux *aux,
634 bool success = false;
635 unsigned char rc_data[16] = {0};
636 unsigned char rc_offset[4] = {0};
637 unsigned char rc_length[2] = {0};
638 unsigned char rc_cmd = 0;
639 unsigned char rc_result = 0xFF;
645 memmove(rc_data, data, length);
646 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_DATA, rc_data, sizeof(rc_data));
652 rc_offset[0] = (unsigned char) offset & 0xFF;
653 rc_offset[1] = (unsigned char) (offset >> 8) & 0xFF;
654 rc_offset[2] = (unsigned char) (offset >> 16) & 0xFF;
655 rc_offset[3] = (unsigned char) (offset >> 24) & 0xFF;
656 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_OFFSET, rc_offset, sizeof(rc_offset));
661 rc_length[0] = (unsigned char) length & 0xFF;
662 rc_length[1] = (unsigned char) (length >> 8) & 0xFF;
663 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_LENGTH, rc_length, sizeof(rc_length));
669 ret = drm_dp_dpcd_write(aux, SYNAPTICS_RC_COMMAND, &rc_cmd, sizeof(rc_cmd));
673 // poll until active is 0
674 for (i = 0; i < 10; i++) {
675 drm_dp_dpcd_read(aux, SYNAPTICS_RC_COMMAND, &rc_cmd, sizeof(rc_cmd));
683 drm_dp_dpcd_read(aux, SYNAPTICS_RC_RESULT, &rc_result, sizeof(rc_result));
684 success = (rc_result == 0);
686 if (success && !is_write_cmd) {
688 drm_dp_dpcd_read(aux, SYNAPTICS_RC_DATA, data, length);
691 drm_dbg_dp(aux->drm_dev, "success = %d\n", success);
696 DRM_ERROR("%s: write cmd ..., err = %d\n", __func__, ret);
700 static void apply_synaptics_fifo_reset_wa(struct drm_dp_aux *aux)
702 unsigned char data[16] = {0};
704 drm_dbg_dp(aux->drm_dev, "Start\n");
713 if (!execute_synaptics_rc_command(aux, true, 0x01, 5, 0, data))
717 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220998, data))
720 data[0] &= (~(1 << 1)); // set bit 1 to 0
721 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x220998, data))
724 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220D98, data))
727 data[0] &= (~(1 << 1)); // set bit 1 to 0
728 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x220D98, data))
731 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x221198, data))
734 data[0] &= (~(1 << 1)); // set bit 1 to 0
735 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x221198, data))
739 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220998, data))
742 data[0] |= (1 << 1); // set bit 1 to 1
743 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x220998, data))
746 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x220D98, data))
749 data[0] |= (1 << 1); // set bit 1 to 1
751 if (!execute_synaptics_rc_command(aux, false, 0x31, 4, 0x221198, data))
754 data[0] |= (1 << 1); // set bit 1 to 1
755 if (!execute_synaptics_rc_command(aux, true, 0x21, 4, 0x221198, data))
759 if (!execute_synaptics_rc_command(aux, true, 0x02, 0, 0, NULL))
762 drm_dbg_dp(aux->drm_dev, "Done\n");
766 static const uint8_t SYNAPTICS_DEVICE_ID[] = "SYNA";
768 static uint8_t write_dsc_enable_synaptics_non_virtual_dpcd_mst(
769 struct drm_dp_aux *aux,
770 const struct dc_stream_state *stream,
775 drm_dbg_dp(aux->drm_dev,
776 "MST_DSC Configure DSC to non-virtual dpcd synaptics\n");
779 /* When DSC is enabled on previous boot and reboot with the hub,
780 * there is a chance that Synaptics hub gets stuck during reboot sequence.
781 * Applying a workaround to reset Synaptics SDP fifo before enabling the first stream
783 if (!stream->link->link_status.link_active &&
784 memcmp(stream->link->dpcd_caps.branch_dev_name,
785 (int8_t *)SYNAPTICS_DEVICE_ID, 4) == 0)
786 apply_synaptics_fifo_reset_wa(aux);
788 ret = drm_dp_dpcd_write(aux, DP_DSC_ENABLE, &enable, 1);
789 DRM_INFO("MST_DSC Send DSC enable to synaptics\n");
792 /* Synaptics hub not support virtual dpcd,
793 * external monitor occur garbage while disable DSC,
794 * Disable DSC only when entire link status turn to false,
796 if (!stream->link->link_status.link_active) {
797 ret = drm_dp_dpcd_write(aux, DP_DSC_ENABLE, &enable, 1);
798 DRM_INFO("MST_DSC Send DSC disable to synaptics\n");
805 bool dm_helpers_dp_write_dsc_enable(
806 struct dc_context *ctx,
807 const struct dc_stream_state *stream,
810 static const uint8_t DSC_DISABLE;
811 static const uint8_t DSC_DECODING = 0x01;
812 static const uint8_t DSC_PASSTHROUGH = 0x02;
814 struct amdgpu_dm_connector *aconnector =
815 (struct amdgpu_dm_connector *)stream->dm_stream_context;
816 struct drm_device *dev = aconnector->base.dev;
817 struct drm_dp_mst_port *port;
818 uint8_t enable_dsc = enable ? DSC_DECODING : DSC_DISABLE;
819 uint8_t enable_passthrough = enable ? DSC_PASSTHROUGH : DSC_DISABLE;
822 if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
823 if (!aconnector->dsc_aux)
826 // apply w/a to synaptics
827 if (needs_dsc_aux_workaround(aconnector->dc_link) &&
828 (aconnector->mst_downstream_port_present.byte & 0x7) != 0x3)
829 return write_dsc_enable_synaptics_non_virtual_dpcd_mst(
830 aconnector->dsc_aux, stream, enable_dsc);
832 port = aconnector->mst_output_port;
835 if (port->passthrough_aux) {
836 ret = drm_dp_dpcd_write(port->passthrough_aux,
838 &enable_passthrough, 1);
840 "MST_DSC Sent DSC pass-through enable to virtual dpcd port, ret = %u\n",
844 ret = drm_dp_dpcd_write(aconnector->dsc_aux,
845 DP_DSC_ENABLE, &enable_dsc, 1);
847 "MST_DSC Sent DSC decoding enable to %s port, ret = %u\n",
848 (port->passthrough_aux) ? "remote RX" :
852 ret = drm_dp_dpcd_write(aconnector->dsc_aux,
853 DP_DSC_ENABLE, &enable_dsc, 1);
855 "MST_DSC Sent DSC decoding disable to %s port, ret = %u\n",
856 (port->passthrough_aux) ? "remote RX" :
860 if (port->passthrough_aux) {
861 ret = drm_dp_dpcd_write(port->passthrough_aux,
863 &enable_passthrough, 1);
865 "MST_DSC Sent DSC pass-through disable to virtual dpcd port, ret = %u\n",
871 if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT || stream->signal == SIGNAL_TYPE_EDP) {
872 if (stream->sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_NONE) {
873 ret = dm_helpers_dp_write_dpcd(ctx, stream->link, DP_DSC_ENABLE, &enable_dsc, 1);
875 "SST_DSC Send DSC %s to SST RX\n",
876 enable_dsc ? "enable" : "disable");
877 } else if (stream->sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER) {
878 ret = dm_helpers_dp_write_dpcd(ctx, stream->link, DP_DSC_ENABLE, &enable_dsc, 1);
880 "SST_DSC Send DSC %s to DP-HDMI PCON\n",
881 enable_dsc ? "enable" : "disable");
888 bool dm_helpers_dp_write_hblank_reduction(struct dc_context *ctx, const struct dc_stream_state *stream)
894 bool dm_helpers_is_dp_sink_present(struct dc_link *link)
896 bool dp_sink_present;
897 struct amdgpu_dm_connector *aconnector = link->priv;
900 BUG_ON("Failed to find connector for link!");
904 mutex_lock(&aconnector->dm_dp_aux.aux.hw_mutex);
905 dp_sink_present = dc_link_is_dp_sink_present(link);
906 mutex_unlock(&aconnector->dm_dp_aux.aux.hw_mutex);
907 return dp_sink_present;
911 dm_helpers_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len)
913 struct drm_connector *connector = data;
914 struct acpi_device *acpidev = ACPI_COMPANION(connector->dev->dev);
915 unsigned char start = block * EDID_LENGTH;
922 /* fetch the entire edid from BIOS */
923 r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, (void *)&edid);
925 drm_dbg(connector->dev, "Failed to get EDID from ACPI: %d\n", r);
928 if (len > r || start > r || start + len > r) {
934 if (edid->revision < 4 || !(edid->input & DRM_EDID_INPUT_DIGITAL) ||
935 (edid->input & DRM_EDID_DIGITAL_TYPE_MASK) == DRM_EDID_DIGITAL_TYPE_UNDEF) {
940 memcpy(buf, (void *)edid + start, len);
949 static const struct drm_edid *
950 dm_helpers_read_acpi_edid(struct amdgpu_dm_connector *aconnector)
952 struct drm_connector *connector = &aconnector->base;
954 if (amdgpu_dc_debug_mask & DC_DISABLE_ACPI_EDID)
957 switch (connector->connector_type) {
958 case DRM_MODE_CONNECTOR_LVDS:
959 case DRM_MODE_CONNECTOR_eDP:
965 if (connector->force == DRM_FORCE_OFF)
968 return drm_edid_read_custom(connector, dm_helpers_probe_acpi_edid, connector);
971 enum dc_edid_status dm_helpers_read_local_edid(
972 struct dc_context *ctx,
973 struct dc_link *link,
974 struct dc_sink *sink)
976 struct amdgpu_dm_connector *aconnector = link->priv;
977 struct drm_connector *connector = &aconnector->base;
978 struct i2c_adapter *ddc;
980 enum dc_edid_status edid_status;
981 const struct drm_edid *drm_edid;
982 const struct edid *edid;
985 ddc = &aconnector->dm_dp_aux.aux.ddc;
987 ddc = &aconnector->i2c->base;
989 /* some dongles read edid incorrectly the first time,
990 * do check sum and retry to make sure read correct edid.
993 drm_edid = dm_helpers_read_acpi_edid(aconnector);
995 drm_info(connector->dev, "Using ACPI provided EDID for %s\n", connector->name);
997 drm_edid = drm_edid_read_ddc(connector, ddc);
998 drm_edid_connector_update(connector, drm_edid);
1000 /* DP Compliance Test 4.2.2.6 */
1001 if (link->aux_mode && connector->edid_corrupt)
1002 drm_dp_send_real_edid_checksum(&aconnector->dm_dp_aux.aux, connector->real_edid_checksum);
1004 if (!drm_edid && connector->edid_corrupt) {
1005 connector->edid_corrupt = false;
1006 return EDID_BAD_CHECKSUM;
1010 return EDID_NO_RESPONSE;
1012 edid = drm_edid_raw(drm_edid); // FIXME: Get rid of drm_edid_raw()
1013 sink->dc_edid.length = EDID_LENGTH * (edid->extensions + 1);
1014 memmove(sink->dc_edid.raw_edid, (uint8_t *)edid, sink->dc_edid.length);
1016 /* We don't need the original edid anymore */
1017 drm_edid_free(drm_edid);
1019 edid_status = dm_helpers_parse_edid_caps(
1024 } while (edid_status == EDID_BAD_CHECKSUM && --retry > 0);
1026 if (edid_status != EDID_OK)
1027 DRM_ERROR("EDID err: %d, on connector: %s",
1029 aconnector->base.name);
1030 if (link->aux_mode) {
1031 union test_request test_request = {0};
1032 union test_response test_response = {0};
1034 dm_helpers_dp_read_dpcd(ctx,
1038 sizeof(union test_request));
1040 if (!test_request.bits.EDID_READ)
1043 test_response.bits.EDID_CHECKSUM_WRITE = 1;
1045 dm_helpers_dp_write_dpcd(ctx,
1047 DP_TEST_EDID_CHECKSUM,
1048 &sink->dc_edid.raw_edid[sink->dc_edid.length-1],
1051 dm_helpers_dp_write_dpcd(ctx,
1055 sizeof(test_response));
1061 int dm_helper_dmub_aux_transfer_sync(
1062 struct dc_context *ctx,
1063 const struct dc_link *link,
1064 struct aux_payload *payload,
1065 enum aux_return_code_type *operation_result)
1067 if (!link->hpd_status) {
1068 *operation_result = AUX_RET_ERROR_HPD_DISCON;
1072 return amdgpu_dm_process_dmub_aux_transfer_sync(ctx, link->link_index, payload,
1076 int dm_helpers_dmub_set_config_sync(struct dc_context *ctx,
1077 const struct dc_link *link,
1078 struct set_config_cmd_payload *payload,
1079 enum set_config_status *operation_result)
1081 return amdgpu_dm_process_dmub_set_config_sync(ctx, link->link_index, payload,
1085 void dm_set_dcn_clocks(struct dc_context *ctx, struct dc_clocks *clks)
1087 /* TODO: something */
1090 void dm_helpers_smu_timeout(struct dc_context *ctx, unsigned int msg_id, unsigned int param, unsigned int timeout_us)
1093 //amdgpu_device_gpu_recover(dc_context->driver-context, NULL);
1096 void dm_helpers_init_panel_settings(
1097 struct dc_context *ctx,
1098 struct dc_panel_config *panel_config,
1099 struct dc_sink *sink)
1101 // Extra Panel Power Sequence
1102 panel_config->pps.extra_t3_ms = sink->edid_caps.panel_patch.extra_t3_ms;
1103 panel_config->pps.extra_t7_ms = sink->edid_caps.panel_patch.extra_t7_ms;
1104 panel_config->pps.extra_delay_backlight_off = sink->edid_caps.panel_patch.extra_delay_backlight_off;
1105 panel_config->pps.extra_post_t7_ms = 0;
1106 panel_config->pps.extra_pre_t11_ms = 0;
1107 panel_config->pps.extra_t12_ms = sink->edid_caps.panel_patch.extra_t12_ms;
1108 panel_config->pps.extra_post_OUI_ms = 0;
1110 panel_config->dsc.disable_dsc_edp = false;
1111 panel_config->dsc.force_dsc_edp_policy = 0;
1114 void dm_helpers_override_panel_settings(
1115 struct dc_context *ctx,
1116 struct dc_panel_config *panel_config)
1119 if (amdgpu_dc_debug_mask & DC_DISABLE_DSC)
1120 panel_config->dsc.disable_dsc_edp = true;
1123 void *dm_helpers_allocate_gpu_mem(
1124 struct dc_context *ctx,
1125 enum dc_gpu_mem_alloc_type type,
1129 struct amdgpu_device *adev = ctx->driver_context;
1131 return dm_allocate_gpu_mem(adev, type, size, addr);
1134 void dm_helpers_free_gpu_mem(
1135 struct dc_context *ctx,
1136 enum dc_gpu_mem_alloc_type type,
1139 struct amdgpu_device *adev = ctx->driver_context;
1141 dm_free_gpu_mem(adev, type, pvMem);
1144 bool dm_helpers_dmub_outbox_interrupt_control(struct dc_context *ctx, bool enable)
1146 enum dc_irq_source irq_source;
1149 irq_source = DC_IRQ_SOURCE_DMCUB_OUTBOX;
1151 ret = dc_interrupt_set(ctx->dc, irq_source, enable);
1153 DRM_DEBUG_DRIVER("Dmub trace irq %sabling: r=%d\n",
1154 enable ? "en" : "dis", ret);
1158 void dm_helpers_mst_enable_stream_features(const struct dc_stream_state *stream)
1160 /* TODO: virtual DPCD */
1161 struct dc_link *link = stream->link;
1162 union down_spread_ctrl old_downspread;
1163 union down_spread_ctrl new_downspread;
1165 if (link->aux_access_disabled)
1168 if (!dm_helpers_dp_read_dpcd(link->ctx, link, DP_DOWNSPREAD_CTRL,
1169 &old_downspread.raw,
1170 sizeof(old_downspread)))
1173 new_downspread.raw = old_downspread.raw;
1174 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1175 (stream->ignore_msa_timing_param) ? 1 : 0;
1177 if (new_downspread.raw != old_downspread.raw)
1178 dm_helpers_dp_write_dpcd(link->ctx, link, DP_DOWNSPREAD_CTRL,
1179 &new_downspread.raw,
1180 sizeof(new_downspread));
1183 bool dm_helpers_dp_handle_test_pattern_request(
1184 struct dc_context *ctx,
1185 const struct dc_link *link,
1186 union link_test_pattern dpcd_test_pattern,
1187 union test_misc dpcd_test_params)
1189 enum dp_test_pattern test_pattern;
1190 enum dp_test_pattern_color_space test_pattern_color_space =
1191 DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED;
1192 enum dc_color_depth requestColorDepth = COLOR_DEPTH_UNDEFINED;
1193 enum dc_pixel_encoding requestPixelEncoding = PIXEL_ENCODING_UNDEFINED;
1194 struct pipe_ctx *pipes = link->dc->current_state->res_ctx.pipe_ctx;
1195 struct pipe_ctx *pipe_ctx = NULL;
1196 struct amdgpu_dm_connector *aconnector = link->priv;
1197 struct drm_device *dev = aconnector->base.dev;
1198 struct dc_state *dc_state = ctx->dc->current_state;
1199 struct clk_mgr *clk_mgr = ctx->dc->clk_mgr;
1202 for (i = 0; i < MAX_PIPES; i++) {
1203 if (pipes[i].stream == NULL)
1206 if (pipes[i].stream->link == link && !pipes[i].top_pipe &&
1207 !pipes[i].prev_odm_pipe) {
1208 pipe_ctx = &pipes[i];
1213 if (pipe_ctx == NULL)
1216 switch (dpcd_test_pattern.bits.PATTERN) {
1217 case LINK_TEST_PATTERN_COLOR_RAMP:
1218 test_pattern = DP_TEST_PATTERN_COLOR_RAMP;
1220 case LINK_TEST_PATTERN_VERTICAL_BARS:
1221 test_pattern = DP_TEST_PATTERN_VERTICAL_BARS;
1222 break; /* black and white */
1223 case LINK_TEST_PATTERN_COLOR_SQUARES:
1224 test_pattern = (dpcd_test_params.bits.DYN_RANGE ==
1225 TEST_DYN_RANGE_VESA ?
1226 DP_TEST_PATTERN_COLOR_SQUARES :
1227 DP_TEST_PATTERN_COLOR_SQUARES_CEA);
1230 test_pattern = DP_TEST_PATTERN_VIDEO_MODE;
1234 if (dpcd_test_params.bits.CLR_FORMAT == 0)
1235 test_pattern_color_space = DP_TEST_PATTERN_COLOR_SPACE_RGB;
1237 test_pattern_color_space = dpcd_test_params.bits.YCBCR_COEFS ?
1238 DP_TEST_PATTERN_COLOR_SPACE_YCBCR709 :
1239 DP_TEST_PATTERN_COLOR_SPACE_YCBCR601;
1241 switch (dpcd_test_params.bits.BPC) {
1243 requestColorDepth = COLOR_DEPTH_666;
1246 requestColorDepth = COLOR_DEPTH_888;
1249 requestColorDepth = COLOR_DEPTH_101010;
1252 requestColorDepth = COLOR_DEPTH_121212;
1258 switch (dpcd_test_params.bits.CLR_FORMAT) {
1260 requestPixelEncoding = PIXEL_ENCODING_RGB;
1263 requestPixelEncoding = PIXEL_ENCODING_YCBCR422;
1266 requestPixelEncoding = PIXEL_ENCODING_YCBCR444;
1269 requestPixelEncoding = PIXEL_ENCODING_RGB;
1273 if ((requestColorDepth != COLOR_DEPTH_UNDEFINED
1274 && pipe_ctx->stream->timing.display_color_depth != requestColorDepth)
1275 || (requestPixelEncoding != PIXEL_ENCODING_UNDEFINED
1276 && pipe_ctx->stream->timing.pixel_encoding != requestPixelEncoding)) {
1278 "original bpc %d pix encoding %d, changing to %d %d\n",
1279 pipe_ctx->stream->timing.display_color_depth,
1280 pipe_ctx->stream->timing.pixel_encoding,
1282 requestPixelEncoding);
1283 pipe_ctx->stream->timing.display_color_depth = requestColorDepth;
1284 pipe_ctx->stream->timing.pixel_encoding = requestPixelEncoding;
1286 dc_link_update_dsc_config(pipe_ctx);
1288 aconnector->timing_changed = true;
1289 /* store current timing */
1290 if (aconnector->timing_requested)
1291 *aconnector->timing_requested = pipe_ctx->stream->timing;
1293 drm_err(dev, "timing storage failed\n");
1297 pipe_ctx->stream->test_pattern.type = test_pattern;
1298 pipe_ctx->stream->test_pattern.color_space = test_pattern_color_space;
1300 /* Temp W/A for compliance test failure */
1301 dc_state->bw_ctx.bw.dcn.clk.p_state_change_support = false;
1302 dc_state->bw_ctx.bw.dcn.clk.dramclk_khz = clk_mgr->dc_mode_softmax_enabled ?
1303 clk_mgr->bw_params->dc_mode_softmax_memclk : clk_mgr->bw_params->max_memclk_mhz;
1304 dc_state->bw_ctx.bw.dcn.clk.idle_dramclk_khz = dc_state->bw_ctx.bw.dcn.clk.dramclk_khz;
1305 ctx->dc->clk_mgr->funcs->update_clocks(
1310 dc_link_dp_set_test_pattern(
1311 (struct dc_link *) link,
1313 test_pattern_color_space,
1321 void dm_set_phyd32clk(struct dc_context *ctx, int freq_khz)
1326 void dm_helpers_enable_periodic_detection(struct dc_context *ctx, bool enable)
1328 struct amdgpu_device *adev = ctx->driver_context;
1330 if (adev->dm.idle_workqueue) {
1331 adev->dm.idle_workqueue->enable = enable;
1332 if (enable && !adev->dm.idle_workqueue->running && amdgpu_dm_is_headless(adev))
1333 schedule_work(&adev->dm.idle_workqueue->work);
1337 void dm_helpers_dp_mst_update_branch_bandwidth(
1338 struct dc_context *ctx,
1339 struct dc_link *link)
1344 static bool dm_is_freesync_pcon_whitelist(const uint32_t branch_dev_id)
1346 bool ret_val = false;
1348 switch (branch_dev_id) {
1349 case DP_BRANCH_DEVICE_ID_0060AD:
1350 case DP_BRANCH_DEVICE_ID_00E04C:
1351 case DP_BRANCH_DEVICE_ID_90CC24:
1361 enum adaptive_sync_type dm_get_adaptive_sync_support_type(struct dc_link *link)
1363 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
1364 enum adaptive_sync_type as_type = ADAPTIVE_SYNC_TYPE_NONE;
1366 switch (dpcd_caps->dongle_type) {
1367 case DISPLAY_DONGLE_DP_HDMI_CONVERTER:
1368 if (dpcd_caps->adaptive_sync_caps.dp_adap_sync_caps.bits.ADAPTIVE_SYNC_SDP_SUPPORT == true &&
1369 dpcd_caps->allow_invalid_MSA_timing_param == true &&
1370 dm_is_freesync_pcon_whitelist(dpcd_caps->branch_dev_id))
1371 as_type = FREESYNC_TYPE_PCON_IN_WHITELIST;
1380 bool dm_helpers_is_fullscreen(struct dc_context *ctx, struct dc_stream_state *stream)
1386 bool dm_helpers_is_hdr_on(struct dc_context *ctx, struct dc_stream_state *stream)