sun8i_vi_layer.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) Jernej Skrabec <jernej.skrabec@siol.net>
  4. */
  5. #include <drm/drm_atomic.h>
  6. #include <drm/drm_atomic_helper.h>
  7. #include <drm/drm_blend.h>
  8. #include <drm/drm_crtc.h>
  9. #include <drm/drm_fb_dma_helper.h>
  10. #include <drm/drm_framebuffer.h>
  11. #include <drm/drm_gem_atomic_helper.h>
  12. #include <drm/drm_gem_dma_helper.h>
  13. #include <drm/drm_probe_helper.h>
  14. #include "sun8i_csc.h"
  15. #include "sun8i_mixer.h"
  16. #include "sun8i_vi_layer.h"
  17. #include "sun8i_vi_scaler.h"
  18. static void sun8i_vi_layer_update_alpha(struct sun8i_mixer *mixer, int channel,
  19. int overlay, struct drm_plane *plane)
  20. {
  21. u32 mask, val, ch_base;
  22. ch_base = sun8i_channel_base(mixer, channel);
  23. if (mixer->cfg->is_de3) {
  24. mask = SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MASK |
  25. SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_MASK;
  26. val = SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA
  27. (plane->state->alpha >> 8);
  28. val |= (plane->state->alpha == DRM_BLEND_ALPHA_OPAQUE) ?
  29. SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_PIXEL :
  30. SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_COMBINED;
  31. regmap_update_bits(mixer->engine.regs,
  32. SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base,
  33. overlay),
  34. mask, val);
  35. } else if (mixer->cfg->vi_num == 1) {
  36. regmap_update_bits(mixer->engine.regs,
  37. SUN8I_MIXER_FCC_GLOBAL_ALPHA_REG,
  38. SUN8I_MIXER_FCC_GLOBAL_ALPHA_MASK,
  39. SUN8I_MIXER_FCC_GLOBAL_ALPHA
  40. (plane->state->alpha >> 8));
  41. }
  42. }
  43. static int sun8i_vi_layer_update_coord(struct sun8i_mixer *mixer, int channel,
  44. int overlay, struct drm_plane *plane,
  45. unsigned int zpos)
  46. {
  47. struct drm_plane_state *state = plane->state;
  48. const struct drm_format_info *format = state->fb->format;
  49. u32 src_w, src_h, dst_w, dst_h;
  50. u32 bld_base, ch_base;
  51. u32 outsize, insize;
  52. u32 hphase, vphase;
  53. u32 hn = 0, hm = 0;
  54. u32 vn = 0, vm = 0;
  55. bool subsampled;
  56. DRM_DEBUG_DRIVER("Updating VI channel %d overlay %d\n",
  57. channel, overlay);
  58. bld_base = sun8i_blender_base(mixer);
  59. ch_base = sun8i_channel_base(mixer, channel);
  60. src_w = drm_rect_width(&state->src) >> 16;
  61. src_h = drm_rect_height(&state->src) >> 16;
  62. dst_w = drm_rect_width(&state->dst);
  63. dst_h = drm_rect_height(&state->dst);
  64. hphase = state->src.x1 & 0xffff;
  65. vphase = state->src.y1 & 0xffff;
  66. /* make coordinates dividable by subsampling factor */
  67. if (format->hsub > 1) {
  68. int mask, remainder;
  69. mask = format->hsub - 1;
  70. remainder = (state->src.x1 >> 16) & mask;
  71. src_w = (src_w + remainder) & ~mask;
  72. hphase += remainder << 16;
  73. }
  74. if (format->vsub > 1) {
  75. int mask, remainder;
  76. mask = format->vsub - 1;
  77. remainder = (state->src.y1 >> 16) & mask;
  78. src_h = (src_h + remainder) & ~mask;
  79. vphase += remainder << 16;
  80. }
  81. insize = SUN8I_MIXER_SIZE(src_w, src_h);
  82. outsize = SUN8I_MIXER_SIZE(dst_w, dst_h);
  83. /* Set height and width */
  84. DRM_DEBUG_DRIVER("Layer source offset X: %d Y: %d\n",
  85. (state->src.x1 >> 16) & ~(format->hsub - 1),
  86. (state->src.y1 >> 16) & ~(format->vsub - 1));
  87. DRM_DEBUG_DRIVER("Layer source size W: %d H: %d\n", src_w, src_h);
  88. regmap_write(mixer->engine.regs,
  89. SUN8I_MIXER_CHAN_VI_LAYER_SIZE(ch_base, overlay),
  90. insize);
  91. regmap_write(mixer->engine.regs,
  92. SUN8I_MIXER_CHAN_VI_OVL_SIZE(ch_base),
  93. insize);
  94. /*
  95. * Scaler must be enabled for subsampled formats, so it scales
  96. * chroma to same size as luma.
  97. */
  98. subsampled = format->hsub > 1 || format->vsub > 1;
  99. if (insize != outsize || subsampled || hphase || vphase) {
  100. unsigned int scanline, required;
  101. struct drm_display_mode *mode;
  102. u32 hscale, vscale, fps;
  103. u64 ability;
  104. DRM_DEBUG_DRIVER("HW scaling is enabled\n");
  105. mode = &plane->state->crtc->state->mode;
  106. fps = (mode->clock * 1000) / (mode->vtotal * mode->htotal);
  107. ability = clk_get_rate(mixer->mod_clk);
  108. /* BSP algorithm assumes 80% efficiency of VI scaler unit */
  109. ability *= 80;
  110. do_div(ability, mode->vdisplay * fps * max(src_w, dst_w));
  111. required = src_h * 100 / dst_h;
  112. if (ability < required) {
  113. DRM_DEBUG_DRIVER("Using vertical coarse scaling\n");
  114. vm = src_h;
  115. vn = (u32)ability * dst_h / 100;
  116. src_h = vn;
  117. }
  118. /* it seems that every RGB scaler has buffer for 2048 pixels */
  119. scanline = subsampled ? mixer->cfg->scanline_yuv : 2048;
  120. if (src_w > scanline) {
  121. DRM_DEBUG_DRIVER("Using horizontal coarse scaling\n");
  122. hm = src_w;
  123. hn = scanline;
  124. src_w = hn;
  125. }
  126. hscale = (src_w << 16) / dst_w;
  127. vscale = (src_h << 16) / dst_h;
  128. sun8i_vi_scaler_setup(mixer, channel, src_w, src_h, dst_w,
  129. dst_h, hscale, vscale, hphase, vphase,
  130. format);
  131. sun8i_vi_scaler_enable(mixer, channel, true);
  132. } else {
  133. DRM_DEBUG_DRIVER("HW scaling is not needed\n");
  134. sun8i_vi_scaler_enable(mixer, channel, false);
  135. }
  136. regmap_write(mixer->engine.regs,
  137. SUN8I_MIXER_CHAN_VI_HDS_Y(ch_base),
  138. SUN8I_MIXER_CHAN_VI_DS_N(hn) |
  139. SUN8I_MIXER_CHAN_VI_DS_M(hm));
  140. regmap_write(mixer->engine.regs,
  141. SUN8I_MIXER_CHAN_VI_HDS_UV(ch_base),
  142. SUN8I_MIXER_CHAN_VI_DS_N(hn) |
  143. SUN8I_MIXER_CHAN_VI_DS_M(hm));
  144. regmap_write(mixer->engine.regs,
  145. SUN8I_MIXER_CHAN_VI_VDS_Y(ch_base),
  146. SUN8I_MIXER_CHAN_VI_DS_N(vn) |
  147. SUN8I_MIXER_CHAN_VI_DS_M(vm));
  148. regmap_write(mixer->engine.regs,
  149. SUN8I_MIXER_CHAN_VI_VDS_UV(ch_base),
  150. SUN8I_MIXER_CHAN_VI_DS_N(vn) |
  151. SUN8I_MIXER_CHAN_VI_DS_M(vm));
  152. /* Set base coordinates */
  153. DRM_DEBUG_DRIVER("Layer destination coordinates X: %d Y: %d\n",
  154. state->dst.x1, state->dst.y1);
  155. DRM_DEBUG_DRIVER("Layer destination size W: %d H: %d\n", dst_w, dst_h);
  156. regmap_write(mixer->engine.regs,
  157. SUN8I_MIXER_BLEND_ATTR_COORD(bld_base, zpos),
  158. SUN8I_MIXER_COORD(state->dst.x1, state->dst.y1));
  159. regmap_write(mixer->engine.regs,
  160. SUN8I_MIXER_BLEND_ATTR_INSIZE(bld_base, zpos),
  161. outsize);
  162. return 0;
  163. }
  164. static u32 sun8i_vi_layer_get_csc_mode(const struct drm_format_info *format)
  165. {
  166. if (!format->is_yuv)
  167. return SUN8I_CSC_MODE_OFF;
  168. switch (format->format) {
  169. case DRM_FORMAT_YVU411:
  170. case DRM_FORMAT_YVU420:
  171. case DRM_FORMAT_YVU422:
  172. case DRM_FORMAT_YVU444:
  173. return SUN8I_CSC_MODE_YVU2RGB;
  174. default:
  175. return SUN8I_CSC_MODE_YUV2RGB;
  176. }
  177. }
  178. static int sun8i_vi_layer_update_formats(struct sun8i_mixer *mixer, int channel,
  179. int overlay, struct drm_plane *plane)
  180. {
  181. struct drm_plane_state *state = plane->state;
  182. u32 val, ch_base, csc_mode, hw_fmt;
  183. const struct drm_format_info *fmt;
  184. int ret;
  185. ch_base = sun8i_channel_base(mixer, channel);
  186. fmt = state->fb->format;
  187. ret = sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt);
  188. if (ret) {
  189. DRM_DEBUG_DRIVER("Invalid format\n");
  190. return ret;
  191. }
  192. val = hw_fmt << SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_OFFSET;
  193. regmap_update_bits(mixer->engine.regs,
  194. SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base, overlay),
  195. SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_MASK, val);
  196. csc_mode = sun8i_vi_layer_get_csc_mode(fmt);
  197. if (csc_mode != SUN8I_CSC_MODE_OFF) {
  198. sun8i_csc_set_ccsc_coefficients(mixer, channel, csc_mode,
  199. state->color_encoding,
  200. state->color_range);
  201. sun8i_csc_enable_ccsc(mixer, channel, true);
  202. } else {
  203. sun8i_csc_enable_ccsc(mixer, channel, false);
  204. }
  205. if (!fmt->is_yuv)
  206. val = SUN8I_MIXER_CHAN_VI_LAYER_ATTR_RGB_MODE;
  207. else
  208. val = 0;
  209. regmap_update_bits(mixer->engine.regs,
  210. SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base, overlay),
  211. SUN8I_MIXER_CHAN_VI_LAYER_ATTR_RGB_MODE, val);
  212. return 0;
  213. }
  214. static int sun8i_vi_layer_update_buffer(struct sun8i_mixer *mixer, int channel,
  215. int overlay, struct drm_plane *plane)
  216. {
  217. struct drm_plane_state *state = plane->state;
  218. struct drm_framebuffer *fb = state->fb;
  219. const struct drm_format_info *format = fb->format;
  220. struct drm_gem_dma_object *gem;
  221. u32 dx, dy, src_x, src_y;
  222. dma_addr_t dma_addr;
  223. u32 ch_base;
  224. int i;
  225. ch_base = sun8i_channel_base(mixer, channel);
  226. /* Adjust x and y to be dividable by subsampling factor */
  227. src_x = (state->src.x1 >> 16) & ~(format->hsub - 1);
  228. src_y = (state->src.y1 >> 16) & ~(format->vsub - 1);
  229. for (i = 0; i < format->num_planes; i++) {
  230. /* Get the physical address of the buffer in memory */
  231. gem = drm_fb_dma_get_gem_obj(fb, i);
  232. DRM_DEBUG_DRIVER("Using GEM @ %pad\n", &gem->dma_addr);
  233. /* Compute the start of the displayed memory */
  234. dma_addr = gem->dma_addr + fb->offsets[i];
  235. dx = src_x;
  236. dy = src_y;
  237. if (i > 0) {
  238. dx /= format->hsub;
  239. dy /= format->vsub;
  240. }
  241. /* Fixup framebuffer address for src coordinates */
  242. dma_addr += dx * format->cpp[i];
  243. dma_addr += dy * fb->pitches[i];
  244. /* Set the line width */
  245. DRM_DEBUG_DRIVER("Layer %d. line width: %d bytes\n",
  246. i + 1, fb->pitches[i]);
  247. regmap_write(mixer->engine.regs,
  248. SUN8I_MIXER_CHAN_VI_LAYER_PITCH(ch_base,
  249. overlay, i),
  250. fb->pitches[i]);
  251. DRM_DEBUG_DRIVER("Setting %d. buffer address to %pad\n",
  252. i + 1, &dma_addr);
  253. regmap_write(mixer->engine.regs,
  254. SUN8I_MIXER_CHAN_VI_LAYER_TOP_LADDR(ch_base,
  255. overlay, i),
  256. lower_32_bits(dma_addr));
  257. }
  258. return 0;
  259. }
  260. static int sun8i_vi_layer_atomic_check(struct drm_plane *plane,
  261. struct drm_atomic_state *state)
  262. {
  263. struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
  264. plane);
  265. struct sun8i_layer *layer = plane_to_sun8i_layer(plane);
  266. struct drm_crtc *crtc = new_plane_state->crtc;
  267. struct drm_crtc_state *crtc_state;
  268. int min_scale, max_scale;
  269. if (!crtc)
  270. return 0;
  271. crtc_state = drm_atomic_get_existing_crtc_state(state,
  272. crtc);
  273. if (WARN_ON(!crtc_state))
  274. return -EINVAL;
  275. min_scale = DRM_PLANE_NO_SCALING;
  276. max_scale = DRM_PLANE_NO_SCALING;
  277. if (layer->mixer->cfg->scaler_mask & BIT(layer->channel)) {
  278. min_scale = SUN8I_VI_SCALER_SCALE_MIN;
  279. max_scale = SUN8I_VI_SCALER_SCALE_MAX;
  280. }
  281. return drm_atomic_helper_check_plane_state(new_plane_state,
  282. crtc_state,
  283. min_scale, max_scale,
  284. true, true);
  285. }
  286. static void sun8i_vi_layer_atomic_update(struct drm_plane *plane,
  287. struct drm_atomic_state *state)
  288. {
  289. struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  290. plane);
  291. struct sun8i_layer *layer = plane_to_sun8i_layer(plane);
  292. unsigned int zpos = new_state->normalized_zpos;
  293. struct sun8i_mixer *mixer = layer->mixer;
  294. if (!new_state->crtc || !new_state->visible)
  295. return;
  296. sun8i_vi_layer_update_coord(mixer, layer->channel,
  297. layer->overlay, plane, zpos);
  298. sun8i_vi_layer_update_alpha(mixer, layer->channel,
  299. layer->overlay, plane);
  300. sun8i_vi_layer_update_formats(mixer, layer->channel,
  301. layer->overlay, plane);
  302. sun8i_vi_layer_update_buffer(mixer, layer->channel,
  303. layer->overlay, plane);
  304. }
  305. static const struct drm_plane_helper_funcs sun8i_vi_layer_helper_funcs = {
  306. .atomic_check = sun8i_vi_layer_atomic_check,
  307. .atomic_update = sun8i_vi_layer_atomic_update,
  308. };
  309. static const struct drm_plane_funcs sun8i_vi_layer_funcs = {
  310. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  311. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  312. .destroy = drm_plane_cleanup,
  313. .disable_plane = drm_atomic_helper_disable_plane,
  314. .reset = drm_atomic_helper_plane_reset,
  315. .update_plane = drm_atomic_helper_update_plane,
  316. };
  317. /*
  318. * While DE2 VI layer supports same RGB formats as UI layer, alpha
  319. * channel is ignored. This structure lists all unique variants
  320. * where alpha channel is replaced with "don't care" (X) channel.
  321. */
  322. static const u32 sun8i_vi_layer_formats[] = {
  323. DRM_FORMAT_BGR565,
  324. DRM_FORMAT_BGR888,
  325. DRM_FORMAT_BGRX4444,
  326. DRM_FORMAT_BGRX5551,
  327. DRM_FORMAT_BGRX8888,
  328. DRM_FORMAT_RGB565,
  329. DRM_FORMAT_RGB888,
  330. DRM_FORMAT_RGBX4444,
  331. DRM_FORMAT_RGBX5551,
  332. DRM_FORMAT_RGBX8888,
  333. DRM_FORMAT_XBGR1555,
  334. DRM_FORMAT_XBGR4444,
  335. DRM_FORMAT_XBGR8888,
  336. DRM_FORMAT_XRGB1555,
  337. DRM_FORMAT_XRGB4444,
  338. DRM_FORMAT_XRGB8888,
  339. DRM_FORMAT_NV16,
  340. DRM_FORMAT_NV12,
  341. DRM_FORMAT_NV21,
  342. DRM_FORMAT_NV61,
  343. DRM_FORMAT_UYVY,
  344. DRM_FORMAT_VYUY,
  345. DRM_FORMAT_YUYV,
  346. DRM_FORMAT_YVYU,
  347. DRM_FORMAT_YUV411,
  348. DRM_FORMAT_YUV420,
  349. DRM_FORMAT_YUV422,
  350. DRM_FORMAT_YVU411,
  351. DRM_FORMAT_YVU420,
  352. DRM_FORMAT_YVU422,
  353. };
  354. static const u32 sun8i_vi_layer_de3_formats[] = {
  355. DRM_FORMAT_ABGR1555,
  356. DRM_FORMAT_ABGR2101010,
  357. DRM_FORMAT_ABGR4444,
  358. DRM_FORMAT_ABGR8888,
  359. DRM_FORMAT_ARGB1555,
  360. DRM_FORMAT_ARGB2101010,
  361. DRM_FORMAT_ARGB4444,
  362. DRM_FORMAT_ARGB8888,
  363. DRM_FORMAT_BGR565,
  364. DRM_FORMAT_BGR888,
  365. DRM_FORMAT_BGRA1010102,
  366. DRM_FORMAT_BGRA5551,
  367. DRM_FORMAT_BGRA4444,
  368. DRM_FORMAT_BGRA8888,
  369. DRM_FORMAT_BGRX8888,
  370. DRM_FORMAT_RGB565,
  371. DRM_FORMAT_RGB888,
  372. DRM_FORMAT_RGBA1010102,
  373. DRM_FORMAT_RGBA4444,
  374. DRM_FORMAT_RGBA5551,
  375. DRM_FORMAT_RGBA8888,
  376. DRM_FORMAT_RGBX8888,
  377. DRM_FORMAT_XBGR8888,
  378. DRM_FORMAT_XRGB8888,
  379. DRM_FORMAT_NV16,
  380. DRM_FORMAT_NV12,
  381. DRM_FORMAT_NV21,
  382. DRM_FORMAT_NV61,
  383. DRM_FORMAT_P010,
  384. DRM_FORMAT_P210,
  385. DRM_FORMAT_UYVY,
  386. DRM_FORMAT_VYUY,
  387. DRM_FORMAT_YUYV,
  388. DRM_FORMAT_YVYU,
  389. DRM_FORMAT_YUV411,
  390. DRM_FORMAT_YUV420,
  391. DRM_FORMAT_YUV422,
  392. DRM_FORMAT_YVU411,
  393. DRM_FORMAT_YVU420,
  394. DRM_FORMAT_YVU422,
  395. };
  396. static const uint64_t sun8i_layer_modifiers[] = {
  397. DRM_FORMAT_MOD_LINEAR,
  398. DRM_FORMAT_MOD_INVALID
  399. };
  400. struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
  401. struct sun8i_mixer *mixer,
  402. int index)
  403. {
  404. enum drm_plane_type type = DRM_PLANE_TYPE_OVERLAY;
  405. u32 supported_encodings, supported_ranges;
  406. unsigned int plane_cnt, format_count;
  407. struct sun8i_layer *layer;
  408. const u32 *formats;
  409. int ret;
  410. layer = devm_kzalloc(drm->dev, sizeof(*layer), GFP_KERNEL);
  411. if (!layer)
  412. return ERR_PTR(-ENOMEM);
  413. if (mixer->cfg->is_de3) {
  414. formats = sun8i_vi_layer_de3_formats;
  415. format_count = ARRAY_SIZE(sun8i_vi_layer_de3_formats);
  416. } else {
  417. formats = sun8i_vi_layer_formats;
  418. format_count = ARRAY_SIZE(sun8i_vi_layer_formats);
  419. }
  420. if (!mixer->cfg->ui_num && index == 0)
  421. type = DRM_PLANE_TYPE_PRIMARY;
  422. /* possible crtcs are set later */
  423. ret = drm_universal_plane_init(drm, &layer->plane, 0,
  424. &sun8i_vi_layer_funcs,
  425. formats, format_count,
  426. sun8i_layer_modifiers,
  427. type, NULL);
  428. if (ret) {
  429. dev_err(drm->dev, "Couldn't initialize layer\n");
  430. return ERR_PTR(ret);
  431. }
  432. plane_cnt = mixer->cfg->ui_num + mixer->cfg->vi_num;
  433. if (mixer->cfg->vi_num == 1 || mixer->cfg->is_de3) {
  434. ret = drm_plane_create_alpha_property(&layer->plane);
  435. if (ret) {
  436. dev_err(drm->dev, "Couldn't add alpha property\n");
  437. return ERR_PTR(ret);
  438. }
  439. }
  440. ret = drm_plane_create_zpos_property(&layer->plane, index,
  441. 0, plane_cnt - 1);
  442. if (ret) {
  443. dev_err(drm->dev, "Couldn't add zpos property\n");
  444. return ERR_PTR(ret);
  445. }
  446. supported_encodings = BIT(DRM_COLOR_YCBCR_BT601) |
  447. BIT(DRM_COLOR_YCBCR_BT709);
  448. if (mixer->cfg->is_de3)
  449. supported_encodings |= BIT(DRM_COLOR_YCBCR_BT2020);
  450. supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
  451. BIT(DRM_COLOR_YCBCR_FULL_RANGE);
  452. ret = drm_plane_create_color_properties(&layer->plane,
  453. supported_encodings,
  454. supported_ranges,
  455. DRM_COLOR_YCBCR_BT709,
  456. DRM_COLOR_YCBCR_LIMITED_RANGE);
  457. if (ret) {
  458. dev_err(drm->dev, "Couldn't add encoding and range properties!\n");
  459. return ERR_PTR(ret);
  460. }
  461. drm_plane_helper_add(&layer->plane, &sun8i_vi_layer_helper_funcs);
  462. layer->mixer = mixer;
  463. layer->type = SUN8I_LAYER_TYPE_VI;
  464. layer->channel = index;
  465. layer->overlay = 0;
  466. return layer;
  467. }