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