2 * Copyright 2019 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.
27 #include "dc_bios_types.h"
28 #include "hw_shared.h"
29 #include "dcn31_apg.h"
30 #include "reg_helper.h"
33 apg31->base.ctx->logger
39 #define FN(reg_name, field_name) \
40 apg31->apg_shift->field_name, apg31->apg_mask->field_name
47 static void apg31_enable(
50 struct dcn31_apg *apg31 = DCN31_APG_FROM_APG(apg);
53 REG_UPDATE(APG_CONTROL, APG_RESET, 1);
57 REG_UPDATE(APG_CONTROL, APG_RESET, 0);
63 REG_UPDATE(APG_CONTROL2, APG_ENABLE, 1);
66 static void apg31_disable(
69 struct dcn31_apg *apg31 = DCN31_APG_FROM_APG(apg);
72 REG_UPDATE(APG_CONTROL2, APG_ENABLE, 0);
75 static union audio_cea_channels speakers_to_channels(
76 struct audio_speaker_flags speaker_flags)
78 union audio_cea_channels cea_channels = {0};
80 /* these are one to one */
81 cea_channels.channels.FL = speaker_flags.FL_FR;
82 cea_channels.channels.FR = speaker_flags.FL_FR;
83 cea_channels.channels.LFE = speaker_flags.LFE;
84 cea_channels.channels.FC = speaker_flags.FC;
86 /* if Rear Left and Right exist move RC speaker to channel 7
87 * otherwise to channel 5
89 if (speaker_flags.RL_RR) {
90 cea_channels.channels.RL_RC = speaker_flags.RL_RR;
91 cea_channels.channels.RR = speaker_flags.RL_RR;
92 cea_channels.channels.RC_RLC_FLC = speaker_flags.RC;
94 cea_channels.channels.RL_RC = speaker_flags.RC;
97 /* FRONT Left Right Center and REAR Left Right Center are exclusive */
98 if (speaker_flags.FLC_FRC) {
99 cea_channels.channels.RC_RLC_FLC = speaker_flags.FLC_FRC;
100 cea_channels.channels.RRC_FRC = speaker_flags.FLC_FRC;
102 cea_channels.channels.RC_RLC_FLC = speaker_flags.RLC_RRC;
103 cea_channels.channels.RRC_FRC = speaker_flags.RLC_RRC;
109 static void apg31_se_audio_setup(
111 unsigned int az_inst,
112 struct audio_info *audio_info)
114 struct dcn31_apg *apg31 = DCN31_APG_FROM_APG(apg);
116 uint32_t speakers = 0;
117 uint32_t channels = 0;
120 /* This should not happen.it does so we don't get BSOD*/
121 if (audio_info == NULL)
124 speakers = audio_info->flags.info.ALLSPEAKERS;
125 channels = speakers_to_channels(audio_info->flags.speaker_flags).all;
127 /* DisplayPort only allows for one audio stream with stream ID 0 */
128 REG_UPDATE(APG_CONTROL2, APG_DP_AUDIO_STREAM_ID, 0);
130 /* When running in "pair mode", pairs of audio channels have their own enable
131 * this is for really old audio drivers */
132 REG_UPDATE(APG_DBG_GEN_CONTROL, APG_DBG_AUDIO_CHANNEL_ENABLE, 0xF);
133 // REG_UPDATE(APG_DBG_GEN_CONTROL, APG_DBG_AUDIO_CHANNEL_ENABLE, channels);
135 /* Disable forced mem power off */
136 REG_UPDATE(APG_MEM_PWR, APG_MEM_PWR_FORCE, 0);
141 static void apg31_audio_mute_control(
151 static struct apg_funcs dcn31_apg_funcs = {
152 .se_audio_setup = apg31_se_audio_setup,
153 .audio_mute_control = apg31_audio_mute_control,
154 .enable_apg = apg31_enable,
155 .disable_apg = apg31_disable,
158 void apg31_construct(struct dcn31_apg *apg31,
159 struct dc_context *ctx,
161 const struct dcn31_apg_registers *apg_regs,
162 const struct dcn31_apg_shift *apg_shift,
163 const struct dcn31_apg_mask *apg_mask)
165 apg31->base.ctx = ctx;
167 apg31->base.inst = inst;
168 apg31->base.funcs = &dcn31_apg_funcs;
170 apg31->regs = apg_regs;
171 apg31->apg_shift = apg_shift;
172 apg31->apg_mask = apg_mask;