xref: /rk3399_rockchip-uboot/drivers/video/drm/rockchip_display.h (revision 38fed2d628da74d6c21d2e0bfde6069e2c28ff73)
1 /*
2  * (C) Copyright 2008-2017 Fuzhou Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #ifndef _ROCKCHIP_DISPLAY_H
8 #define _ROCKCHIP_DISPLAY_H
9 
10 #ifdef CONFIG_SPL_BUILD
11 #include <linux/hdmi.h>
12 #include <linux/media-bus-format.h>
13 #else
14 #include <bmp_layout.h>
15 #include <edid.h>
16 #endif
17 #include <drm_modes.h>
18 #include <dm/ofnode.h>
19 #include <drm/drm_dsc.h>
20 #include <spl_display.h>
21 #include <clk.h>
22 #include <drm/drm_color_mgmt.h>
23 
24 /*
25  * major: IP major version, used for IP structure
26  * minor: big feature change under same structure
27  * build: RTL current SVN number
28  */
29 #define VOP_VERSION(major, minor)		((major) << 8 | (minor))
30 #define VOP_MAJOR(version)			((version) >> 8)
31 #define VOP_MINOR(version)			((version) & 0xff)
32 
33 #define VOP2_VERSION(major, minor, build)	((major) << 24 | (minor) << 16 | (build))
34 #define VOP2_MAJOR(version)			(((version) >> 24) & 0xff)
35 #define VOP2_MINOR(version)			(((version) >> 16) & 0xff)
36 #define VOP2_BUILD(version)			((version) & 0xffff)
37 
38 #define VOP_VERSION_RK3528			VOP2_VERSION(0x50, 0x17, 0x1263)
39 #define VOP_VERSION_RK3562			VOP2_VERSION(0x50, 0x17, 0x4350)
40 #define VOP_VERSION_RK3568			VOP2_VERSION(0x40, 0x15, 0x8023)
41 #define VOP_VERSION_RK3576			VOP2_VERSION(0x50, 0x19, 0x9765)
42 #define VOP_VERSION_RK3588			VOP2_VERSION(0x40, 0x17, 0x6786)
43 
44 #define ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE	BIT(0)
45 #define ROCKCHIP_OUTPUT_DUAL_CHANNEL_ODD_EVEN_MODE	BIT(1)
46 #define ROCKCHIP_OUTPUT_DATA_SWAP			BIT(2)
47 #define ROCKCHIP_OUTPUT_MIPI_DS_MODE			BIT(3)
48 
49 #define ROCKCHIP_DSC_PPS_SIZE_BYTE			88
50 
51 enum data_format {
52 	ROCKCHIP_FMT_ARGB8888 = 0,
53 	ROCKCHIP_FMT_RGB888,
54 	ROCKCHIP_FMT_RGB565,
55 	ROCKCHIP_FMT_YUV420SP = 4,
56 	ROCKCHIP_FMT_YUV422SP,
57 	ROCKCHIP_FMT_YUV444SP,
58 };
59 
60 enum display_mode {
61 	ROCKCHIP_DISPLAY_FULLSCREEN,
62 	ROCKCHIP_DISPLAY_CENTER,
63 };
64 
65 enum rockchip_cmd_type {
66 	CMD_TYPE_DEFAULT,
67 	CMD_TYPE_SPI,
68 	CMD_TYPE_MCU
69 };
70 
71 enum rockchip_mcu_cmd {
72 	MCU_WRCMD = 0,
73 	MCU_WRDATA,
74 	MCU_SETBYPASS,
75 };
76 
77 /*
78  * display output interface supported by rockchip lcdc
79  */
80 #define ROCKCHIP_OUT_MODE_P888		0
81 #define ROCKCHIP_OUT_MODE_BT1120	0
82 #define ROCKCHIP_OUT_MODE_P666		1
83 #define ROCKCHIP_OUT_MODE_P565		2
84 #define ROCKCHIP_OUT_MODE_BT656		5
85 #define ROCKCHIP_OUT_MODE_S666		9
86 #define ROCKCHIP_OUT_MODE_S888		8
87 #define ROCKCHIP_OUT_MODE_YUV422	9
88 #define ROCKCHIP_OUT_MODE_S565		10
89 #define ROCKCHIP_OUT_MODE_S888_DUMMY	12
90 #define ROCKCHIP_OUT_MODE_YUV420	14
91 /* for use special outface */
92 #define ROCKCHIP_OUT_MODE_AAAA		15
93 
94 #define VOP_OUTPUT_IF_RGB	BIT(0)
95 #define VOP_OUTPUT_IF_BT1120	BIT(1)
96 #define VOP_OUTPUT_IF_BT656	BIT(2)
97 #define VOP_OUTPUT_IF_LVDS0	BIT(3)
98 #define VOP_OUTPUT_IF_LVDS1	BIT(4)
99 #define VOP_OUTPUT_IF_MIPI0	BIT(5)
100 #define VOP_OUTPUT_IF_MIPI1	BIT(6)
101 #define VOP_OUTPUT_IF_eDP0	BIT(7)
102 #define VOP_OUTPUT_IF_eDP1	BIT(8)
103 #define VOP_OUTPUT_IF_DP0	BIT(9)
104 #define VOP_OUTPUT_IF_DP1	BIT(10)
105 #define VOP_OUTPUT_IF_HDMI0	BIT(11)
106 #define VOP_OUTPUT_IF_HDMI1	BIT(12)
107 #define VOP_OUTPUT_IF_DP2	BIT(13)
108 
109 struct rockchip_mcu_timing {
110 	int mcu_pix_total;
111 	int mcu_cs_pst;
112 	int mcu_cs_pend;
113 	int mcu_rw_pst;
114 	int mcu_rw_pend;
115 	int mcu_hold_mode;
116 };
117 
118 struct vop_rect {
119 	int width;
120 	int height;
121 };
122 
123 struct vop_urgency {
124 	u8 urgen_thl;
125 	u8 urgen_thh;
126 };
127 
128 struct rockchip_dsc_sink_cap {
129 	/**
130 	 * @slice_width: the number of pixel columns that comprise the slice width
131 	 * @slice_height: the number of pixel rows that comprise the slice height
132 	 * @block_pred: Does block prediction
133 	 * @native_420: Does sink support DSC with 4:2:0 compression
134 	 * @bpc_supported: compressed bpc supported by sink : 10, 12 or 16 bpc
135 	 * @version_major: DSC major version
136 	 * @version_minor: DSC minor version
137 	 * @target_bits_per_pixel_x16: bits num after compress and multiply 16
138 	 */
139 	u16 slice_width;
140 	u16 slice_height;
141 	bool block_pred;
142 	bool native_420;
143 	u8 bpc_supported;
144 	u8 version_major;
145 	u8 version_minor;
146 	u16 target_bits_per_pixel_x16;
147 };
148 
149 struct display_rect {
150 	int x;
151 	int y;
152 	int w;
153 	int h;
154 };
155 
156 struct bcsh_state {
157 	int brightness;
158 	int contrast;
159 	int saturation;
160 	int sin_hue;
161 	int cos_hue;
162 };
163 
164 struct crtc_state {
165 	struct udevice *dev;
166 	struct rockchip_crtc *crtc;
167 	void *private;
168 	ofnode node;
169 	struct device_node *ports_node; /* if (ports_node) it's vop2; */
170 	struct clk dclk;
171 	int crtc_id;
172 
173 	int format;
174 	u32 dma_addr;
175 	int ymirror;
176 	int rb_swap;
177 	int xvir;
178 	int post_csc_mode;
179 	int dclk_core_div;
180 	int dclk_out_div;
181 	struct display_rect src_rect;
182 	struct display_rect crtc_rect;
183 	struct display_rect right_src_rect;
184 	struct display_rect right_crtc_rect;
185 	bool yuv_overlay;
186 	bool post_r2y_en;
187 	bool post_y2r_en;
188 	bool bcsh_en;
189 	bool splice_mode;
190 	bool soft_te;
191 	u8 splice_crtc_id;
192 	u8 dsc_id;
193 	u8 dsc_enable;
194 	u8 dsc_slice_num;
195 	u8 dsc_pixel_num;
196 	struct rockchip_mcu_timing mcu_timing;
197 	u32 dual_channel_swap;
198 	u32 feature;
199 	struct vop_rect max_output;
200 
201 	u64 dsc_txp_clk_rate;
202 	u64 dsc_pxl_clk_rate;
203 	u64 dsc_cds_clk_rate;
204 	struct drm_dsc_picture_parameter_set pps;
205 	struct rockchip_dsc_sink_cap dsc_sink_cap;
206 };
207 
208 struct panel_state {
209 	struct rockchip_panel *panel;
210 
211 	ofnode dsp_lut_node;
212 };
213 
214 struct overscan {
215 	int left_margin;
216 	int right_margin;
217 	int top_margin;
218 	int bottom_margin;
219 };
220 
221 struct connector_state {
222 	struct rockchip_connector *connector;
223 	struct rockchip_connector *secondary;
224 
225 	struct drm_display_mode mode;
226 	struct overscan overscan;
227 	u8 edid[EDID_SIZE * 4];
228 	int bus_format;
229 	u32 bus_flags;
230 	int output_mode;
231 	int type;
232 	int output_if;
233 	int output_flags;
234 	enum drm_color_encoding color_encoding;
235 	enum drm_color_range color_range;
236 	unsigned int bpc;
237 
238 	/**
239 	 * @hold_mode: enabled when it's:
240 	 * (1) mcu hold mode
241 	 * (2) mipi dsi cmd mode
242 	 * (3) edp psr mode
243 	 */
244 	bool hold_mode;
245 
246 	struct base2_disp_info *disp_info; /* disp_info from baseparameter 2.0 */
247 
248 	u8 dsc_id;
249 	u8 dsc_slice_num;
250 	u8 dsc_pixel_num;
251 	u64 dsc_txp_clk;
252 	u64 dsc_pxl_clk;
253 	u64 dsc_cds_clk;
254 	struct rockchip_dsc_sink_cap dsc_sink_cap;
255 	struct drm_dsc_picture_parameter_set pps;
256 
257 	struct gpio_desc *te_gpio;
258 
259 	struct {
260 		u32 *lut;
261 		int size;
262 	} gamma;
263 };
264 
265 struct logo_info {
266 	int mode;
267 	int rotate;
268 	char *mem;
269 	bool ymirror;
270 	u32 offset;
271 	u32 width;
272 	int height;
273 	u32 bpp;
274 };
275 
276 struct rockchip_logo_cache {
277 	struct list_head head;
278 	char name[20];
279 	struct logo_info logo;
280 	int logo_rotate;
281 };
282 
283 struct display_state {
284 	struct list_head head;
285 
286 	const void *blob;
287 	ofnode node;
288 
289 	struct crtc_state crtc_state;
290 	struct connector_state conn_state;
291 	struct panel_state panel_state;
292 
293 	char ulogo_name[30];
294 	char klogo_name[30];
295 
296 	struct logo_info logo;
297 	int logo_mode;
298 	int charge_logo_mode;
299 	int logo_rotate;
300 	void *mem_base;
301 	int mem_size;
302 
303 	int enable;
304 	int is_init;
305 	int is_enable;
306 	bool is_klogo_valid;
307 	bool force_output;
308 	bool enabled_at_spl;
309 	struct drm_display_mode force_mode;
310 	u32 force_bus_format;
311 };
312 
313 int drm_mode_vrefresh(const struct drm_display_mode *mode);
314 int display_send_mcu_cmd(struct display_state *state, u32 type, u32 val);
315 bool drm_mode_is_420(const struct drm_display_info *display,
316 		     struct drm_display_mode *mode);
317 struct base2_disp_info *rockchip_get_disp_info(int type, int id);
318 
319 void drm_mode_max_resolution_filter(struct hdmi_edid_data *edid_data,
320 				    struct vop_rect *max_output);
321 unsigned long get_cubic_lut_buffer(int crtc_id);
322 int rockchip_ofnode_get_display_mode(ofnode node, struct drm_display_mode *mode,
323 				     u32 *bus_flags);
324 void rockchip_display_make_crc32_table(void);
325 uint32_t rockchip_display_crc32c_cal(unsigned char *data, int length);
326 void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags);
327 
328 int display_rect_calc_hscale(struct display_rect *src, struct display_rect *dst,
329 			     int min_hscale, int max_hscale);
330 int display_rect_calc_vscale(struct display_rect *src, struct display_rect *dst,
331 			     int min_vscale, int max_vscale);
332 const struct device_node *
333 rockchip_of_graph_get_endpoint_by_regs(ofnode node, int port, int endpoint);
334 const struct device_node *
335 rockchip_of_graph_get_port_by_id(ofnode node, int id);
336 uint32_t rockchip_drm_get_cycles_per_pixel(uint32_t bus_format);
337 char* rockchip_get_output_if_name(u32 output_if, char *name);
338 
339 #ifdef CONFIG_SPL_BUILD
340 int rockchip_spl_vop_probe(struct crtc_state *crtc_state);
341 int rockchip_spl_dw_hdmi_probe(struct connector_state *conn_state);
342 int inno_spl_hdmi_phy_probe(struct display_state *state);
343 #endif
344 #endif
345