sti_plane.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4. * Fabien Dessenne <fabien.dessenne@st.com>
  5. * for STMicroelectronics.
  6. * License terms: GNU General Public License (GPL), version 2
  7. */
  8. #include <drm/drmP.h>
  9. #include <drm/drm_fb_cma_helper.h>
  10. #include <drm/drm_gem_cma_helper.h>
  11. #include "sti_compositor.h"
  12. #include "sti_drv.h"
  13. #include "sti_plane.h"
  14. /* (Background) < GDP0 < GDP1 < HQVDP0 < GDP2 < GDP3 < (ForeGround) */
  15. enum sti_plane_desc sti_plane_default_zorder[] = {
  16. STI_GDP_0,
  17. STI_GDP_1,
  18. STI_HQVDP_0,
  19. STI_GDP_2,
  20. STI_GDP_3,
  21. };
  22. const char *sti_plane_to_str(struct sti_plane *plane)
  23. {
  24. switch (plane->desc) {
  25. case STI_GDP_0:
  26. return "GDP0";
  27. case STI_GDP_1:
  28. return "GDP1";
  29. case STI_GDP_2:
  30. return "GDP2";
  31. case STI_GDP_3:
  32. return "GDP3";
  33. case STI_HQVDP_0:
  34. return "HQVDP0";
  35. case STI_CURSOR:
  36. return "CURSOR";
  37. default:
  38. return "<UNKNOWN PLANE>";
  39. }
  40. }
  41. #define STI_FPS_INTERVAL_MS 3000
  42. static int sti_plane_timespec_ms_diff(struct timespec lhs, struct timespec rhs)
  43. {
  44. struct timespec tmp_ts = timespec_sub(lhs, rhs);
  45. u64 tmp_ns = (u64)timespec_to_ns(&tmp_ts);
  46. do_div(tmp_ns, NSEC_PER_MSEC);
  47. return (u32)tmp_ns;
  48. }
  49. void sti_plane_update_fps(struct sti_plane *plane,
  50. bool new_frame,
  51. bool new_field)
  52. {
  53. struct timespec now;
  54. struct sti_fps_info *fps;
  55. int fpks, fipks, ms_since_last, num_frames, num_fields;
  56. getrawmonotonic(&now);
  57. /* Compute number of frame updates */
  58. fps = &plane->fps_info;
  59. if (new_field)
  60. fps->curr_field_counter++;
  61. /* do not perform fps calcul if new_frame is false */
  62. if (!new_frame)
  63. return;
  64. fps->curr_frame_counter++;
  65. ms_since_last = sti_plane_timespec_ms_diff(now, fps->last_timestamp);
  66. num_frames = fps->curr_frame_counter - fps->last_frame_counter;
  67. if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
  68. return;
  69. fps->last_timestamp = now;
  70. fps->last_frame_counter = fps->curr_frame_counter;
  71. fpks = (num_frames * 1000000) / ms_since_last;
  72. snprintf(plane->fps_info.fps_str, FPS_LENGTH, "%-6s @ %d.%.3d fps",
  73. sti_plane_to_str(plane), fpks / 1000, fpks % 1000);
  74. if (fps->curr_field_counter) {
  75. /* Compute number of field updates */
  76. num_fields = fps->curr_field_counter - fps->last_field_counter;
  77. fps->last_field_counter = fps->curr_field_counter;
  78. fipks = (num_fields * 1000000) / ms_since_last;
  79. snprintf(plane->fps_info.fips_str,
  80. FPS_LENGTH, " - %d.%.3d field/sec",
  81. fipks / 1000, fipks % 1000);
  82. } else {
  83. plane->fps_info.fips_str[0] = '\0';
  84. }
  85. if (fps->output)
  86. DRM_INFO("%s%s\n",
  87. plane->fps_info.fps_str,
  88. plane->fps_info.fips_str);
  89. }
  90. static void sti_plane_destroy(struct drm_plane *drm_plane)
  91. {
  92. DRM_DEBUG_DRIVER("\n");
  93. drm_plane_helper_disable(drm_plane);
  94. drm_plane_cleanup(drm_plane);
  95. }
  96. static int sti_plane_set_property(struct drm_plane *drm_plane,
  97. struct drm_property *property,
  98. uint64_t val)
  99. {
  100. struct drm_device *dev = drm_plane->dev;
  101. struct sti_private *private = dev->dev_private;
  102. struct sti_plane *plane = to_sti_plane(drm_plane);
  103. DRM_DEBUG_DRIVER("\n");
  104. if (property == private->plane_zorder_property) {
  105. plane->zorder = val;
  106. return 0;
  107. }
  108. return -EINVAL;
  109. }
  110. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane)
  111. {
  112. struct drm_device *dev = drm_plane->dev;
  113. struct sti_private *private = dev->dev_private;
  114. struct sti_plane *plane = to_sti_plane(drm_plane);
  115. struct drm_property *prop;
  116. prop = private->plane_zorder_property;
  117. if (!prop) {
  118. prop = drm_property_create_range(dev, 0, "zpos", 1,
  119. GAM_MIXER_NB_DEPTH_LEVEL);
  120. if (!prop)
  121. return;
  122. private->plane_zorder_property = prop;
  123. }
  124. drm_object_attach_property(&drm_plane->base, prop, plane->zorder);
  125. }
  126. void sti_plane_init_property(struct sti_plane *plane,
  127. enum drm_plane_type type)
  128. {
  129. unsigned int i;
  130. for (i = 0; i < ARRAY_SIZE(sti_plane_default_zorder); i++)
  131. if (sti_plane_default_zorder[i] == plane->desc)
  132. break;
  133. plane->zorder = i + 1;
  134. if (type == DRM_PLANE_TYPE_OVERLAY)
  135. sti_plane_attach_zorder_property(&plane->drm_plane);
  136. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%d\n",
  137. plane->drm_plane.base.id,
  138. sti_plane_to_str(plane), plane->zorder);
  139. }
  140. struct drm_plane_funcs sti_plane_helpers_funcs = {
  141. .update_plane = drm_atomic_helper_update_plane,
  142. .disable_plane = drm_atomic_helper_disable_plane,
  143. .destroy = sti_plane_destroy,
  144. .set_property = sti_plane_set_property,
  145. .reset = drm_atomic_helper_plane_reset,
  146. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  147. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  148. };