sun4i_backend.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2015 Free Electrons
  4. * Copyright (C) 2015 NextThing Co
  5. *
  6. * Maxime Ripard <maxime.ripard@free-electrons.com>
  7. */
  8. #ifndef _SUN4I_BACKEND_H_
  9. #define _SUN4I_BACKEND_H_
  10. #include <linux/clk.h>
  11. #include <linux/list.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include <linux/reset.h>
  15. #include "sunxi_engine.h"
  16. #define SUN4I_BACKEND_MODCTL_REG 0x800
  17. #define SUN4I_BACKEND_MODCTL_LINE_SEL BIT(29)
  18. #define SUN4I_BACKEND_MODCTL_ITLMOD_EN BIT(28)
  19. #define SUN4I_BACKEND_MODCTL_OUT_SEL GENMASK(22, 20)
  20. #define SUN4I_BACKEND_MODCTL_OUT_LCD0 (0 << 20)
  21. #define SUN4I_BACKEND_MODCTL_OUT_LCD1 (1 << 20)
  22. #define SUN4I_BACKEND_MODCTL_OUT_FE0 (6 << 20)
  23. #define SUN4I_BACKEND_MODCTL_OUT_FE1 (7 << 20)
  24. #define SUN4I_BACKEND_MODCTL_HWC_EN BIT(16)
  25. #define SUN4I_BACKEND_MODCTL_LAY_EN(l) BIT(8 + l)
  26. #define SUN4I_BACKEND_MODCTL_OCSC_EN BIT(5)
  27. #define SUN4I_BACKEND_MODCTL_DFLK_EN BIT(4)
  28. #define SUN4I_BACKEND_MODCTL_DLP_START_CTL BIT(2)
  29. #define SUN4I_BACKEND_MODCTL_START_CTL BIT(1)
  30. #define SUN4I_BACKEND_MODCTL_DEBE_EN BIT(0)
  31. #define SUN4I_BACKEND_BACKCOLOR_REG 0x804
  32. #define SUN4I_BACKEND_BACKCOLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b))
  33. #define SUN4I_BACKEND_DISSIZE_REG 0x808
  34. #define SUN4I_BACKEND_DISSIZE(w, h) (((((h) - 1) & 0xffff) << 16) | \
  35. (((w) - 1) & 0xffff))
  36. #define SUN4I_BACKEND_LAYSIZE_REG(l) (0x810 + (0x4 * (l)))
  37. #define SUN4I_BACKEND_LAYSIZE(w, h) (((((h) - 1) & 0x1fff) << 16) | \
  38. (((w) - 1) & 0x1fff))
  39. #define SUN4I_BACKEND_LAYCOOR_REG(l) (0x820 + (0x4 * (l)))
  40. #define SUN4I_BACKEND_LAYCOOR(x, y) ((((u32)(y) & 0xffff) << 16) | \
  41. ((u32)(x) & 0xffff))
  42. #define SUN4I_BACKEND_LAYLINEWIDTH_REG(l) (0x840 + (0x4 * (l)))
  43. #define SUN4I_BACKEND_LAYFB_L32ADD_REG(l) (0x850 + (0x4 * (l)))
  44. #define SUN4I_BACKEND_LAYFB_H4ADD_REG 0x860
  45. #define SUN4I_BACKEND_LAYFB_H4ADD_MSK(l) GENMASK(3 + ((l) * 8), (l) * 8)
  46. #define SUN4I_BACKEND_LAYFB_H4ADD(l, val) ((val) << ((l) * 8))
  47. #define SUN4I_BACKEND_REGBUFFCTL_REG 0x870
  48. #define SUN4I_BACKEND_REGBUFFCTL_AUTOLOAD_DIS BIT(1)
  49. #define SUN4I_BACKEND_REGBUFFCTL_LOADCTL BIT(0)
  50. #define SUN4I_BACKEND_CKMAX_REG 0x880
  51. #define SUN4I_BACKEND_CKMIN_REG 0x884
  52. #define SUN4I_BACKEND_CKCFG_REG 0x888
  53. #define SUN4I_BACKEND_ATTCTL_REG0(l) (0x890 + (0x4 * (l)))
  54. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA_MASK GENMASK(31, 24)
  55. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA(x) ((x) << 24)
  56. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL_MASK BIT(15)
  57. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL(x) ((x) << 15)
  58. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PRISEL_MASK GENMASK(11, 10)
  59. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PRISEL(x) ((x) << 10)
  60. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN BIT(2)
  61. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_VDOEN BIT(1)
  62. #define SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA_EN BIT(0)
  63. #define SUN4I_BACKEND_ATTCTL_REG1(l) (0x8a0 + (0x4 * (l)))
  64. #define SUN4I_BACKEND_ATTCTL_REG1_LAY_HSCAFCT GENMASK(15, 14)
  65. #define SUN4I_BACKEND_ATTCTL_REG1_LAY_WSCAFCT GENMASK(13, 12)
  66. #define SUN4I_BACKEND_ATTCTL_REG1_LAY_FBFMT GENMASK(11, 8)
  67. #define SUN4I_BACKEND_LAY_FBFMT_1BPP (0 << 8)
  68. #define SUN4I_BACKEND_LAY_FBFMT_2BPP (1 << 8)
  69. #define SUN4I_BACKEND_LAY_FBFMT_4BPP (2 << 8)
  70. #define SUN4I_BACKEND_LAY_FBFMT_8BPP (3 << 8)
  71. #define SUN4I_BACKEND_LAY_FBFMT_RGB655 (4 << 8)
  72. #define SUN4I_BACKEND_LAY_FBFMT_RGB565 (5 << 8)
  73. #define SUN4I_BACKEND_LAY_FBFMT_RGB556 (6 << 8)
  74. #define SUN4I_BACKEND_LAY_FBFMT_ARGB1555 (7 << 8)
  75. #define SUN4I_BACKEND_LAY_FBFMT_RGBA5551 (8 << 8)
  76. #define SUN4I_BACKEND_LAY_FBFMT_XRGB8888 (9 << 8)
  77. #define SUN4I_BACKEND_LAY_FBFMT_ARGB8888 (10 << 8)
  78. #define SUN4I_BACKEND_LAY_FBFMT_RGB888 (11 << 8)
  79. #define SUN4I_BACKEND_LAY_FBFMT_ARGB4444 (12 << 8)
  80. #define SUN4I_BACKEND_LAY_FBFMT_RGBA4444 (13 << 8)
  81. #define SUN4I_BACKEND_DLCDPCTL_REG 0x8b0
  82. #define SUN4I_BACKEND_DLCDPFRMBUF_ADDRCTL_REG 0x8b4
  83. #define SUN4I_BACKEND_DLCDPCOOR_REG0 0x8b8
  84. #define SUN4I_BACKEND_DLCDPCOOR_REG1 0x8bc
  85. #define SUN4I_BACKEND_INT_EN_REG 0x8c0
  86. #define SUN4I_BACKEND_INT_FLAG_REG 0x8c4
  87. #define SUN4I_BACKEND_REG_LOAD_FINISHED BIT(1)
  88. #define SUN4I_BACKEND_HWCCTL_REG 0x8d8
  89. #define SUN4I_BACKEND_HWCFBCTL_REG 0x8e0
  90. #define SUN4I_BACKEND_WBCTL_REG 0x8f0
  91. #define SUN4I_BACKEND_WBADD_REG 0x8f4
  92. #define SUN4I_BACKEND_WBLINEWIDTH_REG 0x8f8
  93. #define SUN4I_BACKEND_SPREN_REG 0x900
  94. #define SUN4I_BACKEND_SPRFMTCTL_REG 0x908
  95. #define SUN4I_BACKEND_SPRALPHACTL_REG 0x90c
  96. #define SUN4I_BACKEND_IYUVCTL_REG 0x920
  97. #define SUN4I_BACKEND_IYUVCTL_FBFMT_MASK GENMASK(14, 12)
  98. #define SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV444 (4 << 12)
  99. #define SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422 (3 << 12)
  100. #define SUN4I_BACKEND_IYUVCTL_FBFMT_PLANAR_YUV444 (2 << 12)
  101. #define SUN4I_BACKEND_IYUVCTL_FBFMT_PLANAR_YUV222 (1 << 12)
  102. #define SUN4I_BACKEND_IYUVCTL_FBFMT_PLANAR_YUV111 (0 << 12)
  103. #define SUN4I_BACKEND_IYUVCTL_FBPS_MASK GENMASK(9, 8)
  104. #define SUN4I_BACKEND_IYUVCTL_FBPS_YVYU (3 << 8)
  105. #define SUN4I_BACKEND_IYUVCTL_FBPS_VYUY (2 << 8)
  106. #define SUN4I_BACKEND_IYUVCTL_FBPS_YUYV (1 << 8)
  107. #define SUN4I_BACKEND_IYUVCTL_FBPS_UYVY (0 << 8)
  108. #define SUN4I_BACKEND_IYUVCTL_FBPS_VUYA (1 << 8)
  109. #define SUN4I_BACKEND_IYUVCTL_FBPS_AYUV (0 << 8)
  110. #define SUN4I_BACKEND_IYUVCTL_EN BIT(0)
  111. #define SUN4I_BACKEND_IYUVADD_REG(c) (0x930 + (0x4 * (c)))
  112. #define SUN4I_BACKEND_IYUVLINEWIDTH_REG(c) (0x940 + (0x4 * (c)))
  113. #define SUN4I_BACKEND_YGCOEF_REG(c) (0x950 + (0x4 * (c)))
  114. #define SUN4I_BACKEND_YGCONS_REG 0x95c
  115. #define SUN4I_BACKEND_URCOEF_REG(c) (0x960 + (0x4 * (c)))
  116. #define SUN4I_BACKEND_URCONS_REG 0x96c
  117. #define SUN4I_BACKEND_VBCOEF_REG(c) (0x970 + (0x4 * (c)))
  118. #define SUN4I_BACKEND_VBCONS_REG 0x97c
  119. #define SUN4I_BACKEND_KSCTL_REG 0x980
  120. #define SUN4I_BACKEND_KSBKCOLOR_REG 0x984
  121. #define SUN4I_BACKEND_KSFSTLINEWIDTH_REG 0x988
  122. #define SUN4I_BACKEND_KSVSCAFCT_REG 0x98c
  123. #define SUN4I_BACKEND_KSHSCACOEF_REG(x) (0x9a0 + (0x4 * (x)))
  124. #define SUN4I_BACKEND_OCCTL_REG 0x9c0
  125. #define SUN4I_BACKEND_OCCTL_ENABLE BIT(0)
  126. #define SUN4I_BACKEND_OCRCOEF_REG(x) (0x9d0 + (0x4 * (x)))
  127. #define SUN4I_BACKEND_OCRCONS_REG 0x9dc
  128. #define SUN4I_BACKEND_OCGCOEF_REG(x) (0x9e0 + (0x4 * (x)))
  129. #define SUN4I_BACKEND_OCGCONS_REG 0x9ec
  130. #define SUN4I_BACKEND_OCBCOEF_REG(x) (0x9f0 + (0x4 * (x)))
  131. #define SUN4I_BACKEND_OCBCONS_REG 0x9fc
  132. #define SUN4I_BACKEND_SPRCOORCTL_REG(s) (0xa00 + (0x4 * (s)))
  133. #define SUN4I_BACKEND_SPRATTCTL_REG(s) (0xb00 + (0x4 * (s)))
  134. #define SUN4I_BACKEND_SPRADD_REG(s) (0xc00 + (0x4 * (s)))
  135. #define SUN4I_BACKEND_SPRLINEWIDTH_REG(s) (0xd00 + (0x4 * (s)))
  136. #define SUN4I_BACKEND_SPRPALTAB_OFF 0x4000
  137. #define SUN4I_BACKEND_GAMMATAB_OFF 0x4400
  138. #define SUN4I_BACKEND_HWCPATTERN_OFF 0x4800
  139. #define SUN4I_BACKEND_HWCCOLORTAB_OFF 0x4c00
  140. #define SUN4I_BACKEND_PIPE_OFF(p) (0x5000 + (0x400 * (p)))
  141. #define SUN4I_BACKEND_NUM_LAYERS 4
  142. #define SUN4I_BACKEND_NUM_FRONTEND_LAYERS 1
  143. #define SUN4I_BACKEND_NUM_YUV_PLANES 1
  144. struct sun4i_backend {
  145. struct sunxi_engine engine;
  146. struct sun4i_frontend *frontend;
  147. struct reset_control *reset;
  148. struct clk *bus_clk;
  149. struct clk *mod_clk;
  150. struct clk *ram_clk;
  151. struct clk *sat_clk;
  152. struct reset_control *sat_reset;
  153. /* Protects against races in the frontend teardown */
  154. spinlock_t frontend_lock;
  155. bool frontend_teardown;
  156. const struct sun4i_backend_quirks *quirks;
  157. };
  158. static inline struct sun4i_backend *
  159. engine_to_sun4i_backend(struct sunxi_engine *engine)
  160. {
  161. return container_of(engine, struct sun4i_backend, engine);
  162. }
  163. void sun4i_backend_layer_enable(struct sun4i_backend *backend,
  164. int layer, bool enable);
  165. bool sun4i_backend_format_is_supported(uint32_t fmt, uint64_t modifier);
  166. int sun4i_backend_update_layer_coord(struct sun4i_backend *backend,
  167. int layer, struct drm_plane *plane);
  168. int sun4i_backend_update_layer_formats(struct sun4i_backend *backend,
  169. int layer, struct drm_plane *plane);
  170. int sun4i_backend_update_layer_buffer(struct sun4i_backend *backend,
  171. int layer, struct drm_plane *plane);
  172. int sun4i_backend_update_layer_frontend(struct sun4i_backend *backend,
  173. int layer, uint32_t in_fmt);
  174. int sun4i_backend_update_layer_zpos(struct sun4i_backend *backend,
  175. int layer, struct drm_plane *plane);
  176. void sun4i_backend_cleanup_layer(struct sun4i_backend *backend,
  177. int layer);
  178. #endif /* _SUN4I_BACKEND_H_ */