mtk_ddp_comp.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015 MediaTek Inc.
  4. */
  5. #ifndef MTK_DDP_COMP_H
  6. #define MTK_DDP_COMP_H
  7. #include <linux/io.h>
  8. #include <linux/pm_runtime.h>
  9. #include <linux/soc/mediatek/mtk-cmdq.h>
  10. #include <linux/soc/mediatek/mtk-mmsys.h>
  11. #include <linux/soc/mediatek/mtk-mutex.h>
  12. #include <drm/drm_modes.h>
  13. struct device;
  14. struct device_node;
  15. struct drm_crtc;
  16. struct drm_device;
  17. struct mtk_plane_state;
  18. struct drm_crtc_state;
  19. enum mtk_ddp_comp_type {
  20. MTK_DISP_AAL,
  21. MTK_DISP_BLS,
  22. MTK_DISP_CCORR,
  23. MTK_DISP_COLOR,
  24. MTK_DISP_DITHER,
  25. MTK_DISP_DSC,
  26. MTK_DISP_GAMMA,
  27. MTK_DISP_MERGE,
  28. MTK_DISP_MUTEX,
  29. MTK_DISP_OD,
  30. MTK_DISP_OVL,
  31. MTK_DISP_OVL_2L,
  32. MTK_DISP_OVL_ADAPTOR,
  33. MTK_DISP_POSTMASK,
  34. MTK_DISP_PWM,
  35. MTK_DISP_RDMA,
  36. MTK_DISP_UFOE,
  37. MTK_DISP_WDMA,
  38. MTK_DPI,
  39. MTK_DP_INTF,
  40. MTK_DSI,
  41. MTK_DDP_COMP_TYPE_MAX,
  42. };
  43. struct mtk_ddp_comp;
  44. struct cmdq_pkt;
  45. struct mtk_ddp_comp_funcs {
  46. int (*power_on)(struct device *dev);
  47. void (*power_off)(struct device *dev);
  48. int (*clk_enable)(struct device *dev);
  49. void (*clk_disable)(struct device *dev);
  50. void (*config)(struct device *dev, unsigned int w,
  51. unsigned int h, unsigned int vrefresh,
  52. unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
  53. void (*start)(struct device *dev);
  54. void (*stop)(struct device *dev);
  55. void (*register_vblank_cb)(struct device *dev,
  56. void (*vblank_cb)(void *),
  57. void *vblank_cb_data);
  58. void (*unregister_vblank_cb)(struct device *dev);
  59. void (*enable_vblank)(struct device *dev);
  60. void (*disable_vblank)(struct device *dev);
  61. unsigned int (*supported_rotations)(struct device *dev);
  62. unsigned int (*layer_nr)(struct device *dev);
  63. int (*layer_check)(struct device *dev,
  64. unsigned int idx,
  65. struct mtk_plane_state *state);
  66. void (*layer_config)(struct device *dev, unsigned int idx,
  67. struct mtk_plane_state *state,
  68. struct cmdq_pkt *cmdq_pkt);
  69. unsigned int (*gamma_get_lut_size)(struct device *dev);
  70. void (*gamma_set)(struct device *dev,
  71. struct drm_crtc_state *state);
  72. void (*bgclr_in_on)(struct device *dev);
  73. void (*bgclr_in_off)(struct device *dev);
  74. void (*ctm_set)(struct device *dev,
  75. struct drm_crtc_state *state);
  76. struct device * (*dma_dev_get)(struct device *dev);
  77. u32 (*get_blend_modes)(struct device *dev);
  78. const u32 *(*get_formats)(struct device *dev);
  79. size_t (*get_num_formats)(struct device *dev);
  80. bool (*is_afbc_supported)(struct device *dev);
  81. void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
  82. void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
  83. void (*add)(struct device *dev, struct mtk_mutex *mutex);
  84. void (*remove)(struct device *dev, struct mtk_mutex *mutex);
  85. unsigned int (*encoder_index)(struct device *dev);
  86. enum drm_mode_status (*mode_valid)(struct device *dev, const struct drm_display_mode *mode);
  87. };
  88. struct mtk_ddp_comp {
  89. struct device *dev;
  90. int irq;
  91. unsigned int id;
  92. int encoder_index;
  93. const struct mtk_ddp_comp_funcs *funcs;
  94. };
  95. static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
  96. {
  97. if (comp->funcs && comp->funcs->power_on)
  98. return comp->funcs->power_on(comp->dev);
  99. else
  100. return pm_runtime_resume_and_get(comp->dev);
  101. return 0;
  102. }
  103. static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
  104. {
  105. if (comp->funcs && comp->funcs->power_off)
  106. comp->funcs->power_off(comp->dev);
  107. else
  108. pm_runtime_put(comp->dev);
  109. }
  110. static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
  111. {
  112. if (comp->funcs && comp->funcs->clk_enable)
  113. return comp->funcs->clk_enable(comp->dev);
  114. return 0;
  115. }
  116. static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
  117. {
  118. if (comp->funcs && comp->funcs->clk_disable)
  119. comp->funcs->clk_disable(comp->dev);
  120. }
  121. static inline
  122. enum drm_mode_status mtk_ddp_comp_mode_valid(struct mtk_ddp_comp *comp,
  123. const struct drm_display_mode *mode)
  124. {
  125. if (comp && comp->funcs && comp->funcs->mode_valid)
  126. return comp->funcs->mode_valid(comp->dev, mode);
  127. return MODE_OK;
  128. }
  129. static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
  130. unsigned int w, unsigned int h,
  131. unsigned int vrefresh, unsigned int bpc,
  132. struct cmdq_pkt *cmdq_pkt)
  133. {
  134. if (comp->funcs && comp->funcs->config)
  135. comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
  136. }
  137. static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
  138. {
  139. if (comp->funcs && comp->funcs->start)
  140. comp->funcs->start(comp->dev);
  141. }
  142. static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
  143. {
  144. if (comp->funcs && comp->funcs->stop)
  145. comp->funcs->stop(comp->dev);
  146. }
  147. static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
  148. void (*vblank_cb)(void *),
  149. void *vblank_cb_data)
  150. {
  151. if (comp->funcs && comp->funcs->register_vblank_cb)
  152. comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
  153. vblank_cb_data);
  154. }
  155. static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
  156. {
  157. if (comp->funcs && comp->funcs->unregister_vblank_cb)
  158. comp->funcs->unregister_vblank_cb(comp->dev);
  159. }
  160. static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
  161. {
  162. if (comp->funcs && comp->funcs->enable_vblank)
  163. comp->funcs->enable_vblank(comp->dev);
  164. }
  165. static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
  166. {
  167. if (comp->funcs && comp->funcs->disable_vblank)
  168. comp->funcs->disable_vblank(comp->dev);
  169. }
  170. static inline
  171. unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
  172. {
  173. if (comp->funcs && comp->funcs->supported_rotations)
  174. return comp->funcs->supported_rotations(comp->dev);
  175. /*
  176. * In order to pass IGT tests, DRM_MODE_ROTATE_0 is required when
  177. * rotation is not supported.
  178. */
  179. return DRM_MODE_ROTATE_0;
  180. }
  181. static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
  182. {
  183. if (comp->funcs && comp->funcs->layer_nr)
  184. return comp->funcs->layer_nr(comp->dev);
  185. return 0;
  186. }
  187. static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
  188. unsigned int idx,
  189. struct mtk_plane_state *state)
  190. {
  191. if (comp->funcs && comp->funcs->layer_check)
  192. return comp->funcs->layer_check(comp->dev, idx, state);
  193. return 0;
  194. }
  195. static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
  196. unsigned int idx,
  197. struct mtk_plane_state *state,
  198. struct cmdq_pkt *cmdq_pkt)
  199. {
  200. if (comp->funcs && comp->funcs->layer_config)
  201. comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
  202. }
  203. static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
  204. {
  205. if (comp->funcs && comp->funcs->gamma_get_lut_size)
  206. return comp->funcs->gamma_get_lut_size(comp->dev);
  207. return 0;
  208. }
  209. static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
  210. struct drm_crtc_state *state)
  211. {
  212. if (comp->funcs && comp->funcs->gamma_set)
  213. comp->funcs->gamma_set(comp->dev, state);
  214. }
  215. static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
  216. {
  217. if (comp->funcs && comp->funcs->bgclr_in_on)
  218. comp->funcs->bgclr_in_on(comp->dev);
  219. }
  220. static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
  221. {
  222. if (comp->funcs && comp->funcs->bgclr_in_off)
  223. comp->funcs->bgclr_in_off(comp->dev);
  224. }
  225. static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
  226. struct drm_crtc_state *state)
  227. {
  228. if (comp->funcs && comp->funcs->ctm_set)
  229. comp->funcs->ctm_set(comp->dev, state);
  230. }
  231. static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
  232. {
  233. if (comp->funcs && comp->funcs->dma_dev_get)
  234. return comp->funcs->dma_dev_get(comp->dev);
  235. return comp->dev;
  236. }
  237. static inline
  238. u32 mtk_ddp_comp_get_blend_modes(struct mtk_ddp_comp *comp)
  239. {
  240. if (comp->funcs && comp->funcs->get_blend_modes)
  241. return comp->funcs->get_blend_modes(comp->dev);
  242. return 0;
  243. }
  244. static inline
  245. const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
  246. {
  247. if (comp->funcs && comp->funcs->get_formats)
  248. return comp->funcs->get_formats(comp->dev);
  249. return NULL;
  250. }
  251. static inline
  252. size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
  253. {
  254. if (comp->funcs && comp->funcs->get_num_formats)
  255. return comp->funcs->get_num_formats(comp->dev);
  256. return 0;
  257. }
  258. static inline bool mtk_ddp_comp_is_afbc_supported(struct mtk_ddp_comp *comp)
  259. {
  260. if (comp->funcs && comp->funcs->is_afbc_supported)
  261. return comp->funcs->is_afbc_supported(comp->dev);
  262. return false;
  263. }
  264. static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
  265. {
  266. if (comp->funcs && comp->funcs->add) {
  267. comp->funcs->add(comp->dev, mutex);
  268. return true;
  269. }
  270. return false;
  271. }
  272. static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
  273. {
  274. if (comp->funcs && comp->funcs->remove) {
  275. comp->funcs->remove(comp->dev, mutex);
  276. return true;
  277. }
  278. return false;
  279. }
  280. static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
  281. unsigned int next)
  282. {
  283. if (comp->funcs && comp->funcs->connect) {
  284. comp->funcs->connect(comp->dev, mmsys_dev, next);
  285. return true;
  286. }
  287. return false;
  288. }
  289. static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
  290. unsigned int next)
  291. {
  292. if (comp->funcs && comp->funcs->disconnect) {
  293. comp->funcs->disconnect(comp->dev, mmsys_dev, next);
  294. return true;
  295. }
  296. return false;
  297. }
  298. static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
  299. {
  300. if (comp->funcs && comp->funcs->encoder_index)
  301. comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
  302. }
  303. int mtk_ddp_comp_get_id(struct device_node *node,
  304. enum mtk_ddp_comp_type comp_type);
  305. int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
  306. int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
  307. unsigned int comp_id);
  308. enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
  309. void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
  310. struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
  311. unsigned int offset);
  312. void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
  313. struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
  314. unsigned int offset);
  315. void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
  316. struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
  317. unsigned int offset, unsigned int mask);
  318. #endif /* MTK_DDP_COMP_H */