exynos_drm_crtc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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_enable(struct drm_crtc *crtc)
  22. {
  23. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  24. if (exynos_crtc->ops->enable)
  25. exynos_crtc->ops->enable(exynos_crtc);
  26. drm_crtc_vblank_on(crtc);
  27. }
  28. static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
  29. {
  30. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  31. drm_crtc_vblank_off(crtc);
  32. if (exynos_crtc->ops->disable)
  33. exynos_crtc->ops->disable(exynos_crtc);
  34. if (crtc->state->event && !crtc->state->active) {
  35. spin_lock_irq(&crtc->dev->event_lock);
  36. drm_crtc_send_vblank_event(crtc, crtc->state->event);
  37. spin_unlock_irq(&crtc->dev->event_lock);
  38. crtc->state->event = NULL;
  39. }
  40. }
  41. static void
  42. exynos_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
  43. {
  44. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  45. if (exynos_crtc->ops->commit)
  46. exynos_crtc->ops->commit(exynos_crtc);
  47. }
  48. static int exynos_crtc_atomic_check(struct drm_crtc *crtc,
  49. struct drm_crtc_state *state)
  50. {
  51. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  52. if (!state->enable)
  53. return 0;
  54. if (exynos_crtc->ops->atomic_check)
  55. return exynos_crtc->ops->atomic_check(exynos_crtc, state);
  56. return 0;
  57. }
  58. static void exynos_crtc_atomic_begin(struct drm_crtc *crtc,
  59. struct drm_crtc_state *old_crtc_state)
  60. {
  61. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  62. if (exynos_crtc->ops->atomic_begin)
  63. exynos_crtc->ops->atomic_begin(exynos_crtc);
  64. }
  65. static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
  66. struct drm_crtc_state *old_crtc_state)
  67. {
  68. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  69. if (exynos_crtc->ops->atomic_flush)
  70. exynos_crtc->ops->atomic_flush(exynos_crtc);
  71. }
  72. static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
  73. .enable = exynos_drm_crtc_enable,
  74. .disable = exynos_drm_crtc_disable,
  75. .mode_set_nofb = exynos_drm_crtc_mode_set_nofb,
  76. .atomic_check = exynos_crtc_atomic_check,
  77. .atomic_begin = exynos_crtc_atomic_begin,
  78. .atomic_flush = exynos_crtc_atomic_flush,
  79. };
  80. void exynos_crtc_handle_event(struct exynos_drm_crtc *exynos_crtc)
  81. {
  82. struct drm_crtc *crtc = &exynos_crtc->base;
  83. struct drm_pending_vblank_event *event = crtc->state->event;
  84. unsigned long flags;
  85. if (event) {
  86. crtc->state->event = NULL;
  87. spin_lock_irqsave(&crtc->dev->event_lock, flags);
  88. if (drm_crtc_vblank_get(crtc) == 0)
  89. drm_crtc_arm_vblank_event(crtc, event);
  90. else
  91. drm_crtc_send_vblank_event(crtc, event);
  92. spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  93. }
  94. }
  95. static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
  96. {
  97. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  98. drm_crtc_cleanup(crtc);
  99. kfree(exynos_crtc);
  100. }
  101. static const struct drm_crtc_funcs exynos_crtc_funcs = {
  102. .set_config = drm_atomic_helper_set_config,
  103. .page_flip = drm_atomic_helper_page_flip,
  104. .destroy = exynos_drm_crtc_destroy,
  105. .reset = drm_atomic_helper_crtc_reset,
  106. .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
  107. .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
  108. };
  109. struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
  110. struct drm_plane *plane,
  111. int pipe,
  112. enum exynos_drm_output_type type,
  113. const struct exynos_drm_crtc_ops *ops,
  114. void *ctx)
  115. {
  116. struct exynos_drm_crtc *exynos_crtc;
  117. struct drm_crtc *crtc;
  118. int ret;
  119. exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
  120. if (!exynos_crtc)
  121. return ERR_PTR(-ENOMEM);
  122. exynos_crtc->pipe = pipe;
  123. exynos_crtc->type = type;
  124. exynos_crtc->ops = ops;
  125. exynos_crtc->ctx = ctx;
  126. crtc = &exynos_crtc->base;
  127. ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
  128. &exynos_crtc_funcs, NULL);
  129. if (ret < 0)
  130. goto err_crtc;
  131. drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
  132. return exynos_crtc;
  133. err_crtc:
  134. plane->funcs->destroy(plane);
  135. kfree(exynos_crtc);
  136. return ERR_PTR(ret);
  137. }
  138. int exynos_drm_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe)
  139. {
  140. struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev,
  141. pipe);
  142. if (exynos_crtc->ops->enable_vblank)
  143. return exynos_crtc->ops->enable_vblank(exynos_crtc);
  144. return 0;
  145. }
  146. void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe)
  147. {
  148. struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev,
  149. pipe);
  150. if (exynos_crtc->ops->disable_vblank)
  151. exynos_crtc->ops->disable_vblank(exynos_crtc);
  152. }
  153. int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
  154. enum exynos_drm_output_type out_type)
  155. {
  156. struct drm_crtc *crtc;
  157. list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
  158. struct exynos_drm_crtc *exynos_crtc;
  159. exynos_crtc = to_exynos_crtc(crtc);
  160. if (exynos_crtc->type == out_type)
  161. return exynos_crtc->pipe;
  162. }
  163. return -EPERM;
  164. }
  165. void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
  166. {
  167. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  168. if (exynos_crtc->ops->te_handler)
  169. exynos_crtc->ops->te_handler(exynos_crtc);
  170. }