1345429a6SHarry Wentland /*
2345429a6SHarry Wentland  * Copyright 2012-17 Advanced Micro Devices, Inc.
3345429a6SHarry Wentland  *
4345429a6SHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
5345429a6SHarry Wentland  * copy of this software and associated documentation files (the "Software"),
6345429a6SHarry Wentland  * to deal in the Software without restriction, including without limitation
7345429a6SHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8345429a6SHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
9345429a6SHarry Wentland  * Software is furnished to do so, subject to the following conditions:
10345429a6SHarry Wentland  *
11345429a6SHarry Wentland  * The above copyright notice and this permission notice shall be included in
12345429a6SHarry Wentland  * all copies or substantial portions of the Software.
13345429a6SHarry Wentland  *
14345429a6SHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15345429a6SHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16345429a6SHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17345429a6SHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18345429a6SHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19345429a6SHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20345429a6SHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
21345429a6SHarry Wentland  *
22345429a6SHarry Wentland  * Authors: AMD
23345429a6SHarry Wentland  *
24345429a6SHarry Wentland  */
25345429a6SHarry Wentland 
26345429a6SHarry Wentland #include "reg_helper.h"
27345429a6SHarry Wentland #include "resource.h"
28345429a6SHarry Wentland #include "dwb.h"
29345429a6SHarry Wentland #include "dcn10_dwb.h"
30345429a6SHarry Wentland 
31345429a6SHarry Wentland 
32345429a6SHarry Wentland #define REG(reg)\
33345429a6SHarry Wentland 	dwbc10->dwbc_regs->reg
34345429a6SHarry Wentland 
35345429a6SHarry Wentland #define CTX \
36345429a6SHarry Wentland 	dwbc10->base.ctx
37345429a6SHarry Wentland 
38345429a6SHarry Wentland #undef FN
39345429a6SHarry Wentland #define FN(reg_name, field_name) \
40345429a6SHarry Wentland 	dwbc10->dwbc_shift->field_name, dwbc10->dwbc_mask->field_name
41345429a6SHarry Wentland 
42345429a6SHarry Wentland #define TO_DCN10_DWBC(dwbc_base) \
43345429a6SHarry Wentland 	container_of(dwbc_base, struct dcn10_dwbc, base)
44345429a6SHarry Wentland 
dwb1_get_caps(struct dwbc * dwbc,struct dwb_caps * caps)45345429a6SHarry Wentland static bool dwb1_get_caps(struct dwbc *dwbc, struct dwb_caps *caps)
46345429a6SHarry Wentland {
47345429a6SHarry Wentland 	if (caps) {
48345429a6SHarry Wentland 		caps->adapter_id = 0;	/* we only support 1 adapter currently */
49345429a6SHarry Wentland 		caps->hw_version = DCN_VERSION_1_0;
50345429a6SHarry Wentland 		caps->num_pipes = 2;
51345429a6SHarry Wentland 		memset(&caps->reserved, 0, sizeof(caps->reserved));
52345429a6SHarry Wentland 		memset(&caps->reserved2, 0, sizeof(caps->reserved2));
53345429a6SHarry Wentland 		caps->sw_version = dwb_ver_1_0;
54345429a6SHarry Wentland 		caps->caps.support_dwb = true;
55345429a6SHarry Wentland 		caps->caps.support_ogam = false;
56345429a6SHarry Wentland 		caps->caps.support_wbscl = true;
57345429a6SHarry Wentland 		caps->caps.support_ocsc = false;
58345429a6SHarry Wentland 		return true;
59345429a6SHarry Wentland 	} else {
60345429a6SHarry Wentland 		return false;
61345429a6SHarry Wentland 	}
62345429a6SHarry Wentland }
63345429a6SHarry Wentland 
dwb1_enable(struct dwbc * dwbc,struct dc_dwb_params * params)64345429a6SHarry Wentland static bool dwb1_enable(struct dwbc *dwbc, struct dc_dwb_params *params)
65345429a6SHarry Wentland {
66345429a6SHarry Wentland 	struct dcn10_dwbc *dwbc10 = TO_DCN10_DWBC(dwbc);
67345429a6SHarry Wentland 
68345429a6SHarry Wentland 	/* disable first. */
69345429a6SHarry Wentland 	dwbc->funcs->disable(dwbc);
70345429a6SHarry Wentland 
71345429a6SHarry Wentland 	/* disable power gating */
72345429a6SHarry Wentland 	REG_UPDATE_5(WB_EC_CONFIG, DISPCLK_R_WB_GATE_DIS, 1,
73345429a6SHarry Wentland 		 DISPCLK_G_WB_GATE_DIS, 1, DISPCLK_G_WBSCL_GATE_DIS, 1,
74345429a6SHarry Wentland 		 WB_LB_LS_DIS, 1, WB_LUT_LS_DIS, 1);
75345429a6SHarry Wentland 
76345429a6SHarry Wentland 	REG_UPDATE(WB_ENABLE, WB_ENABLE, 1);
77345429a6SHarry Wentland 
78345429a6SHarry Wentland 	return true;
79345429a6SHarry Wentland }
80345429a6SHarry Wentland 
dwb1_disable(struct dwbc * dwbc)81345429a6SHarry Wentland static bool dwb1_disable(struct dwbc *dwbc)
82345429a6SHarry Wentland {
83345429a6SHarry Wentland 	struct dcn10_dwbc *dwbc10 = TO_DCN10_DWBC(dwbc);
84345429a6SHarry Wentland 
85345429a6SHarry Wentland 	/* disable CNV */
86345429a6SHarry Wentland 	REG_UPDATE(CNV_MODE, CNV_FRAME_CAPTURE_EN, 0);
87345429a6SHarry Wentland 
88345429a6SHarry Wentland 	/* disable WB */
89345429a6SHarry Wentland 	REG_UPDATE(WB_ENABLE, WB_ENABLE, 0);
90345429a6SHarry Wentland 
91345429a6SHarry Wentland 	/* soft reset */
92345429a6SHarry Wentland 	REG_UPDATE(WB_SOFT_RESET, WB_SOFT_RESET, 1);
93345429a6SHarry Wentland 	REG_UPDATE(WB_SOFT_RESET, WB_SOFT_RESET, 0);
94345429a6SHarry Wentland 
95345429a6SHarry Wentland 	/* enable power gating */
96345429a6SHarry Wentland 	REG_UPDATE_5(WB_EC_CONFIG, DISPCLK_R_WB_GATE_DIS, 0,
97345429a6SHarry Wentland 		 DISPCLK_G_WB_GATE_DIS, 0, DISPCLK_G_WBSCL_GATE_DIS, 0,
98345429a6SHarry Wentland 		 WB_LB_LS_DIS, 0, WB_LUT_LS_DIS, 0);
99345429a6SHarry Wentland 
100345429a6SHarry Wentland 	return true;
101345429a6SHarry Wentland }
102345429a6SHarry Wentland 
103345429a6SHarry Wentland const struct dwbc_funcs dcn10_dwbc_funcs = {
104345429a6SHarry Wentland 	.get_caps			= dwb1_get_caps,
105345429a6SHarry Wentland 	.enable				= dwb1_enable,
106345429a6SHarry Wentland 	.disable			= dwb1_disable,
107345429a6SHarry Wentland 	.update				= NULL,
108345429a6SHarry Wentland 	.set_stereo			= NULL,
109345429a6SHarry Wentland 	.set_new_content		= NULL,
110345429a6SHarry Wentland 	.set_warmup			= NULL,
111345429a6SHarry Wentland 	.dwb_set_scaler			= NULL,
112345429a6SHarry Wentland };
113345429a6SHarry Wentland 
dcn10_dwbc_construct(struct dcn10_dwbc * dwbc10,struct dc_context * ctx,const struct dcn10_dwbc_registers * dwbc_regs,const struct dcn10_dwbc_shift * dwbc_shift,const struct dcn10_dwbc_mask * dwbc_mask,int inst)114345429a6SHarry Wentland void dcn10_dwbc_construct(struct dcn10_dwbc *dwbc10,
115345429a6SHarry Wentland 		struct dc_context *ctx,
116345429a6SHarry Wentland 		const struct dcn10_dwbc_registers *dwbc_regs,
117345429a6SHarry Wentland 		const struct dcn10_dwbc_shift *dwbc_shift,
118345429a6SHarry Wentland 		const struct dcn10_dwbc_mask *dwbc_mask,
119345429a6SHarry Wentland 		int inst)
120345429a6SHarry Wentland {
121345429a6SHarry Wentland 	dwbc10->base.ctx = ctx;
122345429a6SHarry Wentland 
123345429a6SHarry Wentland 	dwbc10->base.inst = inst;
124345429a6SHarry Wentland 	dwbc10->base.funcs = &dcn10_dwbc_funcs;
125345429a6SHarry Wentland 
126345429a6SHarry Wentland 	dwbc10->dwbc_regs = dwbc_regs;
127345429a6SHarry Wentland 	dwbc10->dwbc_shift = dwbc_shift;
128345429a6SHarry Wentland 	dwbc10->dwbc_mask = dwbc_mask;
129345429a6SHarry Wentland }
130