omap_crtc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * drivers/gpu/drm/omapdrm/omap_crtc.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Rob Clark <rob@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/completion.h>
  20. #include <drm/drm_atomic.h>
  21. #include <drm/drm_atomic_helper.h>
  22. #include <drm/drm_crtc.h>
  23. #include <drm/drm_crtc_helper.h>
  24. #include <drm/drm_mode.h>
  25. #include <drm/drm_plane_helper.h>
  26. #include "omap_drv.h"
  27. #define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
  28. struct omap_crtc {
  29. struct drm_crtc base;
  30. const char *name;
  31. enum omap_channel channel;
  32. struct drm_encoder *current_encoder;
  33. /*
  34. * Temporary: eventually this will go away, but it is needed
  35. * for now to keep the output's happy. (They only need
  36. * mgr->id.) Eventually this will be replaced w/ something
  37. * more common-panel-framework-y
  38. */
  39. struct omap_overlay_manager *mgr;
  40. struct omap_video_timings timings;
  41. bool enabled;
  42. struct omap_drm_irq vblank_irq;
  43. struct omap_drm_irq error_irq;
  44. /* pending event */
  45. struct drm_pending_vblank_event *event;
  46. wait_queue_head_t flip_wait;
  47. struct completion completion;
  48. bool ignore_digit_sync_lost;
  49. };
  50. /* -----------------------------------------------------------------------------
  51. * Helper Functions
  52. */
  53. uint32_t pipe2vbl(struct drm_crtc *crtc)
  54. {
  55. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  56. return dispc_mgr_get_vsync_irq(omap_crtc->channel);
  57. }
  58. const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc)
  59. {
  60. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  61. return &omap_crtc->timings;
  62. }
  63. enum omap_channel omap_crtc_channel(struct drm_crtc *crtc)
  64. {
  65. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  66. return omap_crtc->channel;
  67. }
  68. /* -----------------------------------------------------------------------------
  69. * DSS Manager Functions
  70. */
  71. /*
  72. * Manager-ops, callbacks from output when they need to configure
  73. * the upstream part of the video pipe.
  74. *
  75. * Most of these we can ignore until we add support for command-mode
  76. * panels.. for video-mode the crtc-helpers already do an adequate
  77. * job of sequencing the setup of the video pipe in the proper order
  78. */
  79. /* ovl-mgr-id -> crtc */
  80. static struct omap_crtc *omap_crtcs[8];
  81. /* we can probably ignore these until we support command-mode panels: */
  82. static int omap_crtc_dss_connect(struct omap_overlay_manager *mgr,
  83. struct omap_dss_device *dst)
  84. {
  85. if (mgr->output)
  86. return -EINVAL;
  87. if ((mgr->supported_outputs & dst->id) == 0)
  88. return -EINVAL;
  89. dst->manager = mgr;
  90. mgr->output = dst;
  91. return 0;
  92. }
  93. static void omap_crtc_dss_disconnect(struct omap_overlay_manager *mgr,
  94. struct omap_dss_device *dst)
  95. {
  96. mgr->output->manager = NULL;
  97. mgr->output = NULL;
  98. }
  99. static void omap_crtc_dss_start_update(struct omap_overlay_manager *mgr)
  100. {
  101. }
  102. /* Called only from omap_crtc_setup and suspend/resume handlers. */
  103. static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
  104. {
  105. struct drm_device *dev = crtc->dev;
  106. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  107. enum omap_channel channel = omap_crtc->channel;
  108. struct omap_irq_wait *wait;
  109. u32 framedone_irq, vsync_irq;
  110. int ret;
  111. if (dispc_mgr_is_enabled(channel) == enable)
  112. return;
  113. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  114. /*
  115. * Digit output produces some sync lost interrupts during the
  116. * first frame when enabling, so we need to ignore those.
  117. */
  118. omap_crtc->ignore_digit_sync_lost = true;
  119. }
  120. framedone_irq = dispc_mgr_get_framedone_irq(channel);
  121. vsync_irq = dispc_mgr_get_vsync_irq(channel);
  122. if (enable) {
  123. wait = omap_irq_wait_init(dev, vsync_irq, 1);
  124. } else {
  125. /*
  126. * When we disable the digit output, we need to wait for
  127. * FRAMEDONE to know that DISPC has finished with the output.
  128. *
  129. * OMAP2/3 does not have FRAMEDONE irq for digit output, and in
  130. * that case we need to use vsync interrupt, and wait for both
  131. * even and odd frames.
  132. */
  133. if (framedone_irq)
  134. wait = omap_irq_wait_init(dev, framedone_irq, 1);
  135. else
  136. wait = omap_irq_wait_init(dev, vsync_irq, 2);
  137. }
  138. dispc_mgr_enable(channel, enable);
  139. ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100));
  140. if (ret) {
  141. dev_err(dev->dev, "%s: timeout waiting for %s\n",
  142. omap_crtc->name, enable ? "enable" : "disable");
  143. }
  144. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  145. omap_crtc->ignore_digit_sync_lost = false;
  146. /* make sure the irq handler sees the value above */
  147. mb();
  148. }
  149. }
  150. static int omap_crtc_dss_enable(struct omap_overlay_manager *mgr)
  151. {
  152. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  153. struct omap_overlay_manager_info info;
  154. memset(&info, 0, sizeof(info));
  155. info.default_color = 0x00000000;
  156. info.trans_key = 0x00000000;
  157. info.trans_key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
  158. info.trans_enabled = false;
  159. dispc_mgr_setup(omap_crtc->channel, &info);
  160. dispc_mgr_set_timings(omap_crtc->channel,
  161. &omap_crtc->timings);
  162. omap_crtc_set_enabled(&omap_crtc->base, true);
  163. return 0;
  164. }
  165. static void omap_crtc_dss_disable(struct omap_overlay_manager *mgr)
  166. {
  167. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  168. omap_crtc_set_enabled(&omap_crtc->base, false);
  169. }
  170. static void omap_crtc_dss_set_timings(struct omap_overlay_manager *mgr,
  171. const struct omap_video_timings *timings)
  172. {
  173. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  174. DBG("%s", omap_crtc->name);
  175. omap_crtc->timings = *timings;
  176. }
  177. static void omap_crtc_dss_set_lcd_config(struct omap_overlay_manager *mgr,
  178. const struct dss_lcd_mgr_config *config)
  179. {
  180. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  181. DBG("%s", omap_crtc->name);
  182. dispc_mgr_set_lcd_config(omap_crtc->channel, config);
  183. }
  184. static int omap_crtc_dss_register_framedone(
  185. struct omap_overlay_manager *mgr,
  186. void (*handler)(void *), void *data)
  187. {
  188. return 0;
  189. }
  190. static void omap_crtc_dss_unregister_framedone(
  191. struct omap_overlay_manager *mgr,
  192. void (*handler)(void *), void *data)
  193. {
  194. }
  195. static const struct dss_mgr_ops mgr_ops = {
  196. .connect = omap_crtc_dss_connect,
  197. .disconnect = omap_crtc_dss_disconnect,
  198. .start_update = omap_crtc_dss_start_update,
  199. .enable = omap_crtc_dss_enable,
  200. .disable = omap_crtc_dss_disable,
  201. .set_timings = omap_crtc_dss_set_timings,
  202. .set_lcd_config = omap_crtc_dss_set_lcd_config,
  203. .register_framedone_handler = omap_crtc_dss_register_framedone,
  204. .unregister_framedone_handler = omap_crtc_dss_unregister_framedone,
  205. };
  206. /* -----------------------------------------------------------------------------
  207. * Setup, Flush and Page Flip
  208. */
  209. void omap_crtc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file)
  210. {
  211. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  212. struct drm_pending_vblank_event *event;
  213. struct drm_device *dev = crtc->dev;
  214. unsigned long flags;
  215. /* Destroy the pending vertical blanking event associated with the
  216. * pending page flip, if any, and disable vertical blanking interrupts.
  217. */
  218. spin_lock_irqsave(&dev->event_lock, flags);
  219. event = omap_crtc->event;
  220. omap_crtc->event = NULL;
  221. if (event && event->base.file_priv == file) {
  222. event->base.destroy(&event->base);
  223. drm_crtc_vblank_put(crtc);
  224. }
  225. spin_unlock_irqrestore(&dev->event_lock, flags);
  226. }
  227. static void omap_crtc_complete_page_flip(struct drm_crtc *crtc)
  228. {
  229. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  230. struct drm_pending_vblank_event *event;
  231. struct drm_device *dev = crtc->dev;
  232. unsigned long flags;
  233. spin_lock_irqsave(&dev->event_lock, flags);
  234. event = omap_crtc->event;
  235. omap_crtc->event = NULL;
  236. if (event) {
  237. drm_crtc_send_vblank_event(crtc, event);
  238. wake_up(&omap_crtc->flip_wait);
  239. drm_crtc_vblank_put(crtc);
  240. }
  241. spin_unlock_irqrestore(&dev->event_lock, flags);
  242. }
  243. static bool omap_crtc_page_flip_pending(struct drm_crtc *crtc)
  244. {
  245. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  246. struct drm_device *dev = crtc->dev;
  247. unsigned long flags;
  248. bool pending;
  249. spin_lock_irqsave(&dev->event_lock, flags);
  250. pending = omap_crtc->event != NULL;
  251. spin_unlock_irqrestore(&dev->event_lock, flags);
  252. return pending;
  253. }
  254. static void omap_crtc_wait_page_flip(struct drm_crtc *crtc)
  255. {
  256. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  257. if (wait_event_timeout(omap_crtc->flip_wait,
  258. !omap_crtc_page_flip_pending(crtc),
  259. msecs_to_jiffies(50)))
  260. return;
  261. dev_warn(crtc->dev->dev, "page flip timeout!\n");
  262. omap_crtc_complete_page_flip(crtc);
  263. }
  264. static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  265. {
  266. struct omap_crtc *omap_crtc =
  267. container_of(irq, struct omap_crtc, error_irq);
  268. if (omap_crtc->ignore_digit_sync_lost) {
  269. irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  270. if (!irqstatus)
  271. return;
  272. }
  273. DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
  274. }
  275. static void omap_crtc_vblank_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  276. {
  277. struct omap_crtc *omap_crtc =
  278. container_of(irq, struct omap_crtc, vblank_irq);
  279. struct drm_device *dev = omap_crtc->base.dev;
  280. if (dispc_mgr_go_busy(omap_crtc->channel))
  281. return;
  282. DBG("%s: apply done", omap_crtc->name);
  283. __omap_irq_unregister(dev, &omap_crtc->vblank_irq);
  284. /* wakeup userspace */
  285. omap_crtc_complete_page_flip(&omap_crtc->base);
  286. complete(&omap_crtc->completion);
  287. }
  288. int omap_crtc_flush(struct drm_crtc *crtc)
  289. {
  290. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  291. DBG("%s: GO", omap_crtc->name);
  292. WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
  293. WARN_ON(omap_crtc->vblank_irq.registered);
  294. dispc_runtime_get();
  295. if (dispc_mgr_is_enabled(omap_crtc->channel)) {
  296. dispc_mgr_go(omap_crtc->channel);
  297. omap_irq_register(crtc->dev, &omap_crtc->vblank_irq);
  298. WARN_ON(!wait_for_completion_timeout(&omap_crtc->completion,
  299. msecs_to_jiffies(100)));
  300. reinit_completion(&omap_crtc->completion);
  301. }
  302. dispc_runtime_put();
  303. return 0;
  304. }
  305. static void omap_crtc_setup(struct drm_crtc *crtc)
  306. {
  307. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  308. struct omap_drm_private *priv = crtc->dev->dev_private;
  309. struct drm_encoder *encoder = NULL;
  310. unsigned int i;
  311. DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled);
  312. dispc_runtime_get();
  313. for (i = 0; i < priv->num_encoders; i++) {
  314. if (priv->encoders[i]->crtc == crtc) {
  315. encoder = priv->encoders[i];
  316. break;
  317. }
  318. }
  319. if (omap_crtc->current_encoder && encoder != omap_crtc->current_encoder)
  320. omap_encoder_set_enabled(omap_crtc->current_encoder, false);
  321. omap_crtc->current_encoder = encoder;
  322. if (!omap_crtc->enabled) {
  323. if (encoder)
  324. omap_encoder_set_enabled(encoder, false);
  325. } else {
  326. if (encoder) {
  327. omap_encoder_set_enabled(encoder, false);
  328. omap_encoder_update(encoder, omap_crtc->mgr,
  329. &omap_crtc->timings);
  330. omap_encoder_set_enabled(encoder, true);
  331. }
  332. }
  333. dispc_runtime_put();
  334. }
  335. /* -----------------------------------------------------------------------------
  336. * CRTC Functions
  337. */
  338. static void omap_crtc_destroy(struct drm_crtc *crtc)
  339. {
  340. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  341. DBG("%s", omap_crtc->name);
  342. WARN_ON(omap_crtc->vblank_irq.registered);
  343. omap_irq_unregister(crtc->dev, &omap_crtc->error_irq);
  344. drm_crtc_cleanup(crtc);
  345. kfree(omap_crtc);
  346. }
  347. static bool omap_crtc_mode_fixup(struct drm_crtc *crtc,
  348. const struct drm_display_mode *mode,
  349. struct drm_display_mode *adjusted_mode)
  350. {
  351. return true;
  352. }
  353. static void omap_crtc_enable(struct drm_crtc *crtc)
  354. {
  355. struct omap_drm_private *priv = crtc->dev->dev_private;
  356. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  357. unsigned int i;
  358. DBG("%s", omap_crtc->name);
  359. if (omap_crtc->enabled)
  360. return;
  361. /* Enable all planes associated with the CRTC. */
  362. for (i = 0; i < priv->num_planes; i++) {
  363. struct drm_plane *plane = priv->planes[i];
  364. if (plane->crtc == crtc)
  365. WARN_ON(omap_plane_set_enable(plane, true));
  366. }
  367. omap_crtc->enabled = true;
  368. omap_crtc_setup(crtc);
  369. omap_crtc_flush(crtc);
  370. dispc_runtime_get();
  371. drm_crtc_vblank_on(crtc);
  372. dispc_runtime_put();
  373. }
  374. static void omap_crtc_disable(struct drm_crtc *crtc)
  375. {
  376. struct omap_drm_private *priv = crtc->dev->dev_private;
  377. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  378. unsigned int i;
  379. DBG("%s", omap_crtc->name);
  380. if (!omap_crtc->enabled)
  381. return;
  382. omap_crtc_wait_page_flip(crtc);
  383. dispc_runtime_get();
  384. drm_crtc_vblank_off(crtc);
  385. dispc_runtime_put();
  386. /* Disable all planes associated with the CRTC. */
  387. for (i = 0; i < priv->num_planes; i++) {
  388. struct drm_plane *plane = priv->planes[i];
  389. if (plane->crtc == crtc)
  390. WARN_ON(omap_plane_set_enable(plane, false));
  391. }
  392. omap_crtc->enabled = false;
  393. omap_crtc_setup(crtc);
  394. omap_crtc_flush(crtc);
  395. }
  396. static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
  397. {
  398. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  399. struct drm_display_mode *mode = &crtc->state->adjusted_mode;
  400. DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  401. omap_crtc->name, mode->base.id, mode->name,
  402. mode->vrefresh, mode->clock,
  403. mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
  404. mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal,
  405. mode->type, mode->flags);
  406. copy_timings_drm_to_omap(&omap_crtc->timings, mode);
  407. }
  408. static void omap_crtc_atomic_begin(struct drm_crtc *crtc)
  409. {
  410. struct drm_pending_vblank_event *event = crtc->state->event;
  411. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  412. struct drm_device *dev = crtc->dev;
  413. unsigned long flags;
  414. dispc_runtime_get();
  415. if (event) {
  416. WARN_ON(omap_crtc->event);
  417. WARN_ON(drm_crtc_vblank_get(crtc) != 0);
  418. spin_lock_irqsave(&dev->event_lock, flags);
  419. omap_crtc->event = event;
  420. spin_unlock_irqrestore(&dev->event_lock, flags);
  421. }
  422. }
  423. static void omap_crtc_atomic_flush(struct drm_crtc *crtc)
  424. {
  425. omap_crtc_flush(crtc);
  426. dispc_runtime_put();
  427. crtc->invert_dimensions = !!(crtc->primary->state->rotation &
  428. (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270)));
  429. }
  430. static int omap_crtc_atomic_set_property(struct drm_crtc *crtc,
  431. struct drm_crtc_state *state,
  432. struct drm_property *property,
  433. uint64_t val)
  434. {
  435. struct drm_plane_state *plane_state;
  436. struct drm_plane *plane = crtc->primary;
  437. /*
  438. * Delegate property set to the primary plane. Get the plane state and
  439. * set the property directly.
  440. */
  441. plane_state = drm_atomic_get_plane_state(state->state, plane);
  442. if (!plane_state)
  443. return -EINVAL;
  444. return drm_atomic_plane_set_property(plane, plane_state, property, val);
  445. }
  446. static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
  447. const struct drm_crtc_state *state,
  448. struct drm_property *property,
  449. uint64_t *val)
  450. {
  451. /*
  452. * Delegate property get to the primary plane. The
  453. * drm_atomic_plane_get_property() function isn't exported, but can be
  454. * called through drm_object_property_get_value() as that will call
  455. * drm_atomic_get_property() for atomic drivers.
  456. */
  457. return drm_object_property_get_value(&crtc->primary->base, property,
  458. val);
  459. }
  460. static const struct drm_crtc_funcs omap_crtc_funcs = {
  461. .reset = drm_atomic_helper_crtc_reset,
  462. .set_config = drm_atomic_helper_set_config,
  463. .destroy = omap_crtc_destroy,
  464. .page_flip = drm_atomic_helper_page_flip,
  465. .set_property = drm_atomic_helper_crtc_set_property,
  466. .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
  467. .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
  468. .atomic_set_property = omap_crtc_atomic_set_property,
  469. .atomic_get_property = omap_crtc_atomic_get_property,
  470. };
  471. static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
  472. .mode_fixup = omap_crtc_mode_fixup,
  473. .mode_set_nofb = omap_crtc_mode_set_nofb,
  474. .disable = omap_crtc_disable,
  475. .enable = omap_crtc_enable,
  476. .atomic_begin = omap_crtc_atomic_begin,
  477. .atomic_flush = omap_crtc_atomic_flush,
  478. };
  479. /* -----------------------------------------------------------------------------
  480. * Init and Cleanup
  481. */
  482. static const char *channel_names[] = {
  483. [OMAP_DSS_CHANNEL_LCD] = "lcd",
  484. [OMAP_DSS_CHANNEL_DIGIT] = "tv",
  485. [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
  486. [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
  487. };
  488. void omap_crtc_pre_init(void)
  489. {
  490. dss_install_mgr_ops(&mgr_ops);
  491. }
  492. void omap_crtc_pre_uninit(void)
  493. {
  494. dss_uninstall_mgr_ops();
  495. }
  496. /* initialize crtc */
  497. struct drm_crtc *omap_crtc_init(struct drm_device *dev,
  498. struct drm_plane *plane, enum omap_channel channel, int id)
  499. {
  500. struct drm_crtc *crtc = NULL;
  501. struct omap_crtc *omap_crtc;
  502. int ret;
  503. DBG("%s", channel_names[channel]);
  504. omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
  505. if (!omap_crtc)
  506. return NULL;
  507. crtc = &omap_crtc->base;
  508. init_waitqueue_head(&omap_crtc->flip_wait);
  509. init_completion(&omap_crtc->completion);
  510. omap_crtc->channel = channel;
  511. omap_crtc->name = channel_names[channel];
  512. omap_crtc->vblank_irq.irqmask = pipe2vbl(crtc);
  513. omap_crtc->vblank_irq.irq = omap_crtc_vblank_irq;
  514. omap_crtc->error_irq.irqmask =
  515. dispc_mgr_get_sync_lost_irq(channel);
  516. omap_crtc->error_irq.irq = omap_crtc_error_irq;
  517. omap_irq_register(dev, &omap_crtc->error_irq);
  518. /* temporary: */
  519. omap_crtc->mgr = omap_dss_get_overlay_manager(channel);
  520. ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
  521. &omap_crtc_funcs);
  522. if (ret < 0) {
  523. kfree(omap_crtc);
  524. return NULL;
  525. }
  526. drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
  527. omap_plane_install_properties(crtc->primary, &crtc->base);
  528. omap_crtcs[channel] = omap_crtc;
  529. return crtc;
  530. }