xref: /openbsd-src/sys/dev/pci/drm/amd/display/dc/gpio/dcn30/hw_factory_dcn30.c (revision 6fcc7b2660c483699b8be04f50da6e5cc423f54c)
1 /*
2  * Copyright 2020 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 #include <generated/autoconf.h>
26 
27 #include "dm_services.h"
28 #include "include/gpio_types.h"
29 #include "../hw_factory.h"
30 
31 
32 #include "../hw_gpio.h"
33 #include "../hw_ddc.h"
34 #include "../hw_hpd.h"
35 #include "../hw_generic.h"
36 
37 #include "hw_factory_dcn30.h"
38 
39 
40 #include "sienna_cichlid_ip_offset.h"
41 #include "dcn/dcn_3_0_0_offset.h"
42 #include "dcn/dcn_3_0_0_sh_mask.h"
43 
44 #include "nbio/nbio_7_4_offset.h"
45 
46 #include "dpcs/dpcs_3_0_0_offset.h"
47 #include "dpcs/dpcs_3_0_0_sh_mask.h"
48 
49 #include "mmhub/mmhub_2_0_0_offset.h"
50 #include "mmhub/mmhub_2_0_0_sh_mask.h"
51 
52 #include "reg_helper.h"
53 #include "../hpd_regs.h"
54 /* begin *********************
55  * macros to expend register list macro defined in HW object header file */
56 
57 /* DCN */
58 #define block HPD
59 #define reg_num 0
60 
61 #undef BASE_INNER
62 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
63 
64 #define BASE(seg) BASE_INNER(seg)
65 
66 
67 
68 #define REG(reg_name)\
69 		BASE(mm ## reg_name ## _BASE_IDX) + mm ## reg_name
70 
71 #define SF_HPD(reg_name, field_name, post_fix)\
72 	.field_name = HPD0_ ## reg_name ## __ ## field_name ## post_fix
73 
74 #define REGI(reg_name, block, id)\
75 	BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
76 				mm ## block ## id ## _ ## reg_name
77 
78 #define SF(reg_name, field_name, post_fix)\
79 	.field_name = reg_name ## __ ## field_name ## post_fix
80 
81 /* macros to expend register list macro defined in HW object header file
82  * end *********************/
83 
84 
85 
86 #define hpd_regs(id) \
87 {\
88 	HPD_REG_LIST(id)\
89 }
90 
91 static const struct hpd_registers hpd_regs[] = {
92 	hpd_regs(0),
93 	hpd_regs(1),
94 	hpd_regs(2),
95 	hpd_regs(3),
96 	hpd_regs(4),
97 	hpd_regs(5),
98 };
99 
100 static const struct hpd_sh_mask hpd_shift = {
101 		HPD_MASK_SH_LIST(__SHIFT)
102 };
103 
104 static const struct hpd_sh_mask hpd_mask = {
105 		HPD_MASK_SH_LIST(_MASK)
106 };
107 
108 #include "../ddc_regs.h"
109 
110  /* set field name */
111 #define SF_DDC(reg_name, field_name, post_fix)\
112 	.field_name = reg_name ## __ ## field_name ## post_fix
113 
114 static const struct ddc_registers ddc_data_regs_dcn[] = {
115 	ddc_data_regs_dcn2(1),
116 	ddc_data_regs_dcn2(2),
117 	ddc_data_regs_dcn2(3),
118 	ddc_data_regs_dcn2(4),
119 	ddc_data_regs_dcn2(5),
120 	ddc_data_regs_dcn2(6),
121 	{
122 			DDC_GPIO_VGA_REG_LIST(DATA),
123 			.ddc_setup = 0,
124 			.phy_aux_cntl = 0,
125 			.dc_gpio_aux_ctrl_5 = 0
126 	}
127 };
128 
129 static const struct ddc_registers ddc_clk_regs_dcn[] = {
130 	ddc_clk_regs_dcn2(1),
131 	ddc_clk_regs_dcn2(2),
132 	ddc_clk_regs_dcn2(3),
133 	ddc_clk_regs_dcn2(4),
134 	ddc_clk_regs_dcn2(5),
135 	ddc_clk_regs_dcn2(6),
136 	{
137 			DDC_GPIO_VGA_REG_LIST(CLK),
138 			.ddc_setup = 0,
139 			.phy_aux_cntl = 0,
140 			.dc_gpio_aux_ctrl_5 = 0
141 	}
142 };
143 
144 static const struct ddc_sh_mask ddc_shift[] = {
145 	DDC_MASK_SH_LIST_DCN2(__SHIFT, 1),
146 	DDC_MASK_SH_LIST_DCN2(__SHIFT, 2),
147 	DDC_MASK_SH_LIST_DCN2(__SHIFT, 3),
148 	DDC_MASK_SH_LIST_DCN2(__SHIFT, 4),
149 	DDC_MASK_SH_LIST_DCN2(__SHIFT, 5),
150 	DDC_MASK_SH_LIST_DCN2(__SHIFT, 6),
151 	DDC_MASK_SH_LIST_DCN2_VGA(__SHIFT)
152 };
153 
154 static const struct ddc_sh_mask ddc_mask[] = {
155 	DDC_MASK_SH_LIST_DCN2(_MASK, 1),
156 	DDC_MASK_SH_LIST_DCN2(_MASK, 2),
157 	DDC_MASK_SH_LIST_DCN2(_MASK, 3),
158 	DDC_MASK_SH_LIST_DCN2(_MASK, 4),
159 	DDC_MASK_SH_LIST_DCN2(_MASK, 5),
160 	DDC_MASK_SH_LIST_DCN2(_MASK, 6),
161 	DDC_MASK_SH_LIST_DCN2_VGA(_MASK)
162 };
163 
164 #include "../generic_regs.h"
165 
166 /* set field name */
167 #define SF_GENERIC(reg_name, field_name, post_fix)\
168 	.field_name = reg_name ## __ ## field_name ## post_fix
169 
170 #define generic_regs(id) \
171 {\
172 	GENERIC_REG_LIST(id)\
173 }
174 
175 static const struct generic_registers generic_regs[] = {
176 	generic_regs(A),
177 	generic_regs(B),
178 };
179 
180 static const struct generic_sh_mask generic_shift[] = {
181 	GENERIC_MASK_SH_LIST(__SHIFT, A),
182 	GENERIC_MASK_SH_LIST(__SHIFT, B),
183 };
184 
185 static const struct generic_sh_mask generic_mask[] = {
186 	GENERIC_MASK_SH_LIST(_MASK, A),
187 	GENERIC_MASK_SH_LIST(_MASK, B),
188 };
189 
define_generic_registers(struct hw_gpio_pin * pin,uint32_t en)190 static void define_generic_registers(struct hw_gpio_pin *pin, uint32_t en)
191 {
192 	struct hw_generic *generic = HW_GENERIC_FROM_BASE(pin);
193 
194 	generic->regs = &generic_regs[en];
195 	generic->shifts = &generic_shift[en];
196 	generic->masks = &generic_mask[en];
197 	generic->base.regs = &generic_regs[en].gpio;
198 }
199 
define_ddc_registers(struct hw_gpio_pin * pin,uint32_t en)200 static void define_ddc_registers(
201 		struct hw_gpio_pin *pin,
202 		uint32_t en)
203 {
204 	struct hw_ddc *ddc = HW_DDC_FROM_BASE(pin);
205 
206 	switch (pin->id) {
207 	case GPIO_ID_DDC_DATA:
208 		ddc->regs = &ddc_data_regs_dcn[en];
209 		ddc->base.regs = &ddc_data_regs_dcn[en].gpio;
210 		break;
211 	case GPIO_ID_DDC_CLOCK:
212 		ddc->regs = &ddc_clk_regs_dcn[en];
213 		ddc->base.regs = &ddc_clk_regs_dcn[en].gpio;
214 		break;
215 	default:
216 		ASSERT_CRITICAL(false);
217 		return;
218 	}
219 
220 	ddc->shifts = &ddc_shift[en];
221 	ddc->masks = &ddc_mask[en];
222 
223 }
224 
define_hpd_registers(struct hw_gpio_pin * pin,uint32_t en)225 static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
226 {
227 	struct hw_hpd *hpd = HW_HPD_FROM_BASE(pin);
228 
229 	hpd->regs = &hpd_regs[en];
230 	hpd->shifts = &hpd_shift;
231 	hpd->masks = &hpd_mask;
232 	hpd->base.regs = &hpd_regs[en].gpio;
233 }
234 
235 
236 /* function table */
237 static const struct hw_factory_funcs funcs = {
238 	.init_ddc_data = dal_hw_ddc_init,
239 	.init_generic = dal_hw_generic_init,
240 	.init_hpd = dal_hw_hpd_init,
241 	.get_ddc_pin = dal_hw_ddc_get_pin,
242 	.get_hpd_pin = dal_hw_hpd_get_pin,
243 	.get_generic_pin = dal_hw_generic_get_pin,
244 	.define_hpd_registers = define_hpd_registers,
245 	.define_ddc_registers = define_ddc_registers,
246 	.define_generic_registers = define_generic_registers
247 };
248 /*
249  * dal_hw_factory_dcn10_init
250  *
251  * @brief
252  * Initialize HW factory function pointers and pin info
253  *
254  * @param
255  * struct hw_factory *factory - [out] struct of function pointers
256  */
dal_hw_factory_dcn30_init(struct hw_factory * factory)257 void dal_hw_factory_dcn30_init(struct hw_factory *factory)
258 {
259 	/*TODO check ASIC CAPs*/
260 	factory->number_of_pins[GPIO_ID_DDC_DATA] = 8;
261 	factory->number_of_pins[GPIO_ID_DDC_CLOCK] = 8;
262 	factory->number_of_pins[GPIO_ID_GENERIC] = 4;
263 	factory->number_of_pins[GPIO_ID_HPD] = 6;
264 	factory->number_of_pins[GPIO_ID_GPIO_PAD] = 28;
265 	factory->number_of_pins[GPIO_ID_VIP_PAD] = 0;
266 	factory->number_of_pins[GPIO_ID_SYNC] = 0;
267 	factory->number_of_pins[GPIO_ID_GSL] = 0;/*add this*/
268 
269 	factory->funcs = &funcs;
270 }
271 
272