1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef __SAMSUNG_DRM_H__
3 #define __SAMSUNG_DRM_H__
4 
5 #if defined(__linux__)
6 #include <linux/types.h>
7 #endif
8 
9 #include "drm.h"
10 
11 #if defined(__cplusplus)
12 extern "C" {
13 #endif
14 
15 #define DRM_SAMSUNG_HDR_EOTF_LUT_LEN	129
16 
17 /**
18  * struct hdr_eotf_lut - HDR EOTF look up table to set by user-space
19  *
20  * @posx: x coordinate of the boundaries between segments in EOTF
21  * @posy: y coordinate of the boundaries between segments in EOTF
22  *
23  * A hdr_eotf_lut represents a look up table of EOTF(Electro-Optical Transfer
24  * Function). It is used for eotf_lut blob property of a plane object if
25  * a plane supports HDR10 feature.
26  */
27 struct hdr_eotf_lut {
28 	__u16 posx[DRM_SAMSUNG_HDR_EOTF_LUT_LEN];
29 	__u32 posy[DRM_SAMSUNG_HDR_EOTF_LUT_LEN];
30 };
31 
32 #define DRM_SAMSUNG_HDR_OETF_LUT_LEN	33
33 
34 /**
35  * struct hdr_oetf_lut - HDR OETF look up table to set by user-space
36  *
37  * @posx: x coordinate of the boundaries between segments in OETF
38  * @posy: y coordinate of the boundaries between segments in OETF
39  *
40  * A hdr_oetf_lut represents a look up table of OETF(Optical-Electro Transfer
41  * Function). It is used for oetf_lut blob property of a plane object if
42  * a plane supports HDR10 feature.
43  */
44 struct hdr_oetf_lut {
45 	__u16 posx[DRM_SAMSUNG_HDR_OETF_LUT_LEN];
46 	__u16 posy[DRM_SAMSUNG_HDR_OETF_LUT_LEN];
47 };
48 
49 #define DRM_SAMSUNG_HDR_GM_DIMENS	3
50 
51 /**
52  * struct hdr_gm_data - HDR gammut matrix data to set by user-space
53  *
54  * @coeffs: coefficients of a gammut matrix
55  * @offsets: offsets of a gammut matrix
56  *
57  * A hdr_gm_data represents coefficients and offsets of a gammut matrix.
58  * It is used to set a plane property for calculating a gammut matrix
59  * if a plane supports HDR10 feature.
60  */
61 struct hdr_gm_data {
62 	__u32 coeffs[DRM_SAMSUNG_HDR_GM_DIMENS * DRM_SAMSUNG_HDR_GM_DIMENS];
63 	__u32 offsets[DRM_SAMSUNG_HDR_GM_DIMENS];
64 };
65 
66 #define DRM_SAMSUNG_HDR_TM_LUT_LEN		33
67 
68 /**
69  * struct hdr_tm_data - HDR tone mapping data and look up table to set
70  *                      by user-space.
71  *
72  * @coeff_r: coefficient to be multiplied with R to convert RGB to Y
73  * @coeff_g: coefficient to be multiplied with G to convert RGB to Y
74  * @coeff_b: coefficient to be multiplied with B to convert RGB to Y
75  * @rng_x_min: left boundary of the decreasing range of the ratio function
76  *             for adaptive mixing
77  * @rng_x_max: right boundary of the decreasing range of the ratio function
78  *             for adaptive mixing
79  * @rng_y_min: minimum ratio for adaptive mixing.
80  * @rng_y_max: maximum ratio for adaptive mixing.
81  * @posx: x coordinate of the boundaries between segments in tone mapping
82  *        gain function.
83  * @posy: y coordinate of the boundaries between segments in tone mapping
84  *        gain function.
85  *
86  * A hdr_tm_data represents tone mapping data. It is used to set a plane
87  * property for calculating tone mapping if a plane supports HDR10+ feature.
88  */
89 struct hdr_tm_data {
90 	__u16 coeff_r;
91 	__u16 coeff_g;
92 	__u16 coeff_b;
93 	__u16 rng_x_min;
94 	__u16 rng_x_max;
95 	__u16 rng_y_min;
96 	__u16 rng_y_max;
97 	__u16 posx[DRM_SAMSUNG_HDR_TM_LUT_LEN];
98 	__u32 posy[DRM_SAMSUNG_HDR_TM_LUT_LEN];
99 };
100 
101 #define DRM_SAMSUNG_CGC_LUT_REG_CNT	2457
102 
103 /**
104  * struct cgc_lut - color gammut control look up table to set by user-space
105  *
106  * @r_values: values for red color
107  * @g_values: values for green color
108  * @b_values: values for blue color
109  *
110  * A cgc_lut represents a look up table of color gammut control. It is used
111  * for cgc_lut blob property of a crtc object if a crtc support color gammut
112  * control.
113  */
114 struct cgc_lut {
115 	__u32 r_values[DRM_SAMSUNG_CGC_LUT_REG_CNT];
116 	__u32 g_values[DRM_SAMSUNG_CGC_LUT_REG_CNT];
117 	__u32 b_values[DRM_SAMSUNG_CGC_LUT_REG_CNT];
118 };
119 
120 #define DRM_SAMSUNG_CGC_DMA_LUT_ENTRY_CNT 4913
121 /**
122  * struct cgc_dma_lut - color gammut control format for cgc dma to set by user-space
123  *
124  * @r_value: value for red color
125  * @g_value: value for green color
126  * @b_value: value for blue color
127  *
128  * A cgc_dma_lut represents a format to support cgc dma. cgc coefficients should be
129  * located in dram according to this format.
130  */
131 struct cgc_dma_lut {
132 	__u16 r_value;
133 	__u16 g_value;
134 	__u16 b_value;
135 };
136 
137 #define DRM_SAMSUNG_MATRIX_DIMENS	3
138 
139 /**
140  * struct exynos_matrix - a matrix data to set by user-space
141  *
142  * @coeffs: coefficients of a matrix
143  * @offsets: offsets of a matrix
144  *
145  * A exynos_matrix represents coefficients and offsets of a matrix.
146  * It is used to set a property for calculating a matrix.
147  */
148 struct exynos_matrix {
149 	__u16 coeffs[DRM_SAMSUNG_MATRIX_DIMENS * DRM_SAMSUNG_MATRIX_DIMENS];
150 	__u16 offsets[DRM_SAMSUNG_MATRIX_DIMENS];
151 };
152 
153 struct dpp_size_range {
154 	__u32 min;
155 	__u32 max;
156 	__u32 align;
157 };
158 
159 struct dpp_restriction {
160 	struct dpp_size_range src_f_w;
161 	struct dpp_size_range src_f_h;
162 	struct dpp_size_range src_w;
163 	struct dpp_size_range src_h;
164 	__u32 src_x_align;
165 	__u32 src_y_align;
166 
167 	struct dpp_size_range dst_f_w;
168 	struct dpp_size_range dst_f_h;
169 	struct dpp_size_range dst_w;
170 	struct dpp_size_range dst_h;
171 	__u32 dst_x_align;
172 	__u32 dst_y_align;
173 
174 	struct dpp_size_range blk_w;
175 	struct dpp_size_range blk_h;
176 	__u32 blk_x_align;
177 	__u32 blk_y_align;
178 
179 	__u32 src_h_rot_max; /* limit of source img height in case of rotation */
180 
181 	__u32 scale_down;
182 	__u32 scale_up;
183 };
184 
185 struct dpp_ch_restriction {
186 	__s32 id;
187 	__u64 attr;
188 	struct dpp_restriction restriction;
189 };
190 
191 /**
192  * struct dither_config - a dither configuration data to set by user-space
193  *
194  * @en: enable or disable a dither
195  * @mode: 0 for dither, 1 for 2bits shift
196  * @frame_con: If frame control is on, the temporal dither is used. Otherwise,
197  *	       the spatial dither is used. If temporal dither is used, a
198  *	       different dither mask can be used for each frame counter.
199  * @frame_offset: The dithers in DQE use same frame counter. However, if two
200  *		  dithers set a different frame offsets, each dither can select
201  *		  a different dither mask according to the different frame
202  *		  counter + offset.
203  * @table_sel_r/g/b: It can select a different dither mask for each channel.
204  *
205  * A dither_config represents the information necessary for setting up the
206  * dither in DQE. It is used to set a property of a crtc for dither
207  * configuration.
208  */
209 struct dither_config {
210 	__u8 en:1;
211 	__u8 mode:1;
212 	__u8 frame_con:1;
213 	__u8 frame_offset:2;
214 	__u8 table_sel_r:1;
215 	__u8 table_sel_g:1;
216 	__u8 table_sel_b:1;
217 	__u32 reserved:24;
218 };
219 
220 struct attribute_range {
221 	__u32 min;
222 	__u32 max;
223 };
224 
225 /**
226  * struct brightness_attribute - brightness attribute data
227  *
228  * @nits: value represents brightness nits range
229  * @level: value represents panel brightness level range
230  * @percentage: value must be between 0 and 100 and be non-decreasing.
231  *		This percentage must comply with display configuration
232  *		file.
233  *
234  * A brightness_attribute represents brightness attribute data.
235  */
236 struct brightness_attribute {
237 	struct attribute_range nits;
238 	struct attribute_range level;
239 	struct attribute_range percentage;
240 };
241 
242 /**
243  * struct brightness_capability - brightness capability query by user-space
244  *
245  * @normal: normal rerepresents the normal brightness attribute.
246  * @hbm: hbm represents the hbm brightness attribute
247  *
248  * A brightness_capability represents normal/hbm brightness attribute. It is
249  * used to query connector property.
250  */
251 struct brightness_capability {
252 	struct brightness_attribute normal;
253 	struct brightness_attribute hbm;
254 };
255 
256 /**
257  * struct tui_hw_buffer - buffer allocation query by user-space
258  *
259  * @fb_physical: the physical address of the buffer allocated
260  * @fb_size: the size of the buffer allocated
261  *
262  * The structure is used to return the parameter of the allocated buffer.
263  */
264 struct tui_hw_buffer {
265 	__u64 fb_physical;
266 	__u64 fb_size;
267 } __attribute__((packed));
268 
269 #define EXYNOS_START_TUI	0x10
270 #define EXYNOS_FINISH_TUI	0x11
271 #define EXYNOS_TUI_REQUEST_BUFFER	0x20
272 #define EXYNOS_TUI_RELEASE_BUFFER	0x21
273 
274 /**
275  * struct histogram_roi - region of interest for histogram to set by user-space
276  *
277  * @start_x: upper left x position of ROI
278  * @start_y: upper left y position of ROI
279  * @hsize: horizontal size of image
280  * @vsize: vertical  size of image
281  *
282  * A histogram_roi sets region of interest on image for gathering histogram
283  * data. It is used to set a property of a crtc.
284  */
285 struct histogram_roi {
286 	__u16 start_x;
287 	__u16 start_y;
288 	__u16 hsize;
289 	__u16 vsize;
290 };
291 
292 /**
293  * struct histogram_weights - weight for each color component to set by user-space
294  *
295  * @weight_r: histogram weight for red
296  * @weight_g: histogram weight for green
297  * @weight_b: histogram weight for blue
298  *
299  * A histogram_weights sets a weight of each color component for calculating
300  * histogram data. It is used to set a property of a crtc.
301  */
302 struct histogram_weights {
303 	__u16 weight_r;
304 	__u16 weight_g;
305 	__u16 weight_b;
306 };
307 
308 #define HISTOGRAM_BIN_COUNT	256
309 struct histogram_bins {
310 	__u16 data[HISTOGRAM_BIN_COUNT];
311 };
312 
313 #define EXYNOS_DRM_HISTOGRAM_EVENT	0x80000000
314 
315 /**
316  * struct exynos_drm_histogram_event - histogram event to wait for user-space
317  *
318  * @base: event header which informs user space event type and length.
319  * @bins: histogram bin data to be sent to user space through using read()
320  *
321  * User space waits for POLLIN event using like poll() or select(). If event
322  * type is EXYNOS_DRM_HISTOGRAM_EVENT, user space can try to read histogram
323  * bin data through "bins".
324  */
325 struct exynos_drm_histogram_event {
326 	struct drm_event base;
327 	struct histogram_bins bins;
328 	__u32 crtc_id;
329 };
330 
331 /**
332  * enum exynos_prog_pos - defines programmable positions
333  *
334  * For example, histogram position and writeback path could be
335  * programmable. This enum defines positions for it.
336  */
337 enum exynos_prog_pos {
338 	POST_DQE,
339 	PRE_DQE,
340 };
341 
342 #define EXYNOS_HISTOGRAM_REQUEST	0x0
343 #define EXYNOS_HISTOGRAM_CANCEL		0x1
344 
345 #define DRM_IOCTL_EXYNOS_HISTOGRAM_REQUEST	DRM_IOW(DRM_COMMAND_BASE + \
346 		EXYNOS_HISTOGRAM_REQUEST, __u32)
347 #define DRM_IOCTL_EXYNOS_HISTOGRAM_CANCEL	DRM_IOW(DRM_COMMAND_BASE + \
348 		EXYNOS_HISTOGRAM_CANCEL, __u32)
349 
350 #if defined(__cplusplus)
351 }
352 #endif
353 
354 #endif /* __SAMSUNG_DRM_H__ */
355