mtk_drm_drv.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. * Copyright (C) 2021 XiaoMi, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef MTK_DRM_DRV_H
  15. #define MTK_DRM_DRV_H
  16. #include <drm/drm_fb_helper.h>
  17. #include <drm/mediatek_drm.h>
  18. #include <linux/types.h>
  19. #include <linux/io.h>
  20. #include <drm/drm_atomic.h>
  21. #include "mtk_drm_ddp_comp.h"
  22. #include "mtk_drm_plane.h"
  23. #include "mtk_drm_crtc.h"
  24. #include "mtk_drm_ddp.h"
  25. #include "mtk_drm_session.h"
  26. #include "mtk_drm_helper.h"
  27. #define MAX_CONNECTOR 3
  28. #ifndef CONFIG_FPGA_EARLY_PORTING
  29. #define MTK_DRM_ESD_SUPPORT
  30. #define MTK_FB_MMDVFS_SUPPORT
  31. #endif
  32. #define MTK_DRM_FENCE_SUPPORT
  33. #define MTK_DRM_CMDQ_ASYNC
  34. #define CONFIG_MTK_DISPLAY_CMDQ
  35. #define MTK_FILL_MIPI_IMPEDANCE
  36. #if (defined(CONFIG_MACH_MT6885) || defined(CONFIG_MACH_MT6873)\
  37. || defined(CONFIG_MACH_MT6893) ||\
  38. defined(CONFIG_MACH_MT6853) || \
  39. defined(CONFIG_MACH_MT6833)) &&\
  40. defined(CONFIG_MTK_SEC_VIDEO_PATH_SUPPORT)
  41. //#define MTK_DRM_DELAY_PRESENT_FENCE
  42. /* Delay present fence would cause config merge */
  43. #endif
  44. struct device;
  45. struct device_node;
  46. struct drm_crtc;
  47. struct drm_device;
  48. struct drm_property;
  49. struct regmap;
  50. struct mm_qos_request;
  51. struct pm_qos_request;
  52. struct mtk_atomic_state {
  53. struct drm_atomic_state base;
  54. struct list_head list;
  55. struct kref kref;
  56. };
  57. struct mtk_fake_eng_reg {
  58. unsigned int CG_idx;
  59. unsigned int CG_bit;
  60. bool share_port;
  61. };
  62. struct mtk_fake_eng_data {
  63. int fake_eng_num;
  64. const struct mtk_fake_eng_reg *fake_eng_reg;
  65. };
  66. struct mtk_mmsys_driver_data {
  67. const struct mtk_crtc_path_data *main_path_data;
  68. const struct mtk_crtc_path_data *ext_path_data;
  69. const struct mtk_crtc_path_data *third_path_data;
  70. enum mtk_mmsys_id mmsys_id;
  71. bool shadow_register;
  72. const struct mtk_session_mode_tb *mode_tb;
  73. void (*sodi_config)(struct drm_device *drm, enum mtk_ddp_comp_id id,
  74. struct cmdq_pkt *handle, void *data);
  75. const struct mtk_fake_eng_data *fake_eng_data;
  76. bool bypass_infra_ddr_control;
  77. };
  78. struct mtk_drm_lyeblob_ids {
  79. uint32_t lye_idx;
  80. uint32_t frame_weight;
  81. uint32_t hrt_num;
  82. int32_t ddp_blob_id;
  83. int32_t ref_cnt;
  84. int32_t ref_cnt_mask;
  85. int32_t free_cnt_mask;
  86. int32_t lye_plane_blob_id[MAX_CRTC][OVL_LAYER_NR];
  87. struct list_head list;
  88. };
  89. struct mtk_drm_private {
  90. struct drm_device *drm;
  91. struct device *dma_dev;
  92. struct device *mmsys_dev;
  93. #if defined(CONFIG_MTK_IOMMU_V2)
  94. struct ion_client *client;
  95. #endif
  96. struct drm_crtc *crtc[MAX_CRTC];
  97. unsigned int num_pipes;
  98. unsigned int session_id[MAX_SESSION_COUNT];
  99. unsigned int num_sessions;
  100. enum MTK_DRM_SESSION_MODE session_mode;
  101. atomic_t crtc_present[MAX_CRTC];
  102. struct device_node *mutex_node;
  103. struct device *mutex_dev;
  104. void __iomem *config_regs;
  105. resource_size_t config_regs_pa;
  106. void __iomem *infra_regs;
  107. resource_size_t infra_regs_pa;
  108. const struct mtk_mmsys_reg_data *reg_data;
  109. struct device_node *comp_node[DDP_COMPONENT_ID_MAX];
  110. struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX];
  111. const struct mtk_mmsys_driver_data *data;
  112. struct {
  113. struct drm_atomic_state *state;
  114. struct work_struct work;
  115. struct mutex lock;
  116. } commit;
  117. struct drm_atomic_state *suspend_state;
  118. struct {
  119. struct work_struct work;
  120. struct list_head list;
  121. spinlock_t lock;
  122. } unreference;
  123. /* property */
  124. struct drm_property *crtc_property[MAX_CRTC][CRTC_PROP_MAX];
  125. struct drm_fb_helper fb_helper;
  126. struct drm_gem_object *fbdev_bo;
  127. struct list_head lyeblob_head;
  128. struct mutex lyeblob_list_mutex;
  129. struct task_struct *fence_release_thread[MAX_CRTC-1];
  130. /* variable for repaint */
  131. struct {
  132. wait_queue_head_t wq;
  133. struct list_head job_queue;
  134. struct list_head job_pool;
  135. } repaint_data;
  136. struct mtk_drm_helper *helper_opt;
  137. atomic_t idle_need_repaint;
  138. atomic_t rollback_all;
  139. unsigned int top_clk_num;
  140. struct clk **top_clk;
  141. bool power_state;
  142. /* for rpo caps info */
  143. unsigned int rsz_in_max[2];
  144. #ifdef MTK_FB_MMDVFS_SUPPORT
  145. struct plist_head bw_request_list;
  146. struct plist_head hrt_request_list;
  147. struct pm_qos_request ddr_opp_request;
  148. struct pm_qos_request mm_freq_request;
  149. struct mm_qos_request hrt_bw_request;
  150. #endif
  151. struct pinctrl *pctrl;
  152. #ifdef DRM_MMPATH
  153. int HWC_gpid; // for mmpath auto gen
  154. #endif
  155. int need_vds_path_switch;
  156. int vds_path_switch_dirty;
  157. int vds_path_switch_done;
  158. int vds_path_enable;
  159. /* Due to 2nd display share 1 secure gce client, need store here */
  160. struct cmdq_client *ext_sec_client;
  161. };
  162. struct mtk_drm_property {
  163. int flags;
  164. char *name;
  165. unsigned long min;
  166. unsigned long max;
  167. unsigned long val;
  168. };
  169. struct repaint_job_t {
  170. struct list_head link;
  171. unsigned int type;
  172. };
  173. #define LCM_FPS_ARRAY_SIZE 32
  174. struct lcm_fps_ctx_t {
  175. atomic_t is_inited;
  176. spinlock_t lock;
  177. atomic_t skip_update;
  178. unsigned int dsi_mode;
  179. unsigned int head_idx;
  180. unsigned int num;
  181. unsigned int fps;
  182. unsigned long long last_ns;
  183. unsigned long long array[LCM_FPS_ARRAY_SIZE];
  184. };
  185. #define DISP_LARB_COUNT 1
  186. struct disp_iommu_device {
  187. struct platform_device *larb_pdev[DISP_LARB_COUNT];
  188. struct platform_device *iommu_pdev;
  189. unsigned int inited;
  190. };
  191. struct disp_iommu_device *disp_get_iommu_dev(void);
  192. extern struct platform_driver mtk_ddp_driver;
  193. extern struct platform_driver mtk_disp_color_driver;
  194. extern struct platform_driver mtk_disp_ccorr_driver;
  195. extern struct platform_driver mtk_disp_gamma_driver;
  196. extern struct platform_driver mtk_disp_aal_driver;
  197. extern struct platform_driver mtk_dmdp_aal_driver;
  198. extern struct platform_driver mtk_disp_postmask_driver;
  199. extern struct platform_driver mtk_disp_dither_driver;
  200. extern struct platform_driver mtk_disp_ovl_driver;
  201. extern struct platform_driver mtk_disp_rdma_driver;
  202. extern struct platform_driver mtk_disp_wdma_driver;
  203. extern struct platform_driver mtk_disp_rsz_driver;
  204. extern struct platform_driver mtk_dpi_driver;
  205. extern struct platform_driver mtk_dsi_driver;
  206. extern struct platform_driver mtk_mipi_tx_driver;
  207. extern struct platform_driver mtk_lvds_driver;
  208. extern struct platform_driver mtk_lvds_tx_driver;
  209. extern struct platform_driver mtk_disp_dsc_driver;
  210. extern struct lcm_fps_ctx_t lcm_fps_ctx[MAX_CRTC];
  211. extern struct platform_driver mtk_disp_merge_driver;
  212. #ifdef CONFIG_MTK_HDMI_SUPPORT
  213. extern struct platform_driver mtk_dp_tx_driver;
  214. extern struct platform_driver mtk_dp_intf_driver;
  215. #endif
  216. void mtk_atomic_state_get(struct drm_atomic_state *state);
  217. void mtk_atomic_state_put(struct drm_atomic_state *state);
  218. void mtk_atomic_state_put_queue(struct drm_atomic_state *state);
  219. void mtk_drm_fence_update(unsigned int fence_idx, unsigned int index);
  220. void drm_trigger_repaint(enum DRM_REPAINT_TYPE type,
  221. struct drm_device *drm_dev);
  222. int mtk_drm_suspend_release_fence(struct device *dev);
  223. void mtk_drm_suspend_release_present_fence(struct device *dev,
  224. unsigned int index);
  225. void mtk_drm_top_clk_prepare_enable(struct drm_device *drm);
  226. void mtk_drm_top_clk_disable_unprepare(struct drm_device *drm);
  227. struct mtk_panel_params *mtk_drm_get_lcm_ext_params(struct drm_crtc *crtc);
  228. struct mtk_panel_funcs *mtk_drm_get_lcm_ext_funcs(struct drm_crtc *crtc);
  229. bool mtk_drm_session_mode_is_decouple_mode(struct drm_device *dev);
  230. bool mtk_drm_session_mode_is_mirror_mode(struct drm_device *dev);
  231. bool mtk_drm_top_clk_isr_get(char *master);
  232. void mtk_drm_top_clk_isr_put(char *master);
  233. int lcm_fps_ctx_init(struct drm_crtc *crtc);
  234. int lcm_fps_ctx_reset(struct drm_crtc *crtc);
  235. int lcm_fps_ctx_update(unsigned long long cur_ns,
  236. unsigned int crtc_id, unsigned int mode);
  237. #endif /* MTK_DRM_DRV_H */