1 /*
2  * Copyright 2012-16 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 
27 #ifndef _DCE_ABM_H_
28 #define _DCE_ABM_H_
29 
30 #include "abm.h"
31 
32 #define ABM_COMMON_REG_LIST_DCE_BASE() \
33 	SR(MASTER_COMM_CNTL_REG), \
34 	SR(MASTER_COMM_CMD_REG), \
35 	SR(MASTER_COMM_DATA_REG1)
36 
37 #define ABM_DCE110_COMMON_REG_LIST() \
38 	ABM_COMMON_REG_LIST_DCE_BASE(), \
39 	SR(DC_ABM1_HG_SAMPLE_RATE), \
40 	SR(DC_ABM1_LS_SAMPLE_RATE), \
41 	SR(BL1_PWM_BL_UPDATE_SAMPLE_RATE), \
42 	SR(DC_ABM1_HG_MISC_CTRL), \
43 	SR(DC_ABM1_IPCSC_COEFF_SEL), \
44 	SR(BL1_PWM_CURRENT_ABM_LEVEL), \
45 	SR(BL1_PWM_TARGET_ABM_LEVEL), \
46 	SR(BL1_PWM_USER_LEVEL), \
47 	SR(DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES), \
48 	SR(DC_ABM1_HGLS_REG_READ_PROGRESS), \
49 	SR(BIOS_SCRATCH_2)
50 
51 #define ABM_DCN10_REG_LIST(id)\
52 	ABM_COMMON_REG_LIST_DCE_BASE(), \
53 	SRI(DC_ABM1_HG_SAMPLE_RATE, ABM, id), \
54 	SRI(DC_ABM1_LS_SAMPLE_RATE, ABM, id), \
55 	SRI(BL1_PWM_BL_UPDATE_SAMPLE_RATE, ABM, id), \
56 	SRI(DC_ABM1_HG_MISC_CTRL, ABM, id), \
57 	SRI(DC_ABM1_IPCSC_COEFF_SEL, ABM, id), \
58 	SRI(BL1_PWM_CURRENT_ABM_LEVEL, ABM, id), \
59 	SRI(BL1_PWM_TARGET_ABM_LEVEL, ABM, id), \
60 	SRI(BL1_PWM_USER_LEVEL, ABM, id), \
61 	SRI(DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES, ABM, id), \
62 	SRI(DC_ABM1_HGLS_REG_READ_PROGRESS, ABM, id), \
63 	NBIO_SR(BIOS_SCRATCH_2)
64 
65 #define ABM_DCN20_REG_LIST() \
66 	ABM_COMMON_REG_LIST_DCE_BASE(), \
67 	SR(DC_ABM1_HG_SAMPLE_RATE), \
68 	SR(DC_ABM1_LS_SAMPLE_RATE), \
69 	SR(BL1_PWM_BL_UPDATE_SAMPLE_RATE), \
70 	SR(DC_ABM1_HG_MISC_CTRL), \
71 	SR(DC_ABM1_IPCSC_COEFF_SEL), \
72 	SR(BL1_PWM_CURRENT_ABM_LEVEL), \
73 	SR(BL1_PWM_TARGET_ABM_LEVEL), \
74 	SR(BL1_PWM_USER_LEVEL), \
75 	SR(DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES), \
76 	SR(DC_ABM1_HGLS_REG_READ_PROGRESS), \
77 	NBIO_SR(BIOS_SCRATCH_2)
78 
79 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
80 #define ABM_DCN301_REG_LIST(id)\
81 	ABM_COMMON_REG_LIST_DCE_BASE(), \
82 	SRI(DC_ABM1_HG_SAMPLE_RATE, ABM, id), \
83 	SRI(DC_ABM1_LS_SAMPLE_RATE, ABM, id), \
84 	SRI(BL1_PWM_BL_UPDATE_SAMPLE_RATE, ABM, id), \
85 	SRI(DC_ABM1_HG_MISC_CTRL, ABM, id), \
86 	SRI(DC_ABM1_IPCSC_COEFF_SEL, ABM, id), \
87 	SRI(BL1_PWM_CURRENT_ABM_LEVEL, ABM, id), \
88 	SRI(BL1_PWM_TARGET_ABM_LEVEL, ABM, id), \
89 	SRI(BL1_PWM_USER_LEVEL, ABM, id), \
90 	SRI(DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES, ABM, id), \
91 	SRI(DC_ABM1_HGLS_REG_READ_PROGRESS, ABM, id), \
92 	NBIO_SR(BIOS_SCRATCH_2)
93 #endif
94 
95 #define ABM_SF(reg_name, field_name, post_fix)\
96 	.field_name = reg_name ## __ ## field_name ## post_fix
97 
98 #define ABM_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(mask_sh) \
99 	ABM_SF(MASTER_COMM_CNTL_REG, MASTER_COMM_INTERRUPT, mask_sh), \
100 	ABM_SF(MASTER_COMM_CMD_REG, MASTER_COMM_CMD_REG_BYTE0, mask_sh), \
101 	ABM_SF(MASTER_COMM_CMD_REG, MASTER_COMM_CMD_REG_BYTE1, mask_sh), \
102 	ABM_SF(MASTER_COMM_CMD_REG, MASTER_COMM_CMD_REG_BYTE2, mask_sh)
103 
104 #define ABM_MASK_SH_LIST_DCE110(mask_sh) \
105 	ABM_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(mask_sh), \
106 	ABM_SF(DC_ABM1_HG_MISC_CTRL, \
107 			ABM1_HG_NUM_OF_BINS_SEL, mask_sh), \
108 	ABM_SF(DC_ABM1_HG_MISC_CTRL, \
109 			ABM1_HG_VMAX_SEL, mask_sh), \
110 	ABM_SF(DC_ABM1_HG_MISC_CTRL, \
111 			ABM1_HG_BIN_BITWIDTH_SIZE_SEL, mask_sh), \
112 	ABM_SF(DC_ABM1_IPCSC_COEFF_SEL, \
113 			ABM1_IPCSC_COEFF_SEL_R, mask_sh), \
114 	ABM_SF(DC_ABM1_IPCSC_COEFF_SEL, \
115 			ABM1_IPCSC_COEFF_SEL_G, mask_sh), \
116 	ABM_SF(DC_ABM1_IPCSC_COEFF_SEL, \
117 			ABM1_IPCSC_COEFF_SEL_B, mask_sh), \
118 	ABM_SF(BL1_PWM_CURRENT_ABM_LEVEL, \
119 			BL1_PWM_CURRENT_ABM_LEVEL, mask_sh), \
120 	ABM_SF(BL1_PWM_TARGET_ABM_LEVEL, \
121 			BL1_PWM_TARGET_ABM_LEVEL, mask_sh), \
122 	ABM_SF(BL1_PWM_USER_LEVEL, \
123 			BL1_PWM_USER_LEVEL, mask_sh), \
124 	ABM_SF(DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES, \
125 			ABM1_LS_MIN_PIXEL_VALUE_THRES, mask_sh), \
126 	ABM_SF(DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES, \
127 			ABM1_LS_MAX_PIXEL_VALUE_THRES, mask_sh), \
128 	ABM_SF(DC_ABM1_HGLS_REG_READ_PROGRESS, \
129 			ABM1_HG_REG_READ_MISSED_FRAME_CLEAR, mask_sh), \
130 	ABM_SF(DC_ABM1_HGLS_REG_READ_PROGRESS, \
131 			ABM1_LS_REG_READ_MISSED_FRAME_CLEAR, mask_sh), \
132 	ABM_SF(DC_ABM1_HGLS_REG_READ_PROGRESS, \
133 			ABM1_BL_REG_READ_MISSED_FRAME_CLEAR, mask_sh)
134 
135 #define ABM_MASK_SH_LIST_DCN10(mask_sh) \
136 	ABM_COMMON_MASK_SH_LIST_DCE_COMMON_BASE(mask_sh), \
137 	ABM_SF(ABM0_DC_ABM1_HG_MISC_CTRL, \
138 			ABM1_HG_NUM_OF_BINS_SEL, mask_sh), \
139 	ABM_SF(ABM0_DC_ABM1_HG_MISC_CTRL, \
140 			ABM1_HG_VMAX_SEL, mask_sh), \
141 	ABM_SF(ABM0_DC_ABM1_HG_MISC_CTRL, \
142 			ABM1_HG_BIN_BITWIDTH_SIZE_SEL, mask_sh), \
143 	ABM_SF(ABM0_DC_ABM1_IPCSC_COEFF_SEL, \
144 			ABM1_IPCSC_COEFF_SEL_R, mask_sh), \
145 	ABM_SF(ABM0_DC_ABM1_IPCSC_COEFF_SEL, \
146 			ABM1_IPCSC_COEFF_SEL_G, mask_sh), \
147 	ABM_SF(ABM0_DC_ABM1_IPCSC_COEFF_SEL, \
148 			ABM1_IPCSC_COEFF_SEL_B, mask_sh), \
149 	ABM_SF(ABM0_BL1_PWM_CURRENT_ABM_LEVEL, \
150 			BL1_PWM_CURRENT_ABM_LEVEL, mask_sh), \
151 	ABM_SF(ABM0_BL1_PWM_TARGET_ABM_LEVEL, \
152 			BL1_PWM_TARGET_ABM_LEVEL, mask_sh), \
153 	ABM_SF(ABM0_BL1_PWM_USER_LEVEL, \
154 			BL1_PWM_USER_LEVEL, mask_sh), \
155 	ABM_SF(ABM0_DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES, \
156 			ABM1_LS_MIN_PIXEL_VALUE_THRES, mask_sh), \
157 	ABM_SF(ABM0_DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES, \
158 			ABM1_LS_MAX_PIXEL_VALUE_THRES, mask_sh), \
159 	ABM_SF(ABM0_DC_ABM1_HGLS_REG_READ_PROGRESS, \
160 			ABM1_HG_REG_READ_MISSED_FRAME_CLEAR, mask_sh), \
161 	ABM_SF(ABM0_DC_ABM1_HGLS_REG_READ_PROGRESS, \
162 			ABM1_LS_REG_READ_MISSED_FRAME_CLEAR, mask_sh), \
163 	ABM_SF(ABM0_DC_ABM1_HGLS_REG_READ_PROGRESS, \
164 			ABM1_BL_REG_READ_MISSED_FRAME_CLEAR, mask_sh)
165 
166 #define ABM_MASK_SH_LIST_DCN20(mask_sh) ABM_MASK_SH_LIST_DCE110(mask_sh)
167 
168 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
169 #define ABM_MASK_SH_LIST_DCN301(mask_sh) ABM_MASK_SH_LIST_DCN10(mask_sh)
170 #endif
171 
172 #define ABM_REG_FIELD_LIST(type) \
173 	type ABM1_HG_NUM_OF_BINS_SEL; \
174 	type ABM1_HG_VMAX_SEL; \
175 	type ABM1_HG_BIN_BITWIDTH_SIZE_SEL; \
176 	type ABM1_IPCSC_COEFF_SEL_R; \
177 	type ABM1_IPCSC_COEFF_SEL_G; \
178 	type ABM1_IPCSC_COEFF_SEL_B; \
179 	type BL1_PWM_CURRENT_ABM_LEVEL; \
180 	type BL1_PWM_TARGET_ABM_LEVEL; \
181 	type BL1_PWM_USER_LEVEL; \
182 	type ABM1_LS_MIN_PIXEL_VALUE_THRES; \
183 	type ABM1_LS_MAX_PIXEL_VALUE_THRES; \
184 	type ABM1_HG_REG_READ_MISSED_FRAME_CLEAR; \
185 	type ABM1_LS_REG_READ_MISSED_FRAME_CLEAR; \
186 	type ABM1_BL_REG_READ_MISSED_FRAME_CLEAR; \
187 	type MASTER_COMM_INTERRUPT; \
188 	type MASTER_COMM_CMD_REG_BYTE0; \
189 	type MASTER_COMM_CMD_REG_BYTE1; \
190 	type MASTER_COMM_CMD_REG_BYTE2
191 
192 struct dce_abm_shift {
193 	ABM_REG_FIELD_LIST(uint8_t);
194 };
195 
196 struct dce_abm_mask {
197 	ABM_REG_FIELD_LIST(uint32_t);
198 };
199 
200 struct dce_abm_registers {
201 	uint32_t DC_ABM1_HG_SAMPLE_RATE;
202 	uint32_t DC_ABM1_LS_SAMPLE_RATE;
203 	uint32_t BL1_PWM_BL_UPDATE_SAMPLE_RATE;
204 	uint32_t DC_ABM1_HG_MISC_CTRL;
205 	uint32_t DC_ABM1_IPCSC_COEFF_SEL;
206 	uint32_t BL1_PWM_CURRENT_ABM_LEVEL;
207 	uint32_t BL1_PWM_TARGET_ABM_LEVEL;
208 	uint32_t BL1_PWM_USER_LEVEL;
209 	uint32_t DC_ABM1_LS_MIN_MAX_PIXEL_VALUE_THRES;
210 	uint32_t DC_ABM1_HGLS_REG_READ_PROGRESS;
211 	uint32_t MASTER_COMM_CNTL_REG;
212 	uint32_t MASTER_COMM_CMD_REG;
213 	uint32_t MASTER_COMM_DATA_REG1;
214 	uint32_t BIOS_SCRATCH_2;
215 };
216 
217 struct dce_abm {
218 	struct abm base;
219 	const struct dce_abm_registers *regs;
220 	const struct dce_abm_shift *abm_shift;
221 	const struct dce_abm_mask *abm_mask;
222 };
223 
224 struct abm *dce_abm_create(
225 	struct dc_context *ctx,
226 	const struct dce_abm_registers *regs,
227 	const struct dce_abm_shift *abm_shift,
228 	const struct dce_abm_mask *abm_mask);
229 
230 void dce_abm_destroy(struct abm **abm);
231 
232 #endif /* _DCE_ABM_H_ */
233