1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef __MTKFB_H
17 #define __MTKFB_H
18 
19 #include <linux/types.h>
20 #include "mtkfb_info.h"
21 
22 
23 /**NOTICE:
24  * Must be consistent with bionic/libc/kernel/linux/common/mtkfb.h
25  */
26 #define MTK_FB_NO_ION_FD                 ((int)(~0U>>1))
27 #define MTK_FB_NO_USE_LAEYR_ID			 ((int)(~0U>>1))
28 #define FBCAPS_GENERIC_MASK              (0x00000fff)
29 #define FBCAPS_LCDC_MASK                 (0x00fff000)
30 #define FBCAPS_PANEL_MASK                (0xff000000)
31 #define FBCAPS_MANUAL_UPDATE             (0x00001000)
32 #define FBCAPS_SET_BACKLIGHT             (0x01000000)
33 #define MTKFB_ERROR_IS_EARLY_SUSPEND     (0x12000000)
34 /* --------------------------------------------------------------------------- */
35 /* IOCTL commands. */
36 #define MTK_IOW(num, dtype)     _IOW('O', num, dtype)
37 #define MTK_IOR(num, dtype)     _IOR('O', num, dtype)
38 #define MTK_IOWR(num, dtype)    _IOWR('O', num, dtype)
39 #define MTK_IO(num)             _IO('O', num)
40 #define MTKFB_QUEUE_OVERLAY_CONFIG			MTK_IOW(137, struct fb_overlay_config)
41 /* -------------------------------------------------------------------------- */
42 #define MTKFB_SET_OVERLAY_LAYER                MTK_IOW(0, struct fb_overlay_layer)
43 #define MTKFB_TRIG_OVERLAY_OUT                 MTK_IO(1)
44 #define MTKFB_SET_VIDEO_LAYERS                 MTK_IOW(2, struct fb_overlay_layer)
45 #define MTKFB_CAPTURE_FRAMEBUFFER              MTK_IOW(3, unsigned long)
46 #define MTKFB_CONFIG_IMMEDIATE_UPDATE          MTK_IOW(4, unsigned long)
47 #define MTKFB_SET_MULTIPLE_LAYERS              MTK_IOW(5, struct fb_overlay_layer)
48 #define MTKFB_REGISTER_OVERLAYBUFFER           MTK_IOW(6, struct fb_overlay_buffer_info)
49 #define MTKFB_UNREGISTER_OVERLAYBUFFER         MTK_IOW(7, unsigned int)
50 #define MTKFB_SET_ORIENTATION                  MTK_IOW(8, unsigned long)
51 #define MTKFB_FBLAYER_ENABLE                   MTK_IOW(9, unsigned int)
52 #define MTKFB_LOCK_FRONT_BUFFER                MTK_IO(10)
53 #define MTKFB_UNLOCK_FRONT_BUFFER              MTK_IO(11)
54 #define MTKFB_POWERON				           MTK_IO(12)
55 #define MTKFB_POWEROFF				           MTK_IO(13)
56 
57 /* Fence/Ion, OVL decoupling */
58 #define MTKFB_PREPARE_OVERLAY_BUFFER           MTK_IOW(14, struct fb_overlay_buffer)
59 
60 /* S3D control */
61 #define MTKFB_SET_COMPOSING3D                  MTK_IOW(15, unsigned long)
62 #define MTKFB_SET_S3D_FTM		               MTK_IOW(16, unsigned long)
63 
64 /* FM De-sense for EM and Normal mode */
65 #define MTKFB_GET_DEFAULT_UPDATESPEED          MTK_IOR(17, unsigned long)
66 #define MTKFB_GET_CURR_UPDATESPEED             MTK_IOR(18, unsigned long)
67 /* for EM, not called change writecycle because DPI change pll ckl */
68 #define MTKFB_CHANGE_UPDATESPEED               MTK_IOW(19, unsigned long)
69 #define MTKFB_GET_INTERFACE_TYPE               MTK_IOR(20, unsigned long)	/* /0 DBI, 1 DPI, 2 MIPI */
70 #define MTKFB_GET_POWERSTATE		           MTK_IOR(21, unsigned long)	/* /0: power off  1: power on */
71 #define MTKFB_GET_DISPLAY_IF_INFORMATION       MTK_IOR(22, mtk_dispif_info_t)
72 /*called before SET_OVERLAY each time, if true, hwc will not use FB_LAYER again*/
73 #define MTKFB_AEE_LAYER_EXIST                  MTK_IOR(23, unsigned long)
74 #define MTKFB_GET_OVERLAY_LAYER_INFO           MTK_IOR(24, struct fb_overlay_layer_info)
75 #define MTKFB_FACTORY_AUTO_TEST                MTK_IOR(25, unsigned long)
76 #define MTKFB_GET_FRAMEBUFFER_MVA              MTK_IOR(26, unsigned int)
77 #define MTKFB_SLT_AUTO_CAPTURE                 MTK_IOWR(27, struct fb_slt_catpure)
78 
79 /*error handling*/
80 #define MTKFB_META_RESTORE_SCREEN              MTK_IOW(101, unsigned long)
81 #define MTKFB_ERROR_INDEX_UPDATE_TIMEOUT       MTK_IO(103)
82 #define MTKFB_ERROR_INDEX_UPDATE_TIMEOUT_AEE   MTK_IO(104)
83 
84 /*restore bootlogo and character in meta mode*/
85 #define MTKFB_META_SHOW_BOOTLOGO               MTK_IO(105)
86 
87 /*Extension FB active option*/
88 #define FB_ACTIVATE_NO_UPDATE  512       /* Skip frame update */
89 /**
90  * Just for mt6589 Platform
91  * @{
92  */
93 #define MTKFB_GETVFRAMEPHYSICAL                MTK_IOW(41, unsigned long)
94 #define MTKFB_WAIT_OVERLAY_READY               MTK_IO(42)
95 #define MTKFB_GET_OVERLAY_LAYER_COUNT          MTK_IOR(43, unsigned long)
96 #define MTKFB_GET_VIDEOLAYER_SIZE              MTK_IOR(44, struct fb_overlay_layer)
97 #define MTKFB_CAPTURE_VIDEOBUFFER              MTK_IOW(45, unsigned long)
98 
99 /* -------------------------------------------------------------------------- */
100 /* Video Playback Mode */
101 #define MTKFB_TV_POST_VIDEO_BUFFER             MTK_IOW(46, unsigned long)
102 #define MTKFB_TV_LEAVE_VIDEO_PLAYBACK_MODE     MTK_IOW(47, unsigned long)
103 /* For Factory Mode */
104 #define MTKFB_IS_TV_CABLE_PLUG_IN              MTK_IOW(48, unsigned long)
105 
106 /* -------------------------------------------------------------------------- */
107 #define MTKFB_BOOTANIMATION			           MTK_IO(49)
108 #define MTKFB_GETFPS			               MTK_IOW(50, unsigned long)
109 #define MTKFB_VSYNC                            MTK_IO(51)
110 
111 /* ----------------------------------------------------------------------FM De-sense for EM and Normal mode */
112 #define MTKFB_FM_NOTIFY_FREQ                   MTK_IOW(52, unsigned long)	/* for Normal mode */
113 #define MTKFB_RESET_UPDATESPEED                MTK_IO(53)
114 #define MTKFB_SET_UI_LAYER_ALPHA               MTK_IOW(54, unsigned long)
115 #define MTKFB_SET_UI_LAYER_SRCKEY              MTK_IOW(55, unsigned long)
116 
117 #define MTKFB_GET_MAX_DISPLAY_COUNT		       MTK_IOR(56, unsigned int)
118 #define MTKFB_SET_FB_LAYER_SECURE              MTK_IOW(57, int)
119 /**
120  * @}
121  */
122 /* ---------------------------------------------------------------------- */
123 
124 /* -------------------------------------------------------------------------- */
125 
126 typedef enum {
127 	MTK_FB_ORIENTATION_0 = 0,
128 	MTK_FB_ORIENTATION_90 = 1,
129 	MTK_FB_ORIENTATION_180 = 2,
130 	MTK_FB_ORIENTATION_270 = 3,
131 } MTK_FB_ORIENTATION;
132 
133 
134 typedef enum {
135 	MTK_FB_TV_SYSTEM_NTSC = 0,
136 	MTK_FB_TV_SYSTEM_PAL = 1,
137 } MTK_FB_TV_SYSTEM;
138 
139 
140 typedef enum {
141 	MTK_FB_TV_FMT_RGB565 = 0,
142 	MTK_FB_TV_FMT_YUV420_SEQ = 1,
143 	MTK_FB_TV_FMT_UYUV422 = 2,
144 	MTK_FB_TV_FMT_YUV420_BLK = 3,
145 } MTK_FB_TV_SRC_FORMAT;
146 
147 typedef enum {
148 	LAYER_NORMAL_BUFFER = 0,
149 	LAYER_SECURE_BUFFER = 1,
150 	LAYER_PROTECTED_BUFFER = 2,
151 	LAYER_SECURE_BUFFER_WITH_ALIGN = 0x10001,	/* the higher 16 bits =1 for adding 64 bytes alignment */
152 } MTK_FB_OVL_LAYER_SECURE_MODE;
153 
154 typedef struct _disp_dfo_item {
155 	char name[32];
156 	int value;
157 } disp_dfo_item_t;
158 
159 /* -------------------------------------------------------------------------- */
160 struct fb_slt_catpure {
161 	MTK_FB_FORMAT format;
162 
163 	volatile char *outputBuffer;
164 	unsigned int wdma_width;
165 	unsigned int wdma_height;
166 };
167 
168 struct fb_scale {
169 	unsigned int xscale, yscale;
170 };
171 
172 struct fb_frame_offset {
173 	unsigned int idx;
174 	unsigned long offset;
175 };
176 
177 struct fb_update_window {
178 	unsigned int x, y;
179 	unsigned int width, height;
180 };
181 
182 typedef enum {
183 	LAYER_2D = 0,
184 	LAYER_3D_SBS_0 = 0x1,
185 	LAYER_3D_SBS_90 = 0x2,
186 	LAYER_3D_SBS_180 = 0x3,
187 	LAYER_3D_SBS_270 = 0x4,
188 	LAYER_3D_TAB_0 = 0x10,
189 	LAYER_3D_TAB_90 = 0x20,
190 	LAYER_3D_TAB_180 = 0x30,
191 	LAYER_3D_TAB_270 = 0x40,
192 } MTK_FB_LAYER_TYPE;
193 
194 typedef enum {
195 	DISP_DIRECT_LINK_MODE,
196 	DISP_DECOUPLE_MODE
197 } MTK_DISP_MODE;
198 struct fb_overlay_mode {
199 	MTK_DISP_MODE mode;
200 };
201 
202 typedef enum {			/* map sessions to scenairos in kernel driver */
203 	DISP_SESSION_LCM = 1 << 0,	/* DSI0 */
204 	DISP_SESSION_MEM = 1 << 1,	/* OVL0->WDMA0 */
205 /* Extension mode, Dst buf is provided by user,for Wifi Display or other purpose */
206 	DISP_SESSION_WFD = 1 << 2,
207 	DISP_SESSION_MHL = 1 << 3,	/* DPI */
208 	DISP_SESSION_LCM1 = 1 << 4,	/* DSI1 */
209 	DISP_SESSION_MEM1 = 1 << 5,	/* OVL1->WDMA1 */
210 	/* TODO:can be extended with other Session Id */
211 	SESSION_MASK = 0xff & ~(1 << 6)
212 } MTK_DISP_SESSION;
213 
214 struct fb_overlay_session {
215 	unsigned int session;	/* one or more @MTK_DISP_SESSION combined */
216 };
217 
218 struct fb_overlay_decouple {
219 	MTK_DISP_MODE mode;
220 	unsigned int session;
221 };
222 struct fb_overlay_buffer {
223 	/* Input */
224 	int layer_id;
225 	unsigned int layer_en;
226 	int ion_fd;
227 	unsigned int cache_sync;
228 	/* Output */
229 	unsigned int index;
230 	int fence_fd;
231 };
232 
233 struct fb_overlay_layer {
234 	unsigned int layer_id;
235 	unsigned int layer_enable;
236 
237 	void *src_base_addr;
238 	void *src_phy_addr;
239 	unsigned int src_direct_link;
240 	MTK_FB_FORMAT src_fmt;
241 	unsigned int src_use_color_key;
242 	unsigned int src_color_key;
243 	unsigned int src_pitch;
244 	unsigned int src_offset_x, src_offset_y;
245 	unsigned int src_width, src_height;
246 
247 	unsigned int tgt_offset_x, tgt_offset_y;
248 	unsigned int tgt_width, tgt_height;
249 	MTK_FB_ORIENTATION layer_rotation;
250 	MTK_FB_LAYER_TYPE layer_type;
251 	MTK_FB_ORIENTATION video_rotation;
252 
253 	unsigned int isTdshp;	/* set to 1, will go through tdshp first, then layer blending, then to color */
254 
255 	int next_buff_idx;
256 	int identity;
257 	int connected_type;
258 	unsigned int security;
259 	unsigned int alpha_enable;
260 	unsigned int alpha;
261 	int fence_fd;		/* 8135 */
262 	int ion_fd;		/* 8135 CL 2340210 */
263 };
264 
265 struct fb_overlay_config {
266 	int fence;
267 	int time;
268 	struct fb_overlay_layer layers[4];
269 };
270 
271 struct fb_overlay_buffer_info {
272 	unsigned int src_vir_addr;
273 	unsigned int size;
274 };
275 
276 struct fb_overlay_layer_info {
277 	unsigned int layer_id;
278 	unsigned int layer_enabled;	/* TO BE DEL */
279 	unsigned int curr_en;
280 	unsigned int next_en;
281 	unsigned int hw_en;
282 	int curr_idx;
283 	int next_idx;
284 	int hw_idx;
285 	int curr_identity;
286 	int next_identity;
287 	int hw_identity;
288 	int curr_conn_type;
289 	int next_conn_type;
290 	int hw_conn_type;
291 	MTK_FB_ORIENTATION layer_rotation;
292 };
293 /* -------------------------------------------------------------------------- */
294 
295 struct fb_post_video_buffer {
296 	void *phy_addr;
297 	void *vir_addr;
298 	MTK_FB_TV_SRC_FORMAT format;
299 	unsigned int width, height;
300 };
301 
302 #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || defined(CONFIG_ARCH_MT6753)
303 extern unsigned int EnableVSyncLog;
304 
305 void mtkfb_log_enable(int enable);
306 int mtkfb_set_backlight_mode(unsigned int mode);
307 int mtkfb_set_backlight_level(unsigned int level);
308 int mtkfb_get_debug_state(char *stringbuf, int buf_len);
309 unsigned int mtkfb_fm_auto_test(void);
310 void mtkfb_clear_lcm(void);
311 #endif /* CONFIG_ARCH_MT6735 */
312 
313 #ifdef __KERNEL__
314 
315 #include <linux/completion.h>
316 #include <linux/interrupt.h>
317 #include <linux/workqueue.h>
318 #include <linux/version.h>
319 #include <../drivers/staging/android/sw_sync.h>
320 
321 
322 #define MTKFB_DRIVER "mtkfb"
323 
324 enum mtkfb_state {
325 	MTKFB_DISABLED = 0,
326 	MTKFB_SUSPENDED = 99,
327 	MTKFB_ACTIVE = 100
328 };
329 
330 typedef enum {
331 	MTKFB_LAYER_ENABLE_DIRTY = (1 << 0),
332 	MTKFB_LAYER_FORMAT_DIRTY = (1 << 1),
333 	MTKFB_LAYER_SET_DIRTY = (1 << 2),
334 } MTKFB_LAYER_CONFIG_DIRTY;
335 
336 typedef struct {
337 	struct work_struct work;
338 	struct list_head list;
339 	struct fb_overlay_config config;
340 	struct sync_fence *fences[4];
341 	struct ion_handle *ion_handles[4];
342 	void *dev;
343 } update_ovls_work_t;
344 
345 struct mtkfb_device {
346 	int state;
347 	void *fb_va_base;	/* MPU virtual address */
348 	dma_addr_t fb_pa_base;	/* Bus physical address */
349 	unsigned long fb_size_in_byte;
350 	void *ovl_va_base;	/* MPU virtual address */
351 	dma_addr_t ovl_pa_base;	/* Bus physical address */
352 	unsigned long ovl_size_in_byte;
353 
354 	unsigned long layer_enable;
355 	MTK_FB_FORMAT *layer_format;
356 	unsigned int layer_config_dirty;
357 
358 	int xscale, yscale, mirror;	/* transformations.
359 					   rotate is stored in fb_info->var */
360 	u32 pseudo_palette[17];
361 
362 	struct fb_info *fb_info;	/* Linux fbdev framework data */
363 	struct device *dev;
364 
365 	/* Android native fence support */
366 	struct workqueue_struct *update_ovls_wq;
367 	struct mutex timeline_lock;
368 	struct sw_sync_timeline *timeline;
369 	int timeline_max;
370 	struct list_head pending_configs;	/* CL2340210 */
371 	struct ion_client *ion_client;
372 };
373 
374 #endif				/* __KERNEL__ */
375 
376 extern long hdmi_handle_cmd(unsigned int cmd, unsigned long arg);
377 
378 #if defined(CONFIG_ARCH_MT6797)
379 extern unsigned int vramsize;
380 #endif
381 
382 #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || defined(CONFIG_ARCH_MT6753)
383 extern bool is_early_suspended;
384 extern void mtkfb_waitVsync(void);
385 extern bool is_ipoh_bootup;
386 
387 #ifdef CONFIG_OF
388 int _parse_tag_videolfb(void);
389 extern unsigned int islcmconnected;
390 extern unsigned int vramsize;
391 #else
392 extern char *saved_command_line;
393 #endif
394 #endif /* CONFIG_ARCH_MT6735 */
395 
396 
397 #endif				/* __MTKFB_H */
398