omap_crtc.c 19 KB

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