sti_plane.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) STMicroelectronics SA 2014
  4. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  5. * Fabien Dessenne <fabien.dessenne@st.com>
  6. * for STMicroelectronics.
  7. */
  8. #include <linux/types.h>
  9. #include <drm/drm_blend.h>
  10. #include <drm/drm_fourcc.h>
  11. #include <drm/drm_framebuffer.h>
  12. #include <drm/drm_gem_dma_helper.h>
  13. #include <drm/drm_print.h>
  14. #include "sti_compositor.h"
  15. #include "sti_drv.h"
  16. #include "sti_plane.h"
  17. const char *sti_plane_to_str(struct sti_plane *plane)
  18. {
  19. switch (plane->desc) {
  20. case STI_GDP_0:
  21. return "GDP0";
  22. case STI_GDP_1:
  23. return "GDP1";
  24. case STI_GDP_2:
  25. return "GDP2";
  26. case STI_GDP_3:
  27. return "GDP3";
  28. case STI_HQVDP_0:
  29. return "HQVDP0";
  30. case STI_CURSOR:
  31. return "CURSOR";
  32. default:
  33. return "<UNKNOWN PLANE>";
  34. }
  35. }
  36. #define STI_FPS_INTERVAL_MS 3000
  37. void sti_plane_update_fps(struct sti_plane *plane,
  38. bool new_frame,
  39. bool new_field)
  40. {
  41. struct drm_plane_state *state = plane->drm_plane.state;
  42. ktime_t now;
  43. struct sti_fps_info *fps;
  44. int fpks, fipks, ms_since_last, num_frames, num_fields;
  45. now = ktime_get();
  46. /* Compute number of frame updates */
  47. fps = &plane->fps_info;
  48. if (new_field)
  49. fps->curr_field_counter++;
  50. /* do not perform fps calcul if new_frame is false */
  51. if (!new_frame)
  52. return;
  53. fps->curr_frame_counter++;
  54. ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
  55. num_frames = fps->curr_frame_counter - fps->last_frame_counter;
  56. if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
  57. return;
  58. fps->last_timestamp = now;
  59. fps->last_frame_counter = fps->curr_frame_counter;
  60. if (state->fb) {
  61. fpks = (num_frames * 1000000) / ms_since_last;
  62. snprintf(plane->fps_info.fps_str, FPS_LENGTH,
  63. "%-8s %4dx%-4d %.4s @ %3d.%-3.3d fps (%s)",
  64. plane->drm_plane.name,
  65. state->fb->width,
  66. state->fb->height,
  67. (char *)&state->fb->format->format,
  68. fpks / 1000, fpks % 1000,
  69. sti_plane_to_str(plane));
  70. }
  71. if (fps->curr_field_counter) {
  72. /* Compute number of field updates */
  73. num_fields = fps->curr_field_counter - fps->last_field_counter;
  74. fps->last_field_counter = fps->curr_field_counter;
  75. fipks = (num_fields * 1000000) / ms_since_last;
  76. snprintf(plane->fps_info.fips_str,
  77. FPS_LENGTH, " - %3d.%-3.3d field/sec",
  78. fipks / 1000, fipks % 1000);
  79. } else {
  80. plane->fps_info.fips_str[0] = '\0';
  81. }
  82. if (fps->output)
  83. DRM_INFO("%s%s\n",
  84. plane->fps_info.fps_str,
  85. plane->fps_info.fips_str);
  86. }
  87. static int sti_plane_get_default_zpos(enum drm_plane_type type)
  88. {
  89. switch (type) {
  90. case DRM_PLANE_TYPE_PRIMARY:
  91. return 0;
  92. case DRM_PLANE_TYPE_OVERLAY:
  93. return 1;
  94. case DRM_PLANE_TYPE_CURSOR:
  95. return 7;
  96. }
  97. return 0;
  98. }
  99. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
  100. enum drm_plane_type type)
  101. {
  102. int zpos = sti_plane_get_default_zpos(type);
  103. switch (type) {
  104. case DRM_PLANE_TYPE_PRIMARY:
  105. case DRM_PLANE_TYPE_OVERLAY:
  106. drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
  107. break;
  108. case DRM_PLANE_TYPE_CURSOR:
  109. drm_plane_create_zpos_immutable_property(drm_plane, zpos);
  110. break;
  111. }
  112. }
  113. void sti_plane_init_property(struct sti_plane *plane,
  114. enum drm_plane_type type)
  115. {
  116. sti_plane_attach_zorder_property(&plane->drm_plane, type);
  117. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
  118. plane->drm_plane.base.id, sti_plane_to_str(plane));
  119. }