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