mtk_drm_crtc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <asm/barrier.h>
  14. #include <drm/drmP.h>
  15. #include <drm/drm_atomic_helper.h>
  16. #include <drm/drm_crtc_helper.h>
  17. #include <drm/drm_plane_helper.h>
  18. #include <linux/clk.h>
  19. #include <linux/pm_runtime.h>
  20. #include <soc/mediatek/smi.h>
  21. #include "mtk_drm_drv.h"
  22. #include "mtk_drm_crtc.h"
  23. #include "mtk_drm_ddp.h"
  24. #include "mtk_drm_ddp_comp.h"
  25. #include "mtk_drm_gem.h"
  26. #include "mtk_drm_plane.h"
  27. /**
  28. * struct mtk_drm_crtc - MediaTek specific crtc structure.
  29. * @base: crtc object.
  30. * @enabled: records whether crtc_enable succeeded
  31. * @planes: array of 4 drm_plane structures, one for each overlay plane
  32. * @pending_planes: whether any plane has pending changes to be applied
  33. * @config_regs: memory mapped mmsys configuration register space
  34. * @mutex: handle to one of the ten disp_mutex streams
  35. * @ddp_comp_nr: number of components in ddp_comp
  36. * @ddp_comp: array of pointers the mtk_ddp_comp structures used by this crtc
  37. */
  38. struct mtk_drm_crtc {
  39. struct drm_crtc base;
  40. bool enabled;
  41. bool pending_needs_vblank;
  42. struct drm_pending_vblank_event *event;
  43. struct drm_plane planes[OVL_LAYER_NR];
  44. bool pending_planes;
  45. void __iomem *config_regs;
  46. struct mtk_disp_mutex *mutex;
  47. unsigned int ddp_comp_nr;
  48. struct mtk_ddp_comp **ddp_comp;
  49. };
  50. struct mtk_crtc_state {
  51. struct drm_crtc_state base;
  52. bool pending_config;
  53. unsigned int pending_width;
  54. unsigned int pending_height;
  55. unsigned int pending_vrefresh;
  56. };
  57. static inline struct mtk_drm_crtc *to_mtk_crtc(struct drm_crtc *c)
  58. {
  59. return container_of(c, struct mtk_drm_crtc, base);
  60. }
  61. static inline struct mtk_crtc_state *to_mtk_crtc_state(struct drm_crtc_state *s)
  62. {
  63. return container_of(s, struct mtk_crtc_state, base);
  64. }
  65. static void mtk_drm_crtc_finish_page_flip(struct mtk_drm_crtc *mtk_crtc)
  66. {
  67. struct drm_crtc *crtc = &mtk_crtc->base;
  68. unsigned long flags;
  69. spin_lock_irqsave(&crtc->dev->event_lock, flags);
  70. drm_crtc_send_vblank_event(crtc, mtk_crtc->event);
  71. drm_crtc_vblank_put(crtc);
  72. mtk_crtc->event = NULL;
  73. spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  74. }
  75. static void mtk_drm_finish_page_flip(struct mtk_drm_crtc *mtk_crtc)
  76. {
  77. drm_crtc_handle_vblank(&mtk_crtc->base);
  78. if (mtk_crtc->pending_needs_vblank) {
  79. mtk_drm_crtc_finish_page_flip(mtk_crtc);
  80. mtk_crtc->pending_needs_vblank = false;
  81. }
  82. }
  83. static void mtk_drm_crtc_destroy(struct drm_crtc *crtc)
  84. {
  85. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  86. int i;
  87. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  88. clk_unprepare(mtk_crtc->ddp_comp[i]->clk);
  89. mtk_disp_mutex_put(mtk_crtc->mutex);
  90. drm_crtc_cleanup(crtc);
  91. }
  92. static void mtk_drm_crtc_reset(struct drm_crtc *crtc)
  93. {
  94. struct mtk_crtc_state *state;
  95. if (crtc->state) {
  96. __drm_atomic_helper_crtc_destroy_state(crtc->state);
  97. state = to_mtk_crtc_state(crtc->state);
  98. memset(state, 0, sizeof(*state));
  99. } else {
  100. state = kzalloc(sizeof(*state), GFP_KERNEL);
  101. if (!state)
  102. return;
  103. crtc->state = &state->base;
  104. }
  105. state->base.crtc = crtc;
  106. }
  107. static struct drm_crtc_state *mtk_drm_crtc_duplicate_state(struct drm_crtc *crtc)
  108. {
  109. struct mtk_crtc_state *state;
  110. state = kzalloc(sizeof(*state), GFP_KERNEL);
  111. if (!state)
  112. return NULL;
  113. __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
  114. WARN_ON(state->base.crtc != crtc);
  115. state->base.crtc = crtc;
  116. return &state->base;
  117. }
  118. static void mtk_drm_crtc_destroy_state(struct drm_crtc *crtc,
  119. struct drm_crtc_state *state)
  120. {
  121. __drm_atomic_helper_crtc_destroy_state(state);
  122. kfree(to_mtk_crtc_state(state));
  123. }
  124. static bool mtk_drm_crtc_mode_fixup(struct drm_crtc *crtc,
  125. const struct drm_display_mode *mode,
  126. struct drm_display_mode *adjusted_mode)
  127. {
  128. /* Nothing to do here, but this callback is mandatory. */
  129. return true;
  130. }
  131. static void mtk_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
  132. {
  133. struct mtk_crtc_state *state = to_mtk_crtc_state(crtc->state);
  134. state->pending_width = crtc->mode.hdisplay;
  135. state->pending_height = crtc->mode.vdisplay;
  136. state->pending_vrefresh = crtc->mode.vrefresh;
  137. wmb(); /* Make sure the above parameters are set before update */
  138. state->pending_config = true;
  139. }
  140. int mtk_drm_crtc_enable_vblank(struct drm_device *drm, unsigned int pipe)
  141. {
  142. struct mtk_drm_private *priv = drm->dev_private;
  143. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(priv->crtc[pipe]);
  144. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  145. mtk_ddp_comp_enable_vblank(ovl, &mtk_crtc->base);
  146. return 0;
  147. }
  148. void mtk_drm_crtc_disable_vblank(struct drm_device *drm, unsigned int pipe)
  149. {
  150. struct mtk_drm_private *priv = drm->dev_private;
  151. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(priv->crtc[pipe]);
  152. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  153. mtk_ddp_comp_disable_vblank(ovl);
  154. }
  155. static int mtk_crtc_ddp_clk_enable(struct mtk_drm_crtc *mtk_crtc)
  156. {
  157. int ret;
  158. int i;
  159. DRM_DEBUG_DRIVER("%s\n", __func__);
  160. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
  161. ret = clk_enable(mtk_crtc->ddp_comp[i]->clk);
  162. if (ret) {
  163. DRM_ERROR("Failed to enable clock %d: %d\n", i, ret);
  164. goto err;
  165. }
  166. }
  167. return 0;
  168. err:
  169. while (--i >= 0)
  170. clk_disable(mtk_crtc->ddp_comp[i]->clk);
  171. return ret;
  172. }
  173. static void mtk_crtc_ddp_clk_disable(struct mtk_drm_crtc *mtk_crtc)
  174. {
  175. int i;
  176. DRM_DEBUG_DRIVER("%s\n", __func__);
  177. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  178. clk_disable(mtk_crtc->ddp_comp[i]->clk);
  179. }
  180. static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
  181. {
  182. struct drm_crtc *crtc = &mtk_crtc->base;
  183. struct drm_connector *connector;
  184. struct drm_encoder *encoder;
  185. unsigned int width, height, vrefresh, bpc = MTK_MAX_BPC;
  186. int ret;
  187. int i;
  188. DRM_DEBUG_DRIVER("%s\n", __func__);
  189. if (WARN_ON(!crtc->state))
  190. return -EINVAL;
  191. width = crtc->state->adjusted_mode.hdisplay;
  192. height = crtc->state->adjusted_mode.vdisplay;
  193. vrefresh = crtc->state->adjusted_mode.vrefresh;
  194. drm_for_each_encoder(encoder, crtc->dev) {
  195. if (encoder->crtc != crtc)
  196. continue;
  197. drm_for_each_connector(connector, crtc->dev) {
  198. if (connector->encoder != encoder)
  199. continue;
  200. if (connector->display_info.bpc != 0 &&
  201. bpc > connector->display_info.bpc)
  202. bpc = connector->display_info.bpc;
  203. }
  204. }
  205. ret = pm_runtime_get_sync(crtc->dev->dev);
  206. if (ret < 0) {
  207. DRM_ERROR("Failed to enable power domain: %d\n", ret);
  208. return ret;
  209. }
  210. ret = mtk_disp_mutex_prepare(mtk_crtc->mutex);
  211. if (ret < 0) {
  212. DRM_ERROR("Failed to enable mutex clock: %d\n", ret);
  213. goto err_pm_runtime_put;
  214. }
  215. ret = mtk_crtc_ddp_clk_enable(mtk_crtc);
  216. if (ret < 0) {
  217. DRM_ERROR("Failed to enable component clocks: %d\n", ret);
  218. goto err_mutex_unprepare;
  219. }
  220. DRM_DEBUG_DRIVER("mediatek_ddp_ddp_path_setup\n");
  221. for (i = 0; i < mtk_crtc->ddp_comp_nr - 1; i++) {
  222. mtk_ddp_add_comp_to_path(mtk_crtc->config_regs,
  223. mtk_crtc->ddp_comp[i]->id,
  224. mtk_crtc->ddp_comp[i + 1]->id);
  225. mtk_disp_mutex_add_comp(mtk_crtc->mutex,
  226. mtk_crtc->ddp_comp[i]->id);
  227. }
  228. mtk_disp_mutex_add_comp(mtk_crtc->mutex, mtk_crtc->ddp_comp[i]->id);
  229. mtk_disp_mutex_enable(mtk_crtc->mutex);
  230. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
  231. struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[i];
  232. mtk_ddp_comp_config(comp, width, height, vrefresh, bpc);
  233. mtk_ddp_comp_start(comp);
  234. }
  235. /* Initially configure all planes */
  236. for (i = 0; i < OVL_LAYER_NR; i++) {
  237. struct drm_plane *plane = &mtk_crtc->planes[i];
  238. struct mtk_plane_state *plane_state;
  239. plane_state = to_mtk_plane_state(plane->state);
  240. mtk_ddp_comp_layer_config(mtk_crtc->ddp_comp[0], i,
  241. plane_state);
  242. }
  243. return 0;
  244. err_mutex_unprepare:
  245. mtk_disp_mutex_unprepare(mtk_crtc->mutex);
  246. err_pm_runtime_put:
  247. pm_runtime_put(crtc->dev->dev);
  248. return ret;
  249. }
  250. static void mtk_crtc_ddp_hw_fini(struct mtk_drm_crtc *mtk_crtc)
  251. {
  252. struct drm_device *drm = mtk_crtc->base.dev;
  253. int i;
  254. DRM_DEBUG_DRIVER("%s\n", __func__);
  255. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  256. mtk_ddp_comp_stop(mtk_crtc->ddp_comp[i]);
  257. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  258. mtk_disp_mutex_remove_comp(mtk_crtc->mutex,
  259. mtk_crtc->ddp_comp[i]->id);
  260. mtk_disp_mutex_disable(mtk_crtc->mutex);
  261. for (i = 0; i < mtk_crtc->ddp_comp_nr - 1; i++) {
  262. mtk_ddp_remove_comp_from_path(mtk_crtc->config_regs,
  263. mtk_crtc->ddp_comp[i]->id,
  264. mtk_crtc->ddp_comp[i + 1]->id);
  265. mtk_disp_mutex_remove_comp(mtk_crtc->mutex,
  266. mtk_crtc->ddp_comp[i]->id);
  267. }
  268. mtk_disp_mutex_remove_comp(mtk_crtc->mutex, mtk_crtc->ddp_comp[i]->id);
  269. mtk_crtc_ddp_clk_disable(mtk_crtc);
  270. mtk_disp_mutex_unprepare(mtk_crtc->mutex);
  271. pm_runtime_put(drm->dev);
  272. }
  273. static void mtk_drm_crtc_enable(struct drm_crtc *crtc)
  274. {
  275. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  276. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  277. int ret;
  278. DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
  279. ret = mtk_smi_larb_get(ovl->larb_dev);
  280. if (ret) {
  281. DRM_ERROR("Failed to get larb: %d\n", ret);
  282. return;
  283. }
  284. ret = mtk_crtc_ddp_hw_init(mtk_crtc);
  285. if (ret) {
  286. mtk_smi_larb_put(ovl->larb_dev);
  287. return;
  288. }
  289. drm_crtc_vblank_on(crtc);
  290. mtk_crtc->enabled = true;
  291. }
  292. static void mtk_drm_crtc_disable(struct drm_crtc *crtc)
  293. {
  294. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  295. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  296. int i;
  297. DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
  298. if (!mtk_crtc->enabled)
  299. return;
  300. /* Set all pending plane state to disabled */
  301. for (i = 0; i < OVL_LAYER_NR; i++) {
  302. struct drm_plane *plane = &mtk_crtc->planes[i];
  303. struct mtk_plane_state *plane_state;
  304. plane_state = to_mtk_plane_state(plane->state);
  305. plane_state->pending.enable = false;
  306. plane_state->pending.config = true;
  307. }
  308. mtk_crtc->pending_planes = true;
  309. /* Wait for planes to be disabled */
  310. drm_crtc_wait_one_vblank(crtc);
  311. drm_crtc_vblank_off(crtc);
  312. mtk_crtc_ddp_hw_fini(mtk_crtc);
  313. mtk_smi_larb_put(ovl->larb_dev);
  314. mtk_crtc->enabled = false;
  315. }
  316. static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc,
  317. struct drm_crtc_state *old_crtc_state)
  318. {
  319. struct mtk_crtc_state *state = to_mtk_crtc_state(crtc->state);
  320. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  321. if (mtk_crtc->event && state->base.event)
  322. DRM_ERROR("new event while there is still a pending event\n");
  323. if (state->base.event) {
  324. state->base.event->pipe = drm_crtc_index(crtc);
  325. WARN_ON(drm_crtc_vblank_get(crtc) != 0);
  326. mtk_crtc->event = state->base.event;
  327. state->base.event = NULL;
  328. }
  329. }
  330. static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc,
  331. struct drm_crtc_state *old_crtc_state)
  332. {
  333. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  334. unsigned int pending_planes = 0;
  335. int i;
  336. if (mtk_crtc->event)
  337. mtk_crtc->pending_needs_vblank = true;
  338. for (i = 0; i < OVL_LAYER_NR; i++) {
  339. struct drm_plane *plane = &mtk_crtc->planes[i];
  340. struct mtk_plane_state *plane_state;
  341. plane_state = to_mtk_plane_state(plane->state);
  342. if (plane_state->pending.dirty) {
  343. plane_state->pending.config = true;
  344. plane_state->pending.dirty = false;
  345. pending_planes |= BIT(i);
  346. }
  347. }
  348. if (pending_planes)
  349. mtk_crtc->pending_planes = true;
  350. if (crtc->state->color_mgmt_changed)
  351. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  352. mtk_ddp_gamma_set(mtk_crtc->ddp_comp[i], crtc->state);
  353. }
  354. static const struct drm_crtc_funcs mtk_crtc_funcs = {
  355. .set_config = drm_atomic_helper_set_config,
  356. .page_flip = drm_atomic_helper_page_flip,
  357. .destroy = mtk_drm_crtc_destroy,
  358. .reset = mtk_drm_crtc_reset,
  359. .atomic_duplicate_state = mtk_drm_crtc_duplicate_state,
  360. .atomic_destroy_state = mtk_drm_crtc_destroy_state,
  361. .gamma_set = drm_atomic_helper_legacy_gamma_set,
  362. };
  363. static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs = {
  364. .mode_fixup = mtk_drm_crtc_mode_fixup,
  365. .mode_set_nofb = mtk_drm_crtc_mode_set_nofb,
  366. .enable = mtk_drm_crtc_enable,
  367. .disable = mtk_drm_crtc_disable,
  368. .atomic_begin = mtk_drm_crtc_atomic_begin,
  369. .atomic_flush = mtk_drm_crtc_atomic_flush,
  370. };
  371. static int mtk_drm_crtc_init(struct drm_device *drm,
  372. struct mtk_drm_crtc *mtk_crtc,
  373. struct drm_plane *primary,
  374. struct drm_plane *cursor, unsigned int pipe)
  375. {
  376. int ret;
  377. ret = drm_crtc_init_with_planes(drm, &mtk_crtc->base, primary, cursor,
  378. &mtk_crtc_funcs, NULL);
  379. if (ret)
  380. goto err_cleanup_crtc;
  381. drm_crtc_helper_add(&mtk_crtc->base, &mtk_crtc_helper_funcs);
  382. return 0;
  383. err_cleanup_crtc:
  384. drm_crtc_cleanup(&mtk_crtc->base);
  385. return ret;
  386. }
  387. void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *ovl)
  388. {
  389. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  390. struct mtk_crtc_state *state = to_mtk_crtc_state(mtk_crtc->base.state);
  391. unsigned int i;
  392. /*
  393. * TODO: instead of updating the registers here, we should prepare
  394. * working registers in atomic_commit and let the hardware command
  395. * queue update module registers on vblank.
  396. */
  397. if (state->pending_config) {
  398. mtk_ddp_comp_config(ovl, state->pending_width,
  399. state->pending_height,
  400. state->pending_vrefresh, 0);
  401. state->pending_config = false;
  402. }
  403. if (mtk_crtc->pending_planes) {
  404. for (i = 0; i < OVL_LAYER_NR; i++) {
  405. struct drm_plane *plane = &mtk_crtc->planes[i];
  406. struct mtk_plane_state *plane_state;
  407. plane_state = to_mtk_plane_state(plane->state);
  408. if (plane_state->pending.config) {
  409. mtk_ddp_comp_layer_config(ovl, i, plane_state);
  410. plane_state->pending.config = false;
  411. }
  412. }
  413. mtk_crtc->pending_planes = false;
  414. }
  415. mtk_drm_finish_page_flip(mtk_crtc);
  416. }
  417. int mtk_drm_crtc_create(struct drm_device *drm_dev,
  418. const enum mtk_ddp_comp_id *path, unsigned int path_len)
  419. {
  420. struct mtk_drm_private *priv = drm_dev->dev_private;
  421. struct device *dev = drm_dev->dev;
  422. struct mtk_drm_crtc *mtk_crtc;
  423. enum drm_plane_type type;
  424. unsigned int zpos;
  425. int pipe = priv->num_pipes;
  426. int ret;
  427. int i;
  428. for (i = 0; i < path_len; i++) {
  429. enum mtk_ddp_comp_id comp_id = path[i];
  430. struct device_node *node;
  431. node = priv->comp_node[comp_id];
  432. if (!node) {
  433. dev_info(dev,
  434. "Not creating crtc %d because component %d is disabled or missing\n",
  435. pipe, comp_id);
  436. return 0;
  437. }
  438. }
  439. mtk_crtc = devm_kzalloc(dev, sizeof(*mtk_crtc), GFP_KERNEL);
  440. if (!mtk_crtc)
  441. return -ENOMEM;
  442. mtk_crtc->config_regs = priv->config_regs;
  443. mtk_crtc->ddp_comp_nr = path_len;
  444. mtk_crtc->ddp_comp = devm_kmalloc_array(dev, mtk_crtc->ddp_comp_nr,
  445. sizeof(*mtk_crtc->ddp_comp),
  446. GFP_KERNEL);
  447. mtk_crtc->mutex = mtk_disp_mutex_get(priv->mutex_dev, pipe);
  448. if (IS_ERR(mtk_crtc->mutex)) {
  449. ret = PTR_ERR(mtk_crtc->mutex);
  450. dev_err(dev, "Failed to get mutex: %d\n", ret);
  451. return ret;
  452. }
  453. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
  454. enum mtk_ddp_comp_id comp_id = path[i];
  455. struct mtk_ddp_comp *comp;
  456. struct device_node *node;
  457. node = priv->comp_node[comp_id];
  458. comp = priv->ddp_comp[comp_id];
  459. if (!comp) {
  460. dev_err(dev, "Component %s not initialized\n",
  461. node->full_name);
  462. ret = -ENODEV;
  463. goto unprepare;
  464. }
  465. ret = clk_prepare(comp->clk);
  466. if (ret) {
  467. dev_err(dev,
  468. "Failed to prepare clock for component %s: %d\n",
  469. node->full_name, ret);
  470. goto unprepare;
  471. }
  472. mtk_crtc->ddp_comp[i] = comp;
  473. }
  474. for (zpos = 0; zpos < OVL_LAYER_NR; zpos++) {
  475. type = (zpos == 0) ? DRM_PLANE_TYPE_PRIMARY :
  476. (zpos == 1) ? DRM_PLANE_TYPE_CURSOR :
  477. DRM_PLANE_TYPE_OVERLAY;
  478. ret = mtk_plane_init(drm_dev, &mtk_crtc->planes[zpos],
  479. BIT(pipe), type);
  480. if (ret)
  481. goto unprepare;
  482. }
  483. ret = mtk_drm_crtc_init(drm_dev, mtk_crtc, &mtk_crtc->planes[0],
  484. &mtk_crtc->planes[1], pipe);
  485. if (ret < 0)
  486. goto unprepare;
  487. drm_mode_crtc_set_gamma_size(&mtk_crtc->base, MTK_LUT_SIZE);
  488. drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, false, MTK_LUT_SIZE);
  489. priv->crtc[pipe] = &mtk_crtc->base;
  490. priv->num_pipes++;
  491. return 0;
  492. unprepare:
  493. while (--i >= 0)
  494. clk_unprepare(mtk_crtc->ddp_comp[i]->clk);
  495. return ret;
  496. }