meson_plane.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2016 BayLibre, SAS
  4. * Author: Neil Armstrong <narmstrong@baylibre.com>
  5. * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
  6. * Copyright (C) 2014 Endless Mobile
  7. *
  8. * Written by:
  9. * Jasper St. Pierre <jstpierre@mecheye.net>
  10. */
  11. #include <linux/bitfield.h>
  12. #include <drm/drm_atomic.h>
  13. #include <drm/drm_atomic_helper.h>
  14. #include <drm/drm_blend.h>
  15. #include <drm/drm_device.h>
  16. #include <drm/drm_fb_dma_helper.h>
  17. #include <drm/drm_fourcc.h>
  18. #include <drm/drm_framebuffer.h>
  19. #include <drm/drm_gem_atomic_helper.h>
  20. #include <drm/drm_gem_dma_helper.h>
  21. #include <drm/drm_print.h>
  22. #include "meson_plane.h"
  23. #include "meson_registers.h"
  24. #include "meson_viu.h"
  25. #include "meson_osd_afbcd.h"
  26. /* OSD_SCI_WH_M1 */
  27. #define SCI_WH_M1_W(w) FIELD_PREP(GENMASK(28, 16), w)
  28. #define SCI_WH_M1_H(h) FIELD_PREP(GENMASK(12, 0), h)
  29. /* OSD_SCO_H_START_END */
  30. /* OSD_SCO_V_START_END */
  31. #define SCO_HV_START(start) FIELD_PREP(GENMASK(27, 16), start)
  32. #define SCO_HV_END(end) FIELD_PREP(GENMASK(11, 0), end)
  33. /* OSD_SC_CTRL0 */
  34. #define SC_CTRL0_PATH_EN BIT(3)
  35. #define SC_CTRL0_SEL_OSD1 BIT(2)
  36. /* OSD_VSC_CTRL0 */
  37. #define VSC_BANK_LEN(value) FIELD_PREP(GENMASK(2, 0), value)
  38. #define VSC_TOP_INI_RCV_NUM(value) FIELD_PREP(GENMASK(6, 3), value)
  39. #define VSC_TOP_RPT_L0_NUM(value) FIELD_PREP(GENMASK(9, 8), value)
  40. #define VSC_BOT_INI_RCV_NUM(value) FIELD_PREP(GENMASK(14, 11), value)
  41. #define VSC_BOT_RPT_L0_NUM(value) FIELD_PREP(GENMASK(17, 16), value)
  42. #define VSC_PROG_INTERLACE BIT(23)
  43. #define VSC_VERTICAL_SCALER_EN BIT(24)
  44. /* OSD_VSC_INI_PHASE */
  45. #define VSC_INI_PHASE_BOT(bottom) FIELD_PREP(GENMASK(31, 16), bottom)
  46. #define VSC_INI_PHASE_TOP(top) FIELD_PREP(GENMASK(15, 0), top)
  47. /* OSD_HSC_CTRL0 */
  48. #define HSC_BANK_LENGTH(value) FIELD_PREP(GENMASK(2, 0), value)
  49. #define HSC_INI_RCV_NUM0(value) FIELD_PREP(GENMASK(6, 3), value)
  50. #define HSC_RPT_P0_NUM0(value) FIELD_PREP(GENMASK(9, 8), value)
  51. #define HSC_HORIZ_SCALER_EN BIT(22)
  52. /* VPP_OSD_VSC_PHASE_STEP */
  53. /* VPP_OSD_HSC_PHASE_STEP */
  54. #define SC_PHASE_STEP(value) FIELD_PREP(GENMASK(27, 0), value)
  55. struct meson_plane {
  56. struct drm_plane base;
  57. struct meson_drm *priv;
  58. bool enabled;
  59. };
  60. #define to_meson_plane(x) container_of(x, struct meson_plane, base)
  61. #define FRAC_16_16(mult, div) (((mult) << 16) / (div))
  62. static int meson_plane_atomic_check(struct drm_plane *plane,
  63. struct drm_atomic_state *state)
  64. {
  65. struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
  66. plane);
  67. struct drm_crtc_state *crtc_state;
  68. if (!new_plane_state->crtc)
  69. return 0;
  70. crtc_state = drm_atomic_get_crtc_state(state,
  71. new_plane_state->crtc);
  72. if (IS_ERR(crtc_state))
  73. return PTR_ERR(crtc_state);
  74. /*
  75. * Only allow :
  76. * - Upscaling up to 5x, vertical and horizontal
  77. * - Final coordinates must match crtc size
  78. */
  79. return drm_atomic_helper_check_plane_state(new_plane_state,
  80. crtc_state,
  81. FRAC_16_16(1, 5),
  82. DRM_PLANE_NO_SCALING,
  83. false, true);
  84. }
  85. #define MESON_MOD_AFBC_VALID_BITS (AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | \
  86. AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | \
  87. AFBC_FORMAT_MOD_YTR | \
  88. AFBC_FORMAT_MOD_SPARSE | \
  89. AFBC_FORMAT_MOD_SPLIT)
  90. /* Takes a fixed 16.16 number and converts it to integer. */
  91. static inline int64_t fixed16_to_int(int64_t value)
  92. {
  93. return value >> 16;
  94. }
  95. static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
  96. {
  97. u32 line_stride = 0;
  98. switch (priv->afbcd.format) {
  99. case DRM_FORMAT_RGB565:
  100. line_stride = ((priv->viu.osd1_width << 4) + 127) >> 7;
  101. break;
  102. case DRM_FORMAT_RGB888:
  103. case DRM_FORMAT_XRGB8888:
  104. case DRM_FORMAT_ARGB8888:
  105. case DRM_FORMAT_XBGR8888:
  106. case DRM_FORMAT_ABGR8888:
  107. line_stride = ((priv->viu.osd1_width << 5) + 127) >> 7;
  108. break;
  109. }
  110. return ((line_stride + 1) >> 1) << 1;
  111. }
  112. static void meson_plane_atomic_update(struct drm_plane *plane,
  113. struct drm_atomic_state *state)
  114. {
  115. struct meson_plane *meson_plane = to_meson_plane(plane);
  116. struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  117. plane);
  118. struct drm_rect dest = drm_plane_state_dest(new_state);
  119. struct meson_drm *priv = meson_plane->priv;
  120. struct drm_framebuffer *fb = new_state->fb;
  121. struct drm_gem_dma_object *gem;
  122. unsigned long flags;
  123. int vsc_ini_rcv_num, vsc_ini_rpt_p0_num;
  124. int vsc_bot_rcv_num, vsc_bot_rpt_p0_num;
  125. int hsc_ini_rcv_num, hsc_ini_rpt_p0_num;
  126. int hf_phase_step, vf_phase_step;
  127. int src_w, src_h, dst_w, dst_h;
  128. int bot_ini_phase;
  129. int hf_bank_len;
  130. int vf_bank_len;
  131. u8 canvas_id_osd1;
  132. /*
  133. * Update Coordinates
  134. * Update Formats
  135. * Update Buffer
  136. * Enable Plane
  137. */
  138. spin_lock_irqsave(&priv->drm->event_lock, flags);
  139. /* Check if AFBC decoder is required for this buffer */
  140. if ((meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
  141. meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) &&
  142. fb->modifier & DRM_FORMAT_MOD_ARM_AFBC(MESON_MOD_AFBC_VALID_BITS))
  143. priv->viu.osd1_afbcd = true;
  144. else
  145. priv->viu.osd1_afbcd = false;
  146. /* Enable OSD and BLK0, set max global alpha */
  147. priv->viu.osd1_ctrl_stat = OSD_ENABLE |
  148. (0x100 << OSD_GLOBAL_ALPHA_SHIFT) |
  149. OSD_BLK0_ENABLE;
  150. priv->viu.osd1_ctrl_stat2 = readl(priv->io_base +
  151. _REG(VIU_OSD1_CTRL_STAT2));
  152. canvas_id_osd1 = priv->canvas_id_osd1;
  153. /* Set up BLK0 to point to the right canvas */
  154. priv->viu.osd1_blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
  155. if (priv->viu.osd1_afbcd) {
  156. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
  157. /* This is the internal decoding memory address */
  158. priv->viu.osd1_blk1_cfg4 = MESON_G12A_AFBCD_OUT_ADDR;
  159. priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_BE;
  160. priv->viu.osd1_ctrl_stat2 |= OSD_PENDING_STAT_CLEAN;
  161. priv->viu.osd1_ctrl_stat |= VIU_OSD1_CFG_SYN_EN;
  162. }
  163. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM)) {
  164. priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_LE;
  165. priv->viu.osd1_ctrl_stat2 |= OSD_DPATH_MALI_AFBCD;
  166. }
  167. } else {
  168. priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_LE;
  169. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
  170. priv->viu.osd1_ctrl_stat2 &= ~OSD_DPATH_MALI_AFBCD;
  171. }
  172. /* On GXBB, Use the old non-HDR RGB2YUV converter */
  173. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
  174. priv->viu.osd1_blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
  175. if (priv->viu.osd1_afbcd &&
  176. meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
  177. priv->viu.osd1_blk0_cfg[0] |= OSD_MALI_SRC_EN |
  178. priv->afbcd.ops->fmt_to_blk_mode(fb->modifier,
  179. fb->format->format);
  180. } else {
  181. switch (fb->format->format) {
  182. case DRM_FORMAT_XRGB8888:
  183. case DRM_FORMAT_ARGB8888:
  184. priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
  185. OSD_COLOR_MATRIX_32_ARGB;
  186. break;
  187. case DRM_FORMAT_XBGR8888:
  188. case DRM_FORMAT_ABGR8888:
  189. priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
  190. OSD_COLOR_MATRIX_32_ABGR;
  191. break;
  192. case DRM_FORMAT_RGB888:
  193. priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_24 |
  194. OSD_COLOR_MATRIX_24_RGB;
  195. break;
  196. case DRM_FORMAT_RGB565:
  197. priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_16 |
  198. OSD_COLOR_MATRIX_16_RGB565;
  199. break;
  200. }
  201. }
  202. switch (fb->format->format) {
  203. case DRM_FORMAT_XRGB8888:
  204. case DRM_FORMAT_XBGR8888:
  205. /* For XRGB, replace the pixel's alpha by 0xFF */
  206. priv->viu.osd1_ctrl_stat2 |= OSD_REPLACE_EN;
  207. break;
  208. case DRM_FORMAT_ARGB8888:
  209. case DRM_FORMAT_ABGR8888:
  210. /* For ARGB, use the pixel's alpha */
  211. priv->viu.osd1_ctrl_stat2 &= ~OSD_REPLACE_EN;
  212. break;
  213. }
  214. /* Default scaler parameters */
  215. vsc_bot_rcv_num = 0;
  216. vsc_bot_rpt_p0_num = 0;
  217. hf_bank_len = 4;
  218. vf_bank_len = 4;
  219. if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
  220. vsc_bot_rcv_num = 6;
  221. vsc_bot_rpt_p0_num = 2;
  222. }
  223. hsc_ini_rcv_num = hf_bank_len;
  224. vsc_ini_rcv_num = vf_bank_len;
  225. hsc_ini_rpt_p0_num = (hf_bank_len / 2) - 1;
  226. vsc_ini_rpt_p0_num = (vf_bank_len / 2) - 1;
  227. src_w = fixed16_to_int(new_state->src_w);
  228. src_h = fixed16_to_int(new_state->src_h);
  229. dst_w = new_state->crtc_w;
  230. dst_h = new_state->crtc_h;
  231. /*
  232. * When the output is interlaced, the OSD must switch between
  233. * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
  234. * at each vsync.
  235. * But the vertical scaler can provide such funtionnality if
  236. * is configured for 2:1 scaling with interlace options enabled.
  237. */
  238. if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
  239. dest.y1 /= 2;
  240. dest.y2 /= 2;
  241. dst_h /= 2;
  242. }
  243. hf_phase_step = ((src_w << 18) / dst_w) << 6;
  244. vf_phase_step = (src_h << 20) / dst_h;
  245. if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
  246. bot_ini_phase = ((vf_phase_step / 2) >> 4);
  247. else
  248. bot_ini_phase = 0;
  249. vf_phase_step = (vf_phase_step << 4);
  250. /* In interlaced mode, scaler is always active */
  251. if (src_h != dst_h || src_w != dst_w) {
  252. priv->viu.osd_sc_i_wh_m1 = SCI_WH_M1_W(src_w - 1) |
  253. SCI_WH_M1_H(src_h - 1);
  254. priv->viu.osd_sc_o_h_start_end = SCO_HV_START(dest.x1) |
  255. SCO_HV_END(dest.x2 - 1);
  256. priv->viu.osd_sc_o_v_start_end = SCO_HV_START(dest.y1) |
  257. SCO_HV_END(dest.y2 - 1);
  258. /* Enable OSD Scaler */
  259. priv->viu.osd_sc_ctrl0 = SC_CTRL0_PATH_EN | SC_CTRL0_SEL_OSD1;
  260. } else {
  261. priv->viu.osd_sc_i_wh_m1 = 0;
  262. priv->viu.osd_sc_o_h_start_end = 0;
  263. priv->viu.osd_sc_o_v_start_end = 0;
  264. priv->viu.osd_sc_ctrl0 = 0;
  265. }
  266. /* In interlaced mode, vertical scaler is always active */
  267. if (src_h != dst_h) {
  268. priv->viu.osd_sc_v_ctrl0 =
  269. VSC_BANK_LEN(vf_bank_len) |
  270. VSC_TOP_INI_RCV_NUM(vsc_ini_rcv_num) |
  271. VSC_TOP_RPT_L0_NUM(vsc_ini_rpt_p0_num) |
  272. VSC_VERTICAL_SCALER_EN;
  273. if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
  274. priv->viu.osd_sc_v_ctrl0 |=
  275. VSC_BOT_INI_RCV_NUM(vsc_bot_rcv_num) |
  276. VSC_BOT_RPT_L0_NUM(vsc_bot_rpt_p0_num) |
  277. VSC_PROG_INTERLACE;
  278. priv->viu.osd_sc_v_phase_step = SC_PHASE_STEP(vf_phase_step);
  279. priv->viu.osd_sc_v_ini_phase = VSC_INI_PHASE_BOT(bot_ini_phase);
  280. } else {
  281. priv->viu.osd_sc_v_ctrl0 = 0;
  282. priv->viu.osd_sc_v_phase_step = 0;
  283. priv->viu.osd_sc_v_ini_phase = 0;
  284. }
  285. /* Horizontal scaler is only used if width does not match */
  286. if (src_w != dst_w) {
  287. priv->viu.osd_sc_h_ctrl0 =
  288. HSC_BANK_LENGTH(hf_bank_len) |
  289. HSC_INI_RCV_NUM0(hsc_ini_rcv_num) |
  290. HSC_RPT_P0_NUM0(hsc_ini_rpt_p0_num) |
  291. HSC_HORIZ_SCALER_EN;
  292. priv->viu.osd_sc_h_phase_step = SC_PHASE_STEP(hf_phase_step);
  293. priv->viu.osd_sc_h_ini_phase = 0;
  294. } else {
  295. priv->viu.osd_sc_h_ctrl0 = 0;
  296. priv->viu.osd_sc_h_phase_step = 0;
  297. priv->viu.osd_sc_h_ini_phase = 0;
  298. }
  299. /*
  300. * The format of these registers is (x2 << 16 | x1),
  301. * where x2 is exclusive.
  302. * e.g. +30x1920 would be (1919 << 16) | 30
  303. */
  304. priv->viu.osd1_blk0_cfg[1] =
  305. ((fixed16_to_int(new_state->src.x2) - 1) << 16) |
  306. fixed16_to_int(new_state->src.x1);
  307. priv->viu.osd1_blk0_cfg[2] =
  308. ((fixed16_to_int(new_state->src.y2) - 1) << 16) |
  309. fixed16_to_int(new_state->src.y1);
  310. priv->viu.osd1_blk0_cfg[3] = ((dest.x2 - 1) << 16) | dest.x1;
  311. priv->viu.osd1_blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
  312. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
  313. priv->viu.osd_blend_din0_scope_h = ((dest.x2 - 1) << 16) | dest.x1;
  314. priv->viu.osd_blend_din0_scope_v = ((dest.y2 - 1) << 16) | dest.y1;
  315. priv->viu.osb_blend0_size = dst_h << 16 | dst_w;
  316. priv->viu.osb_blend1_size = dst_h << 16 | dst_w;
  317. }
  318. /* Update Canvas with buffer address */
  319. gem = drm_fb_dma_get_gem_obj(fb, 0);
  320. priv->viu.osd1_addr = gem->dma_addr;
  321. priv->viu.osd1_stride = fb->pitches[0];
  322. priv->viu.osd1_height = fb->height;
  323. priv->viu.osd1_width = fb->width;
  324. if (priv->viu.osd1_afbcd) {
  325. priv->afbcd.modifier = fb->modifier;
  326. priv->afbcd.format = fb->format->format;
  327. /* Calculate decoder write stride */
  328. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
  329. priv->viu.osd1_blk2_cfg4 =
  330. meson_g12a_afbcd_line_stride(priv);
  331. }
  332. if (!meson_plane->enabled) {
  333. /* Reset OSD1 before enabling it on GXL+ SoCs */
  334. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
  335. meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
  336. meson_viu_osd1_reset(priv);
  337. meson_plane->enabled = true;
  338. }
  339. priv->viu.osd1_enabled = true;
  340. spin_unlock_irqrestore(&priv->drm->event_lock, flags);
  341. }
  342. static void meson_plane_atomic_disable(struct drm_plane *plane,
  343. struct drm_atomic_state *state)
  344. {
  345. struct meson_plane *meson_plane = to_meson_plane(plane);
  346. struct meson_drm *priv = meson_plane->priv;
  347. if (priv->afbcd.ops) {
  348. priv->afbcd.ops->reset(priv);
  349. priv->afbcd.ops->disable(priv);
  350. }
  351. /* Disable OSD1 */
  352. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
  353. writel_bits_relaxed(VIU_OSD1_POSTBLD_SRC_OSD1, 0,
  354. priv->io_base + _REG(OSD1_BLEND_SRC_CTRL));
  355. else
  356. writel_bits_relaxed(VPP_OSD1_POSTBLEND, 0,
  357. priv->io_base + _REG(VPP_MISC));
  358. meson_plane->enabled = false;
  359. priv->viu.osd1_enabled = false;
  360. }
  361. static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
  362. .atomic_check = meson_plane_atomic_check,
  363. .atomic_disable = meson_plane_atomic_disable,
  364. .atomic_update = meson_plane_atomic_update,
  365. };
  366. static bool meson_plane_format_mod_supported(struct drm_plane *plane,
  367. u32 format, u64 modifier)
  368. {
  369. struct meson_plane *meson_plane = to_meson_plane(plane);
  370. struct meson_drm *priv = meson_plane->priv;
  371. int i;
  372. if (modifier == DRM_FORMAT_MOD_INVALID)
  373. return false;
  374. if (modifier == DRM_FORMAT_MOD_LINEAR)
  375. return true;
  376. if (!meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) &&
  377. !meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
  378. return false;
  379. if (modifier & ~DRM_FORMAT_MOD_ARM_AFBC(MESON_MOD_AFBC_VALID_BITS))
  380. return false;
  381. for (i = 0 ; i < plane->modifier_count ; ++i)
  382. if (plane->modifiers[i] == modifier)
  383. break;
  384. if (i == plane->modifier_count) {
  385. DRM_DEBUG_KMS("Unsupported modifier\n");
  386. return false;
  387. }
  388. if (priv->afbcd.ops && priv->afbcd.ops->supported_fmt)
  389. return priv->afbcd.ops->supported_fmt(modifier, format);
  390. DRM_DEBUG_KMS("AFBC Unsupported\n");
  391. return false;
  392. }
  393. static const struct drm_plane_funcs meson_plane_funcs = {
  394. .update_plane = drm_atomic_helper_update_plane,
  395. .disable_plane = drm_atomic_helper_disable_plane,
  396. .destroy = drm_plane_cleanup,
  397. .reset = drm_atomic_helper_plane_reset,
  398. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  399. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  400. .format_mod_supported = meson_plane_format_mod_supported,
  401. };
  402. static const uint32_t supported_drm_formats[] = {
  403. DRM_FORMAT_ARGB8888,
  404. DRM_FORMAT_ABGR8888,
  405. DRM_FORMAT_XRGB8888,
  406. DRM_FORMAT_XBGR8888,
  407. DRM_FORMAT_RGB888,
  408. DRM_FORMAT_RGB565,
  409. };
  410. static const uint64_t format_modifiers_afbc_gxm[] = {
  411. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
  412. AFBC_FORMAT_MOD_SPARSE |
  413. AFBC_FORMAT_MOD_YTR),
  414. /* SPLIT mandates SPARSE, RGB modes mandates YTR */
  415. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
  416. AFBC_FORMAT_MOD_YTR |
  417. AFBC_FORMAT_MOD_SPARSE |
  418. AFBC_FORMAT_MOD_SPLIT),
  419. DRM_FORMAT_MOD_LINEAR,
  420. DRM_FORMAT_MOD_INVALID,
  421. };
  422. static const uint64_t format_modifiers_afbc_g12a[] = {
  423. /*
  424. * - TOFIX Support AFBC modifiers for YUV formats (16x16 + TILED)
  425. * - SPLIT is mandatory for performances reasons when in 16x16
  426. * block size
  427. * - 32x8 block size + SPLIT is mandatory with 4K frame size
  428. * for performances reasons
  429. */
  430. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
  431. AFBC_FORMAT_MOD_SPARSE |
  432. AFBC_FORMAT_MOD_SPLIT),
  433. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
  434. AFBC_FORMAT_MOD_YTR |
  435. AFBC_FORMAT_MOD_SPARSE |
  436. AFBC_FORMAT_MOD_SPLIT),
  437. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 |
  438. AFBC_FORMAT_MOD_SPARSE),
  439. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 |
  440. AFBC_FORMAT_MOD_YTR |
  441. AFBC_FORMAT_MOD_SPARSE),
  442. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 |
  443. AFBC_FORMAT_MOD_SPARSE |
  444. AFBC_FORMAT_MOD_SPLIT),
  445. DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 |
  446. AFBC_FORMAT_MOD_YTR |
  447. AFBC_FORMAT_MOD_SPARSE |
  448. AFBC_FORMAT_MOD_SPLIT),
  449. DRM_FORMAT_MOD_LINEAR,
  450. DRM_FORMAT_MOD_INVALID,
  451. };
  452. static const uint64_t format_modifiers_default[] = {
  453. DRM_FORMAT_MOD_LINEAR,
  454. DRM_FORMAT_MOD_INVALID,
  455. };
  456. int meson_plane_create(struct meson_drm *priv)
  457. {
  458. struct meson_plane *meson_plane;
  459. struct drm_plane *plane;
  460. const uint64_t *format_modifiers = format_modifiers_default;
  461. int ret;
  462. meson_plane = devm_kzalloc(priv->drm->dev, sizeof(*meson_plane),
  463. GFP_KERNEL);
  464. if (!meson_plane)
  465. return -ENOMEM;
  466. meson_plane->priv = priv;
  467. plane = &meson_plane->base;
  468. if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
  469. format_modifiers = format_modifiers_afbc_gxm;
  470. else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
  471. format_modifiers = format_modifiers_afbc_g12a;
  472. ret = drm_universal_plane_init(priv->drm, plane, 0xFF,
  473. &meson_plane_funcs,
  474. supported_drm_formats,
  475. ARRAY_SIZE(supported_drm_formats),
  476. format_modifiers,
  477. DRM_PLANE_TYPE_PRIMARY, "meson_primary_plane");
  478. if (ret) {
  479. devm_kfree(priv->drm->dev, meson_plane);
  480. return ret;
  481. }
  482. drm_plane_helper_add(plane, &meson_plane_helper_funcs);
  483. /* For now, OSD Primary plane is always on the front */
  484. drm_plane_create_zpos_immutable_property(plane, 1);
  485. priv->primary_plane = plane;
  486. return 0;
  487. }