mtkfb.h 12 KB

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