rockchip_drm_vop.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
  3. * Author:Mark Yao <mark.yao@rock-chips.com>
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  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 _ROCKCHIP_DRM_VOP_H
  15. #define _ROCKCHIP_DRM_VOP_H
  16. /* register definition */
  17. #define REG_CFG_DONE 0x0000
  18. #define VERSION_INFO 0x0004
  19. #define SYS_CTRL 0x0008
  20. #define SYS_CTRL1 0x000c
  21. #define DSP_CTRL0 0x0010
  22. #define DSP_CTRL1 0x0014
  23. #define DSP_BG 0x0018
  24. #define MCU_CTRL 0x001c
  25. #define INTR_CTRL0 0x0020
  26. #define INTR_CTRL1 0x0024
  27. #define WIN0_CTRL0 0x0030
  28. #define WIN0_CTRL1 0x0034
  29. #define WIN0_COLOR_KEY 0x0038
  30. #define WIN0_VIR 0x003c
  31. #define WIN0_YRGB_MST 0x0040
  32. #define WIN0_CBR_MST 0x0044
  33. #define WIN0_ACT_INFO 0x0048
  34. #define WIN0_DSP_INFO 0x004c
  35. #define WIN0_DSP_ST 0x0050
  36. #define WIN0_SCL_FACTOR_YRGB 0x0054
  37. #define WIN0_SCL_FACTOR_CBR 0x0058
  38. #define WIN0_SCL_OFFSET 0x005c
  39. #define WIN0_SRC_ALPHA_CTRL 0x0060
  40. #define WIN0_DST_ALPHA_CTRL 0x0064
  41. #define WIN0_FADING_CTRL 0x0068
  42. /* win1 register */
  43. #define WIN1_CTRL0 0x0070
  44. #define WIN1_CTRL1 0x0074
  45. #define WIN1_COLOR_KEY 0x0078
  46. #define WIN1_VIR 0x007c
  47. #define WIN1_YRGB_MST 0x0080
  48. #define WIN1_CBR_MST 0x0084
  49. #define WIN1_ACT_INFO 0x0088
  50. #define WIN1_DSP_INFO 0x008c
  51. #define WIN1_DSP_ST 0x0090
  52. #define WIN1_SCL_FACTOR_YRGB 0x0094
  53. #define WIN1_SCL_FACTOR_CBR 0x0098
  54. #define WIN1_SCL_OFFSET 0x009c
  55. #define WIN1_SRC_ALPHA_CTRL 0x00a0
  56. #define WIN1_DST_ALPHA_CTRL 0x00a4
  57. #define WIN1_FADING_CTRL 0x00a8
  58. /* win2 register */
  59. #define WIN2_CTRL0 0x00b0
  60. #define WIN2_CTRL1 0x00b4
  61. #define WIN2_VIR0_1 0x00b8
  62. #define WIN2_VIR2_3 0x00bc
  63. #define WIN2_MST0 0x00c0
  64. #define WIN2_DSP_INFO0 0x00c4
  65. #define WIN2_DSP_ST0 0x00c8
  66. #define WIN2_COLOR_KEY 0x00cc
  67. #define WIN2_MST1 0x00d0
  68. #define WIN2_DSP_INFO1 0x00d4
  69. #define WIN2_DSP_ST1 0x00d8
  70. #define WIN2_SRC_ALPHA_CTRL 0x00dc
  71. #define WIN2_MST2 0x00e0
  72. #define WIN2_DSP_INFO2 0x00e4
  73. #define WIN2_DSP_ST2 0x00e8
  74. #define WIN2_DST_ALPHA_CTRL 0x00ec
  75. #define WIN2_MST3 0x00f0
  76. #define WIN2_DSP_INFO3 0x00f4
  77. #define WIN2_DSP_ST3 0x00f8
  78. #define WIN2_FADING_CTRL 0x00fc
  79. /* win3 register */
  80. #define WIN3_CTRL0 0x0100
  81. #define WIN3_CTRL1 0x0104
  82. #define WIN3_VIR0_1 0x0108
  83. #define WIN3_VIR2_3 0x010c
  84. #define WIN3_MST0 0x0110
  85. #define WIN3_DSP_INFO0 0x0114
  86. #define WIN3_DSP_ST0 0x0118
  87. #define WIN3_COLOR_KEY 0x011c
  88. #define WIN3_MST1 0x0120
  89. #define WIN3_DSP_INFO1 0x0124
  90. #define WIN3_DSP_ST1 0x0128
  91. #define WIN3_SRC_ALPHA_CTRL 0x012c
  92. #define WIN3_MST2 0x0130
  93. #define WIN3_DSP_INFO2 0x0134
  94. #define WIN3_DSP_ST2 0x0138
  95. #define WIN3_DST_ALPHA_CTRL 0x013c
  96. #define WIN3_MST3 0x0140
  97. #define WIN3_DSP_INFO3 0x0144
  98. #define WIN3_DSP_ST3 0x0148
  99. #define WIN3_FADING_CTRL 0x014c
  100. /* hwc register */
  101. #define HWC_CTRL0 0x0150
  102. #define HWC_CTRL1 0x0154
  103. #define HWC_MST 0x0158
  104. #define HWC_DSP_ST 0x015c
  105. #define HWC_SRC_ALPHA_CTRL 0x0160
  106. #define HWC_DST_ALPHA_CTRL 0x0164
  107. #define HWC_FADING_CTRL 0x0168
  108. /* post process register */
  109. #define POST_DSP_HACT_INFO 0x0170
  110. #define POST_DSP_VACT_INFO 0x0174
  111. #define POST_SCL_FACTOR_YRGB 0x0178
  112. #define POST_SCL_CTRL 0x0180
  113. #define POST_DSP_VACT_INFO_F1 0x0184
  114. #define DSP_HTOTAL_HS_END 0x0188
  115. #define DSP_HACT_ST_END 0x018c
  116. #define DSP_VTOTAL_VS_END 0x0190
  117. #define DSP_VACT_ST_END 0x0194
  118. #define DSP_VS_ST_END_F1 0x0198
  119. #define DSP_VACT_ST_END_F1 0x019c
  120. /* register definition end */
  121. /* interrupt define */
  122. #define DSP_HOLD_VALID_INTR (1 << 0)
  123. #define FS_INTR (1 << 1)
  124. #define LINE_FLAG_INTR (1 << 2)
  125. #define BUS_ERROR_INTR (1 << 3)
  126. #define INTR_MASK (DSP_HOLD_VALID_INTR | FS_INTR | \
  127. LINE_FLAG_INTR | BUS_ERROR_INTR)
  128. #define DSP_HOLD_VALID_INTR_EN(x) ((x) << 4)
  129. #define FS_INTR_EN(x) ((x) << 5)
  130. #define LINE_FLAG_INTR_EN(x) ((x) << 6)
  131. #define BUS_ERROR_INTR_EN(x) ((x) << 7)
  132. #define DSP_HOLD_VALID_INTR_MASK (1 << 4)
  133. #define FS_INTR_MASK (1 << 5)
  134. #define LINE_FLAG_INTR_MASK (1 << 6)
  135. #define BUS_ERROR_INTR_MASK (1 << 7)
  136. #define INTR_CLR_SHIFT 8
  137. #define DSP_HOLD_VALID_INTR_CLR (1 << (INTR_CLR_SHIFT + 0))
  138. #define FS_INTR_CLR (1 << (INTR_CLR_SHIFT + 1))
  139. #define LINE_FLAG_INTR_CLR (1 << (INTR_CLR_SHIFT + 2))
  140. #define BUS_ERROR_INTR_CLR (1 << (INTR_CLR_SHIFT + 3))
  141. #define DSP_LINE_NUM(x) (((x) & 0x1fff) << 12)
  142. #define DSP_LINE_NUM_MASK (0x1fff << 12)
  143. /* src alpha ctrl define */
  144. #define SRC_FADING_VALUE(x) (((x) & 0xff) << 24)
  145. #define SRC_GLOBAL_ALPHA(x) (((x) & 0xff) << 16)
  146. #define SRC_FACTOR_M0(x) (((x) & 0x7) << 6)
  147. #define SRC_ALPHA_CAL_M0(x) (((x) & 0x1) << 5)
  148. #define SRC_BLEND_M0(x) (((x) & 0x3) << 3)
  149. #define SRC_ALPHA_M0(x) (((x) & 0x1) << 2)
  150. #define SRC_COLOR_M0(x) (((x) & 0x1) << 1)
  151. #define SRC_ALPHA_EN(x) (((x) & 0x1) << 0)
  152. /* dst alpha ctrl define */
  153. #define DST_FACTOR_M0(x) (((x) & 0x7) << 6)
  154. /*
  155. * display output interface supported by rockchip lcdc
  156. */
  157. #define ROCKCHIP_OUT_MODE_P888 0
  158. #define ROCKCHIP_OUT_MODE_P666 1
  159. #define ROCKCHIP_OUT_MODE_P565 2
  160. /* for use special outface */
  161. #define ROCKCHIP_OUT_MODE_AAAA 15
  162. enum alpha_mode {
  163. ALPHA_STRAIGHT,
  164. ALPHA_INVERSE,
  165. };
  166. enum global_blend_mode {
  167. ALPHA_GLOBAL,
  168. ALPHA_PER_PIX,
  169. ALPHA_PER_PIX_GLOBAL,
  170. };
  171. enum alpha_cal_mode {
  172. ALPHA_SATURATION,
  173. ALPHA_NO_SATURATION,
  174. };
  175. enum color_mode {
  176. ALPHA_SRC_PRE_MUL,
  177. ALPHA_SRC_NO_PRE_MUL,
  178. };
  179. enum factor_mode {
  180. ALPHA_ZERO,
  181. ALPHA_ONE,
  182. ALPHA_SRC,
  183. ALPHA_SRC_INVERSE,
  184. ALPHA_SRC_GLOBAL,
  185. };
  186. enum scale_mode {
  187. SCALE_NONE = 0x0,
  188. SCALE_UP = 0x1,
  189. SCALE_DOWN = 0x2
  190. };
  191. enum lb_mode {
  192. LB_YUV_3840X5 = 0x0,
  193. LB_YUV_2560X8 = 0x1,
  194. LB_RGB_3840X2 = 0x2,
  195. LB_RGB_2560X4 = 0x3,
  196. LB_RGB_1920X5 = 0x4,
  197. LB_RGB_1280X8 = 0x5
  198. };
  199. enum sacle_up_mode {
  200. SCALE_UP_BIL = 0x0,
  201. SCALE_UP_BIC = 0x1
  202. };
  203. enum scale_down_mode {
  204. SCALE_DOWN_BIL = 0x0,
  205. SCALE_DOWN_AVG = 0x1
  206. };
  207. #define FRAC_16_16(mult, div) (((mult) << 16) / (div))
  208. #define SCL_FT_DEFAULT_FIXPOINT_SHIFT 12
  209. #define SCL_MAX_VSKIPLINES 4
  210. #define MIN_SCL_FT_AFTER_VSKIP 1
  211. static inline uint16_t scl_cal_scale(int src, int dst, int shift)
  212. {
  213. return ((src * 2 - 3) << (shift - 1)) / (dst - 1);
  214. }
  215. #define GET_SCL_FT_BILI_DN(src, dst) scl_cal_scale(src, dst, 12)
  216. #define GET_SCL_FT_BILI_UP(src, dst) scl_cal_scale(src, dst, 16)
  217. #define GET_SCL_FT_BIC(src, dst) scl_cal_scale(src, dst, 16)
  218. static inline uint16_t scl_get_bili_dn_vskip(int src_h, int dst_h,
  219. int vskiplines)
  220. {
  221. int act_height;
  222. act_height = (src_h + vskiplines - 1) / vskiplines;
  223. return GET_SCL_FT_BILI_DN(act_height, dst_h);
  224. }
  225. static inline enum scale_mode scl_get_scl_mode(int src, int dst)
  226. {
  227. if (src < dst)
  228. return SCALE_UP;
  229. else if (src > dst)
  230. return SCALE_DOWN;
  231. return SCALE_NONE;
  232. }
  233. static inline int scl_get_vskiplines(uint32_t srch, uint32_t dsth)
  234. {
  235. uint32_t vskiplines;
  236. for (vskiplines = SCL_MAX_VSKIPLINES; vskiplines > 1; vskiplines /= 2)
  237. if (srch >= vskiplines * dsth * MIN_SCL_FT_AFTER_VSKIP)
  238. break;
  239. return vskiplines;
  240. }
  241. static inline int scl_vop_cal_lb_mode(int width, bool is_yuv)
  242. {
  243. int lb_mode;
  244. if (width > 2560)
  245. lb_mode = LB_RGB_3840X2;
  246. else if (width > 1920)
  247. lb_mode = LB_RGB_2560X4;
  248. else if (!is_yuv)
  249. lb_mode = LB_RGB_1920X5;
  250. else if (width > 1280)
  251. lb_mode = LB_YUV_3840X5;
  252. else
  253. lb_mode = LB_YUV_2560X8;
  254. return lb_mode;
  255. }
  256. #endif /* _ROCKCHIP_DRM_VOP_H */