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 enum mpc_output_csc_mode {
35 	MPC_OUTPUT_CSC_DISABLE = 0,
36 	MPC_OUTPUT_CSC_COEF_A,
37 	MPC_OUTPUT_CSC_COEF_B
38 };
39 
40 
41 enum mpcc_blend_mode {
42 	MPCC_BLEND_MODE_BYPASS,
43 	MPCC_BLEND_MODE_TOP_LAYER_PASSTHROUGH,
44 	MPCC_BLEND_MODE_TOP_LAYER_ONLY,
45 	MPCC_BLEND_MODE_TOP_BOT_BLENDING
46 };
47 
48 enum mpcc_alpha_blend_mode {
49 	MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA,
50 	MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN,
51 	MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA
52 };
53 
54 /*
55  * MPCC blending configuration
56  */
57 struct mpcc_blnd_cfg {
58 	struct tg_color black_color;	/* background color */
59 	enum mpcc_alpha_blend_mode alpha_mode;	/* alpha blend mode */
60 	bool pre_multiplied_alpha;	/* alpha pre-multiplied mode flag */
61 	int global_gain;
62 	int global_alpha;
63 	bool overlap_only;
64 
65 };
66 
67 struct mpcc_sm_cfg {
68 	bool enable;
69 	/* 0-single plane,2-row subsampling,4-column subsampling,6-checkboard subsampling */
70 	int sm_mode;
71 	/* 0- disable frame alternate, 1- enable frame alternate */
72 	bool frame_alt;
73 	/* 0- disable field alternate, 1- enable field alternate */
74 	bool field_alt;
75 	/* 0-no force,2-force frame polarity from top,3-force frame polarity from bottom */
76 	int force_next_frame_porlarity;
77 	/* 0-no force,2-force field polarity from top,3-force field polarity from bottom */
78 	int force_next_field_polarity;
79 };
80 
81 /*
82  * MPCC connection and blending configuration for a single MPCC instance.
83  * This struct is used as a node in an MPC tree.
84  */
85 struct mpcc {
86 	int mpcc_id;			/* MPCC physical instance */
87 	int dpp_id;			/* DPP input to this MPCC */
88 	struct mpcc *mpcc_bot;		/* pointer to bottom layer MPCC.  NULL when not connected */
89 	struct mpcc_blnd_cfg blnd_cfg;	/* The blending configuration for this MPCC */
90 	struct mpcc_sm_cfg sm_cfg;	/* stereo mix setting for this MPCC */
91 };
92 
93 /*
94  * MPC tree represents all MPCC connections for a pipe.
95  */
96 struct mpc_tree {
97 	int opp_id;			/* The OPP instance that owns this MPC tree */
98 	struct mpcc *opp_list;		/* The top MPCC layer of the MPC tree that outputs to OPP endpoint */
99 };
100 
101 struct mpc {
102 	const struct mpc_funcs *funcs;
103 	struct dc_context *ctx;
104 
105 	struct mpcc mpcc_array[MAX_MPCC];
106 };
107 
108 struct mpcc_state {
109 	uint32_t opp_id;
110 	uint32_t dpp_id;
111 	uint32_t bot_mpcc_id;
112 	uint32_t mode;
113 	uint32_t alpha_mode;
114 	uint32_t pre_multiplied_alpha;
115 	uint32_t overlap_only;
116 	uint32_t idle;
117 	uint32_t busy;
118 };
119 
120 struct mpc_funcs {
121 	void (*read_mpcc_state)(
122 			struct mpc *mpc,
123 			int mpcc_inst,
124 			struct mpcc_state *s);
125 
126 	/*
127 	 * Insert DPP into MPC tree based on specified blending position.
128 	 * Only used for planes that are part of blending chain for OPP output
129 	 *
130 	 * Parameters:
131 	 * [in/out] mpc		- MPC context.
132 	 * [in/out] tree	- MPC tree structure that plane will be added to.
133 	 * [in]	blnd_cfg	- MPCC blending configuration for the new blending layer.
134 	 * [in]	sm_cfg		- MPCC stereo mix configuration for the new blending layer.
135 	 *			  stereo mix must disable for the very bottom layer of the tree config.
136 	 * [in]	insert_above_mpcc - Insert new plane above this MPCC.  If NULL, insert as bottom plane.
137 	 * [in]	dpp_id		 - DPP instance for the plane to be added.
138 	 * [in]	mpcc_id		 - The MPCC physical instance to use for blending.
139 	 *
140 	 * Return:  struct mpcc* - MPCC that was added.
141 	 */
142 	struct mpcc* (*insert_plane)(
143 			struct mpc *mpc,
144 			struct mpc_tree *tree,
145 			struct mpcc_blnd_cfg *blnd_cfg,
146 			struct mpcc_sm_cfg *sm_cfg,
147 			struct mpcc *insert_above_mpcc,
148 			int dpp_id,
149 			int mpcc_id);
150 
151 	/*
152 	 * Remove a specified MPCC from the MPC tree.
153 	 *
154 	 * Parameters:
155 	 * [in/out] mpc		- MPC context.
156 	 * [in/out] tree	- MPC tree structure that plane will be removed from.
157 	 * [in/out] mpcc	- MPCC to be removed from tree.
158 	 *
159 	 * Return:  void
160 	 */
161 	void (*remove_mpcc)(
162 			struct mpc *mpc,
163 			struct mpc_tree *tree,
164 			struct mpcc *mpcc);
165 
166 	/*
167 	 * Reset the MPCC HW status by disconnecting all muxes.
168 	 *
169 	 * Parameters:
170 	 * [in/out] mpc		- MPC context.
171 	 *
172 	 * Return:  void
173 	 */
174 	void (*mpc_init)(struct mpc *mpc);
175 
176 	/*
177 	 * Update the blending configuration for a specified MPCC.
178 	 *
179 	 * Parameters:
180 	 * [in/out] mpc		- MPC context.
181 	 * [in]     blnd_cfg	- MPCC blending configuration.
182 	 * [in]     mpcc_id	- The MPCC physical instance.
183 	 *
184 	 * Return:  void
185 	 */
186 	void (*update_blending)(
187 		struct mpc *mpc,
188 		struct mpcc_blnd_cfg *blnd_cfg,
189 		int mpcc_id);
190 
191 	struct mpcc* (*get_mpcc_for_dpp)(
192 			struct mpc_tree *tree,
193 			int dpp_id);
194 
195 	void (*wait_for_idle)(struct mpc *mpc, int id);
196 
197 	void (*assert_mpcc_idle_before_connect)(struct mpc *mpc, int mpcc_id);
198 
199 	void (*init_mpcc_list_from_hw)(
200 		struct mpc *mpc,
201 		struct mpc_tree *tree);
202 
203 };
204 
205 #endif
206