1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev * Copyright 2012-15 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev *
4*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev *
11*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev *
14*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev *
22*b843c749SSergey Zigachev * Authors: AMD
23*b843c749SSergey Zigachev *
24*b843c749SSergey Zigachev */
25*b843c749SSergey Zigachev
26*b843c749SSergey Zigachev #include "reg_helper.h"
27*b843c749SSergey Zigachev #include "dcn10_mpc.h"
28*b843c749SSergey Zigachev
29*b843c749SSergey Zigachev #define REG(reg)\
30*b843c749SSergey Zigachev mpc10->mpc_regs->reg
31*b843c749SSergey Zigachev
32*b843c749SSergey Zigachev #define CTX \
33*b843c749SSergey Zigachev mpc10->base.ctx
34*b843c749SSergey Zigachev
35*b843c749SSergey Zigachev #undef FN
36*b843c749SSergey Zigachev #define FN(reg_name, field_name) \
37*b843c749SSergey Zigachev mpc10->mpc_shift->field_name, mpc10->mpc_mask->field_name
38*b843c749SSergey Zigachev
39*b843c749SSergey Zigachev
mpc1_set_bg_color(struct mpc * mpc,struct tg_color * bg_color,int mpcc_id)40*b843c749SSergey Zigachev void mpc1_set_bg_color(struct mpc *mpc,
41*b843c749SSergey Zigachev struct tg_color *bg_color,
42*b843c749SSergey Zigachev int mpcc_id)
43*b843c749SSergey Zigachev {
44*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
45*b843c749SSergey Zigachev
46*b843c749SSergey Zigachev /* mpc color is 12 bit. tg_color is 10 bit */
47*b843c749SSergey Zigachev /* todo: might want to use 16 bit to represent color and have each
48*b843c749SSergey Zigachev * hw block translate to correct color depth.
49*b843c749SSergey Zigachev */
50*b843c749SSergey Zigachev uint32_t bg_r_cr = bg_color->color_r_cr << 2;
51*b843c749SSergey Zigachev uint32_t bg_g_y = bg_color->color_g_y << 2;
52*b843c749SSergey Zigachev uint32_t bg_b_cb = bg_color->color_b_cb << 2;
53*b843c749SSergey Zigachev
54*b843c749SSergey Zigachev REG_SET(MPCC_BG_R_CR[mpcc_id], 0,
55*b843c749SSergey Zigachev MPCC_BG_R_CR, bg_r_cr);
56*b843c749SSergey Zigachev REG_SET(MPCC_BG_G_Y[mpcc_id], 0,
57*b843c749SSergey Zigachev MPCC_BG_G_Y, bg_g_y);
58*b843c749SSergey Zigachev REG_SET(MPCC_BG_B_CB[mpcc_id], 0,
59*b843c749SSergey Zigachev MPCC_BG_B_CB, bg_b_cb);
60*b843c749SSergey Zigachev }
61*b843c749SSergey Zigachev
mpc1_update_blending(struct mpc * mpc,struct mpcc_blnd_cfg * blnd_cfg,int mpcc_id)62*b843c749SSergey Zigachev static void mpc1_update_blending(
63*b843c749SSergey Zigachev struct mpc *mpc,
64*b843c749SSergey Zigachev struct mpcc_blnd_cfg *blnd_cfg,
65*b843c749SSergey Zigachev int mpcc_id)
66*b843c749SSergey Zigachev {
67*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
68*b843c749SSergey Zigachev struct mpcc *mpcc = mpc1_get_mpcc(mpc, mpcc_id);
69*b843c749SSergey Zigachev
70*b843c749SSergey Zigachev REG_UPDATE_5(MPCC_CONTROL[mpcc_id],
71*b843c749SSergey Zigachev MPCC_ALPHA_BLND_MODE, blnd_cfg->alpha_mode,
72*b843c749SSergey Zigachev MPCC_ALPHA_MULTIPLIED_MODE, blnd_cfg->pre_multiplied_alpha,
73*b843c749SSergey Zigachev MPCC_BLND_ACTIVE_OVERLAP_ONLY, blnd_cfg->overlap_only,
74*b843c749SSergey Zigachev MPCC_GLOBAL_ALPHA, blnd_cfg->global_alpha,
75*b843c749SSergey Zigachev MPCC_GLOBAL_GAIN, blnd_cfg->global_gain);
76*b843c749SSergey Zigachev
77*b843c749SSergey Zigachev mpc1_set_bg_color(mpc, &blnd_cfg->black_color, mpcc_id);
78*b843c749SSergey Zigachev mpcc->blnd_cfg = *blnd_cfg;
79*b843c749SSergey Zigachev }
80*b843c749SSergey Zigachev
mpc1_update_stereo_mix(struct mpc * mpc,struct mpcc_sm_cfg * sm_cfg,int mpcc_id)81*b843c749SSergey Zigachev void mpc1_update_stereo_mix(
82*b843c749SSergey Zigachev struct mpc *mpc,
83*b843c749SSergey Zigachev struct mpcc_sm_cfg *sm_cfg,
84*b843c749SSergey Zigachev int mpcc_id)
85*b843c749SSergey Zigachev {
86*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
87*b843c749SSergey Zigachev
88*b843c749SSergey Zigachev REG_UPDATE_6(MPCC_SM_CONTROL[mpcc_id],
89*b843c749SSergey Zigachev MPCC_SM_EN, sm_cfg->enable,
90*b843c749SSergey Zigachev MPCC_SM_MODE, sm_cfg->sm_mode,
91*b843c749SSergey Zigachev MPCC_SM_FRAME_ALT, sm_cfg->frame_alt,
92*b843c749SSergey Zigachev MPCC_SM_FIELD_ALT, sm_cfg->field_alt,
93*b843c749SSergey Zigachev MPCC_SM_FORCE_NEXT_FRAME_POL, sm_cfg->force_next_frame_porlarity,
94*b843c749SSergey Zigachev MPCC_SM_FORCE_NEXT_TOP_POL, sm_cfg->force_next_field_polarity);
95*b843c749SSergey Zigachev }
mpc1_assert_idle_mpcc(struct mpc * mpc,int id)96*b843c749SSergey Zigachev void mpc1_assert_idle_mpcc(struct mpc *mpc, int id)
97*b843c749SSergey Zigachev {
98*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
99*b843c749SSergey Zigachev
100*b843c749SSergey Zigachev ASSERT(!(mpc10->mpcc_in_use_mask & 1 << id));
101*b843c749SSergey Zigachev REG_WAIT(MPCC_STATUS[id],
102*b843c749SSergey Zigachev MPCC_IDLE, 1,
103*b843c749SSergey Zigachev 1, 100000);
104*b843c749SSergey Zigachev }
105*b843c749SSergey Zigachev
mpc1_get_mpcc(struct mpc * mpc,int mpcc_id)106*b843c749SSergey Zigachev struct mpcc *mpc1_get_mpcc(struct mpc *mpc, int mpcc_id)
107*b843c749SSergey Zigachev {
108*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
109*b843c749SSergey Zigachev
110*b843c749SSergey Zigachev ASSERT(mpcc_id < mpc10->num_mpcc);
111*b843c749SSergey Zigachev return &(mpc->mpcc_array[mpcc_id]);
112*b843c749SSergey Zigachev }
113*b843c749SSergey Zigachev
mpc1_get_mpcc_for_dpp(struct mpc_tree * tree,int dpp_id)114*b843c749SSergey Zigachev struct mpcc *mpc1_get_mpcc_for_dpp(struct mpc_tree *tree, int dpp_id)
115*b843c749SSergey Zigachev {
116*b843c749SSergey Zigachev struct mpcc *tmp_mpcc = tree->opp_list;
117*b843c749SSergey Zigachev
118*b843c749SSergey Zigachev while (tmp_mpcc != NULL) {
119*b843c749SSergey Zigachev if (tmp_mpcc->dpp_id == dpp_id)
120*b843c749SSergey Zigachev return tmp_mpcc;
121*b843c749SSergey Zigachev tmp_mpcc = tmp_mpcc->mpcc_bot;
122*b843c749SSergey Zigachev }
123*b843c749SSergey Zigachev return NULL;
124*b843c749SSergey Zigachev }
125*b843c749SSergey Zigachev
mpc1_is_mpcc_idle(struct mpc * mpc,int mpcc_id)126*b843c749SSergey Zigachev bool mpc1_is_mpcc_idle(struct mpc *mpc, int mpcc_id)
127*b843c749SSergey Zigachev {
128*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
129*b843c749SSergey Zigachev unsigned int top_sel;
130*b843c749SSergey Zigachev unsigned int opp_id;
131*b843c749SSergey Zigachev unsigned int idle;
132*b843c749SSergey Zigachev
133*b843c749SSergey Zigachev REG_GET(MPCC_TOP_SEL[mpcc_id], MPCC_TOP_SEL, &top_sel);
134*b843c749SSergey Zigachev REG_GET(MPCC_OPP_ID[mpcc_id], MPCC_OPP_ID, &opp_id);
135*b843c749SSergey Zigachev REG_GET(MPCC_STATUS[mpcc_id], MPCC_IDLE, &idle);
136*b843c749SSergey Zigachev if (top_sel == 0xf && opp_id == 0xf && idle)
137*b843c749SSergey Zigachev return true;
138*b843c749SSergey Zigachev else
139*b843c749SSergey Zigachev return false;
140*b843c749SSergey Zigachev }
141*b843c749SSergey Zigachev
mpc1_assert_mpcc_idle_before_connect(struct mpc * mpc,int mpcc_id)142*b843c749SSergey Zigachev void mpc1_assert_mpcc_idle_before_connect(struct mpc *mpc, int mpcc_id)
143*b843c749SSergey Zigachev {
144*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
145*b843c749SSergey Zigachev unsigned int top_sel, mpc_busy, mpc_idle;
146*b843c749SSergey Zigachev
147*b843c749SSergey Zigachev REG_GET(MPCC_TOP_SEL[mpcc_id],
148*b843c749SSergey Zigachev MPCC_TOP_SEL, &top_sel);
149*b843c749SSergey Zigachev
150*b843c749SSergey Zigachev if (top_sel == 0xf) {
151*b843c749SSergey Zigachev REG_GET_2(MPCC_STATUS[mpcc_id],
152*b843c749SSergey Zigachev MPCC_BUSY, &mpc_busy,
153*b843c749SSergey Zigachev MPCC_IDLE, &mpc_idle);
154*b843c749SSergey Zigachev
155*b843c749SSergey Zigachev ASSERT(mpc_busy == 0);
156*b843c749SSergey Zigachev ASSERT(mpc_idle == 1);
157*b843c749SSergey Zigachev }
158*b843c749SSergey Zigachev }
159*b843c749SSergey Zigachev
160*b843c749SSergey Zigachev /*
161*b843c749SSergey Zigachev * Insert DPP into MPC tree based on specified blending position.
162*b843c749SSergey Zigachev * Only used for planes that are part of blending chain for OPP output
163*b843c749SSergey Zigachev *
164*b843c749SSergey Zigachev * Parameters:
165*b843c749SSergey Zigachev * [in/out] mpc - MPC context.
166*b843c749SSergey Zigachev * [in/out] tree - MPC tree structure that plane will be added to.
167*b843c749SSergey Zigachev * [in] blnd_cfg - MPCC blending configuration for the new blending layer.
168*b843c749SSergey Zigachev * [in] sm_cfg - MPCC stereo mix configuration for the new blending layer.
169*b843c749SSergey Zigachev * stereo mix must disable for the very bottom layer of the tree config.
170*b843c749SSergey Zigachev * [in] insert_above_mpcc - Insert new plane above this MPCC. If NULL, insert as bottom plane.
171*b843c749SSergey Zigachev * [in] dpp_id - DPP instance for the plane to be added.
172*b843c749SSergey Zigachev * [in] mpcc_id - The MPCC physical instance to use for blending.
173*b843c749SSergey Zigachev *
174*b843c749SSergey Zigachev * Return: struct mpcc* - MPCC that was added.
175*b843c749SSergey Zigachev */
mpc1_insert_plane(struct mpc * mpc,struct mpc_tree * tree,struct mpcc_blnd_cfg * blnd_cfg,struct mpcc_sm_cfg * sm_cfg,struct mpcc * insert_above_mpcc,int dpp_id,int mpcc_id)176*b843c749SSergey Zigachev struct mpcc *mpc1_insert_plane(
177*b843c749SSergey Zigachev struct mpc *mpc,
178*b843c749SSergey Zigachev struct mpc_tree *tree,
179*b843c749SSergey Zigachev struct mpcc_blnd_cfg *blnd_cfg,
180*b843c749SSergey Zigachev struct mpcc_sm_cfg *sm_cfg,
181*b843c749SSergey Zigachev struct mpcc *insert_above_mpcc,
182*b843c749SSergey Zigachev int dpp_id,
183*b843c749SSergey Zigachev int mpcc_id)
184*b843c749SSergey Zigachev {
185*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
186*b843c749SSergey Zigachev struct mpcc *new_mpcc = NULL;
187*b843c749SSergey Zigachev
188*b843c749SSergey Zigachev /* sanity check parameters */
189*b843c749SSergey Zigachev ASSERT(mpcc_id < mpc10->num_mpcc);
190*b843c749SSergey Zigachev ASSERT(!(mpc10->mpcc_in_use_mask & 1 << mpcc_id));
191*b843c749SSergey Zigachev
192*b843c749SSergey Zigachev if (insert_above_mpcc) {
193*b843c749SSergey Zigachev /* check insert_above_mpcc exist in tree->opp_list */
194*b843c749SSergey Zigachev struct mpcc *temp_mpcc = tree->opp_list;
195*b843c749SSergey Zigachev
196*b843c749SSergey Zigachev while (temp_mpcc && temp_mpcc->mpcc_bot != insert_above_mpcc)
197*b843c749SSergey Zigachev temp_mpcc = temp_mpcc->mpcc_bot;
198*b843c749SSergey Zigachev if (temp_mpcc == NULL)
199*b843c749SSergey Zigachev return NULL;
200*b843c749SSergey Zigachev }
201*b843c749SSergey Zigachev
202*b843c749SSergey Zigachev /* Get and update MPCC struct parameters */
203*b843c749SSergey Zigachev new_mpcc = mpc1_get_mpcc(mpc, mpcc_id);
204*b843c749SSergey Zigachev new_mpcc->dpp_id = dpp_id;
205*b843c749SSergey Zigachev
206*b843c749SSergey Zigachev /* program mux and MPCC_MODE */
207*b843c749SSergey Zigachev if (insert_above_mpcc) {
208*b843c749SSergey Zigachev new_mpcc->mpcc_bot = insert_above_mpcc;
209*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[mpcc_id], 0, MPCC_BOT_SEL, insert_above_mpcc->mpcc_id);
210*b843c749SSergey Zigachev REG_UPDATE(MPCC_CONTROL[mpcc_id], MPCC_MODE, MPCC_BLEND_MODE_TOP_BOT_BLENDING);
211*b843c749SSergey Zigachev } else {
212*b843c749SSergey Zigachev new_mpcc->mpcc_bot = NULL;
213*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[mpcc_id], 0, MPCC_BOT_SEL, 0xf);
214*b843c749SSergey Zigachev REG_UPDATE(MPCC_CONTROL[mpcc_id], MPCC_MODE, MPCC_BLEND_MODE_TOP_LAYER_PASSTHROUGH);
215*b843c749SSergey Zigachev }
216*b843c749SSergey Zigachev REG_SET(MPCC_TOP_SEL[mpcc_id], 0, MPCC_TOP_SEL, dpp_id);
217*b843c749SSergey Zigachev REG_SET(MPCC_OPP_ID[mpcc_id], 0, MPCC_OPP_ID, tree->opp_id);
218*b843c749SSergey Zigachev
219*b843c749SSergey Zigachev /* update mpc tree mux setting */
220*b843c749SSergey Zigachev if (tree->opp_list == insert_above_mpcc) {
221*b843c749SSergey Zigachev /* insert the toppest mpcc */
222*b843c749SSergey Zigachev tree->opp_list = new_mpcc;
223*b843c749SSergey Zigachev REG_UPDATE(MUX[tree->opp_id], MPC_OUT_MUX, mpcc_id);
224*b843c749SSergey Zigachev } else {
225*b843c749SSergey Zigachev /* find insert position */
226*b843c749SSergey Zigachev struct mpcc *temp_mpcc = tree->opp_list;
227*b843c749SSergey Zigachev
228*b843c749SSergey Zigachev while (temp_mpcc && temp_mpcc->mpcc_bot != insert_above_mpcc)
229*b843c749SSergey Zigachev temp_mpcc = temp_mpcc->mpcc_bot;
230*b843c749SSergey Zigachev if (temp_mpcc && temp_mpcc->mpcc_bot == insert_above_mpcc) {
231*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[temp_mpcc->mpcc_id], 0, MPCC_BOT_SEL, mpcc_id);
232*b843c749SSergey Zigachev temp_mpcc->mpcc_bot = new_mpcc;
233*b843c749SSergey Zigachev if (!insert_above_mpcc)
234*b843c749SSergey Zigachev REG_UPDATE(MPCC_CONTROL[temp_mpcc->mpcc_id],
235*b843c749SSergey Zigachev MPCC_MODE, MPCC_BLEND_MODE_TOP_BOT_BLENDING);
236*b843c749SSergey Zigachev }
237*b843c749SSergey Zigachev }
238*b843c749SSergey Zigachev
239*b843c749SSergey Zigachev /* update the blending configuration */
240*b843c749SSergey Zigachev mpc->funcs->update_blending(mpc, blnd_cfg, mpcc_id);
241*b843c749SSergey Zigachev
242*b843c749SSergey Zigachev /* update the stereo mix settings, if provided */
243*b843c749SSergey Zigachev if (sm_cfg != NULL) {
244*b843c749SSergey Zigachev new_mpcc->sm_cfg = *sm_cfg;
245*b843c749SSergey Zigachev mpc1_update_stereo_mix(mpc, sm_cfg, mpcc_id);
246*b843c749SSergey Zigachev }
247*b843c749SSergey Zigachev
248*b843c749SSergey Zigachev /* mark this mpcc as in use */
249*b843c749SSergey Zigachev mpc10->mpcc_in_use_mask |= 1 << mpcc_id;
250*b843c749SSergey Zigachev
251*b843c749SSergey Zigachev return new_mpcc;
252*b843c749SSergey Zigachev }
253*b843c749SSergey Zigachev
254*b843c749SSergey Zigachev /*
255*b843c749SSergey Zigachev * Remove a specified MPCC from the MPC tree.
256*b843c749SSergey Zigachev *
257*b843c749SSergey Zigachev * Parameters:
258*b843c749SSergey Zigachev * [in/out] mpc - MPC context.
259*b843c749SSergey Zigachev * [in/out] tree - MPC tree structure that plane will be removed from.
260*b843c749SSergey Zigachev * [in/out] mpcc - MPCC to be removed from tree.
261*b843c749SSergey Zigachev *
262*b843c749SSergey Zigachev * Return: void
263*b843c749SSergey Zigachev */
mpc1_remove_mpcc(struct mpc * mpc,struct mpc_tree * tree,struct mpcc * mpcc_to_remove)264*b843c749SSergey Zigachev void mpc1_remove_mpcc(
265*b843c749SSergey Zigachev struct mpc *mpc,
266*b843c749SSergey Zigachev struct mpc_tree *tree,
267*b843c749SSergey Zigachev struct mpcc *mpcc_to_remove)
268*b843c749SSergey Zigachev {
269*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
270*b843c749SSergey Zigachev bool found = false;
271*b843c749SSergey Zigachev int mpcc_id = mpcc_to_remove->mpcc_id;
272*b843c749SSergey Zigachev
273*b843c749SSergey Zigachev if (tree->opp_list == mpcc_to_remove) {
274*b843c749SSergey Zigachev found = true;
275*b843c749SSergey Zigachev /* remove MPCC from top of tree */
276*b843c749SSergey Zigachev if (mpcc_to_remove->mpcc_bot) {
277*b843c749SSergey Zigachev /* set the next MPCC in list to be the top MPCC */
278*b843c749SSergey Zigachev tree->opp_list = mpcc_to_remove->mpcc_bot;
279*b843c749SSergey Zigachev REG_UPDATE(MUX[tree->opp_id], MPC_OUT_MUX, tree->opp_list->mpcc_id);
280*b843c749SSergey Zigachev } else {
281*b843c749SSergey Zigachev /* there are no other MPCC is list */
282*b843c749SSergey Zigachev tree->opp_list = NULL;
283*b843c749SSergey Zigachev REG_UPDATE(MUX[tree->opp_id], MPC_OUT_MUX, 0xf);
284*b843c749SSergey Zigachev }
285*b843c749SSergey Zigachev } else {
286*b843c749SSergey Zigachev /* find mpcc to remove MPCC list */
287*b843c749SSergey Zigachev struct mpcc *temp_mpcc = tree->opp_list;
288*b843c749SSergey Zigachev
289*b843c749SSergey Zigachev while (temp_mpcc && temp_mpcc->mpcc_bot != mpcc_to_remove)
290*b843c749SSergey Zigachev temp_mpcc = temp_mpcc->mpcc_bot;
291*b843c749SSergey Zigachev
292*b843c749SSergey Zigachev if (temp_mpcc && temp_mpcc->mpcc_bot == mpcc_to_remove) {
293*b843c749SSergey Zigachev found = true;
294*b843c749SSergey Zigachev temp_mpcc->mpcc_bot = mpcc_to_remove->mpcc_bot;
295*b843c749SSergey Zigachev if (mpcc_to_remove->mpcc_bot) {
296*b843c749SSergey Zigachev /* remove MPCC in middle of list */
297*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[temp_mpcc->mpcc_id], 0,
298*b843c749SSergey Zigachev MPCC_BOT_SEL, mpcc_to_remove->mpcc_bot->mpcc_id);
299*b843c749SSergey Zigachev } else {
300*b843c749SSergey Zigachev /* remove MPCC from bottom of list */
301*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[temp_mpcc->mpcc_id], 0,
302*b843c749SSergey Zigachev MPCC_BOT_SEL, 0xf);
303*b843c749SSergey Zigachev REG_UPDATE(MPCC_CONTROL[temp_mpcc->mpcc_id],
304*b843c749SSergey Zigachev MPCC_MODE, MPCC_BLEND_MODE_TOP_LAYER_PASSTHROUGH);
305*b843c749SSergey Zigachev }
306*b843c749SSergey Zigachev }
307*b843c749SSergey Zigachev }
308*b843c749SSergey Zigachev
309*b843c749SSergey Zigachev if (found) {
310*b843c749SSergey Zigachev /* turn off MPCC mux registers */
311*b843c749SSergey Zigachev REG_SET(MPCC_TOP_SEL[mpcc_id], 0, MPCC_TOP_SEL, 0xf);
312*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[mpcc_id], 0, MPCC_BOT_SEL, 0xf);
313*b843c749SSergey Zigachev REG_SET(MPCC_OPP_ID[mpcc_id], 0, MPCC_OPP_ID, 0xf);
314*b843c749SSergey Zigachev
315*b843c749SSergey Zigachev /* mark this mpcc as not in use */
316*b843c749SSergey Zigachev mpc10->mpcc_in_use_mask &= ~(1 << mpcc_id);
317*b843c749SSergey Zigachev mpcc_to_remove->dpp_id = 0xf;
318*b843c749SSergey Zigachev mpcc_to_remove->mpcc_bot = NULL;
319*b843c749SSergey Zigachev } else {
320*b843c749SSergey Zigachev /* In case of resume from S3/S4, remove mpcc from bios left over */
321*b843c749SSergey Zigachev REG_SET(MPCC_TOP_SEL[mpcc_id], 0, MPCC_TOP_SEL, 0xf);
322*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[mpcc_id], 0, MPCC_BOT_SEL, 0xf);
323*b843c749SSergey Zigachev REG_SET(MPCC_OPP_ID[mpcc_id], 0, MPCC_OPP_ID, 0xf);
324*b843c749SSergey Zigachev }
325*b843c749SSergey Zigachev }
326*b843c749SSergey Zigachev
mpc1_init_mpcc(struct mpcc * mpcc,int mpcc_inst)327*b843c749SSergey Zigachev static void mpc1_init_mpcc(struct mpcc *mpcc, int mpcc_inst)
328*b843c749SSergey Zigachev {
329*b843c749SSergey Zigachev mpcc->mpcc_id = mpcc_inst;
330*b843c749SSergey Zigachev mpcc->dpp_id = 0xf;
331*b843c749SSergey Zigachev mpcc->mpcc_bot = NULL;
332*b843c749SSergey Zigachev mpcc->blnd_cfg.overlap_only = false;
333*b843c749SSergey Zigachev mpcc->blnd_cfg.global_alpha = 0xff;
334*b843c749SSergey Zigachev mpcc->blnd_cfg.global_gain = 0xff;
335*b843c749SSergey Zigachev mpcc->sm_cfg.enable = false;
336*b843c749SSergey Zigachev }
337*b843c749SSergey Zigachev
338*b843c749SSergey Zigachev /*
339*b843c749SSergey Zigachev * Reset the MPCC HW status by disconnecting all muxes.
340*b843c749SSergey Zigachev *
341*b843c749SSergey Zigachev * Parameters:
342*b843c749SSergey Zigachev * [in/out] mpc - MPC context.
343*b843c749SSergey Zigachev *
344*b843c749SSergey Zigachev * Return: void
345*b843c749SSergey Zigachev */
mpc1_mpc_init(struct mpc * mpc)346*b843c749SSergey Zigachev void mpc1_mpc_init(struct mpc *mpc)
347*b843c749SSergey Zigachev {
348*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
349*b843c749SSergey Zigachev int mpcc_id;
350*b843c749SSergey Zigachev int opp_id;
351*b843c749SSergey Zigachev
352*b843c749SSergey Zigachev mpc10->mpcc_in_use_mask = 0;
353*b843c749SSergey Zigachev for (mpcc_id = 0; mpcc_id < mpc10->num_mpcc; mpcc_id++) {
354*b843c749SSergey Zigachev REG_SET(MPCC_TOP_SEL[mpcc_id], 0, MPCC_TOP_SEL, 0xf);
355*b843c749SSergey Zigachev REG_SET(MPCC_BOT_SEL[mpcc_id], 0, MPCC_BOT_SEL, 0xf);
356*b843c749SSergey Zigachev REG_SET(MPCC_OPP_ID[mpcc_id], 0, MPCC_OPP_ID, 0xf);
357*b843c749SSergey Zigachev
358*b843c749SSergey Zigachev mpc1_init_mpcc(&(mpc->mpcc_array[mpcc_id]), mpcc_id);
359*b843c749SSergey Zigachev }
360*b843c749SSergey Zigachev
361*b843c749SSergey Zigachev for (opp_id = 0; opp_id < MAX_OPP; opp_id++) {
362*b843c749SSergey Zigachev if (REG(MUX[opp_id]))
363*b843c749SSergey Zigachev REG_UPDATE(MUX[opp_id], MPC_OUT_MUX, 0xf);
364*b843c749SSergey Zigachev }
365*b843c749SSergey Zigachev }
366*b843c749SSergey Zigachev
mpc1_init_mpcc_list_from_hw(struct mpc * mpc,struct mpc_tree * tree)367*b843c749SSergey Zigachev void mpc1_init_mpcc_list_from_hw(
368*b843c749SSergey Zigachev struct mpc *mpc,
369*b843c749SSergey Zigachev struct mpc_tree *tree)
370*b843c749SSergey Zigachev {
371*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
372*b843c749SSergey Zigachev unsigned int opp_id;
373*b843c749SSergey Zigachev unsigned int top_sel;
374*b843c749SSergey Zigachev unsigned int bot_sel;
375*b843c749SSergey Zigachev unsigned int out_mux;
376*b843c749SSergey Zigachev struct mpcc *mpcc;
377*b843c749SSergey Zigachev int mpcc_id;
378*b843c749SSergey Zigachev int bot_mpcc_id;
379*b843c749SSergey Zigachev
380*b843c749SSergey Zigachev REG_GET(MUX[tree->opp_id], MPC_OUT_MUX, &out_mux);
381*b843c749SSergey Zigachev
382*b843c749SSergey Zigachev if (out_mux != 0xf) {
383*b843c749SSergey Zigachev for (mpcc_id = 0; mpcc_id < mpc10->num_mpcc; mpcc_id++) {
384*b843c749SSergey Zigachev REG_GET(MPCC_OPP_ID[mpcc_id], MPCC_OPP_ID, &opp_id);
385*b843c749SSergey Zigachev REG_GET(MPCC_TOP_SEL[mpcc_id], MPCC_TOP_SEL, &top_sel);
386*b843c749SSergey Zigachev REG_GET(MPCC_BOT_SEL[mpcc_id], MPCC_BOT_SEL, &bot_sel);
387*b843c749SSergey Zigachev
388*b843c749SSergey Zigachev if (bot_sel == mpcc_id)
389*b843c749SSergey Zigachev bot_sel = 0xf;
390*b843c749SSergey Zigachev
391*b843c749SSergey Zigachev if ((opp_id == tree->opp_id) && (top_sel != 0xf)) {
392*b843c749SSergey Zigachev mpcc = mpc1_get_mpcc(mpc, mpcc_id);
393*b843c749SSergey Zigachev mpcc->dpp_id = top_sel;
394*b843c749SSergey Zigachev mpc10->mpcc_in_use_mask |= 1 << mpcc_id;
395*b843c749SSergey Zigachev
396*b843c749SSergey Zigachev if (out_mux == mpcc_id)
397*b843c749SSergey Zigachev tree->opp_list = mpcc;
398*b843c749SSergey Zigachev if (bot_sel != 0xf && bot_sel < mpc10->num_mpcc) {
399*b843c749SSergey Zigachev bot_mpcc_id = bot_sel;
400*b843c749SSergey Zigachev REG_GET(MPCC_OPP_ID[bot_mpcc_id], MPCC_OPP_ID, &opp_id);
401*b843c749SSergey Zigachev REG_GET(MPCC_TOP_SEL[bot_mpcc_id], MPCC_TOP_SEL, &top_sel);
402*b843c749SSergey Zigachev if ((opp_id == tree->opp_id) && (top_sel != 0xf)) {
403*b843c749SSergey Zigachev struct mpcc *mpcc_bottom = mpc1_get_mpcc(mpc, bot_mpcc_id);
404*b843c749SSergey Zigachev
405*b843c749SSergey Zigachev mpcc->mpcc_bot = mpcc_bottom;
406*b843c749SSergey Zigachev }
407*b843c749SSergey Zigachev }
408*b843c749SSergey Zigachev }
409*b843c749SSergey Zigachev }
410*b843c749SSergey Zigachev }
411*b843c749SSergey Zigachev }
412*b843c749SSergey Zigachev
mpc1_read_mpcc_state(struct mpc * mpc,int mpcc_inst,struct mpcc_state * s)413*b843c749SSergey Zigachev void mpc1_read_mpcc_state(
414*b843c749SSergey Zigachev struct mpc *mpc,
415*b843c749SSergey Zigachev int mpcc_inst,
416*b843c749SSergey Zigachev struct mpcc_state *s)
417*b843c749SSergey Zigachev {
418*b843c749SSergey Zigachev struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
419*b843c749SSergey Zigachev
420*b843c749SSergey Zigachev REG_GET(MPCC_OPP_ID[mpcc_inst], MPCC_OPP_ID, &s->opp_id);
421*b843c749SSergey Zigachev REG_GET(MPCC_TOP_SEL[mpcc_inst], MPCC_TOP_SEL, &s->dpp_id);
422*b843c749SSergey Zigachev REG_GET(MPCC_BOT_SEL[mpcc_inst], MPCC_BOT_SEL, &s->bot_mpcc_id);
423*b843c749SSergey Zigachev REG_GET_4(MPCC_CONTROL[mpcc_inst], MPCC_MODE, &s->mode,
424*b843c749SSergey Zigachev MPCC_ALPHA_BLND_MODE, &s->alpha_mode,
425*b843c749SSergey Zigachev MPCC_ALPHA_MULTIPLIED_MODE, &s->pre_multiplied_alpha,
426*b843c749SSergey Zigachev MPCC_BLND_ACTIVE_OVERLAP_ONLY, &s->overlap_only);
427*b843c749SSergey Zigachev REG_GET_2(MPCC_STATUS[mpcc_inst], MPCC_IDLE, &s->idle,
428*b843c749SSergey Zigachev MPCC_BUSY, &s->busy);
429*b843c749SSergey Zigachev }
430*b843c749SSergey Zigachev
431*b843c749SSergey Zigachev static const struct mpc_funcs dcn10_mpc_funcs = {
432*b843c749SSergey Zigachev .read_mpcc_state = mpc1_read_mpcc_state,
433*b843c749SSergey Zigachev .insert_plane = mpc1_insert_plane,
434*b843c749SSergey Zigachev .remove_mpcc = mpc1_remove_mpcc,
435*b843c749SSergey Zigachev .mpc_init = mpc1_mpc_init,
436*b843c749SSergey Zigachev .get_mpcc_for_dpp = mpc1_get_mpcc_for_dpp,
437*b843c749SSergey Zigachev .wait_for_idle = mpc1_assert_idle_mpcc,
438*b843c749SSergey Zigachev .assert_mpcc_idle_before_connect = mpc1_assert_mpcc_idle_before_connect,
439*b843c749SSergey Zigachev .init_mpcc_list_from_hw = mpc1_init_mpcc_list_from_hw,
440*b843c749SSergey Zigachev .update_blending = mpc1_update_blending,
441*b843c749SSergey Zigachev };
442*b843c749SSergey Zigachev
dcn10_mpc_construct(struct dcn10_mpc * mpc10,struct dc_context * ctx,const struct dcn_mpc_registers * mpc_regs,const struct dcn_mpc_shift * mpc_shift,const struct dcn_mpc_mask * mpc_mask,int num_mpcc)443*b843c749SSergey Zigachev void dcn10_mpc_construct(struct dcn10_mpc *mpc10,
444*b843c749SSergey Zigachev struct dc_context *ctx,
445*b843c749SSergey Zigachev const struct dcn_mpc_registers *mpc_regs,
446*b843c749SSergey Zigachev const struct dcn_mpc_shift *mpc_shift,
447*b843c749SSergey Zigachev const struct dcn_mpc_mask *mpc_mask,
448*b843c749SSergey Zigachev int num_mpcc)
449*b843c749SSergey Zigachev {
450*b843c749SSergey Zigachev int i;
451*b843c749SSergey Zigachev
452*b843c749SSergey Zigachev mpc10->base.ctx = ctx;
453*b843c749SSergey Zigachev
454*b843c749SSergey Zigachev mpc10->base.funcs = &dcn10_mpc_funcs;
455*b843c749SSergey Zigachev
456*b843c749SSergey Zigachev mpc10->mpc_regs = mpc_regs;
457*b843c749SSergey Zigachev mpc10->mpc_shift = mpc_shift;
458*b843c749SSergey Zigachev mpc10->mpc_mask = mpc_mask;
459*b843c749SSergey Zigachev
460*b843c749SSergey Zigachev mpc10->mpcc_in_use_mask = 0;
461*b843c749SSergey Zigachev mpc10->num_mpcc = num_mpcc;
462*b843c749SSergey Zigachev
463*b843c749SSergey Zigachev for (i = 0; i < MAX_MPCC; i++)
464*b843c749SSergey Zigachev mpc1_init_mpcc(&mpc10->base.mpcc_array[i], i);
465*b843c749SSergey Zigachev }
466*b843c749SSergey Zigachev
467