omap_crtc.c 19 KB

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