1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <linux/delay.h>
27
28#include "dc_bios_types.h"
29#include "dcn20_stream_encoder.h"
30#include "reg_helper.h"
31#include "hw_shared.h"
32
33#define DC_LOGGER \
34 enc1->base.ctx->logger
35
36
37#define REG(reg)\
38 (enc1->regs->reg)
39
40#undef FN
41#define FN(reg_name, field_name) \
42 enc1->se_shift->field_name, enc1->se_mask->field_name
43
44
45#define CTX \
46 enc1->base.ctx
47
48
49static void enc2_update_hdmi_info_packet(
50 struct dcn10_stream_encoder *enc1,
51 uint32_t packet_index,
52 const struct dc_info_packet *info_packet)
53{
54 uint32_t cont, send, line;
55
56 if (info_packet->valid) {
57 enc1_update_generic_info_packet(
58 enc1,
59 packet_index,
60 info_packet);
61
62
63
64 cont = 1;
65
66 send = 1;
67
68 line = 2;
69 } else {
70 cont = 0;
71 send = 0;
72 line = 0;
73 }
74
75
76
77
78 switch (packet_index) {
79 case 0:
80 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
81 HDMI_GENERIC0_CONT, cont,
82 HDMI_GENERIC0_SEND, send);
83 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL1,
84 HDMI_GENERIC0_LINE, line);
85 break;
86 case 1:
87 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
88 HDMI_GENERIC1_CONT, cont,
89 HDMI_GENERIC1_SEND, send);
90 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL1,
91 HDMI_GENERIC1_LINE, line);
92 break;
93 case 2:
94 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
95 HDMI_GENERIC2_CONT, cont,
96 HDMI_GENERIC2_SEND, send);
97 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL2,
98 HDMI_GENERIC2_LINE, line);
99 break;
100 case 3:
101 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
102 HDMI_GENERIC3_CONT, cont,
103 HDMI_GENERIC3_SEND, send);
104 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL2,
105 HDMI_GENERIC3_LINE, line);
106 break;
107 case 4:
108 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
109 HDMI_GENERIC4_CONT, cont,
110 HDMI_GENERIC4_SEND, send);
111 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL3,
112 HDMI_GENERIC4_LINE, line);
113 break;
114 case 5:
115 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
116 HDMI_GENERIC5_CONT, cont,
117 HDMI_GENERIC5_SEND, send);
118 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL3,
119 HDMI_GENERIC5_LINE, line);
120 break;
121 case 6:
122 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
123 HDMI_GENERIC6_CONT, cont,
124 HDMI_GENERIC6_SEND, send);
125 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL4,
126 HDMI_GENERIC6_LINE, line);
127 break;
128 case 7:
129 REG_UPDATE_2(HDMI_GENERIC_PACKET_CONTROL0,
130 HDMI_GENERIC7_CONT, cont,
131 HDMI_GENERIC7_SEND, send);
132 REG_UPDATE(HDMI_GENERIC_PACKET_CONTROL4,
133 HDMI_GENERIC7_LINE, line);
134 break;
135 default:
136
137 DC_LOG_WARNING(
138 "Invalid HW packet index: %s()\n",
139 __func__);
140 return;
141 }
142}
143
144static void enc2_stream_encoder_update_hdmi_info_packets(
145 struct stream_encoder *enc,
146 const struct encoder_info_frame *info_frame)
147{
148 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
149
150
151 REG_UPDATE(HDMI_DB_CONTROL, HDMI_DB_DISABLE, 1);
152
153
154 enc2_update_hdmi_info_packet(enc1, 0, &info_frame->avi);
155 enc2_update_hdmi_info_packet(enc1, 1, &info_frame->hfvsif);
156 enc2_update_hdmi_info_packet(enc1, 2, &info_frame->gamut);
157 enc2_update_hdmi_info_packet(enc1, 3, &info_frame->vendor);
158 enc2_update_hdmi_info_packet(enc1, 4, &info_frame->spd);
159 enc2_update_hdmi_info_packet(enc1, 5, &info_frame->hdrsmd);
160}
161
162static void enc2_stream_encoder_stop_hdmi_info_packets(
163 struct stream_encoder *enc)
164{
165 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
166
167
168 REG_SET_4(HDMI_GENERIC_PACKET_CONTROL0, 0,
169 HDMI_GENERIC0_CONT, 0,
170 HDMI_GENERIC0_SEND, 0,
171 HDMI_GENERIC1_CONT, 0,
172 HDMI_GENERIC1_SEND, 0);
173 REG_SET_2(HDMI_GENERIC_PACKET_CONTROL1, 0,
174 HDMI_GENERIC0_LINE, 0,
175 HDMI_GENERIC1_LINE, 0);
176
177
178 REG_SET_4(HDMI_GENERIC_PACKET_CONTROL0, 0,
179 HDMI_GENERIC2_CONT, 0,
180 HDMI_GENERIC2_SEND, 0,
181 HDMI_GENERIC3_CONT, 0,
182 HDMI_GENERIC3_SEND, 0);
183 REG_SET_2(HDMI_GENERIC_PACKET_CONTROL2, 0,
184 HDMI_GENERIC2_LINE, 0,
185 HDMI_GENERIC3_LINE, 0);
186
187
188 REG_SET_4(HDMI_GENERIC_PACKET_CONTROL0, 0,
189 HDMI_GENERIC4_CONT, 0,
190 HDMI_GENERIC4_SEND, 0,
191 HDMI_GENERIC5_CONT, 0,
192 HDMI_GENERIC5_SEND, 0);
193 REG_SET_2(HDMI_GENERIC_PACKET_CONTROL3, 0,
194 HDMI_GENERIC4_LINE, 0,
195 HDMI_GENERIC5_LINE, 0);
196
197
198 REG_SET_4(HDMI_GENERIC_PACKET_CONTROL0, 0,
199 HDMI_GENERIC6_CONT, 0,
200 HDMI_GENERIC6_SEND, 0,
201 HDMI_GENERIC7_CONT, 0,
202 HDMI_GENERIC7_SEND, 0);
203 REG_SET_2(HDMI_GENERIC_PACKET_CONTROL4, 0,
204 HDMI_GENERIC6_LINE, 0,
205 HDMI_GENERIC7_LINE, 0);
206}
207
208
209
210static void enc2_update_gsp7_128_info_packet(
211 struct dcn10_stream_encoder *enc1,
212 const struct dc_info_packet_128 *info_packet)
213{
214 uint32_t i;
215
216
217
218
219 uint32_t max_retries = 50;
220 const uint32_t *content = (const uint32_t *) &info_packet->sb[0];
221
222 ASSERT(info_packet->hb1 == DC_DP_INFOFRAME_TYPE_PPS);
223
224
225 REG_UPDATE(DP_SEC_CNTL2, DP_SEC_GSP7_PPS, 1);
226
227
228 REG_UPDATE(AFMT_CNTL, AFMT_AUDIO_CLOCK_EN, 1);
229
230
231
232
233
234
235
236 REG_WAIT(AFMT_VBI_PACKET_CONTROL, AFMT_GENERIC_CONFLICT,
237 0, 10, max_retries);
238
239
240 REG_UPDATE(AFMT_VBI_PACKET_CONTROL, AFMT_GENERIC_CONFLICT_CLR, 1);
241
242
243 REG_UPDATE(AFMT_VBI_PACKET_CONTROL, AFMT_GENERIC_INDEX, 7);
244 REG_SET_4(AFMT_GENERIC_HDR, 0,
245 AFMT_GENERIC_HB0, info_packet->hb0,
246 AFMT_GENERIC_HB1, info_packet->hb1,
247 AFMT_GENERIC_HB2, info_packet->hb2,
248 AFMT_GENERIC_HB3, info_packet->hb3);
249
250
251
252
253 for (i = 0; i < 4; i++) {
254 uint32_t packet_index = 7 + i;
255 REG_UPDATE(AFMT_VBI_PACKET_CONTROL, AFMT_GENERIC_INDEX, packet_index);
256
257 REG_WRITE(AFMT_GENERIC_0, *content++);
258 REG_WRITE(AFMT_GENERIC_1, *content++);
259 REG_WRITE(AFMT_GENERIC_2, *content++);
260 REG_WRITE(AFMT_GENERIC_3, *content++);
261 REG_WRITE(AFMT_GENERIC_4, *content++);
262 REG_WRITE(AFMT_GENERIC_5, *content++);
263 REG_WRITE(AFMT_GENERIC_6, *content++);
264 REG_WRITE(AFMT_GENERIC_7, *content++);
265 }
266
267 REG_UPDATE(AFMT_VBI_PACKET_CONTROL1, AFMT_GENERIC7_FRAME_UPDATE, 1);
268}
269
270
271
272
273
274
275static void enc2_dp_set_dsc_config(struct stream_encoder *enc,
276 enum optc_dsc_mode dsc_mode,
277 uint32_t dsc_bytes_per_pixel,
278 uint32_t dsc_slice_width)
279{
280 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
281
282 REG_UPDATE_2(DP_DSC_CNTL,
283 DP_DSC_MODE, dsc_mode,
284 DP_DSC_SLICE_WIDTH, dsc_slice_width);
285
286 REG_SET(DP_DSC_BYTES_PER_PIXEL, 0,
287 DP_DSC_BYTES_PER_PIXEL, dsc_bytes_per_pixel);
288}
289
290
291static void enc2_dp_set_dsc_pps_info_packet(struct stream_encoder *enc,
292 bool enable,
293 uint8_t *dsc_packed_pps)
294{
295 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
296
297 if (enable) {
298 struct dc_info_packet_128 pps_sdp;
299
300 ASSERT(dsc_packed_pps);
301
302
303 pps_sdp.valid = true;
304 pps_sdp.hb0 = 0;
305 pps_sdp.hb1 = DC_DP_INFOFRAME_TYPE_PPS;
306 pps_sdp.hb2 = 127;
307 pps_sdp.hb3 = 0;
308 memcpy(&pps_sdp.sb[0], dsc_packed_pps, sizeof(pps_sdp.sb));
309 enc2_update_gsp7_128_info_packet(enc1, &pps_sdp);
310
311
312
313
314
315
316
317
318 REG_UPDATE(DP_SEC_CNTL6,
319 DP_SEC_GSP7_LINE_NUM, 2);
320 REG_UPDATE_2(DP_MSA_VBID_MISC,
321 DP_VBID6_LINE_REFERENCE, 0,
322 DP_VBID6_LINE_NUM, 3);
323
324
325
326
327
328
329
330
331 REG_UPDATE_2(DP_SEC_CNTL,
332 DP_SEC_GSP7_ENABLE, 1,
333 DP_SEC_STREAM_ENABLE, 1);
334 } else {
335
336 REG_UPDATE(DP_SEC_CNTL, DP_SEC_GSP7_ENABLE, 0);
337 REG_UPDATE(DP_SEC_CNTL2, DP_SEC_GSP7_PPS, 0);
338 }
339}
340
341
342
343
344
345static void enc2_read_state(struct stream_encoder *enc, struct enc_state *s)
346{
347 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
348
349
350 REG_GET(DP_DSC_CNTL, DP_DSC_MODE, &s->dsc_mode);
351 if (s->dsc_mode) {
352 REG_GET(DP_DSC_CNTL, DP_DSC_SLICE_WIDTH, &s->dsc_slice_width);
353 REG_GET(DP_SEC_CNTL6, DP_SEC_GSP7_LINE_NUM, &s->sec_gsp_pps_line_num);
354
355 REG_GET(DP_MSA_VBID_MISC, DP_VBID6_LINE_REFERENCE, &s->vbid6_line_reference);
356 REG_GET(DP_MSA_VBID_MISC, DP_VBID6_LINE_NUM, &s->vbid6_line_num);
357
358 REG_GET(DP_SEC_CNTL, DP_SEC_GSP7_ENABLE, &s->sec_gsp_pps_enable);
359 REG_GET(DP_SEC_CNTL, DP_SEC_STREAM_ENABLE, &s->sec_stream_enable);
360 }
361}
362
363
364
365
366
367
368
369
370
371void enc2_set_dynamic_metadata(struct stream_encoder *enc,
372 bool enable_dme,
373 uint32_t hubp_requestor_id,
374 enum dynamic_metadata_mode dmdata_mode)
375{
376 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
377
378 if (enable_dme) {
379 REG_UPDATE_2(DME_CONTROL,
380 METADATA_HUBP_REQUESTOR_ID, hubp_requestor_id,
381 METADATA_STREAM_TYPE, (dmdata_mode == dmdata_dolby_vision) ? 1 : 0);
382
383
384
385
386 if (dmdata_mode == dmdata_dp)
387 REG_UPDATE_3(DP_SEC_METADATA_TRANSMISSION,
388 DP_SEC_METADATA_PACKET_ENABLE, 1,
389 DP_SEC_METADATA_PACKET_LINE_REFERENCE, 0,
390 DP_SEC_METADATA_PACKET_LINE, 20);
391 else {
392 REG_UPDATE_3(HDMI_METADATA_PACKET_CONTROL,
393 HDMI_METADATA_PACKET_ENABLE, 1,
394 HDMI_METADATA_PACKET_LINE_REFERENCE, 0,
395 HDMI_METADATA_PACKET_LINE, 2);
396
397 if (dmdata_mode == dmdata_dolby_vision)
398 REG_UPDATE(DIG_FE_CNTL,
399 DOLBY_VISION_EN, 1);
400 }
401
402 REG_UPDATE(DME_CONTROL,
403 METADATA_ENGINE_EN, 1);
404 } else {
405 REG_UPDATE(DME_CONTROL,
406 METADATA_ENGINE_EN, 0);
407
408 if (dmdata_mode == dmdata_dp)
409 REG_UPDATE(DP_SEC_METADATA_TRANSMISSION,
410 DP_SEC_METADATA_PACKET_ENABLE, 0);
411 else {
412 REG_UPDATE(HDMI_METADATA_PACKET_CONTROL,
413 HDMI_METADATA_PACKET_ENABLE, 0);
414 REG_UPDATE(DIG_FE_CNTL,
415 DOLBY_VISION_EN, 0);
416 }
417 }
418}
419
420static void enc2_stream_encoder_update_dp_info_packets(
421 struct stream_encoder *enc,
422 const struct encoder_info_frame *info_frame)
423{
424 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
425 uint32_t dmdata_packet_enabled = 0;
426
427 enc1_stream_encoder_update_dp_info_packets(enc, info_frame);
428
429
430 REG_GET(DP_SEC_METADATA_TRANSMISSION,
431 DP_SEC_METADATA_PACKET_ENABLE, &dmdata_packet_enabled);
432
433 if (dmdata_packet_enabled)
434 REG_UPDATE(DP_SEC_CNTL, DP_SEC_STREAM_ENABLE, 1);
435}
436
437static bool is_two_pixels_per_containter(const struct dc_crtc_timing *timing)
438{
439 bool two_pix = timing->pixel_encoding == PIXEL_ENCODING_YCBCR420;
440
441 two_pix = two_pix || (timing->flags.DSC && timing->pixel_encoding == PIXEL_ENCODING_YCBCR422
442 && !timing->dsc_cfg.ycbcr422_simple);
443 return two_pix;
444}
445
446void enc2_stream_encoder_dp_unblank(
447 struct stream_encoder *enc,
448 const struct encoder_unblank_param *param)
449{
450 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
451
452 if (param->link_settings.link_rate != LINK_RATE_UNKNOWN) {
453 uint32_t n_vid = 0x8000;
454 uint32_t m_vid;
455 uint32_t n_multiply = 0;
456 uint64_t m_vid_l = n_vid;
457
458
459 if (is_two_pixels_per_containter(¶m->timing) || param->opp_cnt > 1) {
460
461 n_multiply = 1;
462 }
463
464
465
466
467 m_vid_l *= param->timing.pix_clk_100hz / 10;
468 m_vid_l = div_u64(m_vid_l,
469 param->link_settings.link_rate
470 * LINK_RATE_REF_FREQ_IN_KHZ);
471
472 m_vid = (uint32_t) m_vid_l;
473
474
475
476 REG_UPDATE(DP_VID_TIMING, DP_VID_M_N_GEN_EN, 0);
477
478
479
480
481
482 REG_UPDATE(DP_VID_N, DP_VID_N, n_vid);
483
484 REG_UPDATE(DP_VID_M, DP_VID_M, m_vid);
485
486 REG_UPDATE_2(DP_VID_TIMING,
487 DP_VID_M_N_GEN_EN, 1,
488 DP_VID_N_MUL, n_multiply);
489 }
490
491
492 REG_UPDATE(DP_VID_STREAM_CNTL, DP_VID_STREAM_ENABLE, false);
493 REG_WAIT(DP_VID_STREAM_CNTL, DP_VID_STREAM_STATUS, 0, 10, 5000);
494
495
496 REG_UPDATE(DIG_FE_CNTL, DIG_START, 1);
497 udelay(1);
498
499
500
501 REG_UPDATE(DIG_FE_CNTL, DIG_START, 0);
502
503
504
505
506 REG_UPDATE(DP_STEER_FIFO, DP_STEER_FIFO_RESET, 1);
507 udelay(10);
508
509 REG_UPDATE(DP_STEER_FIFO, DP_STEER_FIFO_RESET, 0);
510
511
512
513
514 udelay(100);
515
516
517
518
519
520
521
522
523
524 REG_UPDATE(DP_VID_STREAM_CNTL, DP_VID_STREAM_ENABLE, true);
525}
526
527static void enc2_dp_set_odm_combine(
528 struct stream_encoder *enc,
529 bool odm_combine)
530{
531 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
532
533 REG_UPDATE(DP_PIXEL_FORMAT, DP_PIXEL_COMBINE, odm_combine);
534}
535
536void enc2_stream_encoder_dp_set_stream_attribute(
537 struct stream_encoder *enc,
538 struct dc_crtc_timing *crtc_timing,
539 enum dc_color_space output_color_space,
540 bool use_vsc_sdp_for_colorimetry,
541 uint32_t enable_sdp_splitting)
542{
543 struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
544
545 enc1_stream_encoder_dp_set_stream_attribute(enc,
546 crtc_timing,
547 output_color_space,
548 use_vsc_sdp_for_colorimetry,
549 enable_sdp_splitting);
550
551 REG_UPDATE(DP_SEC_FRAMING4,
552 DP_SST_SDP_SPLITTING, enable_sdp_splitting);
553}
554
555static const struct stream_encoder_funcs dcn20_str_enc_funcs = {
556 .dp_set_odm_combine =
557 enc2_dp_set_odm_combine,
558 .dp_set_stream_attribute =
559 enc2_stream_encoder_dp_set_stream_attribute,
560 .hdmi_set_stream_attribute =
561 enc1_stream_encoder_hdmi_set_stream_attribute,
562 .dvi_set_stream_attribute =
563 enc1_stream_encoder_dvi_set_stream_attribute,
564 .set_throttled_vcp_size =
565 enc1_stream_encoder_set_throttled_vcp_size,
566 .update_hdmi_info_packets =
567 enc2_stream_encoder_update_hdmi_info_packets,
568 .stop_hdmi_info_packets =
569 enc2_stream_encoder_stop_hdmi_info_packets,
570 .update_dp_info_packets =
571 enc2_stream_encoder_update_dp_info_packets,
572 .send_immediate_sdp_message =
573 enc1_stream_encoder_send_immediate_sdp_message,
574 .stop_dp_info_packets =
575 enc1_stream_encoder_stop_dp_info_packets,
576 .dp_blank =
577 enc1_stream_encoder_dp_blank,
578 .dp_unblank =
579 enc2_stream_encoder_dp_unblank,
580 .audio_mute_control = enc1_se_audio_mute_control,
581
582 .dp_audio_setup = enc1_se_dp_audio_setup,
583 .dp_audio_enable = enc1_se_dp_audio_enable,
584 .dp_audio_disable = enc1_se_dp_audio_disable,
585
586 .hdmi_audio_setup = enc1_se_hdmi_audio_setup,
587 .hdmi_audio_disable = enc1_se_hdmi_audio_disable,
588 .setup_stereo_sync = enc1_setup_stereo_sync,
589 .set_avmute = enc1_stream_encoder_set_avmute,
590 .dig_connect_to_otg = enc1_dig_connect_to_otg,
591 .dig_source_otg = enc1_dig_source_otg,
592
593 .dp_get_pixel_format =
594 enc1_stream_encoder_dp_get_pixel_format,
595
596 .enc_read_state = enc2_read_state,
597 .dp_set_dsc_config = enc2_dp_set_dsc_config,
598 .dp_set_dsc_pps_info_packet = enc2_dp_set_dsc_pps_info_packet,
599 .set_dynamic_metadata = enc2_set_dynamic_metadata,
600 .hdmi_reset_stream_attribute = enc1_reset_hdmi_stream_attribute,
601};
602
603void dcn20_stream_encoder_construct(
604 struct dcn10_stream_encoder *enc1,
605 struct dc_context *ctx,
606 struct dc_bios *bp,
607 enum engine_id eng_id,
608 const struct dcn10_stream_enc_registers *regs,
609 const struct dcn10_stream_encoder_shift *se_shift,
610 const struct dcn10_stream_encoder_mask *se_mask)
611{
612 enc1->base.funcs = &dcn20_str_enc_funcs;
613 enc1->base.ctx = ctx;
614 enc1->base.id = eng_id;
615 enc1->base.bp = bp;
616 enc1->regs = regs;
617 enc1->se_shift = se_shift;
618 enc1->se_mask = se_mask;
619 enc1->base.stream_enc_inst = eng_id - ENGINE_ID_DIGA;
620}
621
622