mtk_drm_crtc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. static int mtk_drm_crtc_enable_vblank(struct drm_crtc *crtc)
  141. {
  142. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  143. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  144. mtk_ddp_comp_enable_vblank(ovl, &mtk_crtc->base);
  145. return 0;
  146. }
  147. static void mtk_drm_crtc_disable_vblank(struct drm_crtc *crtc)
  148. {
  149. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  150. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  151. mtk_ddp_comp_disable_vblank(ovl);
  152. }
  153. static int mtk_crtc_ddp_clk_enable(struct mtk_drm_crtc *mtk_crtc)
  154. {
  155. int ret;
  156. int i;
  157. DRM_DEBUG_DRIVER("%s\n", __func__);
  158. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
  159. ret = clk_enable(mtk_crtc->ddp_comp[i]->clk);
  160. if (ret) {
  161. DRM_ERROR("Failed to enable clock %d: %d\n", i, ret);
  162. goto err;
  163. }
  164. }
  165. return 0;
  166. err:
  167. while (--i >= 0)
  168. clk_disable(mtk_crtc->ddp_comp[i]->clk);
  169. return ret;
  170. }
  171. static void mtk_crtc_ddp_clk_disable(struct mtk_drm_crtc *mtk_crtc)
  172. {
  173. int i;
  174. DRM_DEBUG_DRIVER("%s\n", __func__);
  175. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  176. clk_disable(mtk_crtc->ddp_comp[i]->clk);
  177. }
  178. static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
  179. {
  180. struct drm_crtc *crtc = &mtk_crtc->base;
  181. struct drm_connector *connector;
  182. struct drm_encoder *encoder;
  183. unsigned int width, height, vrefresh, bpc = MTK_MAX_BPC;
  184. int ret;
  185. int i;
  186. DRM_DEBUG_DRIVER("%s\n", __func__);
  187. if (WARN_ON(!crtc->state))
  188. return -EINVAL;
  189. width = crtc->state->adjusted_mode.hdisplay;
  190. height = crtc->state->adjusted_mode.vdisplay;
  191. vrefresh = crtc->state->adjusted_mode.vrefresh;
  192. drm_for_each_encoder(encoder, crtc->dev) {
  193. if (encoder->crtc != crtc)
  194. continue;
  195. drm_for_each_connector(connector, crtc->dev) {
  196. if (connector->encoder != encoder)
  197. continue;
  198. if (connector->display_info.bpc != 0 &&
  199. bpc > connector->display_info.bpc)
  200. bpc = connector->display_info.bpc;
  201. }
  202. }
  203. ret = pm_runtime_get_sync(crtc->dev->dev);
  204. if (ret < 0) {
  205. DRM_ERROR("Failed to enable power domain: %d\n", ret);
  206. return ret;
  207. }
  208. ret = mtk_disp_mutex_prepare(mtk_crtc->mutex);
  209. if (ret < 0) {
  210. DRM_ERROR("Failed to enable mutex clock: %d\n", ret);
  211. goto err_pm_runtime_put;
  212. }
  213. ret = mtk_crtc_ddp_clk_enable(mtk_crtc);
  214. if (ret < 0) {
  215. DRM_ERROR("Failed to enable component clocks: %d\n", ret);
  216. goto err_mutex_unprepare;
  217. }
  218. DRM_DEBUG_DRIVER("mediatek_ddp_ddp_path_setup\n");
  219. for (i = 0; i < mtk_crtc->ddp_comp_nr - 1; i++) {
  220. mtk_ddp_add_comp_to_path(mtk_crtc->config_regs,
  221. mtk_crtc->ddp_comp[i]->id,
  222. mtk_crtc->ddp_comp[i + 1]->id);
  223. mtk_disp_mutex_add_comp(mtk_crtc->mutex,
  224. mtk_crtc->ddp_comp[i]->id);
  225. }
  226. mtk_disp_mutex_add_comp(mtk_crtc->mutex, mtk_crtc->ddp_comp[i]->id);
  227. mtk_disp_mutex_enable(mtk_crtc->mutex);
  228. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
  229. struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[i];
  230. mtk_ddp_comp_config(comp, width, height, vrefresh, bpc);
  231. mtk_ddp_comp_start(comp);
  232. }
  233. /* Initially configure all planes */
  234. for (i = 0; i < OVL_LAYER_NR; i++) {
  235. struct drm_plane *plane = &mtk_crtc->planes[i];
  236. struct mtk_plane_state *plane_state;
  237. plane_state = to_mtk_plane_state(plane->state);
  238. mtk_ddp_comp_layer_config(mtk_crtc->ddp_comp[0], i,
  239. plane_state);
  240. }
  241. return 0;
  242. err_mutex_unprepare:
  243. mtk_disp_mutex_unprepare(mtk_crtc->mutex);
  244. err_pm_runtime_put:
  245. pm_runtime_put(crtc->dev->dev);
  246. return ret;
  247. }
  248. static void mtk_crtc_ddp_hw_fini(struct mtk_drm_crtc *mtk_crtc)
  249. {
  250. struct drm_device *drm = mtk_crtc->base.dev;
  251. int i;
  252. DRM_DEBUG_DRIVER("%s\n", __func__);
  253. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  254. mtk_ddp_comp_stop(mtk_crtc->ddp_comp[i]);
  255. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  256. mtk_disp_mutex_remove_comp(mtk_crtc->mutex,
  257. mtk_crtc->ddp_comp[i]->id);
  258. mtk_disp_mutex_disable(mtk_crtc->mutex);
  259. for (i = 0; i < mtk_crtc->ddp_comp_nr - 1; i++) {
  260. mtk_ddp_remove_comp_from_path(mtk_crtc->config_regs,
  261. mtk_crtc->ddp_comp[i]->id,
  262. mtk_crtc->ddp_comp[i + 1]->id);
  263. mtk_disp_mutex_remove_comp(mtk_crtc->mutex,
  264. mtk_crtc->ddp_comp[i]->id);
  265. }
  266. mtk_disp_mutex_remove_comp(mtk_crtc->mutex, mtk_crtc->ddp_comp[i]->id);
  267. mtk_crtc_ddp_clk_disable(mtk_crtc);
  268. mtk_disp_mutex_unprepare(mtk_crtc->mutex);
  269. pm_runtime_put(drm->dev);
  270. }
  271. static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
  272. {
  273. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  274. struct mtk_crtc_state *state = to_mtk_crtc_state(mtk_crtc->base.state);
  275. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  276. unsigned int i;
  277. /*
  278. * TODO: instead of updating the registers here, we should prepare
  279. * working registers in atomic_commit and let the hardware command
  280. * queue update module registers on vblank.
  281. */
  282. if (state->pending_config) {
  283. mtk_ddp_comp_config(ovl, state->pending_width,
  284. state->pending_height,
  285. state->pending_vrefresh, 0);
  286. state->pending_config = false;
  287. }
  288. if (mtk_crtc->pending_planes) {
  289. for (i = 0; i < OVL_LAYER_NR; i++) {
  290. struct drm_plane *plane = &mtk_crtc->planes[i];
  291. struct mtk_plane_state *plane_state;
  292. plane_state = to_mtk_plane_state(plane->state);
  293. if (plane_state->pending.config) {
  294. mtk_ddp_comp_layer_config(ovl, i, plane_state);
  295. plane_state->pending.config = false;
  296. }
  297. }
  298. mtk_crtc->pending_planes = false;
  299. }
  300. }
  301. static void mtk_drm_crtc_enable(struct drm_crtc *crtc)
  302. {
  303. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  304. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  305. int ret;
  306. DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
  307. ret = mtk_smi_larb_get(ovl->larb_dev);
  308. if (ret) {
  309. DRM_ERROR("Failed to get larb: %d\n", ret);
  310. return;
  311. }
  312. ret = mtk_crtc_ddp_hw_init(mtk_crtc);
  313. if (ret) {
  314. mtk_smi_larb_put(ovl->larb_dev);
  315. return;
  316. }
  317. drm_crtc_vblank_on(crtc);
  318. mtk_crtc->enabled = true;
  319. }
  320. static void mtk_drm_crtc_disable(struct drm_crtc *crtc)
  321. {
  322. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  323. struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0];
  324. int i;
  325. DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
  326. if (!mtk_crtc->enabled)
  327. return;
  328. /* Set all pending plane state to disabled */
  329. for (i = 0; i < OVL_LAYER_NR; i++) {
  330. struct drm_plane *plane = &mtk_crtc->planes[i];
  331. struct mtk_plane_state *plane_state;
  332. plane_state = to_mtk_plane_state(plane->state);
  333. plane_state->pending.enable = false;
  334. plane_state->pending.config = true;
  335. }
  336. mtk_crtc->pending_planes = true;
  337. /* Wait for planes to be disabled */
  338. drm_crtc_wait_one_vblank(crtc);
  339. drm_crtc_vblank_off(crtc);
  340. mtk_crtc_ddp_hw_fini(mtk_crtc);
  341. mtk_smi_larb_put(ovl->larb_dev);
  342. mtk_crtc->enabled = false;
  343. }
  344. static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc,
  345. struct drm_crtc_state *old_crtc_state)
  346. {
  347. struct mtk_crtc_state *state = to_mtk_crtc_state(crtc->state);
  348. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  349. if (mtk_crtc->event && state->base.event)
  350. DRM_ERROR("new event while there is still a pending event\n");
  351. if (state->base.event) {
  352. state->base.event->pipe = drm_crtc_index(crtc);
  353. WARN_ON(drm_crtc_vblank_get(crtc) != 0);
  354. mtk_crtc->event = state->base.event;
  355. state->base.event = NULL;
  356. }
  357. }
  358. static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc,
  359. struct drm_crtc_state *old_crtc_state)
  360. {
  361. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  362. struct mtk_drm_private *priv = crtc->dev->dev_private;
  363. unsigned int pending_planes = 0;
  364. int i;
  365. if (mtk_crtc->event)
  366. mtk_crtc->pending_needs_vblank = true;
  367. for (i = 0; i < OVL_LAYER_NR; i++) {
  368. struct drm_plane *plane = &mtk_crtc->planes[i];
  369. struct mtk_plane_state *plane_state;
  370. plane_state = to_mtk_plane_state(plane->state);
  371. if (plane_state->pending.dirty) {
  372. plane_state->pending.config = true;
  373. plane_state->pending.dirty = false;
  374. pending_planes |= BIT(i);
  375. }
  376. }
  377. if (pending_planes)
  378. mtk_crtc->pending_planes = true;
  379. if (crtc->state->color_mgmt_changed)
  380. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
  381. mtk_ddp_gamma_set(mtk_crtc->ddp_comp[i], crtc->state);
  382. if (priv->data->shadow_register) {
  383. mtk_disp_mutex_acquire(mtk_crtc->mutex);
  384. mtk_crtc_ddp_config(crtc);
  385. mtk_disp_mutex_release(mtk_crtc->mutex);
  386. }
  387. }
  388. static const struct drm_crtc_funcs mtk_crtc_funcs = {
  389. .set_config = drm_atomic_helper_set_config,
  390. .page_flip = drm_atomic_helper_page_flip,
  391. .destroy = mtk_drm_crtc_destroy,
  392. .reset = mtk_drm_crtc_reset,
  393. .atomic_duplicate_state = mtk_drm_crtc_duplicate_state,
  394. .atomic_destroy_state = mtk_drm_crtc_destroy_state,
  395. .gamma_set = drm_atomic_helper_legacy_gamma_set,
  396. .enable_vblank = mtk_drm_crtc_enable_vblank,
  397. .disable_vblank = mtk_drm_crtc_disable_vblank,
  398. };
  399. static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs = {
  400. .mode_fixup = mtk_drm_crtc_mode_fixup,
  401. .mode_set_nofb = mtk_drm_crtc_mode_set_nofb,
  402. .enable = mtk_drm_crtc_enable,
  403. .disable = mtk_drm_crtc_disable,
  404. .atomic_begin = mtk_drm_crtc_atomic_begin,
  405. .atomic_flush = mtk_drm_crtc_atomic_flush,
  406. };
  407. static int mtk_drm_crtc_init(struct drm_device *drm,
  408. struct mtk_drm_crtc *mtk_crtc,
  409. struct drm_plane *primary,
  410. struct drm_plane *cursor, unsigned int pipe)
  411. {
  412. int ret;
  413. ret = drm_crtc_init_with_planes(drm, &mtk_crtc->base, primary, cursor,
  414. &mtk_crtc_funcs, NULL);
  415. if (ret)
  416. goto err_cleanup_crtc;
  417. drm_crtc_helper_add(&mtk_crtc->base, &mtk_crtc_helper_funcs);
  418. return 0;
  419. err_cleanup_crtc:
  420. drm_crtc_cleanup(&mtk_crtc->base);
  421. return ret;
  422. }
  423. void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *ovl)
  424. {
  425. struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
  426. struct mtk_drm_private *priv = crtc->dev->dev_private;
  427. if (!priv->data->shadow_register)
  428. mtk_crtc_ddp_config(crtc);
  429. mtk_drm_finish_page_flip(mtk_crtc);
  430. }
  431. int mtk_drm_crtc_create(struct drm_device *drm_dev,
  432. const enum mtk_ddp_comp_id *path, unsigned int path_len)
  433. {
  434. struct mtk_drm_private *priv = drm_dev->dev_private;
  435. struct device *dev = drm_dev->dev;
  436. struct mtk_drm_crtc *mtk_crtc;
  437. enum drm_plane_type type;
  438. unsigned int zpos;
  439. int pipe = priv->num_pipes;
  440. int ret;
  441. int i;
  442. for (i = 0; i < path_len; i++) {
  443. enum mtk_ddp_comp_id comp_id = path[i];
  444. struct device_node *node;
  445. node = priv->comp_node[comp_id];
  446. if (!node) {
  447. dev_info(dev,
  448. "Not creating crtc %d because component %d is disabled or missing\n",
  449. pipe, comp_id);
  450. return 0;
  451. }
  452. }
  453. mtk_crtc = devm_kzalloc(dev, sizeof(*mtk_crtc), GFP_KERNEL);
  454. if (!mtk_crtc)
  455. return -ENOMEM;
  456. mtk_crtc->config_regs = priv->config_regs;
  457. mtk_crtc->ddp_comp_nr = path_len;
  458. mtk_crtc->ddp_comp = devm_kmalloc_array(dev, mtk_crtc->ddp_comp_nr,
  459. sizeof(*mtk_crtc->ddp_comp),
  460. GFP_KERNEL);
  461. mtk_crtc->mutex = mtk_disp_mutex_get(priv->mutex_dev, pipe);
  462. if (IS_ERR(mtk_crtc->mutex)) {
  463. ret = PTR_ERR(mtk_crtc->mutex);
  464. dev_err(dev, "Failed to get mutex: %d\n", ret);
  465. return ret;
  466. }
  467. for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
  468. enum mtk_ddp_comp_id comp_id = path[i];
  469. struct mtk_ddp_comp *comp;
  470. struct device_node *node;
  471. node = priv->comp_node[comp_id];
  472. comp = priv->ddp_comp[comp_id];
  473. if (!comp) {
  474. dev_err(dev, "Component %s not initialized\n",
  475. node->full_name);
  476. ret = -ENODEV;
  477. goto unprepare;
  478. }
  479. ret = clk_prepare(comp->clk);
  480. if (ret) {
  481. dev_err(dev,
  482. "Failed to prepare clock for component %s: %d\n",
  483. node->full_name, ret);
  484. goto unprepare;
  485. }
  486. mtk_crtc->ddp_comp[i] = comp;
  487. }
  488. for (zpos = 0; zpos < OVL_LAYER_NR; zpos++) {
  489. type = (zpos == 0) ? DRM_PLANE_TYPE_PRIMARY :
  490. (zpos == 1) ? DRM_PLANE_TYPE_CURSOR :
  491. DRM_PLANE_TYPE_OVERLAY;
  492. ret = mtk_plane_init(drm_dev, &mtk_crtc->planes[zpos],
  493. BIT(pipe), type);
  494. if (ret)
  495. goto unprepare;
  496. }
  497. ret = mtk_drm_crtc_init(drm_dev, mtk_crtc, &mtk_crtc->planes[0],
  498. &mtk_crtc->planes[1], pipe);
  499. if (ret < 0)
  500. goto unprepare;
  501. drm_mode_crtc_set_gamma_size(&mtk_crtc->base, MTK_LUT_SIZE);
  502. drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, false, MTK_LUT_SIZE);
  503. priv->num_pipes++;
  504. return 0;
  505. unprepare:
  506. while (--i >= 0)
  507. clk_unprepare(mtk_crtc->ddp_comp[i]->clk);
  508. return ret;
  509. }