omap_crtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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 "omap_drv.h"
  21. #include <drm/drm_mode.h>
  22. #include <drm/drm_plane_helper.h>
  23. #include "drm_crtc.h"
  24. #include "drm_crtc_helper.h"
  25. #define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
  26. struct omap_crtc {
  27. struct drm_crtc base;
  28. const char *name;
  29. int pipe;
  30. enum omap_channel channel;
  31. struct omap_overlay_manager_info info;
  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. /* list of framebuffers to unpin */
  45. struct list_head pending_unpins;
  46. /*
  47. * The flip_pending flag indicates if a page flip has been queued and
  48. * hasn't completed yet. The flip event, if any, is stored in
  49. * flip_event.
  50. *
  51. * The flip_work work queue handles page flip requests without caring
  52. * about what context the GEM async callback is called from. Possibly we
  53. * should just make omap_gem always call the cb from the worker so we
  54. * don't have to care about this.
  55. */
  56. bool flip_pending;
  57. struct drm_pending_vblank_event *flip_event;
  58. struct work_struct flip_work;
  59. struct completion completion;
  60. bool ignore_digit_sync_lost;
  61. };
  62. struct omap_framebuffer_unpin {
  63. struct list_head list;
  64. struct drm_framebuffer *fb;
  65. };
  66. /* -----------------------------------------------------------------------------
  67. * Helper Functions
  68. */
  69. uint32_t pipe2vbl(struct drm_crtc *crtc)
  70. {
  71. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  72. return dispc_mgr_get_vsync_irq(omap_crtc->channel);
  73. }
  74. const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc)
  75. {
  76. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  77. return &omap_crtc->timings;
  78. }
  79. enum omap_channel omap_crtc_channel(struct drm_crtc *crtc)
  80. {
  81. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  82. return omap_crtc->channel;
  83. }
  84. /* -----------------------------------------------------------------------------
  85. * DSS Manager Functions
  86. */
  87. /*
  88. * Manager-ops, callbacks from output when they need to configure
  89. * the upstream part of the video pipe.
  90. *
  91. * Most of these we can ignore until we add support for command-mode
  92. * panels.. for video-mode the crtc-helpers already do an adequate
  93. * job of sequencing the setup of the video pipe in the proper order
  94. */
  95. /* ovl-mgr-id -> crtc */
  96. static struct omap_crtc *omap_crtcs[8];
  97. /* we can probably ignore these until we support command-mode panels: */
  98. static int omap_crtc_connect(struct omap_overlay_manager *mgr,
  99. struct omap_dss_device *dst)
  100. {
  101. if (mgr->output)
  102. return -EINVAL;
  103. if ((mgr->supported_outputs & dst->id) == 0)
  104. return -EINVAL;
  105. dst->manager = mgr;
  106. mgr->output = dst;
  107. return 0;
  108. }
  109. static void omap_crtc_disconnect(struct omap_overlay_manager *mgr,
  110. struct omap_dss_device *dst)
  111. {
  112. mgr->output->manager = NULL;
  113. mgr->output = NULL;
  114. }
  115. static void omap_crtc_start_update(struct omap_overlay_manager *mgr)
  116. {
  117. }
  118. /* Called only from omap_crtc_setup and suspend/resume handlers. */
  119. static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
  120. {
  121. struct drm_device *dev = crtc->dev;
  122. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  123. enum omap_channel channel = omap_crtc->channel;
  124. struct omap_irq_wait *wait;
  125. u32 framedone_irq, vsync_irq;
  126. int ret;
  127. if (dispc_mgr_is_enabled(channel) == enable)
  128. return;
  129. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  130. /*
  131. * Digit output produces some sync lost interrupts during the
  132. * first frame when enabling, so we need to ignore those.
  133. */
  134. omap_crtc->ignore_digit_sync_lost = true;
  135. }
  136. framedone_irq = dispc_mgr_get_framedone_irq(channel);
  137. vsync_irq = dispc_mgr_get_vsync_irq(channel);
  138. if (enable) {
  139. wait = omap_irq_wait_init(dev, vsync_irq, 1);
  140. } else {
  141. /*
  142. * When we disable the digit output, we need to wait for
  143. * FRAMEDONE to know that DISPC has finished with the output.
  144. *
  145. * OMAP2/3 does not have FRAMEDONE irq for digit output, and in
  146. * that case we need to use vsync interrupt, and wait for both
  147. * even and odd frames.
  148. */
  149. if (framedone_irq)
  150. wait = omap_irq_wait_init(dev, framedone_irq, 1);
  151. else
  152. wait = omap_irq_wait_init(dev, vsync_irq, 2);
  153. }
  154. dispc_mgr_enable(channel, enable);
  155. ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100));
  156. if (ret) {
  157. dev_err(dev->dev, "%s: timeout waiting for %s\n",
  158. omap_crtc->name, enable ? "enable" : "disable");
  159. }
  160. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  161. omap_crtc->ignore_digit_sync_lost = false;
  162. /* make sure the irq handler sees the value above */
  163. mb();
  164. }
  165. }
  166. static int omap_crtc_enable(struct omap_overlay_manager *mgr)
  167. {
  168. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  169. dispc_mgr_setup(omap_crtc->channel, &omap_crtc->info);
  170. dispc_mgr_set_timings(omap_crtc->channel,
  171. &omap_crtc->timings);
  172. omap_crtc_set_enabled(&omap_crtc->base, true);
  173. return 0;
  174. }
  175. static void omap_crtc_disable(struct omap_overlay_manager *mgr)
  176. {
  177. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  178. omap_crtc_set_enabled(&omap_crtc->base, false);
  179. }
  180. static void omap_crtc_set_timings(struct omap_overlay_manager *mgr,
  181. const struct omap_video_timings *timings)
  182. {
  183. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  184. DBG("%s", omap_crtc->name);
  185. omap_crtc->timings = *timings;
  186. }
  187. static void omap_crtc_set_lcd_config(struct omap_overlay_manager *mgr,
  188. const struct dss_lcd_mgr_config *config)
  189. {
  190. struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
  191. DBG("%s", omap_crtc->name);
  192. dispc_mgr_set_lcd_config(omap_crtc->channel, config);
  193. }
  194. static int omap_crtc_register_framedone_handler(
  195. struct omap_overlay_manager *mgr,
  196. void (*handler)(void *), void *data)
  197. {
  198. return 0;
  199. }
  200. static void omap_crtc_unregister_framedone_handler(
  201. struct omap_overlay_manager *mgr,
  202. void (*handler)(void *), void *data)
  203. {
  204. }
  205. static const struct dss_mgr_ops mgr_ops = {
  206. .connect = omap_crtc_connect,
  207. .disconnect = omap_crtc_disconnect,
  208. .start_update = omap_crtc_start_update,
  209. .enable = omap_crtc_enable,
  210. .disable = omap_crtc_disable,
  211. .set_timings = omap_crtc_set_timings,
  212. .set_lcd_config = omap_crtc_set_lcd_config,
  213. .register_framedone_handler = omap_crtc_register_framedone_handler,
  214. .unregister_framedone_handler = omap_crtc_unregister_framedone_handler,
  215. };
  216. /* -----------------------------------------------------------------------------
  217. * Setup and Flush
  218. */
  219. static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  220. {
  221. struct omap_crtc *omap_crtc =
  222. container_of(irq, struct omap_crtc, error_irq);
  223. if (omap_crtc->ignore_digit_sync_lost) {
  224. irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  225. if (!irqstatus)
  226. return;
  227. }
  228. DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
  229. }
  230. static void omap_crtc_vblank_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  231. {
  232. struct omap_crtc *omap_crtc =
  233. container_of(irq, struct omap_crtc, vblank_irq);
  234. struct drm_device *dev = omap_crtc->base.dev;
  235. unsigned long flags;
  236. if (dispc_mgr_go_busy(omap_crtc->channel))
  237. return;
  238. DBG("%s: apply done", omap_crtc->name);
  239. __omap_irq_unregister(dev, &omap_crtc->vblank_irq);
  240. spin_lock_irqsave(&dev->event_lock, flags);
  241. /* wakeup userspace */
  242. if (omap_crtc->flip_event)
  243. drm_send_vblank_event(dev, omap_crtc->pipe,
  244. omap_crtc->flip_event);
  245. omap_crtc->flip_event = NULL;
  246. omap_crtc->flip_pending = false;
  247. spin_unlock_irqrestore(&dev->event_lock, flags);
  248. complete(&omap_crtc->completion);
  249. }
  250. int omap_crtc_flush(struct drm_crtc *crtc)
  251. {
  252. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  253. struct omap_framebuffer_unpin *fb, *next;
  254. DBG("%s: GO", omap_crtc->name);
  255. WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
  256. WARN_ON(omap_crtc->vblank_irq.registered);
  257. dispc_runtime_get();
  258. if (dispc_mgr_is_enabled(omap_crtc->channel)) {
  259. dispc_mgr_go(omap_crtc->channel);
  260. omap_irq_register(crtc->dev, &omap_crtc->vblank_irq);
  261. WARN_ON(!wait_for_completion_timeout(&omap_crtc->completion,
  262. msecs_to_jiffies(100)));
  263. reinit_completion(&omap_crtc->completion);
  264. }
  265. dispc_runtime_put();
  266. /* Unpin and unreference pending framebuffers. */
  267. list_for_each_entry_safe(fb, next, &omap_crtc->pending_unpins, list) {
  268. omap_framebuffer_unpin(fb->fb);
  269. drm_framebuffer_unreference(fb->fb);
  270. list_del(&fb->list);
  271. kfree(fb);
  272. }
  273. return 0;
  274. }
  275. int omap_crtc_queue_unpin(struct drm_crtc *crtc, struct drm_framebuffer *fb)
  276. {
  277. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  278. struct omap_framebuffer_unpin *unpin;
  279. unpin = kzalloc(sizeof(*unpin), GFP_KERNEL);
  280. if (!unpin)
  281. return -ENOMEM;
  282. unpin->fb = fb;
  283. list_add_tail(&unpin->list, &omap_crtc->pending_unpins);
  284. return 0;
  285. }
  286. static void omap_crtc_setup(struct drm_crtc *crtc)
  287. {
  288. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  289. struct omap_drm_private *priv = crtc->dev->dev_private;
  290. struct drm_encoder *encoder = NULL;
  291. unsigned int i;
  292. DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled);
  293. dispc_runtime_get();
  294. for (i = 0; i < priv->num_encoders; i++) {
  295. if (priv->encoders[i]->crtc == crtc) {
  296. encoder = priv->encoders[i];
  297. break;
  298. }
  299. }
  300. if (omap_crtc->current_encoder && encoder != omap_crtc->current_encoder)
  301. omap_encoder_set_enabled(omap_crtc->current_encoder, false);
  302. omap_crtc->current_encoder = encoder;
  303. if (!omap_crtc->enabled) {
  304. if (encoder)
  305. omap_encoder_set_enabled(encoder, false);
  306. } else {
  307. if (encoder) {
  308. omap_encoder_set_enabled(encoder, false);
  309. omap_encoder_update(encoder, omap_crtc->mgr,
  310. &omap_crtc->timings);
  311. omap_encoder_set_enabled(encoder, true);
  312. }
  313. }
  314. dispc_runtime_put();
  315. }
  316. /* -----------------------------------------------------------------------------
  317. * CRTC Functions
  318. */
  319. static void omap_crtc_destroy(struct drm_crtc *crtc)
  320. {
  321. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  322. DBG("%s", omap_crtc->name);
  323. WARN_ON(omap_crtc->vblank_irq.registered);
  324. omap_irq_unregister(crtc->dev, &omap_crtc->error_irq);
  325. drm_crtc_cleanup(crtc);
  326. kfree(omap_crtc);
  327. }
  328. static void omap_crtc_dpms(struct drm_crtc *crtc, int mode)
  329. {
  330. struct omap_drm_private *priv = crtc->dev->dev_private;
  331. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  332. bool enabled = (mode == DRM_MODE_DPMS_ON);
  333. int i;
  334. DBG("%s: %d", omap_crtc->name, mode);
  335. if (enabled == omap_crtc->enabled)
  336. return;
  337. /* Enable/disable all planes associated with the CRTC. */
  338. for (i = 0; i < priv->num_planes; i++) {
  339. struct drm_plane *plane = priv->planes[i];
  340. if (plane->crtc == crtc)
  341. WARN_ON(omap_plane_set_enable(plane, enabled));
  342. }
  343. omap_crtc->enabled = enabled;
  344. omap_crtc_setup(crtc);
  345. omap_crtc_flush(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 int omap_crtc_mode_set(struct drm_crtc *crtc,
  354. struct drm_display_mode *mode,
  355. struct drm_display_mode *adjusted_mode,
  356. int x, int y,
  357. struct drm_framebuffer *old_fb)
  358. {
  359. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  360. mode = adjusted_mode;
  361. DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  362. omap_crtc->name, mode->base.id, mode->name,
  363. mode->vrefresh, mode->clock,
  364. mode->hdisplay, mode->hsync_start,
  365. mode->hsync_end, mode->htotal,
  366. mode->vdisplay, mode->vsync_start,
  367. mode->vsync_end, mode->vtotal,
  368. mode->type, mode->flags);
  369. copy_timings_drm_to_omap(&omap_crtc->timings, mode);
  370. /*
  371. * The primary plane CRTC can be reset if the plane is disabled directly
  372. * through the universal plane API. Set it again here.
  373. */
  374. crtc->primary->crtc = crtc;
  375. return omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
  376. 0, 0, mode->hdisplay, mode->vdisplay,
  377. x, y, mode->hdisplay, mode->vdisplay);
  378. }
  379. static void omap_crtc_prepare(struct drm_crtc *crtc)
  380. {
  381. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  382. DBG("%s", omap_crtc->name);
  383. omap_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  384. }
  385. static void omap_crtc_commit(struct drm_crtc *crtc)
  386. {
  387. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  388. DBG("%s", omap_crtc->name);
  389. omap_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  390. }
  391. static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  392. struct drm_framebuffer *old_fb)
  393. {
  394. struct drm_plane *plane = crtc->primary;
  395. struct drm_display_mode *mode = &crtc->mode;
  396. int ret;
  397. ret = omap_plane_mode_set(plane, crtc, crtc->primary->fb,
  398. 0, 0, mode->hdisplay, mode->vdisplay,
  399. x, y, mode->hdisplay, mode->vdisplay);
  400. if (ret < 0)
  401. return ret;
  402. return omap_crtc_flush(crtc);
  403. }
  404. static void page_flip_worker(struct work_struct *work)
  405. {
  406. struct omap_crtc *omap_crtc =
  407. container_of(work, struct omap_crtc, flip_work);
  408. struct drm_crtc *crtc = &omap_crtc->base;
  409. struct drm_display_mode *mode = &crtc->mode;
  410. struct drm_gem_object *bo;
  411. drm_modeset_lock(&crtc->mutex, NULL);
  412. omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
  413. 0, 0, mode->hdisplay, mode->vdisplay,
  414. crtc->x, crtc->y, mode->hdisplay, mode->vdisplay);
  415. omap_crtc_flush(crtc);
  416. drm_modeset_unlock(&crtc->mutex);
  417. bo = omap_framebuffer_bo(crtc->primary->fb, 0);
  418. drm_gem_object_unreference_unlocked(bo);
  419. drm_framebuffer_unreference(crtc->primary->fb);
  420. }
  421. static void page_flip_cb(void *arg)
  422. {
  423. struct drm_crtc *crtc = arg;
  424. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  425. struct omap_drm_private *priv = crtc->dev->dev_private;
  426. /* avoid assumptions about what ctxt we are called from: */
  427. queue_work(priv->wq, &omap_crtc->flip_work);
  428. }
  429. static int omap_crtc_page_flip(struct drm_crtc *crtc,
  430. struct drm_framebuffer *fb,
  431. struct drm_pending_vblank_event *event,
  432. uint32_t page_flip_flags)
  433. {
  434. struct drm_device *dev = crtc->dev;
  435. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  436. struct drm_plane *primary = crtc->primary;
  437. struct drm_gem_object *bo;
  438. unsigned long flags;
  439. DBG("%d -> %d (event=%p)", primary->fb ? primary->fb->base.id : -1,
  440. fb->base.id, event);
  441. spin_lock_irqsave(&dev->event_lock, flags);
  442. if (omap_crtc->flip_pending) {
  443. spin_unlock_irqrestore(&dev->event_lock, flags);
  444. dev_err(dev->dev, "already a pending flip\n");
  445. return -EBUSY;
  446. }
  447. omap_crtc->flip_event = event;
  448. omap_crtc->flip_pending = true;
  449. primary->fb = fb;
  450. drm_framebuffer_reference(fb);
  451. spin_unlock_irqrestore(&dev->event_lock, flags);
  452. /*
  453. * Hold a reference temporarily until the crtc is updated
  454. * and takes the reference to the bo. This avoids it
  455. * getting freed from under us:
  456. */
  457. bo = omap_framebuffer_bo(fb, 0);
  458. drm_gem_object_reference(bo);
  459. omap_gem_op_async(bo, OMAP_GEM_READ, page_flip_cb, crtc);
  460. return 0;
  461. }
  462. static int omap_crtc_set_property(struct drm_crtc *crtc,
  463. struct drm_property *property, uint64_t val)
  464. {
  465. if (property == crtc->dev->mode_config.rotation_property) {
  466. crtc->invert_dimensions =
  467. !!(val & ((1LL << DRM_ROTATE_90) | (1LL << DRM_ROTATE_270)));
  468. }
  469. return omap_plane_set_property(crtc->primary, property, val);
  470. }
  471. static const struct drm_crtc_funcs omap_crtc_funcs = {
  472. .set_config = drm_crtc_helper_set_config,
  473. .destroy = omap_crtc_destroy,
  474. .page_flip = omap_crtc_page_flip,
  475. .set_property = omap_crtc_set_property,
  476. };
  477. static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
  478. .dpms = omap_crtc_dpms,
  479. .mode_fixup = omap_crtc_mode_fixup,
  480. .mode_set = omap_crtc_mode_set,
  481. .prepare = omap_crtc_prepare,
  482. .commit = omap_crtc_commit,
  483. .mode_set_base = omap_crtc_mode_set_base,
  484. };
  485. /* -----------------------------------------------------------------------------
  486. * Init and Cleanup
  487. */
  488. static const char *channel_names[] = {
  489. [OMAP_DSS_CHANNEL_LCD] = "lcd",
  490. [OMAP_DSS_CHANNEL_DIGIT] = "tv",
  491. [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
  492. [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
  493. };
  494. void omap_crtc_pre_init(void)
  495. {
  496. dss_install_mgr_ops(&mgr_ops);
  497. }
  498. void omap_crtc_pre_uninit(void)
  499. {
  500. dss_uninstall_mgr_ops();
  501. }
  502. /* initialize crtc */
  503. struct drm_crtc *omap_crtc_init(struct drm_device *dev,
  504. struct drm_plane *plane, enum omap_channel channel, int id)
  505. {
  506. struct drm_crtc *crtc = NULL;
  507. struct omap_crtc *omap_crtc;
  508. struct omap_overlay_manager_info *info;
  509. int ret;
  510. DBG("%s", channel_names[channel]);
  511. omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
  512. if (!omap_crtc)
  513. return NULL;
  514. crtc = &omap_crtc->base;
  515. INIT_WORK(&omap_crtc->flip_work, page_flip_worker);
  516. INIT_LIST_HEAD(&omap_crtc->pending_unpins);
  517. init_completion(&omap_crtc->completion);
  518. omap_crtc->channel = channel;
  519. omap_crtc->name = channel_names[channel];
  520. omap_crtc->pipe = id;
  521. omap_crtc->vblank_irq.irqmask = pipe2vbl(crtc);
  522. omap_crtc->vblank_irq.irq = omap_crtc_vblank_irq;
  523. omap_crtc->error_irq.irqmask =
  524. dispc_mgr_get_sync_lost_irq(channel);
  525. omap_crtc->error_irq.irq = omap_crtc_error_irq;
  526. omap_irq_register(dev, &omap_crtc->error_irq);
  527. /* temporary: */
  528. omap_crtc->mgr = omap_dss_get_overlay_manager(channel);
  529. /* TODO: fix hard-coded setup.. add properties! */
  530. info = &omap_crtc->info;
  531. info->default_color = 0x00000000;
  532. info->trans_key = 0x00000000;
  533. info->trans_key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
  534. info->trans_enabled = false;
  535. ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
  536. &omap_crtc_funcs);
  537. if (ret < 0) {
  538. kfree(omap_crtc);
  539. return NULL;
  540. }
  541. drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
  542. omap_plane_install_properties(crtc->primary, &crtc->base);
  543. omap_crtcs[channel] = omap_crtc;
  544. return crtc;
  545. }