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/slab.h>
27
28#include "reg_helper.h"
29#include "dce_audio.h"
30#include "dce/dce_11_0_d.h"
31#include "dce/dce_11_0_sh_mask.h"
32
33#define DCE_AUD(audio)\
34 container_of(audio, struct dce_audio, base)
35
36#define CTX \
37 aud->base.ctx
38
39#define DC_LOGGER_INIT()
40
41#define REG(reg)\
42 (aud->regs->reg)
43
44#undef FN
45#define FN(reg_name, field_name) \
46 aud->shifts->field_name, aud->masks->field_name
47
48#define IX_REG(reg)\
49 ix ## reg
50
51#define AZ_REG_READ(reg_name) \
52 read_indirect_azalia_reg(audio, IX_REG(reg_name))
53
54#define AZ_REG_WRITE(reg_name, value) \
55 write_indirect_azalia_reg(audio, IX_REG(reg_name), value)
56
57static void write_indirect_azalia_reg(struct audio *audio,
58 uint32_t reg_index,
59 uint32_t reg_data)
60{
61 struct dce_audio *aud = DCE_AUD(audio);
62
63
64 REG_SET(AZALIA_F0_CODEC_ENDPOINT_INDEX, 0,
65 AZALIA_ENDPOINT_REG_INDEX, reg_index);
66
67
68 REG_SET(AZALIA_F0_CODEC_ENDPOINT_DATA, 0,
69 AZALIA_ENDPOINT_REG_DATA, reg_data);
70}
71
72static uint32_t read_indirect_azalia_reg(struct audio *audio, uint32_t reg_index)
73{
74 struct dce_audio *aud = DCE_AUD(audio);
75
76 uint32_t value = 0;
77
78
79 REG_SET(AZALIA_F0_CODEC_ENDPOINT_INDEX, 0,
80 AZALIA_ENDPOINT_REG_INDEX, reg_index);
81
82
83 value = REG_READ(AZALIA_F0_CODEC_ENDPOINT_DATA);
84
85 return value;
86}
87
88static bool is_audio_format_supported(
89 const struct audio_info *audio_info,
90 enum audio_format_code audio_format_code,
91 uint32_t *format_index)
92{
93 uint32_t index;
94 uint32_t max_channe_index = 0;
95 bool found = false;
96
97 if (audio_info == NULL)
98 return found;
99
100
101 for (index = 0; index < audio_info->mode_count; index++) {
102 if (audio_info->modes[index].format_code == audio_format_code) {
103 if (found) {
104
105
106 if (audio_info->modes[index].channel_count >
107 audio_info->modes[max_channe_index].channel_count) {
108 max_channe_index = index;
109 }
110 } else {
111
112 found = true;
113 max_channe_index = index;
114 }
115 }
116 }
117
118
119 if (found && format_index != NULL)
120 *format_index = max_channe_index;
121
122 return found;
123}
124
125
126static void check_audio_bandwidth_hdmi(
127 const struct audio_crtc_info *crtc_info,
128 uint32_t channel_count,
129 union audio_sample_rates *sample_rates)
130{
131 uint32_t samples;
132 uint32_t h_blank;
133 bool limit_freq_to_48_khz = false;
134 bool limit_freq_to_88_2_khz = false;
135 bool limit_freq_to_96_khz = false;
136 bool limit_freq_to_174_4_khz = false;
137 if (!crtc_info)
138 return;
139
140
141 if (channel_count > 2) {
142
143
144 if ((crtc_info->requested_pixel_clock_100Hz <= 270000) &&
145 (crtc_info->v_active <= 576) &&
146 !(crtc_info->interlaced) &&
147 !(crtc_info->pixel_repetition == 2 ||
148 crtc_info->pixel_repetition == 4)) {
149 limit_freq_to_48_khz = true;
150
151 } else if ((crtc_info->requested_pixel_clock_100Hz <= 270000) &&
152 (crtc_info->v_active <= 576) &&
153 (crtc_info->interlaced) &&
154 (crtc_info->pixel_repetition == 2)) {
155 limit_freq_to_88_2_khz = true;
156
157 } else if ((crtc_info->requested_pixel_clock_100Hz <= 540000) &&
158 (crtc_info->v_active <= 576) &&
159 !(crtc_info->interlaced)) {
160 limit_freq_to_174_4_khz = true;
161 }
162 }
163
164
165
166
167 h_blank = crtc_info->h_total - crtc_info->h_active;
168
169 if (crtc_info->pixel_repetition)
170 h_blank *= crtc_info->pixel_repetition;
171
172
173 h_blank -= 58;
174
175 h_blank -= 16;
176
177 samples = h_blank * 10;
178
179
180
181 samples /= 32;
182 samples *= crtc_info->v_active;
183
184 samples *= crtc_info->refresh_rate;
185
186 samples /= 10;
187
188
189
190
191
192
193
194
195 switch (crtc_info->color_depth) {
196 case COLOR_DEPTH_888:
197 samples *= 4;
198 break;
199 case COLOR_DEPTH_101010:
200 samples *= 5;
201 break;
202 case COLOR_DEPTH_121212:
203 samples *= 6;
204 break;
205 default:
206 samples *= 4;
207 break;
208 }
209
210 samples /= 4;
211
212
213 if (samples < 88200)
214 limit_freq_to_48_khz = true;
215 else if (samples < 96000)
216 limit_freq_to_88_2_khz = true;
217 else if (samples < 176400)
218 limit_freq_to_96_khz = true;
219 else if (samples < 192000)
220 limit_freq_to_174_4_khz = true;
221
222 if (sample_rates != NULL) {
223
224 if (limit_freq_to_174_4_khz)
225 sample_rates->rate.RATE_192 = 0;
226
227 if (limit_freq_to_96_khz) {
228 sample_rates->rate.RATE_192 = 0;
229 sample_rates->rate.RATE_176_4 = 0;
230 }
231 if (limit_freq_to_88_2_khz) {
232 sample_rates->rate.RATE_192 = 0;
233 sample_rates->rate.RATE_176_4 = 0;
234 sample_rates->rate.RATE_96 = 0;
235 }
236 if (limit_freq_to_48_khz) {
237 sample_rates->rate.RATE_192 = 0;
238 sample_rates->rate.RATE_176_4 = 0;
239 sample_rates->rate.RATE_96 = 0;
240 sample_rates->rate.RATE_88_2 = 0;
241 }
242 }
243}
244
245
246static void check_audio_bandwidth_dpsst(
247 const struct audio_crtc_info *crtc_info,
248 uint32_t channel_count,
249 union audio_sample_rates *sample_rates)
250{
251
252}
253
254
255static void check_audio_bandwidth_dpmst(
256 const struct audio_crtc_info *crtc_info,
257 uint32_t channel_count,
258 union audio_sample_rates *sample_rates)
259{
260
261}
262
263static void check_audio_bandwidth(
264 const struct audio_crtc_info *crtc_info,
265 uint32_t channel_count,
266 enum signal_type signal,
267 union audio_sample_rates *sample_rates)
268{
269 switch (signal) {
270 case SIGNAL_TYPE_HDMI_TYPE_A:
271 check_audio_bandwidth_hdmi(
272 crtc_info, channel_count, sample_rates);
273 break;
274 case SIGNAL_TYPE_EDP:
275 case SIGNAL_TYPE_DISPLAY_PORT:
276 check_audio_bandwidth_dpsst(
277 crtc_info, channel_count, sample_rates);
278 break;
279 case SIGNAL_TYPE_DISPLAY_PORT_MST:
280 check_audio_bandwidth_dpmst(
281 crtc_info, channel_count, sample_rates);
282 break;
283 default:
284 break;
285 }
286}
287
288
289static void set_high_bit_rate_capable(
290 struct audio *audio,
291 bool capable)
292{
293 uint32_t value = 0;
294
295
296 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_HBR);
297
298 set_reg_field_value(value, capable,
299 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_HBR,
300 HBR_CAPABLE);
301
302 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_HBR, value);
303}
304
305
306static void set_video_latency(
307 struct audio *audio,
308 int latency_in_ms)
309{
310 uint32_t value = 0;
311
312 if ((latency_in_ms < 0) || (latency_in_ms > 255))
313 return;
314
315 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC);
316
317 set_reg_field_value(value, latency_in_ms,
318 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC,
319 VIDEO_LIPSYNC);
320
321 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC,
322 value);
323}
324
325
326static void set_audio_latency(
327 struct audio *audio,
328 int latency_in_ms)
329{
330 uint32_t value = 0;
331
332 if (latency_in_ms < 0)
333 latency_in_ms = 0;
334
335 if (latency_in_ms > 255)
336 latency_in_ms = 255;
337
338 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC);
339
340 set_reg_field_value(value, latency_in_ms,
341 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC,
342 AUDIO_LIPSYNC);
343
344 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC,
345 value);
346}
347
348void dce_aud_az_enable(struct audio *audio)
349{
350 uint32_t value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL);
351 DC_LOGGER_INIT();
352
353 set_reg_field_value(value, 1,
354 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
355 CLOCK_GATING_DISABLE);
356 set_reg_field_value(value, 1,
357 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
358 AUDIO_ENABLED);
359
360 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
361 set_reg_field_value(value, 0,
362 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
363 CLOCK_GATING_DISABLE);
364 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
365
366 DC_LOG_HW_AUDIO("\n\t========= AUDIO:dce_aud_az_enable: index: %u data: 0x%x\n",
367 audio->inst, value);
368}
369
370void dce_aud_az_disable(struct audio *audio)
371{
372 uint32_t value;
373 DC_LOGGER_INIT();
374
375 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL);
376 set_reg_field_value(value, 1,
377 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
378 CLOCK_GATING_DISABLE);
379 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
380
381 set_reg_field_value(value, 0,
382 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
383 AUDIO_ENABLED);
384 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
385
386 set_reg_field_value(value, 0,
387 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
388 CLOCK_GATING_DISABLE);
389 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
390 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL);
391 DC_LOG_HW_AUDIO("\n\t========= AUDIO:dce_aud_az_disable: index: %u data: 0x%x\n",
392 audio->inst, value);
393}
394
395void dce_aud_az_configure(
396 struct audio *audio,
397 enum signal_type signal,
398 const struct audio_crtc_info *crtc_info,
399 const struct audio_info *audio_info)
400{
401 struct dce_audio *aud = DCE_AUD(audio);
402
403 uint32_t speakers = audio_info->flags.info.ALLSPEAKERS;
404 uint32_t value;
405 uint32_t field = 0;
406 enum audio_format_code audio_format_code;
407 uint32_t format_index;
408 uint32_t index;
409 bool is_ac3_supported = false;
410 union audio_sample_rates sample_rate;
411 uint32_t strlen = 0;
412 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL);
413 set_reg_field_value(value, 1,
414 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
415 CLOCK_GATING_DISABLE);
416 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
417
418
419
420
421
422 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER);
423
424 set_reg_field_value(value,
425 speakers,
426 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
427 SPEAKER_ALLOCATION);
428
429
430
431
432
433
434
435 set_reg_field_value(value,
436 0,
437 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
438 LFE_PLAYBACK_LEVEL);
439
440
441
442
443 set_reg_field_value(value,
444 0,
445 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
446 HDMI_CONNECTION);
447
448 set_reg_field_value(value,
449 0,
450 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
451 DP_CONNECTION);
452
453 field = get_reg_field_value(value,
454 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
455 EXTRA_CONNECTION_INFO);
456
457 field &= ~0x1;
458
459 set_reg_field_value(value,
460 field,
461 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
462 EXTRA_CONNECTION_INFO);
463
464
465 switch (signal) {
466 case SIGNAL_TYPE_HDMI_TYPE_A:
467 set_reg_field_value(value,
468 1,
469 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
470 HDMI_CONNECTION);
471
472 break;
473
474 case SIGNAL_TYPE_EDP:
475 case SIGNAL_TYPE_DISPLAY_PORT:
476 case SIGNAL_TYPE_DISPLAY_PORT_MST:
477 set_reg_field_value(value,
478 1,
479 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER,
480 DP_CONNECTION);
481 break;
482 default:
483 BREAK_TO_DEBUGGER();
484 break;
485 }
486
487 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, value);
488
489
490
491 for (format_index = 0; format_index < AUDIO_FORMAT_CODE_COUNT;
492 format_index++) {
493 audio_format_code =
494 (AUDIO_FORMAT_CODE_FIRST + format_index);
495
496
497 if (audio_format_code == AUDIO_FORMAT_CODE_1BITAUDIO ||
498 audio_format_code == AUDIO_FORMAT_CODE_DST)
499 continue;
500
501 value = 0;
502
503
504 if (is_audio_format_supported(
505 audio_info, audio_format_code, &index)) {
506 const struct audio_mode *audio_mode =
507 &audio_info->modes[index];
508 union audio_sample_rates sample_rates =
509 audio_mode->sample_rates;
510 uint8_t byte2 = audio_mode->max_bit_rate;
511 uint8_t channel_count = audio_mode->channel_count;
512
513
514 switch (audio_format_code) {
515 case AUDIO_FORMAT_CODE_LINEARPCM: {
516
517 check_audio_bandwidth(
518 crtc_info,
519 channel_count,
520 signal,
521 &sample_rates);
522
523 byte2 = audio_mode->sample_size;
524
525 set_reg_field_value(value,
526 sample_rates.all,
527 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0,
528 SUPPORTED_FREQUENCIES_STEREO);
529 }
530 break;
531 case AUDIO_FORMAT_CODE_AC3:
532 is_ac3_supported = true;
533 break;
534 case AUDIO_FORMAT_CODE_DOLBYDIGITALPLUS:
535 case AUDIO_FORMAT_CODE_DTS_HD:
536 case AUDIO_FORMAT_CODE_MAT_MLP:
537 case AUDIO_FORMAT_CODE_DST:
538 case AUDIO_FORMAT_CODE_WMAPRO:
539 byte2 = audio_mode->vendor_specific;
540 break;
541 default:
542 break;
543 }
544
545
546 set_reg_field_value(value,
547 channel_count - 1,
548 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0,
549 MAX_CHANNELS);
550
551 set_reg_field_value(value,
552 sample_rates.all,
553 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0,
554 SUPPORTED_FREQUENCIES);
555
556 set_reg_field_value(value,
557 byte2,
558 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0,
559 DESCRIPTOR_BYTE_2);
560 }
561
562 AZ_REG_WRITE(
563 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0 + format_index,
564 value);
565 }
566
567 if (is_ac3_supported)
568
569 REG_WRITE(AZALIA_F0_CODEC_FUNCTION_PARAMETER_STREAM_FORMATS,
570 0x05);
571
572
573 sample_rate.all = 0;
574 sample_rate.rate.RATE_192 = 1;
575
576 check_audio_bandwidth(
577 crtc_info,
578 8,
579 signal,
580 &sample_rate);
581
582 set_high_bit_rate_capable(audio, sample_rate.rate.RATE_192);
583
584
585 set_video_latency(audio, audio_info->video_latency);
586 set_audio_latency(audio, audio_info->audio_latency);
587
588 value = 0;
589 set_reg_field_value(value, audio_info->manufacture_id,
590 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO0,
591 MANUFACTURER_ID);
592
593 set_reg_field_value(value, audio_info->product_id,
594 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO0,
595 PRODUCT_ID);
596
597 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO0,
598 value);
599
600 value = 0;
601
602
603 while (audio_info->display_name[strlen++] != '\0') {
604 if (strlen >=
605 MAX_HW_AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS)
606 break;
607 }
608 set_reg_field_value(value, strlen,
609 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO1,
610 SINK_DESCRIPTION_LEN);
611
612 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO1,
613 value);
614 DC_LOG_HW_AUDIO("\n\tAUDIO:az_configure: index: %u data, 0x%x, displayName %s: \n",
615 audio->inst, value, audio_info->display_name);
616
617
618
619
620
621
622
623
624 value = 0;
625
626 set_reg_field_value(value, audio_info->port_id[0],
627 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO2,
628 PORT_ID0);
629
630 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO2, value);
631
632 value = 0;
633 set_reg_field_value(value, audio_info->port_id[1],
634 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO3,
635 PORT_ID1);
636
637 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO3, value);
638
639
640
641 value = 0;
642 set_reg_field_value(value, audio_info->display_name[0],
643 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO4,
644 DESCRIPTION0);
645
646 set_reg_field_value(value, audio_info->display_name[1],
647 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO4,
648 DESCRIPTION1);
649
650 set_reg_field_value(value, audio_info->display_name[2],
651 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO4,
652 DESCRIPTION2);
653
654 set_reg_field_value(value, audio_info->display_name[3],
655 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO4,
656 DESCRIPTION3);
657
658 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO4, value);
659
660 value = 0;
661 set_reg_field_value(value, audio_info->display_name[4],
662 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO5,
663 DESCRIPTION4);
664
665 set_reg_field_value(value, audio_info->display_name[5],
666 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO5,
667 DESCRIPTION5);
668
669 set_reg_field_value(value, audio_info->display_name[6],
670 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO5,
671 DESCRIPTION6);
672
673 set_reg_field_value(value, audio_info->display_name[7],
674 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO5,
675 DESCRIPTION7);
676
677 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO5, value);
678
679 value = 0;
680 set_reg_field_value(value, audio_info->display_name[8],
681 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO6,
682 DESCRIPTION8);
683
684 set_reg_field_value(value, audio_info->display_name[9],
685 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO6,
686 DESCRIPTION9);
687
688 set_reg_field_value(value, audio_info->display_name[10],
689 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO6,
690 DESCRIPTION10);
691
692 set_reg_field_value(value, audio_info->display_name[11],
693 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO6,
694 DESCRIPTION11);
695
696 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO6, value);
697
698 value = 0;
699 set_reg_field_value(value, audio_info->display_name[12],
700 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO7,
701 DESCRIPTION12);
702
703 set_reg_field_value(value, audio_info->display_name[13],
704 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO7,
705 DESCRIPTION13);
706
707 set_reg_field_value(value, audio_info->display_name[14],
708 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO7,
709 DESCRIPTION14);
710
711 set_reg_field_value(value, audio_info->display_name[15],
712 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO7,
713 DESCRIPTION15);
714
715 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO7, value);
716
717 value = 0;
718 set_reg_field_value(value, audio_info->display_name[16],
719 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO8,
720 DESCRIPTION16);
721
722 set_reg_field_value(value, audio_info->display_name[17],
723 AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO8,
724 DESCRIPTION17);
725
726 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_SINK_INFO8, value);
727 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL);
728 set_reg_field_value(value, 0,
729 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
730 CLOCK_GATING_DISABLE);
731 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
732}
733
734
735
736
737
738
739static void get_azalia_clock_info_hdmi(
740 uint32_t crtc_pixel_clock_100hz,
741 uint32_t actual_pixel_clock_100Hz,
742 struct azalia_clock_info *azalia_clock_info)
743{
744
745
746 azalia_clock_info->audio_dto_phase =
747 24 * 10000;
748
749
750
751 azalia_clock_info->audio_dto_module =
752 actual_pixel_clock_100Hz;
753}
754
755static void get_azalia_clock_info_dp(
756 uint32_t requested_pixel_clock_100Hz,
757 const struct audio_pll_info *pll_info,
758 struct azalia_clock_info *azalia_clock_info)
759{
760
761
762
763
764
765
766
767 azalia_clock_info->audio_dto_phase = 24 * 10000;
768
769
770
771 azalia_clock_info->audio_dto_module =
772 pll_info->dp_dto_source_clock_in_khz * 10;
773}
774
775void dce_aud_wall_dto_setup(
776 struct audio *audio,
777 enum signal_type signal,
778 const struct audio_crtc_info *crtc_info,
779 const struct audio_pll_info *pll_info)
780{
781 struct dce_audio *aud = DCE_AUD(audio);
782
783 struct azalia_clock_info clock_info = { 0 };
784
785 if (dc_is_hdmi_tmds_signal(signal)) {
786 uint32_t src_sel;
787
788
789
790
791
792
793
794 get_azalia_clock_info_hdmi(
795 crtc_info->requested_pixel_clock_100Hz,
796 crtc_info->calculated_pixel_clock_100Hz,
797 &clock_info);
798
799 DC_LOG_HW_AUDIO("\n%s:Input::requested_pixel_clock_100Hz = %d"\
800 "calculated_pixel_clock_100Hz =%d\n"\
801 "audio_dto_module = %d audio_dto_phase =%d \n\n", __func__,\
802 crtc_info->requested_pixel_clock_100Hz,\
803 crtc_info->calculated_pixel_clock_100Hz,\
804 clock_info.audio_dto_module,\
805 clock_info.audio_dto_phase);
806
807
808
809
810
811
812
813
814
815 src_sel = pll_info->dto_source - DTO_SOURCE_ID0;
816 REG_UPDATE_2(DCCG_AUDIO_DTO_SOURCE,
817 DCCG_AUDIO_DTO0_SOURCE_SEL, src_sel,
818 DCCG_AUDIO_DTO_SEL, 0);
819
820
821 REG_UPDATE(DCCG_AUDIO_DTO0_MODULE,
822 DCCG_AUDIO_DTO0_MODULE, clock_info.audio_dto_module);
823
824
825 REG_UPDATE(DCCG_AUDIO_DTO0_PHASE,
826 DCCG_AUDIO_DTO0_PHASE, clock_info.audio_dto_phase);
827 } else {
828
829
830
831
832
833
834
835 get_azalia_clock_info_dp(
836 crtc_info->requested_pixel_clock_100Hz,
837 pll_info,
838 &clock_info);
839
840
841
842
843 REG_UPDATE(DCCG_AUDIO_DTO_SOURCE,
844 DCCG_AUDIO_DTO_SEL, 1);
845
846
847
848
849
850
851
852
853 REG_UPDATE(DCCG_AUDIO_DTO1_MODULE,
854 DCCG_AUDIO_DTO1_MODULE, clock_info.audio_dto_module);
855
856
857 REG_UPDATE(DCCG_AUDIO_DTO1_PHASE,
858 DCCG_AUDIO_DTO1_PHASE, clock_info.audio_dto_phase);
859
860 REG_UPDATE(DCCG_AUDIO_DTO_SOURCE,
861 DCCG_AUDIO_DTO2_USE_512FBR_DTO, 1);
862
863 }
864}
865
866#if defined(CONFIG_DRM_AMD_DC_SI)
867static void dce60_aud_wall_dto_setup(
868 struct audio *audio,
869 enum signal_type signal,
870 const struct audio_crtc_info *crtc_info,
871 const struct audio_pll_info *pll_info)
872{
873 struct dce_audio *aud = DCE_AUD(audio);
874
875 struct azalia_clock_info clock_info = { 0 };
876
877 if (dc_is_hdmi_signal(signal)) {
878 uint32_t src_sel;
879
880
881
882
883
884
885
886 get_azalia_clock_info_hdmi(
887 crtc_info->requested_pixel_clock_100Hz,
888 crtc_info->calculated_pixel_clock_100Hz,
889 &clock_info);
890
891 DC_LOG_HW_AUDIO("\n%s:Input::requested_pixel_clock_100Hz = %d"\
892 "calculated_pixel_clock_100Hz =%d\n"\
893 "audio_dto_module = %d audio_dto_phase =%d \n\n", __func__,\
894 crtc_info->requested_pixel_clock_100Hz,\
895 crtc_info->calculated_pixel_clock_100Hz,\
896 clock_info.audio_dto_module,\
897 clock_info.audio_dto_phase);
898
899
900
901
902
903
904
905
906
907 src_sel = pll_info->dto_source - DTO_SOURCE_ID0;
908 REG_UPDATE_2(DCCG_AUDIO_DTO_SOURCE,
909 DCCG_AUDIO_DTO0_SOURCE_SEL, src_sel,
910 DCCG_AUDIO_DTO_SEL, 0);
911
912
913 REG_UPDATE(DCCG_AUDIO_DTO0_MODULE,
914 DCCG_AUDIO_DTO0_MODULE, clock_info.audio_dto_module);
915
916
917 REG_UPDATE(DCCG_AUDIO_DTO0_PHASE,
918 DCCG_AUDIO_DTO0_PHASE, clock_info.audio_dto_phase);
919 } else {
920
921
922
923
924
925
926
927 get_azalia_clock_info_dp(
928 crtc_info->requested_pixel_clock_100Hz,
929 pll_info,
930 &clock_info);
931
932
933
934
935 REG_UPDATE(DCCG_AUDIO_DTO_SOURCE,
936 DCCG_AUDIO_DTO_SEL, 1);
937
938
939
940
941
942
943
944
945 REG_UPDATE(DCCG_AUDIO_DTO1_MODULE,
946 DCCG_AUDIO_DTO1_MODULE, clock_info.audio_dto_module);
947
948
949 REG_UPDATE(DCCG_AUDIO_DTO1_PHASE,
950 DCCG_AUDIO_DTO1_PHASE, clock_info.audio_dto_phase);
951
952
953
954 }
955}
956#endif
957
958static bool dce_aud_endpoint_valid(struct audio *audio)
959{
960 uint32_t value;
961 uint32_t port_connectivity;
962
963 value = AZ_REG_READ(
964 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
965
966 port_connectivity = get_reg_field_value(value,
967 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT,
968 PORT_CONNECTIVITY);
969
970 return !(port_connectivity == 1);
971}
972
973
974void dce_aud_hw_init(
975 struct audio *audio)
976{
977 uint32_t value;
978 struct dce_audio *aud = DCE_AUD(audio);
979
980
981
982 if (audio->inst != 0)
983 return;
984
985
986
987
988
989
990 value = AZ_REG_READ(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL);
991 set_reg_field_value(value, 1,
992 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
993 CLOCK_GATING_DISABLE);
994 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
995 REG_UPDATE(AZALIA_F0_CODEC_FUNCTION_PARAMETER_SUPPORTED_SIZE_RATES,
996 AUDIO_RATE_CAPABILITIES, 0x70);
997
998
999 REG_UPDATE_2(AZALIA_F0_CODEC_FUNCTION_PARAMETER_POWER_STATES,
1000 CLKSTOP, 1,
1001 EPSS, 1);
1002 set_reg_field_value(value, 0,
1003 AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
1004 CLOCK_GATING_DISABLE);
1005 AZ_REG_WRITE(AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, value);
1006}
1007
1008static const struct audio_funcs funcs = {
1009 .endpoint_valid = dce_aud_endpoint_valid,
1010 .hw_init = dce_aud_hw_init,
1011 .wall_dto_setup = dce_aud_wall_dto_setup,
1012 .az_enable = dce_aud_az_enable,
1013 .az_disable = dce_aud_az_disable,
1014 .az_configure = dce_aud_az_configure,
1015 .destroy = dce_aud_destroy,
1016};
1017
1018#if defined(CONFIG_DRM_AMD_DC_SI)
1019static const struct audio_funcs dce60_funcs = {
1020 .endpoint_valid = dce_aud_endpoint_valid,
1021 .hw_init = dce_aud_hw_init,
1022 .wall_dto_setup = dce60_aud_wall_dto_setup,
1023 .az_enable = dce_aud_az_enable,
1024 .az_disable = dce_aud_az_disable,
1025 .az_configure = dce_aud_az_configure,
1026 .destroy = dce_aud_destroy,
1027};
1028#endif
1029
1030void dce_aud_destroy(struct audio **audio)
1031{
1032 struct dce_audio *aud = DCE_AUD(*audio);
1033
1034 kfree(aud);
1035 *audio = NULL;
1036}
1037
1038struct audio *dce_audio_create(
1039 struct dc_context *ctx,
1040 unsigned int inst,
1041 const struct dce_audio_registers *reg,
1042 const struct dce_audio_shift *shifts,
1043 const struct dce_audio_mask *masks
1044 )
1045{
1046 struct dce_audio *audio = kzalloc(sizeof(*audio), GFP_KERNEL);
1047
1048 if (audio == NULL) {
1049 ASSERT_CRITICAL(audio);
1050 return NULL;
1051 }
1052
1053 audio->base.ctx = ctx;
1054 audio->base.inst = inst;
1055 audio->base.funcs = &funcs;
1056
1057 audio->regs = reg;
1058 audio->shifts = shifts;
1059 audio->masks = masks;
1060 return &audio->base;
1061}
1062
1063#if defined(CONFIG_DRM_AMD_DC_SI)
1064struct audio *dce60_audio_create(
1065 struct dc_context *ctx,
1066 unsigned int inst,
1067 const struct dce_audio_registers *reg,
1068 const struct dce_audio_shift *shifts,
1069 const struct dce_audio_mask *masks
1070 )
1071{
1072 struct dce_audio *audio = kzalloc(sizeof(*audio), GFP_KERNEL);
1073
1074 if (audio == NULL) {
1075 ASSERT_CRITICAL(audio);
1076 return NULL;
1077 }
1078
1079 audio->base.ctx = ctx;
1080 audio->base.inst = inst;
1081 audio->base.funcs = &dce60_funcs;
1082
1083 audio->regs = reg;
1084 audio->shifts = shifts;
1085 audio->masks = masks;
1086 return &audio->base;
1087}
1088#endif
1089