xref: /openbmc/linux/drivers/gpu/drm/amd/display/dc/inc/hw/mpc.h (revision 788b041a)
1 /* Copyright 2012-15 Advanced Micro Devices, Inc.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a
4  * copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation
6  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7  * and/or sell copies of the Software, and to permit persons to whom the
8  * Software is furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
16  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
17  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19  * OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * Authors: AMD
22  *
23  */
24 
25 #ifndef __DC_MPCC_H__
26 #define __DC_MPCC_H__
27 
28 #include "dc_hw_types.h"
29 #include "hw_shared.h"
30 
31 #define MAX_MPCC 6
32 #define MAX_OPP 6
33 
34 #define MAX_DWB		1
35 
36 enum mpc_output_csc_mode {
37 	MPC_OUTPUT_CSC_DISABLE = 0,
38 	MPC_OUTPUT_CSC_COEF_A,
39 	MPC_OUTPUT_CSC_COEF_B
40 };
41 
42 
43 enum mpcc_blend_mode {
44 	MPCC_BLEND_MODE_BYPASS,
45 	MPCC_BLEND_MODE_TOP_LAYER_PASSTHROUGH,
46 	MPCC_BLEND_MODE_TOP_LAYER_ONLY,
47 	MPCC_BLEND_MODE_TOP_BOT_BLENDING
48 };
49 
50 enum mpcc_alpha_blend_mode {
51 	MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA,
52 	MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN,
53 	MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA
54 };
55 
56 /*
57  * MPCC blending configuration
58  */
59 struct mpcc_blnd_cfg {
60 	struct tg_color black_color;	/* background color */
61 	enum mpcc_alpha_blend_mode alpha_mode;	/* alpha blend mode */
62 	bool pre_multiplied_alpha;	/* alpha pre-multiplied mode flag */
63 	int global_gain;
64 	int global_alpha;
65 	bool overlap_only;
66 
67 	/* MPCC top/bottom gain settings */
68 	int bottom_gain_mode;
69 	int background_color_bpc;
70 	int top_gain;
71 	int bottom_inside_gain;
72 	int bottom_outside_gain;
73 };
74 
75 struct mpcc_sm_cfg {
76 	bool enable;
77 	/* 0-single plane,2-row subsampling,4-column subsampling,6-checkboard subsampling */
78 	int sm_mode;
79 	/* 0- disable frame alternate, 1- enable frame alternate */
80 	bool frame_alt;
81 	/* 0- disable field alternate, 1- enable field alternate */
82 	bool field_alt;
83 	/* 0-no force,2-force frame polarity from top,3-force frame polarity from bottom */
84 	int force_next_frame_porlarity;
85 	/* 0-no force,2-force field polarity from top,3-force field polarity from bottom */
86 	int force_next_field_polarity;
87 };
88 
89 struct mpc_denorm_clamp {
90 	int clamp_max_r_cr;
91 	int clamp_min_r_cr;
92 	int clamp_max_g_y;
93 	int clamp_min_g_y;
94 	int clamp_max_b_cb;
95 	int clamp_min_b_cb;
96 };
97 
98 /*
99  * MPCC connection and blending configuration for a single MPCC instance.
100  * This struct is used as a node in an MPC tree.
101  */
102 struct mpcc {
103 	int mpcc_id;			/* MPCC physical instance */
104 	int dpp_id;			/* DPP input to this MPCC */
105 	struct mpcc *mpcc_bot;		/* pointer to bottom layer MPCC.  NULL when not connected */
106 	struct mpcc_blnd_cfg blnd_cfg;	/* The blending configuration for this MPCC */
107 	struct mpcc_sm_cfg sm_cfg;	/* stereo mix setting for this MPCC */
108 };
109 
110 /*
111  * MPC tree represents all MPCC connections for a pipe.
112  */
113 struct mpc_tree {
114 	int opp_id;			/* The OPP instance that owns this MPC tree */
115 	struct mpcc *opp_list;		/* The top MPCC layer of the MPC tree that outputs to OPP endpoint */
116 };
117 
118 struct mpc {
119 	const struct mpc_funcs *funcs;
120 	struct dc_context *ctx;
121 
122 	struct mpcc mpcc_array[MAX_MPCC];
123 	struct pwl_params blender_params;
124 	bool cm_bypass_mode;
125 };
126 
127 struct mpcc_state {
128 	uint32_t opp_id;
129 	uint32_t dpp_id;
130 	uint32_t bot_mpcc_id;
131 	uint32_t mode;
132 	uint32_t alpha_mode;
133 	uint32_t pre_multiplied_alpha;
134 	uint32_t overlap_only;
135 	uint32_t idle;
136 	uint32_t busy;
137 };
138 
139 struct mpc_funcs {
140 	void (*read_mpcc_state)(
141 			struct mpc *mpc,
142 			int mpcc_inst,
143 			struct mpcc_state *s);
144 
145 	/*
146 	 * Insert DPP into MPC tree based on specified blending position.
147 	 * Only used for planes that are part of blending chain for OPP output
148 	 *
149 	 * Parameters:
150 	 * [in/out] mpc		- MPC context.
151 	 * [in/out] tree	- MPC tree structure that plane will be added to.
152 	 * [in]	blnd_cfg	- MPCC blending configuration for the new blending layer.
153 	 * [in]	sm_cfg		- MPCC stereo mix configuration for the new blending layer.
154 	 *			  stereo mix must disable for the very bottom layer of the tree config.
155 	 * [in]	insert_above_mpcc - Insert new plane above this MPCC.  If NULL, insert as bottom plane.
156 	 * [in]	dpp_id		 - DPP instance for the plane to be added.
157 	 * [in]	mpcc_id		 - The MPCC physical instance to use for blending.
158 	 *
159 	 * Return:  struct mpcc* - MPCC that was added.
160 	 */
161 	struct mpcc* (*insert_plane)(
162 			struct mpc *mpc,
163 			struct mpc_tree *tree,
164 			struct mpcc_blnd_cfg *blnd_cfg,
165 			struct mpcc_sm_cfg *sm_cfg,
166 			struct mpcc *insert_above_mpcc,
167 			int dpp_id,
168 			int mpcc_id);
169 
170 	/*
171 	 * Remove a specified MPCC from the MPC tree.
172 	 *
173 	 * Parameters:
174 	 * [in/out] mpc		- MPC context.
175 	 * [in/out] tree	- MPC tree structure that plane will be removed from.
176 	 * [in/out] mpcc	- MPCC to be removed from tree.
177 	 *
178 	 * Return:  void
179 	 */
180 	void (*remove_mpcc)(
181 			struct mpc *mpc,
182 			struct mpc_tree *tree,
183 			struct mpcc *mpcc);
184 
185 	/*
186 	 * Reset the MPCC HW status by disconnecting all muxes.
187 	 *
188 	 * Parameters:
189 	 * [in/out] mpc		- MPC context.
190 	 *
191 	 * Return:  void
192 	 */
193 	void (*mpc_init)(struct mpc *mpc);
194 	void (*mpc_init_single_inst)(
195 			struct mpc *mpc,
196 			unsigned int mpcc_id);
197 
198 	/*
199 	 * Update the blending configuration for a specified MPCC.
200 	 *
201 	 * Parameters:
202 	 * [in/out] mpc		- MPC context.
203 	 * [in]     blnd_cfg	- MPCC blending configuration.
204 	 * [in]     mpcc_id	- The MPCC physical instance.
205 	 *
206 	 * Return:  void
207 	 */
208 	void (*update_blending)(
209 		struct mpc *mpc,
210 		struct mpcc_blnd_cfg *blnd_cfg,
211 		int mpcc_id);
212 
213 	struct mpcc* (*get_mpcc_for_dpp)(
214 			struct mpc_tree *tree,
215 			int dpp_id);
216 
217 	void (*wait_for_idle)(struct mpc *mpc, int id);
218 
219 	void (*assert_mpcc_idle_before_connect)(struct mpc *mpc, int mpcc_id);
220 
221 	void (*init_mpcc_list_from_hw)(
222 		struct mpc *mpc,
223 		struct mpc_tree *tree);
224 
225 	void (*set_denorm)(struct mpc *mpc,
226 			int opp_id,
227 			enum dc_color_depth output_depth);
228 
229 	void (*set_denorm_clamp)(
230 			struct mpc *mpc,
231 			int opp_id,
232 			struct mpc_denorm_clamp denorm_clamp);
233 
234 	void (*set_output_csc)(struct mpc *mpc,
235 			int opp_id,
236 			const uint16_t *regval,
237 			enum mpc_output_csc_mode ocsc_mode);
238 
239 	void (*set_ocsc_default)(struct mpc *mpc,
240 			int opp_id,
241 			enum dc_color_space color_space,
242 			enum mpc_output_csc_mode ocsc_mode);
243 
244 	void (*set_output_gamma)(
245 			struct mpc *mpc,
246 			int mpcc_id,
247 			const struct pwl_params *params);
248 	void (*power_on_mpc_mem_pwr)(
249 			struct mpc *mpc,
250 			int mpcc_id,
251 			bool power_on);
252 
253 };
254 
255 #endif
256