omap_crtc.c 20 KB

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