omap_crtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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, Flush and Page Flip
  218. */
  219. void omap_crtc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file)
  220. {
  221. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  222. struct drm_device *dev = crtc->dev;
  223. unsigned long flags;
  224. spin_lock_irqsave(&dev->event_lock, flags);
  225. /* Only complete events queued for our file handle. */
  226. if (omap_crtc->flip_event &&
  227. file == omap_crtc->flip_event->base.file_priv) {
  228. drm_send_vblank_event(dev, omap_crtc->pipe,
  229. omap_crtc->flip_event);
  230. omap_crtc->flip_event = NULL;
  231. }
  232. spin_unlock_irqrestore(&dev->event_lock, flags);
  233. }
  234. static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  235. {
  236. struct omap_crtc *omap_crtc =
  237. container_of(irq, struct omap_crtc, error_irq);
  238. if (omap_crtc->ignore_digit_sync_lost) {
  239. irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  240. if (!irqstatus)
  241. return;
  242. }
  243. DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
  244. }
  245. static void omap_crtc_vblank_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  246. {
  247. struct omap_crtc *omap_crtc =
  248. container_of(irq, struct omap_crtc, vblank_irq);
  249. struct drm_device *dev = omap_crtc->base.dev;
  250. unsigned long flags;
  251. if (dispc_mgr_go_busy(omap_crtc->channel))
  252. return;
  253. DBG("%s: apply done", omap_crtc->name);
  254. __omap_irq_unregister(dev, &omap_crtc->vblank_irq);
  255. spin_lock_irqsave(&dev->event_lock, flags);
  256. /* wakeup userspace */
  257. if (omap_crtc->flip_event)
  258. drm_send_vblank_event(dev, omap_crtc->pipe,
  259. omap_crtc->flip_event);
  260. omap_crtc->flip_event = NULL;
  261. omap_crtc->flip_pending = false;
  262. spin_unlock_irqrestore(&dev->event_lock, flags);
  263. complete(&omap_crtc->completion);
  264. }
  265. int omap_crtc_flush(struct drm_crtc *crtc)
  266. {
  267. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  268. struct omap_framebuffer_unpin *fb, *next;
  269. DBG("%s: GO", omap_crtc->name);
  270. WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
  271. WARN_ON(omap_crtc->vblank_irq.registered);
  272. dispc_runtime_get();
  273. if (dispc_mgr_is_enabled(omap_crtc->channel)) {
  274. dispc_mgr_go(omap_crtc->channel);
  275. omap_irq_register(crtc->dev, &omap_crtc->vblank_irq);
  276. WARN_ON(!wait_for_completion_timeout(&omap_crtc->completion,
  277. msecs_to_jiffies(100)));
  278. reinit_completion(&omap_crtc->completion);
  279. }
  280. dispc_runtime_put();
  281. /* Unpin and unreference pending framebuffers. */
  282. list_for_each_entry_safe(fb, next, &omap_crtc->pending_unpins, list) {
  283. omap_framebuffer_unpin(fb->fb);
  284. drm_framebuffer_unreference(fb->fb);
  285. list_del(&fb->list);
  286. kfree(fb);
  287. }
  288. return 0;
  289. }
  290. int omap_crtc_queue_unpin(struct drm_crtc *crtc, struct drm_framebuffer *fb)
  291. {
  292. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  293. struct omap_framebuffer_unpin *unpin;
  294. unpin = kzalloc(sizeof(*unpin), GFP_KERNEL);
  295. if (!unpin)
  296. return -ENOMEM;
  297. unpin->fb = fb;
  298. list_add_tail(&unpin->list, &omap_crtc->pending_unpins);
  299. return 0;
  300. }
  301. static void omap_crtc_setup(struct drm_crtc *crtc)
  302. {
  303. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  304. struct omap_drm_private *priv = crtc->dev->dev_private;
  305. struct drm_encoder *encoder = NULL;
  306. unsigned int i;
  307. DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled);
  308. dispc_runtime_get();
  309. for (i = 0; i < priv->num_encoders; i++) {
  310. if (priv->encoders[i]->crtc == crtc) {
  311. encoder = priv->encoders[i];
  312. break;
  313. }
  314. }
  315. if (omap_crtc->current_encoder && encoder != omap_crtc->current_encoder)
  316. omap_encoder_set_enabled(omap_crtc->current_encoder, false);
  317. omap_crtc->current_encoder = encoder;
  318. if (!omap_crtc->enabled) {
  319. if (encoder)
  320. omap_encoder_set_enabled(encoder, false);
  321. } else {
  322. if (encoder) {
  323. omap_encoder_set_enabled(encoder, false);
  324. omap_encoder_update(encoder, omap_crtc->mgr,
  325. &omap_crtc->timings);
  326. omap_encoder_set_enabled(encoder, true);
  327. }
  328. }
  329. dispc_runtime_put();
  330. }
  331. /* -----------------------------------------------------------------------------
  332. * CRTC Functions
  333. */
  334. static void omap_crtc_destroy(struct drm_crtc *crtc)
  335. {
  336. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  337. DBG("%s", omap_crtc->name);
  338. WARN_ON(omap_crtc->vblank_irq.registered);
  339. omap_irq_unregister(crtc->dev, &omap_crtc->error_irq);
  340. drm_crtc_cleanup(crtc);
  341. kfree(omap_crtc);
  342. }
  343. static void omap_crtc_dpms(struct drm_crtc *crtc, int mode)
  344. {
  345. struct omap_drm_private *priv = crtc->dev->dev_private;
  346. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  347. bool enabled = (mode == DRM_MODE_DPMS_ON);
  348. int i;
  349. DBG("%s: %d", omap_crtc->name, mode);
  350. if (enabled == omap_crtc->enabled)
  351. return;
  352. /* Enable/disable all planes associated with the CRTC. */
  353. for (i = 0; i < priv->num_planes; i++) {
  354. struct drm_plane *plane = priv->planes[i];
  355. if (plane->crtc == crtc)
  356. WARN_ON(omap_plane_set_enable(plane, enabled));
  357. }
  358. omap_crtc->enabled = enabled;
  359. omap_crtc_setup(crtc);
  360. omap_crtc_flush(crtc);
  361. }
  362. static bool omap_crtc_mode_fixup(struct drm_crtc *crtc,
  363. const struct drm_display_mode *mode,
  364. struct drm_display_mode *adjusted_mode)
  365. {
  366. return true;
  367. }
  368. static int omap_crtc_mode_set(struct drm_crtc *crtc,
  369. struct drm_display_mode *mode,
  370. struct drm_display_mode *adjusted_mode,
  371. int x, int y,
  372. struct drm_framebuffer *old_fb)
  373. {
  374. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  375. mode = adjusted_mode;
  376. DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  377. omap_crtc->name, mode->base.id, mode->name,
  378. mode->vrefresh, mode->clock,
  379. mode->hdisplay, mode->hsync_start,
  380. mode->hsync_end, mode->htotal,
  381. mode->vdisplay, mode->vsync_start,
  382. mode->vsync_end, mode->vtotal,
  383. mode->type, mode->flags);
  384. copy_timings_drm_to_omap(&omap_crtc->timings, mode);
  385. /*
  386. * The primary plane CRTC can be reset if the plane is disabled directly
  387. * through the universal plane API. Set it again here.
  388. */
  389. crtc->primary->crtc = crtc;
  390. return omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
  391. 0, 0, mode->hdisplay, mode->vdisplay,
  392. x, y, mode->hdisplay, mode->vdisplay);
  393. }
  394. static void omap_crtc_prepare(struct drm_crtc *crtc)
  395. {
  396. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  397. DBG("%s", omap_crtc->name);
  398. omap_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  399. }
  400. static void omap_crtc_commit(struct drm_crtc *crtc)
  401. {
  402. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  403. DBG("%s", omap_crtc->name);
  404. omap_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  405. }
  406. static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  407. struct drm_framebuffer *old_fb)
  408. {
  409. struct drm_plane *plane = crtc->primary;
  410. struct drm_display_mode *mode = &crtc->mode;
  411. int ret;
  412. ret = omap_plane_mode_set(plane, crtc, crtc->primary->fb,
  413. 0, 0, mode->hdisplay, mode->vdisplay,
  414. x, y, mode->hdisplay, mode->vdisplay);
  415. if (ret < 0)
  416. return ret;
  417. return omap_crtc_flush(crtc);
  418. }
  419. static void page_flip_worker(struct work_struct *work)
  420. {
  421. struct omap_crtc *omap_crtc =
  422. container_of(work, struct omap_crtc, flip_work);
  423. struct drm_crtc *crtc = &omap_crtc->base;
  424. struct drm_display_mode *mode = &crtc->mode;
  425. struct drm_gem_object *bo;
  426. drm_modeset_lock(&crtc->mutex, NULL);
  427. omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
  428. 0, 0, mode->hdisplay, mode->vdisplay,
  429. crtc->x, crtc->y, mode->hdisplay, mode->vdisplay);
  430. omap_crtc_flush(crtc);
  431. drm_modeset_unlock(&crtc->mutex);
  432. bo = omap_framebuffer_bo(crtc->primary->fb, 0);
  433. drm_gem_object_unreference_unlocked(bo);
  434. drm_framebuffer_unreference(crtc->primary->fb);
  435. }
  436. static void page_flip_cb(void *arg)
  437. {
  438. struct drm_crtc *crtc = arg;
  439. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  440. struct omap_drm_private *priv = crtc->dev->dev_private;
  441. /* avoid assumptions about what ctxt we are called from: */
  442. queue_work(priv->wq, &omap_crtc->flip_work);
  443. }
  444. static int omap_crtc_page_flip(struct drm_crtc *crtc,
  445. struct drm_framebuffer *fb,
  446. struct drm_pending_vblank_event *event,
  447. uint32_t page_flip_flags)
  448. {
  449. struct drm_device *dev = crtc->dev;
  450. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  451. struct drm_plane *primary = crtc->primary;
  452. struct drm_gem_object *bo;
  453. unsigned long flags;
  454. DBG("%d -> %d (event=%p)", primary->fb ? primary->fb->base.id : -1,
  455. fb->base.id, event);
  456. spin_lock_irqsave(&dev->event_lock, flags);
  457. if (omap_crtc->flip_pending) {
  458. spin_unlock_irqrestore(&dev->event_lock, flags);
  459. dev_err(dev->dev, "already a pending flip\n");
  460. return -EBUSY;
  461. }
  462. omap_crtc->flip_event = event;
  463. omap_crtc->flip_pending = true;
  464. primary->fb = fb;
  465. drm_framebuffer_reference(fb);
  466. spin_unlock_irqrestore(&dev->event_lock, flags);
  467. /*
  468. * Hold a reference temporarily until the crtc is updated
  469. * and takes the reference to the bo. This avoids it
  470. * getting freed from under us:
  471. */
  472. bo = omap_framebuffer_bo(fb, 0);
  473. drm_gem_object_reference(bo);
  474. omap_gem_op_async(bo, OMAP_GEM_READ, page_flip_cb, crtc);
  475. return 0;
  476. }
  477. static int omap_crtc_set_property(struct drm_crtc *crtc,
  478. struct drm_property *property, uint64_t val)
  479. {
  480. if (property == crtc->dev->mode_config.rotation_property) {
  481. crtc->invert_dimensions =
  482. !!(val & ((1LL << DRM_ROTATE_90) | (1LL << DRM_ROTATE_270)));
  483. }
  484. return omap_plane_set_property(crtc->primary, property, val);
  485. }
  486. static const struct drm_crtc_funcs omap_crtc_funcs = {
  487. .set_config = drm_crtc_helper_set_config,
  488. .destroy = omap_crtc_destroy,
  489. .page_flip = omap_crtc_page_flip,
  490. .set_property = omap_crtc_set_property,
  491. };
  492. static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
  493. .dpms = omap_crtc_dpms,
  494. .mode_fixup = omap_crtc_mode_fixup,
  495. .mode_set = omap_crtc_mode_set,
  496. .prepare = omap_crtc_prepare,
  497. .commit = omap_crtc_commit,
  498. .mode_set_base = omap_crtc_mode_set_base,
  499. };
  500. /* -----------------------------------------------------------------------------
  501. * Init and Cleanup
  502. */
  503. static const char *channel_names[] = {
  504. [OMAP_DSS_CHANNEL_LCD] = "lcd",
  505. [OMAP_DSS_CHANNEL_DIGIT] = "tv",
  506. [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
  507. [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
  508. };
  509. void omap_crtc_pre_init(void)
  510. {
  511. dss_install_mgr_ops(&mgr_ops);
  512. }
  513. void omap_crtc_pre_uninit(void)
  514. {
  515. dss_uninstall_mgr_ops();
  516. }
  517. /* initialize crtc */
  518. struct drm_crtc *omap_crtc_init(struct drm_device *dev,
  519. struct drm_plane *plane, enum omap_channel channel, int id)
  520. {
  521. struct drm_crtc *crtc = NULL;
  522. struct omap_crtc *omap_crtc;
  523. struct omap_overlay_manager_info *info;
  524. int ret;
  525. DBG("%s", channel_names[channel]);
  526. omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
  527. if (!omap_crtc)
  528. return NULL;
  529. crtc = &omap_crtc->base;
  530. INIT_WORK(&omap_crtc->flip_work, page_flip_worker);
  531. INIT_LIST_HEAD(&omap_crtc->pending_unpins);
  532. init_completion(&omap_crtc->completion);
  533. omap_crtc->channel = channel;
  534. omap_crtc->name = channel_names[channel];
  535. omap_crtc->pipe = id;
  536. omap_crtc->vblank_irq.irqmask = pipe2vbl(crtc);
  537. omap_crtc->vblank_irq.irq = omap_crtc_vblank_irq;
  538. omap_crtc->error_irq.irqmask =
  539. dispc_mgr_get_sync_lost_irq(channel);
  540. omap_crtc->error_irq.irq = omap_crtc_error_irq;
  541. omap_irq_register(dev, &omap_crtc->error_irq);
  542. /* temporary: */
  543. omap_crtc->mgr = omap_dss_get_overlay_manager(channel);
  544. /* TODO: fix hard-coded setup.. add properties! */
  545. info = &omap_crtc->info;
  546. info->default_color = 0x00000000;
  547. info->trans_key = 0x00000000;
  548. info->trans_key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
  549. info->trans_enabled = false;
  550. ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
  551. &omap_crtc_funcs);
  552. if (ret < 0) {
  553. kfree(omap_crtc);
  554. return NULL;
  555. }
  556. drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
  557. omap_plane_install_properties(crtc->primary, &crtc->base);
  558. omap_crtcs[channel] = omap_crtc;
  559. return crtc;
  560. }