2 * Copyright 2012-15 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 "dc_bios_types.h"
27 #include "dce_stream_encoder.h"
28 #include "reg_helper.h"
29 #include "hw_shared.h"
32 enc110->base.ctx->logger
39 #define FN(reg_name, field_name) \
40 enc110->se_shift->field_name, enc110->se_mask->field_name
43 #define DP_BLANK_MAX_RETRY 20
44 #define HDMI_CLOCK_CHANNEL_RATE_MORE_340M 340000
46 #ifndef TMDS_CNTL__TMDS_PIXEL_ENCODING_MASK
47 #define TMDS_CNTL__TMDS_PIXEL_ENCODING_MASK 0x00000010L
48 #define TMDS_CNTL__TMDS_COLOR_FORMAT_MASK 0x00000300L
49 #define TMDS_CNTL__TMDS_PIXEL_ENCODING__SHIFT 0x00000004
50 #define TMDS_CNTL__TMDS_COLOR_FORMAT__SHIFT 0x00000008
54 DP_MST_UPDATE_MAX_RETRY
= 50
57 #define DCE110_SE(audio)\
58 container_of(audio, struct dce110_stream_encoder, base)
63 static void dce110_update_generic_info_packet(
64 struct dce110_stream_encoder
*enc110
,
65 uint32_t packet_index
,
66 const struct dc_info_packet
*info_packet
)
69 /* TODOFPGA Figure out a proper number for max_retries polling for lock
72 uint32_t max_retries
= 50;
74 /*we need turn on clock before programming AFMT block*/
76 REG_UPDATE(AFMT_CNTL
, AFMT_AUDIO_CLOCK_EN
, 1);
78 if (REG(AFMT_VBI_PACKET_CONTROL1
)) {
79 if (packet_index
>= 8)
82 /* poll dig_update_lock is not locked -> asic internal signal
83 * assume otg master lock will unlock it
85 /* REG_WAIT(AFMT_VBI_PACKET_CONTROL, AFMT_GENERIC_LOCK_STATUS,
86 0, 10, max_retries);*/
88 /* check if HW reading GSP memory */
89 REG_WAIT(AFMT_VBI_PACKET_CONTROL
, AFMT_GENERIC_CONFLICT
,
92 /* HW does is not reading GSP memory not reading too long ->
93 * something wrong. clear GPS memory access and notify?
94 * hw SW is writing to GSP memory
96 REG_UPDATE(AFMT_VBI_PACKET_CONTROL
, AFMT_GENERIC_CONFLICT_CLR
, 1);
98 /* choose which generic packet to use */
100 regval
= REG_READ(AFMT_VBI_PACKET_CONTROL
);
101 REG_UPDATE(AFMT_VBI_PACKET_CONTROL
,
102 AFMT_GENERIC_INDEX
, packet_index
);
105 /* write generic packet header
106 * (4th byte is for GENERIC0 only) */
108 REG_SET_4(AFMT_GENERIC_HDR
, 0,
109 AFMT_GENERIC_HB0
, info_packet
->hb0
,
110 AFMT_GENERIC_HB1
, info_packet
->hb1
,
111 AFMT_GENERIC_HB2
, info_packet
->hb2
,
112 AFMT_GENERIC_HB3
, info_packet
->hb3
);
115 /* write generic packet contents
116 * (we never use last 4 bytes)
117 * there are 8 (0-7) mmDIG0_AFMT_GENERIC0_x registers */
119 const uint32_t *content
=
120 (const uint32_t *) &info_packet
->sb
[0];
122 REG_WRITE(AFMT_GENERIC_0
, *content
++);
123 REG_WRITE(AFMT_GENERIC_1
, *content
++);
124 REG_WRITE(AFMT_GENERIC_2
, *content
++);
125 REG_WRITE(AFMT_GENERIC_3
, *content
++);
126 REG_WRITE(AFMT_GENERIC_4
, *content
++);
127 REG_WRITE(AFMT_GENERIC_5
, *content
++);
128 REG_WRITE(AFMT_GENERIC_6
, *content
++);
129 REG_WRITE(AFMT_GENERIC_7
, *content
);
132 if (!REG(AFMT_VBI_PACKET_CONTROL1
)) {
133 /* force double-buffered packet update */
134 REG_UPDATE_2(AFMT_VBI_PACKET_CONTROL
,
135 AFMT_GENERIC0_UPDATE
, (packet_index
== 0),
136 AFMT_GENERIC2_UPDATE
, (packet_index
== 2));
138 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
139 if (REG(AFMT_VBI_PACKET_CONTROL1
)) {
140 switch (packet_index
) {
142 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
143 AFMT_GENERIC0_FRAME_UPDATE
, 1);
146 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
147 AFMT_GENERIC1_FRAME_UPDATE
, 1);
150 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
151 AFMT_GENERIC2_FRAME_UPDATE
, 1);
154 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
155 AFMT_GENERIC3_FRAME_UPDATE
, 1);
158 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
159 AFMT_GENERIC4_FRAME_UPDATE
, 1);
162 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
163 AFMT_GENERIC5_FRAME_UPDATE
, 1);
166 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
167 AFMT_GENERIC6_FRAME_UPDATE
, 1);
170 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1
,
171 AFMT_GENERIC7_FRAME_UPDATE
, 1);
180 static void dce110_update_hdmi_info_packet(
181 struct dce110_stream_encoder
*enc110
,
182 uint32_t packet_index
,
183 const struct dc_info_packet
*info_packet
)
185 uint32_t cont
, send
, line
;
187 if (info_packet
->valid
) {
188 dce110_update_generic_info_packet(
193 /* enable transmission of packet(s) -
194 * packet transmission begins on the next frame */
196 /* send packet(s) every frame */
198 /* select line number to send packets on */
206 /* choose which generic packet control to use */
207 switch (packet_index
) {
209 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL0
,
210 HDMI_GENERIC0_CONT
, cont
,
211 HDMI_GENERIC0_SEND
, send
,
212 HDMI_GENERIC0_LINE
, line
);
215 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL0
,
216 HDMI_GENERIC1_CONT
, cont
,
217 HDMI_GENERIC1_SEND
, send
,
218 HDMI_GENERIC1_LINE
, line
);
221 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL1
,
222 HDMI_GENERIC0_CONT
, cont
,
223 HDMI_GENERIC0_SEND
, send
,
224 HDMI_GENERIC0_LINE
, line
);
227 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL1
,
228 HDMI_GENERIC1_CONT
, cont
,
229 HDMI_GENERIC1_SEND
, send
,
230 HDMI_GENERIC1_LINE
, line
);
232 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
234 if (REG(HDMI_GENERIC_PACKET_CONTROL2
))
235 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL2
,
236 HDMI_GENERIC0_CONT
, cont
,
237 HDMI_GENERIC0_SEND
, send
,
238 HDMI_GENERIC0_LINE
, line
);
241 if (REG(HDMI_GENERIC_PACKET_CONTROL2
))
242 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL2
,
243 HDMI_GENERIC1_CONT
, cont
,
244 HDMI_GENERIC1_SEND
, send
,
245 HDMI_GENERIC1_LINE
, line
);
248 if (REG(HDMI_GENERIC_PACKET_CONTROL3
))
249 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL3
,
250 HDMI_GENERIC0_CONT
, cont
,
251 HDMI_GENERIC0_SEND
, send
,
252 HDMI_GENERIC0_LINE
, line
);
255 if (REG(HDMI_GENERIC_PACKET_CONTROL3
))
256 REG_UPDATE_3(HDMI_GENERIC_PACKET_CONTROL3
,
257 HDMI_GENERIC1_CONT
, cont
,
258 HDMI_GENERIC1_SEND
, send
,
259 HDMI_GENERIC1_LINE
, line
);
263 /* invalid HW packet index */
265 "Invalid HW packet index: %s()\n",
271 /* setup stream encoder in dp mode */
272 static void dce110_stream_encoder_dp_set_stream_attribute(
273 struct stream_encoder
*enc
,
274 struct dc_crtc_timing
*crtc_timing
,
275 enum dc_color_space output_color_space
)
277 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
278 uint32_t h_active_start
;
279 uint32_t v_active_start
;
283 uint32_t h_back_porch
;
284 uint8_t synchronous_clock
= 0; /* asynchronous mode */
285 uint8_t colorimetry_bpc
;
286 uint8_t dynamic_range_rgb
= 0; /*full range*/
287 uint8_t dynamic_range_ycbcr
= 1; /*bt709*/
290 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
292 /* set pixel encoding */
293 switch (crtc_timing
->pixel_encoding
) {
294 case PIXEL_ENCODING_YCBCR422
:
295 REG_UPDATE(DP_PIXEL_FORMAT
, DP_PIXEL_ENCODING
,
296 DP_PIXEL_ENCODING_TYPE_YCBCR422
);
298 case PIXEL_ENCODING_YCBCR444
:
299 REG_UPDATE(DP_PIXEL_FORMAT
, DP_PIXEL_ENCODING
,
300 DP_PIXEL_ENCODING_TYPE_YCBCR444
);
302 if (crtc_timing
->flags
.Y_ONLY
)
303 if (crtc_timing
->display_color_depth
!= COLOR_DEPTH_666
)
304 /* HW testing only, no use case yet.
305 * Color depth of Y-only could be
306 * 8, 10, 12, 16 bits */
307 REG_UPDATE(DP_PIXEL_FORMAT
, DP_PIXEL_ENCODING
,
308 DP_PIXEL_ENCODING_TYPE_Y_ONLY
);
309 /* Note: DP_MSA_MISC1 bit 7 is the indicator
311 * This bit is set in HW if register
312 * DP_PIXEL_ENCODING is programmed to 0x4 */
314 case PIXEL_ENCODING_YCBCR420
:
315 REG_UPDATE(DP_PIXEL_FORMAT
, DP_PIXEL_ENCODING
,
316 DP_PIXEL_ENCODING_TYPE_YCBCR420
);
317 if (enc110
->se_mask
->DP_VID_M_DOUBLE_VALUE_EN
)
318 REG_UPDATE(DP_VID_TIMING
, DP_VID_M_DOUBLE_VALUE_EN
, 1);
320 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
321 if (enc110
->se_mask
->DP_VID_N_MUL
)
322 REG_UPDATE(DP_VID_TIMING
, DP_VID_N_MUL
, 1);
326 REG_UPDATE(DP_PIXEL_FORMAT
, DP_PIXEL_ENCODING
,
327 DP_PIXEL_ENCODING_TYPE_RGB444
);
331 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
332 if (REG(DP_MSA_MISC
))
333 misc1
= REG_READ(DP_MSA_MISC
);
336 /* set color depth */
338 switch (crtc_timing
->display_color_depth
) {
339 case COLOR_DEPTH_666
:
340 REG_UPDATE(DP_PIXEL_FORMAT
, DP_COMPONENT_DEPTH
,
343 case COLOR_DEPTH_888
:
344 REG_UPDATE(DP_PIXEL_FORMAT
, DP_COMPONENT_DEPTH
,
345 DP_COMPONENT_PIXEL_DEPTH_8BPC
);
347 case COLOR_DEPTH_101010
:
348 REG_UPDATE(DP_PIXEL_FORMAT
, DP_COMPONENT_DEPTH
,
349 DP_COMPONENT_PIXEL_DEPTH_10BPC
);
352 case COLOR_DEPTH_121212
:
353 REG_UPDATE(DP_PIXEL_FORMAT
, DP_COMPONENT_DEPTH
,
354 DP_COMPONENT_PIXEL_DEPTH_12BPC
);
357 REG_UPDATE(DP_PIXEL_FORMAT
, DP_COMPONENT_DEPTH
,
358 DP_COMPONENT_PIXEL_DEPTH_6BPC
);
362 /* set dynamic range and YCbCr range */
365 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
366 switch (crtc_timing
->display_color_depth
) {
367 case COLOR_DEPTH_666
:
370 case COLOR_DEPTH_888
:
373 case COLOR_DEPTH_101010
:
376 case COLOR_DEPTH_121212
:
384 misc0
= misc0
| synchronous_clock
;
385 misc0
= colorimetry_bpc
<< 5;
387 if (REG(DP_MSA_TIMING_PARAM1
)) {
388 switch (output_color_space
) {
389 case COLOR_SPACE_SRGB
:
391 misc1
= misc1
& ~0x80; /* bit7 = 0*/
392 dynamic_range_rgb
= 0; /*full range*/
394 case COLOR_SPACE_SRGB_LIMITED
:
395 misc0
= misc0
| 0x8; /* bit3=1 */
396 misc1
= misc1
& ~0x80; /* bit7 = 0*/
397 dynamic_range_rgb
= 1; /*limited range*/
399 case COLOR_SPACE_YCBCR601
:
400 case COLOR_SPACE_YCBCR601_LIMITED
:
401 misc0
= misc0
| 0x8; /* bit3=1, bit4=0 */
402 misc1
= misc1
& ~0x80; /* bit7 = 0*/
403 dynamic_range_ycbcr
= 0; /*bt601*/
404 if (crtc_timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
)
405 misc0
= misc0
| 0x2; /* bit2=0, bit1=1 */
406 else if (crtc_timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR444
)
407 misc0
= misc0
| 0x4; /* bit2=1, bit1=0 */
409 case COLOR_SPACE_YCBCR709
:
410 case COLOR_SPACE_YCBCR709_LIMITED
:
411 misc0
= misc0
| 0x18; /* bit3=1, bit4=1 */
412 misc1
= misc1
& ~0x80; /* bit7 = 0*/
413 dynamic_range_ycbcr
= 1; /*bt709*/
414 if (crtc_timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
)
415 misc0
= misc0
| 0x2; /* bit2=0, bit1=1 */
416 else if (crtc_timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR444
)
417 misc0
= misc0
| 0x4; /* bit2=1, bit1=0 */
419 case COLOR_SPACE_2020_RGB_LIMITEDRANGE
:
420 dynamic_range_rgb
= 1; /*limited range*/
422 case COLOR_SPACE_2020_RGB_FULLRANGE
:
423 case COLOR_SPACE_2020_YCBCR
:
424 case COLOR_SPACE_XR_RGB
:
425 case COLOR_SPACE_MSREF_SCRGB
:
426 case COLOR_SPACE_ADOBERGB
:
427 case COLOR_SPACE_DCIP3
:
428 case COLOR_SPACE_XV_YCC_709
:
429 case COLOR_SPACE_XV_YCC_601
:
430 case COLOR_SPACE_DISPLAYNATIVE
:
431 case COLOR_SPACE_DOLBYVISION
:
432 case COLOR_SPACE_APPCTRL
:
433 case COLOR_SPACE_CUSTOMPOINTS
:
434 case COLOR_SPACE_UNKNOWN
:
438 if (enc110
->se_mask
->DP_DYN_RANGE
&& enc110
->se_mask
->DP_YCBCR_RANGE
)
441 DP_DYN_RANGE
, dynamic_range_rgb
,
442 DP_YCBCR_RANGE
, dynamic_range_ycbcr
);
444 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
445 if (REG(DP_MSA_COLORIMETRY
))
446 REG_SET(DP_MSA_COLORIMETRY
, 0, DP_MSA_MISC0
, misc0
);
448 if (REG(DP_MSA_MISC
))
449 REG_WRITE(DP_MSA_MISC
, misc1
); /* MSA_MISC1 */
452 * dc_crtc_timing is vesa dmt struct. data from edid
454 if (REG(DP_MSA_TIMING_PARAM1
))
455 REG_SET_2(DP_MSA_TIMING_PARAM1
, 0,
456 DP_MSA_HTOTAL
, crtc_timing
->h_total
,
457 DP_MSA_VTOTAL
, crtc_timing
->v_total
);
460 /* calcuate from vesa timing parameters
461 * h_active_start related to leading edge of sync
464 h_blank
= crtc_timing
->h_total
- crtc_timing
->h_border_left
-
465 crtc_timing
->h_addressable
- crtc_timing
->h_border_right
;
467 h_back_porch
= h_blank
- crtc_timing
->h_front_porch
-
468 crtc_timing
->h_sync_width
;
470 /* start at begining of left border */
471 h_active_start
= crtc_timing
->h_sync_width
+ h_back_porch
;
474 v_active_start
= crtc_timing
->v_total
- crtc_timing
->v_border_top
-
475 crtc_timing
->v_addressable
- crtc_timing
->v_border_bottom
-
476 crtc_timing
->v_front_porch
;
479 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
480 /* start at begining of left border */
481 if (REG(DP_MSA_TIMING_PARAM2
))
482 REG_SET_2(DP_MSA_TIMING_PARAM2
, 0,
483 DP_MSA_HSTART
, h_active_start
,
484 DP_MSA_VSTART
, v_active_start
);
486 if (REG(DP_MSA_TIMING_PARAM3
))
487 REG_SET_4(DP_MSA_TIMING_PARAM3
, 0,
489 crtc_timing
->h_sync_width
,
490 DP_MSA_HSYNCPOLARITY
,
491 !crtc_timing
->flags
.HSYNC_POSITIVE_POLARITY
,
493 crtc_timing
->v_sync_width
,
494 DP_MSA_VSYNCPOLARITY
,
495 !crtc_timing
->flags
.VSYNC_POSITIVE_POLARITY
);
497 /* HWDITH include border or overscan */
498 if (REG(DP_MSA_TIMING_PARAM4
))
499 REG_SET_2(DP_MSA_TIMING_PARAM4
, 0,
500 DP_MSA_HWIDTH
, crtc_timing
->h_border_left
+
501 crtc_timing
->h_addressable
+ crtc_timing
->h_border_right
,
502 DP_MSA_VHEIGHT
, crtc_timing
->v_border_top
+
503 crtc_timing
->v_addressable
+ crtc_timing
->v_border_bottom
);
509 static void dce110_stream_encoder_set_stream_attribute_helper(
510 struct dce110_stream_encoder
*enc110
,
511 struct dc_crtc_timing
*crtc_timing
)
513 if (enc110
->regs
->TMDS_CNTL
) {
514 switch (crtc_timing
->pixel_encoding
) {
515 case PIXEL_ENCODING_YCBCR422
:
516 REG_UPDATE(TMDS_CNTL
, TMDS_PIXEL_ENCODING
, 1);
519 REG_UPDATE(TMDS_CNTL
, TMDS_PIXEL_ENCODING
, 0);
522 REG_UPDATE(TMDS_CNTL
, TMDS_COLOR_FORMAT
, 0);
523 } else if (enc110
->regs
->DIG_FE_CNTL
) {
524 switch (crtc_timing
->pixel_encoding
) {
525 case PIXEL_ENCODING_YCBCR422
:
526 REG_UPDATE(DIG_FE_CNTL
, TMDS_PIXEL_ENCODING
, 1);
529 REG_UPDATE(DIG_FE_CNTL
, TMDS_PIXEL_ENCODING
, 0);
532 REG_UPDATE(DIG_FE_CNTL
, TMDS_COLOR_FORMAT
, 0);
537 /* setup stream encoder in hdmi mode */
538 static void dce110_stream_encoder_hdmi_set_stream_attribute(
539 struct stream_encoder
*enc
,
540 struct dc_crtc_timing
*crtc_timing
,
541 int actual_pix_clk_khz
,
544 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
545 struct bp_encoder_control cntl
= {0};
547 cntl
.action
= ENCODER_CONTROL_SETUP
;
548 cntl
.engine_id
= enc110
->base
.id
;
549 cntl
.signal
= SIGNAL_TYPE_HDMI_TYPE_A
;
550 cntl
.enable_dp_audio
= enable_audio
;
551 cntl
.pixel_clock
= actual_pix_clk_khz
;
552 cntl
.lanes_number
= LANE_COUNT_FOUR
;
554 if (enc110
->base
.bp
->funcs
->encoder_control(
555 enc110
->base
.bp
, &cntl
) != BP_RESULT_OK
)
558 dce110_stream_encoder_set_stream_attribute_helper(enc110
, crtc_timing
);
560 /* setup HDMI engine */
561 if (!enc110
->se_mask
->HDMI_DATA_SCRAMBLE_EN
) {
562 REG_UPDATE_3(HDMI_CONTROL
,
563 HDMI_PACKET_GEN_VERSION
, 1,
564 HDMI_KEEPOUT_MODE
, 1,
565 HDMI_DEEP_COLOR_ENABLE
, 0);
566 } else if (enc110
->regs
->DIG_FE_CNTL
) {
567 REG_UPDATE_5(HDMI_CONTROL
,
568 HDMI_PACKET_GEN_VERSION
, 1,
569 HDMI_KEEPOUT_MODE
, 1,
570 HDMI_DEEP_COLOR_ENABLE
, 0,
571 HDMI_DATA_SCRAMBLE_EN
, 0,
572 HDMI_CLOCK_CHANNEL_RATE
, 0);
575 switch (crtc_timing
->display_color_depth
) {
576 case COLOR_DEPTH_888
:
577 REG_UPDATE(HDMI_CONTROL
, HDMI_DEEP_COLOR_DEPTH
, 0);
579 case COLOR_DEPTH_101010
:
580 if (crtc_timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
) {
581 REG_UPDATE_2(HDMI_CONTROL
,
582 HDMI_DEEP_COLOR_DEPTH
, 1,
583 HDMI_DEEP_COLOR_ENABLE
, 0);
585 REG_UPDATE_2(HDMI_CONTROL
,
586 HDMI_DEEP_COLOR_DEPTH
, 1,
587 HDMI_DEEP_COLOR_ENABLE
, 1);
590 case COLOR_DEPTH_121212
:
591 if (crtc_timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
) {
592 REG_UPDATE_2(HDMI_CONTROL
,
593 HDMI_DEEP_COLOR_DEPTH
, 2,
594 HDMI_DEEP_COLOR_ENABLE
, 0);
596 REG_UPDATE_2(HDMI_CONTROL
,
597 HDMI_DEEP_COLOR_DEPTH
, 2,
598 HDMI_DEEP_COLOR_ENABLE
, 1);
601 case COLOR_DEPTH_161616
:
602 REG_UPDATE_2(HDMI_CONTROL
,
603 HDMI_DEEP_COLOR_DEPTH
, 3,
604 HDMI_DEEP_COLOR_ENABLE
, 1);
610 if (enc110
->se_mask
->HDMI_DATA_SCRAMBLE_EN
) {
611 if (actual_pix_clk_khz
>= HDMI_CLOCK_CHANNEL_RATE_MORE_340M
) {
612 /* enable HDMI data scrambler
613 * HDMI_CLOCK_CHANNEL_RATE_MORE_340M
614 * Clock channel frequency is 1/4 of character rate.
616 REG_UPDATE_2(HDMI_CONTROL
,
617 HDMI_DATA_SCRAMBLE_EN
, 1,
618 HDMI_CLOCK_CHANNEL_RATE
, 1);
619 } else if (crtc_timing
->flags
.LTE_340MCSC_SCRAMBLE
) {
621 /* TODO: New feature for DCE11, still need to implement */
623 /* enable HDMI data scrambler
624 * HDMI_CLOCK_CHANNEL_FREQ_EQUAL_TO_CHAR_RATE
625 * Clock channel frequency is the same
628 REG_UPDATE_2(HDMI_CONTROL
,
629 HDMI_DATA_SCRAMBLE_EN
, 1,
630 HDMI_CLOCK_CHANNEL_RATE
, 0);
634 REG_UPDATE_3(HDMI_VBI_PACKET_CONTROL
,
639 /* following belongs to audio */
640 REG_UPDATE(HDMI_INFOFRAME_CONTROL0
, HDMI_AUDIO_INFO_SEND
, 1);
642 REG_UPDATE(AFMT_INFOFRAME_CONTROL0
, AFMT_AUDIO_INFO_UPDATE
, 1);
644 REG_UPDATE(HDMI_INFOFRAME_CONTROL1
, HDMI_AUDIO_INFO_LINE
,
647 REG_UPDATE(HDMI_GC
, HDMI_GC_AVMUTE
, 0);
651 /* setup stream encoder in dvi mode */
652 static void dce110_stream_encoder_dvi_set_stream_attribute(
653 struct stream_encoder
*enc
,
654 struct dc_crtc_timing
*crtc_timing
,
657 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
658 struct bp_encoder_control cntl
= {0};
660 cntl
.action
= ENCODER_CONTROL_SETUP
;
661 cntl
.engine_id
= enc110
->base
.id
;
662 cntl
.signal
= is_dual_link
?
663 SIGNAL_TYPE_DVI_DUAL_LINK
: SIGNAL_TYPE_DVI_SINGLE_LINK
;
664 cntl
.enable_dp_audio
= false;
665 cntl
.pixel_clock
= crtc_timing
->pix_clk_khz
;
666 cntl
.lanes_number
= (is_dual_link
) ? LANE_COUNT_EIGHT
: LANE_COUNT_FOUR
;
668 if (enc110
->base
.bp
->funcs
->encoder_control(
669 enc110
->base
.bp
, &cntl
) != BP_RESULT_OK
)
672 ASSERT(crtc_timing
->pixel_encoding
== PIXEL_ENCODING_RGB
);
673 ASSERT(crtc_timing
->display_color_depth
== COLOR_DEPTH_888
);
674 dce110_stream_encoder_set_stream_attribute_helper(enc110
, crtc_timing
);
677 static void dce110_stream_encoder_set_mst_bandwidth(
678 struct stream_encoder
*enc
,
679 struct fixed31_32 avg_time_slots_per_mtp
)
681 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
682 uint32_t x
= dc_fixpt_floor(
683 avg_time_slots_per_mtp
);
684 uint32_t y
= dc_fixpt_ceil(
687 avg_time_slots_per_mtp
,
692 REG_SET_2(DP_MSE_RATE_CNTL
, 0,
697 /* wait for update to be completed on the link */
698 /* i.e. DP_MSE_RATE_UPDATE_PENDING field (read only) */
699 /* is reset to 0 (not pending) */
700 REG_WAIT(DP_MSE_RATE_UPDATE
, DP_MSE_RATE_UPDATE_PENDING
,
702 10, DP_MST_UPDATE_MAX_RETRY
);
705 static void dce110_stream_encoder_update_hdmi_info_packets(
706 struct stream_encoder
*enc
,
707 const struct encoder_info_frame
*info_frame
)
709 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
711 if (enc110
->se_mask
->HDMI_AVI_INFO_CONT
&&
712 enc110
->se_mask
->HDMI_AVI_INFO_SEND
) {
714 if (info_frame
->avi
.valid
) {
715 const uint32_t *content
=
716 (const uint32_t *) &info_frame
->avi
.sb
[0];
717 /*we need turn on clock before programming AFMT block*/
719 REG_UPDATE(AFMT_CNTL
, AFMT_AUDIO_CLOCK_EN
, 1);
721 REG_WRITE(AFMT_AVI_INFO0
, content
[0]);
723 REG_WRITE(AFMT_AVI_INFO1
, content
[1]);
725 REG_WRITE(AFMT_AVI_INFO2
, content
[2]);
727 REG_WRITE(AFMT_AVI_INFO3
, content
[3]);
729 REG_UPDATE(AFMT_AVI_INFO3
, AFMT_AVI_INFO_VERSION
,
730 info_frame
->avi
.hb1
);
732 REG_UPDATE_2(HDMI_INFOFRAME_CONTROL0
,
733 HDMI_AVI_INFO_SEND
, 1,
734 HDMI_AVI_INFO_CONT
, 1);
736 REG_UPDATE(HDMI_INFOFRAME_CONTROL1
, HDMI_AVI_INFO_LINE
,
740 REG_UPDATE_2(HDMI_INFOFRAME_CONTROL0
,
741 HDMI_AVI_INFO_SEND
, 0,
742 HDMI_AVI_INFO_CONT
, 0);
746 if (enc110
->se_mask
->HDMI_AVI_INFO_CONT
&&
747 enc110
->se_mask
->HDMI_AVI_INFO_SEND
) {
748 dce110_update_hdmi_info_packet(enc110
, 0, &info_frame
->vendor
);
749 dce110_update_hdmi_info_packet(enc110
, 1, &info_frame
->gamut
);
750 dce110_update_hdmi_info_packet(enc110
, 2, &info_frame
->spd
);
751 dce110_update_hdmi_info_packet(enc110
, 3, &info_frame
->hdrsmd
);
754 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
755 if (enc110
->se_mask
->HDMI_DB_DISABLE
) {
756 /* for bring up, disable dp double TODO */
757 if (REG(HDMI_DB_CONTROL
))
758 REG_UPDATE(HDMI_DB_CONTROL
, HDMI_DB_DISABLE
, 1);
760 dce110_update_hdmi_info_packet(enc110
, 0, &info_frame
->avi
);
761 dce110_update_hdmi_info_packet(enc110
, 1, &info_frame
->vendor
);
762 dce110_update_hdmi_info_packet(enc110
, 2, &info_frame
->gamut
);
763 dce110_update_hdmi_info_packet(enc110
, 3, &info_frame
->spd
);
764 dce110_update_hdmi_info_packet(enc110
, 4, &info_frame
->hdrsmd
);
769 static void dce110_stream_encoder_stop_hdmi_info_packets(
770 struct stream_encoder
*enc
)
772 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
774 /* stop generic packets 0 & 1 on HDMI */
775 REG_SET_6(HDMI_GENERIC_PACKET_CONTROL0
, 0,
776 HDMI_GENERIC1_CONT
, 0,
777 HDMI_GENERIC1_LINE
, 0,
778 HDMI_GENERIC1_SEND
, 0,
779 HDMI_GENERIC0_CONT
, 0,
780 HDMI_GENERIC0_LINE
, 0,
781 HDMI_GENERIC0_SEND
, 0);
783 /* stop generic packets 2 & 3 on HDMI */
784 REG_SET_6(HDMI_GENERIC_PACKET_CONTROL1
, 0,
785 HDMI_GENERIC0_CONT
, 0,
786 HDMI_GENERIC0_LINE
, 0,
787 HDMI_GENERIC0_SEND
, 0,
788 HDMI_GENERIC1_CONT
, 0,
789 HDMI_GENERIC1_LINE
, 0,
790 HDMI_GENERIC1_SEND
, 0);
792 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
793 /* stop generic packets 2 & 3 on HDMI */
794 if (REG(HDMI_GENERIC_PACKET_CONTROL2
))
795 REG_SET_6(HDMI_GENERIC_PACKET_CONTROL2
, 0,
796 HDMI_GENERIC0_CONT
, 0,
797 HDMI_GENERIC0_LINE
, 0,
798 HDMI_GENERIC0_SEND
, 0,
799 HDMI_GENERIC1_CONT
, 0,
800 HDMI_GENERIC1_LINE
, 0,
801 HDMI_GENERIC1_SEND
, 0);
803 if (REG(HDMI_GENERIC_PACKET_CONTROL3
))
804 REG_SET_6(HDMI_GENERIC_PACKET_CONTROL3
, 0,
805 HDMI_GENERIC0_CONT
, 0,
806 HDMI_GENERIC0_LINE
, 0,
807 HDMI_GENERIC0_SEND
, 0,
808 HDMI_GENERIC1_CONT
, 0,
809 HDMI_GENERIC1_LINE
, 0,
810 HDMI_GENERIC1_SEND
, 0);
814 static void dce110_stream_encoder_update_dp_info_packets(
815 struct stream_encoder
*enc
,
816 const struct encoder_info_frame
*info_frame
)
818 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
821 if (info_frame
->vsc
.valid
)
822 dce110_update_generic_info_packet(
827 if (info_frame
->spd
.valid
)
828 dce110_update_generic_info_packet(
833 if (info_frame
->hdrsmd
.valid
)
834 dce110_update_generic_info_packet(
837 &info_frame
->hdrsmd
);
839 /* enable/disable transmission of packet(s).
840 * If enabled, packet transmission begins on the next frame
842 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_GSP0_ENABLE
, info_frame
->vsc
.valid
);
843 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_GSP2_ENABLE
, info_frame
->spd
.valid
);
844 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_GSP3_ENABLE
, info_frame
->hdrsmd
.valid
);
846 /* This bit is the master enable bit.
847 * When enabling secondary stream engine,
848 * this master bit must also be set.
849 * This register shared with audio info frame.
850 * Therefore we need to enable master bit
851 * if at least on of the fields is not 0
853 value
= REG_READ(DP_SEC_CNTL
);
855 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_STREAM_ENABLE
, 1);
858 static void dce110_stream_encoder_stop_dp_info_packets(
859 struct stream_encoder
*enc
)
861 /* stop generic packets on DP */
862 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
865 if (enc110
->se_mask
->DP_SEC_AVI_ENABLE
) {
866 REG_SET_7(DP_SEC_CNTL
, 0,
867 DP_SEC_GSP0_ENABLE
, 0,
868 DP_SEC_GSP1_ENABLE
, 0,
869 DP_SEC_GSP2_ENABLE
, 0,
870 DP_SEC_GSP3_ENABLE
, 0,
871 DP_SEC_AVI_ENABLE
, 0,
872 DP_SEC_MPG_ENABLE
, 0,
873 DP_SEC_STREAM_ENABLE
, 0);
876 /* this register shared with audio info frame.
877 * therefore we need to keep master enabled
878 * if at least one of the fields is not 0 */
879 value
= REG_READ(DP_SEC_CNTL
);
881 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_STREAM_ENABLE
, 1);
885 static void dce110_stream_encoder_dp_blank(
886 struct stream_encoder
*enc
)
888 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
889 uint32_t retries
= 0;
891 uint32_t max_retries
= DP_BLANK_MAX_RETRY
* 10;
893 /* Note: For CZ, we are changing driver default to disable
894 * stream deferred to next VBLANK. If results are positive, we
895 * will make the same change to all DCE versions. There are a
896 * handful of panels that cannot handle disable stream at
897 * HBLANK and will result in a white line flash across the
898 * screen on stream disable. */
899 REG_GET(DP_VID_STREAM_CNTL
, DP_VID_STREAM_ENABLE
, ®1
);
900 if ((reg1
& 0x1) == 0)
901 /*stream not enabled*/
903 /* Specify the video stream disable point
904 * (2 = start of the next vertical blank) */
905 REG_UPDATE(DP_VID_STREAM_CNTL
, DP_VID_STREAM_DIS_DEFER
, 2);
906 /* Larger delay to wait until VBLANK - use max retry of
907 * 10us*3000=30ms. This covers 16.6ms of typical 60 Hz mode +
908 * a little more because we may not trust delay accuracy.
910 max_retries
= DP_BLANK_MAX_RETRY
* 150;
912 /* disable DP stream */
913 REG_UPDATE(DP_VID_STREAM_CNTL
, DP_VID_STREAM_ENABLE
, 0);
915 /* the encoder stops sending the video stream
916 * at the start of the vertical blanking.
917 * Poll for DP_VID_STREAM_STATUS == 0
920 REG_WAIT(DP_VID_STREAM_CNTL
, DP_VID_STREAM_STATUS
,
924 ASSERT(retries
<= max_retries
);
926 /* Tell the DP encoder to ignore timing from CRTC, must be done after
927 * the polling. If we set DP_STEER_FIFO_RESET before DP stream blank is
928 * complete, stream status will be stuck in video stream enabled state,
929 * i.e. DP_VID_STREAM_STATUS stuck at 1.
932 REG_UPDATE(DP_STEER_FIFO
, DP_STEER_FIFO_RESET
, true);
935 /* output video stream to link encoder */
936 static void dce110_stream_encoder_dp_unblank(
937 struct stream_encoder
*enc
,
938 const struct encoder_unblank_param
*param
)
940 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
942 if (param
->link_settings
.link_rate
!= LINK_RATE_UNKNOWN
) {
943 uint32_t n_vid
= 0x8000;
946 /* M / N = Fstream / Flink
947 * m_vid / n_vid = pixel rate / link rate
950 uint64_t m_vid_l
= n_vid
;
952 m_vid_l
*= param
->pixel_clk_khz
;
953 m_vid_l
= div_u64(m_vid_l
,
954 param
->link_settings
.link_rate
955 * LINK_RATE_REF_FREQ_IN_KHZ
);
957 m_vid
= (uint32_t) m_vid_l
;
959 /* enable auto measurement */
961 REG_UPDATE(DP_VID_TIMING
, DP_VID_M_N_GEN_EN
, 0);
963 /* auto measurement need 1 full 0x8000 symbol cycle to kick in,
964 * therefore program initial value for Mvid and Nvid
967 REG_UPDATE(DP_VID_N
, DP_VID_N
, n_vid
);
969 REG_UPDATE(DP_VID_M
, DP_VID_M
, m_vid
);
971 REG_UPDATE(DP_VID_TIMING
, DP_VID_M_N_GEN_EN
, 1);
974 /* set DIG_START to 0x1 to resync FIFO */
976 REG_UPDATE(DIG_FE_CNTL
, DIG_START
, 1);
978 /* switch DP encoder to CRTC data */
980 REG_UPDATE(DP_STEER_FIFO
, DP_STEER_FIFO_RESET
, 0);
982 /* wait 100us for DIG/DP logic to prime
983 * (i.e. a few video lines)
987 /* the hardware would start sending video at the start of the next DP
988 * frame (i.e. rising edge of the vblank).
989 * NOTE: We used to program DP_VID_STREAM_DIS_DEFER = 2 here, but this
990 * register has no effect on enable transition! HW always guarantees
991 * VID_STREAM enable at start of next frame, and this is not
995 REG_UPDATE(DP_VID_STREAM_CNTL
, DP_VID_STREAM_ENABLE
, true);
998 static void dce110_stream_encoder_set_avmute(
999 struct stream_encoder
*enc
,
1002 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1003 unsigned int value
= enable
? 1 : 0;
1005 REG_UPDATE(HDMI_GC
, HDMI_GC_AVMUTE
, value
);
1009 #define DP_SEC_AUD_N__DP_SEC_AUD_N__DEFAULT 0x8000
1010 #define DP_SEC_TIMESTAMP__DP_SEC_TIMESTAMP_MODE__AUTO_CALC 1
1012 #include "include/audio_types.h"
1015 * speakersToChannels
1018 * translate speakers to channels
1026 * FLC - Front Left Center
1027 * FRC - Front Right Center
1028 * RLC - Rear Left Center
1029 * RRC - Rear Right Center
1030 * LFE - Low Freq Effect
1044 * ch 8 7 6 5 4 3 2 1
1045 * 0b00000011 - - - - - - FR FL
1046 * 0b00000111 - - - - - LFE FR FL
1047 * 0b00001011 - - - - FC - FR FL
1048 * 0b00001111 - - - - FC LFE FR FL
1049 * 0b00010011 - - - RC - - FR FL
1050 * 0b00010111 - - - RC - LFE FR FL
1051 * 0b00011011 - - - RC FC - FR FL
1052 * 0b00011111 - - - RC FC LFE FR FL
1053 * 0b00110011 - - RR RL - - FR FL
1054 * 0b00110111 - - RR RL - LFE FR FL
1055 * 0b00111011 - - RR RL FC - FR FL
1056 * 0b00111111 - - RR RL FC LFE FR FL
1057 * 0b01110011 - RC RR RL - - FR FL
1058 * 0b01110111 - RC RR RL - LFE FR FL
1059 * 0b01111011 - RC RR RL FC - FR FL
1060 * 0b01111111 - RC RR RL FC LFE FR FL
1061 * 0b11110011 RRC RLC RR RL - - FR FL
1062 * 0b11110111 RRC RLC RR RL - LFE FR FL
1063 * 0b11111011 RRC RLC RR RL FC - FR FL
1064 * 0b11111111 RRC RLC RR RL FC LFE FR FL
1065 * 0b11000011 FRC FLC - - - - FR FL
1066 * 0b11000111 FRC FLC - - - LFE FR FL
1067 * 0b11001011 FRC FLC - - FC - FR FL
1068 * 0b11001111 FRC FLC - - FC LFE FR FL
1069 * 0b11010011 FRC FLC - RC - - FR FL
1070 * 0b11010111 FRC FLC - RC - LFE FR FL
1071 * 0b11011011 FRC FLC - RC FC - FR FL
1072 * 0b11011111 FRC FLC - RC FC LFE FR FL
1073 * 0b11110011 FRC FLC RR RL - - FR FL
1074 * 0b11110111 FRC FLC RR RL - LFE FR FL
1075 * 0b11111011 FRC FLC RR RL FC - FR FL
1076 * 0b11111111 FRC FLC RR RL FC LFE FR FL
1079 * speakers - speaker information as it comes from CEA audio block
1081 /* translate speakers to channels */
1083 union audio_cea_channels
{
1085 struct audio_cea_channels_bits
{
1092 uint32_t RC_RLC_FLC
:1;
1097 struct audio_clock_info
{
1098 /* pixel clock frequency*/
1099 uint32_t pixel_clock_in_10khz
;
1100 /* N - 32KHz audio */
1102 /* CTS - 32KHz audio*/
1123 static const struct audio_clock_info audio_clock_info_table
[16] = {
1124 {2517, 4576, 28125, 7007, 31250, 6864, 28125},
1125 {2518, 4576, 28125, 7007, 31250, 6864, 28125},
1126 {2520, 4096, 25200, 6272, 28000, 6144, 25200},
1127 {2700, 4096, 27000, 6272, 30000, 6144, 27000},
1128 {2702, 4096, 27027, 6272, 30030, 6144, 27027},
1129 {2703, 4096, 27027, 6272, 30030, 6144, 27027},
1130 {5400, 4096, 54000, 6272, 60000, 6144, 54000},
1131 {5405, 4096, 54054, 6272, 60060, 6144, 54054},
1132 {7417, 11648, 210937, 17836, 234375, 11648, 140625},
1133 {7425, 4096, 74250, 6272, 82500, 6144, 74250},
1134 {14835, 11648, 421875, 8918, 234375, 5824, 140625},
1135 {14850, 4096, 148500, 6272, 165000, 6144, 148500},
1136 {29670, 5824, 421875, 4459, 234375, 5824, 281250},
1137 {29700, 3072, 222750, 4704, 247500, 5120, 247500},
1138 {59340, 5824, 843750, 8918, 937500, 5824, 562500},
1139 {59400, 3072, 445500, 9408, 990000, 6144, 594000}
1142 static const struct audio_clock_info audio_clock_info_table_36bpc
[14] = {
1143 {2517, 9152, 84375, 7007, 48875, 9152, 56250},
1144 {2518, 9152, 84375, 7007, 48875, 9152, 56250},
1145 {2520, 4096, 37800, 6272, 42000, 6144, 37800},
1146 {2700, 4096, 40500, 6272, 45000, 6144, 40500},
1147 {2702, 8192, 81081, 6272, 45045, 8192, 54054},
1148 {2703, 8192, 81081, 6272, 45045, 8192, 54054},
1149 {5400, 4096, 81000, 6272, 90000, 6144, 81000},
1150 {5405, 4096, 81081, 6272, 90090, 6144, 81081},
1151 {7417, 11648, 316406, 17836, 351562, 11648, 210937},
1152 {7425, 4096, 111375, 6272, 123750, 6144, 111375},
1153 {14835, 11648, 632812, 17836, 703125, 11648, 421875},
1154 {14850, 4096, 222750, 6272, 247500, 6144, 222750},
1155 {29670, 5824, 632812, 8918, 703125, 5824, 421875},
1156 {29700, 4096, 445500, 4704, 371250, 5120, 371250}
1159 static const struct audio_clock_info audio_clock_info_table_48bpc
[14] = {
1160 {2517, 4576, 56250, 7007, 62500, 6864, 56250},
1161 {2518, 4576, 56250, 7007, 62500, 6864, 56250},
1162 {2520, 4096, 50400, 6272, 56000, 6144, 50400},
1163 {2700, 4096, 54000, 6272, 60000, 6144, 54000},
1164 {2702, 4096, 54054, 6267, 60060, 8192, 54054},
1165 {2703, 4096, 54054, 6272, 60060, 8192, 54054},
1166 {5400, 4096, 108000, 6272, 120000, 6144, 108000},
1167 {5405, 4096, 108108, 6272, 120120, 6144, 108108},
1168 {7417, 11648, 421875, 17836, 468750, 11648, 281250},
1169 {7425, 4096, 148500, 6272, 165000, 6144, 148500},
1170 {14835, 11648, 843750, 8918, 468750, 11648, 281250},
1171 {14850, 4096, 297000, 6272, 330000, 6144, 297000},
1172 {29670, 5824, 843750, 4459, 468750, 5824, 562500},
1173 {29700, 3072, 445500, 4704, 495000, 5120, 495000}
1178 static union audio_cea_channels
speakers_to_channels(
1179 struct audio_speaker_flags speaker_flags
)
1181 union audio_cea_channels cea_channels
= {0};
1183 /* these are one to one */
1184 cea_channels
.channels
.FL
= speaker_flags
.FL_FR
;
1185 cea_channels
.channels
.FR
= speaker_flags
.FL_FR
;
1186 cea_channels
.channels
.LFE
= speaker_flags
.LFE
;
1187 cea_channels
.channels
.FC
= speaker_flags
.FC
;
1189 /* if Rear Left and Right exist move RC speaker to channel 7
1190 * otherwise to channel 5
1192 if (speaker_flags
.RL_RR
) {
1193 cea_channels
.channels
.RL_RC
= speaker_flags
.RL_RR
;
1194 cea_channels
.channels
.RR
= speaker_flags
.RL_RR
;
1195 cea_channels
.channels
.RC_RLC_FLC
= speaker_flags
.RC
;
1197 cea_channels
.channels
.RL_RC
= speaker_flags
.RC
;
1200 /* FRONT Left Right Center and REAR Left Right Center are exclusive */
1201 if (speaker_flags
.FLC_FRC
) {
1202 cea_channels
.channels
.RC_RLC_FLC
= speaker_flags
.FLC_FRC
;
1203 cea_channels
.channels
.RRC_FRC
= speaker_flags
.FLC_FRC
;
1205 cea_channels
.channels
.RC_RLC_FLC
= speaker_flags
.RLC_RRC
;
1206 cea_channels
.channels
.RRC_FRC
= speaker_flags
.RLC_RRC
;
1209 return cea_channels
;
1212 static uint32_t calc_max_audio_packets_per_line(
1213 const struct audio_crtc_info
*crtc_info
)
1215 uint32_t max_packets_per_line
;
1217 max_packets_per_line
=
1218 crtc_info
->h_total
- crtc_info
->h_active
;
1220 if (crtc_info
->pixel_repetition
)
1221 max_packets_per_line
*= crtc_info
->pixel_repetition
;
1223 /* for other hdmi features */
1224 max_packets_per_line
-= 58;
1225 /* for Control Period */
1226 max_packets_per_line
-= 16;
1227 /* Number of Audio Packets per Line */
1228 max_packets_per_line
/= 32;
1230 return max_packets_per_line
;
1233 static void get_audio_clock_info(
1234 enum dc_color_depth color_depth
,
1235 uint32_t crtc_pixel_clock_in_khz
,
1236 uint32_t actual_pixel_clock_in_khz
,
1237 struct audio_clock_info
*audio_clock_info
)
1239 const struct audio_clock_info
*clock_info
;
1241 uint32_t crtc_pixel_clock_in_10khz
= crtc_pixel_clock_in_khz
/ 10;
1242 uint32_t audio_array_size
;
1244 switch (color_depth
) {
1245 case COLOR_DEPTH_161616
:
1246 clock_info
= audio_clock_info_table_48bpc
;
1247 audio_array_size
= ARRAY_SIZE(
1248 audio_clock_info_table_48bpc
);
1250 case COLOR_DEPTH_121212
:
1251 clock_info
= audio_clock_info_table_36bpc
;
1252 audio_array_size
= ARRAY_SIZE(
1253 audio_clock_info_table_36bpc
);
1256 clock_info
= audio_clock_info_table
;
1257 audio_array_size
= ARRAY_SIZE(
1258 audio_clock_info_table
);
1262 if (clock_info
!= NULL
) {
1263 /* search for exact pixel clock in table */
1264 for (index
= 0; index
< audio_array_size
; index
++) {
1265 if (clock_info
[index
].pixel_clock_in_10khz
>
1266 crtc_pixel_clock_in_10khz
)
1267 break; /* not match */
1268 else if (clock_info
[index
].pixel_clock_in_10khz
==
1269 crtc_pixel_clock_in_10khz
) {
1271 *audio_clock_info
= clock_info
[index
];
1278 if (actual_pixel_clock_in_khz
== 0)
1279 actual_pixel_clock_in_khz
= crtc_pixel_clock_in_khz
;
1281 /* See HDMI spec the table entry under
1282 * pixel clock of "Other". */
1283 audio_clock_info
->pixel_clock_in_10khz
=
1284 actual_pixel_clock_in_khz
/ 10;
1285 audio_clock_info
->cts_32khz
= actual_pixel_clock_in_khz
;
1286 audio_clock_info
->cts_44khz
= actual_pixel_clock_in_khz
;
1287 audio_clock_info
->cts_48khz
= actual_pixel_clock_in_khz
;
1289 audio_clock_info
->n_32khz
= 4096;
1290 audio_clock_info
->n_44khz
= 6272;
1291 audio_clock_info
->n_48khz
= 6144;
1294 static void dce110_se_audio_setup(
1295 struct stream_encoder
*enc
,
1296 unsigned int az_inst
,
1297 struct audio_info
*audio_info
)
1299 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1301 uint32_t speakers
= 0;
1302 uint32_t channels
= 0;
1305 if (audio_info
== NULL
)
1306 /* This should not happen.it does so we don't get BSOD*/
1309 speakers
= audio_info
->flags
.info
.ALLSPEAKERS
;
1310 channels
= speakers_to_channels(audio_info
->flags
.speaker_flags
).all
;
1312 /* setup the audio stream source select (audio -> dig mapping) */
1313 REG_SET(AFMT_AUDIO_SRC_CONTROL
, 0, AFMT_AUDIO_SRC_SELECT
, az_inst
);
1315 /* Channel allocation */
1316 REG_UPDATE(AFMT_AUDIO_PACKET_CONTROL2
, AFMT_AUDIO_CHANNEL_ENABLE
, channels
);
1319 static void dce110_se_setup_hdmi_audio(
1320 struct stream_encoder
*enc
,
1321 const struct audio_crtc_info
*crtc_info
)
1323 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1325 struct audio_clock_info audio_clock_info
= {0};
1326 uint32_t max_packets_per_line
;
1328 /* For now still do calculation, although this field is ignored when
1329 above HDMI_PACKET_GEN_VERSION set to 1 */
1330 max_packets_per_line
= calc_max_audio_packets_per_line(crtc_info
);
1332 /* HDMI_AUDIO_PACKET_CONTROL */
1333 REG_UPDATE_2(HDMI_AUDIO_PACKET_CONTROL
,
1334 HDMI_AUDIO_PACKETS_PER_LINE
, max_packets_per_line
,
1335 HDMI_AUDIO_DELAY_EN
, 1);
1337 /* AFMT_AUDIO_PACKET_CONTROL */
1338 REG_UPDATE(AFMT_AUDIO_PACKET_CONTROL
, AFMT_60958_CS_UPDATE
, 1);
1340 /* AFMT_AUDIO_PACKET_CONTROL2 */
1341 REG_UPDATE_2(AFMT_AUDIO_PACKET_CONTROL2
,
1342 AFMT_AUDIO_LAYOUT_OVRD
, 0,
1343 AFMT_60958_OSF_OVRD
, 0);
1345 /* HDMI_ACR_PACKET_CONTROL */
1346 REG_UPDATE_3(HDMI_ACR_PACKET_CONTROL
,
1347 HDMI_ACR_AUTO_SEND
, 1,
1349 HDMI_ACR_AUDIO_PRIORITY
, 0);
1351 /* Program audio clock sample/regeneration parameters */
1352 get_audio_clock_info(crtc_info
->color_depth
,
1353 crtc_info
->requested_pixel_clock
,
1354 crtc_info
->calculated_pixel_clock
,
1357 "\n%s:Input::requested_pixel_clock = %d" \
1358 "calculated_pixel_clock = %d \n", __func__
, \
1359 crtc_info
->requested_pixel_clock
, \
1360 crtc_info
->calculated_pixel_clock
);
1362 /* HDMI_ACR_32_0__HDMI_ACR_CTS_32_MASK */
1363 REG_UPDATE(HDMI_ACR_32_0
, HDMI_ACR_CTS_32
, audio_clock_info
.cts_32khz
);
1365 /* HDMI_ACR_32_1__HDMI_ACR_N_32_MASK */
1366 REG_UPDATE(HDMI_ACR_32_1
, HDMI_ACR_N_32
, audio_clock_info
.n_32khz
);
1368 /* HDMI_ACR_44_0__HDMI_ACR_CTS_44_MASK */
1369 REG_UPDATE(HDMI_ACR_44_0
, HDMI_ACR_CTS_44
, audio_clock_info
.cts_44khz
);
1371 /* HDMI_ACR_44_1__HDMI_ACR_N_44_MASK */
1372 REG_UPDATE(HDMI_ACR_44_1
, HDMI_ACR_N_44
, audio_clock_info
.n_44khz
);
1374 /* HDMI_ACR_48_0__HDMI_ACR_CTS_48_MASK */
1375 REG_UPDATE(HDMI_ACR_48_0
, HDMI_ACR_CTS_48
, audio_clock_info
.cts_48khz
);
1377 /* HDMI_ACR_48_1__HDMI_ACR_N_48_MASK */
1378 REG_UPDATE(HDMI_ACR_48_1
, HDMI_ACR_N_48
, audio_clock_info
.n_48khz
);
1380 /* Video driver cannot know in advance which sample rate will
1381 be used by HD Audio driver
1382 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_N_MULTIPLE field is
1383 programmed below in interruppt callback */
1385 /* AFMT_60958_0__AFMT_60958_CS_CHANNEL_NUMBER_L_MASK &
1386 AFMT_60958_0__AFMT_60958_CS_CLOCK_ACCURACY_MASK */
1387 REG_UPDATE_2(AFMT_60958_0
,
1388 AFMT_60958_CS_CHANNEL_NUMBER_L
, 1,
1389 AFMT_60958_CS_CLOCK_ACCURACY
, 0);
1391 /* AFMT_60958_1 AFMT_60958_CS_CHALNNEL_NUMBER_R */
1392 REG_UPDATE(AFMT_60958_1
, AFMT_60958_CS_CHANNEL_NUMBER_R
, 2);
1394 /*AFMT_60958_2 now keep this settings until
1395 * Programming guide comes out*/
1396 REG_UPDATE_6(AFMT_60958_2
,
1397 AFMT_60958_CS_CHANNEL_NUMBER_2
, 3,
1398 AFMT_60958_CS_CHANNEL_NUMBER_3
, 4,
1399 AFMT_60958_CS_CHANNEL_NUMBER_4
, 5,
1400 AFMT_60958_CS_CHANNEL_NUMBER_5
, 6,
1401 AFMT_60958_CS_CHANNEL_NUMBER_6
, 7,
1402 AFMT_60958_CS_CHANNEL_NUMBER_7
, 8);
1405 static void dce110_se_setup_dp_audio(
1406 struct stream_encoder
*enc
)
1408 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1410 /* --- DP Audio packet configurations --- */
1412 /* ATP Configuration */
1413 REG_SET(DP_SEC_AUD_N
, 0,
1414 DP_SEC_AUD_N
, DP_SEC_AUD_N__DP_SEC_AUD_N__DEFAULT
);
1416 /* Async/auto-calc timestamp mode */
1417 REG_SET(DP_SEC_TIMESTAMP
, 0, DP_SEC_TIMESTAMP_MODE
,
1418 DP_SEC_TIMESTAMP__DP_SEC_TIMESTAMP_MODE__AUTO_CALC
);
1420 /* --- The following are the registers
1421 * copied from the SetupHDMI --- */
1423 /* AFMT_AUDIO_PACKET_CONTROL */
1424 REG_UPDATE(AFMT_AUDIO_PACKET_CONTROL
, AFMT_60958_CS_UPDATE
, 1);
1426 /* AFMT_AUDIO_PACKET_CONTROL2 */
1427 /* Program the ATP and AIP next */
1428 REG_UPDATE_2(AFMT_AUDIO_PACKET_CONTROL2
,
1429 AFMT_AUDIO_LAYOUT_OVRD
, 0,
1430 AFMT_60958_OSF_OVRD
, 0);
1432 /* AFMT_INFOFRAME_CONTROL0 */
1433 REG_UPDATE(AFMT_INFOFRAME_CONTROL0
, AFMT_AUDIO_INFO_UPDATE
, 1);
1435 /* AFMT_60958_0__AFMT_60958_CS_CLOCK_ACCURACY_MASK */
1436 REG_UPDATE(AFMT_60958_0
, AFMT_60958_CS_CLOCK_ACCURACY
, 0);
1439 static void dce110_se_enable_audio_clock(
1440 struct stream_encoder
*enc
,
1443 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1445 if (REG(AFMT_CNTL
) == 0)
1446 return; /* DCE8/10 does not have this register */
1448 REG_UPDATE(AFMT_CNTL
, AFMT_AUDIO_CLOCK_EN
, !!enable
);
1450 /* wait for AFMT clock to turn on,
1451 * expectation: this should complete in 1-2 reads
1453 * REG_WAIT(AFMT_CNTL, AFMT_AUDIO_CLOCK_ON, !!enable, 1, 10);
1455 * TODO: wait for clock_on does not work well. May need HW
1456 * program sequence. But audio seems work normally even without wait
1457 * for clock_on status change
1461 static void dce110_se_enable_dp_audio(
1462 struct stream_encoder
*enc
)
1464 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1466 /* Enable Audio packets */
1467 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_ASP_ENABLE
, 1);
1469 /* Program the ATP and AIP next */
1470 REG_UPDATE_2(DP_SEC_CNTL
,
1471 DP_SEC_ATP_ENABLE
, 1,
1472 DP_SEC_AIP_ENABLE
, 1);
1474 /* Program STREAM_ENABLE after all the other enables. */
1475 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_STREAM_ENABLE
, 1);
1478 static void dce110_se_disable_dp_audio(
1479 struct stream_encoder
*enc
)
1481 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1484 /* Disable Audio packets */
1485 REG_UPDATE_5(DP_SEC_CNTL
,
1486 DP_SEC_ASP_ENABLE
, 0,
1487 DP_SEC_ATP_ENABLE
, 0,
1488 DP_SEC_AIP_ENABLE
, 0,
1489 DP_SEC_ACM_ENABLE
, 0,
1490 DP_SEC_STREAM_ENABLE
, 0);
1492 /* This register shared with encoder info frame. Therefore we need to
1493 keep master enabled if at least on of the fields is not 0 */
1494 value
= REG_READ(DP_SEC_CNTL
);
1496 REG_UPDATE(DP_SEC_CNTL
, DP_SEC_STREAM_ENABLE
, 1);
1500 void dce110_se_audio_mute_control(
1501 struct stream_encoder
*enc
,
1504 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1506 REG_UPDATE(AFMT_AUDIO_PACKET_CONTROL
, AFMT_AUDIO_SAMPLE_SEND
, !mute
);
1509 void dce110_se_dp_audio_setup(
1510 struct stream_encoder
*enc
,
1511 unsigned int az_inst
,
1512 struct audio_info
*info
)
1514 dce110_se_audio_setup(enc
, az_inst
, info
);
1517 void dce110_se_dp_audio_enable(
1518 struct stream_encoder
*enc
)
1520 dce110_se_enable_audio_clock(enc
, true);
1521 dce110_se_setup_dp_audio(enc
);
1522 dce110_se_enable_dp_audio(enc
);
1525 void dce110_se_dp_audio_disable(
1526 struct stream_encoder
*enc
)
1528 dce110_se_disable_dp_audio(enc
);
1529 dce110_se_enable_audio_clock(enc
, false);
1532 void dce110_se_hdmi_audio_setup(
1533 struct stream_encoder
*enc
,
1534 unsigned int az_inst
,
1535 struct audio_info
*info
,
1536 struct audio_crtc_info
*audio_crtc_info
)
1538 dce110_se_enable_audio_clock(enc
, true);
1539 dce110_se_setup_hdmi_audio(enc
, audio_crtc_info
);
1540 dce110_se_audio_setup(enc
, az_inst
, info
);
1543 void dce110_se_hdmi_audio_disable(
1544 struct stream_encoder
*enc
)
1546 dce110_se_enable_audio_clock(enc
, false);
1550 static void setup_stereo_sync(
1551 struct stream_encoder
*enc
,
1552 int tg_inst
, bool enable
)
1554 struct dce110_stream_encoder
*enc110
= DCE110STRENC_FROM_STRENC(enc
);
1555 REG_UPDATE(DIG_FE_CNTL
, DIG_STEREOSYNC_SELECT
, tg_inst
);
1556 REG_UPDATE(DIG_FE_CNTL
, DIG_STEREOSYNC_GATE_EN
, !enable
);
1560 static const struct stream_encoder_funcs dce110_str_enc_funcs
= {
1561 .dp_set_stream_attribute
=
1562 dce110_stream_encoder_dp_set_stream_attribute
,
1563 .hdmi_set_stream_attribute
=
1564 dce110_stream_encoder_hdmi_set_stream_attribute
,
1565 .dvi_set_stream_attribute
=
1566 dce110_stream_encoder_dvi_set_stream_attribute
,
1567 .set_mst_bandwidth
=
1568 dce110_stream_encoder_set_mst_bandwidth
,
1569 .update_hdmi_info_packets
=
1570 dce110_stream_encoder_update_hdmi_info_packets
,
1571 .stop_hdmi_info_packets
=
1572 dce110_stream_encoder_stop_hdmi_info_packets
,
1573 .update_dp_info_packets
=
1574 dce110_stream_encoder_update_dp_info_packets
,
1575 .stop_dp_info_packets
=
1576 dce110_stream_encoder_stop_dp_info_packets
,
1578 dce110_stream_encoder_dp_blank
,
1580 dce110_stream_encoder_dp_unblank
,
1581 .audio_mute_control
= dce110_se_audio_mute_control
,
1583 .dp_audio_setup
= dce110_se_dp_audio_setup
,
1584 .dp_audio_enable
= dce110_se_dp_audio_enable
,
1585 .dp_audio_disable
= dce110_se_dp_audio_disable
,
1587 .hdmi_audio_setup
= dce110_se_hdmi_audio_setup
,
1588 .hdmi_audio_disable
= dce110_se_hdmi_audio_disable
,
1589 .setup_stereo_sync
= setup_stereo_sync
,
1590 .set_avmute
= dce110_stream_encoder_set_avmute
,
1594 void dce110_stream_encoder_construct(
1595 struct dce110_stream_encoder
*enc110
,
1596 struct dc_context
*ctx
,
1598 enum engine_id eng_id
,
1599 const struct dce110_stream_enc_registers
*regs
,
1600 const struct dce_stream_encoder_shift
*se_shift
,
1601 const struct dce_stream_encoder_mask
*se_mask
)
1603 enc110
->base
.funcs
= &dce110_str_enc_funcs
;
1604 enc110
->base
.ctx
= ctx
;
1605 enc110
->base
.id
= eng_id
;
1606 enc110
->base
.bp
= bp
;
1607 enc110
->regs
= regs
;
1608 enc110
->se_shift
= se_shift
;
1609 enc110
->se_mask
= se_mask
;