sti_plane.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. const char *sti_plane_to_str(struct sti_plane *plane)
  15. {
  16. switch (plane->desc) {
  17. case STI_GDP_0:
  18. return "GDP0";
  19. case STI_GDP_1:
  20. return "GDP1";
  21. case STI_GDP_2:
  22. return "GDP2";
  23. case STI_GDP_3:
  24. return "GDP3";
  25. case STI_HQVDP_0:
  26. return "HQVDP0";
  27. case STI_CURSOR:
  28. return "CURSOR";
  29. default:
  30. return "<UNKNOWN PLANE>";
  31. }
  32. }
  33. #define STI_FPS_INTERVAL_MS 3000
  34. void sti_plane_update_fps(struct sti_plane *plane,
  35. bool new_frame,
  36. bool new_field)
  37. {
  38. ktime_t now;
  39. struct sti_fps_info *fps;
  40. int fpks, fipks, ms_since_last, num_frames, num_fields;
  41. now = ktime_get();
  42. /* Compute number of frame updates */
  43. fps = &plane->fps_info;
  44. if (new_field)
  45. fps->curr_field_counter++;
  46. /* do not perform fps calcul if new_frame is false */
  47. if (!new_frame)
  48. return;
  49. fps->curr_frame_counter++;
  50. ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
  51. num_frames = fps->curr_frame_counter - fps->last_frame_counter;
  52. if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
  53. return;
  54. fps->last_timestamp = now;
  55. fps->last_frame_counter = fps->curr_frame_counter;
  56. fpks = (num_frames * 1000000) / ms_since_last;
  57. snprintf(plane->fps_info.fps_str, FPS_LENGTH, "%-6s @ %d.%.3d fps",
  58. sti_plane_to_str(plane), fpks / 1000, fpks % 1000);
  59. if (fps->curr_field_counter) {
  60. /* Compute number of field updates */
  61. num_fields = fps->curr_field_counter - fps->last_field_counter;
  62. fps->last_field_counter = fps->curr_field_counter;
  63. fipks = (num_fields * 1000000) / ms_since_last;
  64. snprintf(plane->fps_info.fips_str,
  65. FPS_LENGTH, " - %d.%.3d field/sec",
  66. fipks / 1000, fipks % 1000);
  67. } else {
  68. plane->fps_info.fips_str[0] = '\0';
  69. }
  70. if (fps->output)
  71. DRM_INFO("%s%s\n",
  72. plane->fps_info.fps_str,
  73. plane->fps_info.fips_str);
  74. }
  75. static int sti_plane_get_default_zpos(enum drm_plane_type type)
  76. {
  77. switch (type) {
  78. case DRM_PLANE_TYPE_PRIMARY:
  79. return 0;
  80. case DRM_PLANE_TYPE_OVERLAY:
  81. return 1;
  82. case DRM_PLANE_TYPE_CURSOR:
  83. return 7;
  84. }
  85. return 0;
  86. }
  87. void sti_plane_reset(struct drm_plane *plane)
  88. {
  89. drm_atomic_helper_plane_reset(plane);
  90. plane->state->zpos = sti_plane_get_default_zpos(plane->type);
  91. }
  92. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
  93. enum drm_plane_type type)
  94. {
  95. int zpos = sti_plane_get_default_zpos(type);
  96. switch (type) {
  97. case DRM_PLANE_TYPE_PRIMARY:
  98. case DRM_PLANE_TYPE_OVERLAY:
  99. drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
  100. break;
  101. case DRM_PLANE_TYPE_CURSOR:
  102. drm_plane_create_zpos_immutable_property(drm_plane, zpos);
  103. break;
  104. }
  105. }
  106. void sti_plane_init_property(struct sti_plane *plane,
  107. enum drm_plane_type type)
  108. {
  109. sti_plane_attach_zorder_property(&plane->drm_plane, type);
  110. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
  111. plane->drm_plane.base.id, sti_plane_to_str(plane));
  112. }