omap_crtc.c 20 KB

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