exynos_drm_crtc.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* exynos_drm_crtc.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Authors:
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. * Seung-Woo Kim <sw0312.kim@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <drm/drmP.h>
  15. #include <drm/drm_crtc_helper.h>
  16. #include <drm/drm_atomic.h>
  17. #include <drm/drm_atomic_helper.h>
  18. #include "exynos_drm_crtc.h"
  19. #include "exynos_drm_drv.h"
  20. #include "exynos_drm_plane.h"
  21. static void exynos_drm_crtc_atomic_enable(struct drm_crtc *crtc,
  22. struct drm_crtc_state *old_state)
  23. {
  24. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  25. if (exynos_crtc->ops->enable)
  26. exynos_crtc->ops->enable(exynos_crtc);
  27. drm_crtc_vblank_on(crtc);
  28. }
  29. static void exynos_drm_crtc_atomic_disable(struct drm_crtc *crtc,
  30. struct drm_crtc_state *old_state)
  31. {
  32. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  33. drm_crtc_vblank_off(crtc);
  34. if (exynos_crtc->ops->disable)
  35. exynos_crtc->ops->disable(exynos_crtc);
  36. if (crtc->state->event && !crtc->state->active) {
  37. spin_lock_irq(&crtc->dev->event_lock);
  38. drm_crtc_send_vblank_event(crtc, crtc->state->event);
  39. spin_unlock_irq(&crtc->dev->event_lock);
  40. crtc->state->event = NULL;
  41. }
  42. }
  43. static int exynos_crtc_atomic_check(struct drm_crtc *crtc,
  44. struct drm_crtc_state *state)
  45. {
  46. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  47. if (!state->enable)
  48. return 0;
  49. if (exynos_crtc->ops->atomic_check)
  50. return exynos_crtc->ops->atomic_check(exynos_crtc, state);
  51. return 0;
  52. }
  53. static void exynos_crtc_atomic_begin(struct drm_crtc *crtc,
  54. struct drm_crtc_state *old_crtc_state)
  55. {
  56. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  57. if (exynos_crtc->ops->atomic_begin)
  58. exynos_crtc->ops->atomic_begin(exynos_crtc);
  59. }
  60. static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
  61. struct drm_crtc_state *old_crtc_state)
  62. {
  63. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  64. if (exynos_crtc->ops->atomic_flush)
  65. exynos_crtc->ops->atomic_flush(exynos_crtc);
  66. }
  67. static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
  68. .atomic_check = exynos_crtc_atomic_check,
  69. .atomic_begin = exynos_crtc_atomic_begin,
  70. .atomic_flush = exynos_crtc_atomic_flush,
  71. .atomic_enable = exynos_drm_crtc_atomic_enable,
  72. .atomic_disable = exynos_drm_crtc_atomic_disable,
  73. };
  74. void exynos_crtc_handle_event(struct exynos_drm_crtc *exynos_crtc)
  75. {
  76. struct drm_crtc *crtc = &exynos_crtc->base;
  77. struct drm_pending_vblank_event *event = crtc->state->event;
  78. unsigned long flags;
  79. if (!event)
  80. return;
  81. crtc->state->event = NULL;
  82. WARN_ON(drm_crtc_vblank_get(crtc) != 0);
  83. spin_lock_irqsave(&crtc->dev->event_lock, flags);
  84. drm_crtc_arm_vblank_event(crtc, event);
  85. spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  86. }
  87. static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
  88. {
  89. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  90. drm_crtc_cleanup(crtc);
  91. kfree(exynos_crtc);
  92. }
  93. static int exynos_drm_crtc_enable_vblank(struct drm_crtc *crtc)
  94. {
  95. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  96. if (exynos_crtc->ops->enable_vblank)
  97. return exynos_crtc->ops->enable_vblank(exynos_crtc);
  98. return 0;
  99. }
  100. static void exynos_drm_crtc_disable_vblank(struct drm_crtc *crtc)
  101. {
  102. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  103. if (exynos_crtc->ops->disable_vblank)
  104. exynos_crtc->ops->disable_vblank(exynos_crtc);
  105. }
  106. static u32 exynos_drm_crtc_get_vblank_counter(struct drm_crtc *crtc)
  107. {
  108. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  109. if (exynos_crtc->ops->get_vblank_counter)
  110. return exynos_crtc->ops->get_vblank_counter(exynos_crtc);
  111. return 0;
  112. }
  113. static const struct drm_crtc_funcs exynos_crtc_funcs = {
  114. .set_config = drm_atomic_helper_set_config,
  115. .page_flip = drm_atomic_helper_page_flip,
  116. .destroy = exynos_drm_crtc_destroy,
  117. .reset = drm_atomic_helper_crtc_reset,
  118. .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
  119. .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
  120. .enable_vblank = exynos_drm_crtc_enable_vblank,
  121. .disable_vblank = exynos_drm_crtc_disable_vblank,
  122. .get_vblank_counter = exynos_drm_crtc_get_vblank_counter,
  123. };
  124. struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
  125. struct drm_plane *plane,
  126. enum exynos_drm_output_type type,
  127. const struct exynos_drm_crtc_ops *ops,
  128. void *ctx)
  129. {
  130. struct exynos_drm_crtc *exynos_crtc;
  131. struct drm_crtc *crtc;
  132. int ret;
  133. exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
  134. if (!exynos_crtc)
  135. return ERR_PTR(-ENOMEM);
  136. exynos_crtc->type = type;
  137. exynos_crtc->ops = ops;
  138. exynos_crtc->ctx = ctx;
  139. crtc = &exynos_crtc->base;
  140. ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
  141. &exynos_crtc_funcs, NULL);
  142. if (ret < 0)
  143. goto err_crtc;
  144. drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
  145. return exynos_crtc;
  146. err_crtc:
  147. plane->funcs->destroy(plane);
  148. kfree(exynos_crtc);
  149. return ERR_PTR(ret);
  150. }
  151. int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
  152. enum exynos_drm_output_type out_type)
  153. {
  154. struct drm_crtc *crtc;
  155. drm_for_each_crtc(crtc, drm_dev)
  156. if (to_exynos_crtc(crtc)->type == out_type)
  157. return drm_crtc_index(crtc);
  158. return -EPERM;
  159. }
  160. void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
  161. {
  162. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  163. if (exynos_crtc->ops->te_handler)
  164. exynos_crtc->ops->te_handler(exynos_crtc);
  165. }