1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 VeriSilicon Holdings Co., Ltd.
7 #include <linux/bits.h>
8 #include <linux/media-bus-format.h>
10 #include <drm/vs_drm.h>
14 #include "vs_dc_dec.h"
16 static const u32 horKernel[] = {
17 0x00000000, 0x20000000, 0x00002000, 0x00000000,
18 0x00000000, 0x00000000, 0x23fd1c03, 0x00000000,
19 0x00000000, 0x00000000, 0x181f0000, 0x000027e1,
20 0x00000000, 0x00000000, 0x00000000, 0x2b981468,
21 0x00000000, 0x00000000, 0x00000000, 0x10f00000,
22 0x00002f10, 0x00000000, 0x00000000, 0x00000000,
23 0x32390dc7, 0x00000000, 0x00000000, 0x00000000,
24 0x0af50000, 0x0000350b, 0x00000000, 0x00000000,
25 0x00000000, 0x3781087f, 0x00000000, 0x00000000,
26 0x00000000, 0x06660000, 0x0000399a, 0x00000000,
27 0x00000000, 0x00000000, 0x3b5904a7, 0x00000000,
28 0x00000000, 0x00000000, 0x033c0000, 0x00003cc4,
29 0x00000000, 0x00000000, 0x00000000, 0x3de1021f,
30 0x00000000, 0x00000000, 0x00000000, 0x01470000,
31 0x00003eb9, 0x00000000, 0x00000000, 0x00000000,
32 0x3f5300ad, 0x00000000, 0x00000000, 0x00000000,
33 0x00480000, 0x00003fb8, 0x00000000, 0x00000000,
34 0x00000000, 0x3fef0011, 0x00000000, 0x00000000,
35 0x00000000, 0x00000000, 0x00004000, 0x00000000,
36 0x00000000, 0x00000000, 0x20002000, 0x00000000,
37 0x00000000, 0x00000000, 0x1c030000, 0x000023fd,
38 0x00000000, 0x00000000, 0x00000000, 0x27e1181f,
39 0x00000000, 0x00000000, 0x00000000, 0x14680000,
40 0x00002b98, 0x00000000, 0x00000000, 0x00000000,
41 0x2f1010f0, 0x00000000, 0x00000000, 0x00000000,
42 0x0dc70000, 0x00003239, 0x00000000, 0x00000000,
43 0x00000000, 0x350b0af5, 0x00000000, 0x00000000,
44 0x00000000, 0x087f0000, 0x00003781, 0x00000000,
45 0x00000000, 0x00000000, 0x399a0666, 0x00000000,
46 0x00000000, 0x00000000, 0x04a70000, 0x00003b59,
47 0x00000000, 0x00000000, 0x00000000, 0x3cc4033c,
48 0x00000000, 0x00000000, 0x00000000, 0x021f0000,
50 #define H_COEF_SIZE (sizeof(horKernel) / sizeof(u32))
52 static const u32 verKernel[] = {
53 0x00000000, 0x20000000, 0x00002000, 0x00000000,
54 0x00000000, 0x00000000, 0x23fd1c03, 0x00000000,
55 0x00000000, 0x00000000, 0x181f0000, 0x000027e1,
56 0x00000000, 0x00000000, 0x00000000, 0x2b981468,
57 0x00000000, 0x00000000, 0x00000000, 0x10f00000,
58 0x00002f10, 0x00000000, 0x00000000, 0x00000000,
59 0x32390dc7, 0x00000000, 0x00000000, 0x00000000,
60 0x0af50000, 0x0000350b, 0x00000000, 0x00000000,
61 0x00000000, 0x3781087f, 0x00000000, 0x00000000,
62 0x00000000, 0x06660000, 0x0000399a, 0x00000000,
63 0x00000000, 0x00000000, 0x3b5904a7, 0x00000000,
64 0x00000000, 0x00000000, 0x033c0000, 0x00003cc4,
65 0x00000000, 0x00000000, 0x00000000, 0x3de1021f,
66 0x00000000, 0x00000000, 0x00000000, 0x01470000,
67 0x00003eb9, 0x00000000, 0x00000000, 0x00000000,
68 0x3f5300ad, 0x00000000, 0x00000000, 0x00000000,
69 0x00480000, 0x00003fb8, 0x00000000, 0x00000000,
70 0x00000000, 0x3fef0011, 0x00000000, 0x00000000,
71 0x00000000, 0x00000000, 0x00004000, 0x00000000,
72 0xcdcd0000, 0xfdfdfdfd, 0xabababab, 0xabababab,
73 0x00000000, 0x00000000, 0x5ff5f456, 0x000f5f58,
74 0x02cc6c78, 0x02cc0c28, 0xfeeefeee, 0xfeeefeee,
75 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
76 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
77 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
78 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
79 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
80 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
81 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
82 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
83 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
84 0xfeeefeee, 0xfeeefeee, 0xfeeefeee, 0xfeeefeee,
86 #define V_COEF_SIZE (sizeof(verKernel) / sizeof(u32))
89 * RGB 709->2020 conversion parameters
91 static u16 RGB2RGB[RGB_TO_RGB_TABLE_SIZE] = {
98 * YUV601 to RGB conversion parameters
99 * YUV2RGB[0] - [8] : C0 - C8;
100 * YUV2RGB[9] - [11]: D0 - D2;
101 * YUV2RGB[12] - [13]: Y clamp min & max calue;
102 * YUV2RGB[14] - [15]: UV clamp min & max calue;
104 static s32 YUV601_2RGB[YUV_TO_RGB_TABLE_SIZE] = {
106 -404, -836, 1196, 2076,
107 0, -916224, 558336, -1202944,
112 * YUV709 to RGB conversion parameters
113 * YUV2RGB[0] - [8] : C0 - C8;
114 * YUV2RGB[9] - [11]: D0 - D2;
115 * YUV2RGB[12] - [13]: Y clamp min & max calue;
116 * YUV2RGB[14] - [15]: UV clamp min & max calue;
118 static s32 YUV709_2RGB[YUV_TO_RGB_TABLE_SIZE] = {
120 -220, -548, 1196, 2172,
121 0, -1020672, 316672, -1188608,
126 * YUV2020 to RGB conversion parameters
127 * YUV2RGB[0] - [8] : C0 - C8;
128 * YUV2RGB[9] - [11]: D0 - D2;
129 * YUV2RGB[12] - [13]: Y clamp min & max calue;
130 * YUV2RGB[14] - [15]: UV clamp min & max calue;
132 static s32 YUV2020_2RGB[YUV_TO_RGB_TABLE_SIZE] = {
134 -192, -668, 1196, 2200,
135 0, -959232, 363776, -1202944,
140 * RGB to YUV2020 conversion parameters
141 * RGB2YUV[0] - [8] : C0 - C8;
142 * RGB2YUV[9] - [11]: D0 - D2;
144 static s16 RGB2YUV[RGB_TO_YUV_TABLE_SIZE] = {
152 * Degamma table for 709 color space data.
154 static u16 DEGAMMA_709[DEGAMMA_SIZE] = {
155 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0005,
156 0x0007, 0x000a, 0x000d, 0x0011, 0x0015, 0x0019, 0x001e, 0x0024,
157 0x002a, 0x0030, 0x0038, 0x003f, 0x0048, 0x0051, 0x005a, 0x0064,
158 0x006f, 0x007b, 0x0087, 0x0094, 0x00a1, 0x00af, 0x00be, 0x00ce,
159 0x00de, 0x00ef, 0x0101, 0x0114, 0x0127, 0x013b, 0x0150, 0x0166,
160 0x017c, 0x0193, 0x01ac, 0x01c4, 0x01de, 0x01f9, 0x0214, 0x0230,
161 0x024d, 0x026b, 0x028a, 0x02aa, 0x02ca, 0x02ec, 0x030e, 0x0331,
162 0x0355, 0x037a, 0x03a0, 0x03c7, 0x03ef, 0x0418, 0x0441, 0x046c,
163 0x0498, 0x04c4, 0x04f2, 0x0520, 0x0550, 0x0581, 0x05b2, 0x05e5,
164 0x0618, 0x064d, 0x0682, 0x06b9, 0x06f0, 0x0729, 0x0763, 0x079d,
165 0x07d9, 0x0816, 0x0854, 0x0893, 0x08d3, 0x0914, 0x0956, 0x0999,
166 0x09dd, 0x0a23, 0x0a69, 0x0ab1, 0x0afa, 0x0b44, 0x0b8f, 0x0bdb,
167 0x0c28, 0x0c76, 0x0cc6, 0x0d17, 0x0d69, 0x0dbb, 0x0e10, 0x0e65,
168 0x0ebb, 0x0f13, 0x0f6c, 0x0fc6, 0x1021, 0x107d, 0x10db, 0x113a,
169 0x119a, 0x11fb, 0x125d, 0x12c1, 0x1325, 0x138c, 0x13f3, 0x145b,
170 0x14c5, 0x1530, 0x159c, 0x160a, 0x1678, 0x16e8, 0x175a, 0x17cc,
171 0x1840, 0x18b5, 0x192b, 0x19a3, 0x1a1c, 0x1a96, 0x1b11, 0x1b8e,
172 0x1c0c, 0x1c8c, 0x1d0c, 0x1d8e, 0x1e12, 0x1e96, 0x1f1c, 0x1fa3,
173 0x202c, 0x20b6, 0x2141, 0x21ce, 0x225c, 0x22eb, 0x237c, 0x240e,
174 0x24a1, 0x2536, 0x25cc, 0x2664, 0x26fc, 0x2797, 0x2832, 0x28cf,
175 0x296e, 0x2a0e, 0x2aaf, 0x2b51, 0x2bf5, 0x2c9b, 0x2d41, 0x2dea,
176 0x2e93, 0x2f3e, 0x2feb, 0x3099, 0x3148, 0x31f9, 0x32ab, 0x335f,
177 0x3414, 0x34ca, 0x3582, 0x363c, 0x36f7, 0x37b3, 0x3871, 0x3930,
178 0x39f1, 0x3ab3, 0x3b77, 0x3c3c, 0x3d02, 0x3dcb, 0x3e94, 0x3f5f,
179 0x402c, 0x40fa, 0x41ca, 0x429b, 0x436d, 0x4442, 0x4517, 0x45ee,
180 0x46c7, 0x47a1, 0x487d, 0x495a, 0x4a39, 0x4b19, 0x4bfb, 0x4cde,
181 0x4dc3, 0x4eaa, 0x4f92, 0x507c, 0x5167, 0x5253, 0x5342, 0x5431,
182 0x5523, 0x5616, 0x570a, 0x5800, 0x58f8, 0x59f1, 0x5aec, 0x5be9,
183 0x5ce7, 0x5de6, 0x5ee7, 0x5fea, 0x60ef, 0x61f5, 0x62fc, 0x6406,
184 0x6510, 0x661d, 0x672b, 0x683b, 0x694c, 0x6a5f, 0x6b73, 0x6c8a,
185 0x6da2, 0x6ebb, 0x6fd6, 0x70f3, 0x7211, 0x7331, 0x7453, 0x7576,
186 0x769b, 0x77c2, 0x78ea, 0x7a14, 0x7b40, 0x7c6d, 0x7d9c, 0x7ecd,
187 0x3f65, 0x3f8c, 0x3fb2, 0x3fd8
191 * Degamma table for 2020 color space data.
193 static u16 DEGAMMA_2020[DEGAMMA_SIZE] = {
194 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
195 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
196 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
197 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
198 0x0001, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0003, 0x0003,
199 0x0003, 0x0003, 0x0004, 0x0004, 0x0004, 0x0005, 0x0005, 0x0006,
200 0x0006, 0x0006, 0x0007, 0x0007, 0x0008, 0x0008, 0x0009, 0x000a,
201 0x000a, 0x000b, 0x000c, 0x000c, 0x000d, 0x000e, 0x000f, 0x000f,
202 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0016, 0x0017, 0x0018,
203 0x0019, 0x001b, 0x001c, 0x001e, 0x001f, 0x0021, 0x0022, 0x0024,
204 0x0026, 0x0028, 0x002a, 0x002c, 0x002e, 0x0030, 0x0033, 0x0035,
205 0x0038, 0x003a, 0x003d, 0x0040, 0x0043, 0x0046, 0x0049, 0x004d,
206 0x0050, 0x0054, 0x0057, 0x005b, 0x005f, 0x0064, 0x0068, 0x006d,
207 0x0071, 0x0076, 0x007c, 0x0081, 0x0086, 0x008c, 0x0092, 0x0098,
208 0x009f, 0x00a5, 0x00ac, 0x00b4, 0x00bb, 0x00c3, 0x00cb, 0x00d3,
209 0x00dc, 0x00e5, 0x00ee, 0x00f8, 0x0102, 0x010c, 0x0117, 0x0123,
210 0x012e, 0x013a, 0x0147, 0x0154, 0x0161, 0x016f, 0x017e, 0x018d,
211 0x019c, 0x01ac, 0x01bd, 0x01ce, 0x01e0, 0x01f3, 0x0206, 0x021a,
212 0x022f, 0x0244, 0x025a, 0x0272, 0x0289, 0x02a2, 0x02bc, 0x02d6,
213 0x02f2, 0x030f, 0x032c, 0x034b, 0x036b, 0x038b, 0x03ae, 0x03d1,
214 0x03f5, 0x041b, 0x0443, 0x046b, 0x0495, 0x04c1, 0x04ee, 0x051d,
215 0x054e, 0x0580, 0x05b4, 0x05ea, 0x0622, 0x065c, 0x0698, 0x06d6,
216 0x0717, 0x075a, 0x079f, 0x07e7, 0x0831, 0x087e, 0x08cd, 0x0920,
217 0x0976, 0x09ce, 0x0a2a, 0x0a89, 0x0aec, 0x0b52, 0x0bbc, 0x0c2a,
218 0x0c9b, 0x0d11, 0x0d8b, 0x0e0a, 0x0e8d, 0x0f15, 0x0fa1, 0x1033,
219 0x10ca, 0x1167, 0x120a, 0x12b2, 0x1360, 0x1415, 0x14d1, 0x1593,
220 0x165d, 0x172e, 0x1806, 0x18e7, 0x19d0, 0x1ac1, 0x1bbb, 0x1cbf,
221 0x1dcc, 0x1ee3, 0x2005, 0x2131, 0x2268, 0x23ab, 0x24fa, 0x2656,
222 0x27be, 0x2934, 0x2ab8, 0x2c4a, 0x2dec, 0x2f9d, 0x315f, 0x3332,
223 0x3516, 0x370d, 0x3916, 0x3b34, 0x3d66, 0x3fad, 0x420b, 0x4480,
224 0x470d, 0x49b3, 0x4c73, 0x4f4e, 0x5246, 0x555a, 0x588e, 0x5be1,
225 0x5f55, 0x62eb, 0x66a6, 0x6a86, 0x6e8c, 0x72bb, 0x7714, 0x7b99,
226 0x3dcb, 0x3e60, 0x3ef5, 0x3f8c
229 /* one is for primary plane and the other is for all overlay planes */
230 static const struct dc_hw_plane_reg dc_plane_reg[] = {
232 .y_address = DC_FRAMEBUFFER_ADDRESS,
233 .u_address = DC_FRAMEBUFFER_U_ADDRESS,
234 .v_address = DC_FRAMEBUFFER_V_ADDRESS,
235 .y_stride = DC_FRAMEBUFFER_STRIDE,
236 .u_stride = DC_FRAMEBUFFER_U_STRIDE,
237 .v_stride = DC_FRAMEBUFFER_V_STRIDE,
238 .size = DC_FRAMEBUFFER_SIZE,
239 .top_left = DC_FRAMEBUFFER_TOP_LEFT,
240 .bottom_right = DC_FRAMEBUFFER_BOTTOM_RIGHT,
241 .scale_factor_x = DC_FRAMEBUFFER_SCALE_FACTOR_X,
242 .scale_factor_y = DC_FRAMEBUFFER_SCALE_FACTOR_Y,
243 .h_filter_coef_index = DC_FRAMEBUFFER_H_FILTER_COEF_INDEX,
244 .h_filter_coef_data = DC_FRAMEBUFFER_H_FILTER_COEF_DATA,
245 .v_filter_coef_index = DC_FRAMEBUFFER_V_FILTER_COEF_INDEX,
246 .v_filter_coef_data = DC_FRAMEBUFFER_V_FILTER_COEF_DATA,
247 .init_offset = DC_FRAMEBUFFER_INIT_OFFSET,
248 .color_key = DC_FRAMEBUFFER_COLOR_KEY,
249 .color_key_high = DC_FRAMEBUFFER_COLOR_KEY_HIGH,
250 .clear_value = DC_FRAMEBUFFER_CLEAR_VALUE,
251 .color_table_index = DC_FRAMEBUFFER_COLOR_TABLE_INDEX,
252 .color_table_data = DC_FRAMEBUFFER_COLOR_TABLE_DATA,
253 .scale_config = DC_FRAMEBUFFER_SCALE_CONFIG,
254 .water_mark = DC_FRAMEBUFFER_WATER_MARK,
255 .degamma_index = DC_FRAMEBUFFER_DEGAMMA_INDEX,
256 .degamma_data = DC_FRAMEBUFFER_DEGAMMA_DATA,
257 .degamma_ex_data = DC_FRAMEBUFFER_DEGAMMA_EX_DATA,
258 .src_global_color = DC_FRAMEBUFFER_SRC_GLOBAL_COLOR,
259 .dst_global_color = DC_FRAMEBUFFER_DST_GLOBAL_COLOR,
260 .blend_config = DC_FRAMEBUFFER_BLEND_CONFIG,
261 .roi_origin = DC_FRAMEBUFFER_ROI_ORIGIN,
262 .roi_size = DC_FRAMEBUFFER_ROI_SIZE,
263 .YUVToRGBCoef0 = DC_FRAMEBUFFER_YUVTORGB_COEF0,
264 .YUVToRGBCoef1 = DC_FRAMEBUFFER_YUVTORGB_COEF1,
265 .YUVToRGBCoef2 = DC_FRAMEBUFFER_YUVTORGB_COEF2,
266 .YUVToRGBCoef3 = DC_FRAMEBUFFER_YUVTORGB_COEF3,
267 .YUVToRGBCoef4 = DC_FRAMEBUFFER_YUVTORGB_COEF4,
268 .YUVToRGBCoefD0 = DC_FRAMEBUFFER_YUVTORGB_COEFD0,
269 .YUVToRGBCoefD1 = DC_FRAMEBUFFER_YUVTORGB_COEFD1,
270 .YUVToRGBCoefD2 = DC_FRAMEBUFFER_YUVTORGB_COEFD2,
271 .YClampBound = DC_FRAMEBUFFER_Y_CLAMP_BOUND,
272 .UVClampBound = DC_FRAMEBUFFER_UV_CLAMP_BOUND,
273 .RGBToRGBCoef0 = DC_FRAMEBUFFER_RGBTORGB_COEF0,
274 .RGBToRGBCoef1 = DC_FRAMEBUFFER_RGBTORGB_COEF1,
275 .RGBToRGBCoef2 = DC_FRAMEBUFFER_RGBTORGB_COEF2,
276 .RGBToRGBCoef3 = DC_FRAMEBUFFER_RGBTORGB_COEF3,
277 .RGBToRGBCoef4 = DC_FRAMEBUFFER_RGBTORGB_COEF4,
280 .y_address = DC_OVERLAY_ADDRESS,
281 .u_address = DC_OVERLAY_U_ADDRESS,
282 .v_address = DC_OVERLAY_V_ADDRESS,
283 .y_stride = DC_OVERLAY_STRIDE,
284 .u_stride = DC_OVERLAY_U_STRIDE,
285 .v_stride = DC_OVERLAY_V_STRIDE,
286 .size = DC_OVERLAY_SIZE,
287 .top_left = DC_OVERLAY_TOP_LEFT,
288 .bottom_right = DC_OVERLAY_BOTTOM_RIGHT,
289 .scale_factor_x = DC_OVERLAY_SCALE_FACTOR_X,
290 .scale_factor_y = DC_OVERLAY_SCALE_FACTOR_Y,
291 .h_filter_coef_index = DC_OVERLAY_H_FILTER_COEF_INDEX,
292 .h_filter_coef_data = DC_OVERLAY_H_FILTER_COEF_DATA,
293 .v_filter_coef_index = DC_OVERLAY_V_FILTER_COEF_INDEX,
294 .v_filter_coef_data = DC_OVERLAY_V_FILTER_COEF_DATA,
295 .init_offset = DC_OVERLAY_INIT_OFFSET,
296 .color_key = DC_OVERLAY_COLOR_KEY,
297 .color_key_high = DC_OVERLAY_COLOR_KEY_HIGH,
298 .clear_value = DC_OVERLAY_CLEAR_VALUE,
299 .color_table_index = DC_OVERLAY_COLOR_TABLE_INDEX,
300 .color_table_data = DC_OVERLAY_COLOR_TABLE_DATA,
301 .scale_config = DC_OVERLAY_SCALE_CONFIG,
302 .water_mark = DC_OVERLAY_WATER_MARK,
303 .degamma_index = DC_OVERLAY_DEGAMMA_INDEX,
304 .degamma_data = DC_OVERLAY_DEGAMMA_DATA,
305 .degamma_ex_data = DC_OVERLAY_DEGAMMA_EX_DATA,
306 .src_global_color = DC_OVERLAY_SRC_GLOBAL_COLOR,
307 .dst_global_color = DC_OVERLAY_DST_GLOBAL_COLOR,
308 .blend_config = DC_OVERLAY_BLEND_CONFIG,
309 .roi_origin = DC_OVERLAY_ROI_ORIGIN,
310 .roi_size = DC_OVERLAY_ROI_SIZE,
311 .YUVToRGBCoef0 = DC_OVERLAY_YUVTORGB_COEF0,
312 .YUVToRGBCoef1 = DC_OVERLAY_YUVTORGB_COEF1,
313 .YUVToRGBCoef2 = DC_OVERLAY_YUVTORGB_COEF2,
314 .YUVToRGBCoef3 = DC_OVERLAY_YUVTORGB_COEF3,
315 .YUVToRGBCoef4 = DC_OVERLAY_YUVTORGB_COEF4,
316 .YUVToRGBCoefD0 = DC_OVERLAY_YUVTORGB_COEFD0,
317 .YUVToRGBCoefD1 = DC_OVERLAY_YUVTORGB_COEFD1,
318 .YUVToRGBCoefD2 = DC_OVERLAY_YUVTORGB_COEFD2,
319 .YClampBound = DC_OVERLAY_Y_CLAMP_BOUND,
320 .UVClampBound = DC_OVERLAY_UV_CLAMP_BOUND,
321 .RGBToRGBCoef0 = DC_OVERLAY_RGBTORGB_COEF0,
322 .RGBToRGBCoef1 = DC_OVERLAY_RGBTORGB_COEF1,
323 .RGBToRGBCoef2 = DC_OVERLAY_RGBTORGB_COEF2,
324 .RGBToRGBCoef3 = DC_OVERLAY_RGBTORGB_COEF3,
325 .RGBToRGBCoef4 = DC_OVERLAY_RGBTORGB_COEF4,
329 #ifdef CONFIG_VERISILICON_MMU
330 static const u32 mmu_reg_base = SE_MMU_REG_BASE;
332 static const struct dc_hw_mmu_reg dc_mmu_reg = {
333 .mmu_config = SE_MMU_REG_CONFIG,
334 .mmu_control = SE_MMU_REG_CONTROL,
335 .table_array_size = SE_MMU_REG_TABLE_ARRAY_SIZE,
336 .safe_non_secure = SE_MMU_REG_SAFE_NON_SECUR,
337 .safe_secure = SE_MMU_REG_SAFE_SECURE,
338 .safe_ex = SE_MMU_REG_SAFE_EXT_ADDRESS,
339 .context_pd_entry = SE_MMU_REG_CONTEXT_PD,
343 static const u32 primary_overlay_format0[] = {
370 DRM_FORMAT_ARGB2101010,
371 DRM_FORMAT_ABGR2101010,
372 DRM_FORMAT_RGBA1010102,
373 DRM_FORMAT_BGRA1010102,
387 static const u32 primary_overlay_format1[] = {
396 DRM_FORMAT_ARGB2101010,
397 DRM_FORMAT_ABGR2101010,
398 DRM_FORMAT_RGBA1010102,
399 DRM_FORMAT_BGRA1010102,
405 static const u32 cursor_formats[] = {
409 static const u64 format_modifier0[] = {
410 DRM_FORMAT_MOD_LINEAR,
411 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_LINEAR),
412 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_XMAJOR),
413 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_YMAJOR),
414 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_TILE_8X8),
415 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_TILE_8X4),
416 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_XMAJOR_8X4),
417 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_YMAJOR_4X8),
418 #ifdef CONFIG_VERISILICON_DEC
419 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_TILE_8X8_XMAJOR,
420 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
421 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_TILE_8X4,
422 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
423 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_TILE_4X8,
424 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
425 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_256X1,
426 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
427 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_128X1,
428 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
429 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_64X1,
430 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
431 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_TILE_16X8,
432 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
433 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_32X1,
434 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
435 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_TILE_32X8,
436 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
438 DRM_FORMAT_MOD_INVALID
441 static const u64 format_modifier1[] = {
442 DRM_FORMAT_MOD_LINEAR,
443 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_LINEAR),
444 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_XMAJOR),
445 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_YMAJOR),
446 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_TILE_8X8),
447 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_TILE_8X4),
448 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_XMAJOR_8X4),
449 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_SUPER_TILED_YMAJOR_4X8),
450 fourcc_mod_vs_norm_code(DRM_FORMAT_MOD_VS_TILE_MODE4X4),
451 fourcc_mod_vs_custom_code(DRM_FORMAT_MOD_VS_TILE_MODE4X4),
452 DRM_FORMAT_MOD_INVALID
455 static const u64 secondary_format_modifiers[] = {
456 DRM_FORMAT_MOD_LINEAR,
457 #ifdef CONFIG_VERISILICON_DEC
458 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_256X1,
459 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
460 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_128X1,
461 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
462 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_64X1,
463 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
464 fourcc_mod_vs_dec_code(DRM_FORMAT_MOD_VS_DEC_RASTER_32X1,
465 DRM_FORMAT_MOD_VS_DEC_ALIGN_32),
467 DRM_FORMAT_MOD_INVALID
470 #define FRAC_16_16(mult, div) (((mult) << 16) / (div))
472 static const struct vs_plane_info dc_hw_planes[][PLANE_NUM] = {
477 .id = PRIMARY_PLANE_0,
478 .type = DRM_PLANE_TYPE_PRIMARY,
479 .num_formats = ARRAY_SIZE(primary_overlay_format0),
480 .formats = primary_overlay_format0,
481 .num_modifiers = ARRAY_SIZE(format_modifier0),
482 .modifiers = format_modifier0,
487 .rotation = DRM_MODE_ROTATE_0 |
489 DRM_MODE_ROTATE_180 |
490 DRM_MODE_ROTATE_270 |
493 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
494 BIT(DRM_MODE_BLEND_PREMULTI) |
495 BIT(DRM_MODE_BLEND_COVERAGE),
496 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
497 BIT(DRM_COLOR_YCBCR_BT2020),
498 .degamma_size = DEGAMMA_SIZE,
499 .min_scale = FRAC_16_16(1, 3),
500 .max_scale = FRAC_16_16(10, 1),
508 .id = OVERLAY_PLANE_0,
509 .type = DRM_PLANE_TYPE_OVERLAY,
510 .num_formats = ARRAY_SIZE(primary_overlay_format0),
511 .formats = primary_overlay_format0,
512 .num_modifiers = ARRAY_SIZE(format_modifier0),
513 .modifiers = format_modifier0,
518 .rotation = DRM_MODE_ROTATE_0 |
520 DRM_MODE_ROTATE_180 |
521 DRM_MODE_ROTATE_270 |
524 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
525 BIT(DRM_MODE_BLEND_PREMULTI) |
526 BIT(DRM_MODE_BLEND_COVERAGE),
527 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
528 BIT(DRM_COLOR_YCBCR_BT2020),
529 .degamma_size = DEGAMMA_SIZE,
530 .min_scale = FRAC_16_16(1, 3),
531 .max_scale = FRAC_16_16(10, 1),
539 .id = OVERLAY_PLANE_1,
540 .type = DRM_PLANE_TYPE_OVERLAY,
541 .num_formats = ARRAY_SIZE(primary_overlay_format0),
542 .formats = primary_overlay_format0,
543 .num_modifiers = ARRAY_SIZE(secondary_format_modifiers),
544 .modifiers = secondary_format_modifiers,
550 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
551 BIT(DRM_MODE_BLEND_PREMULTI) |
552 BIT(DRM_MODE_BLEND_COVERAGE),
553 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
554 BIT(DRM_COLOR_YCBCR_BT2020),
555 .degamma_size = DEGAMMA_SIZE,
556 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
557 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
565 .id = PRIMARY_PLANE_1,
566 .type = DRM_PLANE_TYPE_PRIMARY,
567 .num_formats = ARRAY_SIZE(primary_overlay_format0),
568 .formats = primary_overlay_format0,
569 .num_modifiers = ARRAY_SIZE(format_modifier0),
570 .modifiers = format_modifier0,
575 .rotation = DRM_MODE_ROTATE_0 |
577 DRM_MODE_ROTATE_180 |
578 DRM_MODE_ROTATE_270 |
581 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
582 BIT(DRM_MODE_BLEND_PREMULTI) |
583 BIT(DRM_MODE_BLEND_COVERAGE),
584 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
585 BIT(DRM_COLOR_YCBCR_BT2020),
586 .degamma_size = DEGAMMA_SIZE,
587 .min_scale = FRAC_16_16(1, 3),
588 .max_scale = FRAC_16_16(10, 1),
596 .id = OVERLAY_PLANE_2,
597 .type = DRM_PLANE_TYPE_OVERLAY,
598 .num_formats = ARRAY_SIZE(primary_overlay_format0),
599 .formats = primary_overlay_format0,
600 .num_modifiers = ARRAY_SIZE(format_modifier0),
601 .modifiers = format_modifier0,
606 .rotation = DRM_MODE_ROTATE_0 |
608 DRM_MODE_ROTATE_180 |
609 DRM_MODE_ROTATE_270 |
612 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
613 BIT(DRM_MODE_BLEND_PREMULTI) |
614 BIT(DRM_MODE_BLEND_COVERAGE),
615 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
616 BIT(DRM_COLOR_YCBCR_BT2020),
617 .degamma_size = DEGAMMA_SIZE,
618 .min_scale = FRAC_16_16(1, 3),
619 .max_scale = FRAC_16_16(10, 1),
627 .id = OVERLAY_PLANE_3,
628 .type = DRM_PLANE_TYPE_OVERLAY,
629 .num_formats = ARRAY_SIZE(primary_overlay_format0),
630 .formats = primary_overlay_format0,
631 .num_modifiers = ARRAY_SIZE(secondary_format_modifiers),
632 .modifiers = secondary_format_modifiers,
638 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
639 BIT(DRM_MODE_BLEND_PREMULTI) |
640 BIT(DRM_MODE_BLEND_COVERAGE),
641 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
642 BIT(DRM_COLOR_YCBCR_BT2020),
643 .degamma_size = DEGAMMA_SIZE,
644 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
645 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
653 .id = CURSOR_PLANE_0,
654 .type = DRM_PLANE_TYPE_CURSOR,
655 .num_formats = ARRAY_SIZE(cursor_formats),
656 .formats = cursor_formats,
665 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
666 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
674 .id = CURSOR_PLANE_1,
675 .type = DRM_PLANE_TYPE_CURSOR,
676 .num_formats = ARRAY_SIZE(cursor_formats),
677 .formats = cursor_formats,
686 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
687 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
698 .id = PRIMARY_PLANE_0,
699 .type = DRM_PLANE_TYPE_PRIMARY,
700 .num_formats = ARRAY_SIZE(primary_overlay_format0),
701 .formats = primary_overlay_format0,
702 .num_modifiers = ARRAY_SIZE(format_modifier0),
703 .modifiers = format_modifier0,
708 .rotation = DRM_MODE_ROTATE_0 |
710 DRM_MODE_ROTATE_180 |
711 DRM_MODE_ROTATE_270 |
714 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
715 BIT(DRM_MODE_BLEND_PREMULTI) |
716 BIT(DRM_MODE_BLEND_COVERAGE),
717 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
718 BIT(DRM_COLOR_YCBCR_BT2020),
719 .degamma_size = DEGAMMA_SIZE,
720 .min_scale = FRAC_16_16(1, 3),
721 .max_scale = FRAC_16_16(10, 1),
729 .id = OVERLAY_PLANE_0,
730 .type = DRM_PLANE_TYPE_OVERLAY,
731 .num_formats = ARRAY_SIZE(primary_overlay_format0),
732 .formats = primary_overlay_format0,
733 .num_modifiers = ARRAY_SIZE(format_modifier0),
734 .modifiers = format_modifier0,
739 .rotation = DRM_MODE_ROTATE_0 |
741 DRM_MODE_ROTATE_180 |
742 DRM_MODE_ROTATE_270 |
745 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
746 BIT(DRM_MODE_BLEND_PREMULTI) |
747 BIT(DRM_MODE_BLEND_COVERAGE),
748 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
749 BIT(DRM_COLOR_YCBCR_BT2020),
750 .degamma_size = DEGAMMA_SIZE,
751 .min_scale = FRAC_16_16(1, 3),
752 .max_scale = FRAC_16_16(10, 1),
760 .id = PRIMARY_PLANE_1,
761 .type = DRM_PLANE_TYPE_PRIMARY,
762 .num_formats = ARRAY_SIZE(primary_overlay_format0),
763 .formats = primary_overlay_format0,
764 .num_modifiers = ARRAY_SIZE(format_modifier0),
765 .modifiers = format_modifier0,
770 .rotation = DRM_MODE_ROTATE_0 |
772 DRM_MODE_ROTATE_180 |
773 DRM_MODE_ROTATE_270 |
776 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
777 BIT(DRM_MODE_BLEND_PREMULTI) |
778 BIT(DRM_MODE_BLEND_COVERAGE),
779 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
780 BIT(DRM_COLOR_YCBCR_BT2020),
781 .degamma_size = DEGAMMA_SIZE,
782 .min_scale = FRAC_16_16(1, 3),
783 .max_scale = FRAC_16_16(10, 1),
791 .id = OVERLAY_PLANE_2,
792 .type = DRM_PLANE_TYPE_OVERLAY,
793 .num_formats = ARRAY_SIZE(primary_overlay_format0),
794 .formats = primary_overlay_format0,
795 .num_modifiers = ARRAY_SIZE(format_modifier0),
796 .modifiers = format_modifier0,
801 .rotation = DRM_MODE_ROTATE_0 |
803 DRM_MODE_ROTATE_180 |
804 DRM_MODE_ROTATE_270 |
807 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
808 BIT(DRM_MODE_BLEND_PREMULTI) |
809 BIT(DRM_MODE_BLEND_COVERAGE),
810 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
811 BIT(DRM_COLOR_YCBCR_BT2020),
812 .degamma_size = DEGAMMA_SIZE,
813 .min_scale = FRAC_16_16(1, 3),
814 .max_scale = FRAC_16_16(10, 1),
822 .id = CURSOR_PLANE_0,
823 .type = DRM_PLANE_TYPE_CURSOR,
824 .num_formats = ARRAY_SIZE(cursor_formats),
825 .formats = cursor_formats,
834 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
835 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
843 .id = CURSOR_PLANE_1,
844 .type = DRM_PLANE_TYPE_CURSOR,
845 .num_formats = ARRAY_SIZE(cursor_formats),
846 .formats = cursor_formats,
855 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
856 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
867 .id = PRIMARY_PLANE_0,
868 .type = DRM_PLANE_TYPE_PRIMARY,
869 .num_formats = ARRAY_SIZE(primary_overlay_format1),
870 .formats = primary_overlay_format1,
871 .num_modifiers = ARRAY_SIZE(format_modifier1),
872 .modifiers = format_modifier1,
877 .rotation = DRM_MODE_ROTATE_0 |
879 DRM_MODE_ROTATE_180 |
880 DRM_MODE_ROTATE_270 |
883 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
884 BIT(DRM_MODE_BLEND_PREMULTI) |
885 BIT(DRM_MODE_BLEND_COVERAGE),
886 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
887 BIT(DRM_COLOR_YCBCR_BT2020),
888 .degamma_size = DEGAMMA_SIZE,
889 .min_scale = FRAC_16_16(1, 3),
890 .max_scale = FRAC_16_16(10, 1),
898 .id = OVERLAY_PLANE_0,
899 .type = DRM_PLANE_TYPE_OVERLAY,
900 .num_formats = ARRAY_SIZE(primary_overlay_format1),
901 .formats = primary_overlay_format1,
902 .num_modifiers = ARRAY_SIZE(format_modifier1),
903 .modifiers = format_modifier1,
908 .rotation = DRM_MODE_ROTATE_0 |
910 DRM_MODE_ROTATE_180 |
911 DRM_MODE_ROTATE_270 |
914 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
915 BIT(DRM_MODE_BLEND_PREMULTI) |
916 BIT(DRM_MODE_BLEND_COVERAGE),
917 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
918 BIT(DRM_COLOR_YCBCR_BT2020),
919 .degamma_size = DEGAMMA_SIZE,
920 .min_scale = FRAC_16_16(1, 3),
921 .max_scale = FRAC_16_16(10, 1),
929 .id = OVERLAY_PLANE_1,
930 .type = DRM_PLANE_TYPE_OVERLAY,
931 .num_formats = ARRAY_SIZE(primary_overlay_format1),
932 .formats = primary_overlay_format1,
933 .num_modifiers = ARRAY_SIZE(secondary_format_modifiers),
934 .modifiers = secondary_format_modifiers,
940 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
941 BIT(DRM_MODE_BLEND_PREMULTI) |
942 BIT(DRM_MODE_BLEND_COVERAGE),
943 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
944 BIT(DRM_COLOR_YCBCR_BT2020),
945 .degamma_size = DEGAMMA_SIZE,
946 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
947 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
955 .id = PRIMARY_PLANE_1,
956 .type = DRM_PLANE_TYPE_PRIMARY,
957 .num_formats = ARRAY_SIZE(primary_overlay_format1),
958 .formats = primary_overlay_format1,
959 .num_modifiers = ARRAY_SIZE(format_modifier1),
960 .modifiers = format_modifier1,
965 .rotation = DRM_MODE_ROTATE_0 |
967 DRM_MODE_ROTATE_180 |
968 DRM_MODE_ROTATE_270 |
971 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
972 BIT(DRM_MODE_BLEND_PREMULTI) |
973 BIT(DRM_MODE_BLEND_COVERAGE),
974 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
975 BIT(DRM_COLOR_YCBCR_BT2020),
976 .degamma_size = DEGAMMA_SIZE,
977 .min_scale = FRAC_16_16(1, 3),
978 .max_scale = FRAC_16_16(10, 1),
986 .id = OVERLAY_PLANE_2,
987 .type = DRM_PLANE_TYPE_OVERLAY,
988 .num_formats = ARRAY_SIZE(primary_overlay_format1),
989 .formats = primary_overlay_format1,
990 .num_modifiers = ARRAY_SIZE(format_modifier1),
991 .modifiers = format_modifier1,
996 .rotation = DRM_MODE_ROTATE_0 |
998 DRM_MODE_ROTATE_180 |
999 DRM_MODE_ROTATE_270 |
1000 DRM_MODE_REFLECT_X |
1002 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
1003 BIT(DRM_MODE_BLEND_PREMULTI) |
1004 BIT(DRM_MODE_BLEND_COVERAGE),
1005 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
1006 BIT(DRM_COLOR_YCBCR_BT2020),
1007 .degamma_size = DEGAMMA_SIZE,
1008 .min_scale = FRAC_16_16(1, 3),
1009 .max_scale = FRAC_16_16(10, 1),
1016 .name = "Overlay_3",
1017 .id = OVERLAY_PLANE_3,
1018 .type = DRM_PLANE_TYPE_OVERLAY,
1019 .num_formats = ARRAY_SIZE(primary_overlay_format1),
1020 .formats = primary_overlay_format1,
1021 .num_modifiers = ARRAY_SIZE(secondary_format_modifiers),
1022 .modifiers = secondary_format_modifiers,
1028 .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
1029 BIT(DRM_MODE_BLEND_PREMULTI) |
1030 BIT(DRM_MODE_BLEND_COVERAGE),
1031 .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
1032 BIT(DRM_COLOR_YCBCR_BT2020),
1033 .degamma_size = DEGAMMA_SIZE,
1034 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
1035 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
1043 .id = CURSOR_PLANE_0,
1044 .type = DRM_PLANE_TYPE_CURSOR,
1045 .num_formats = ARRAY_SIZE(cursor_formats),
1046 .formats = cursor_formats,
1055 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
1056 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
1059 .color_mgmt = false,
1064 .id = CURSOR_PLANE_1,
1065 .type = DRM_PLANE_TYPE_CURSOR,
1066 .num_formats = ARRAY_SIZE(cursor_formats),
1067 .formats = cursor_formats,
1076 .min_scale = DRM_PLANE_HELPER_NO_SCALING,
1077 .max_scale = DRM_PLANE_HELPER_NO_SCALING,
1080 .color_mgmt = false,
1086 static const struct vs_dc_info dc_info[] = {
1092 .planes = dc_hw_planes[DC_REV_0],
1095 .color_formats = DRM_COLOR_FORMAT_RGB444 |
1096 DRM_COLOR_FORMAT_YCRCB444 |
1097 DRM_COLOR_FORMAT_YCRCB422 |
1098 DRM_COLOR_FORMAT_YCRCB420,
1099 .gamma_size = GAMMA_EX_SIZE,
1101 .pitch_alignment = 128,
1103 .mmu_prefetch = false,
1113 .planes = dc_hw_planes[DC_REV_1],
1116 .color_formats = DRM_COLOR_FORMAT_RGB444 |
1117 DRM_COLOR_FORMAT_YCRCB444 |
1118 DRM_COLOR_FORMAT_YCRCB422 |
1119 DRM_COLOR_FORMAT_YCRCB420,
1120 .gamma_size = GAMMA_EX_SIZE,
1122 .pitch_alignment = 128,
1124 .mmu_prefetch = false,
1134 .planes = dc_hw_planes[DC_REV_2],
1137 .color_formats = DRM_COLOR_FORMAT_RGB444 |
1138 DRM_COLOR_FORMAT_YCRCB444 |
1139 DRM_COLOR_FORMAT_YCRCB422 |
1140 DRM_COLOR_FORMAT_YCRCB420,
1141 .gamma_size = GAMMA_EX_SIZE,
1143 .pitch_alignment = 128,
1145 .mmu_prefetch = false,
1152 static const struct dc_hw_funcs hw_func;
1154 static inline u32 hi_read(struct dc_hw *hw, u32 reg)
1156 return readl(hw->hi_base + reg);
1159 static inline void hi_write(struct dc_hw *hw, u32 reg, u32 value)
1161 writel(value, hw->hi_base + reg);
1164 static inline void dc_write(struct dc_hw *hw, u32 reg, u32 value)
1166 writel(value, hw->reg_base + reg - DC_REG_BASE);
1169 static inline u32 dc_read(struct dc_hw *hw, u32 reg)
1171 u32 value = readl(hw->reg_base + reg - DC_REG_BASE);
1176 static inline void dc_set_clear(struct dc_hw *hw, u32 reg, u32 set, u32 clear)
1178 u32 value = dc_read(hw, reg);
1182 dc_write(hw, reg, value);
1185 static void load_default_filter(struct dc_hw *hw,
1186 const struct dc_hw_plane_reg *reg, u32 offset)
1190 dc_write(hw, reg->scale_config + offset, 0x33);
1191 dc_write(hw, reg->init_offset + offset, 0x80008000);
1192 dc_write(hw, reg->h_filter_coef_index + offset, 0x00);
1193 for (i = 0; i < H_COEF_SIZE; i++)
1194 dc_write(hw, reg->h_filter_coef_data + offset, horKernel[i]);
1196 dc_write(hw, reg->v_filter_coef_index + offset, 0x00);
1197 for (i = 0; i < V_COEF_SIZE; i++)
1198 dc_write(hw, reg->v_filter_coef_data + offset, verKernel[i]);
1201 static void load_rgb_to_rgb(struct dc_hw *hw, const struct dc_hw_plane_reg *reg,
1202 u32 offset, u16 *table)
1204 dc_write(hw, reg->RGBToRGBCoef0 + offset, table[0] | (table[1] << 16));
1205 dc_write(hw, reg->RGBToRGBCoef1 + offset, table[2] | (table[3] << 16));
1206 dc_write(hw, reg->RGBToRGBCoef2 + offset, table[4] | (table[5] << 16));
1207 dc_write(hw, reg->RGBToRGBCoef3 + offset, table[6] | (table[7] << 16));
1208 dc_write(hw, reg->RGBToRGBCoef4 + offset, table[8]);
1211 static void load_yuv_to_rgb(struct dc_hw *hw, const struct dc_hw_plane_reg *reg,
1212 u32 offset, s32 *table)
1214 dc_write(hw, reg->YUVToRGBCoef0 + offset,
1215 (0xFFFF & table[0]) | (table[1] << 16));
1216 dc_write(hw, reg->YUVToRGBCoef1 + offset,
1217 (0xFFFF & table[2]) | (table[3] << 16));
1218 dc_write(hw, reg->YUVToRGBCoef2 + offset,
1219 (0xFFFF & table[4]) | (table[5] << 16));
1220 dc_write(hw, reg->YUVToRGBCoef3 + offset,
1221 (0xFFFF & table[6]) | (table[7] << 16));
1222 dc_write(hw, reg->YUVToRGBCoef4 + offset, table[8]);
1223 dc_write(hw, reg->YUVToRGBCoefD0 + offset, table[9]);
1224 dc_write(hw, reg->YUVToRGBCoefD1 + offset, table[10]);
1225 dc_write(hw, reg->YUVToRGBCoefD2 + offset, table[11]);
1226 dc_write(hw, reg->YClampBound + offset, table[12] | (table[13] << 16));
1227 dc_write(hw, reg->UVClampBound + offset, table[14] | (table[15] << 16));
1230 static void load_rgb_to_yuv(struct dc_hw *hw, u32 offset, s16 *table)
1232 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEF0 + offset,
1233 table[0] | (table[1] << 16));
1234 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEF1 + offset,
1235 table[2] | (table[3] << 16));
1236 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEF2 + offset,
1237 table[4] | (table[5] << 16));
1238 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEF3 + offset,
1239 table[6] | (table[7] << 16));
1240 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEF4 + offset, table[8]);
1241 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEFD0 + offset, table[9]);
1242 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEFD1 + offset, table[10]);
1243 dc_write(hw, DC_DISPLAY_RGBTOYUV_COEFD2 + offset, table[11]);
1246 static bool is_rgb(enum dc_hw_color_format format)
1249 case FORMAT_X4R4G4B4:
1250 case FORMAT_A4R4G4B4:
1251 case FORMAT_X1R5G5B5:
1252 case FORMAT_A1R5G5B5:
1254 case FORMAT_X8R8G8B8:
1255 case FORMAT_A8R8G8B8:
1256 case FORMAT_A2R10G10B10:
1263 static void load_degamma_table(struct dc_hw *hw,
1264 const struct dc_hw_plane_reg *reg,
1265 u32 offset, u16 *table)
1270 dc_write(hw, reg->degamma_index + offset, 0);
1272 for (i = 0; i < DEGAMMA_SIZE; i++) {
1273 value = table[i] | (table[i] << 16);
1274 dc_write(hw, reg->degamma_data + offset, value);
1275 dc_write(hw, reg->degamma_ex_data + offset, table[i]);
1279 static u32 get_addr_offset(u32 id)
1284 case PRIMARY_PLANE_1:
1285 case OVERLAY_PLANE_1:
1288 case OVERLAY_PLANE_2:
1291 case OVERLAY_PLANE_3:
1301 int dc_hw_init(struct dc_hw *hw)
1303 u8 i, id, panel_num, layer_num;
1305 u32 revision = hi_read(hw, DC_HW_REVISION);
1306 u32 cid = hi_read(hw, DC_HW_CHIP_CID);
1307 const struct dc_hw_plane_reg *reg;
1330 hw->info = (struct vs_dc_info *)&dc_info[hw->rev];
1331 hw->func = (struct dc_hw_funcs *)&hw_func;
1333 layer_num = hw->info->layer_num;
1334 for (i = 0; i < layer_num; i++) {
1335 id = hw->info->planes[i].id;
1336 offset = get_addr_offset(id);
1337 if (id == PRIMARY_PLANE_0 || id == PRIMARY_PLANE_1)
1338 reg = &dc_plane_reg[0];
1340 reg = &dc_plane_reg[1];
1342 load_default_filter(hw, reg, offset);
1343 load_rgb_to_rgb(hw, reg, offset, RGB2RGB);
1347 panel_num = hw->info->panel_num;
1348 for (i = 0; i < panel_num; i++) {
1351 load_rgb_to_yuv(hw, offset, RGB2YUV);
1352 dc_write(hw, DC_DISPLAY_PANEL_CONFIG + offset, 0x111);
1354 offset = i ? DC_CURSOR_OFFSET : 0;
1355 dc_write(hw, DC_CURSOR_BACKGROUND + offset, 0x00FFFFFF);
1356 dc_write(hw, DC_CURSOR_FOREGROUND + offset, 0x00AAAAAA);
1363 void dc_hw_deinit(struct dc_hw *hw)
1368 void dc_hw_update_plane(struct dc_hw *hw, u8 id,
1369 struct dc_hw_fb *fb, struct dc_hw_scale *scale,
1370 struct dc_hw_position *pos, struct dc_hw_blend *blend)
1372 struct dc_hw_plane *plane = &hw->plane[id];
1376 if (fb->enable == false)
1377 plane->fb.enable = false;
1379 memcpy(&plane->fb, fb,
1380 sizeof(*fb) - sizeof(fb->dirty));
1381 plane->fb.dirty = true;
1384 memcpy(&plane->scale, scale,
1385 sizeof(*scale) - sizeof(scale->dirty));
1386 plane->scale.dirty = true;
1389 memcpy(&plane->pos, pos,
1390 sizeof(*pos) - sizeof(pos->dirty));
1391 plane->pos.dirty = true;
1394 memcpy(&plane->blend, blend,
1395 sizeof(*blend) - sizeof(blend->dirty));
1396 plane->blend.dirty = true;
1401 void dc_hw_update_degamma(struct dc_hw *hw, u8 id, u32 mode)
1403 struct dc_hw_plane *plane = &hw->plane[id];
1406 if (hw->info->planes[id].degamma_size) {
1407 plane->degamma.mode = mode;
1408 plane->degamma.dirty = true;
1410 plane->degamma.dirty = false;
1415 void dc_hw_update_roi(struct dc_hw *hw, u8 id, struct dc_hw_roi *roi)
1417 struct dc_hw_plane *plane = &hw->plane[id];
1420 memcpy(&plane->roi, roi, sizeof(*roi) - sizeof(roi->dirty));
1421 plane->roi.dirty = true;
1425 void dc_hw_update_colorkey(struct dc_hw *hw, u8 id,
1426 struct dc_hw_colorkey *colorkey)
1428 struct dc_hw_plane *plane = &hw->plane[id];
1431 memcpy(&plane->colorkey, colorkey,
1432 sizeof(*colorkey) - sizeof(colorkey->dirty));
1433 plane->colorkey.dirty = true;
1437 void dc_hw_update_qos(struct dc_hw *hw, struct dc_hw_qos *qos)
1439 memcpy(&hw->qos, qos, sizeof(*qos) - sizeof(qos->dirty));
1440 hw->qos.dirty = true;
1443 void dc_hw_update_cursor(struct dc_hw *hw, u8 id, struct dc_hw_cursor *cursor)
1445 memcpy(&hw->cursor[id], cursor, sizeof(*cursor) - sizeof(cursor->dirty));
1446 hw->cursor[id].dirty = true;
1449 void dc_hw_update_gamma(struct dc_hw *hw, u8 id, u16 index,
1450 u16 r, u16 g, u16 b)
1452 if (index >= hw->info->gamma_size)
1455 hw->gamma[id].gamma[index][0] = r;
1456 hw->gamma[id].gamma[index][1] = g;
1457 hw->gamma[id].gamma[index][2] = b;
1458 hw->gamma[id].dirty = true;
1461 void dc_hw_enable_gamma(struct dc_hw *hw, u8 id, bool enable)
1463 hw->gamma[id].enable = enable;
1464 hw->gamma[id].dirty = true;
1467 void dc_hw_enable_dump(struct dc_hw *hw, u32 addr, u32 pitch)
1469 dc_write(hw, 0x14F0, addr);
1470 dc_write(hw, 0x14E8, addr);
1471 dc_write(hw, 0x1500, pitch);
1472 dc_write(hw, 0x14F8, 0x30000);
1475 void dc_hw_disable_dump(struct dc_hw *hw)
1477 dc_write(hw, 0x14F8, 0x00);
1480 void dc_hw_setup_display(struct dc_hw *hw, struct dc_hw_display *display)
1482 u8 id = display->id;
1484 memcpy(&hw->display[id], display, sizeof(*display));
1486 hw->func->display(hw, display);
1489 void dc_hw_enable_interrupt(struct dc_hw *hw, bool enable)
1491 u8 id = 1;//display->id;
1494 if (hw->display[id].sync_enable)
1495 dc_set_clear(hw, DC_DISPLAY_PANEL_START, BIT(2) | BIT(3), 0);
1497 dc_set_clear(hw, DC_DISPLAY_PANEL_START, BIT(0), BIT(3));
1499 if (hw->out[id] == OUT_DPI)
1500 dc_set_clear(hw, DC_DISPLAY_PANEL_START, BIT(1), BIT(3));
1502 hi_write(hw, AQ_INTR_ENBL, 0xFFFFFFFF);
1504 hi_write(hw, AQ_INTR_ENBL, 0);
1508 u32 dc_hw_get_interrupt(struct dc_hw *hw)
1510 return hi_read(hw, AQ_INTR_ACKNOWLEDGE);
1513 bool dc_hw_check_underflow(struct dc_hw *hw)
1515 return dc_read(hw, DC_FRAMEBUFFER_CONFIG) & BIT(5);
1518 void dc_hw_enable_shadow_register(struct dc_hw *hw, bool enable)
1521 u8 id, layer_num = hw->info->layer_num;
1522 u8 panel_num = hw->info->panel_num;
1524 for (i = 0; i < layer_num; i++) {
1525 id = hw->info->planes[i].id;
1526 offset = get_addr_offset(id);
1528 if (id == PRIMARY_PLANE_0 || id == PRIMARY_PLANE_1)
1529 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX + offset, BIT(12), 0);
1531 dc_set_clear(hw, DC_OVERLAY_CONFIG + offset, BIT(31), 0);
1533 if (id == PRIMARY_PLANE_0 || id == PRIMARY_PLANE_1)
1534 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX + offset, 0, BIT(12));
1536 dc_set_clear(hw, DC_OVERLAY_CONFIG + offset, 0, BIT(31));
1540 for (i = 0; i < panel_num; i++) {
1543 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG_EX + offset, 0, BIT(0));
1545 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG_EX + offset, BIT(0), 0);
1549 void dc_hw_set_out(struct dc_hw *hw, enum dc_hw_out out, u8 id)
1555 static void gamma_ex_commit(struct dc_hw *hw)
1557 u8 panel_num = hw->info->panel_num;
1561 for (j = 0; j < panel_num; j++) {
1562 if (hw->gamma[j].dirty) {
1563 if (hw->gamma[j].enable) {
1564 dc_write(hw, DC_DISPLAY_GAMMA_EX_INDEX + (j << 2), 0x00);
1565 for (i = 0; i < GAMMA_EX_SIZE; i++) {
1566 value = hw->gamma[j].gamma[i][2] |
1567 (hw->gamma[j].gamma[i][1] << 12);
1568 dc_write(hw, DC_DISPLAY_GAMMA_EX_DATA + (j << 2), value);
1569 dc_write(hw, DC_DISPLAY_GAMMA_EX_ONE_DATA + (j << 2),
1570 hw->gamma[j].gamma[i][0]);
1572 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG + (j << 2),
1575 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG + (j << 2),
1578 hw->gamma[j].dirty = false;
1583 static void plane_commit(struct dc_hw *hw)
1585 struct dc_hw_plane *plane;
1586 const struct dc_hw_plane_reg *reg;
1587 bool primary = false;
1588 u8 id, layer_num = hw->info->layer_num;
1591 for (i = 0; i < layer_num; i++) {
1592 plane = &hw->plane[i];
1593 id = hw->info->planes[i].id;
1594 offset = get_addr_offset(id);
1595 if (id == PRIMARY_PLANE_0 || id == PRIMARY_PLANE_1) {
1596 reg = &dc_plane_reg[0];
1599 reg = &dc_plane_reg[1];
1603 if (plane->fb.dirty) {
1604 if (plane->fb.enable) {
1605 dc_write(hw, reg->y_address + offset,
1606 plane->fb.y_address);
1607 dc_write(hw, reg->u_address + offset,
1608 plane->fb.u_address);
1609 dc_write(hw, reg->v_address + offset,
1610 plane->fb.v_address);
1611 dc_write(hw, reg->y_stride + offset,
1612 plane->fb.y_stride);
1613 dc_write(hw, reg->u_stride + offset,
1614 plane->fb.u_stride);
1615 dc_write(hw, reg->v_stride + offset,
1616 plane->fb.v_stride);
1617 dc_write(hw, reg->size + offset,
1619 (plane->fb.height << 15));
1620 dc_write(hw, reg->water_mark + offset,
1621 plane->fb.water_mark);
1623 if (plane->fb.clear_enable)
1624 dc_write(hw, reg->clear_value + offset,
1625 plane->fb.clear_value);
1629 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG + offset,
1630 (plane->fb.format << 26) |
1631 (plane->fb.uv_swizzle << 25) |
1632 (plane->fb.swizzle << 23) |
1633 (plane->fb.tile_mode << 17) |
1634 (plane->fb.yuv_color_space << 14) |
1635 (plane->fb.rotation << 11) |
1636 (plane->fb.clear_enable << 8),
1644 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX + offset,
1645 (plane->fb.dec_enable << 1) |
1646 (plane->fb.enable << 13) |
1647 (plane->fb.zpos << 16) |
1648 (plane->fb.display_id << 19),
1649 BIT(1) | BIT(13) | (0x07 << 16) | BIT(19));
1651 dc_set_clear(hw, DC_OVERLAY_CONFIG + offset,
1652 (plane->fb.dec_enable << 27) |
1653 (plane->fb.clear_enable << 25) |
1654 (plane->fb.enable << 24) |
1655 (plane->fb.format << 16) |
1656 (plane->fb.uv_swizzle << 15) |
1657 (plane->fb.swizzle << 13) |
1658 (plane->fb.tile_mode << 8) |
1659 (plane->fb.yuv_color_space << 5) |
1660 (plane->fb.rotation << 2),
1670 dc_set_clear(hw, DC_OVERLAY_CONFIG_EX + offset,
1671 plane->fb.zpos | (plane->fb.display_id << 3),
1674 plane->fb.dirty = false;
1677 if (plane->scale.dirty) {
1678 if (plane->scale.enable) {
1679 dc_write(hw, reg->scale_factor_x + offset,
1680 plane->scale.scale_factor_x);
1681 dc_write(hw, reg->scale_factor_y + offset,
1682 plane->scale.scale_factor_y);
1685 DC_FRAMEBUFFER_CONFIG + offset,
1689 DC_OVERLAY_SCALE_CONFIG + offset,
1694 DC_FRAMEBUFFER_CONFIG + offset,
1698 DC_OVERLAY_SCALE_CONFIG + offset,
1701 plane->scale.dirty = false;
1704 if (plane->pos.dirty) {
1705 dc_write(hw, reg->top_left + offset,
1706 plane->pos.start_x |
1707 (plane->pos.start_y << 15));
1708 dc_write(hw, reg->bottom_right + offset,
1710 (plane->pos.end_y << 15));
1711 plane->pos.dirty = false;
1714 if (plane->blend.dirty) {
1715 dc_write(hw, reg->src_global_color + offset,
1716 plane->blend.alpha << 24);
1717 dc_write(hw, reg->dst_global_color + offset,
1718 plane->blend.alpha << 24);
1719 switch (plane->blend.blend_mode) {
1720 case BLEND_PREMULTI:
1721 dc_write(hw, reg->blend_config + offset, 0x3450);
1723 case BLEND_COVERAGE:
1724 dc_write(hw, reg->blend_config + offset, 0x3950);
1726 case BLEND_PIXEL_NONE:
1727 dc_write(hw, reg->blend_config + offset, 0x3548);
1732 plane->blend.dirty = false;
1735 if (plane->colorkey.dirty) {
1736 dc_write(hw, reg->color_key + offset, plane->colorkey.colorkey);
1737 dc_write(hw, reg->color_key_high + offset,
1738 plane->colorkey.colorkey_high);
1741 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG + offset,
1742 plane->colorkey.transparency << 9, 0x03 << 9);
1744 dc_set_clear(hw, DC_OVERLAY_CONFIG + offset,
1745 plane->colorkey.transparency, 0x03);
1747 plane->colorkey.dirty = false;
1750 if (plane->roi.dirty) {
1751 if (plane->roi.enable) {
1752 dc_write(hw, reg->roi_origin + offset,
1753 plane->roi.x | (plane->roi.y << 16));
1754 dc_write(hw, reg->roi_size + offset,
1755 plane->roi.width | (plane->roi.height << 16));
1757 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX + offset,
1760 dc_set_clear(hw, DC_OVERLAY_CONFIG + offset,
1764 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX + offset,
1767 dc_set_clear(hw, DC_OVERLAY_CONFIG + offset,
1770 plane->roi.dirty = false;
1775 static void plane_ex_commit(struct dc_hw *hw)
1777 struct dc_hw_plane *plane;
1778 const struct dc_hw_plane_reg *reg;
1779 bool primary = false;
1780 u8 id, layer_num = hw->info->layer_num;
1783 for (i = 0; i < layer_num; i++) {
1784 plane = &hw->plane[i];
1785 id = hw->info->planes[i].id;
1786 offset = get_addr_offset(id);
1787 if (id == PRIMARY_PLANE_0 || id == PRIMARY_PLANE_1) {
1788 reg = &dc_plane_reg[0];
1791 reg = &dc_plane_reg[1];
1795 if (plane->fb.dirty) {
1796 if (is_rgb(plane->fb.format)) {
1799 DC_FRAMEBUFFER_CONFIG_EX + offset,
1803 DC_OVERLAY_CONFIG + offset,
1808 DC_FRAMEBUFFER_CONFIG_EX + offset,
1812 DC_OVERLAY_CONFIG + offset,
1814 switch (plane->fb.yuv_color_space) {
1815 case COLOR_SPACE_601:
1816 load_yuv_to_rgb(hw, reg, offset, YUV601_2RGB);
1818 case COLOR_SPACE_709:
1819 load_yuv_to_rgb(hw, reg, offset, YUV709_2RGB);
1821 case COLOR_SPACE_2020:
1822 load_yuv_to_rgb(hw, reg, offset, YUV2020_2RGB);
1829 if (plane->degamma.dirty) {
1830 switch (plane->degamma.mode) {
1831 case VS_DEGAMMA_DISABLE:
1834 DC_FRAMEBUFFER_CONFIG_EX + offset,
1838 DC_OVERLAY_CONFIG + offset,
1841 case VS_DEGAMMA_BT709:
1842 load_degamma_table(hw, reg, offset, DEGAMMA_709);
1845 DC_FRAMEBUFFER_CONFIG_EX + offset,
1849 DC_OVERLAY_CONFIG + offset,
1852 case VS_DEGAMMA_BT2020:
1853 load_degamma_table(hw, reg, offset, DEGAMMA_2020);
1856 DC_FRAMEBUFFER_CONFIG_EX + offset,
1860 DC_OVERLAY_CONFIG + offset,
1866 plane->degamma.dirty = false;
1872 static void setup_display(struct dc_hw *hw, struct dc_hw_display *display)
1874 u8 id = display->id;
1875 u32 dpi_cfg, offset = id << 2;
1877 if (hw->display[id].enable) {
1878 switch (display->bus_format) {
1879 case MEDIA_BUS_FMT_RGB565_1X16:
1882 case MEDIA_BUS_FMT_RGB666_1X18:
1885 case MEDIA_BUS_FMT_RGB666_1X24_CPADHI:
1888 case MEDIA_BUS_FMT_RGB888_1X24:
1891 case MEDIA_BUS_FMT_RGB101010_1X30:
1898 dc_write(hw, DC_DISPLAY_DPI_CONFIG + offset, dpi_cfg);
1901 dc_set_clear(hw, DC_DISPLAY_PANEL_START, 0, BIT(0) | BIT(2));
1903 dc_set_clear(hw, DC_DISPLAY_PANEL_START, 0, BIT(1) | BIT(2));
1905 dc_write(hw, DC_DISPLAY_H + offset, hw->display[id].h_active |
1906 (hw->display[id].h_total << 16));
1907 dc_write(hw, DC_DISPLAY_H_SYNC + offset,
1908 hw->display[id].h_sync_start |
1909 (hw->display[id].h_sync_end << 15) |
1910 (hw->display[id].h_sync_polarity ? 0 : BIT(31)) |
1912 dc_write(hw, DC_DISPLAY_V + offset, hw->display[id].v_active |
1913 (hw->display[id].v_total << 16));
1914 dc_write(hw, DC_DISPLAY_V_SYNC + offset,
1915 hw->display[id].v_sync_start |
1916 (hw->display[id].v_sync_end << 15) |
1917 (hw->display[id].v_sync_polarity ? 0 : BIT(31)) |
1920 if (hw->info->pipe_sync) {
1921 switch (display->sync_mode) {
1923 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX,
1924 0, BIT(3) | BIT(4));
1926 case VS_MULTI_DC_PRIMARY:
1927 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX,
1928 BIT(3) | BIT(4), 0);
1930 case VS_MULTI_DC_SECONDARY:
1931 dc_set_clear(hw, DC_FRAMEBUFFER_CONFIG_EX,
1939 if (hw->info->background)
1940 dc_write(hw, DC_FRAMEBUFFER_BG_COLOR + offset,
1941 hw->display[id].bg_color);
1943 if (hw->display[id].dither_enable) {
1944 dc_write(hw, DC_DISPLAY_DITHER_TABLE_LOW + offset,
1945 DC_DISPLAY_DITHERTABLE_LOW);
1946 dc_write(hw, DC_DISPLAY_DITHER_TABLE_HIGH + offset,
1947 DC_DISPLAY_DITHERTABLE_HIGH);
1948 dc_write(hw, DC_DISPLAY_DITHER_CONFIG + offset, BIT(31));
1950 dc_write(hw, DC_DISPLAY_DITHER_CONFIG + offset, 0);
1953 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG + offset, BIT(12), 0);
1954 if (hw->display[id].sync_enable)
1955 dc_set_clear(hw, DC_DISPLAY_PANEL_START, BIT(2) | BIT(3), 0);
1957 dc_set_clear(hw, DC_DISPLAY_PANEL_START, BIT(0), BIT(3));
1959 if (hw->out[id] != OUT_DPI)
1960 dc_set_clear(hw, DC_DISPLAY_PANEL_START, BIT(1), BIT(3));
1962 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG + offset, 0, BIT(12));
1964 dc_set_clear(hw, DC_DISPLAY_PANEL_START, 0, BIT(0) | BIT(2));
1966 dc_set_clear(hw, DC_DISPLAY_PANEL_START, 0, BIT(1) | BIT(2));
1968 dc_set_clear(hw, DC_OVERLAY_CONFIG + 0x0, 0x0, BIT(24));
1969 dc_set_clear(hw, DC_OVERLAY_CONFIG + 0x4, 0x0, BIT(24));
1970 dc_set_clear(hw, DC_OVERLAY_CONFIG + 0x8, 0x0, BIT(24));
1971 dc_set_clear(hw, DC_OVERLAY_CONFIG + 0xc, 0x0, BIT(24));
1973 dc_set_clear(hw, DC_CURSOR_CONFIG + 0x0, BIT(3), 0x03);
1974 dc_set_clear(hw, DC_CURSOR_CONFIG + DC_CURSOR_OFFSET, BIT(3), 0x03);
1978 static void setup_display_ex(struct dc_hw *hw, struct dc_hw_display *display)
1980 u8 id = display->id;
1981 u32 dp_cfg, offset = id << 2;
1982 bool is_yuv = false;
1984 if (hw->display[id].enable && hw->out[id] == OUT_DP) {
1985 switch (display->bus_format) {
1986 case MEDIA_BUS_FMT_RGB565_1X16:
1989 case MEDIA_BUS_FMT_RGB666_1X18:
1992 case MEDIA_BUS_FMT_RGB888_1X24:
1995 case MEDIA_BUS_FMT_RGB101010_1X30:
1998 case MEDIA_BUS_FMT_UYVY8_1X16:
2002 case MEDIA_BUS_FMT_YUV8_1X24:
2006 case MEDIA_BUS_FMT_UYVY10_1X20:
2010 case MEDIA_BUS_FMT_YUV10_1X30:
2014 case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
2018 case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
2027 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG + offset, BIT(16), 0);
2029 dc_set_clear(hw, DC_DISPLAY_PANEL_CONFIG + offset, 0, BIT(16));
2030 dc_write(hw, DC_DISPLAY_DP_CONFIG + offset, dp_cfg | BIT(3));
2033 if (hw->out[id] == OUT_DPI)
2034 dc_set_clear(hw, DC_DISPLAY_DP_CONFIG + offset, 0, BIT(3));
2036 setup_display(hw, display);
2039 static const struct dc_hw_funcs hw_func = {
2040 .gamma = &gamma_ex_commit,
2041 .plane = &plane_ex_commit,
2042 .display = setup_display_ex,
2045 void dc_hw_commit(struct dc_hw *hw)
2048 u8 plane_num = hw->info->plane_num;
2049 u8 layer_num = hw->info->layer_num;
2050 u8 cursor_num = plane_num - layer_num;
2052 hw->func->gamma(hw);
2053 hw->func->plane(hw);
2055 for (i = 0; i < cursor_num; i++) {
2056 if (hw->cursor[i].dirty) {
2057 offset = hw->cursor[i].display_id ? DC_CURSOR_OFFSET : 0;
2058 if (hw->cursor[i].enable) {
2059 dc_write(hw, DC_CURSOR_ADDRESS + offset,
2060 hw->cursor[i].address);
2061 dc_write(hw, DC_CURSOR_LOCATION + offset, hw->cursor[i].x |
2062 (hw->cursor[i].y << 16));
2063 dc_set_clear(hw, DC_CURSOR_CONFIG + offset,
2064 (hw->cursor[i].hot_x << 16) |
2065 (hw->cursor[i].hot_y << 8) |
2066 (hw->cursor[i].size << 5) |
2067 BIT(3) | BIT(2) | 0x02,
2070 (0x07 << 5) | 0x1F);
2072 dc_set_clear(hw, DC_CURSOR_CONFIG + offset, BIT(3), 0x03);
2074 hw->cursor[i].dirty = false;
2078 if (hw->qos.dirty) {
2079 dc_set_clear(hw, DC_QOS_CONFIG, (hw->qos.high_value << 4) |
2080 hw->qos.low_value, 0xFF);
2081 hw->qos.dirty = false;
2085 #ifdef CONFIG_VERISILICON_DEC
2086 void dc_hw_dec_init(struct dc_hw *hw)
2090 config = DEC_CONTROL_RESET & (~COMPRESSION_DISABLE);
2091 dc_write(hw, DEC_CONTROL, config | FLUSH_ENABLE);
2093 config = DEC_CONTROL_EX2_RESET &
2094 (~TILE_STATUS_READ_ID_MASK) &
2095 (~TILE_STATUS_READ_ID_H_MASK) &
2096 (~DISABLE_HW_DEC_FLUSH);
2097 dc_write(hw, DEC_CONTROL_EX2,
2098 config | (TILE_STATUS_READ_ID_H << 22) |
2099 TILE_STATUS_READ_ID);
2101 config = DEC_CONTROL_EX_RESET &
2102 (~WRITE_MISS_POLICY_MASK) &
2103 (~READ_MISS_POLICY_MASK);
2104 dc_write(hw, DEC_CONTROL_EX, config | (WRITE_MISS_POLICY1 << 19));
2107 void dc_hw_dec_stream_set(struct dc_hw *hw, u32 main_base_addr,
2108 u32 ts_base_addr, u8 tile_mode, u8 align_mode,
2109 u8 format, u8 depth, u8 stream_id)
2111 u32 offset = stream_id << 2;
2113 dc_set_clear(hw, DEC_READ_CONFIG + offset,
2115 (align_mode << 16) |
2119 COMPRESSION_ALIGN_MODE_MASK |
2120 COMPRESSION_FORMAT_MASK);
2122 dc_set_clear(hw, DEC_READ_EX_CONFIG + offset,
2123 (depth << 16), BIT_DEPTH_MASK);
2125 dc_write(hw, DEC_READ_BUFFER_BASE + offset, main_base_addr);
2126 dc_write(hw, DEC_READ_BUFFER_END + offset, ts_base_addr - 128);
2127 dc_write(hw, DEC_READ_CACHE_BASE + offset, ts_base_addr);
2130 void dc_hw_dec_stream_disable(struct dc_hw *hw, u8 stream_id)
2132 u32 offset = stream_id << 2;
2134 dc_write(hw, DEC_READ_CONFIG + offset, DEC_READ_CONFIG_RESET);
2135 dc_write(hw, DEC_READ_BUFFER_BASE + offset, 0xFFFFFFFF);
2136 dc_write(hw, DEC_READ_BUFFER_END + offset, 0xFFFFFFFF);
2140 #ifdef CONFIG_VERISILICON_MMU
2141 static u32 mmu_read(struct dc_hw *hw, u32 reg)
2143 return readl(hw->mmu_base + reg - mmu_reg_base);
2146 static void mmu_write(struct dc_hw *hw, u32 reg, u32 value)
2148 writel(value, hw->mmu_base + reg - mmu_reg_base);
2151 static void mmu_set_clear(struct dc_hw *hw, u32 reg, u32 set, u32 clear)
2153 u32 value = mmu_read(hw, reg);
2157 mmu_write(hw, reg, value);
2160 int dc_hw_mmu_init(struct dc_hw *hw, dc_mmu_pt mmu)
2162 const struct dc_hw_mmu_reg *reg;
2163 u32 mtlb = 0, ext_mtlb = 0;
2164 u32 safe_addr = 0, ext_safe_addr = 0;
2169 mtlb = (u32)(mmu->mtlb_physical & 0xFFFFFFFF);
2170 ext_mtlb = (u32)(mmu->mtlb_physical >> 32);
2172 /* more than 40bit physical address */
2173 if (ext_mtlb & 0xFFFFFF00) {
2174 pr_err("Mtlb address out of range.\n");
2178 config = (ext_mtlb << 20) | (mtlb >> 12);
2179 if (mmu->mode == MMU_MODE_1K)
2180 mmu_set_clear(hw, reg->context_pd_entry,
2181 (config << 4) | BIT(0),
2182 (0xFFFFFFF << 4) | (0x07));
2184 mmu_set_clear(hw, reg->context_pd_entry,
2186 (0xFFFFFFF << 4) | (0x07));
2188 safe_addr = (u32)(mmu->safe_page_physical & 0xFFFFFFFF);
2189 ext_safe_addr = (u32)(mmu->safe_page_physical >> 32);
2191 if ((safe_addr & 0x3F) || (ext_safe_addr & 0xFFFFFF00)) {
2192 pr_err("Invalid safe_address.\n");
2196 mmu_write(hw, reg->table_array_size, 1);
2197 mmu_write(hw, reg->safe_secure, safe_addr);
2198 mmu_write(hw, reg->safe_non_secure, safe_addr);
2200 mmu_set_clear(hw, reg->safe_ex,
2201 (ext_safe_addr << 16) | ext_safe_addr,
2202 BIT(31) | (0xFF << 16) | BIT(15) | 0xFF);
2204 /* mmu configuration for ree driver */
2205 mmu_write(hw, reg->mmu_control, BIT(5) | BIT(0));
2207 mmu_write(hw, SE_MMU_REG_INTR_ENBL, 0xFFFFFFFF);
2212 void dc_hw_enable_mmu_prefetch(struct dc_hw *hw, bool enable)
2214 if (!hw->info->mmu_prefetch)
2218 dc_write(hw, DC_MMU_PREFETCH, BIT(0));
2220 dc_write(hw, DC_MMU_PREFETCH, 0);
2223 void dc_hw_mmu_flush(struct dc_hw *hw)
2225 const struct dc_hw_mmu_reg *reg = &dc_mmu_reg;
2226 u32 value = mmu_read(hw, reg->mmu_config);
2228 mmu_write(hw, reg->mmu_config, value | BIT(4));
2229 mmu_write(hw, reg->mmu_config, value);